VAPOR3 3.9.4
NetCDFSimple.h
Go to the documentation of this file.
1//
2// $Id$
3//
4
5#ifndef _NetCDFSimple_h_
6#define _NetCDFSimple_h_
7
8#include <vector>
9#include <map>
10
11#include <sstream>
12#include <vapor/MyBase.h>
13
14namespace VAPoR {
15
16//
32//
34public:
36 virtual ~NetCDFSimple();
37
42 //
43 class Variable {
44 public:
46
53 Variable(string varname, std::vector<string> dimnames, int type);
54
56 //
57 string GetName() const { return (_name); };
58
63 //
64 std::vector<string> GetAttNames() const;
65
70 std::vector<string> GetDimNames() const { return (_dimnames); };
71 void SetDimNames(const std::vector<string> dimnames) { _dimnames = dimnames; }
72
80 //
81 int GetAttType(string name) const;
82
85 int GetXType() const { return (_type); };
86
100 //
101 void GetAtt(string name, std::vector<double> &values) const;
102 void GetAtt(string name, std::vector<long> &values) const;
103 void GetAtt(string name, string &values) const;
104
109 //
110 void SetAtt(string name, const std::vector<double> &values) { _flt_atts.push_back(make_pair(name, values)); }
111 void SetAtt(string name, const std::vector<long> &values) { _int_atts.push_back(make_pair(name, values)); }
112 void SetAtt(string name, const string &values) { _str_atts.push_back(make_pair(name, values)); }
113
114 VDF_API friend std::ostream &operator<<(std::ostream &o, const Variable &var);
115 VDF_API friend bool operator==(const Variable &v1, const Variable &v2)
116 {
117 return ((v1._name == v2._name) && (v1._dimnames == v2._dimnames) && (v1._flt_atts == v2._flt_atts) && (v1._int_atts == v2._int_atts) && (v1._str_atts == v2._str_atts)
118 && (v1._type == v2._type));
119 }
120
121 private:
122 string _name; // variable name
123 std::vector<string> _dimnames; // order list of dimension names
124 std::vector<std::pair<string, std::vector<double>>> _flt_atts;
125 std::vector<std::pair<string, std::vector<long>>> _int_atts;
126 std::vector<std::pair<string, string>> _str_atts;
127 int _type; // netCDF variable type
128 };
129
139 virtual int Initialize(string path);
140
157 virtual int OpenRead(const NetCDFSimple::Variable &variable);
158
177 int Read(const size_t start[], const size_t count[], double *data, int fd = 0) const;
178 int Read(const size_t start[], const size_t count[], float *data, int fd = 0) const;
179 int Read(const size_t start[], const size_t count[], int *data, int fd = 0) const;
180 int Read(const size_t start[], const size_t count[], char *data, int fd = 0) const;
181
186 //
187 virtual int Close(int fd = 0);
188
196 const std::vector<NetCDFSimple::Variable> &GetVariables() const { return (_variables); };
197
209 void GetDimensions(std::vector<string> &names, std::vector<size_t> &dims) const;
210
221 //
222 string DimName(int id) const;
223
235 //
236 size_t DimLen(string name) const;
237
248 //
249 int DimId(string name) const;
250
259 //
260 std::vector<string> GetAttNames() const;
261
269 //
270 int GetAttType(string name) const;
271
285 //
286 void GetAtt(string name, std::vector<double> &values) const;
287 void GetAtt(string name, std::vector<long> &values) const;
288 void GetAtt(string name, string &values) const;
289
302 static bool IsNCTypeInt(int type);
303
314 static bool IsNCTypeFloat(int type);
315
326 static bool IsNCTypeText(int type);
327
328 VDF_API friend std::ostream &operator<<(std::ostream &o, const NetCDFSimple &nc);
329
330protected:
331 int _ncid;
332 std::map<int, int> _ovr_table; // open variable map: fd -> varid
333 string _path;
334 std::vector<string> _dimnames;
335 std::vector<size_t> _dims;
336 std::vector<string> _unlimited_dimnames;
337 std::vector<std::pair<string, std::vector<double>>> _flt_atts;
338 std::vector<std::pair<string, std::vector<long>>> _int_atts;
339 std::vector<std::pair<string, string>> _str_atts;
340 std::vector<NetCDFSimple::Variable> _variables;
341
342 int _GetAtts(int ncid, int varid, std::vector<std::pair<string, std::vector<double>>> &flt_atts, std::vector<std::pair<string, std::vector<long>>> &int_atts,
343 std::vector<std::pair<string, string>> &str_atts);
344};
345
346}; // namespace VAPoR
347#endif
NetCDFSimple API interface.
Definition: NetCDFSimple.h:43
void SetAtt(string name, const std::vector< double > &values)
Definition: NetCDFSimple.h:110
void SetAtt(string name, const string &values)
Definition: NetCDFSimple.h:112
int GetAttType(string name) const
void SetAtt(string name, const std::vector< long > &values)
Definition: NetCDFSimple.h:111
std::vector< string > GetDimNames() const
Definition: NetCDFSimple.h:70
void GetAtt(string name, string &values) const
string GetName() const
Return the variable's name.
Definition: NetCDFSimple.h:57
std::vector< string > GetAttNames() const
VDF_API friend bool operator==(const Variable &v1, const Variable &v2)
Definition: NetCDFSimple.h:115
void GetAtt(string name, std::vector< double > &values) const
void GetAtt(string name, std::vector< long > &values) const
void SetDimNames(const std::vector< string > dimnames)
Definition: NetCDFSimple.h:71
VDF_API friend std::ostream & operator<<(std::ostream &o, const Variable &var)
Variable(string varname, std::vector< string > dimnames, int type)
NetCDFSimple API interface.
Definition: NetCDFSimple.h:33
VDF_API friend std::ostream & operator<<(std::ostream &o, const NetCDFSimple &nc)
virtual ~NetCDFSimple()
string DimName(int id) const
std::vector< std::pair< string, std::vector< double > > > _flt_atts
Definition: NetCDFSimple.h:337
int Read(const size_t start[], const size_t count[], char *data, int fd=0) const
std::vector< string > GetAttNames() const
virtual int Initialize(string path)
int _GetAtts(int ncid, int varid, std::vector< std::pair< string, std::vector< double > > > &flt_atts, std::vector< std::pair< string, std::vector< long > > > &int_atts, std::vector< std::pair< string, string > > &str_atts)
int GetAttType(string name) const
std::vector< std::pair< string, string > > _str_atts
Definition: NetCDFSimple.h:339
void GetAtt(string name, string &values) const
size_t DimLen(string name) const
const std::vector< NetCDFSimple::Variable > & GetVariables() const
Definition: NetCDFSimple.h:196
std::vector< NetCDFSimple::Variable > _variables
Definition: NetCDFSimple.h:340
virtual int Close(int fd=0)
std::vector< string > _dimnames
Definition: NetCDFSimple.h:334
virtual int OpenRead(const NetCDFSimple::Variable &variable)
void GetDimensions(std::vector< string > &names, std::vector< size_t > &dims) const
void GetAtt(string name, std::vector< long > &values) const
static bool IsNCTypeInt(int type)
std::vector< size_t > _dims
Definition: NetCDFSimple.h:335
std::vector< string > _unlimited_dimnames
Definition: NetCDFSimple.h:336
int Read(const size_t start[], const size_t count[], float *data, int fd=0) const
static bool IsNCTypeText(int type)
static bool IsNCTypeFloat(int type)
std::vector< std::pair< string, std::vector< long > > > _int_atts
Definition: NetCDFSimple.h:338
int Read(const size_t start[], const size_t count[], int *data, int fd=0) const
std::map< int, int > _ovr_table
Definition: NetCDFSimple.h:332
int Read(const size_t start[], const size_t count[], double *data, int fd=0) const
void GetAtt(string name, std::vector< double > &values) const
int DimId(string name) const
Wasp base class.
Definition: MyBase.h:67
#define VDF_API
Definition: common.h:73