FileWriterCDFISTP.cc
7.32 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
/**
* FileWriterCDFISTP.cc
*
* Created on: 28 feb. 2022
* Author: AKKA
*/
#include "FileWriterCDFISTP.hh"
#include "FileWriterCDF.hh"
#include "TimeUtil.hh"
#include "FileWriter.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"
#include <sstream>
#include <cstring>
#include <stdlib.h>
#include <boost/cast.hpp>
#define CDF_TIME_VAR "AMDA_TIME"
namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
namespace FileWriter {
using namespace AMDA::Info;
FileWriterCDFISTP::FileWriterCDFISTP(AMDA::Parameters::ParameterManager& pParameterManager) :
FileWriterCDF(pParameterManager)
{
}
FileWriterCDFISTP::~FileWriterCDFISTP(void)
{
closeFile();
}
std::string FileWriterCDFISTP::getExtension(void)
{
return "cdf";
}
void FileWriterCDFISTP::addInfoInMap(std::string key, std::string value){
_infoMap.push_back(std::pair<std::string,std::string>(key,value));
}
void FileWriterCDFISTP::writeParamVariableAttributes(ParamInfoSPtr paramInfo, std::string paramId)
{
int varNum = _cdfVarMap[paramId].varNum;
addInfoInMap("CATDESC", paramInfo->getName());
addInfoInMap("DATA", "NaN");
if(paramInfo->getTables().size() > 0){
addInfoInMap("DISPLAY_TYPE", "spectrogram");
}
else{
addInfoInMap("DISPLAY_TYPE", "time_series");
}
addInfoInMap("FIELDNAM", paramInfo->getId());
addInfoInMap("FILLVAL", std::to_string(paramInfo->getFillValue()));
addInfoInMap("FORMAT", "ToDo");
//addInfoInMap("FORM_PTR", "time_series");
addInfoInMap("LABLAXIS", paramInfo->getShortName());
addInfoInMap("LABL_PTR_1", "ToDo");
addInfoInMap("LABL_PTR_2", "ToDo");
addInfoInMap("LABL_PTR_3", "ToDo");
addInfoInMap("REPRESENTATION_i", paramInfo->getComponents());
addInfoInMap("SI_CONVERSION", paramInfo->getSiConversion());
addInfoInMap("SIZES", "ToDo");
addInfoInMap("TENSOR_FRAME", paramInfo->getCoordinatesSystem());
addInfoInMap("TENSOR_ORDER", std::to_string(paramInfo->getTensorOrder()));
addInfoInMap("UNITS", paramInfo->getUnits());
addInfoInMap("VALID_MIN", "-Inf");
addInfoInMap("VALID_MAX", "+Inf");
addInfoInMap("VALUE_TYPE", "ToDo");
(_cdfVarMap[paramId].isTableParam) ? addInfoInMap("VAR_TYPE", "support_data") : addInfoInMap("VAR_TYPE", "data");
addInfoInMap("DEPEND_0", CDF_TIME_VAR);
for (auto info : _infoMap)
addAttribute(info.first, info.second, VARIABLE_SCOPE, varNum);
}
bool FileWriterCDFISTP::writeTableParamsInfo(std::map<int, boost::shared_ptr<ParamTable>> &dependTables, std::string currentParamId)
{
for (auto dependTable : dependTables)
{
if(dependTable.second != nullptr)
{
if (!dependTable.second->isVariable(&_parameterManager))
{
std::string tableLabel = dependTable.second->getName(&_parameterManager);
std::string tableName = currentParamId;
tableName += "_";
tableName += tableLabel;
int tableSize = dependTable.second->getSize(&_parameterManager);
std::string tableUnits = dependTable.second->getUnits(&_parameterManager);
long dimSizes[1] = {tableSize};
long dimVarys[1] = {VARY};
long recVary= {NOVARY};
long tableNum = 0;
std::string dependName = "DEPEND_";
dependName += std::to_string(dependTable.first +1);
addAttribute(dependName, tableName, VARIABLE_SCOPE, _cdfVarMap[currentParamId].varNum);
// Creation of the new parameter.
CDFstatus status = CDFcreatezVar(FileWriterCDF::_cdfid, tableName.c_str(), CDF_DOUBLE, 1, 1L,
dimSizes, recVary, dimVarys, &tableNum);
if (status == CDF_OK)
{
double* paramList = (double*)malloc(tableSize*sizeof(double));
for (int i = 0; i <tableSize; ++i ){
AMDA::Info::t_TableBound minMax = dependTable.second->getBound(&_parameterManager, i);
paramList[i] = minMax.min+(minMax.max-minMax.min)/2;
}
status = CDFputzVarRecordData(_cdfid, tableNum, 0, (void*) paramList);
free(paramList);
addAttribute("LABLAXIS", tableLabel, VARIABLE_SCOPE, tableNum);
addAttribute("UNITS", tableUnits, VARIABLE_SCOPE, tableNum);
addAttribute("VAR_TYPE", "support_data", VARIABLE_SCOPE, tableNum);
}
}
else{
//ParameterSPtr p = _parameterManager.getParameter(currentParamId);
AMDA::Parameters::ParameterSPtr paramTable = dependTable.second->createRelatedParameter(&_parameterManager);
std::string dependName = "DEPEND_";
dependName += std::to_string(dependTable.first +1);
addAttribute(dependName, paramTable->getId(), VARIABLE_SCOPE, _cdfVarMap[currentParamId].varNum);
// addAttribute("LABLAXIS", tableLabel, VARIABLE_SCOPE, tableNum);
// addAttribute("UNITS", tableUnits, VARIABLE_SCOPE, tableNum);
// addAttribute("VAR_TYPE", "support_data", VARIABLE_SCOPE, tableNum);
// }
}
}
}
}
bool FileWriterCDFISTP::writeParamsInfo(ParamPropertiesList ¶mPropertiesList, OutputStructure outputStructure,
std::string currentParamId)
{
for (auto paramProperties : paramPropertiesList)
{
if ((outputStructure == ONE_FILE_PER_PARAMETER_PER_INTERVAL) &&
(currentParamId != paramProperties->getOutputId()))
// add info only for current parameter
continue;
ParameterSPtr p = _parameterManager.getParameter(paramProperties->getOutputId());
AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
writeParamVariableAttributes(paramInfo, paramProperties->getOutputId());
if(paramInfo != nullptr){
// Adding DEPEND_S, only for non-variable case.
writeTableParamsInfo(paramInfo->getTables(), paramProperties->getOutputId());
}
}
return true;
}
/*bool FileWriterCDFISTP::writeMissionInfo(MissionInfoSPtr missionInfo, long varNum)
{
if (missionInfo == nullptr) {
std::cout << std::endl << std::endl << std::endl << "FER - HAHAHAHA" << std::endl << std::endl << std::endl<< std::endl;
addAttribute("Source_name", "unk>Unknown mission", GLOBAL_SCOPE);
return false;
}
std::vector<std::pair<std::string,std::string>> infoMap = missionInfo->getInfoMap();
for (auto info : infoMap)
std::cout << std::endl << std::endl << std::endl << "FER - " << &info << std::cout << std::endl << std::endl << std::endl << std::endl;
//for (auto info : infoMap)
// if(info.first == "MISSION_NAME")
// addAttribute(info.first + ">" + info["MISSION_DESCRIPTION"]);
//write info about mission
// std::vector<std::pair<std::string,std::string>> infoMap = missionInfo->getInfoMap();
//
// for (auto info : infoMap)
// addAttribute(info.first, info.second, VARIABLE_SCOPE, varNum);
// return true;
// }
return true;
}*/
} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */