FV3 Bundle
src/fileio/IodaIO.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef FILEIO_IODAIO_H_
9 #define FILEIO_IODAIO_H_
10 
11 #include <string>
12 
13 #include "oops/util/Printable.h"
14 
15 // Forward declarations
16 namespace eckit {
17  class Configuration;
18 }
19 
20 namespace ioda {
21 
22 /*!
23  * \brief File access class for IODA
24  *
25  * \details The IodaIO class provides the interface for file access. Note that IodaIO is an
26  * abstract base class.
27  *
28  * Eventually, we want to get to the same file format for every obs type.
29  * Currently we are defining this as follows. A file can contain any
30  * number of variables. Each variable is a 1D vector that is nlocs long.
31  * Variables can contain missing values.
32  *
33  * There are four dimensions defined in the file:
34  *
35  * nlocs: number of locations (length of each variable)
36  * nvars: number of variables
37  * nobs: number of observations (equal to nlocs * nvars)
38  * nrecs: number of records
39  *
40  * A record is an atomic unit that is to stay intact when distributing
41  * observations across multiple processes.
42  *
43  * Older netcdf files have either a single variable, or have multiple variables
44  * (satellite channels, eg) flattened out into a single variable. These
45  * vectors are nobs long. Locations will be repeated in the case of multiple
46  * variables so the ObsSpace constructor (client of this class) needs to
47  * reshape these vectors into a set of variables that correspond to the new
48  * file format above.
49  *
50  * For now, limit the write interface to writing 1D vectors that are nlocs
51  * in length. This may be too restrictive, so we should revisit this in the future.
52  *
53  * The constructor that you fill in a subclass is responsible for:
54  * 1. Open the file
55  * The file name and mode (read, write) is passed in to the subclass
56  * constructor via a call to the factory method Create in the class IodaIOfactory.
57  * 2. The following data members are set according to the file mode
58  * * nlocs_
59  * * nobs_
60  * * nrecs_
61  * * nvars_
62  *
63  * If in read mode, metadata from the input file are used to set the data members
64  * If in write mode, the data members are set from the constructor arguments
65  *
66  * \author Stephen Herbener (JCSDA)
67  */
68 
69 class IodaIO : public util::Printable {
70  public:
71  virtual ~IodaIO() = 0;
72 
73  // Methods provided by subclasses
74  virtual void ReadVar(const std::string & VarName, int* VarData) = 0;
75  virtual void ReadVar(const std::string & VarName, float* VarData) = 0;
76  virtual void ReadVar(const std::string & VarName, double* VarData) = 0;
77 
78  virtual void WriteVar(const std::string & VarName, int* VarData) = 0;
79  virtual void WriteVar(const std::string & VarName, float* VarData) = 0;
80  virtual void WriteVar(const std::string & VarName, double* VarData) = 0;
81 
82  virtual void ReadDateTime(int* VarDate, int* VarTime)= 0;
83 
84  // Methods inherited from base class
85  std::string fname() const;
86  std::string fmode() const;
87 
88  std::size_t nlocs();
89  std::size_t nobs();
90  std::size_t nrecs();
91  std::size_t nvars();
92 
93  protected:
94  // Methods provided by subclasses
95 
96  // Methods inherited from base class
97 
98  // Data members
99 
100  /*! \brief file name */
101  std::string fname_;
102 
103  /*! \brief file mode ("r" -> read, "w" -> overwrite, "W" -> create and write) */
104  std::string fmode_;
105 
106  /*! \brief number of unique locations */
107  std::size_t nlocs_;
108 
109  /*! \brief number of unique observations */
110  std::size_t nobs_;
111 
112  /*! \brief number of unique records */
113  std::size_t nrecs_;
114 
115  /*! \brief number of unique variables */
116  std::size_t nvars_;
117 };
118 
119 } // namespace ioda
120 
121 #endif // FILEIO_IODAIO_H_
std::size_t nobs_
number of unique observations
virtual ~IodaIO()=0
Definition: IodaIO.cc:17
std::string fname() const
Definition: IodaIO.cc:24
virtual void ReadVar(const std::string &VarName, int *VarData)=0
std::size_t nlocs_
number of unique locations
std::size_t nobs()
Definition: IodaIO.cc:51
std::string fname_
file name
File access class for IODA.
virtual void WriteVar(const std::string &VarName, int *VarData)=0
std::string fmode() const
Definition: IodaIO.cc:33
std::size_t nvars()
Definition: IodaIO.cc:72
std::size_t nrecs()
Definition: IodaIO.cc:63
virtual void ReadDateTime(int *VarDate, int *VarTime)=0
std::string fmode_
file mode ("r" -> read, "w" -> overwrite, "W" -> create and write)
std::size_t nlocs()
Definition: IodaIO.cc:42
std::size_t nrecs_
number of unique records
std::size_t nvars_
number of unique variables