LRAUV  revA
NetCdf.h
Go to the documentation of this file.
1 
9 #ifndef NETCDF_H_
10 #define NETCDF_H_
11 
12 #define USE_NETCDF4
13 
14 #include "utils/FastMap.h"
15 #include "utils/FlexArray.h"
16 #include "utils/Str.h"
17 
18 #include <netcdf.h>
19 
20 class DataValue;
21 class Unit;
22 
23 // from official netcdf.h
24 #define NC_MAX_DIMS 1024 /* max dimensions per file */
25 #define NC_MAX_ATTRS 8192 /* max global or per variable attributes */
26 #define NC_MAX_VARS 8192 /* max variables per file */
27 #define NC_MAX_NAME 256 /* max length of a name */
28 #ifndef NC_MAX_VAR_DIMS
29 #define NC_MAX_VAR_DIMS NC_MAX_DIMS /* max per variable dimensions */
30 #endif
31 
32 #define NC_MAX_ATTR_SIZE 8192 /* max size of an attribute */
33 #define NC_MAX_STRING_SIZE 8192 /* max size of a string */
34 
40 class NetCdf
41 {
42 public:
43 
44  typedef enum
45  {
47  NC_BYTE_TYPE = NC_BYTE, // data is array of 8 bit signed integer
48  NC_CHAR_TYPE = NC_CHAR, // data is array of characters, i.e., text
49  NC_SHORT_TYPE = NC_SHORT, // data is array of 16 bit signed integer
50  NC_INT_TYPE = NC_INT, // data is array of 32 bit signed integer
51  NC_FLOAT_TYPE = NC_FLOAT, // data is array of IEEE single precision float
52  NC_DOUBLE_TYPE = NC_DOUBLE, // data is array of IEEE double precision float
53  NC_UBYTE_TYPE = NC_UBYTE, // Netcdf-4 only, unsigned 1 byte int
54  NC_USHORT_TYPE = NC_USHORT, // Netcdf-4 only, unsigned 2-byte int
55  NC_UINT_TYPE = NC_UINT, // Netcdf-4 only, unsigned 4-byte int
56  NC_INT64_TYPE = NC_INT64, // Netcdf-4 only, signed 8-byte int
57  NC_UINT64_TYPE = NC_UINT64 , // Netcdf-4 only, unsigned 8-byte int
58  NC_STRING_TYPE = NC_STRING, // Netcdf-4 only, string type.
59  } NetCdfType;
60 
61  // lookup table that indicates #of bytes for each NetCdfType
62  static unsigned int NetCdfTypeSize_[NC_DOUBLE_TYPE + 1];
63 
64  typedef struct
65  {
66  int dimId_;
67  unsigned int dimSize_;
68  } NetCdfDim;
69 
72 
73  typedef struct
74  {
75  int attId_;
76  int varId_; // Can be NC_GLOBAL
79  unsigned int nelems_;
80  } NetCdfAtt;
81 
83 
84  struct NetCdfVar
85  {
86  int varId_;
87  int nDims_;
88  int* dimIds_;
89  NetCdfAtts atts_;
90  bool isRecord_;
92  unsigned int varIndex_;
94  size_t numRecs_;
95  int ncId_;
96  NetCdfVar();
97  ~NetCdfVar();
98  };
99 
102 
104  virtual ~NetCdf();
105 
107  const NetCdfDimArray& getDimArray()
108  {
109  return dimArray_;
110  }
111 
113  const NetCdfAtts& getGlobalAtts()
114  {
115  return gatts_;
116  }
117 
119  const NetCdfVars& getVars()
120  {
121  return vars_;
122  }
123 
126  NetCdfDim* findDim( const Str& name );
127 
129 
131  NetCdfAtt* findAtt( const Str& name );
132 
135  NetCdfVar* findVar( const Str& name );
136 
139  NetCdfAtt* findAtt( NetCdfVar& var, const Str& name );
140 
141  const char* status();
142 
143 protected:
144 
146  NetCdf();
147 
150  NetCdfDim* findDim( NetCdfDims& dims, const Str& name );
151 
154  NetCdfAtt* findAtt( NetCdfAtts& atts, const Str& name );
155 
158  NetCdfVar* findVar( NetCdfVars& vars, const Str& name );
159 
160  int status_; /* error status */
161  int ncId_; /* netCDF ID */
162  NetCdfDimArray dimArray_; /* dimensions */
163  NetCdfDims dims_; /* dimension id map */
164  NetCdfAtts gatts_; /* global attribute map */
165  NetCdfVarArray varArray_; /* variables */
166  NetCdfVars vars_; /* variable map */
167 
168 
169 };
170 
171 #endif /*NETCDF_H_*/
Definition: NetCdf.h:55
NetCdfVarArray varArray_
Definition: NetCdf.h:165
int status_
Definition: NetCdf.h:160
const NetCdfDimArray & getDimArray()
Returns the dimensions.
Definition: NetCdf.h:107
unsigned int nelems_
Definition: NetCdf.h:79
FlexArray< NetCdfDim * > NetCdfDimArray
Definition: NetCdf.h:71
~NetCdfVar()
Destructor.
Definition: NetCdf.cpp:29
Definition: NetCdf.h:46
Definition: NetCdf.h:57
FastMap< const Str, NetCdfDim * > NetCdfDims
Definition: NetCdf.h:70
Definition: NetCdf.h:47
NetCdfType netCdfType_
Definition: NetCdf.h:78
NetCdfAtts atts_
Definition: NetCdf.h:89
NetCdfVar()
Constructor.
Definition: NetCdf.cpp:16
Definition: NetCdf.h:49
NetCdfVar * findVar(const Str &name)
Finds a variable by name Returns NULL if error.
Definition: NetCdf.cpp:80
NetCdfType netCdfType_
Definition: NetCdf.h:91
FlexArray< NetCdfVar * > NetCdfVarArray
Definition: NetCdf.h:101
Definition: NetCdf.h:48
int varId_
Definition: NetCdf.h:76
int ncId_
Definition: NetCdf.h:161
bool isRecord_
Definition: NetCdf.h:90
const NetCdfVars & getVars()
Returns the variables.
Definition: NetCdf.h:119
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
Contains the FlexArrayBase and FlexArray class declarations.
Definition: NetCdf.h:73
virtual ~NetCdf()
Destructor.
Definition: NetCdf.cpp:47
size_t numRecs_
Definition: NetCdf.h:94
NetCdfType
Definition: NetCdf.h:44
Definition: NetCdf.h:54
const char * status()
Definition: NetCdf.cpp:92
NetCdfDims dims_
Definition: NetCdf.h:163
Replacement for standard template class string.
Definition: Str.h:12
Definition: NetCdf.h:50
NetCdfDim * findDim(const Str &name)
Finds a dimension by name Returns NULL if error.
Definition: NetCdf.cpp:66
int * dimIds_
Definition: NetCdf.h:88
int varId_
Definition: NetCdf.h:86
Contains the NetCdf class declaration.
int dimId_
Definition: NetCdf.h:66
FastMap< const Str, NetCdfAtt * > NetCdfAtts
Definition: NetCdf.h:82
Contains the FastMap class declaration.
Abstract base class for NetCcfReader and NetCdfWriter.
Definition: NetCdf.h:40
DataValue * dataValue_
Definition: NetCdf.h:93
int ncId_
Definition: NetCdf.h:95
const NetCdfAtts & getGlobalAtts()
Returns the global attributes.
Definition: NetCdf.h:113
Definition: NetCdf.h:53
static unsigned int NetCdfTypeSize_[NC_DOUBLE_TYPE+1]
Definition: NetCdf.h:62
FastMap< const Str, NetCdfVar * > NetCdfVars
Definition: NetCdf.h:100
Str name_
Definition: NetCdf.h:77
int attId_
Definition: NetCdf.h:75
unsigned int dimSize_
Definition: NetCdf.h:67
NetCdfDimArray dimArray_
Definition: NetCdf.h:162
int nDims_
Definition: NetCdf.h:87
Definition: NetCdf.h:52
Definition: NetCdf.h:56
Definition: NetCdf.h:51
NetCdfAtts gatts_
Definition: NetCdf.h:164
NetCdfAtt * findAtt(const Str &name)
Finds a global attribute by name NetCdfAtt* invalidValue_;.
Definition: NetCdf.cpp:73
Definition: NetCdf.h:64
Code that represents an engineering unit.
Definition: Unit.h:24
NetCdf()
Protected constructor.
Definition: NetCdf.cpp:98
Definition: NetCdf.h:84
Definition: NetCdf.h:58
unsigned int varIndex_
Definition: NetCdf.h:92
NetCdfVars vars_
Definition: NetCdf.h:166