27#include "jurassic_unified_library.h"
55 ERRMSG(
"Give parameters: <ctl> <obs> <atm> <rad>");
72 jur_unified_init(argc, argv);
73 jur_unified_formod_multiple_packages(&atm, &obs, 1, NULL);
80 char dirlist[
LEN], task[
LEN];
83 scan_ctl(argc, argv,
"TASK", -1,
"-", task);
86 scan_ctl(argc, argv,
"DIRLIST", -1,
"-", dirlist);
89 if (dirlist[0] ==
'-')
90 call_formod(&ctl, NULL, argv[2], argv[3], argv[4], task);
97 if (!(in = fopen(dirlist,
"r")))
98 ERRMSG(
"Cannot open directory list!");
102 while (fscanf(in,
"%s", wrkdir) != EOF) {
105 LOG(1,
"\nWorking directory: %s", wrkdir);
108 call_formod(&ctl, wrkdir, argv[2], argv[3], argv[4], task);
130 static atm_t atm, atm2;
131 static obs_t obs, obs2;
134 read_obs(wrkdir, obsfile, ctl, &obs);
137 read_atm(wrkdir, atmfile, ctl, &atm);
140 if (task[0] ==
'p' || task[0] ==
'P') {
143 for (
int ir = 0; ir < obs.
nr; ir++) {
147 for (
int ip = 0; ip < atm.
np; ip++)
150 atm2.
z[atm2.
np] = atm.
z[ip];
153 atm2.
p[atm2.
np] = atm.
p[ip];
154 atm2.
t[atm2.
np] = atm.
t[ip];
155 for (
int ig = 0; ig < ctl->
ng; ig++)
156 atm2.
q[ig][atm2.
np] = atm.
q[ig][ip];
157 for (
int iw = 0; iw < ctl->
nw; iw++)
158 atm2.
k[iw][atm2.
np] = atm.
k[iw][ip];
165 obs2.
vpz[0] = obs.
vpz[ir];
176 formod(ctl, &atm2, &obs2);
179 for (
int id = 0;
id < ctl->
nd;
id++) {
180 obs.
rad[id][ir] = obs2.
rad[id][0];
181 obs.
tau[id][ir] = obs2.
tau[id][0];
200 if (task[0] ==
'c' || task[0] ==
'C') {
211 for (
int ig = 0; ig < ctl->
ng; ig++) {
217 for (
int iw = 0; iw < ctl->
nw; iw++)
218 for (
int ip = 0; ip < atm2.
np; ip++)
222 for (
int ig2 = 0; ig2 < ctl->
ng; ig2++)
224 for (
int ip = 0; ip < atm2.
np; ip++)
231 sprintf(filename,
"%s.%s", radfile, ctl->
emitter[ig]);
239 for (
int ig = 0; ig < ctl->
ng; ig++)
240 for (
int ip = 0; ip < atm2.
np; ip++)
247 sprintf(filename,
"%s.EXTINCT", radfile);
252 if (task[0] ==
't' || task[0] ==
'T') {
255 double t_min, t_max, t_mean = 0, t_sigma = 0;
260 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
267 double dtemp = 40. * (gsl_rng_uniform(rng) - 0.5);
268 double dpress = 1. - 0.1 * gsl_rng_uniform(rng);
270 for (
int ig = 0; ig < ctl->
ng; ig++)
271 dq[ig] = 0.8 + 0.4 * gsl_rng_uniform(rng);
272 for (
int ip = 0; ip < atm2.
np; ip++) {
275 for (
int ig = 0; ig < ctl->
ng; ig++)
276 atm.
q[ig][ip] *= dq[ig];
280 double t0 = omp_get_wtime();
282 double dt = omp_get_wtime() - t0;
287 if (n == 0 || dt < t_min)
289 if (n == 0 || dt > t_max)
293 }
while (t_mean < 10.0);
296 t_mean /= (double) n;
297 t_sigma = sqrt(t_sigma / (
double) n -
POW2(t_mean));
298 printf(
"RUNTIME_MEAN = %g s\n", t_mean);
299 printf(
"RUNTIME_SIGMA = %g s\n", t_sigma);
300 printf(
"RUNTIME_MIN = %g s\n", t_min);
301 printf(
"RUNTIME_MAX = %g s\n", t_max);
302 printf(
"RAYS_PER_SECOND = %g", (
double) obs.
nr / t_mean);
306 if (task[0] ==
's' || task[0] ==
'S') {
315 for (
double dz = 0.01; dz <= 2; dz *= 1.1) {
316 printf(
"STEPSIZE: \n");
317 for (
double ds = 0.1; ds <= 50; ds *= 1.1) {
324 double t0 = omp_get_wtime();
326 double dt = omp_get_wtime() - t0;
329 double mean[
ND], sigma[
ND];
330 for (
int id = 0;
id < ctl->
nd;
id++) {
331 mean[id] = sigma[id] = 0;
333 for (
int ir = 0; ir < obs.
nr; ir++) {
334 double err = 200. * (obs.
rad[id][ir] - obs2.
rad[id][ir])
335 / (obs.
rad[
id][ir] + obs2.
rad[
id][ir]);
337 sigma[id] +=
POW2(err);
341 sigma[id] = sqrt(sigma[
id] / n -
POW2(mean[
id]));
345 printf(
"STEPSIZE: %g %g %g", ds, dz, dt);
346 for (
int id = 0;
id < ctl->
nd;
id++)
347 printf(
" %g %g", mean[
id], sigma[
id]);
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read forward model control parameters.
void formod(const ctl_t *ctl, atm_t *atm, obs_t *obs)
Determine ray paths and compute radiative transfer.
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, int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
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.