VAPOR3 3.9.4
NetCDFCpp.h
Go to the documentation of this file.
1#include <vector>
2#include <map>
3#include <iostream>
4#include <netcdf.h>
5#include <vapor/utils.h>
6#include <vapor/MyBase.h>
7
8#ifndef _NetCDFCpp_H_
9 #define _NetCDFCpp_H_
10
11namespace VAPoR {
12
43//
45public:
47 virtual ~NetCDFCpp();
48
54 //
55 virtual int Create(string path, int cmode, size_t initialsz, size_t &bufrsizehintp);
56
61 //
62 virtual int Open(string path, int mode);
63
65 virtual int DefDim(string name, size_t len) const;
66
68 virtual int DefVar(string name, int xtype, vector<string> dimnames);
69
71 virtual int InqVarDims(string name, vector<string> &dimnames, vector<size_t> &dims) const;
72
74 //
75 virtual int InqDims(vector<string> &dimnames, vector<size_t> &dims) const;
76
78 virtual int InqDimlen(string name, size_t &len) const;
79
81 //
82 int InqAttnames(string varname, std::vector<string> &attnames) const;
83
95 int CopyAtt(string varname_in, string attname, NetCDFCpp &ncdf_out, string varname_out) const;
96
97 //
98 // PutAtt - Integer
99 //
100
102 virtual int PutAtt(string varname, string attname, int value) const;
103 virtual int PutAtt(string varname, string attname, vector<int> values) const;
104 virtual int PutAtt(string varname, string attname, const int values[], size_t n) const;
105
106 //
107 // GetAtt - Integer
108 //
109
111 virtual int GetAtt(string varname, string attname, int &value) const;
112 virtual int GetAtt(string varname, string attname, vector<int> &values) const;
113 virtual int GetAtt(string varname, string attname, int values[], size_t n) const;
114
115 //
116 // PutAtt - size_t
117 //
118 virtual int PutAtt(string varname, string attname, size_t value) const;
119 virtual int PutAtt(string varname, string attname, vector<size_t> values) const;
120 virtual int PutAtt(string varname, string attname, const size_t values[], size_t n) const;
121
122 //
123 // GetAtt - size_t
124 //
125 virtual int GetAtt(string varname, string attname, size_t &value) const;
126 virtual int GetAtt(string varname, string attname, vector<size_t> &values) const;
127 virtual int GetAtt(string varname, string attname, size_t values[], size_t n) const;
128
129 //
130 // PutAtt - Float
131 //
132 virtual int PutAtt(string varname, string attname, float value) const;
133 virtual int PutAtt(string varname, string attname, vector<float> values) const;
134 virtual int PutAtt(string varname, string attname, const float values[], size_t n) const;
135
136 //
137 // GetAtt - Float
138 //
139 virtual int GetAtt(string varname, string attname, float &value) const;
140 virtual int GetAtt(string varname, string attname, vector<float> &values) const;
141 virtual int GetAtt(string varname, string attname, float values[], size_t n) const;
142
143 //
144 // PutAtt - Double
145 //
146 virtual int PutAtt(string varname, string attname, double value) const;
147 virtual int PutAtt(string varname, string attname, vector<double> values) const;
148 virtual int PutAtt(string varname, string attname, const double values[], size_t n) const;
149
150 //
151 // GetAtt - Double
152 //
153 virtual int GetAtt(string varname, string attname, double &value) const;
154 virtual int GetAtt(string varname, string attname, vector<double> &values) const;
155 virtual int GetAtt(string varname, string attname, double values[], size_t n) const;
156
157 //
158 // PutAtt - String
159 //
160 virtual int PutAtt(string varname, string attname, string value) const;
161 virtual int PutAtt(string varname, string attname, vector<string> values) const;
162 virtual int PutAtt(string varname, string attname, const char values[], size_t n) const;
163
164 //
165 // GetAtt - String
166 //
167 virtual int GetAtt(string varname, string attname, string &value) const;
168 virtual int GetAtt(string varname, string attname, char values[], size_t n) const;
169
177 //
178 virtual int GetAtt(string varname, string attname, vector<string> &values) const;
179
181 virtual int InqVarid(string varname, int &varid) const;
182
184 virtual int InqAtt(string varname, string attname, nc_type &xtype, size_t &len) const;
185
187 //
188 virtual int InqVartype(string varname, nc_type &xtype) const;
189
191 virtual int SetFill(int fillmode, int &old_modep);
192
194 virtual int EndDef() const;
195
197 virtual int ReDef() const;
198
200 virtual int Close();
201
203 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const void *data);
204 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const float *data);
205 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const double *data);
206 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const int *data);
207 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const long *data);
208 virtual int PutVara(string varname, vector<size_t> start, vector<size_t> count, const unsigned char *data);
209
211 virtual int PutVar(string varname, const void *data);
212 virtual int PutVar(string varname, const float *data);
213 virtual int PutVar(string varname, const double *data);
214 virtual int PutVar(string varname, const int *data);
215 virtual int PutVar(string varname, const long *data);
216 virtual int PutVar(string varname, const unsigned char *data);
217
219 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, void *data) const;
220 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, float *data) const;
221 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, double *data) const;
222 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, int *data) const;
223 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, long *data) const;
224 virtual int GetVara(string varname, vector<size_t> start, vector<size_t> count, unsigned char *data) const;
225
227 virtual int GetVar(string varname, void *data) const;
228 virtual int GetVar(string varname, float *data) const;
229 virtual int GetVar(string varname, double *data) const;
230 virtual int GetVar(string varname, int *data) const;
231 virtual int GetVar(string varname, long *data) const;
232 virtual int GetVar(string varname, unsigned char *data) const;
233
235 //
236 virtual int CopyVar(string varname, NetCDFCpp &ncdf_out) const;
237
240 static size_t SizeOf(int nctype);
241
247 virtual bool ValidFile(string path);
248
252 //
253 virtual bool InqDimDefined(string dimname);
254
258 //
259 virtual bool InqAttDefined(string varname, string attname);
260
265 //
266 virtual int InqVarnames(vector<string> &varnames) const;
267
270 int GetNCID() const { return (_ncid); }
271
272private:
273 int _ncid;
274 string _path;
275
276 int _PutVara(string varname, vector<size_t> start, vector<size_t> count, const void *data, string func);
277 int _PutVar(string varname, const void *data, string func);
278
279 int _GetVara(string varname, vector<size_t> start, vector<size_t> count, void *data, string func) const;
280 int _GetVar(string varname, void *data, string func) const;
281};
282
283} // namespace VAPoR
284
285#endif // _NetCDFCpp_H_
Defines simple C++ wrapper for NetCDF.
Definition: NetCDFCpp.h:44
virtual int GetAtt(string varname, string attname, vector< int > &values) const
int InqAttnames(string varname, std::vector< string > &attnames) const
Learn the names of all the global or variable attributes.
virtual int PutVar(string varname, const unsigned char *data)
virtual int PutAtt(string varname, string attname, vector< int > values) const
virtual int PutAtt(string varname, string attname, const char values[], size_t n) const
virtual int GetAtt(string varname, string attname, vector< double > &values) const
virtual int InqVartype(string varname, nc_type &xtype) const
Find a variable's external representation type.
virtual int PutVar(string varname, const long *data)
virtual bool InqDimDefined(string dimname)
virtual int GetVar(string varname, unsigned char *data) const
virtual int Close()
Close the currently opened file.
virtual int PutAtt(string varname, string attname, vector< string > values) const
virtual int GetAtt(string varname, string attname, double values[], size_t n) const
virtual int InqVarnames(vector< string > &varnames) const
virtual int GetAtt(string varname, string attname, vector< string > &values) const
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, float *data) const
virtual int EndDef() const
End the metadata definition section.
int GetNCID() const
Definition: NetCDFCpp.h:270
virtual int PutAtt(string varname, string attname, string value) const
virtual int PutAtt(string varname, string attname, float value) const
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const float *data)
virtual int GetVar(string varname, double *data) const
virtual int SetFill(int fillmode, int &old_modep)
Set the fill value.
virtual int GetAtt(string varname, string attname, vector< size_t > &values) const
virtual int GetAtt(string varname, string attname, size_t values[], size_t n) const
virtual ~NetCDFCpp()
virtual int InqVarDims(string name, vector< string > &dimnames, vector< size_t > &dims) const
Learn the dimension names associated with a variable.
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const int *data)
virtual int InqAtt(string varname, string attname, nc_type &xtype, size_t &len) const
Return information about a NetCDF attribute.
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, int *data) const
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const unsigned char *data)
virtual int PutAtt(string varname, string attname, vector< float > values) const
virtual int GetVar(string varname, float *data) const
virtual int PutAtt(string varname, string attname, const double values[], size_t n) const
virtual int GetVar(string varname, long *data) const
virtual int GetVar(string varname, void *data) const
Read an entire variable with one function call.
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const void *data)
Write an array of values to a variable.
virtual bool ValidFile(string path)
virtual int GetAtt(string varname, string attname, char values[], size_t n) const
virtual int GetAtt(string varname, string attname, double &value) const
virtual int GetAtt(string varname, string attname, float values[], size_t n) const
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, unsigned char *data) const
virtual int PutAtt(string varname, string attname, const size_t values[], size_t n) const
virtual int GetVar(string varname, int *data) const
int CopyAtt(string varname_in, string attname, NetCDFCpp &ncdf_out, string varname_out) const
virtual int Create(string path, int cmode, size_t initialsz, size_t &bufrsizehintp)
static size_t SizeOf(int nctype)
virtual int InqVarid(string varname, int &varid) const
Find the NetCDF ID of a variable.
virtual int CopyVar(string varname, NetCDFCpp &ncdf_out) const
Copy a variable from one file to another.
virtual int InqDimlen(string name, size_t &len) const
Learn the length of a named dimension.
virtual int Open(string path, int mode)
virtual int PutVar(string varname, const int *data)
virtual int GetAtt(string varname, string attname, int &value) const
Read an integer attribute.
virtual int GetAtt(string varname, string attname, float &value) const
virtual int DefDim(string name, size_t len) const
Define a dimension.
virtual int DefVar(string name, int xtype, vector< string > dimnames)
Define a variable.
virtual int PutAtt(string varname, string attname, vector< size_t > values) const
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, double *data) const
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const double *data)
virtual int PutVar(string varname, const double *data)
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, void *data) const
Read an array of values from a variable.
virtual bool InqAttDefined(string varname, string attname)
virtual int ReDef() const
Put open netcdf dataset into define mode.
virtual int InqDims(vector< string > &dimnames, vector< size_t > &dims) const
Learn the dimension names and lengths defined in a file.
virtual int PutAtt(string varname, string attname, int value) const
Write an integer attribute.
virtual int PutAtt(string varname, string attname, const int values[], size_t n) const
virtual int PutAtt(string varname, string attname, vector< double > values) const
virtual int GetVara(string varname, vector< size_t > start, vector< size_t > count, long *data) const
virtual int PutVara(string varname, vector< size_t > start, vector< size_t > count, const long *data)
virtual int GetAtt(string varname, string attname, int values[], size_t n) const
virtual int PutAtt(string varname, string attname, size_t value) const
virtual int PutVar(string varname, const void *data)
Write an entire variable with one function call.
virtual int GetAtt(string varname, string attname, vector< float > &values) const
virtual int GetAtt(string varname, string attname, string &value) const
virtual int PutAtt(string varname, string attname, double value) const
virtual int PutAtt(string varname, string attname, const float values[], size_t n) const
virtual int PutVar(string varname, const float *data)
virtual int GetAtt(string varname, string attname, size_t &value) const
Wasp base class.
Definition: MyBase.h:67
#define WASP_API
Definition: common.h:74