FileReaderCDF.hh
5.5 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* FileReaderCDF.hh
*
* Created on: Nov 24, 2014
* Author: AKKA
*/
#ifndef FILEREADERCDF_HH_
#define FILEREADERCDF_HH_
#include "FileReaderAbstract.hh"
#include "cdf.h"
namespace AMDA {
namespace LocalFileInterface {
/*
* @brief Implementation of the class FileReaderAbstract to load a CDF file format
*/
class FileReaderCDF : public FileReaderAbstract
{
public:
/*
* @brief Constructor
*/
FileReaderCDF();
/*
* @brief Destructor
*/
virtual ~FileReaderCDF();
/*
* @brief Open a CDF file
*/
virtual bool open(std::string filePath);
/*
* @brief Close the CDF file
*/
virtual bool close(void);
/*
* @brief Test if a CDF file is currently opened
*/
virtual bool isOpened(void);
/*
* @brief Get the id of the time param to use. For the CDF format, it's the first CDF_EPOCH var
*/
virtual std::string getTimeParamId(void);
/*
* @brief Get a param type and a param size in the CDF 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 CDF file
*/
virtual int getRecordIndex(std::string& timeId, double time);
/*
* @brief Get a param packet from the CDF file
*/
virtual FileReaderStatus getParamPacketData(std::string& timeId, std::string& paramId,
int recordIndex, double stopTime, LocalParamDataPacket *packet);
protected:
/*
* @brief TimeStamp (Unix time) to EPOCH time conversion
*/
double timeStampToEPOCHTime(double timeStamp);
/*
* @brief EPOCH time to TimeStamp conversion
*/
double epochTimeToTimeStamp(double epochTime);
private:
/*
* @brief CDF var type : rVariable or zVariable
*/
typedef enum {CDFVT_R,CDFVT_Z} CDFVarType;
/*
* @brief Working structure to contain CDF variable info
*/
typedef struct
{
//variable name
char _name[CDF_VAR_NAME_LEN256+1];
//rVariable or zVariable
CDFVarType _type;
//variable number
long _num;
//data type
long _dataType;
//number of bytes for the data type
long _numBytes;
//number of elements (of the data type)
long _numElts;
//number of dimensions
long _numDims;
//dimension sizes
long _dimSizes[CDF_MAX_DIMS];
//record variance
long _recVary;
//dimension variances
long _dimVarys[CDF_MAX_DIMS];
//maximum record number
long _maxRecNum;
} CDFVarInfo;
/*
* @brief Working buffers container
*/
class CDFWorkingBuffers
{
public:
/*
* @brief Buffer type:
*/
typedef enum {
//buffer used to store time data
BUFFER_TIME,
//buffer used to store param data
BUFFER_DATA,
//buffer used to store packet data for one record
BUFFER_PACKETREC
} BufferType;
/*
* @brief Constructor
*/
CDFWorkingBuffers() : _timeBuffer(NULL), _dataBuffer(NULL), _packetRecBuffer(NULL)
{
}
/*
* @brief Destructor
*/
~CDFWorkingBuffers()
{
//free all buffers
if (_timeBuffer != NULL)
free(_timeBuffer);
if (_dataBuffer != NULL)
free(_dataBuffer);
if (_packetRecBuffer != NULL)
free(_packetRecBuffer);
}
/*
* @brief Get buffer pointer from a buffer type
*/
void* getBuffer(BufferType type)
{
switch (type)
{
case BUFFER_TIME:
return _timeBuffer;
case BUFFER_DATA:
return _dataBuffer;
case BUFFER_PACKETREC:
return _packetRecBuffer;
}
return NULL;
}
/*
* @brief Reallocate a buffer from a buffer type
*/
void reallocBuffer(BufferType type, long size)
{
switch (type)
{
case BUFFER_TIME:
if (_timeBuffer != NULL)
free(_timeBuffer);
_timeBuffer = malloc(size);
break;
case BUFFER_DATA:
if (_dataBuffer != NULL)
free(_dataBuffer);
_dataBuffer = malloc(size);
break;
case BUFFER_PACKETREC:
if (_packetRecBuffer != NULL)
free(_packetRecBuffer);
_packetRecBuffer = malloc(size);
break;
}
}
private:
/*
* @brief Buffer for time data
*/
void* _timeBuffer;
/*
* @brief Buffer for param data
*/
void* _dataBuffer;
/*
* @brief Buffer for one record packet data
*/
void* _packetRecBuffer;
};
/*
* @brief CDF identifier
*/
CDFid _cdfid;
/*
* @brief Working buffers container
*/
boost::shared_ptr<CDFWorkingBuffers> _workingBuffers;
/*
* @brief Get CDF variable Info from param name
*/
bool getCDFVarInfo(std::string paramName, CDFVarInfo& varInfo);
/*
* @brief Get CDF data for paramId from startRec to the end of the file
*/
bool getCDFData(std::string& varId, long startRec, CDFWorkingBuffers::BufferType bufferType,
long& dataType, long& numBytes, long& nbRec, long& dimSize);
/*
* @brief Extract a short to a CDF data buffer
*/
bool extractShort(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize,
long dataType, long numBytes, short& value);
/*
* @brief Extract a int to a CDF data buffer
*/
bool extractInt(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize,
long dataType, long numBytes, int& value);
/*
* @brief Extract a float to a CDF data buffer
*/
bool extractFloat(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize,
long dataType, long numBytes, float& value);
/*
* @brief Extract a int to a CDF data buffer
*/
bool extractDouble(CDFWorkingBuffers::BufferType bufferType, long recIndex, long dimIndex, long dimSize,
long dataType, long numBytes, double& value);
};
} /* LocalFileInterface */
} /* AMDA */
#endif /* FILEREADERCDF_HH_ */