Blame view

src/ParamOutputImpl/Download/FileWriterCDF.hh 7.44 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * FileWriterCDF.hh
 *
 *  Created on: 08 oct. 2014
 *      Author: AKKA
 */

#ifndef FILEWRITERCDF_HH_
#define FILEWRITERCDF_HH_

#include "FileWriter.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"

#include "cdf.h"

#include <map>

7929a8a9   Benjamin Renard   CDF writer optimi...
21
22
#define NB_RECORDS_BUFFER 100000

1a6e8df3   Erdogan Furkan   7875 - time inter...
23
namespace AMDA
fbe3c2bb   Benjamin Renard   First commit
24
{
1a6e8df3   Erdogan Furkan   7875 - time inter...
25
	namespace ParamOutputImpl
fbe3c2bb   Benjamin Renard   First commit
26
	{
1a6e8df3   Erdogan Furkan   7875 - time inter...
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
		namespace Download
		{
			namespace FileWriter
			{

				using namespace AMDA::Info;

				/**
				 * @class FileWriterCDF
				 * @brief Implementation of FileWriter for CDF file format.
				 * @details
				 */
				class FileWriterCDF : public FileWriter
				{
				public:
					/*
					 * structure used to store variable info
					 */
					typedef struct
					{
						long varNum;
						long recNum;
						long type;
						long dim1Size;
						long dim2Size;
						long lastPushRec = 0;
						long bufferNbRec = 0;
						long numBytes = 0;
1e085406   Furkan   Adding ValidMin/M...
55
56
						void *validMin = NULL;
						void *validMax = NULL;
256d4fda   Furkan   The end is close
57
						std::string format;
5291eadc   Erdogan Furkan   For now - Ca avance
58
						bool isTableParam = false;
1a6e8df3   Erdogan Furkan   7875 - time inter...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
						void *buffer = NULL;
					} ParamCDFVar;

					/*
					 * @brief Constructor
					 */
					FileWriterCDF(AMDA::Parameters::ParameterManager &pParameterManager);

					/*
					 * @brief Destructor
					 */
					virtual ~FileWriterCDF(void);

					/*
					 * @overload FileWriter::getExtension - method to get file format extension
					 */
					virtual std::string getExtension(void);

					/*
					 * @overload FileWriter::createNewFile - Create a new CDF file
					 */
256d4fda   Furkan   The end is close
80
					virtual bool createNewFile(std::string filePath, std::string filePrefix="");
1a6e8df3   Erdogan Furkan   7875 - time inter...
81
82
83
84
85
86
87
88
89
90

					/*
					 * @overload FileWriter::closeFile - Close current opened CDF file
					 */
					virtual void closeFile(void);

					/*
					 * @overload FileWriter::addParameter - Add an output parameter in CDF file
					 */
					virtual bool addParameter(ParamProperties *paramProp, AMDA::Common::ParameterIndexComponentList &indexList,
5291eadc   Erdogan Furkan   For now - Ca avance
91
											  FileDataType type, bool isFirstParam, int dim1Size = 1, int dim2Size = 1, bool isTableParam=false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
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

					/*
					 * @overload FileWriter::isInfoInSeparateFile - Function use to know if info must be write in a separate file
					 */
					virtual bool isInfoInSeparateFile(bool separateInfoFile, bool onlyOneInterval, OutputStructure outputStructure);

					/*
					 * @overload FileWriter::writeError - Write an error message in the CDF file
					 */
					virtual bool writeError(std::string msg);

					/*
					 * @overload FileWriter::writeAMDAInfo - Write an AMDA info bloc for CDF file
					 */
					virtual bool writeAMDAInfo(std::string version, std::string createdby, std::string acknowledgement);

					/*
					 * @overload FileWriter::writeRequestInfo - Write a request info bloc for CDF file
					 */
					virtual bool writeRequestInfo(std::string structure, std::string timeFormat,
												  int timeResolution, std::string outputParams, std::string ttName);

					/*
					 * @overload FileWriter::writeParamsInfo - Write a parameter info bloc for CDF file
					 */
					virtual bool writeParamsInfo(ParamPropertiesList &paramPropertiesList, OutputStructure outputStructure,
												 std::string currentParamId = "");

					/*
					 * @overload FileWriter::writeIntervalInfo - Write an interval info bloc for CDF file
					 */
					virtual bool writeIntervalInfo(std::string startTime, std::string stopTime, bool isSeveralIntervals);

					/*
					 * @overload FileWriter::writeTimeData - Write a time data in the CDF file
					 */
					virtual bool writeTimeData(std::string paramId, double data, OutputFormatTime timeFormat, bool isFirstParam);

					/*
					 * @overload FileWriter::writeFloatData - Write a float data in the CDF file
					 */
					virtual bool writeFloatData(std::string paramId, int varIndex, float data, bool precision);

					/*
					 * @overload FileWriter::writeShortData - Write a short data in the CDF file
					 */
					virtual bool writeShortData(std::string paramId, int varIndex, short data, bool precision);

					/*
					 * @overload FileWriter::writeIntData - Write a int data in the CDF file
					 */
					virtual bool writeIntData(std::string paramId, int varIndex, int data, bool precision);

					/*
					 * @overload FileWriter::writeDoubleData - Write a double data in the CDF file
					 */
					virtual bool writeDoubleData(std::string paramId, int varIndex, double data, bool precision);

					/*
					 * @overload FileWriter::writeLongDoubleData - Write a long double data in the CDF file
					 */
					virtual bool writeLongDoubleData(std::string paramId, int varIndex, long double data, bool precision);

					/*
					 * @overload FileWriter::writeLogicalData - Write a logical data in the CDF file
					 */
					virtual bool writeLogicalData(std::string paramId, int varIndex, AMDA::Parameters::LogicalData data, bool precision);

					/*
					 * @overload FileWriter::goToNextRecord - Prepare CDF writer to write the next record
					 */
					virtual bool goToNextRecord(std::string paramId, bool isFirstParam);

					/*
					 * @brief Flush data in current opened file
					 */
					virtual bool flushData(std::string paramId, bool isFirstParam);

					/*
					 * @overload FileWriter::finalize - Finalize CDF file write.
					 */
					virtual bool finalize(bool isInfoFile = false);

				protected:
					/*
					 * @brief Write one data in the CDF file
					 */
					bool writeOneData(std::string paramId, int varIndex, void *data);

					/*
					 * @brief Add a parameter in the CDF file
					 */
					bool addCDFParameter(std::string outputId, AMDA::Common::ParameterIndexComponentList &indexList,
5291eadc   Erdogan Furkan   For now - Ca avance
185
										 FileDataType type, int dim1Size, int dim2Size, bool isTableParam);
1a6e8df3   Erdogan Furkan   7875 - time inter...
186
187
188
189
190

					/*
					 * @brief Create a variable in the CDF file
					 */
					bool createCDFVar(const char *name, FileDataType type, long varDim1Size, long varDim2Size,
5291eadc   Erdogan Furkan   For now - Ca avance
191
									  ParamCDFVar &cdfVar, bool isConst=false, bool isTableParam =false);
1a6e8df3   Erdogan Furkan   7875 - time inter...
192
193
194
195
196
197
198
199

					/*
					 * @brief Add an attribute in the CDF file
					 */
					bool addAttribute(std::string attName, std::string attVal,
									  long scope, long varNum = 0);

					/*
c2e1eb0f   Erdogan Furkan   More compliant now
200
201
202
203
204
					 * @brief Add an attribute in the CDF file
					 */
					bool addAttribute(std::string attName, double attVal,
									  long scope, long varNum = 0);

1e085406   Furkan   Adding ValidMin/M...
205
206
207
					bool addAttribute(std::string attName, void* attBuffer,
												 long scope, long type, long varNum =0);

c2e1eb0f   Erdogan Furkan   More compliant now
208
					/*
1a6e8df3   Erdogan Furkan   7875 - time inter...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
					 * @brief Write mission info attributes in the CDF file
					 */
					bool writeMissionInfo(MissionInfoSPtr missionInfo, long varNum);

					/*
					 * @brief Write instrument info attributes in the CDF file
					 */
					bool writeInstrumentInfo(InstrumentInfoSPtr instrumentInfo, long varNum);

					/*
					 * @brief Write dataset info attributes in the CDF file
					 */
					bool writeDatasetInfo(DataSetInfoSPtr datasetInfo, long varNum);

					/*
					 * @brief Write parameter info attributes in the CDF file
					 */
					bool writeParameterInfo(ParamInfoSPtr parameterInfo, long varNum);

					/*
					 * @brief Write parameter table info attributes in the CDF file
					 */
					bool writeTableParamsInfo(std::vector<std::string> tableParams, int level);

c2e1eb0f   Erdogan Furkan   More compliant now
233
234
					virtual void writeTimeInfo();

1a6e8df3   Erdogan Furkan   7875 - time inter...
235
236
237
238
					/*
					 * @brief CDF identifier
					 */
					CDFid _cdfid;
1a6e8df3   Erdogan Furkan   7875 - time inter...
239
240
241
242
					/*
					 * @brief Map of CDF var info
					 */
					std::map<std::string, ParamCDFVar> _cdfVarMap;
5a693c10   Erdogan Furkan   For now
243

c2e1eb0f   Erdogan Furkan   More compliant now
244
245

					std::string _fileName;
256d4fda   Furkan   The end is close
246
					std::string _filePrefix;
c2e1eb0f   Erdogan Furkan   More compliant now
247

5a693c10   Erdogan Furkan   For now
248
249
250
				private:
					

1a6e8df3   Erdogan Furkan   7875 - time inter...
251
252
253
254
255
				};

			} /* namespace FileWriter */
		}	  /* namespace Download */
	}		  /* namespace ParamOutputImpl */
fbe3c2bb   Benjamin Renard   First commit
256
257
258
} /* namespace AMDA */

#endif /* FILEWRITERCDF_HH_ */