Perform forward model calculations in a single directory.
128 {
129
130 static atm_t atm, atm2;
131 static obs_t obs, obs2;
132
133
134 read_obs(wrkdir, obsfile, ctl, &obs);
135
136
137 read_atm(wrkdir, atmfile, ctl, &atm);
138
139
140 if (task[0] == 'p' || task[0] == 'P') {
141
142
143 for (
int ir = 0; ir < obs.
nr; ir++) {
144
145
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];
160 }
161
162
165 obs2.
vpz[0] = obs.
vpz[ir];
171
172
174
175
176 formod(ctl, &atm2, &obs2);
177
178
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];
182 }
183 }
184 }
185
186
188 }
189
190
191 else {
192
193
195
196
198
199
200 if (task[0] == 'c' || task[0] == 'C') {
201
203
204
209
210
211 for (
int ig = 0; ig < ctl->
ng; ig++) {
212
213
215
216
217 for (
int iw = 0; iw < ctl->
nw; iw++)
218 for (
int ip = 0; ip < atm2.
np; ip++)
220
221
222 for (
int ig2 = 0; ig2 < ctl->
ng; ig2++)
223 if (ig2 != ig)
224 for (
int ip = 0; ip < atm2.
np; ip++)
226
227
229
230
231 sprintf(filename,
"%s.%s", radfile, ctl->
emitter[ig]);
233 }
234
235
237
238
239 for (
int ig = 0; ig < ctl->
ng; ig++)
240 for (
int ip = 0; ip < atm2.
np; ip++)
242
243
245
246
247 sprintf(filename, "%s.EXTINCT", radfile);
249 }
250
251
252 if (task[0] == 't' || task[0] == 'T') {
253
254
255 double t_min, t_max, t_mean = 0, t_sigma = 0;
256 int n = 0;
257
258
259 gsl_rng_env_setup();
260 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
261
262
263 do {
264
265
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];
277 }
278
279
280 double t0 = omp_get_wtime();
282 double dt = omp_get_wtime() - t0;
283
284
285 t_mean += (dt);
287 if (n == 0 || dt < t_min)
288 t_min = dt;
289 if (n == 0 || dt > t_max)
290 t_max = dt;
291 n++;
292
293 } while (t_mean < 10.0);
294
295
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);
303 }
304
305
306 if (task[0] == 's' || task[0] == 'S') {
307
308
313
314
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) {
318
319
322
323
324 double t0 = omp_get_wtime();
326 double dt = omp_get_wtime() - t0;
327
328
329 double mean[
ND], sigma[
ND];
330 for (
int id = 0;
id < ctl->
nd;
id++) {
331 mean[id] = sigma[id] = 0;
332 int n = 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]);
336 mean[id] += err;
337 sigma[id] +=
POW2(err);
338 n++;
339 }
340 mean[id] /= n;
341 sigma[id] = sqrt(sigma[
id] / n -
POW2(mean[
id]));
342 }
343
344
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]);
348 printf("\n");
349 }
350 }
351 }
352 }
353}
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.
void copy_atm(const ctl_t *ctl, atm_t *atm_dest, const atm_t *atm_src, const int init)
Copy and initialize atmospheric data.
#define LEN
Maximum length of ASCII data lines.
#define POW2(x)
Compute x^2.
#define ND
Maximum number of radiance channels.
#define NG
Maximum number of emitters.
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.
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.