FileReaderNetCDF.hh
2.35 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* FileReaderNetCDF.hh
*
* Created on: Feb 08, 2018
* Author: AKKA
*/
#ifndef FILEREADERNETCDF_HH_
#define FILEREADERNETCDF_HH_
#include "FileReaderAbstract.hh"
#include "netcdf.h"
#include <vector>
namespace AMDA {
namespace LocalFileInterface {
/*
* @brief Implementation of the class FileReaderAbstract to load a netCDF file format
*/
class FileReaderNetCDF : public FileReaderAbstract
{
public:
/*
* @brief Constructor
*/
FileReaderNetCDF();
/*
* @brief Destructor
*/
virtual ~FileReaderNetCDF();
/*
* @brief Open a netCDF file
*/
virtual bool open(std::string filePath);
/*
* @brief Close the netCDF file
*/
virtual bool close(void);
/*
* @brief Test if a netCDF file is currently opened
*/
virtual bool isOpened(void);
/*
* @brief Get the id of the time param to use.
*/
virtual std::string getTimeParamId(void);
/*
* @brief Get a param type and a param size in the netCDF file
*/
virtual bool getParamInfo(std::string& paramId, LocalParamType& paramType, int& dim1Size, int& dim2Size);
/*
* @brief Get the index of the nearest record of time (the higher one) in the netCDF file
*/
virtual int getRecordIndex(std::string& timeId, double time);
/*
* @brief Get a param packet from the netCDF file
*/
virtual FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId,
int recordIndex, double stopTime, LocalParamDataPacket *packet);
/*
* @brief Get an information
*/
virtual bool getInfo(const char* pInfoName, std::vector<double>& res);
private:
struct NetCDFDim {
int id;
char name[NC_MAX_NAME+1];
size_t length;
bool isUnlimited;
};
struct NetCDFAtt {
int id;
char name[NC_MAX_NAME+1];
size_t length;
nc_type type;
};
struct NetCDFVar {
int id;
char name[NC_MAX_NAME+1];
std::vector<int> dimids;
std::vector<NetCDFAtt> atts;
nc_type type;
void* buffer;
int valuesize;
};
struct NetCDFFile {
int id;
std::vector<NetCDFDim> dims;
std::vector<NetCDFVar> vars;
std::vector<NetCDFAtt> atts;
};
NetCDFFile _file;
void resetFile();
bool loadNetCDFFileInfo();
int getNbVarRecords(const NetCDFVar& var);
int getNbVarValuesByRecord(const NetCDFVar& var);
bool loadData(NetCDFVar& var);
std::string getErrorMessage(int status);
};
} /* LocalFileInterface */
} /* AMDA */
#endif /* FILEREADERNETCDF_HH_ */