63 static double *timem, ps, *psm, ts, *tsm, zs, *zsm, us, *usm, vs, *vsm,
64 ess, *essm, nss, *nssm, shf, *shfm, lsm, *lsmm, sst, *sstm, pbl, *pblm,
65 pt, *ptm, t, *pm, *tm, u, *um, v, *vm, w, *wm, h2o, *h2om, h2ot, *h2otm,
66 o3, *o3m, *hno3m, *ohm, *h2o2m, *ho2m, *o1dm, *tdewm, *ticem, *tnatm,
67 lwc, *lwcm, rwc, *rwcm, iwc, *iwcm, swc, *swcm, cc, *ccm, z, *zm,
68 pv, *pvm, zt, *ztm, tt, *ttm, pct, *pctm, pcb, *pcbm, cl, *clm,
69 plcl, *plclm, plfc, *plfcm, pel, *pelm, cape, *capem, cin, *cinm,
70 o3c, *o3cm, *rhm, *rhicem, ptop, pbot, t0, lon, lons[
NX], lat, lats[
NY];
72 static int *np, *npc, *npt, nx, ny;
75 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
172 ALLOC(rhicem,
double,
186 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
187 "Usage: met_map <ctl> <map.tab> <met0> [<met1> ...]\n\n"
188 "Use -h for full help.");
192 double p0 =
P(
scan_ctl(argv[1], argc, argv,
"MAP_Z0", -1,
"10", NULL));
193 double lon0 =
scan_ctl(argv[1], argc, argv,
"MAP_LON0", -1,
"-180", NULL);
194 double lon1 =
scan_ctl(argv[1], argc, argv,
"MAP_LON1", -1,
"180", NULL);
195 double dlon =
scan_ctl(argv[1], argc, argv,
"MAP_DLON", -1,
"-999", NULL);
196 double lat0 =
scan_ctl(argv[1], argc, argv,
"MAP_LAT0", -1,
"-90", NULL);
197 double lat1 =
scan_ctl(argv[1], argc, argv,
"MAP_LAT1", -1,
"90", NULL);
198 double dlat =
scan_ctl(argv[1], argc, argv,
"MAP_DLAT", -1,
"-999", NULL);
199 double theta =
scan_ctl(argv[1], argc, argv,
"MAP_THETA", -1,
"-999", NULL);
205 for (
int i = 3; i < argc; i++) {
213 dlon = fabs(met->
lon[1] - met->
lon[0]);
215 dlat = fabs(met->
lat[1] - met->
lat[0]);
216 if (lon0 < -360 && lon1 > 360) {
217 lon0 = gsl_stats_min(met->
lon, 1, (
size_t) met->
nx);
218 lon1 = gsl_stats_max(met->
lon, 1, (
size_t) met->
nx);
221 for (lon = lon0; lon <= lon1 + 0.001; lon += dlon) {
222 lons[nx] = round(lon * 1e3) / 1e3;
224 ERRMSG(
"Too many longitudes!");
226 if (lat0 < -90 && lat1 > 90) {
227 lat0 = gsl_stats_min(met->
lat, 1, (
size_t) met->
ny);
228 lat1 = gsl_stats_max(met->
lat, 1, (
size_t) met->
ny);
230 for (lat = lat0; lat <= lat1 + 0.001; lat += dlat) {
231 lats[ny] = round(lat * 1e3) / 1e3;
233 ERRMSG(
"Too many latitudes!");
237 for (
int ix = 0; ix < nx; ix++)
238 for (
int iy = 0; iy < ny; iy++) {
243 ptop = met->
p[met->
np - 1];
246 p0 = 0.5 * (ptop + pbot);
249 if (
THETA(p0, t0) > theta)
253 }
while (fabs(ptop - pbot) > 1e-5);
260 timem[iy * nx + ix] += met->
time;
261 zm[iy * nx + ix] += z;
262 pm[iy * nx + ix] += p0;
263 tm[iy * nx + ix] += t;
264 um[iy * nx + ix] += u;
265 vm[iy * nx + ix] += v;
266 wm[iy * nx + ix] += w;
267 pvm[iy * nx + ix] += pv;
268 h2om[iy * nx + ix] += h2o;
269 o3m[iy * nx + ix] += o3;
270 lwcm[iy * nx + ix] += lwc;
271 rwcm[iy * nx + ix] += rwc;
272 iwcm[iy * nx + ix] += iwc;
273 swcm[iy * nx + ix] += swc;
274 ccm[iy * nx + ix] += cc;
275 psm[iy * nx + ix] += ps;
276 tsm[iy * nx + ix] += ts;
277 zsm[iy * nx + ix] += zs;
278 usm[iy * nx + ix] += us;
279 vsm[iy * nx + ix] += vs;
280 essm[iy * nx + ix] += ess;
281 nssm[iy * nx + ix] += nss;
282 shfm[iy * nx + ix] += shf;
283 lsmm[iy * nx + ix] += lsm;
284 sstm[iy * nx + ix] += sst;
285 pblm[iy * nx + ix] += pbl;
286 pctm[iy * nx + ix] += pct;
287 pcbm[iy * nx + ix] += pcb;
288 clm[iy * nx + ix] += cl;
289 if (isfinite(plfc) && isfinite(pel) && cape >= ctl.
conv_cape
291 plclm[iy * nx + ix] += plcl;
292 plfcm[iy * nx + ix] += plfc;
293 pelm[iy * nx + ix] += pel;
294 capem[iy * nx + ix] += cape;
295 cinm[iy * nx + ix] += cin;
299 ptm[iy * nx + ix] += pt;
300 ztm[iy * nx + ix] += zt;
301 ttm[iy * nx + ix] += tt;
302 h2otm[iy * nx + ix] += h2ot;
305 o3cm[iy * nx + ix] += o3c;
307 tnatm[iy * nx + ix] +=
311 clim_oh(&ctl, clim, met->
time, lons[ix], lats[iy], p0);
313 ho2m[iy * nx + ix] +=
clim_zm(&clim->
ho2, met->
time, lats[iy], p0);
314 o1dm[iy * nx + ix] +=
clim_zm(&clim->
o1d, met->
time, lats[iy], p0);
315 rhm[iy * nx + ix] +=
RH(p0, t, h2o);
316 rhicem[iy * nx + ix] +=
RHICE(p0, t, h2o);
317 tdewm[iy * nx + ix] +=
TDEW(p0, h2o);
318 ticem[iy * nx + ix] +=
TICE(p0, h2o);
324 LOG(1,
"Write meteorological data file: %s", argv[2]);
325 if (!(out = fopen(argv[2],
"w")))
326 ERRMSG(
"Cannot create file!");
332 for (
int iy = 0; iy < ny; iy++) {
334 for (
int ix = 0; ix < nx; ix++)
336 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
337 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
338 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %d\n",
339 timem[iy * nx + ix] / np[iy * nx + ix],
340 Z(pm[iy * nx + ix] / np[iy * nx + ix]), lons[ix], lats[iy],
341 pm[iy * nx + ix] / np[iy * nx + ix],
342 tm[iy * nx + ix] / np[iy * nx + ix],
343 um[iy * nx + ix] / np[iy * nx + ix],
344 vm[iy * nx + ix] / np[iy * nx + ix],
345 wm[iy * nx + ix] / np[iy * nx + ix],
346 h2om[iy * nx + ix] / np[iy * nx + ix],
347 o3m[iy * nx + ix] / np[iy * nx + ix],
348 zm[iy * nx + ix] / np[iy * nx + ix],
349 pvm[iy * nx + ix] / np[iy * nx + ix],
350 psm[iy * nx + ix] / np[iy * nx + ix],
351 tsm[iy * nx + ix] / np[iy * nx + ix],
352 zsm[iy * nx + ix] / np[iy * nx + ix],
353 usm[iy * nx + ix] / np[iy * nx + ix],
354 vsm[iy * nx + ix] / np[iy * nx + ix],
355 essm[iy * nx + ix] / np[iy * nx + ix],
356 nssm[iy * nx + ix] / np[iy * nx + ix],
357 shfm[iy * nx + ix] / np[iy * nx + ix],
358 lsmm[iy * nx + ix] / np[iy * nx + ix],
359 sstm[iy * nx + ix] / np[iy * nx + ix],
360 ptm[iy * nx + ix] / npt[iy * nx + ix],
361 ztm[iy * nx + ix] / npt[iy * nx + ix],
362 ttm[iy * nx + ix] / npt[iy * nx + ix],
363 h2otm[iy * nx + ix] / npt[iy * nx + ix],
364 lwcm[iy * nx + ix] / np[iy * nx + ix],
365 rwcm[iy * nx + ix] / np[iy * nx + ix],
366 iwcm[iy * nx + ix] / np[iy * nx + ix],
367 swcm[iy * nx + ix] / np[iy * nx + ix],
368 ccm[iy * nx + ix] / np[iy * nx + ix],
369 clm[iy * nx + ix] / np[iy * nx + ix],
370 pctm[iy * nx + ix] / np[iy * nx + ix],
371 pcbm[iy * nx + ix] / np[iy * nx + ix],
372 plclm[iy * nx + ix] / npc[iy * nx + ix],
373 plfcm[iy * nx + ix] / npc[iy * nx + ix],
374 pelm[iy * nx + ix] / npc[iy * nx + ix],
375 capem[iy * nx + ix] / npc[iy * nx + ix],
376 cinm[iy * nx + ix] / npc[iy * nx + ix],
377 rhm[iy * nx + ix] / np[iy * nx + ix],
378 rhicem[iy * nx + ix] / np[iy * nx + ix],
379 tdewm[iy * nx + ix] / np[iy * nx + ix],
380 ticem[iy * nx + ix] / np[iy * nx + ix],
381 tnatm[iy * nx + ix] / np[iy * nx + ix],
382 hno3m[iy * nx + ix] / np[iy * nx + ix],
383 ohm[iy * nx + ix] / np[iy * nx + ix],
384 h2o2m[iy * nx + ix] / np[iy * nx + ix],
385 ho2m[iy * nx + ix] / np[iy * nx + ix],
386 o1dm[iy * nx + ix] / np[iy * nx + ix],
387 pblm[iy * nx + ix] / np[iy * nx + ix],
388 o3cm[iy * nx + ix] / np[iy * nx + ix], np[iy * nx + ix],
389 npt[iy * nx + ix], npc[iy * nx + ix]);
396 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);