VAPOR3 3.9.4
WASP.h
Go to the documentation of this file.
1
2#ifndef _WASP_H_
3#define _WASP_H_
4
5#include <vector>
6#include <map>
7#include <iostream>
8#include <netcdf.h>
9#include <vapor/NetCDFCpp.h>
10#include <vapor/Compressor.h>
11#include <vapor/EasyThreads.h>
12#include <vapor/utils.h>
13
14namespace VAPoR {
15
98//
100public:
111 //
112 WASP(int nthreads = 0);
113 virtual ~WASP();
114
134 //
135 virtual int Create(string path, int cmode, size_t initialsz, size_t &bufrsizehintp, int numfiles);
136
143 //
144 virtual int Open(string path, int mode);
145
147 //
148 virtual int SetFill(int fillmode, int &old_modep);
149
151 //
152 virtual int EndDef() const;
153
159 virtual int Close();
160
184 //
185 virtual int InqVarDimlens(string name, int level, vector<size_t> &dims, vector<size_t> &bs) const;
186
188 //
189 virtual int InqVarDims(string name, vector<string> &dimnames, vector<size_t> &dims) const;
190
205 virtual int InqVarCompressionParams(string name, string &wname, vector<size_t> &bs, vector<size_t> &cratios) const;
206
231 //
232 static int InqDimsAtLevel(string wname, int level, vector<size_t> dims, vector<size_t> bs, vector<size_t> &dims_at_level, vector<size_t> &bs_at_level);
233
247 //
248 virtual int InqVarNumRefLevels(string name) const;
249
270 static bool InqCompressionInfo(vector<size_t> bs, string wname, size_t &nlevels, size_t &maxcratio);
271
304 //
305 virtual int DefVar(string name, int xtype, vector<string> dimnames, string wname, vector<size_t> bs, vector<size_t> cratios);
306
321 virtual int DefVar(string name, int xtype, vector<string> dimnames, string wname, vector<size_t> bs, vector<size_t> cratios, double missing_value);
322
324 // Is this needed?
325 virtual int DefVar(string name, int xtype, vector<string> dimnames) { return (NetCDFCpp::DefVar(name, xtype, dimnames)); };
326
328 //
329 int DefDim(string name, size_t len) const;
330
336 //
337 virtual int InqVarCompressed(string varname, bool &compressed) const;
338
345 int InqVarWASP(string varname, bool &wasp) const;
346
368 //
369 virtual int OpenVarWrite(string name, int lod);
370
392 //
393 virtual int OpenVarRead(string name, int level, int lod);
394
401 //
403 virtual int CloseVar();
404
427 //
428 virtual int PutVara(vector<size_t> start, vector<size_t> count, const float *data);
429 virtual int PutVar(const float *data);
430
431 virtual int PutVara(vector<size_t> start, vector<size_t> count, const double *data);
432 virtual int PutVar(const double *data);
433
434 virtual int PutVara(vector<size_t> start, vector<size_t> count, const int *data);
435 virtual int PutVar(const int *data);
436
437 virtual int PutVara(vector<size_t> start, vector<size_t> count, const int16_t *data);
438 virtual int PutVar(const int16_t *data);
439
440 virtual int PutVara(vector<size_t> start, vector<size_t> count, const unsigned char *data);
441 virtual int PutVar(const unsigned char *data);
442
459 virtual int PutVara(vector<size_t> start, vector<size_t> count, const float *data, const unsigned char *mask);
460 virtual int PutVar(const float *data, const unsigned char *mask);
461
462 virtual int PutVara(vector<size_t> start, vector<size_t> count, const double *data, const unsigned char *mask);
463 virtual int PutVar(const double *data, const unsigned char *mask);
464
465 virtual int PutVara(vector<size_t> start, vector<size_t> count, const int *data, const unsigned char *mask);
466 virtual int PutVar(const int *data, const unsigned char *mask);
467
468 virtual int PutVara(vector<size_t> start, vector<size_t> count, const int16_t *data, const unsigned char *mask);
469 virtual int PutVar(const int16_t *data, const unsigned char *mask);
470
471 virtual int PutVara(vector<size_t> start, vector<size_t> count, const unsigned char *data, const unsigned char *mask);
472 virtual int PutVar(const unsigned char *data, const unsigned char *mask);
473
497 //
498 virtual int GetVara(vector<size_t> start, vector<size_t> count, float *data);
499 virtual int GetVara(vector<size_t> start, vector<size_t> count, double *data);
500 virtual int GetVara(vector<size_t> start, vector<size_t> count, int *data);
501 virtual int GetVara(vector<size_t> start, vector<size_t> count, int16_t *data);
502
503 virtual int GetVara(vector<size_t> start, vector<size_t> count, unsigned char *data);
504
524 //
525 virtual int GetVaraBlock(vector<size_t> start, vector<size_t> count, float *data);
526 virtual int GetVaraBlock(vector<size_t> start, vector<size_t> count, double *data);
527 virtual int GetVaraBlock(vector<size_t> start, vector<size_t> count, int *data);
528 virtual int GetVaraBlock(vector<size_t> start, vector<size_t> count, int16_t *data);
529 virtual int GetVaraBlock(vector<size_t> start, vector<size_t> count, unsigned char *data);
530
548 //
549 virtual int GetVar(float *data);
550 virtual int GetVar(double *data);
551 virtual int GetVar(int *data);
552 virtual int GetVar(int16_t *data);
553 virtual int GetVar(unsigned char *data);
554
564 //
565 virtual int CopyVar(string varname, WASP &wasp);
566
573 //
574 virtual int CopyVarFrom(string varname, NetCDFCpp &ncdf);
575
582 //
583 virtual int CopyVarTo(string varname, NetCDFCpp &ncdf);
584
595 //
596 static std::vector<string> GetPaths(string path, int numfiles)
597 {
598 if (numfiles > 1) {
599 return (mkmultipaths(path, numfiles));
600 } else {
601 std::vector<string> t(1, path);
602 return (t);
603 }
604 }
605
607 static string AttNameWavelet() { return ("WASP.Wavelet"); }
608
610 static string AttNameBlockSize() { return ("WASP.BlockSize"); }
611
613 static string AttNameNumFiles() { return ("WASP.NumFiles"); }
614
616 static string AttNameCRatios() { return ("WASP.CRatios"); }
617
620 static string AttNameWASP() { return ("WASP"); }
621
623 static string AttNameDimNames() { return ("WASP.DimNames"); }
624
626 static string AttNameMissingValue() { return ("WASP.MissingValue"); }
627
629 static string AttNameVersion() { return ("WASP.Version"); }
630
631private:
632 Wasp::EasyThreads * _et;
633 int _nthreads;
634 vector<NetCDFCpp> _ncdfcs;
635 vector<NetCDFCpp *> _ncdfcptrs; // pointers into _ncdfcs;
636 bool _waspFile; // Is this a WASP file
637 int _numfiles; // Number of NetCDF files
638 int _currentVersion; // Current WASP version number;
639 int _fileVersion; // version number of opened file;
640 Wasp::SmartBuf _blockbuf; // Dynamic storage for blocks
641 Wasp::SmartBuf _coeffbuf; // Dynamic storage wavelet coefficients
642 Wasp::SmartBuf _sigbuf; // Dynamic storage encoded signficance maps
643
644 bool _open; // compressed variable open for reading or writing?
645 string _open_wname; // wavelet name of opened variable
646 vector<size_t> _open_bs; // block size of opened variable
647 vector<size_t> _open_cratios; // compression ratios of opened variable
648 vector<size_t> _open_udims; // uncompressed dims of opened variable
649 vector<size_t> _open_dims; // compressed dims of opened variable
650 int _open_lod; // level-of-detail of opened variable
651 int _open_level; // grid refinement level of opened variable
652 bool _open_write; // opened variable open for writing?
653 bool _open_waspvar; // opened variable is a WASP variable?
654 string _open_varname; // name of opened variable
655 nc_type _open_varxtype; // external type of opened variable
656 vector<Compressor *> _open_compressors; // Compressor for opened variable
657
658 int _GetBlockAlignedDims(vector<string> dimnames, vector<size_t> bs, vector<string> &badimnames, vector<size_t> &badims) const;
659
660 int _GetCompressedDims(vector<string> dimnames, string wname, vector<size_t> bs, vector<size_t> cratios, int xtype, vector<string> &cdimnames, vector<size_t> &cdims,
661 vector<string> &encoded_dim_names, vector<size_t> &encoded_dims) const;
662
663 int _InqDimlen(string name, size_t &len) const;
664
665 void _get_encoding_vectors(string wname, vector<size_t> bs, vector<size_t> cratios, int xtype, vector<size_t> &ncoeffs, vector<size_t> &encoded_dims) const;
666
667 bool _validate_compression_params(string wname, vector<size_t> dims, vector<size_t> bs, vector<size_t> cratios) const;
668
669 bool _validate_put_vara_compressed(vector<size_t> start, vector<size_t> count, vector<size_t> bs, vector<size_t> udims, vector<size_t> cratios) const;
670
671 bool _validate_get_vara_compressed(vector<size_t> start, vector<size_t> count, vector<size_t> bs, vector<size_t> udims, vector<size_t> cratios, bool unblock) const;
672
673 int _get_compression_params(string name, vector<size_t> &bs, vector<size_t> &cratios, vector<size_t> &udims, vector<size_t> &dims, string &wname) const;
674
675 template<class T, class U> int _GetVara(vector<size_t> start, vector<size_t> count, bool unblock, T *data, U dummy);
676
677 template<class T> int _GetVara(vector<size_t> start, vector<size_t> count, bool unblock_flag, T *data);
678
679 static void _dims_at_level(vector<size_t> dims, vector<size_t> bs, int level, string wname, vector<size_t> &dims_level, vector<size_t> &bs_level);
680
681 static vector<string> mkmultipaths(string path, int n);
682
683 template<class T, class U> int _PutVara(vector<size_t> start, vector<size_t> count, const T *data, const unsigned char *mask, U dummy);
684
685 template<class T> int _PutVara(vector<size_t> start, vector<size_t> count, const T *data, const unsigned char *mask);
686
687 template<class T> int _CopyHyperSlice(string varname, NetCDFCpp &src_ncdf, NetCDFCpp &dst_ncdf, vector<size_t> start, vector<size_t> count, T *buf) const;
688
689 int _CopyVar(string varname, NetCDFCpp &src_ncdf, NetCDFCpp &dst_ncdf) const;
690
691 // Determine POD type
692 //
693 int _NetCDFType(float dummy) { return NC_FLOAT; }
694 int _NetCDFType(char dummy) { return NC_BYTE; }
695 int _NetCDFType(double dummy) { return NC_DOUBLE; }
696 int _NetCDFType(unsigned char dummy) { return NC_UBYTE; }
697 int _NetCDFType(int16_t dummy) { return NC_SHORT; }
698 int _NetCDFType(int dummy) { return NC_INT; }
699 int _NetCDFType(long dummy) { return NC_INT64; }
700};
701
702} // namespace VAPoR
703
704namespace Wasp {
705}
706
707#endif // _WASP_H_
Defines simple C++ wrapper for NetCDF.
Definition: NetCDFCpp.h:44
Implements WASP compression conventions for NetCDF.
Definition: WASP.h:99
virtual ~WASP()
virtual int OpenVarWrite(string name, int lod)
virtual int CloseVar()
virtual int CopyVarTo(string varname, NetCDFCpp &ncdf)
static bool InqCompressionInfo(vector< size_t > bs, string wname, size_t &nlevels, size_t &maxcratio)
virtual int PutVar(const float *data)
static string AttNameCRatios()
NetCDF attribute name specifying compression ratios.
Definition: WASP.h:616
virtual int CopyVarFrom(string varname, NetCDFCpp &ncdf)
virtual int PutVar(const double *data)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const int *data, const unsigned char *mask)
virtual int PutVar(const float *data, const unsigned char *mask)
virtual int InqVarCompressionParams(string name, string &wname, vector< size_t > &bs, vector< size_t > &cratios) const
virtual int PutVar(const int *data)
virtual int GetVar(int *data)
virtual int GetVaraBlock(vector< size_t > start, vector< size_t > count, double *data)
virtual int GetVara(vector< size_t > start, vector< size_t > count, unsigned char *data)
virtual int PutVar(const int *data, const unsigned char *mask)
static string AttNameNumFiles()
NetCDF attribute name specifying number of compression files.
Definition: WASP.h:613
virtual int PutVara(vector< size_t > start, vector< size_t > count, const double *data)
virtual int GetVar(int16_t *data)
virtual int InqVarNumRefLevels(string name) const
virtual int GetVar(double *data)
virtual int DefVar(string name, int xtype, vector< string > dimnames)
Define a variable.
Definition: WASP.h:325
virtual int Open(string path, int mode)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const float *data, const unsigned char *mask)
virtual int GetVaraBlock(vector< size_t > start, vector< size_t > count, unsigned char *data)
virtual int Create(string path, int cmode, size_t initialsz, size_t &bufrsizehintp, int numfiles)
virtual int PutVar(const unsigned char *data)
int DefDim(string name, size_t len) const
Define a dimension.
virtual int PutVar(const int16_t *data)
virtual int InqVarDims(string name, vector< string > &dimnames, vector< size_t > &dims) const
static string AttNameVersion()
NetCDF attribute name specifying WASP version number.
Definition: WASP.h:629
virtual int GetVar(unsigned char *data)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const int *data)
int InqVarWASP(string varname, bool &wasp) const
virtual int PutVara(vector< size_t > start, vector< size_t > count, const float *data)
virtual int GetVara(vector< size_t > start, vector< size_t > count, float *data)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const int16_t *data)
static string AttNameMissingValue()
NetCDF attribute name specifying if missing data values are present.
Definition: WASP.h:626
virtual int InqVarCompressed(string varname, bool &compressed) const
virtual int PutVar(const double *data, const unsigned char *mask)
static string AttNameWASP()
Definition: WASP.h:620
virtual int PutVar(const int16_t *data, const unsigned char *mask)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const double *data, const unsigned char *mask)
virtual int GetVaraBlock(vector< size_t > start, vector< size_t > count, int16_t *data)
virtual int GetVara(vector< size_t > start, vector< size_t > count, int16_t *data)
static int InqDimsAtLevel(string wname, int level, vector< size_t > dims, vector< size_t > bs, vector< size_t > &dims_at_level, vector< size_t > &bs_at_level)
static string AttNameWavelet()
NetCDF attribute name specifying Wavelet name.
Definition: WASP.h:607
virtual int OpenVarRead(string name, int level, int lod)
static std::vector< string > GetPaths(string path, int numfiles)
Definition: WASP.h:596
static string AttNameBlockSize()
NetCDF attribute name specifying compression block dimensions.
Definition: WASP.h:610
virtual int PutVar(const unsigned char *data, const unsigned char *mask)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const int16_t *data, const unsigned char *mask)
virtual int CopyVar(string varname, WASP &wasp)
virtual int InqVarDimlens(string name, int level, vector< size_t > &dims, vector< size_t > &bs) const
virtual int SetFill(int fillmode, int &old_modep)
Set the fill value.
virtual int GetVaraBlock(vector< size_t > start, vector< size_t > count, int *data)
virtual int Close()
virtual int EndDef() const
End the metadata definition section.
WASP(int nthreads=0)
virtual int GetVara(vector< size_t > start, vector< size_t > count, double *data)
virtual int DefVar(string name, int xtype, vector< string > dimnames, string wname, vector< size_t > bs, vector< size_t > cratios)
virtual int GetVar(float *data)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const unsigned char *data)
virtual int DefVar(string name, int xtype, vector< string > dimnames, string wname, vector< size_t > bs, vector< size_t > cratios, double missing_value)
virtual int GetVaraBlock(vector< size_t > start, vector< size_t > count, float *data)
static string AttNameDimNames()
NetCDF attribute name specifying names of uncompressed dimensions.
Definition: WASP.h:623
virtual int GetVara(vector< size_t > start, vector< size_t > count, int *data)
virtual int PutVara(vector< size_t > start, vector< size_t > count, const unsigned char *data, const unsigned char *mask)
#define WASP_API
Definition: common.h:74
Definition: CFuncs.h:31