FV3 Bundle
NetcdfIO.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_NETCDFIO_H_
9 #define FILEIO_NETCDFIO_H_
10 
11 
12 #include <string>
13 
14 #include "fileio/IodaIO.h"
15 #include "oops/util/ObjectCounter.h"
16 
17 
18 ////////////////////////////////////////////////////////////////////////
19 // Implementation of IodaIO for netcdf.
20 ////////////////////////////////////////////////////////////////////////
21 
22 // Forward declarations
23 namespace eckit {
24  class Configuration;
25 }
26 
27 namespace ioda {
28 
29 /*! \brief Implementation of IodaIO for netcdf.
30  *
31  * \details The NetcdfIO class defines the constructor and methods for
32  * the abstract class IodaIO.
33  *
34  * \author Stephen Herbener (JCSDA)
35  */
36 class NetcdfIO : public IodaIO,
37  private util::ObjectCounter<NetcdfIO> {
38  public:
39  /*!
40  * \brief classname method for object counter
41  *
42  * \details This method is supplied for the ObjectCounter base class.
43  * It defines a name to identify an object of this class
44  * for reporting by OOPS.
45  */
46  static const std::string classname() {return "ioda::NetcdfIO";}
47 
48  NetcdfIO(const std::string & FileName, const std::string & FileMode,
49  const std::size_t & Nlocs, const std::size_t & Nobs,
50  const std::size_t & Nrecs, const std::size_t & Nvars);
51  ~NetcdfIO();
52 
53  void ReadVar(const std::string & VarName, int* VarData);
54  void ReadVar(const std::string & VarName, float* VarData);
55  void ReadVar(const std::string & VarName, double* VarData);
56 
57  void WriteVar(const std::string & VarName, int* VarData);
58  void WriteVar(const std::string & VarName, float* VarData);
59  void WriteVar(const std::string & VarName, double* VarData);
60 
61  void ReadDateTime(int* VarDate, int* VarTime);
62 
63  private:
64  // For the oops::Printable base class
65  void print(std::ostream & os) const;
66 
67  void CheckNcCall(int, std::string &);
68 
69  // Data members
70  /*!
71  * \brief netcdf file id
72  *
73  * \details This data member holds the file id of the open netcdf file.
74  * It gives access to the dimensions, attributes and variables in
75  * the netcdf file.
76  */
77  int ncid_;
78 
79  /*!
80  * \brief This data member holds the netcdf id of the "nlocs" dimension
81  * in the opened netcdf file.
82  */
83  int nlocs_id_;
84 
85  /*!
86  * \brief This data member holds the netcdf id of the "nvars" dimension
87  * in the opened netcdf file.
88  */
89  int nvars_id_;
90 
91  /*!
92  * \brief This data member holds the netcdf id of the "nobs" dimension
93  * in the opened netcdf file.
94  */
95  int nobs_id_;
96 
97  /*!
98  * \brief This data member holds the netcdf id of the "nrecs" dimension
99  * in the opened netcdf file.
100  */
102 
103  /*!
104  * \brief This data member holds the netcdf id of the "nchans" dimension
105  * in the opened netcdf file.
106  */
108 
109  /*!
110  * \brief This data member holds the netcdf id of the current dataset (variable)
111  * in the opened netcdf file.
112  */
114 
115  /*!
116  * \brief This data member is a flag that indicates the existence of the
117  * "nlocs" dimension in the opened netcdf file.
118  */
120 
121  /*!
122  * \brief This data member is a flag that indicates the existence of the
123  * "nvars" dimension in the opened netcdf file.
124  */
126 
127  /*!
128  * \brief This data member is a flag that indicates the existence of the
129  * "nobs" dimension in the opened netcdf file.
130  */
132 
133  /*!
134  * \brief This data member is a flag that indicates the existence of the
135  * "nrecs" dimension in the opened netcdf file.
136  */
138 
139  /*!
140  * \brief This data member is a flag that indicates the existence of the
141  * "nchans" dimension in the opened netcdf file.
142  */
144 
145  /*!
146  * \brief This data member holds the netcdf id of the current attribute
147  * in the opened netcdf file.
148  */
150 };
151 
152 } // namespace ioda
153 
154 #endif // FILEIO_NETCDFIO_H_
void print(std::ostream &os) const
print method for stream output
Definition: NetcdfIO.cc:360
bool have_nlocs_
This data member is a flag that indicates the existence of the "nlocs" dimension in the opened netcdf...
Definition: NetcdfIO.h:119
bool have_nrecs_
This data member is a flag that indicates the existence of the "nrecs" dimension in the opened netcdf...
Definition: NetcdfIO.h:137
File access class for IODA.
int nobs_id_
This data member holds the netcdf id of the "nobs" dimension in the opened netcdf file...
Definition: NetcdfIO.h:95
Implementation of IodaIO for netcdf.
Definition: NetcdfIO.h:36
void ReadDateTime(int *VarDate, int *VarTime)
Read and format the date, time values.
Definition: NetcdfIO.cc:296
static const std::string classname()
classname method for object counter
Definition: NetcdfIO.h:46
int nvars_id_
This data member holds the netcdf id of the "nvars" dimension in the opened netcdf file...
Definition: NetcdfIO.h:89
int nlocs_id_
This data member holds the netcdf id of the "nlocs" dimension in the opened netcdf file...
Definition: NetcdfIO.h:83
bool have_nobs_
This data member is a flag that indicates the existence of the "nobs" dimension in the opened netcdf ...
Definition: NetcdfIO.h:131
int nc_varid_
This data member holds the netcdf id of the current dataset (variable) in the opened netcdf file...
Definition: NetcdfIO.h:113
void CheckNcCall(int, std::string &)
check results of netcdf call
Definition: NetcdfIO.cc:378
int ncid_
netcdf file id
Definition: NetcdfIO.h:77
bool have_nchans_
This data member is a flag that indicates the existence of the "nchans" dimension in the opened netcd...
Definition: NetcdfIO.h:143
int nc_attid_
This data member holds the netcdf id of the current attribute in the opened netcdf file...
Definition: NetcdfIO.h:149
bool have_nvars_
This data member is a flag that indicates the existence of the "nvars" dimension in the opened netcdf...
Definition: NetcdfIO.h:125
void ReadVar(const std::string &VarName, int *VarData)
Read data from netcdf file to memory.
Definition: NetcdfIO.cc:169
int nrecs_id_
This data member holds the netcdf id of the "nrecs" dimension in the opened netcdf file...
Definition: NetcdfIO.h:101
void WriteVar(const std::string &VarName, int *VarData)
Write data from memory to netcdf file.
Definition: NetcdfIO.cc:223
int nchans_id_
This data member holds the netcdf id of the "nchans" dimension in the opened netcdf file...
Definition: NetcdfIO.h:107
NetcdfIO(const std::string &FileName, const std::string &FileMode, const std::size_t &Nlocs, const std::size_t &Nobs, const std::size_t &Nrecs, const std::size_t &Nvars)
Definition: NetcdfIO.cc:47