40 {
41
43
45
47
48 FILE *out;
49
50 static double timem[
NZ], z, lon, lonm[
NZ], lat, latm[
NZ], t, tm[
NZ], u,
51 um[
NZ], v, vm[
NZ], w, wm[
NZ], h2o, h2om[
NZ], h2ot, h2otm[
NZ], o3, o3m[
NZ],
52 lwc, lwcm[
NZ], rwc, rwcm[
NZ], iwc, iwcm[
NZ], swc, swcm[
NZ], cc, ccm[
NZ],
53 ps, psm[
NZ], ts, tsm[
NZ], zs, zsm[
NZ], us, usm[
NZ], vs, vsm[
NZ], lsm,
54 lsmm[
NZ], sst, sstm[
NZ], pbl, pblm[
NZ], pt, ptm[
NZ], pct, pctm[
NZ], pcb,
55 pcbm[
NZ], cl, clm[
NZ], plcl, plclm[
NZ], plfc, plfcm[
NZ], pel, pelm[
NZ],
56 cape, capem[
NZ], cin, cinm[
NZ], o3c, o3cm[
NZ], tt, ttm[
NZ], zm[
NZ], zt,
57 ztm[
NZ], pv, pvm[
NZ], plev[
NZ], rhm[
NZ], rhicem[
NZ], tdewm[
NZ], ticem[
NZ],
58 tnatm[
NZ], hno3m[
NZ], ohm[
NZ], h2o2m[
NZ], ho2m[
NZ], o1dm[
NZ];
59
60 static int iz, np[
NZ], npc[
NZ], npt[
NZ], nz;
61
62
65
66
67 if (argc < 4)
68 ERRMSG(
"Give parameters: <ctl> <prof.tab> <met0> [ <met1> ... ]");
69
70
72 double z0 =
scan_ctl(argv[1], argc, argv,
"PROF_Z0", -1,
"-999", NULL);
73 double z1 =
scan_ctl(argv[1], argc, argv,
"PROF_Z1", -1,
"-999", NULL);
74 double dz =
scan_ctl(argv[1], argc, argv,
"PROF_DZ", -1,
"-999", NULL);
75 double lon0 =
scan_ctl(argv[1], argc, argv,
"PROF_LON0", -1,
"0", NULL);
76 double lon1 =
scan_ctl(argv[1], argc, argv,
"PROF_LON1", -1,
"0", NULL);
77 double dlon =
scan_ctl(argv[1], argc, argv,
"PROF_DLON", -1,
"-999", NULL);
78 double lat0 =
scan_ctl(argv[1], argc, argv,
"PROF_LAT0", -1,
"0", NULL);
79 double lat1 =
scan_ctl(argv[1], argc, argv,
"PROF_LAT1", -1,
"0", NULL);
80 double dlat =
scan_ctl(argv[1], argc, argv,
"PROF_DLAT", -1,
"-999", NULL);
81
82
84
85
86 for (int i = 3; i < argc; i++) {
87
88
89 if (!
read_met(argv[i], &ctl, clim, met))
90 continue;
91
92
93 if (z0 < 0)
95 if (z1 < 0)
96 z1 =
Z(met->
p[met->
np - 1]);
97 nz = 0;
98 if (dz < 0) {
99 for (iz = 0; iz < met->
np; iz++)
100 if (
Z(met->
p[iz]) >= z0 &&
Z(met->
p[iz]) <= z1) {
101 plev[nz] = met->
p[iz];
103 ERRMSG(
"Too many pressure levels!");
104 }
105 } else
106 for (z = z0; z <= z1; z += dz) {
109 ERRMSG(
"Too many pressure levels!");
110 }
111
112
113 if (dlon <= 0)
114 dlon = fabs(met->
lon[1] - met->
lon[0]);
115 if (dlat <= 0)
116 dlat = fabs(met->
lat[1] - met->
lat[0]);
117
118
119 for (iz = 0; iz < nz; iz++)
120 for (lon = lon0; lon <= lon1; lon += dlon)
121 for (lat = lat0; lat <= lat1; lat += dlat) {
122
123
126
127
128 if (isfinite(t) && isfinite(u) && isfinite(v) && isfinite(w)) {
129 timem[iz] += met->
time;
130 lonm[iz] += lon;
131 latm[iz] += lat;
132 zm[iz] += z;
133 tm[iz] += t;
134 um[iz] += u;
135 vm[iz] += v;
136 wm[iz] += w;
137 pvm[iz] += pv;
138 h2om[iz] += h2o;
139 o3m[iz] += o3;
140 lwcm[iz] += lwc;
141 rwcm[iz] += rwc;
142 iwcm[iz] += iwc;
143 swcm[iz] += swc;
144 ccm[iz] += cc;
145 psm[iz] += ps;
146 tsm[iz] += ts;
147 zsm[iz] += zs;
148 usm[iz] += us;
149 vsm[iz] += vs;
150 lsmm[iz] += lsm;
151 sstm[iz] += sst;
152 pblm[iz] += pbl;
153 pctm[iz] += pct;
154 pcbm[iz] += pcb;
155 clm[iz] += cl;
156 if (isfinite(plfc) && isfinite(pel) && cape >= ctl.
conv_cape
158 plclm[iz] += plcl;
159 plfcm[iz] += plfc;
160 pelm[iz] += pel;
161 capem[iz] += cape;
162 cinm[iz] += cin;
163 npc[iz]++;
164 }
165 if (isfinite(pt)) {
166 ptm[iz] += pt;
167 ztm[iz] += zt;
168 ttm[iz] += tt;
169 h2otm[iz] += h2ot;
170 npt[iz]++;
171 }
172 o3cm[iz] += o3c;
173 rhm[iz] +=
RH(plev[iz], t, h2o);
174 rhicem[iz] +=
RHICE(plev[iz], t, h2o);
175 tdewm[iz] +=
TDEW(plev[iz], h2o);
176 ticem[iz] +=
TICE(plev[iz], h2o);
178 tnatm[iz] +=
181 ohm[iz] +=
clim_oh(&ctl, clim, met->
time, lon, lat, plev[iz]);
185 np[iz]++;
186 }
187 }
188 }
189
190
191 LOG(1,
"Write meteorological data file: %s", argv[2]);
192 if (!(out = fopen(argv[2], "w")))
193 ERRMSG(
"Cannot create file!");
194
195
197
198
199 fprintf(out, "\n");
200 for (iz = 0; iz < nz; iz++)
201 fprintf(out,
202 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
203 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
204 " %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %d\n",
205 timem[iz] / np[iz],
Z(plev[iz]), lonm[iz] / np[iz],
206 latm[iz] / np[iz], plev[iz], tm[iz] / np[iz], um[iz] / np[iz],
207 vm[iz] / np[iz], wm[iz] / np[iz], h2om[iz] / np[iz],
208 o3m[iz] / np[iz], zm[iz] / np[iz], pvm[iz] / np[iz],
209 psm[iz] / np[iz], tsm[iz] / np[iz], zsm[iz] / np[iz],
210 usm[iz] / np[iz], vsm[iz] / np[iz], lsmm[iz] / np[iz],
211 sstm[iz] / np[iz], ptm[iz] / npt[iz], ztm[iz] / npt[iz],
212 ttm[iz] / npt[iz], h2otm[iz] / npt[iz],
213 lwcm[iz] / np[iz], rwcm[iz] / np[iz], iwcm[iz] / np[iz],
214 swcm[iz] / np[iz], ccm[iz] / np[iz], clm[iz] / np[iz],
215 pctm[iz] / np[iz], pcbm[iz] / np[iz], plclm[iz] / npc[iz],
216 plfcm[iz] / npc[iz], pelm[iz] / npc[iz], capem[iz] / npc[iz],
217 cinm[iz] / npc[iz], rhm[iz] / np[iz], rhicem[iz] / np[iz],
218 tdewm[iz] / np[iz], ticem[iz] / np[iz], tnatm[iz] / np[iz],
219 hno3m[iz] / np[iz], ohm[iz] / np[iz], h2o2m[iz] / np[iz],
220 ho2m[iz] / np[iz], o1dm[iz] / np[iz], pblm[iz] / np[iz],
221 o3cm[iz] / np[iz], np[iz], npt[iz], npc[iz]);
222
223
224 fclose(out);
225
226
227 free(clim);
228 free(met);
229
230 return EXIT_SUCCESS;
231}
#define NZ
Maximum number of altitudes.
double clim_zm(const clim_zm_t *zm, const double t, const double lat, const double p)
Interpolates monthly mean zonal mean climatological variables.
double nat_temperature(const double p, const double h2o, const double hno3)
Calculates the nitric acid trihydrate (NAT) temperature.
double scan_ctl(const char *filename, int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scans a control file or command-line arguments for a specified variable.
double clim_oh(const ctl_t *ctl, const clim_t *clim, const double t, const double lon, const double lat, const double p)
Calculates the hydroxyl radical (OH) concentration from climatology data, with an optional diurnal co...
void read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
int read_met(const char *filename, ctl_t *ctl, clim_t *clim, met_t *met)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
#define INTPOL_SPACE_ALL(p, lon, lat)
Interpolate multiple meteorological variables in space.
#define INTPOL_INIT
Initialize arrays for interpolation.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define Z(p)
Convert pressure to altitude.
#define P(z)
Compute pressure at given altitude.
#define MET_HEADER
Write header for meteorological data file.
#define TICE(p, h2o)
Calculate frost point temperature (WMO, 2018).
#define RHICE(p, t, h2o)
Compute relative humidity over ice.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define RH(p, t, h2o)
Compute relative humidity over water.
#define LOG(level,...)
Print a log message with a specified logging level.
#define TDEW(p, h2o)
Calculate dew point temperature.
clim_zm_t ho2
HO2 zonal means.
clim_zm_t hno3
HNO3 zonal means.
clim_zm_t o1d
O(1D) zonal means.
clim_zm_t h2o2
H2O2 zonal means.
double conv_cape
CAPE threshold for convection module [J/kg].
double conv_cin
CIN threshold for convection module [J/kg].
int np
Number of pressure levels.
double lon[EX]
Longitude [deg].
double lat[EY]
Latitude [deg].
double p[EP]
Pressure levels [hPa].