VAPoR  3.0.0
VDCNetCDF.h
Go to the documentation of this file.
1 #include <vector>
2 #include <map>
3 #include <algorithm>
4 #include <iostream>
5 #include "vapor/VDC.h"
6 #include "vapor/WASP.h"
7 
8 #ifndef _VDCNetCDF_H_
9 #define _VDCNetCDF_H_
10 
11 namespace VAPoR {
12 
27 class VDF_API VDCNetCDF : public VAPoR::VDC {
28 public:
29 
48  //
49  VDCNetCDF(
50  int numthreads = 0,
51  size_t master_theshold=10*1024*1024,
52  size_t variable_threshold=100*1024*1024
53  );
54  virtual ~VDCNetCDF();
55 
69  //
70  static string GetDataDir(string path);
71 
88  virtual int GetPath(
89  string varname, size_t ts, string &path, size_t &file_ts,
90  size_t &max_ts
91  ) const;
92 
94  //
95  virtual int GetDimLensAtLevel(
96  string varname, int level, std::vector <size_t> &dims_at_level,
97  vector <size_t> &bs_at_level
98  ) const;
99 
106  //
107  static bool DataDirExists(string path) ;
108 
109 
115  //
116  virtual int Initialize(
117  const vector <string> &paths, AccessMode mode, size_t chunksizehint = 0
118  );
119  virtual int Initialize(
120  string path, AccessMode mode, size_t chunksizehint = 0
121  ) {
122  std::vector <string> paths;
123  paths.push_back(path);
124  return(Initialize(paths, mode, chunksizehint));
125  }
126 
130  //
131  size_t GetMasterThreshold() const {return _master_threshold; };
132 
136  //
137  size_t GetVariableThreshold() const {return _variable_threshold; };
138 
140  //
141  int OpenVariableRead(
142  size_t ts, string varname, int level=0, int lod=-1
143  );
144 
146  //
147  int CloseVariable();
148 
149 
151  //
152  int OpenVariableWrite(size_t ts, string varname, int lod=-1);
153 
155  //
156  int Write(const float *region);
157 
158  int WriteSlice(const float *slice);
159 
161  //
162  int Read(float *region);
163 
165  //
166  int ReadSlice(float *slice);
167 
169  //
170  int ReadRegion(
171  const std::vector<size_t> &min,
172  const std::vector<size_t> &max, float *region
173  );
174 
176  //
177  int ReadRegionBlock(
178  const vector <size_t> &min, const vector <size_t> &max, float *region
179  );
180 
182  //
183  int PutVar(string varname, int lod, const float *data);
184 
186  //
187  int PutVar(size_t ts, string varname, int lod, const float *data);
188 
190  //
191  int GetVar(string varname, int level, int lod, float *data);
192 
194  //
195  int GetVar(size_t ts, string varname, int level, int lod, float *data);
196 
197 
199  //
200  bool CompressionInfo(
201  std::vector <size_t> bs, string wname, size_t &nlevels, size_t &maxcratio
202  ) const;
203 
204  virtual bool VariableExists(
205  size_t ts,
206  string varname,
207  int reflevel = 0,
208  int lod = 0
209  ) const;
210 
211 
212 
213 protected:
214 
215 #ifndef DOXYGEN_SKIP_THIS
216  virtual int _WriteMasterMeta();
217  virtual int _ReadMasterMeta();
218 #endif
219 
220 private:
221  int _version;
222  WASP *_master; // Master NetCDF file
223 
224  class open_file_info {
225  public:
226  open_file_info() {
227  _wasp = NULL;
228  _write = false;
229  _slice_num = 0;
230  _ts = 0;
231  _file_ts = 0;
232  _varname.clear();
233  _level = 0;
234  };
235  open_file_info(
236  WASP *wasp, bool write, BaseVar var, size_t slice_num,
237  size_t ts, size_t file_ts, string varname, int level
238  ) :
239  _wasp(wasp),
240  _write(write),
241  _var(var),
242  _slice_num(slice_num),
243  _ts(ts),
244  _file_ts(file_ts),
245  _varname(varname),
246  _level(level)
247  { };
248 
249  WASP *_wasp; // Currently opened data file
250  bool _write; // opened for writing?
251  BaseVar _var;
252  size_t _slice_num; // index of current slice for WriteSlice, ReadSlice
253  size_t _ts; // global time step of current open variable
254  size_t _file_ts; // local (within file) time step of current open var
255  string _varname; // name of current open variable
256  int _level;
257  };
258  open_file_info _ofi; // currently open data or coordinate variable
259  open_file_info _ofimask; // current opened mask variable
260 
261  VetsUtil::SmartBuf _sb_slice_buffer;
262  VetsUtil::SmartBuf _mask_buffer;
263  float *_slice_buffer;
264 
265  size_t _chunksizehint; // NetCDF chunk size hint for file creates
266  size_t _master_threshold;
267  size_t _variable_threshold;
268  int _nthreads;
269 
270  int _WriteMasterDimensions();
271  int _WriteMasterAttributes (
272  string prefix, const map <string, Attribute> &atts
273  );
274  int _WriteMasterAttributes ();
275  int _WriteMasterBaseVarDefs(string prefix, const BaseVar &var);
276  int _WriteMasterCoordVarsDefs();
277  int _WriteMasterDataVarsDefs();
278  int _WriteSlice(WASP *file, const float *slice);
279  int _WriteSlice(NetCDFCpp *file, const float *slice);
280 
281  int _ReadMasterDimensions();
282  int _ReadMasterAttributes (
283  string prefix, map <string, Attribute> &atts
284  );
285  int _ReadMasterAttributes ();
286  int _ReadMasterBaseVarDefs(string prefix, BaseVar &var);
287  int _ReadMasterCoordVarsDefs();
288  int _ReadMasterDataVarsDefs();
289  int _ReadSlice(WASP *file, float *slice);
290  int _ReadSlice(NetCDFCpp *file, float *slice);
291 
292  int _PutAtt(
293  WASP *ncdf,
294  string varname,
295  string tag,
296  const Attribute &attr
297  );
298 
299  int _DefBaseVar(WASP *ncdf, const VDC::BaseVar &var, size_t max_ts);
300  int _DefDataVar(WASP *ncdf, const VDC::DataVar &var, size_t max_ts);
301  int _DefCoordVar(WASP *ncdf, const VDC::CoordVar &var, size_t max_ts);
302 
303  bool _var_in_master(const VDC::BaseVar &var) const;
304 
305  string _get_mask_varname(string varname) const;
306 
307  unsigned char *_read_mask_var(
308  vector <size_t> start, vector <size_t> count
309  );
310 
311  WASP *_OpenVariableRead(
312  size_t ts, const VDC::BaseVar &var, int clevel, int lod,
313  size_t &file_ts
314  );
315 
316 
317 
318 };
319 };
320 
321 #endif
Defines API for reading, writing, and appending data to a VAPOR Data Collection (Version 3) ...
Definition: VDC.h:177
virtual int Initialize(string path, AccessMode mode, size_t chunksizehint=0)
Definition: VDCNetCDF.h:119
size_t GetVariableThreshold() const
Definition: VDCNetCDF.h:137
Implements WASP compression conventions for NetCDF.
Definition: WASP.h:98
Implements the VDC abstract class, providing storage of VDC data in NetCDF files. ...
Definition: VDCNetCDF.h:27
#define VDF_API
Definition: DC.h:10
size_t GetMasterThreshold() const
Definition: VDCNetCDF.h:131
AccessMode
Definition: VDC.h:182