getInputs.cpp
10.1 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
////////////////
// CPP HEADER //
////////////////
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
////////////
/// DDLIB //
////////////
#include "DD.h"
using namespace std;
///////////////////////////
/// FUNCTIONS PROTOTYPES //
//////////////////////////
void getPlasmaData(string plasmaVi, string ddStart, string ddInterval,
string timeParameter, string vnormParameter, string rampParameter,
string velParameter, string magParameter,
vector<string>& plasmaTimeArray, vector<float>& vnormArray,
vector<float>& rampArray,
vector<float>& vxArray, vector<float>& vyArray, vector<float>& vzArray,
vector<float>& bxArray, vector<float>& byArray, vector<float>& bzArray);
void getOrbitData(string satelliteVi, string ddStart, string ddInterval,
string timeParameter, string orbitParameter,
vector<string>& satelliteTimeArray,
vector<float>& x, vector<float>& y, vector<float>& z);
void getSymIndexData(string symIndexVi, string ddStart, string ddInterval,
string timeParameter, string symIndexParameter,
vector<string>& symIndexTimeArray, vector<float>& symIndexArray);
///////////
/// MAIN //
///////////
int main(int argc, char const *argv[])
{
// CHECK ARGS
if (argc != 11)
{
cerr << "[ERROR] Usage : GetData (Plasma VI) (Plasma DD Start) (Plasma DD Interval) (Satellite VI) (Satellite Orbit parameter) (Satellite DD Start) (Satellite DD Interval) (Sym Index VI) (Sym Index DD Start) (Sym Index DD Interval)" << endl;
exit(EXIT_FAILURE);
}
// CONSTANTS
string timeParameter = "Time";
string plasmaVNorm = "V";
string plasmaRamP = "RamP";
string plasmaVel = "Vel";
string plasmaMag = "B";
string indexSym = "SYM";
// GET PLASMA DATA
string plasmaVi = argv[1];
string pddStart = argv[2];
string pddInterval = argv[3];
vector<string> plasmaTimeArray;
vector<float> vnormArray,rampArray, vx, vy, vz, bx, by, bz;
getPlasmaData(plasmaVi, pddStart, pddInterval,
timeParameter, plasmaVNorm, plasmaRamP, plasmaVel, plasmaMag,
plasmaTimeArray, vnormArray, rampArray, vx, vy, vz, bx, by, bz);
ofstream plasmaData("plasma.txt", ios::out | ios::trunc);
int plasmaSize = plasmaTimeArray.size();
plasmaData << "Time,V,ramP,vx,vy,vz,bx,by,bz" << endl;
for (int i = 0; i < plasmaSize; ++i)
{
plasmaData << plasmaTimeArray[i] << ","
<< vnormArray[i] << ","
<< rampArray[i] << ","
<< vx[i] << "," << vy[i] << "," << vz[i] << ","
<< bx[i] << "," << by[i] << "," << bz[i] << endl;
}
plasmaData.close();
cout << "getPlasmaData ok"<< endl;
// GET SATELLITE DATA
string satelliteVi = argv[4];
string satelliteOrbParam = argv[5];
string satddStart = argv[6];
string satddInterval = argv[7];
vector<string> satelliteTimeArray;
vector<float> x, y, z;
getOrbitData(satelliteVi, satddStart, satddInterval,
timeParameter, satelliteOrbParam, satelliteTimeArray,
x, y, z);
ofstream satelliteData("orbit.txt", ios::out | ios::trunc);
int satelliteSize = satelliteTimeArray.size();
satelliteData << "Time,x,y,z" << endl;
for (int i = 0; i < satelliteSize; ++i)
{
satelliteData << satelliteTimeArray[i] << ","
<< x[i] << "," << y[i] << "," << z[i] << endl;
}
satelliteData.close();
cout << "getOrbitData ok"<< endl;
// GET SYM H DATA
string indexVi = argv[8];
string symddStart = argv[9];
string symddInterval = argv[10];
vector<string> symIndexTimeArray;
vector<float> symIndexArray;
getSymIndexData(indexVi, symddStart, symddInterval,
timeParameter, indexSym,
symIndexTimeArray, symIndexArray);
cout << "getSymIndexData ok"<< endl;
ofstream symData("sym.txt", ios::out | ios::trunc);
int symSize = symIndexTimeArray.size();
symData << "Time,symIndex" << endl;
for (int i = 0; i < symSize; ++i)
{
symData << symIndexTimeArray[i] << "," << symIndexArray[i] << endl;
}
symData.close();
return 0;
}
////////////////////////////
/// FUNCTIONS DEFINITIONS //
////////////////////////////
void getPlasmaData(string plasmaVi, string ddStart, string ddInterval,
string timeParameter, string vnormParameter, string rampParameter,
string velParameter, string magParameter,
vector<string>& plasmaTimeArray, vector<float>& vnormArray,
vector<float>& rampArray,
vector<float>& vxArray, vector<float>& vyArray, vector<float>& vzArray,
vector<float>& bxArray, vector<float>& byArray, vector<float>& bzArray)
{
int id = DD_SetVariable( const_cast<char*>( plasmaVi.c_str() ) );
cout << "getPlasmaData id : "<< id << endl;
char *st = const_cast<char*>( ddStart.c_str() );
cout << "getPlasmaData st : "<< st << endl;
int error = DD_SetTime(id, st);
cout << "getPlasmaData error : "<< error << endl;
if (error < 0)
{
std::string ddSetTimeErr = "[ERROR] getPlasmaData : bad time pointer init in DD_SetTime -> err value : " + error;
throw std::string(ddSetTimeErr);
}
// GET DATA
char *params[5];
params[0] = const_cast<char*>( timeParameter.c_str() );
params[1] = const_cast<char*>( vnormParameter.c_str() );
params[2] = const_cast<char*>( rampParameter.c_str() );
params[3] = const_cast<char*>( velParameter.c_str() );
params[4] = const_cast<char*>( magParameter.c_str() );
char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
DD_data_t *data;
int status = 0;
do {
status = DD_GetMultiData(id, 5, static_cast<char**>(params), timeIntervall, &data, 1);
if (status < 0)
{
std::string ddGetDataErr = "[ERROR] getPlasmaData : failed to get data -> status : " + status;
throw std::string(ddGetDataErr);
}
for (int j = 0; j < data->VarNumber; ++j)
{
plasmaTimeArray.push_back( static_cast<char*>(data[0].Variables[j]) );
vnormArray.push_back( *(static_cast<float*>(data[1].Variables[j])) );
rampArray.push_back( *(static_cast<float*>(data[2].Variables[j])) );
vxArray.push_back( static_cast<float*>(data[3].Variables[j])[0] );
vyArray.push_back( static_cast<float*>(data[3].Variables[j])[1] );
vzArray.push_back( static_cast<float*>(data[3].Variables[j])[2] );
bxArray.push_back( static_cast<float*>(data[4].Variables[j])[0] );
byArray.push_back( static_cast<float*>(data[4].Variables[j])[1] );
bzArray.push_back( static_cast<float*>(data[4].Variables[j])[2] );
}
} while (status == MOREDATA);
DD_Close(id);
}
void getOrbitData(string satelliteVi, string ddStart, string ddInterval,
string timeParameter, string orbitParameter,
vector<string>& satelliteTimeArray,
vector<float>& x, vector<float>& y, vector<float>& z)
{
int id = DD_SetVariable( const_cast<char*>( satelliteVi.c_str() ) );
cout << "getOrbitData id : "<< id << endl;
char *st = const_cast<char*>( ddStart.c_str() );
cout << "getOrbitData st : " << st<< endl;
int error = DD_SetTime(id, st);
cout << "getOrbitData error: " << error<< endl;
if (error < 0)
{
std::string ddSetTimeErr = "[ERROR] getOrbitData : bad time pointer init in DD_SetTime -> err value : " + error;
throw std::string(ddSetTimeErr);
}
char *params[2];
params[0] = const_cast<char*>( timeParameter.c_str() );
params[1] = const_cast<char*>( orbitParameter.c_str() );
char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
DD_data_t *data;
int status = 0;
do {
cout << "getOrbitData DD_GetMultiData ... " << endl;
cout << "getOrbitData id : "<< id << endl;
cout << "getOrbitData param 1 : " << params[0] << endl;
cout << "getOrbitData param 2 : " << params[1] << endl;
cout << "getOrbitData timeIntervall : " << timeIntervall << endl;
status = DD_GetMultiData(id, 2, static_cast<char**>(params), timeIntervall, &data, 1);
cout << "getOrbitData DD_GetMultiData OK " << endl;
if (status < 0)
{
std::string ddGetDataErr = "[ERROR] getOrbitData : failed to get data -> status : " + status;
throw std::string(ddGetDataErr);
}
int dataType = data[1].type;
for (int j = 0; j < data->VarNumber; j++)
{
satelliteTimeArray.push_back( static_cast<char*>(data[0].Variables[j]) );
if ( dataType == 3 ) // DOUBLE
{
x.push_back( static_cast<float>(static_cast<double*>(data[1].Variables[j])[0]) );
y.push_back( static_cast<float>(static_cast<double*>(data[1].Variables[j])[1]) );
z.push_back( static_cast<float>(static_cast<double*>(data[1].Variables[j])[2]) );
}
else if ( dataType == 2 ) // FLOAT
{
x.push_back( static_cast<float*>(data[1].Variables[j])[0] );
y.push_back( static_cast<float*>(data[1].Variables[j])[1] );
z.push_back( static_cast<float*>(data[1].Variables[j])[2] );
}
else
{
std::string ddGetDataTypeErr = "[ERROR] getOrbitData : failed to get data -> Unknown data type (not double nor float)";
throw std::string(ddGetDataTypeErr);
}
}
} while (status == MOREDATA);
DD_Close(id);
}
void getSymIndexData(string symIndexVi, string ddStart, string ddInterval,
string timeParameter, string symIndexParameter,
vector<string>& symIndexTimeArray, vector<float>& symIndexArray)
{
int id = DD_SetVariable( const_cast<char*>( symIndexVi.c_str() ) );
cout << "getSymIndexData id : "<< id << endl;
char *st = const_cast<char*>( ddStart.c_str() );
cout << "getSymIndexData st : "<< st << endl;
int error = DD_SetTime(id, st);
cout << "getSymIndexData error : "<< error << endl;
if (error < 0)
{
std::string ddSetTimeErr = "[ERROR] getSymIndexData : bad time pointer init in DD_SetTime -> err value : " + error;
throw std::string(ddSetTimeErr);
}
char *params[2];
params[0] = const_cast<char*>( timeParameter.c_str() );
params[1] = const_cast<char*>( symIndexParameter.c_str() );
char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
DD_data_t *data;
int status = 0;
do {
status = DD_GetMultiData(id, 2, static_cast<char**>(params), timeIntervall, &data, 1);
if (status < 0)
{
std::string ddGetDataErr = "[ERROR] getSymIndexData : failed to get data -> status : " + status;
throw std::string(ddGetDataErr);
}
// 5 min to 1 min resampling
for (int j = 0; j < data->VarNumber; j+=5)
{
symIndexTimeArray.push_back( static_cast<char*>(data[0].Variables[j]) );
symIndexArray.push_back( static_cast<float*>(data[1].Variables[j])[0] );
}
} while (status == MOREDATA);
DD_Close(id);
}