-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmsis.cpp
More file actions
324 lines (262 loc) · 8.74 KB
/
Copy pathmsis.cpp
File metadata and controls
324 lines (262 loc) · 8.74 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
// Copyright 2023, the Aether Development Team (see doc/dev_team.md for members)
// Full license can be found in License.md
//
// initial version - A. Ridley - April 30, 2023
#include <iostream>
#include "aether.h"
// -----------------------------------------------------------------------------
// Call msis model if we enable this in the cmake file
// -----------------------------------------------------------------------------
extern "C" void init_msis(void);
extern "C" void call_msis_f(int *iYear,
int *iDay,
float *second,
float *gLonDeg,
float *gLatDeg,
float *altKm,
float *f107,
float *f107a,
float *ap,
float[], float[]);
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Msis::Msis() {
#ifdef FORTRAN
// Initialize msis (reading in the data file):
init_msis();
isCompiled = true;
#else
isCompiled = false;
#endif
// This is the order in which we will store values:
if (isCompiled) {
value_lookup["He"] = 0;
value_lookup["O"] = 1;
value_lookup["N2"] = 2;
value_lookup["O2"] = 3;
value_lookup["Ar"] = 4;
value_lookup["H"] = 5;
value_lookup["N"] = 6;
value_lookup["N_4S"] = 6;
value_lookup["NO"] = 7;
value_lookup["Tn"] = 8;
nVars = 9;
} else {
value_lookup["unknown"] = 0;
nVars = 0;
}
didChange = true;
nX = -1;
nY = -1;
nZ = -1;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::is_ok() {
return isCompiled;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::is_valid_species(std::string cValue) {
if (value_lookup.contains(cValue))
return true;
else
return false;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::set_time(Times time) {
bool didWork = true;
std::vector<int> iCurrent = time.get_iCurrent();
iYear = iCurrent[0];
iDay = time.get_julian_day();
second =
float(iCurrent[3]) * 3600.0 +
float(iCurrent[4]) * 60.0 +
float(iCurrent[5]) +
float(iCurrent[6]) / 1000.0;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::set_f107(precision_t f107in, precision_t f107ain) {
bool didWork = true;
f107 = f107in;
f107a = f107ain;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::set_ap(precision_t apin) {
bool didWork = true;
ap = apin;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::reset_interface_variable_sizes() {
bool didWork = true;
lonDeg.set_size(nX, nY, nZ);
latDeg.set_size(nX, nY, nZ);
altKm.set_size(nX, nY, nZ);
msis_results = make_cube_vector(nX, nY, nZ, nVars);
return didWork;
}
// -----------------------------------------------------------------------------
// longitude is in radians
// latitude is in radians
// altitude is in meters
// -----------------------------------------------------------------------------
bool Msis::set_locations(arma_vec longitude,
arma_vec latitude,
arma_vec altitude) {
bool didWork = true;
// Set the size of the results if we need to:
if (longitude.n_rows != nX) {
nX = longitude.n_rows;
nY = 1;
nZ = 1;
didWork = reset_interface_variable_sizes();
}
lonDeg.tube(0, 0) = longitude * cRtoD;
latDeg.tube(0, 0) = latitude * cRtoD;
altKm.tube(0, 0) = altitude / 1000.0;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::set_locations(arma_mat longitude,
arma_mat latitude,
arma_mat altitude) {
bool didWork = true;
// Set the size of the results if we need to:
if (longitude.n_rows != nX ||
longitude.n_cols != nY) {
nX = longitude.n_rows;
nY = longitude.n_cols;
nZ = 1;
didWork = reset_interface_variable_sizes();
}
lonDeg.slice(0) = longitude * cRtoD;
latDeg.slice(0) = latitude * cRtoD;
altKm.slice(0) = altitude / 1000.0;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::set_locations(arma_cube longitude,
arma_cube latitude,
arma_cube altitude) {
bool didWork = true;
// Set the size of the results if we need to:
if (longitude.n_rows != nX ||
longitude.n_cols != nY ||
longitude.n_slices != nZ) {
nX = longitude.n_rows;
nY = longitude.n_cols;
nZ = longitude.n_slices;
didWork = reset_interface_variable_sizes();
}
lonDeg = longitude * cRtoD;
latDeg = latitude * cRtoD;
altKm = altitude / 1000.0;
didChange = true;
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool Msis::reset_results() {
bool didWork = true;
float density_back[10];
float temperature_back[2];
float gAltKm;
float gLatDeg;
float gLonDeg;
for (int i = 0; i < 10; i++)
density_back[i] = -1.0;
temperature_back[0] = -1.0;
temperature_back[1] = -1.0;
int64_t iX, iY, iZ;
for (iX = 0; iX < nX; iX++) {
for (iY = 0; iY < nY; iY++) {
for (iZ = 0; iZ < nZ; iZ++) {
gLonDeg = lonDeg(iX, iY, iZ);
gLatDeg = latDeg(iX, iY, iZ);
gAltKm = altKm(iX, iY, iZ);
#ifdef FORTRAN
// Call msis in fortran:
call_msis_f(&iYear, &iDay, &second, &gLonDeg, &gLatDeg, &gAltKm,
&f107, &f107a, &ap, density_back, temperature_back);
#endif
// convert from /cm3 to /m3
msis_results[0](iX, iY, iZ) = density_back[0] * 1e6;
msis_results[1](iX, iY, iZ) = density_back[1] * 1e6;
msis_results[2](iX, iY, iZ) = density_back[2] * 1e6;
msis_results[3](iX, iY, iZ) = density_back[3] * 1e6;
msis_results[4](iX, iY, iZ) = density_back[4] * 1e6;
msis_results[5](iX, iY, iZ) = density_back[6] * 1e6;
msis_results[6](iX, iY, iZ) = density_back[7] * 1e6;
msis_results[7](iX, iY, iZ) = density_back[9] * 1e6;
msis_results[8](iX, iY, iZ) = temperature_back[1];
} // iZ
} // iY
} // iX
return didWork;
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
arma_vec Msis::get_vec(std::string cVar) {
bool didWork = true;
int item_ = -1;
if (didChange)
didWork = reset_results();
if (didWork)
item_ = value_lookup[cVar];
return msis_results[item_].tube(0, 0);
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
arma_mat Msis::get_mat(std::string cVar) {
bool didWork = true;
int item_ = -1;
if (didChange)
didWork = reset_results();
if (didWork)
item_ = value_lookup[cVar];
return msis_results[item_].slice(0);
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
arma_cube Msis::get_cube(std::string cVar) {
bool didWork = true;
int item_ = -1;
if (didChange)
didWork = reset_results();
if (didWork)
item_ = value_lookup[cVar];
return msis_results[item_];
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------