Perform forward model calculations in a single directory.
151 {
152
153 static atm_t atm, atm2;
154 static obs_t obs, obs2;
155
156
157 read_atm(wrkdir, atmfile, ctl, &atm);
158
159
160 read_obs(wrkdir, obsfile, ctl, &obs);
161
162
163 if (task[0] == 'p' || task[0] == 'P') {
164
165
166 for (
int ir = 0; ir < obs.
nr; ir++) {
167
168
170 for (
int ip = 0; ip < atm.
np; ip++)
173 atm2.
z[atm2.
np] = atm.
z[ip];
176 atm2.
p[atm2.
np] = atm.
p[ip];
177 atm2.
t[atm2.
np] = atm.
t[ip];
178 for (
int ig = 0; ig < ctl->
ng; ig++)
179 atm2.
q[ig][atm2.
np] = atm.
q[ig][ip];
180 for (
int iw = 0; iw < ctl->
nw; iw++)
181 atm2.
k[iw][atm2.
np] = atm.
k[iw][ip];
183 }
184
185
188 obs2.
vpz[0] = obs.
vpz[ir];
194
195
197
198
199 formod(ctl, tbl, &atm2, &obs2);
200
201
202 for (
int id = 0;
id < ctl->
nd;
id++) {
203 obs.
rad[id][ir] = obs2.
rad[id][0];
204 obs.
tau[id][ir] = obs2.
tau[id][0];
205 }
206 }
207 }
208
209
211 }
212
213
214 else {
215
216
217 formod(ctl, tbl, &atm, &obs);
218
219
221
222
223 if (obsref[0] != '-') {
224
225
226 read_obs(wrkdir, obsref, ctl, &obs2);
227
228
229 double mre[
ND], sdre[
ND], minre[
ND], maxre[
ND];
231
232
233 for (
int id = 0;
id < ctl->
nd;
id++)
234 printf
235 ("EVAL: nu= %.4f cm^-1 | MRE= %g %% | SDRE= %g %% | MinRE= %g %% | MaxRE= %g %%\n",
236 ctl->
nu[
id], mre[
id], sdre[
id], minre[
id], maxre[
id]);
237 }
238
239
240 if (task[0] == 'c' || task[0] == 'C') {
241
243
244
249
250
251 for (
int ig = 0; ig < ctl->
ng; ig++) {
252
253
255
256
257 for (
int iw = 0; iw < ctl->
nw; iw++)
258 for (
int ip = 0; ip < atm2.
np; ip++)
260
261
262 for (
int ig2 = 0; ig2 < ctl->
ng; ig2++)
263 if (ig2 != ig)
264 for (
int ip = 0; ip < atm2.
np; ip++)
266
267
268 formod(ctl, tbl, &atm2, &obs);
269
270
271 sprintf(filename,
"%s.%s", radfile, ctl->
emitter[ig]);
273 }
274
275
277
278
279 for (
int ig = 0; ig < ctl->
ng; ig++)
280 for (
int ip = 0; ip < atm2.
np; ip++)
282
283
284 formod(ctl, tbl, &atm2, &obs);
285
286
287 sprintf(filename, "%s.EXTINCT", radfile);
289 }
290
291
292 if (task[0] == 't' || task[0] == 'T') {
293
294
295 double t_min, t_max, t_mean = 0, t_sd = 0;
296 int n = 0;
297
298
299 gsl_rng_env_setup();
300 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
301
302
303 do {
304
305
307 double dtemp = 40. * (gsl_rng_uniform(rng) - 0.5);
308 double dpress = 1. - 0.1 * gsl_rng_uniform(rng);
310 for (
int ig = 0; ig < ctl->
ng; ig++)
311 dq[ig] = 0.8 + 0.4 * gsl_rng_uniform(rng);
312 for (
int ip = 0; ip < atm2.
np; ip++) {
314 atm2.
p[ip] *= dpress;
315 for (
int ig = 0; ig < ctl->
ng; ig++)
316 atm2.
q[ig][ip] *= dq[ig];
317 }
318
319
320 double t0 = omp_get_wtime();
321 formod(ctl, tbl, &atm2, &obs);
322 double dt = omp_get_wtime() - t0;
323
324
325 t_mean += dt;
327 if (n == 0 || dt < t_min)
328 t_min = dt;
329 if (n == 0 || dt > t_max)
330 t_max = dt;
331 n++;
332
333 } while (t_mean < 10.0);
334
335
336 t_mean /= (double) n;
337 t_sd = sqrt(t_sd / (
double) n -
POW2(t_mean));
338 printf("RUNTIME: mean= %g s | stddev= %g s | min= %g s | max= %g s\n",
339 t_mean, t_sd, t_min, t_max);
340
341
342 gsl_rng_free(rng);
343 }
344
345
346 if (task[0] == 's' || task[0] == 'S') {
347
348
351 formod(ctl, tbl, &atm, &obs);
353
354
355 for (double dz = 0.01; dz <= 2; dz *= 1.1)
356 for (double ds = 0.1; ds <= 50; ds *= 1.1) {
357
358
361
362
363 double t0 = omp_get_wtime();
364 formod(ctl, tbl, &atm, &obs);
365 double dt = omp_get_wtime() - t0;
366
367
368 double mre[
ND], sdre[
ND], minre[
ND], maxre[
ND];
370
371
372 for (
int id = 0;
id < ctl->
nd;
id++)
373 printf
374 ("STEPSIZE: ds= %.4f km | dz= %g km | t= %g s | nu= %.4f cm^-1"
375 " | MRE= %g %% | SDRE= %g %% | MinRE= %g %% | MaxRE= %g %%\n",
376 ds, dz, dt, ctl->
nu[
id], mre[
id], sdre[
id], minre[
id], maxre[
id]);
377 }
378 }
379 }
380}
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric profile data from an ASCII file.
void copy_obs(const ctl_t *ctl, obs_t *obs_dest, const obs_t *obs_src, const int init)
Copy or initialize observation geometry and radiance data.
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs)
Read observation geometry and radiance data from an ASCII file.
void write_obs(const char *dirname, const char *filename, const ctl_t *ctl, const obs_t *obs)
void formod(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs)
Execute the selected forward model.
void copy_atm(const ctl_t *ctl, atm_t *atm_dest, const atm_t *atm_src, const int init)
Copy or initialize atmospheric profile data.
#define LEN
Maximum length of ASCII data lines.
#define POW2(x)
Compute the square of a value.
#define ND
Maximum number of radiance channels.
#define NG
Maximum number of emitters.
Atmospheric profile data.
double time[NP]
Time (seconds since 2000-01-01T00:00Z).
double k[NW][NP]
Extinction [km^-1].
double lat[NP]
Latitude [deg].
double lon[NP]
Longitude [deg].
double t[NP]
Temperature [K].
int np
Number of data points.
double z[NP]
Altitude [km].
double q[NG][NP]
Volume mixing ratio [ppv].
double p[NP]
Pressure [hPa].
int nw
Number of spectral windows.
double nu[ND]
Centroid wavenumber of each channel [cm^-1].
int ctm_co2
Compute CO2 continuum (0=no, 1=yes).
int ctm_n2
Compute N2 continuum (0=no, 1=yes).
int ctm_h2o
Compute H2O continuum (0=no, 1=yes).
int ng
Number of emitters.
int nd
Number of radiance channels.
int ctm_o2
Compute O2 continuum (0=no, 1=yes).
char emitter[NG][LEN]
Name of each emitter.
double rayds
Maximum step length for raytracing [km].
double raydz
Vertical step length for raytracing [km].
Observation geometry and radiance data.
double tau[ND][NR]
Transmittance of ray path.
double rad[ND][NR]
Radiance [W/(m^2 sr cm^-1)].
double vpz[NR]
View point altitude [km].
double vplat[NR]
View point latitude [deg].
double obslon[NR]
Observer longitude [deg].
double obslat[NR]
Observer latitude [deg].
double obsz[NR]
Observer altitude [km].
double vplon[NR]
View point longitude [deg].
double time[NR]
Time (seconds since 2000-01-01T00:00Z).
int nr
Number of ray paths.