Commit 1e085406405191e10e398948377dfdc1acfd4d94
1 parent
23cd82f6
Exists in
master
and in
28 other branches
Adding ValidMin/Max attributes
Showing
3 changed files
with
126 additions
and
18 deletions
Show diff stats
src/ParamOutputImpl/Download/FileWriterCDF.cc
... | ... | @@ -63,6 +63,16 @@ namespace AMDA |
63 | 63 | free(cdfVar.second.buffer); |
64 | 64 | cdfVar.second.buffer = NULL; |
65 | 65 | } |
66 | + if (cdfVar.second.validMin != NULL) | |
67 | + { | |
68 | + free(cdfVar.second.validMin); | |
69 | + cdfVar.second.validMin = NULL; | |
70 | + } | |
71 | + if (cdfVar.second.validMax != NULL) | |
72 | + { | |
73 | + free(cdfVar.second.validMax); | |
74 | + cdfVar.second.validMax = NULL; | |
75 | + } | |
66 | 76 | } |
67 | 77 | _cdfVarMap.clear(); |
68 | 78 | } |
... | ... | @@ -141,29 +151,19 @@ namespace AMDA |
141 | 151 | { |
142 | 152 | case DT_FLOAT: |
143 | 153 | cdfVar.type = CDF_FLOAT; |
144 | - cdfVar.validMax = "3.402823e+38"; | |
145 | - cdfVar.validMin = "1.175494e-38"; | |
146 | 154 | break; |
147 | 155 | case DT_SHORT: |
148 | 156 | cdfVar.type = CDF_INT2; |
149 | - cdfVar.validMax= std::to_string(SHRT_MAX); | |
150 | - cdfVar.validMin= std::to_string(SHRT_MIN); | |
151 | 157 | break; |
152 | 158 | case DT_INT: |
153 | 159 | cdfVar.type = CDF_INT4; |
154 | - cdfVar.validMax= std::to_string(INT_MAX); | |
155 | - cdfVar.validMin= std::to_string(INT_MIN); | |
156 | 160 | break; |
157 | 161 | case DT_DOUBLE: |
158 | 162 | case DT_LONGDOUBLE: |
159 | 163 | cdfVar.type = CDF_DOUBLE; |
160 | - cdfVar.validMax = "1.797693e+308"; | |
161 | - cdfVar.validMin = "2.225074e-308"; | |
162 | 164 | break; |
163 | 165 | case DT_LOGICAL: |
164 | 166 | cdfVar.type = CDF_UINT2; |
165 | - cdfVar.validMax= std::to_string(UINT_MAX); | |
166 | - cdfVar.validMin= std::to_string(0); | |
167 | 167 | break; |
168 | 168 | case DT_TIME: |
169 | 169 | switch (_outputFormatTime) { |
... | ... | @@ -178,8 +178,6 @@ namespace AMDA |
178 | 178 | default: |
179 | 179 | cdfVar.type = CDF_EPOCH; |
180 | 180 | } |
181 | - cdfVar.validMax= "ToDo"; | |
182 | - cdfVar.validMin= "ToDo"; | |
183 | 181 | break; |
184 | 182 | case DT_NONE: |
185 | 183 | cdfVar.type = CDF_CHAR; |
... | ... | @@ -224,7 +222,77 @@ namespace AMDA |
224 | 222 | return false; |
225 | 223 | } |
226 | 224 | cdfVar.buffer = malloc(varDim1Size * varDim2Size * cdfVar.numBytes * NB_RECORDS_BUFFER); |
225 | + cdfVar.validMin = malloc(cdfVar.numBytes); | |
226 | + cdfVar.validMax = malloc(cdfVar.numBytes); | |
227 | 227 | |
228 | + switch (cdfVar.type){ | |
229 | + case CDF_FLOAT: | |
230 | + { | |
231 | + float validMin = -std::numeric_limits<float>::max(); | |
232 | + float validMax = std::numeric_limits<float>::max(); | |
233 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
234 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
235 | + } | |
236 | + break; | |
237 | + case CDF_INT2: | |
238 | + { | |
239 | + short validMin = -std::numeric_limits<short>::max(); | |
240 | + short validMax = std::numeric_limits<short>::max(); | |
241 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
242 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
243 | + } | |
244 | + break; | |
245 | + case CDF_INT4: | |
246 | + { | |
247 | + int validMin = -std::numeric_limits<int>::max(); | |
248 | + int validMax = std::numeric_limits<int>::max(); | |
249 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
250 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
251 | + } | |
252 | + break; | |
253 | + case CDF_DOUBLE: | |
254 | + { | |
255 | + double validMin = -std::numeric_limits<double>::max(); | |
256 | + double validMax = std::numeric_limits<double>::max(); | |
257 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
258 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
259 | + } | |
260 | + break; | |
261 | + case CDF_UINT2: | |
262 | + { | |
263 | + unsigned short validMin = 0; | |
264 | + unsigned short validMax = std::numeric_limits<unsigned short>::max(); | |
265 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
266 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
267 | + } | |
268 | + break; | |
269 | + case CDF_EPOCH16: | |
270 | + { | |
271 | + double validMin[2] = {0,0}; | |
272 | + double validMax[2] = {0,0}; | |
273 | + computeEPOCH16(1970,1,1,0,0,0,0,0,0,0,validMin); | |
274 | + computeEPOCH16(2050,12,31,23,59,59,999,999,999,999,validMax); | |
275 | + memcpy(cdfVar.validMin,validMin,cdfVar.numBytes); | |
276 | + memcpy(cdfVar.validMax,validMax,cdfVar.numBytes); | |
277 | + } | |
278 | + break; | |
279 | + case CDF_TIME_TT2000: | |
280 | + { | |
281 | + long long validMin = computeTT2000(1970,1,1,TT2000END); | |
282 | + long long validMax = computeTT2000(2050,12,31,TT2000END); | |
283 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
284 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
285 | + } | |
286 | + break; | |
287 | + case CDF_EPOCH: | |
288 | + { | |
289 | + double validMin = computeEPOCH(1970,1,1,0,0,0,0); | |
290 | + double validMax = computeEPOCH(2050,12,31,23,59,59,999); | |
291 | + memcpy(cdfVar.validMin,&validMin,cdfVar.numBytes); | |
292 | + memcpy(cdfVar.validMax,&validMax,cdfVar.numBytes); | |
293 | + } | |
294 | + break; | |
295 | + } | |
228 | 296 | status = CDFcreatezVar(_cdfid, name, cdfVar.type, numElts, numDims, |
229 | 297 | dimSizes, recVary, dimVarys, &cdfVar.varNum); |
230 | 298 | |
... | ... | @@ -467,6 +535,33 @@ namespace AMDA |
467 | 535 | return (status == CDF_OK); |
468 | 536 | } |
469 | 537 | |
538 | + bool FileWriterCDF::addAttribute(std::string attName, void* attBuffer, | |
539 | + long scope, long type, long varNum) | |
540 | + { | |
541 | + boost::mutex::scoped_lock scoped_lock(ParameterManager::mutexCDFLib); | |
542 | + if (_cdfid == NULL) | |
543 | + return false; | |
544 | + | |
545 | + CDFstatus status; | |
546 | + | |
547 | + long attNum = CDFgetAttrNum(_cdfid, (char *)attName.c_str()); | |
548 | + | |
549 | + if (attNum < 0) | |
550 | + { | |
551 | + status = CDFcreateAttr(_cdfid, (char *)attName.c_str(), scope, &attNum); | |
552 | + | |
553 | + if (status != CDF_OK) | |
554 | + return false; | |
555 | + } | |
556 | + | |
557 | + if (scope == GLOBAL_SCOPE) | |
558 | + status = CDFputAttrgEntry(_cdfid, attNum, 0, type, 1, attBuffer); | |
559 | + else | |
560 | + status = CDFputAttrzEntry(_cdfid, attNum, varNum, type, 1, attBuffer); | |
561 | + | |
562 | + return (status == CDF_OK); | |
563 | + } | |
564 | + | |
470 | 565 | |
471 | 566 | bool FileWriterCDF::writeTimeData(std::string /* paramId */, double data, OutputFormatTime /* timeFormat */, bool isFirstParam) |
472 | 567 | { | ... | ... |
src/ParamOutputImpl/Download/FileWriterCDF.hh
... | ... | @@ -52,8 +52,8 @@ namespace AMDA |
52 | 52 | long lastPushRec = 0; |
53 | 53 | long bufferNbRec = 0; |
54 | 54 | long numBytes = 0; |
55 | - std::string validMin; | |
56 | - std::string validMax; | |
55 | + void *validMin = NULL; | |
56 | + void *validMax = NULL; | |
57 | 57 | bool isTableParam = false; |
58 | 58 | void *buffer = NULL; |
59 | 59 | } ParamCDFVar; |
... | ... | @@ -201,6 +201,9 @@ namespace AMDA |
201 | 201 | bool addAttribute(std::string attName, double attVal, |
202 | 202 | long scope, long varNum = 0); |
203 | 203 | |
204 | + bool addAttribute(std::string attName, void* attBuffer, | |
205 | + long scope, long type, long varNum =0); | |
206 | + | |
204 | 207 | /* |
205 | 208 | * @brief Write mission info attributes in the CDF file |
206 | 209 | */ | ... | ... |
src/ParamOutputImpl/Download/FileWriterCDFISTP.cc
... | ... | @@ -80,8 +80,17 @@ namespace AMDA { |
80 | 80 | addAttribute("FIELDNAM", "Time", VARIABLE_SCOPE, varNum); |
81 | 81 | addAttribute("FORMAT", "ToDo", VARIABLE_SCOPE, varNum); |
82 | 82 | addAttribute("VAR_TYPE", "support_data", VARIABLE_SCOPE, varNum); |
83 | - addAttribute("UNITS", "ToDo", VARIABLE_SCOPE, varNum); | |
84 | - addAttribute("TIME_BASE", "ToDO", VARIABLE_SCOPE, varNum); | |
83 | + addAttribute("UNITS", "ns", VARIABLE_SCOPE, varNum); | |
84 | + | |
85 | + if(_cdfVarMap[CDF_TIME_VAR].type == CDF_TIME_TT2000){ | |
86 | + addAttribute("TIME_BASE", "J2000", VARIABLE_SCOPE, varNum); | |
87 | + addAttribute("SI_CONVERSION", "1.0E-9>Second", VARIABLE_SCOPE, varNum); | |
88 | + } | |
89 | + | |
90 | + addAttribute("TIME_BASE", "ToDo", VARIABLE_SCOPE, varNum); | |
91 | + | |
92 | + addAttribute("VALIDMIN", _cdfVarMap[CDF_TIME_VAR].validMin, VARIABLE_SCOPE, _cdfVarMap[CDF_TIME_VAR].type, varNum); | |
93 | + addAttribute("VALIDMAX", _cdfVarMap[CDF_TIME_VAR].validMax, VARIABLE_SCOPE, _cdfVarMap[CDF_TIME_VAR].type, varNum); | |
85 | 94 | } |
86 | 95 | void FileWriterCDFISTP::writeParamVariableAttributes(ParamInfoSPtr paramInfo, std::string paramId) |
87 | 96 | { |
... | ... | @@ -109,8 +118,9 @@ namespace AMDA { |
109 | 118 | addInfoInMap("TENSOR_FRAME", paramInfo->getCoordinatesSystem()); |
110 | 119 | addInfoInMap("TENSOR_ORDER", std::to_string(paramInfo->getTensorOrder())); |
111 | 120 | addInfoInMap("UNITS", paramInfo->getUnits()); |
112 | - addInfoInMap("VALIDMIN", _cdfVarMap[paramId].validMin); | |
113 | - addInfoInMap("VALIDMAX", _cdfVarMap[paramId].validMax); | |
121 | + | |
122 | + addAttribute("VALIDMIN", _cdfVarMap[paramId].validMin, VARIABLE_SCOPE, _cdfVarMap[paramId].type, varNum); | |
123 | + addAttribute("VALIDMAX", _cdfVarMap[paramId].validMax, VARIABLE_SCOPE, _cdfVarMap[paramId].type, varNum); | |
114 | 124 | //addInfoInMap("VALUE_TYPE", "ToDo"); |
115 | 125 | if (_cdfVarMap[paramId].isTableParam) |
116 | 126 | addInfoInMap("VAR_TYPE", "support_data"); | ... | ... |