VAPoR  3.0.0
WASP.h
Go to the documentation of this file.
1 #include <vector>
2 #include <map>
3 #include <iostream>
4 #include <netcdf.h>
5 #include <vapor/NetCDFCpp.h>
6 #include <vapor/Compressor.h>
7 #include <vapor/EasyThreads.h>
8 #include <vapor/utils.h>
9 
10 #ifndef _WASP_H_
11 #define _WASP_H_
12 
13 namespace VAPoR {
14 
97 //
98 class WASP_API WASP : public VAPoR::NetCDFCpp {
99 public:
100 
111  //
112  WASP(int nthreads = 0);
113  virtual ~WASP();
114 
134  //
135  virtual int Create(
136  string path, int cmode, size_t initialsz,
137  size_t &bufrsizehintp, int numfiles
138  );
139 
146  //
147  virtual int Open(string path, int mode);
148 
150  //
151  virtual int SetFill(int fillmode, int &old_modep);
152 
154  //
155  virtual int EndDef() const;
156 
162  virtual int Close();
163 
164 
165 
189  //
190  virtual int InqVarDimlens(
191  string name, int level, vector <size_t> &dims, vector <size_t> &bs
192  ) const;
193 
195  //
196  virtual int InqVarDims(
197  string name, vector <string> &dimnames, vector <size_t> &dims
198  ) const;
199 
214  virtual int InqVarCompressionParams(
215  string name, string &wname, vector <size_t> &bs, vector <size_t> &cratios
216  ) const;
217 
242  //
243  static int InqDimsAtLevel(
244  string wname, int level, vector <size_t> dims, vector <size_t> bs,
245  vector <size_t> &dims_at_level, vector <size_t> &bs_at_level
246  );
247 
261  //
262  virtual int InqVarNumRefLevels(string name) const;
263 
284  static bool InqCompressionInfo(
285  vector <size_t> bs, string wname, size_t &nlevels, size_t &maxcratio
286  );
287 
320  //
321  virtual int DefVar(
322  string name, int xtype, vector <string> dimnames,
323  string wname, vector <size_t> bs, vector <size_t> cratios
324  );
325 
340  virtual int DefVar(
341  string name, int xtype, vector <string> dimnames,
342  string wname, vector <size_t> bs, vector <size_t> cratios,
343  double missing_value
344  );
345 
347  // Is this needed?
348  virtual int DefVar(
349  string name, int xtype, vector <string> dimnames
350  ) {
351  return(NetCDFCpp::DefVar(name, xtype, dimnames));
352  };
353 
355  //
356  int DefDim(string name, size_t len) const;
357 
358 
364  //
365  virtual int InqVarCompressed(
366  string varname, bool &compressed
367  ) const;
368 
375  int InqVarWASP(
376  string varname, bool &wasp
377  ) const;
378 
400  //
401  virtual int OpenVarWrite(string name, int lod);
402 
424  //
425  virtual int OpenVarRead(string name, int level, int lod);
426 
433  //
435  virtual int CloseVar();
436 
459  //
460  virtual int PutVara(
461  vector <size_t> start, vector <size_t> count, const float *data
462  );
463  virtual int PutVar(const float *data);
464 
465  virtual int PutVara(
466  vector <size_t> start, vector <size_t> count, const double *data
467  );
468  virtual int PutVar(const double *data);
469 
470  virtual int PutVara(
471  vector <size_t> start, vector <size_t> count, const int *data
472  );
473  virtual int PutVar(const int *data);
474 
475  virtual int PutVara(
476  vector <size_t> start, vector <size_t> count, const unsigned char *data
477  );
478  virtual int PutVar(const unsigned char *data);
479 
496  virtual int PutVara(
497  vector <size_t> start, vector <size_t> count, const float *data,
498  const unsigned char *mask
499  );
500  virtual int PutVar(const float *data, const unsigned char *mask);
501 
502  virtual int PutVara(
503  vector <size_t> start, vector <size_t> count, const double *data,
504  const unsigned char *mask
505  );
506  virtual int PutVar(const double *data, const unsigned char *mask);
507 
508  virtual int PutVara(
509  vector <size_t> start, vector <size_t> count, const int *data,
510  const unsigned char *mask
511  );
512  virtual int PutVar(const int *data, const unsigned char *mask);
513 
514  virtual int PutVara(
515  vector <size_t> start, vector <size_t> count, const unsigned char *data,
516  const unsigned char *mask
517  );
518  virtual int PutVar(const unsigned char *data, const unsigned char *mask);
519 
543  //
544  virtual int GetVara(
545  vector <size_t> start, vector <size_t> count, float *data
546  );
547  virtual int GetVara(
548  vector <size_t> start, vector <size_t> count, double *data
549  );
550  virtual int GetVara(
551  vector <size_t> start, vector <size_t> count, int *data
552  );
553 
554  virtual int GetVara(
555  vector <size_t> start, vector <size_t> count, unsigned char *data
556  );
557 
577  //
578  virtual int GetVaraBlock(
579  vector <size_t> start, vector <size_t> count, float *data
580  );
581  virtual int GetVaraBlock(
582  vector <size_t> start, vector <size_t> count, double *data
583  );
584  virtual int GetVaraBlock(
585  vector <size_t> start, vector <size_t> count, int *data
586  );
587  virtual int GetVaraBlock(
588  vector <size_t> start, vector <size_t> count, unsigned char *data
589  );
590 
608  //
609  virtual int GetVar(float *data);
610  virtual int GetVar(double *data);
611  virtual int GetVar(int *data);
612  virtual int GetVar(unsigned char *data);
613 
624  //
625  static std::vector <string> GetPaths(string path, int numfiles) {
626  if (numfiles > 1) {
627  return(mkmultipaths(path, numfiles));
628  }
629  else {
630  std::vector <string> t(1,path); return(t);
631  }
632  }
633 
635  static string AttNameWavelet() {return("WASP.Wavelet");}
636 
638  static string AttNameBlockSize() {return("WASP.BlockSize");}
639 
641  static string AttNameNumFiles() {return("WASP.NumFiles");}
642 
644  static string AttNameCRatios() {return("WASP.CRatios");}
645 
648  static string AttNameWASP() {return("WASP");}
649 
651  static string AttNameDimNames() {return("WASP.DimNames");}
652 
654  static string AttNameMissingValue() {return("WASP.MissingValue");}
655 
657  static string AttNameVersion() {return("WASP.Version");}
658 
659 
660 private:
661 
662  VetsUtil::EasyThreads *_et;
663  int _nthreads;
664  vector <NetCDFCpp> _ncdfcs;
665  vector <NetCDFCpp *> _ncdfcptrs; // pointers into _ncdfcs;
666  bool _waspFile; // Is this a WASP file
667  int _numfiles; // Number of NetCDF files
668  int _currentVersion; // Current WASP version number;
669  int _fileVersion; // version number of opened file;
670  VetsUtil::SmartBuf _blockbuf; // Dynamic storage for blocks
671  VetsUtil::SmartBuf _coeffbuf; // Dynamic storage wavelet coefficients
672  VetsUtil::SmartBuf _sigbuf; // Dynamic storage encoded signficance maps
673 
674  bool _open; // compressed variable open for reading or writing?
675  string _open_wname; // wavelet name of opened variable
676  vector <size_t> _open_bs; // block size of opened variable
677  vector <size_t> _open_cratios; // compression ratios of opened variable
678  vector <size_t> _open_udims; // uncompressed dims of opened variable
679  vector <size_t> _open_dims; // compressed dims of opened variable
680  int _open_lod; // level-of-detail of opened variable
681  int _open_level; // grid refinement level of opened variable
682  bool _open_write; // opened variable open for writing?
683  bool _open_waspvar; // opened variable is a WASP variable?
684  string _open_varname; // name of opened variable
685  nc_type _open_varxtype; // external type of opened variable
686  vector <Compressor *> _open_compressors; // Compressor for opened variable
687 
688 
689  int _GetBlockAlignedDims(
690  vector <string> dimnames,
691  vector <size_t> bs,
692  vector <string> &badimnames,
693  vector <size_t> &badims
694  ) const;
695 
696  int _GetCompressedDims(
697  vector <string> dimnames,
698  string wname,
699  vector <size_t> bs,
700  vector <size_t> cratios,
701  int xtype,
702  vector <string> &cdimnames,
703  vector <size_t> &cdims,
704  vector <string> &encoded_dim_names,
705  vector <size_t> &encoded_dims
706  ) const;
707 
708  int _InqDimlen(string name, size_t &len) const;
709 
710  void _get_encoding_vectors(
711  string wname, vector <size_t> bs, vector <size_t> cratios, int xtype,
712  vector <size_t> &ncoeffs, vector <size_t> &encoded_dims
713  ) const;
714 
715 
716  bool _validate_compression_params(
717  string wname, vector <size_t> dims,
718  vector <size_t> bs, vector <size_t> cratios
719  ) const;
720 
721  bool _validate_put_vara_compressed(
722  vector <size_t> start, vector <size_t> count,
723  vector <size_t> bs, vector <size_t> udims, vector <size_t> cratios
724  ) const;
725 
726  bool _validate_get_vara_compressed(
727  vector <size_t> start, vector <size_t> count,
728  vector <size_t> bs, vector <size_t> udims, vector <size_t> cratios,
729  bool unblock
730  ) const;
731 
732  int _get_compression_params(
733  string name, vector <size_t> &bs, vector <size_t> &cratios,
734  vector <size_t> &udims, vector <size_t> &dims, string &wname
735  ) const;
736 
737  template <class T, class U>
738  int _GetVara(
739  vector <size_t> start, vector <size_t> count, bool unblock, T *data,
740  U dummy
741  );
742 
743  template <class T>
744  int _GetVara(
745  vector <size_t> start, vector <size_t> count, bool unblock_flag, T *data
746  );
747 
748  static void _dims_at_level(
749  vector <size_t> dims, vector <size_t> bs, int level,
750  string wname, vector <size_t> &dims_level, vector <size_t> &bs_level
751  ) ;
752 
753  static vector <string> mkmultipaths(string path, int n);
754 
755 
756  template <class T, class U>
757  int _PutVara(
758  vector <size_t> start, vector <size_t> count, const T *data,
759  const unsigned char *mask, U dummy
760  );
761 
762  template <class T>
763  int _PutVara(
764  vector <size_t> start, vector <size_t> count, const T *data,
765  const unsigned char *mask
766  );
767 
768 
769 };
770 
771 }
772 
773 #endif // _WASP_H_
static string AttNameCRatios()
NetCDF attribute name specifying compression ratios.
Definition: WASP.h:644
virtual int DefVar(string name, int xtype, vector< string > dimnames)
Define a variable.
Definition: WASP.h:348
Implements WASP compression conventions for NetCDF.
Definition: WASP.h:98
static string AttNameWavelet()
NetCDF attribute name specifying Wavelet name.
Definition: WASP.h:635
static string AttNameBlockSize()
NetCDF attribute name specifying compression block dimensions.
Definition: WASP.h:638
virtual int DefVar(string name, int xtype, vector< string > dimnames)
Define a variable.
static std::vector< string > GetPaths(string path, int numfiles)
Definition: WASP.h:625
Defines simple C++ wrapper for NetCDF.
Definition: NetCDFCpp.h:43
static string AttNameVersion()
NetCDF attribute name specifying WASP version number.
Definition: WASP.h:657
static string AttNameWASP()
Definition: WASP.h:648
static string AttNameNumFiles()
NetCDF attribute name specifying number of compression files.
Definition: WASP.h:641
#define WASP_API
static string AttNameDimNames()
NetCDF attribute name specifying names of uncompressed dimensions.
Definition: WASP.h:651
Definition: DC.h:10
static string AttNameMissingValue()
NetCDF attribute name specifying if missing data values are present.
Definition: WASP.h:654