VAPoR  0.1
WaveletBlockIOBase.h
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 
5 
6 #ifndef _WavletBlockIOBase_h_
7 #define _WavletBlockIOBase_h_
8 
9 #include <cstdio>
10 #include <vapor/MyBase.h>
11 #include <vapor/WaveletBlock3D.h>
12 #include <vapor/WaveletBlock2D.h>
13 #include <vapor/VDFIOBase.h>
14 
15 namespace VAPoR {
16 
17 
18 //
27 //
29 
30 public:
31 
41  //
43  const MetadataVDC &metadata
44  );
45 
55  //
57  const string &metafile
58  );
59 
60  virtual ~WaveletBlockIOBase();
61 
73  //
74  virtual int VariableExists(
75  size_t ts,
76  const char *varname,
77  int reflevel = 0,
78  int lod = 0
79  ) const ;
80 
81 
104  virtual int OpenVariableWrite(
105  size_t timestep,
106  const char *varname,
107  int reflevel = -1,
108  int lod = -1
109  );
110 
111  virtual int BlockWriteRegion(
112  const float *region, const size_t bmin[3], const size_t bmax[3],
113  bool block=true
114  ) { SetErrMsg("Not implemented"); return(-1); }
115 
116  virtual int WriteRegion(
117  const float *region, const size_t min[3], const size_t max[3]
118  ) { SetErrMsg("Not implemented"); return(-1); }
119 
120  virtual int WriteRegion(
121  const float *region
122  ) { SetErrMsg("Not implemented"); return(-1); }
123 
124  virtual int WriteSlice(const float *slice)
125  { SetErrMsg("Not implemented"); return(-1); }
126 
127 
128 
153  virtual int OpenVariableRead(
154  size_t timestep,
155  const char *varname,
156  int reflevel = 0,
157  int lod = 0
158  );
159 
160  virtual int BlockReadRegion(
161  const size_t bmin[3], const size_t bmax[3], float *region, bool unblock=true
162  ) { SetErrMsg("Not implemented"); return(-1); }
163 
164  virtual int ReadRegion(
165  const size_t min[3], const size_t max[3], float *region
166  ) { SetErrMsg("Not implemented"); return(-1); }
167 
168  virtual int ReadRegion(
169  float *region
170  ) { SetErrMsg("Not implemented"); return(-1); }
171 
172  virtual int ReadSlice(float *slice) {
173  SetErrMsg("Not implemented"); return(-1);
174  }
175 
179  //
180  virtual int CloseVariable();
181 
198  int GetBlockMins(const float **mins, int reflevel);
199 
202  int GetBlockMaxs(const float **maxs, int reflevel);
203 
215  //
216  void Tile2NonTile(
217  const float *blk,
218  const size_t bcoord[2],
219  const size_t min[2],
220  const size_t max[2],
221  VarType_T vtype,
222  float *voxels
223  ) const;
224 
236  //
237  void Block2NonBlock(
238  const float *blk,
239  const size_t bcoord[3],
240  const size_t min[3],
241  const size_t max[3],
242  float *voxels
243  ) const;
244 
245  virtual const float *GetDataRange() const { return (_dataRange); }
246 
247  void GetValidRegion(
248  size_t min[3], size_t max[3], int reflevel
249  ) const;
250 
251  virtual void GetDim(size_t dim[3], int reflevel = 0) const;
252 
253  virtual void GetDimBlk(size_t bdim[3], int reflevel = 0) const;
254 
255 protected:
256  static const int MAX_LEVELS = 16; // Max # of forward transforms permitted
257 
258 
259  int _reflevel; // refinement level of currently opened file.
260 
261  size_t _timeStep; // Currently opened timestep
262  string _varName; // Currently opened variable
263  float *_super_block; // temp storage for gamma blocks;
264  float *_super_tile;
265  VarType_T _vtype; // Type of currently opened variable
266 
271 
272  float *_mins3d[MAX_LEVELS]; // min value contained in a block
273  float *_maxs3d[MAX_LEVELS]; // max value contained in a block
274 
275  float *_mins2d[MAX_LEVELS]; // min value contained in a block
276  float *_maxs2d[MAX_LEVELS]; // max value contained in a block
277 
278 
279  // This method moves the file pointer associated with the currently
280  // open variable to the disk block indicated by 'offset' and
281  // 'reflevel', where 'offset' indicates the desired position, in
282  // blocks, and 'reflevel' indicates the refinement level
283  // If 'reflevel' is zero, for example,
284  // the file pointer is moved 'offset' blocks past the beginning
285  // of the coefficients associated with the coarsest data resolution.
286  //
287  int seekBlocks(unsigned int offset, int reflevel = 0);
288 
289  // This method moves the file pointer associated with the currently
290  // open variable to the disk block containing lambda coefficients
291  // indicated by the block coordinates 'bcoord'.
292  //
293  // A non-negative return value indicates success
294  //
295  int seekLambdaBlocks(const size_t bcoord[3]);
296 
297  // This method moves the file pointer associated with the currently
298  // open variable to the disk block containing gamma coefficients
299  // indicated by the block coordinates 'bcoord', and the refinement level
300  // 'reflevel'. The parameter 'reflevel'
301  // must be in the range [1.._max_reflevel]. Note, if max_xforms_c is
302  // zero, an error is generated as there are no gamma coefficients.
303  //
304  // A non-negative return value indicates success
305  //
306  int seekGammaBlocks(const size_t bcoord[3], int reflevel);
307 
308  // Read 'n' contiguous coefficient blocks, associated with the refinement
309  // level, 'reflevel', from the currently open variable
310  // file. The 'reflevel' parameter must be in the range [0.._max_reflevel],
311  // where a value of zero indicates the coefficients for the
312  // finest resolution. The results are stored in 'blks', which must
313  // point to an area of adequately sized memory.
314  //
315  int readBlocks(size_t n, float *blks, int reflevel);
316 
317  //
318  // Read 'n' contiguous lambda coefficient blocks
319  // from the currently open variable file.
320  // The results are stored in 'blks', which must
321  // point to an area of adequately sized memory.
322  //
323  int readLambdaBlocks(size_t n, float *blks);
324 
325  //
326  // Read 'n' contiguous gamma coefficient blocks, associated with
327  // the indicated refinement level, 'ref_level',
328  // from the currently open variable file.
329  // The results are stored in 'blks', which must
330  // point to an area of adequately sized memory.
331  // An error is generated if 'reflevel' is less than one or
332  // 'reflevel' is greater than _max_reflevel.
333  //
334  int readGammaBlocks(size_t n, float *blks, int reflevel);
335 
336  // Write 'n' contiguous coefficient blocks, associated with the indicated
337  // number of transforms, 'num_xforms', from the currently open variable
338  // file. The 'num_xforms' parameter must be in the range [0.._max_reflevel],
339  // where a value of zero indicates the coefficients for the
340  // finest resolution. The coefficients are copied from the memory area
341  // pointed to by 'blks'
342  //
343  int writeBlocks(const float *blks, size_t n, int reflevel);
344 
345  // Write 'n' contiguous lambda coefficient blocks
346  // from the currently open variable file.
347  // The blocks are copied to disk from the memory area pointed to
348  // by 'blks'.
349  //
350  int writeLambdaBlocks(const float *blks, size_t n);
351 
352  // Write 'n' contiguous gamma coefficient blocks, associated with
353  // the indicated refinement level, 'ref_level',
354  // from the currently open variable file.
355  // The data are copied from the area of memory pointed to by 'blks'.
356  // An error is generated if ref_level is less than one or
357  // 'ref_level' is greater than _max_reflevel.
358  //
359  int writeGammaBlocks(const float *blks, size_t n, int reflevel);
360 
361 
362 
363 
364  virtual void _GetDataRange(float range[2]) const = 0;
365  virtual void _GetValidRegion(size_t minreg[3], size_t maxreg[3]) const;
366 
367 
368 private:
369  string _ncpaths[MAX_LEVELS];
370  int _ncids[MAX_LEVELS];
371  int _ncvars[MAX_LEVELS];
372  int _ncminvars[MAX_LEVELS];
373  int _ncmaxvars[MAX_LEVELS];
374  int _ncoffsets[MAX_LEVELS]; // file ptr offset for netcdf
375  float _dataRange[2];
376  size_t _validRegMin[3];
377  size_t _validRegMax[3]; // Bounds (in voxels) of valid region relative
378  // to the finest level
379 
380 
381 
382 
383 // int n_c; // # filter coefficients
384 // int ntilde_c; // # lifting coefficients
385  int is_open_c; // true if a file is open
386  int write_mode_c; // true if file opened for writing
387  bool _is_alloc2d; // space allocated for 2D data?
388  bool _is_alloc3d; // space allocated for 3D data?
389 
390  static const string _blockSizeXName;
391  static const string _blockSizeYName;
392  static const string _blockSizeZName;
393  static const string _nBlocksDimName;
394  static const string _blockDimXName;
395  static const string _blockDimYName;
396  static const string _blockDimZName;
397  static const string _fileVersionName;
398  static const string _refLevelName;
399  static const string _nativeMinValidRegionName;
400  static const string _nativeMaxValidRegionName;
401  static const string _refLevMinValidRegionName;
402  static const string _refLevMaxValidRegionName;
403  static const string _nativeResName;
404  static const string _refLevelResName;
405  static const string _filterCoeffName;
406  static const string _liftingCoeffName;
407  static const string _scalarRangeName;
408  static const string _minsName;
409  static const string _maxsName;
410  static const string _lambdaName;
411  static const string _gammaName;
412 
413  int _WaveletBlockIOBase();
414 
415  int open_var_write(const string &basename);
416  int open_var_read(size_t ts, const char *varname, const string &basename);
417  int my_alloc2d();
418  int my_alloc3d();
419  void my_free2d();
420  void my_free3d();
421 
422  virtual int ncDefineDimsVars2D(
423  int j,
424  const string &path,
425  const int bs_dim_ids[3],
426  const int dim_ids[3]
427 
428  );
429 
430  virtual int ncVerifyDimsVars2D(
431  int j,
432  const string &path
433  );
434 
435  virtual int ncDefineDimsVars3D(
436  int j,
437  const string &path,
438  const int bs_dim_ids[3],
439  const int dim_ids[3]
440 
441  );
442 
443  virtual int ncVerifyDimsVars3D(
444  int j,
445  const string &path
446  );
447 
448 };
449 
450 }
451 
452 #endif // _WavletBlock3d_h_
virtual int ReadRegion(float *region)
A block-based, 3D wavelet transformer.
#define VDF_API
Definition: common.h:61
virtual int WriteRegion(const float *region, const size_t min[3], const size_t max[3])
virtual int ReadRegion(const size_t min[3], const size_t max[3], float *region)
virtual int WriteSlice(const float *slice)
virtual int ReadSlice(float *slice)
virtual const float * GetDataRange() const
A class for managing data set metadata.
Definition: MetadataVDC.h:92
virtual int BlockWriteRegion(const float *region, const size_t bmin[3], const size_t bmax[3], bool block=true)
A tile-based, 2D wavelet transformer.
Performs data IO to VDF files.
virtual int WriteRegion(const float *region)
Abstract base class for performing data IO to a VDC.
Definition: VDFIOBase.h:27
virtual int BlockReadRegion(const size_t bmin[3], const size_t bmax[3], float *region, bool unblock=true)