Perform forward model calculations in a single directory.
234 {
235
236 static atm_t atm, atm2;
237 static obs_t obs, obs2;
238
239
241 read_atm(wrkdir, atmfile, ctl, &atm, 0);
242
243
245 read_obs(wrkdir, obsfile, ctl, &obs, 0);
246
247
248 if (task[0] == 'p' || task[0] == 'P') {
249
251
252
253 for (
int ir = 0; ir < obs.
nr; ir++) {
254
255
257 for (
int ip = 0; ip < atm.
np; ip++)
260 atm2.
z[atm2.
np] = atm.
z[ip];
263 atm2.
p[atm2.
np] = atm.
p[ip];
264 atm2.
t[atm2.
np] = atm.
t[ip];
265 for (
int ig = 0; ig < ctl->
ng; ig++)
266 atm2.
q[ig][atm2.
np] = atm.
q[ig][ip];
267 for (
int iw = 0; iw < ctl->
nw; iw++)
268 atm2.
k[iw][atm2.
np] = atm.
k[iw][ip];
270 }
271
272
275 obs2.
vpz[0] = obs.
vpz[ir];
281
282
284
285
286 formod(ctl, tbl, &atm2, &obs2);
287
288
289 for (
int id = 0;
id < ctl->
nd;
id++) {
290 obs.
rad[id][ir] = obs2.
rad[id][0];
291 obs.
tau[id][ir] = obs2.
tau[id][0];
292 }
293 }
294 }
295
296
298 write_obs(wrkdir, radfile, ctl, &obs, 0);
299 }
300
301
302 else {
303
304
306 formod(ctl, tbl, &atm, &obs);
307
308
310 write_obs(wrkdir, radfile, ctl, &obs, 0);
311
312
313 if (obsref[0] != '-') {
314
316
317
318 read_obs(wrkdir, obsref, ctl, &obs2, 0);
319
320
321 double mre[
ND], sdre[
ND], minre[
ND], maxre[
ND];
323
324
325 for (
int id = 0;
id < ctl->
nd;
id++)
326 printf
327 ("EVAL: nu= %.4f cm^-1 | MRE= %g %% | SDRE= %g %% | MinRE= %g %% | MaxRE= %g %%\n",
328 ctl->
nu[
id], mre[
id], sdre[
id], minre[
id], maxre[
id]);
329 }
330
331
332 if (task[0] == 'c' || task[0] == 'C') {
333
335
337
338
343
344
345 for (
int ig = 0; ig < ctl->
ng; ig++) {
346
347
349
350
351 for (
int iw = 0; iw < ctl->
nw; iw++)
352 for (
int ip = 0; ip < atm2.
np; ip++)
354
355
356 for (
int ig2 = 0; ig2 < ctl->
ng; ig2++)
357 if (ig2 != ig)
358 for (
int ip = 0; ip < atm2.
np; ip++)
360
361
362 formod(ctl, tbl, &atm2, &obs);
363
364
365 sprintf(filename,
"%s.%s", radfile, ctl->
emitter[ig]);
366 write_obs(wrkdir, filename, ctl, &obs, 0);
367 }
368
369
371
372
373 for (
int ig = 0; ig < ctl->
ng; ig++)
374 for (
int ip = 0; ip < atm2.
np; ip++)
376
377
378 formod(ctl, tbl, &atm2, &obs);
379
380
381 sprintf(filename, "%s.EXTINCT", radfile);
382 write_obs(wrkdir, filename, ctl, &obs, 0);
383 }
384
385
386 if (task[0] == 't' || task[0] == 'T') {
387
388
389 double t_min = 0, t_max = 0, t_mean = 0, t_sd = 0;
390 int n = 0;
391
392
393 gsl_rng_env_setup();
394 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
395
396
397 do {
398
399
401 double dtemp = 40. * (gsl_rng_uniform(rng) - 0.5);
402 double dpress = 1. - 0.1 * gsl_rng_uniform(rng);
404 for (
int ig = 0; ig < ctl->
ng; ig++)
405 dq[ig] = 0.8 + 0.4 * gsl_rng_uniform(rng);
406 for (
int ip = 0; ip < atm2.
np; ip++) {
408 atm2.
p[ip] *= dpress;
409 for (
int ig = 0; ig < ctl->
ng; ig++)
410 atm2.
q[ig][ip] *= dq[ig];
411 }
412
413
415 double t0 = omp_get_wtime();
416 formod(ctl, tbl, &atm2, &obs);
417 double dt = omp_get_wtime() - t0;
418
419
420 t_mean += dt;
422 if (n == 0 || dt < t_min)
423 t_min = dt;
424 if (n == 0 || dt > t_max)
425 t_max = dt;
426 n++;
427
428 } while (t_mean < 10.0);
429
430
431 t_mean /= (double) n;
432 t_sd = sqrt(t_sd / (
double) n -
POW2(t_mean));
433 printf("RUNTIME: mean= %g s | stddev= %g s | min= %g s | max= %g s\n",
434 t_mean, t_sd, t_min, t_max);
435
436
437 gsl_rng_free(rng);
438 }
439
440
441 if (task[0] == 's' || task[0] == 'S') {
442
444
445
448 formod(ctl, tbl, &atm, &obs);
450
451
452 for (double dz = 0.01; dz <= 2; dz *= 1.1)
453 for (double ds = 0.1; ds <= 50; ds *= 1.1) {
454
455
458
459
460 double t0 = omp_get_wtime();
461 formod(ctl, tbl, &atm, &obs);
462 double dt = omp_get_wtime() - t0;
463
464
465 double mre[
ND], sdre[
ND], minre[
ND], maxre[
ND];
467
468
469 for (
int id = 0;
id < ctl->
nd;
id++)
470 printf
471 ("STEPSIZE: ds= %.4f km | dz= %g km | t= %g s | nu= %.4f cm^-1"
472 " | MRE= %g %% | SDRE= %g %% | MinRE= %g %% | MaxRE= %g %%\n",
473 ds, dz, dt, ctl->
nu[
id], mre[
id], sdre[
id], minre[
id],
474 maxre[id]);
475 }
476 }
477 }
478}
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs, int profile)
Read observation data from an input file.
void write_obs(const char *dirname, const char *filename, const ctl_t *ctl, const obs_t *obs, int profile)
Write observation data to an output file in ASCII or binary format.
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read atmospheric input data from a 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 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 SELECT_TIMER(id, group)
Switch to a named aggregated timer.
#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.