forked from pacificclimate/VIC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateIONetCDF.h
58 lines (48 loc) · 2.5 KB
/
StateIONetCDF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef STATEIONETCDF_H_
#define STATEIONETCDF_H_
#include "user_def.h" // Need to know the NETCDF_OUTPUT_AVAILABLE option here.
#if NETCDF_OUTPUT_AVAILABLE
#include <map>
#include <string>
#include "StateIO.h"
namespace netCDF {
class NcFile;
}
class StateIONetCDF: public StateIO {
public:
StateIONetCDF(std::string filename, IOType ioType, const ProgramState* state);
virtual ~StateIONetCDF();
void initializeOutput();
int write(const int* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int write(const double* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int write(const float* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int write(const bool* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int write(const char* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int read(int* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int read(double* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int read(float* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int read(bool* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
int read(char* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
StateHeader readHeader();
void notifyDimensionUpdate(StateVariables::StateVariableDimensionId dimension, int value = -1);
void initializeDimensionIndices();
int getCurrentDimensionIndex(StateVariables::StateVariableDimensionId dimension);
int seekToCell(int cellid, int* nVeg, int* nBand);
void flush();
void rewindFile();
private:
template<typename T> int generalWrite(const T* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
template<typename T> int generalRead(T* data, int numValues, const StateVariables::StateMetaDataVariableIndices id);
void populateMetaData();
void populateMetaDimensions();
void initializeLatLonDims();
std::map<StateVariables::StateMetaDataVariableIndices, StateVariableMetaData> metaData;
std::map<StateVariables::StateVariableDimensionId, StateVariableDimension> metaDimensions;
void checkAndRead(std::string name, int * storage, int length);
void openFile();
void closeFile();
netCDF::NcFile* netCDF;
std::map<StateVariables::StateVariableDimensionId, int> curDimensionIndices;
};
#endif // NETCDF_OUTPUT_AVAILABLE
#endif /* STATEIONETCDF_H_ */