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