VAPoR  0.1
DCReaderMOM.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 
5 
6 #ifndef _DCReaderMOM_h_
7 #define _DCReaderMOM_h_
8 
9 #include <vector>
10 #include <cassert>
11 #include <vapor/NetCDFCFCollection.h>
12 #include <vapor/DCReaderNCDF.h>
13 #include <vapor/WeightTable.h>
14 #ifdef WIN32
15 #pragma warning(disable : 4251)
16 #endif
17 
18 namespace VAPoR {
19 
20 //
29 class VDF_API DCReaderMOM : public DCReader {
30 public:
31 
32  DCReaderMOM(const std::vector <string> &files);
33 
34  virtual ~DCReaderMOM();
35 
36  virtual void GetGridDim(size_t dim[3]) const {
37  for (int i=0; i<3; i++) dim[i] = _dims[i];
38  }
39 
40  void GetBlockSize(size_t bs[3], int) const {
42  }
43 
44  virtual string GetGridType() const {return("stretched"); };
45 
46  virtual std::vector<double> GetTSZCoords(size_t ) const {
47  return(_vertCoordinates);
48  };
49 
50  virtual std::vector <double> GetExtents(size_t ts = 0) const {
51  return(_cartesianExtents);
52  }
53 
54  long GetNumTimeSteps() const {
55  return(_ncdfc->GetNumTimeSteps());
56  }
57 
58  virtual string GetMapProjection() const;
59 
60  virtual std::vector <string> GetVariables3D() const {
61  return(_vars3d);
62  };
63 
64  virtual std::vector <string> GetVariables2DXY() const {
65  return(_vars2dXY);
66  };
67 
68 
69  virtual std::vector <string> GetVariables2DXZ() const {
70  std::vector <string> empty; return(empty);
71  };
72 
73  virtual std::vector <string> GetVariables2DYZ() const {
74  std::vector <string> empty; return(empty);
75  };
76 
77  virtual std::vector <string> GetVariables3DExcluded() const {
78  return(_vars3dExcluded);
79  };
80 
81  virtual std::vector <string> GetVariables2DExcluded() const {
82  return(_vars2dExcluded);
83  };
84 
85 
86  //
87  // There a no spatial coordinate variables because we project
88  // the data to a horizontally uniformly sampled Cartesian
89  // grid.
90  //
91  virtual std::vector <string> GetCoordinateVariables() const {
92  vector <string> v;
93  v.push_back("NONE"); v.push_back("NONE"); v.push_back("NONE");
94  return(v);
95 }
96 
97  //
98  // Boundary may be periodic in X (longitude), but we have no way
99  // of knowing this by examining the netCDF files
100  //
101  virtual std::vector<long> GetPeriodicBoundary() const {
102  vector <long> p;
103  p.push_back(0); p.push_back(0); p.push_back(0);
104  return(p);
105  }
106 
107  virtual std::vector<long> GetGridPermutation() const {
108  vector <long> p;
109  p.push_back(0); p.push_back(1); p.push_back(2);
110  return(p);
111 }
112 
113  double GetTSUserTime(size_t ts) const ;
114 
115  bool GetMissingValue(string varname, float &value) const;
116 
117  void GetTSUserTimeStamp(size_t ts, string &s) const;
118 
119  virtual bool IsCoordinateVariable(string varname) const;
120 
121 
122  virtual int OpenVariableRead(
123  size_t timestep, string varname, int reflevel=0, int lod=0
124  );
125 
126  virtual int CloseVariable();
127 
128  virtual int ReadSlice(float *slice);
129 
130  virtual int Read(float *data);
131 
132  virtual bool VariableExists(size_t ts, string varname, int i0=0, int i1=0) const {
133  if (IsVariableDerived(varname)) return (true);
134  return(_ncdfc->VariableExists(ts, varname));
135  }
136 
137  virtual bool IsVariableDerived(string varname) const {
138  return(find(_varsDerived.begin(), _varsDerived.end(), varname) != _varsDerived.end());
139  }
140 
141  virtual void GetLatLonExtents(
142  size_t ts, double lon_exts[2], double lat_exts[2]
143  ) const {
144  lon_exts[0] = _lonExts[0]; lon_exts[1] = _lonExts[1];
145  lat_exts[0] = _latExts[0]; lat_exts[1] = _latExts[1];
146  }
147 
148 private:
149  std::vector <size_t> _dims;
150  double _latExts[2];
151  double _lonExts[2];
152  std::vector <double> _vertCoordinates;
153  std::vector <double> _cartesianExtents;
154  std::vector <string> _vars3d;
155  std::vector <string> _vars2dXY;
156  std::vector <string> _vars3dExcluded;
157  std::vector <string> _vars2dExcluded;
158  std::vector <string> _varsDerived;
159  std::map <string, WeightTable *> _weightTableMap;
160  std::map <string, string> _varsLatLonMap;
161  NetCDFCFCollection *_ncdfc;
162  float *_sliceBuffer; // buffer for reading data
163  float *_angleRADBuf; // buffer for derived "angleRAD" variable
164  float *_latDEGBuf; // buffer for derived "latDEG" variable
165  string _vertCV; // vertical coordinate variable name
166  string _timeCV; // time coordinate variable name
167  std::vector <string> _latCVs; // all valid latitude coordinate variables
168  std::vector <string> _lonCVs; // all valid longitude coordinate variables
169  WeightTable *_ovr_weight_tbl;
170  string _ovr_varname;
171  size_t _ovr_slice;
172  size_t _ovr_nz;
173  int _ovr_fd;
174  float _defaultMV;
175  bool _reverseRead;
176 
177  class latLonBuf {
178  public:
179  size_t _nx;
180  size_t _ny;
181  float *_latbuf;
182  float *_lonbuf;
183  float _latexts[2];
184  float _lonexts[2];
185  };
186 
187 
188  void _encodeLatLon(string latcv, string loncv, string &key) const;
189  void _decodeLatLon(string key, string &latcv, string &loncv) const;
190 
191  int _initLatLonBuf(
192  NetCDFCFCollection *ncdfc, string latvar, string lonvar,
193  DCReaderMOM::latLonBuf &llb
194  ) const;
195 
196  void _getRotationVariables(
197  const std::map <string, WeightTable *> _weightTableMap,
198  float *_angleRADBuf, float *_latDEGBuf
199  ) const;
200 
201  std::vector <size_t> _GetSpatialDims(
202  NetCDFCFCollection *ncdfc, string varname
203  ) const;
204 
205  int _InitCoordVars(NetCDFCFCollection *ncdfc);
206 
207  void _ParseCoordVarNames(
208  NetCDFCFCollection *ncdfc, const vector <string> &cvars,
209  string &timecv, string &vertcv, string &latcv, string &loncv
210  ) const;
211 
212 
213  int _InitVerticalCoordinates(
214  NetCDFCFCollection *ncdfc,
215  string cvar,
216  vector <double> &vertCoords
217  );
218 
219  void _InitDimensions(
220  NetCDFCFCollection *ncdfc,
221  vector <size_t> &dims,
222  vector <string> &vars3d,
223  vector <string> &vars2dxy
224  );
225 
226  //
227  // Convert horizontal extents expressed in lat-lon to Cartesian
228  // coordinates in whatever units the vertical coordinate is
229  // expressed in.
230  //
231  int _InitCartographicExtents(
232  string mapProj,
233  const double lonExts[2],
234  const double latExts[2],
235  const std::vector <double> vertCoordinates,
236  std::vector <double> &extents
237  ) const;
238 
239  float *_get_2d_var(NetCDFCFCollection *ncdfc, size_t ts, string name) const;
240  float *_get_1d_var(NetCDFCFCollection *ncdfc, size_t ts, string name) const;
241 
242 
243 
244 };
245 };
246 
247 #endif // _DCReaderMOM_h_
virtual std::vector< long > GetGridPermutation() const
Definition: DCReaderMOM.h:107
virtual std::vector< double > GetTSZCoords(size_t) const
Definition: DCReaderMOM.h:46
#define VDF_API
Definition: common.h:61
virtual std::vector< double > GetExtents(size_t ts=0) const
Definition: DCReaderMOM.h:50
virtual bool VariableExists(size_t ts, string varname, int i0=0, int i1=0) const
Definition: DCReaderMOM.h:132
long GetNumTimeSteps() const
Definition: DCReaderMOM.h:54
Wrapper for a collection of netCDF files.
virtual void GetLatLonExtents(size_t ts, double lon_exts[2], double lat_exts[2]) const
Definition: DCReaderMOM.h:141
virtual std::vector< string > GetVariables2DXY() const
Definition: DCReaderMOM.h:64
void GetBlockSize(size_t bs[3], int) const
Definition: DCReaderMOM.h:40
virtual std::vector< string > GetVariables2DExcluded() const
Definition: DCReaderMOM.h:81
virtual std::vector< string > GetCoordinateVariables() const
Definition: DCReaderMOM.h:91
virtual bool IsVariableDerived(string varname) const
Definition: DCReaderMOM.h:137
virtual string GetGridType() const
Definition: DCReaderMOM.h:44
virtual std::vector< string > GetVariables3D() const
Definition: DCReaderMOM.h:60
virtual std::vector< string > GetVariables3DExcluded() const
Definition: DCReaderMOM.h:77
virtual void GetGridDim(size_t dim[3]) const
Definition: DCReaderMOM.h:36
virtual std::vector< long > GetPeriodicBoundary() const
Definition: DCReaderMOM.h:101
virtual std::vector< string > GetVariables2DYZ() const
Definition: DCReaderMOM.h:73
virtual std::vector< string > GetVariables2DXZ() const
Definition: DCReaderMOM.h:69