VAPOR3 3.9.4
DCMPAS.h
Go to the documentation of this file.
1#include <vector>
2#include <algorithm>
3#include <map>
4#include <iostream>
5#include <vapor/MyBase.h>
7#include <vapor/DerivedVar.h>
10#include <vapor/utils.h>
11#include <vapor/DC.h>
12
13#ifndef _DCMPAS_H_
14 #define _DCMPAS_H_
15
16namespace VAPoR {
17
18class DerivedCoordVar_WRFTime;
19
31class VDF_API DCMPAS : public VAPoR::DC {
32public:
37 virtual ~DCMPAS();
38
39protected:
55 //
56 virtual int initialize(const vector<string> &paths, const std::vector<string> &options);
57
60 virtual bool getDimension(string dimname, DC::Dimension &dimension) const;
61
64 virtual std::vector<string> getDimensionNames() const;
65
68 std::vector<string> getMeshNames() const;
69
72 virtual bool getMesh(string mesh_name, DC::Mesh &mesh) const;
73
76 virtual bool getCoordVarInfo(string varname, DC::CoordVar &cvar) const;
77
80 virtual bool getDataVarInfo(string varname, DC::DataVar &datavar) const;
81
83 //
84 virtual bool getAuxVarInfo(string varname, DC::AuxVar &var) const;
85
87 //
88 virtual bool getBaseVarInfo(string varname, DC::BaseVar &var) const;
89
92 virtual std::vector<string> getDataVarNames() const;
93
96 virtual std::vector<string> getCoordVarNames() const;
97
98 virtual std::vector<string> getAuxVarNames() const;
99
102 virtual size_t getNumRefLevels(string varname) const { return (1); }
103
106 virtual string getMapProjection() const { return ("+proj=eqc +ellps=WGS84 +lon_0=0.0 +lat_0=0.0"); }
107
110 virtual bool getAtt(string varname, string attname, vector<double> &values) const;
111 virtual bool getAtt(string varname, string attname, vector<long> &values) const;
112 virtual bool getAtt(string varname, string attname, string &values) const;
113
116 virtual std::vector<string> getAttNames(string varname) const;
117
120 virtual XType getAttType(string varname, string attname) const;
121
124 virtual int getDimLensAtLevel(string varname, int level, std::vector<size_t> &dims_at_level, std::vector<size_t> &bs_at_level) const;
125
126 virtual int openVariableRead(size_t ts, string varname, int, int);
127
130 virtual int closeVariable(int fd);
131
133 //
134 virtual int readRegion(int fd, const vector<size_t> &min, const vector<size_t> &max, float *region) { return (_readRegionTemplate(fd, min, max, region)); }
135 virtual int readRegion(int fd, const vector<size_t> &min, const vector<size_t> &max, double *region) { return (_readRegionTemplate(fd, min, max, region)); }
136 virtual int readRegion(int fd, const vector<size_t> &min, const vector<size_t> &max, int *region) { return (_readRegionTemplate(fd, min, max, region)); }
137
140 virtual bool variableExists(size_t ts, string varname, int reflevel = 0, int lod = 0) const;
141
142private:
143 NetCDFCollection *_ncdfc;
144 VAPoR::UDUnits _udunits;
145 DerivedVarMgr _dvm;
146 bool _hasVertical; // has 3D data (i.e. vertical data)
147
148 class MPASFileObject : public DC::FileTable::FileObject {
149 public:
150 MPASFileObject(size_t ts, string varname, int level, int lod, int fd, bool derivedFlag) : FileObject(ts, varname, level, lod, fd), _derivedFlag(derivedFlag) {}
151
152 bool GetDerivedFlag() const { return (_derivedFlag); }
153
154 private:
155 bool _derivedFlag;
156 };
157
158 std::map<string, DC::Dimension> _dimsMap;
159 std::map<string, DC::CoordVar> _coordVarsMap;
160 std::map<string, DC::Mesh> _meshMap;
161 std::map<string, DC::DataVar> _dataVarsMap;
162 std::map<string, DC::AuxVar> _auxVarsMap;
163 std::vector<string> _cellVars;
164 std::vector<string> _pointVars;
165 std::vector<string> _edgeVars;
166 Wasp::SmartBuf _nEdgesOnCellBuf;
167 Wasp::SmartBuf _lonCellSmartBuf;
168 Wasp::SmartBuf _lonVertexSmartBuf;
169
170 int _InitDerivedVars(NetCDFCollection *ncdfc);
171 int _InitCoordvars(NetCDFCollection *ncdfc);
172
173 int _InitVerticalCoordinatesDerivedAtmosphere(NetCDFCollection *ncdfc);
174 int _InitVerticalCoordinatesDerivedOcean(NetCDFCollection *ncdfc);
175
176 int _CheckRequiredFields(NetCDFCollection *ncdfc) const;
177 bool _HasVertical(NetCDFCollection *ncdfc) const;
178
179 int _InitDimensions(NetCDFCollection *ncdfc);
180
181 int _GetVarCoordinates(NetCDFCollection *ncdfc, string varname, vector<string> &sdimnames, vector<string> &scoordvars, string &time_dim_name, string &time_coordvar);
182
183 int _InitMeshes(NetCDFCollection *ncdfc);
184 int _InitAuxVars(NetCDFCollection *ncdfc);
185 int _InitDataVars(NetCDFCollection *ncdfc);
186
187 vector<string> _GetSpatialDimNames(NetCDFCollection *ncdfc, string varname) const;
188
189 bool _isAtmosphere(NetCDFCollection *ncdfc) const;
190 bool _isOcean(NetCDFCollection *ncdfc) const;
191
192 bool _isCoordVar(string varname) const;
193 bool _isDataVar(string varname) const;
194
195 int _read_nEdgesOnCell(size_t ts);
196 void _addMissingFlag(int *data) const;
197 int _readVarToSmartBuf(size_t ts, string varname, Wasp::SmartBuf &smartBuf);
198 int _readCoordinates(size_t ts);
199
200 void _splitOnBoundary(string varname, int *connData) const;
201
202 int _readRegionTransposed(MPASFileObject *w, const vector<size_t> &min, const vector<size_t> &max, float *region);
203
204 int _readRegionEdgeVariable(MPASFileObject *w, const vector<size_t> &min, const vector<size_t> &max, float *region);
205
206 template<class T> int _readRegionTemplate(int fd, const vector<size_t> &min, const vector<size_t> &max, T *region);
207
208 template<class T> bool _getAttTemplate(string varname, string attname, T &values) const;
209
210 // Derive vertical coordinate variable for dual mesh from primary mesh
211 //
212 class DerivedCoordVertFromCell : public DerivedCoordVar {
213 public:
214 DerivedCoordVertFromCell(string derivedVarName, string derivedDimName, DC *dc, string inName, string cellsOnVertexName);
215
216 int Initialize();
217
218 bool GetBaseVarInfo(DC::BaseVar &var) const;
219
220 bool GetCoordVarInfo(DC::CoordVar &cvar) const;
221
222 virtual std::vector<string> GetInputs() const { return (std::vector<string>{_inName}); }
223
224 int GetDimLensAtLevel(int, std::vector<size_t> &dims_at_level, std::vector<size_t> &bs_at_level) const;
225
226 int OpenVariableRead(size_t ts, int, int);
227
228 int CloseVariable(int fd);
229
230 int ReadRegion(int fd, const vector<size_t> &min, const vector<size_t> &max, float *region);
231
232 bool VariableExists(size_t ts, int, int) const;
233
234 private:
235 string _derivedDimName;
236 DC * _dc;
237 string _inName;
238 string _cellsOnVertexName;
239 DC::CoordVar _coordVarInfo;
240
241 float *_getCellData();
242
243 int *_getCellsOnVertex(size_t i0, size_t i1, int &vertexDegree);
244 };
245
246 // Derive Uzonal and Umeridional data variable
247 //
248 class DerivedZonalMeridonal : public DerivedDataVar {
249 public:
250 DerivedZonalMeridonal(string derivedVarName, DC *dc, NetCDFCollection *ncdfc, string normalVarName, string tangentialVarName, bool zonalFlag);
251
252 int Initialize();
253
254 bool GetBaseVarInfo(DC::BaseVar &var) const;
255
256 bool GetDataVarInfo(DC::DataVar &cvar) const;
257
258 virtual std::vector<string> GetInputs() const { return (std::vector<string>{_normalVarName, _tangentialVarName}); }
259
260 int GetDimLensAtLevel(int, std::vector<size_t> &dims_at_level, std::vector<size_t> &bs_at_level) const;
261
262 int OpenVariableRead(size_t ts, int, int);
263
264 int CloseVariable(int fd);
265
266 int ReadRegion(int fd, const vector<size_t> &min, const vector<size_t> &max, float *region);
267
268 bool VariableExists(size_t ts, int, int) const;
269
270 private:
271 DC * _dc;
272 NetCDFCollection *_ncdfc;
273 string _normalVarName;
274 string _tangentialVarName;
275 bool _zonalFlag;
276 DC::DataVar _dataVarInfo;
277 };
278};
279}; // namespace VAPoR
280
281#endif
Class for reading a NetCDF Climate Forecast (MPAS) data set stored as a series of NetCDF files.
Definition: DCMPAS.h:31
virtual std::vector< string > getDimensionNames() const
virtual bool getDataVarInfo(string varname, DC::DataVar &datavar) const
virtual string getMapProjection() const
Definition: DCMPAS.h:106
std::vector< string > getMeshNames() const
virtual bool getAtt(string varname, string attname, vector< double > &values) const
virtual std::vector< string > getDataVarNames() const
virtual int closeVariable(int fd)
virtual ~DCMPAS()
virtual int readRegion(int fd, const vector< size_t > &min, const vector< size_t > &max, float *region)
Definition: DCMPAS.h:134
virtual std::vector< string > getAttNames(string varname) const
virtual bool getAtt(string varname, string attname, vector< long > &values) const
virtual bool getAuxVarInfo(string varname, DC::AuxVar &var) const
virtual bool variableExists(size_t ts, string varname, int reflevel=0, int lod=0) const
virtual bool getAtt(string varname, string attname, string &values) const
virtual bool getDimension(string dimname, DC::Dimension &dimension) const
virtual int getDimLensAtLevel(string varname, int level, std::vector< size_t > &dims_at_level, std::vector< size_t > &bs_at_level) const
virtual size_t getNumRefLevels(string varname) const
Definition: DCMPAS.h:102
virtual XType getAttType(string varname, string attname) const
virtual std::vector< string > getCoordVarNames() const
virtual int initialize(const vector< string > &paths, const std::vector< string > &options)
virtual int readRegion(int fd, const vector< size_t > &min, const vector< size_t > &max, int *region)
Definition: DCMPAS.h:136
virtual bool getMesh(string mesh_name, DC::Mesh &mesh) const
virtual std::vector< string > getAuxVarNames() const
virtual int openVariableRead(size_t ts, string varname, int, int)
virtual int readRegion(int fd, const vector< size_t > &min, const vector< size_t > &max, double *region)
Definition: DCMPAS.h:135
virtual bool getBaseVarInfo(string varname, DC::BaseVar &var) const
virtual bool getCoordVarInfo(string varname, DC::CoordVar &cvar) const
Auxiliary variable metadata.
Definition: DC.h:1230
Base class for storing variable metadata.
Definition: DC.h:754
Coordinate variable metadata.
Definition: DC.h:881
Data variable metadata.
Definition: DC.h:987
Metadata describing a named dimension length.
Definition: DC.h:163
Metadata describing a computational mesh.
Definition: DC.h:310
A Template Method design pattern for reading a collection of data.
Definition: DC.h:150
XType
External storage types for primitive data.
Definition: DC.h:154
Derived variables constructed from other variables.
Definition: DerivedVarMgr.h:20
Wrapper for a collection of netCDF files.
#define VDF_API
Definition: common.h:73
RENDER_API int Initialize(int *argc, char **argv)