VAPOR3 3.9.4
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
11namespace VAPoR {
12
28public:
47 //
48 VDCNetCDF(int numthreads = 0, size_t master_theshold = 10 * 1024 * 1024, size_t variable_threshold = 100 * 1024 * 1024);
49 virtual ~VDCNetCDF();
50
55 virtual int GetHyperSliceInfo(string varname, int level, std::vector<size_t> &dims, size_t &nslice);
56
70 //
71 static string GetDataDir(string path);
72
89 virtual int GetPath(string varname, size_t ts, string &path, size_t &file_ts, size_t &max_ts) const;
90
92 //
93 virtual int getDimLensAtLevel(string varname, int level, std::vector<size_t> &dims_at_level, vector<size_t> &bs_at_level) const;
94
101 //
102 static bool DataDirExists(string path);
103
109 //
110 virtual int Initialize(const vector<string> &paths, const vector<string> &options = {}, AccessMode mode = VDC::R, vector<size_t> bs = {64, 64, 64}, size_t chunksizehint = 0);
111 virtual int Initialize(string path, const vector<string> &options, AccessMode mode, vector<size_t> bs = {64, 64, 64}, size_t chunksizehint = 0)
112 {
113 std::vector<string> paths;
114 paths.push_back(path);
115 return (Initialize(paths, options, mode, bs, chunksizehint));
116 }
117
121 //
122 size_t GetMasterThreshold() const { return _master_threshold; };
123
127 //
128 size_t GetVariableThreshold() const { return _variable_threshold; };
129
131 //
132 int OpenVariableWrite(size_t ts, string varname, int lod = -1);
133
134 int CloseVariableWrite(int fd) { return (closeVariable(fd)); };
135
137 //
138 int Write(int fd, const float *region) { return (_writeTemplate(fd, region)); }
139 int Write(int fd, const int *region) { return (_writeTemplate(fd, region)); }
140
141 int WriteSlice(int fd, const float *slice) { return (_writeSliceTemplate(fd, slice)); };
142 int WriteSlice(int fd, const int *slice) { return (_writeSliceTemplate(fd, slice)); };
143 int WriteSlice(int fd, const unsigned char *slice) { return (_writeSliceTemplate(fd, slice)); }
144
146 //
147 int PutVar(string varname, int lod, const float *data) { return (_putVarTemplate(varname, lod, data)); }
148 int PutVar(string varname, int lod, const int *data) { return (_putVarTemplate(varname, lod, data)); }
149
151 //
152 int PutVar(size_t ts, string varname, int lod, const float *data) { return (_putVarTemplate(ts, varname, lod, data)); }
153 int PutVar(size_t ts, string varname, int lod, const int *data) { return (_putVarTemplate(ts, varname, lod, data)); }
154
155 int CopyVar(DC &dc, string varname, int srclod, int dstlod);
156 int CopyVar(DC &dc, size_t ts, string varname, int srclod, int dstlod);
157
159 //
160 bool CompressionInfo(std::vector<size_t> bs, string wname, size_t &nlevels, size_t &maxcratio) const;
161
169 //
170 int SetFill(int fillmode);
171
172protected:
173 #ifndef DOXYGEN_SKIP_THIS
174 virtual int _WriteMasterMeta();
175 virtual int _ReadMasterMeta();
176 #endif
177
178 int openVariableRead(size_t ts, string varname, int level = 0, int lod = -1);
179
180 int closeVariable(int fd);
181
182 int readRegion(int fd, const std::vector<size_t> &min, const std::vector<size_t> &max, float *region);
183 int readRegion(int fd, const std::vector<size_t> &min, const std::vector<size_t> &max, double *region);
184 int readRegion(int fd, const std::vector<size_t> &min, const std::vector<size_t> &max, int *region);
185
186 virtual bool variableExists(size_t ts, string varname, int reflevel = 0, int lod = 0) const;
187
188private:
189 string _version;
190 WASP * _master; // Master NetCDF file
191
192 class VDCFileObject : public DC::FileTable::FileObject {
193 public:
194 VDCFileObject(size_t ts, string varname, int level, int lod, size_t file_ts, WASP *wasp_data, WASP *wasp_mask, string varname_mask, int level_mask, size_t file_ts_mask, double mv)
195 : FileObject(ts, varname, level, lod), _file_ts(file_ts), _wasp_data(wasp_data), _wasp_mask(wasp_mask), _varname_mask(varname_mask), _level_mask(level_mask), _file_ts_mask(file_ts_mask),
196 _mv(mv)
197 {
198 }
199
200 size_t GetFileTS() const { return (_file_ts); }
201 WASP * GetWaspData() const { return (_wasp_data); }
202 WASP * GetWaspMask() const { return (_wasp_mask); }
203 string GetVarnameMask() const { return (_varname_mask); }
204 int GetLevelMask() const { return (_level_mask); }
205 size_t GetFileTSMask() const { return (_file_ts_mask); }
206 double GetMissingValue() const { return (_mv); }
207
208 private:
209 size_t _file_ts;
210 WASP * _wasp_data;
211 WASP * _wasp_mask;
212 string _varname_mask;
213 int _level_mask;
214 size_t _file_ts_mask;
215 double _mv;
216 };
217
218 Wasp::SmartBuf _sb_slice_buffer;
219 Wasp::SmartBuf _mask_buffer;
220
221 size_t _chunksizehint; // NetCDF chunk size hint for file creates
222 size_t _master_threshold;
223 size_t _variable_threshold;
224 int _nthreads;
225
226 int _WriteMasterDimensions();
227 int _WriteMasterAttributes(string prefix, const map<string, Attribute> &atts);
228 int _WriteMasterAttributes();
229 int _WriteMasterMeshDefs();
230 int _WriteMasterBaseVarDefs(string prefix, const BaseVar &var);
231 int _WriteMasterCoordVarsDefs();
232 int _WriteMasterDataVarsDefs();
233
234 template<class T> int _writeTemplate(int fd, const T *data);
235
236 template<class T> int _writeSliceTemplate(int fd, const T *slice);
237
238 int _ReadMasterDimensions();
239 int _ReadMasterAttributes(string prefix, map<string, Attribute> &atts);
240 int _ReadMasterAttributes();
241 int _ReadMasterMeshDefs();
242 int _ReadMasterBaseVarDefs(string prefix, BaseVar &var);
243 int _ReadMasterCoordVarsDefs();
244 int _ReadMasterDataVarsDefs();
245
246 template<class T> int _ReadSlice(WASP *file, T *slice);
247
248 int _PutAtt(WASP *ncdf, string varname, string tag, const Attribute &attr);
249
250 int _WriteAttributes(WASP *wasp, string varname, const map<string, Attribute> &atts);
251 int _DefBaseVar(WASP *ncdf, const VDC::BaseVar &var, size_t max_ts);
252 int _DefDataVar(WASP *ncdf, const VDC::DataVar &var, size_t max_ts);
253 int _DefCoordVar(WASP *ncdf, const VDC::CoordVar &var, size_t max_ts);
254
255 bool _var_in_master(const VDC::BaseVar &var) const;
256
257 string _get_mask_varname(string varname, double &mv) const;
258
259 unsigned char *_read_mask_var(WASP *wasp, string varname, string varname_mask, vector<size_t> start, vector<size_t> count);
260
261 WASP *_OpenVariableRead(size_t ts, string varname, int clevel, int lod, size_t &file_ts);
262
263 int _ReadHelper(vector<size_t> &start, vector<size_t> &count) const;
264
265 template<class T> int _putVarTemplate(string varname, int lod, const T *data);
266
267 template<class T> int _putVarTemplate(size_t ts, string varname, int lod, const T *data);
268
269 int _copyVar0d(DC &dc, size_t ts, const BaseVar &varInfo);
270
271 template<class T>
272 int _copyVarHelper(DC &dc, int fdr, int fdw, vector<size_t> &buffer_dims, vector<size_t> &src_hslice_dims, vector<size_t> &dst_hslice_dims, size_t src_nslice, size_t dst_nslice, T *buffer);
273
274 template<class T> int _readRegionTemplate(int fd, const vector<size_t> &min, const vector<size_t> &max, T *region);
275};
276}; // namespace VAPoR
277
278#endif
A Template Method design pattern for reading a collection of data.
Definition: DC.h:150
Implements the VDC abstract class, providing storage of VDC data in NetCDF files.
Definition: VDCNetCDF.h:27
int PutVar(size_t ts, string varname, int lod, const float *data)
Definition: VDCNetCDF.h:152
int CopyVar(DC &dc, string varname, int srclod, int dstlod)
int closeVariable(int fd)
virtual int Initialize(const vector< string > &paths, const vector< string > &options={}, AccessMode mode=VDC::R, vector< size_t > bs={64, 64, 64}, size_t chunksizehint=0)
int OpenVariableWrite(size_t ts, string varname, int lod=-1)
VDCNetCDF(int numthreads=0, size_t master_theshold=10 *1024 *1024, size_t variable_threshold=100 *1024 *1024)
int WriteSlice(int fd, const float *slice)
Definition: VDCNetCDF.h:141
int PutVar(string varname, int lod, const float *data)
Definition: VDCNetCDF.h:147
int openVariableRead(size_t ts, string varname, int level=0, int lod=-1)
int Write(int fd, const int *region)
Definition: VDCNetCDF.h:139
int SetFill(int fillmode)
bool CompressionInfo(std::vector< size_t > bs, string wname, size_t &nlevels, size_t &maxcratio) const
int WriteSlice(int fd, const unsigned char *slice)
Definition: VDCNetCDF.h:143
static bool DataDirExists(string path)
virtual ~VDCNetCDF()
int readRegion(int fd, const std::vector< size_t > &min, const std::vector< size_t > &max, double *region)
size_t GetMasterThreshold() const
Definition: VDCNetCDF.h:122
int CloseVariableWrite(int fd)
Definition: VDCNetCDF.h:134
virtual int Initialize(string path, const vector< string > &options, AccessMode mode, vector< size_t > bs={64, 64, 64}, size_t chunksizehint=0)
Definition: VDCNetCDF.h:111
size_t GetVariableThreshold() const
Definition: VDCNetCDF.h:128
int readRegion(int fd, const std::vector< size_t > &min, const std::vector< size_t > &max, int *region)
virtual int GetHyperSliceInfo(string varname, int level, std::vector< size_t > &dims, size_t &nslice)
int PutVar(size_t ts, string varname, int lod, const int *data)
Definition: VDCNetCDF.h:153
virtual int getDimLensAtLevel(string varname, int level, std::vector< size_t > &dims_at_level, vector< size_t > &bs_at_level) const
virtual bool variableExists(size_t ts, string varname, int reflevel=0, int lod=0) const
virtual int GetPath(string varname, size_t ts, string &path, size_t &file_ts, size_t &max_ts) const
int WriteSlice(int fd, const int *slice)
Definition: VDCNetCDF.h:142
int PutVar(string varname, int lod, const int *data)
Definition: VDCNetCDF.h:148
int CopyVar(DC &dc, size_t ts, string varname, int srclod, int dstlod)
static string GetDataDir(string path)
int Write(int fd, const float *region)
Definition: VDCNetCDF.h:138
int readRegion(int fd, const std::vector< size_t > &min, const std::vector< size_t > &max, float *region)
Defines API for reading, writing, and appending data to a VAPOR Data Collection (Version 3)
Definition: VDC.h:165
AccessMode
Definition: VDC.h:169
Implements WASP compression conventions for NetCDF.
Definition: WASP.h:99
#define VDF_API
Definition: common.h:73