VAPoR  0.1
DataMgrMPAS.h
Go to the documentation of this file.
1 #ifndef MPASDataMg_h
2 #define MPASDataMg_h
3 
4 #include <list>
5 #include <map>
6 #include <string>
7 #include <vector>
8 #include <iostream>
9 #include <cstdlib>
10 #include <fstream>
11 #include <sstream>
12 #include <cmath>
13 #include <cfloat>
14 #include <algorithm>
15 #include <cstdio>
16 #include <limits>
17 
18 #include <vapor/MyBase.h>
19 #include <vapor/DataMgr.h>
20 #include <vapor/common.h>
21 #include <vapor/NetCDFCollection.h>
22 
23 using namespace std;
24 
25 struct kdtree;
26 
27 namespace VAPoR {
28 
29 class VDF_API DataMgrMPAS : public DataMgr {
30 
31 
32 public:
33 
34  DataMgrMPAS( const vector <string> &files, size_t mem_size );
35  virtual ~DataMgrMPAS();
36 
37 protected:
38 
39  virtual int Initialize(vector <string> files);
40  virtual string _GetGridType() const { return("regular"); }
41  virtual int _GetNumTransforms() const { return(0); };
42  virtual long _GetNumTimeSteps() const { return(_numberOfTimeSteps); };
43  virtual string _GetMapProjection() const {return (_proj4String); };
44  virtual void _GetBlockSize(size_t bs[3], int reflevel) const;
45  virtual vector <string> _GetVariables3D() const;
46  virtual vector <string> _GetVariables2DXY() const;
47  virtual vector <string> _GetVariables2DXZ() const {vector <string> empty; return (empty); };
48  virtual vector <string> _GetVariables2DYZ() const {vector <string> empty; return (empty); };
49  virtual int _OpenVariableRead( size_t timestep, const char *varname, int, int);
50  virtual bool _GetMissingValue(string varname, float &value) const {
51  value=_missing_value; return(_has_missing);
52  };
53  virtual int _CloseVariable() {return (0);};
54  virtual vector<double> _GetExtents(size_t ts) const;
55  virtual vector<long> _GetPeriodicBoundary() const { return(_bool_false); };
56  virtual vector<long> _GetGridPermutation() const { return(_bool_false); };
57  virtual const float *_GetDataRange() const {return(_range);};
58  virtual void _GetDim(size_t dim[3], int ) const;
59  virtual void _GetValidRegion( size_t min[3], size_t max[3], int) const;
60  virtual int _BlockReadRegion( const size_t *, const size_t *, float *region);
61 
62  virtual double _GetTSUserTime(size_t ts) const { return(0); };
63  virtual void _GetTSUserTimeStamp(size_t ts, string &s) const { }
64  virtual int _VariableExists( size_t ts, const char *varname, int reflevel = 0, int lod = 0 ) const { return (1); };
65 
66 private:
67 
68  enum var_type_t {CELL, VERT, EDGE};
69 
70  bool ValidFile();
71  bool GetDims();
72  bool GetVars(string cellDimName, string pointDimName, string edgeDimName);
73  void ResampleDataCell(const int width, const int height, float *data);
74  void _resampleDataCell(const int width, const int height, float *data);
75  void _resampleDataPoint(
76  const int width, const int height,
77  const float *resampleWeights, const int *resampleIds, float *data
78  );
79  int ConstructGridGeometry();
80  void _constructCellResampleWeights(
81  const int *cellsOnVertex, const int *vertsOnCell,
82  const int *nVertsOnCell,
83  float *cellResampleWeights, int *cellResampleIds
84  );
85  void _constructPointResampleWeights(
86  const int *vertsOnCell, const int *nVertsOnCell,
87  const double *pointLons, const double *pointLats, int nLatLons,
88  float *pointResampleWeights, int *pointResampleIds
89  );
90 
91  void _constructEdgeResampleWeights(
92  const int *edgesOnCell, const int *nEdgesOnCell, const int *verticesOnEdge,
93  const double *vertLons, const double *vertLats, int nLatLons,
94  float *edgeResampleWeights, int *edgeResampleIds
95  );
96 
97  int _constructResampleWeights();
98  void CreateKdTree();
99  void XYSize();
100 
101  bool _barycentricCoordsForCell(
102  const vector <int> &vertList, int cellid, const double pt[2],
103  const double *pointLons, const double *pointLats, int nLatLons,
104  float *lambda, int *vertIds
105  ) const;
106 
107  bool _barycentricCoordsForTriangle(
108  const int *cellsOnVertex, int pointid, int copid, const double pt[2],
109  float *lambda, int cellIds[3], int &n
110  ) const;
111 
112  NetCDFCollection _ncCollection;
113  float* _varBuf1;
114  float* _varBuf2; // space to buffer variables on native grid
115  float *_cellResampleWeights;
116  int *_cellResampleIds;
117  float *_pointResampleWeights;
118  int *_pointResampleIds;
119  float *_edgeResampleWeights;
120  int *_edgeResampleIds;
121  int _reg_res_x, _reg_res_y;
122  double _oversampling;
123  double _missing_value;
124  bool _has_missing;
125  bool _interpolation;
126  bool _activeVar3D;
127  var_type_t _var_type;
128  std::vector<long> _bool_false;
129  string _cells_name;
130  string _vertices_name;
131  string _edges_name;
132  string _vertexdegree_name;
133  string _maxedges_name;
134  string _time_name;
135  string _vertlevels_name;
136  string _vertlevelsP1_name;
137  double _clon_range[2], _clat_range[2], _vlon_range[2], _vlat_range[2];
138  double _elon_range[2], _elat_range[2];
139  double _lon_range[2], _lat_range[2];
140  double _lon_rangePCS[2], _lat_rangePCS[2];
141  int _numberOfTimeSteps;
142 
143  int _numberOfVertLevels;
144  int _numberOfVertLevelsP1;
145  int _numberOfCells;
146  int _numberOfPoints;
147  int _numberOfEdges;
148 
149  int _cellDegreeMax;
150  int _vertexDegree;
151 
152  double* _cellLon;
153  double* _cellLat;
154  double* _pointLon;
155  double* _pointLat;
156  double* _edgeLon;
157  double* _edgeLat;
158  int *_cellIndex;
159  kdtree *_cellTree;
160  string _proj4String;
161 
162  std::vector <string> _cellVars;
163  std::vector <string> _pointVars;
164  std::vector <string> _edgeVars;
165 
166  float _range[2];
167 
168 };
169 
170 };
171 #endif
virtual vector< long > _GetPeriodicBoundary() const
Definition: DataMgrMPAS.h:55
#define VDF_API
Definition: common.h:61
virtual vector< long > _GetGridPermutation() const
Definition: DataMgrMPAS.h:56
A cache based data reader.
Definition: DataMgr.h:39
virtual const float * _GetDataRange() const
Definition: DataMgrMPAS.h:57
virtual vector< string > _GetVariables2DXZ() const
Definition: DataMgrMPAS.h:47
virtual int _GetNumTransforms() const
Definition: DataMgrMPAS.h:41
virtual double _GetTSUserTime(size_t ts) const
Definition: DataMgrMPAS.h:62
virtual bool _GetMissingValue(string varname, float &value) const
Definition: DataMgrMPAS.h:50
virtual string _GetGridType() const
Definition: DataMgrMPAS.h:40
virtual string _GetMapProjection() const
Definition: DataMgrMPAS.h:43
virtual int _VariableExists(size_t ts, const char *varname, int reflevel=0, int lod=0) const
Definition: DataMgrMPAS.h:64
virtual int _CloseVariable()
Definition: DataMgrMPAS.h:53
virtual void _GetTSUserTimeStamp(size_t ts, string &s) const
Definition: DataMgrMPAS.h:63
virtual vector< string > _GetVariables2DYZ() const
Definition: DataMgrMPAS.h:48
virtual long _GetNumTimeSteps() const
Definition: DataMgrMPAS.h:42