VAPoR  0.1
DCReaderWRF.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 
5 
6 #ifndef _DCReaderWRF_h_
7 #define _DCReaderWRF_h_
8 
9 #include <vector>
10 #include <cassert>
11 #include <vapor/DCReader.h>
12 #include <vapor/NetCDFCollection.h>
13 #include <vapor/common.h>
14 #include <vapor/Proj4API.h>
15 
16 #ifdef WIN32
17 #pragma warning(disable : 4251)
18 #endif
19 
20 namespace VAPoR {
21 
22 //
31 class VDF_API DCReaderWRF : public DCReader {
32 
33 public:
34 
35  DCReaderWRF(const std::vector <string> &files);
36 
37  virtual ~DCReaderWRF();
38 
39  virtual void GetGridDim(size_t dim[3]) const {
40  for (int i=0; i<3; i++) dim[i] = _dims[i];
41  }
42 
43  void GetBlockSize(size_t bs[3], int) const {
45  }
46 
47  virtual string GetGridType() const {
48  return("layered");
49  }
50 
51  virtual std::vector <double> GetExtents(size_t ts = 0) const;
52 
53  long GetNumTimeSteps() const {
54  return(_ncdfc->GetNumTimeSteps());
55  }
56 
57  virtual string GetMapProjection() const {
58  return(_projString);
59  };
60 
61  virtual std::vector <string> GetVariables3D() const {
62  return(_vars3d);
63  };
64 
65  virtual std::vector <string> GetVariables2DXY() const {
66  return(_vars2dXY);
67  };
68 
69 
70  virtual std::vector <string> GetVariables2DXZ() const {
71  std::vector <string> empty; return(empty);
72  };
73 
74  virtual std::vector <string> GetVariables2DYZ() const {
75  std::vector <string> empty; return(empty);
76  };
77 
78  virtual std::vector <string> GetVariables3DExcluded() const {
79  return(_vars3dExcluded);
80  };
81 
82  virtual std::vector <string> GetVariables2DExcluded() const {
83  return(_vars2dExcluded);
84  };
85 
86 
87  //
88  // There a no spatial coordinate variables because we project
89  // the data to a horizontally uniformly sampled Cartesian
90  // grid.
91  //
92  virtual std::vector <string> GetCoordinateVariables() const {
93  vector <string> v;
94  v.push_back("NONE"); v.push_back("NONE"); v.push_back("ELEVATION");
95  return(v);
96 }
97 
98  //
99  // Boundary may be periodic in X (longitude), but we have no way
100  // of knowing this by examining the netCDF files
101  //
102  virtual std::vector<long> GetPeriodicBoundary() const {
103  vector <long> p;
104  p.push_back(0); p.push_back(0); p.push_back(0);
105  return(p);
106  }
107 
108  virtual std::vector<long> GetGridPermutation() const {
109  vector <long> p;
110  p.push_back(0); p.push_back(1); p.push_back(2);
111  return(p);
112 }
113 
114  double GetTSUserTime(size_t ts) const ;
115 
116  bool GetMissingValue(string varname, float &value) const {
117  value = 0.0;
118  return(false);
119  };
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  ts = _timeLookup[ts];
138  return(_ncdfc->VariableExists(ts, varname));
139  }
140 
141 
143  _timeBias = 978307200.0; // Make consistent with legacy code
144  }
145 
146  virtual void GetLatLonExtents(
147  size_t ts, double lon_exts[2], double lat_exts[2]
148  ) const {
149  double dummy[4];
150  ts = _timeLookup[ts];
151  (void) _GetLatLonExtentsCorners(
152  _ncdfc, ts, lon_exts, lat_exts, dummy, dummy
153  );
154  }
155 
156 
157 private:
158 
159  class DerivedVarElevation : public NetCDFCollection::DerivedVar {
160  public:
161  DerivedVarElevation(
162  NetCDFCollection *ncdfcf, float grav
163  );
164  virtual ~DerivedVarElevation();
165 
166  virtual int Open(size_t ts);
167  virtual int ReadSlice(float *slice, int );
168  virtual int Read(float *buf, int );
169  virtual int SeekSlice(int offset, int whence, int );
170  virtual int Close(int fd);
171  virtual bool TimeVarying() const {return(true); };
172  virtual std::vector <size_t> GetSpatialDims() const { return(_dims); }
173  virtual std::vector <string> GetSpatialDimNames() const { return(_dimnames); }
174  virtual size_t GetTimeDim() const { return(_num_ts); }
175  virtual string GetTimeDimName() const { return("Time"); };
176  virtual bool GetMissingValue(double &mv) const {mv=0.0; return(false); }
177 
178  private:
179  std::vector <size_t> _dims;
180  std::vector <string> _dimnames;
181  float _grav;
182  string _PHvar;
183  string _PHBvar;
184  float *_PH;
185  float *_PHB;
186  int _PHfd;
187  int _PHBfd;
188  size_t _num_ts;
189  bool _is_open;
190  bool _ok;
191  };
192 
193 
194  std::vector <size_t> _dims;
195  std::vector <string> _vars3d;
196  std::vector <string> _vars2dXY;
197  std::vector <string> _vars3dExcluded;
198  std::vector <string> _vars2dExcluded;
199  std::vector <string> _timeStamps;
200  std::vector <double> _times;
201  std::vector <size_t> _timeLookup;
202  NetCDFCollection *_ncdfc;
203  float *_sliceBuffer; // buffer for reading data
204  int _ovr_fd;
205  string _projString;
206  Proj4API _proj4API;
207  int _mapProj;
208  float _dx;
209  float _dy;
210  float _cen_lat;
211  float _cen_lon;
212  float _pole_lat;
213  float _pole_lon;
214  float _grav;
215  float _days_per_year;
216  float _radius; // planet radius for PlanetWRF
217  float _p2si; // multiplier for time conversion for PlanetWRF
218  DerivedVarElevation *_elev;
219  double _timeBias;
220 
221 
222  std::vector <size_t> _GetSpatialDims(
223  NetCDFCollection *ncdfc, string varname
224  ) const;
225  std::vector <string> _GetSpatialDimNames(
226  NetCDFCollection *ncdfc, string varname
227  ) const;
228 
229 
230  int _InitAtts(NetCDFCollection *ncdfc);
231  int _InitProjection(NetCDFCollection *ncdfc, float radius);
232  int _InitDimensions(NetCDFCollection *ncdfc);
233  int _InitVerticalCoordinates(NetCDFCollection *ncdfc);
234  int _InitTime(NetCDFCollection *ncdfc);
235  int _InitVars(NetCDFCollection *ncdfc);
236 
237  int _GetVerticalExtents(
238  NetCDFCollection *ncdfc, size_t ts, double height[2]
239  ) const;
240 
241  int _GetLatLonExtentsCorners(
242  NetCDFCollection *ncdfc,
243  size_t ts, double lon_exts[2], double lat_exts[2],
244  double lon_corners[4], double lat_corners[4]
245  ) const;
246 
247 };
248 
249 };
250 
251 #endif // _DCReaderWRF_h_
virtual std::vector< long > GetPeriodicBoundary() const
Definition: DCReaderWRF.h:102
virtual void GetGridDim(size_t dim[3]) const
Definition: DCReaderWRF.h:39
#define VDF_API
Definition: common.h:61
virtual std::vector< string > GetVariables2DXY() const
Definition: DCReaderWRF.h:65
bool GetMissingValue(string varname, float &value) const
Definition: DCReaderWRF.h:116
virtual std::vector< string > GetVariables2DYZ() const
Definition: DCReaderWRF.h:74
void GetBlockSize(size_t bs[3], int) const
Definition: DCReaderWRF.h:43
void EnableLegacyTimeConversion()
Definition: DCReaderWRF.h:142
virtual bool VariableExists(size_t ts, string varname, int i0=0, int i1=0) const
Definition: DCReaderWRF.h:136
long GetNumTimeSteps() const
Definition: DCReaderWRF.h:53
virtual std::vector< string > GetVariables2DXZ() const
Definition: DCReaderWRF.h:70
virtual string GetMapProjection() const
Definition: DCReaderWRF.h:57
virtual void GetLatLonExtents(size_t ts, double lon_exts[2], double lat_exts[2]) const
Definition: DCReaderWRF.h:146
virtual std::vector< long > GetGridPermutation() const
Definition: DCReaderWRF.h:108
virtual std::vector< string > GetVariables2DExcluded() const
Definition: DCReaderWRF.h:82
virtual string GetGridType() const
Definition: DCReaderWRF.h:47
virtual std::vector< string > GetVariables3D() const
Definition: DCReaderWRF.h:61
virtual std::vector< string > GetVariables3DExcluded() const
Definition: DCReaderWRF.h:78
Wrapper for a collection of netCDF files.
virtual std::vector< string > GetCoordinateVariables() const
Definition: DCReaderWRF.h:92