27#include "jurassic_unified_library.h"
56 ERRMSG(
"Give parameters: <ctl> <obs> <atm> <rad>");
76 jur_unified_init(argc, argv);
77 jur_unified_formod_multiple_packages(&atm, &obs, 1, NULL);
84 char dirlist[
LEN], task[
LEN];
87 scan_ctl(argc, argv,
"TASK", -1,
"-", task);
90 scan_ctl(argc, argv,
"DIRLIST", -1,
"-", dirlist);
93 if (dirlist[0] ==
'-')
94 call_formod(&ctl, tbl, NULL, argv[2], argv[3], argv[4], task);
101 if (!(in = fopen(dirlist,
"r")))
102 ERRMSG(
"Cannot open directory list!");
106 while (fscanf(in,
"%4999s", wrkdir) != EOF) {
109 LOG(1,
"\nWorking directory: %s", wrkdir);
112 call_formod(&ctl, tbl, wrkdir, argv[2], argv[3], argv[4], task);
138 static atm_t atm, atm2;
139 static obs_t obs, obs2;
142 read_obs(wrkdir, obsfile, ctl, &obs);
145 read_atm(wrkdir, atmfile, ctl, &atm);
148 if (task[0] ==
'p' || task[0] ==
'P') {
151 for (
int ir = 0; ir < obs.
nr; ir++) {
155 for (
int ip = 0; ip < atm.
np; ip++)
158 atm2.
z[atm2.
np] = atm.
z[ip];
161 atm2.
p[atm2.
np] = atm.
p[ip];
162 atm2.
t[atm2.
np] = atm.
t[ip];
163 for (
int ig = 0; ig < ctl->
ng; ig++)
164 atm2.
q[ig][atm2.
np] = atm.
q[ig][ip];
165 for (
int iw = 0; iw < ctl->
nw; iw++)
166 atm2.
k[iw][atm2.
np] = atm.
k[iw][ip];
173 obs2.
vpz[0] = obs.
vpz[ir];
184 formod(ctl, tbl, &atm2, &obs2);
187 for (
int id = 0;
id < ctl->
nd;
id++) {
188 obs.
rad[id][ir] = obs2.
rad[id][0];
189 obs.
tau[id][ir] = obs2.
tau[id][0];
202 formod(ctl, tbl, &atm, &obs);
208 if (task[0] ==
'c' || task[0] ==
'C') {
219 for (
int ig = 0; ig < ctl->
ng; ig++) {
225 for (
int iw = 0; iw < ctl->
nw; iw++)
226 for (
int ip = 0; ip < atm2.
np; ip++)
230 for (
int ig2 = 0; ig2 < ctl->
ng; ig2++)
232 for (
int ip = 0; ip < atm2.
np; ip++)
236 formod(ctl, tbl, &atm2, &obs);
239 sprintf(filename,
"%s.%s", radfile, ctl->
emitter[ig]);
247 for (
int ig = 0; ig < ctl->
ng; ig++)
248 for (
int ip = 0; ip < atm2.
np; ip++)
252 formod(ctl, tbl, &atm2, &obs);
255 sprintf(filename,
"%s.EXTINCT", radfile);
260 if (task[0] ==
't' || task[0] ==
'T') {
263 double t_min, t_max, t_mean = 0, t_sigma = 0;
268 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
275 double dtemp = 40. * (gsl_rng_uniform(rng) - 0.5);
276 double dpress = 1. - 0.1 * gsl_rng_uniform(rng);
278 for (
int ig = 0; ig < ctl->
ng; ig++)
279 dq[ig] = 0.8 + 0.4 * gsl_rng_uniform(rng);
280 for (
int ip = 0; ip < atm2.
np; ip++) {
283 for (
int ig = 0; ig < ctl->
ng; ig++)
284 atm.
q[ig][ip] *= dq[ig];
288 double t0 = omp_get_wtime();
289 formod(ctl, tbl, &atm2, &obs);
290 double dt = omp_get_wtime() - t0;
295 if (n == 0 || dt < t_min)
297 if (n == 0 || dt > t_max)
301 }
while (t_mean < 10.0);
304 t_mean /= (double) n;
305 t_sigma = sqrt(t_sigma / (
double) n -
POW2(t_mean));
306 printf(
"RUNTIME_MEAN = %g s\n", t_mean);
307 printf(
"RUNTIME_SIGMA = %g s\n", t_sigma);
308 printf(
"RUNTIME_MIN = %g s\n", t_min);
309 printf(
"RUNTIME_MAX = %g s\n", t_max);
310 printf(
"RAYS_PER_SECOND = %g", (
double) obs.
nr / t_mean);
314 if (task[0] ==
's' || task[0] ==
'S') {
319 formod(ctl, tbl, &atm, &obs);
323 for (
double dz = 0.01; dz <= 2; dz *= 1.1) {
324 printf(
"STEPSIZE: \n");
325 for (
double ds = 0.1; ds <= 50; ds *= 1.1) {
332 double t0 = omp_get_wtime();
333 formod(ctl, tbl, &atm, &obs);
334 double dt = omp_get_wtime() - t0;
337 double mean[
ND], sigma[
ND];
338 for (
int id = 0;
id < ctl->
nd;
id++) {
339 mean[id] = sigma[id] = 0;
341 for (
int ir = 0; ir < obs.
nr; ir++) {
342 double err = 200. * (obs.
rad[id][ir] - obs2.
rad[id][ir])
343 / (obs.
rad[
id][ir] + obs2.
rad[
id][ir]);
345 sigma[id] +=
POW2(err);
349 sigma[id] = sqrt(sigma[
id] / n -
POW2(mean[
id]));
353 printf(
"STEPSIZE: %g %g %g", ds, dz, dt);
354 for (
int id = 0;
id < ctl->
nd;
id++)
355 printf(
" %g %g", mean[
id], sigma[
id]);
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read forward model control parameters.
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm)
Read atmospheric data.
void copy_obs(const ctl_t *ctl, obs_t *obs_dest, const obs_t *obs_src, const int init)
Copy and initialize observation data.
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs)
Read observation data.
void write_obs(const char *dirname, const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data.
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
void formod(const ctl_t *ctl, const tbl_t *tbl, atm_t *atm, obs_t *obs)
Determine ray paths and compute radiative transfer.
tbl_t * read_tbl(const ctl_t *ctl)
Read look-up table data.
void copy_atm(const ctl_t *ctl, atm_t *atm_dest, const atm_t *atm_src, const int init)
Copy and initialize atmospheric data.
JURASSIC library declarations.
#define LEN
Maximum length of ASCII data lines.
#define POW2(x)
Compute x^2.
#define ERRMSG(...)
Print error message and quit program.
#define ND
Maximum number of radiance channels.
#define NG
Maximum number of emitters.
#define LOG(level,...)
Print log message.
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].
Forward model control parameters.
int nw
Number of spectral windows.
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.
Emissivity look-up tables.