MPTRAC
Macros | Functions
met_prof.c File Reference

Extract vertical profile from meteorological data. More...

#include "mptrac.h"

Go to the source code of this file.

Macros

#define NZ   1000
 Maximum number of altitudes. More...
 

Functions

int main (int argc, char *argv[])
 

Detailed Description

Extract vertical profile from meteorological data.

Definition in file met_prof.c.

Macro Definition Documentation

◆ NZ

#define NZ   1000

Maximum number of altitudes.

Definition at line 32 of file met_prof.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 38 of file met_prof.c.

40 {
41
42 ctl_t ctl;
43
44 clim_t *clim;
45
46 met_t *met;
47
48 dd_t *dd;
49
50 FILE *out;
51
52 static double timem[NZ], z, lon, lonm[NZ], lat, latm[NZ], t, tm[NZ], u,
53 um[NZ], v, vm[NZ], w, wm[NZ], h2o, h2om[NZ], h2ot, h2otm[NZ], o3, o3m[NZ],
54 lwc, lwcm[NZ], rwc, rwcm[NZ], iwc, iwcm[NZ], swc, swcm[NZ], cc, ccm[NZ],
55 ps, psm[NZ], ts, tsm[NZ], zs, zsm[NZ], us, usm[NZ], vs, vsm[NZ],
56 ess, essm[NZ], nss, nssm[NZ], shf, shfm[NZ], lsm, lsmm[NZ],
57 sst, sstm[NZ], pbl, pblm[NZ], pt, ptm[NZ], pct, pctm[NZ], pcb,
58 pcbm[NZ], cl, clm[NZ], plcl, plclm[NZ], plfc, plfcm[NZ], pel, pelm[NZ],
59 cape, capem[NZ], cin, cinm[NZ], o3c, o3cm[NZ], tt, ttm[NZ], zm[NZ], zt,
60 ztm[NZ], pv, pvm[NZ], plev[NZ], rhm[NZ], rhicem[NZ], tdewm[NZ], ticem[NZ],
61 tnatm[NZ], hno3m[NZ], ohm[NZ], h2o2m[NZ], ho2m[NZ], o1dm[NZ];
62
63 static int iz, np[NZ], npc[NZ], npt[NZ], nz;
64
65 /* Allocate... */
66 ALLOC(clim, clim_t, 1);
67 ALLOC(met, met_t, 1);
68 ALLOC(dd, dd_t, 1);
69
70 /* Check arguments... */
71 if (argc < 4)
72 ERRMSG("Give parameters: <ctl> <prof.tab> <met0> [ <met1> ... ]");
73
74 /* Read control parameters... */
75 mptrac_read_ctl(argv[1], argc, argv, &ctl);
76 double z0 = scan_ctl(argv[1], argc, argv, "PROF_Z0", -1, "-999", NULL);
77 double z1 = scan_ctl(argv[1], argc, argv, "PROF_Z1", -1, "-999", NULL);
78 double dz = scan_ctl(argv[1], argc, argv, "PROF_DZ", -1, "-999", NULL);
79 double lon0 = scan_ctl(argv[1], argc, argv, "PROF_LON0", -1, "0", NULL);
80 double lon1 = scan_ctl(argv[1], argc, argv, "PROF_LON1", -1, "0", NULL);
81 double dlon = scan_ctl(argv[1], argc, argv, "PROF_DLON", -1, "-999", NULL);
82 double lat0 = scan_ctl(argv[1], argc, argv, "PROF_LAT0", -1, "0", NULL);
83 double lat1 = scan_ctl(argv[1], argc, argv, "PROF_LAT1", -1, "0", NULL);
84 double dlat = scan_ctl(argv[1], argc, argv, "PROF_DLAT", -1, "-999", NULL);
85
86 /* Read climatological data... */
87 mptrac_read_clim(&ctl, clim);
88
89 /* Loop over input files... */
90 for (int i = 3; i < argc; i++) {
91
92 /* Read meteorological data... */
93 if (!mptrac_read_met(argv[i], &ctl, clim, met, dd))
94 continue;
95
96 /* Set vertical grid... */
97 if (z0 < 0)
98 z0 = Z(met->p[0]);
99 if (z1 < 0)
100 z1 = Z(met->p[met->np - 1]);
101 nz = 0;
102 if (dz < 0) {
103 for (iz = 0; iz < met->np; iz++)
104 if (Z(met->p[iz]) >= z0 && Z(met->p[iz]) <= z1) {
105 plev[nz] = met->p[iz];
106 if ((++nz) >= NZ)
107 ERRMSG("Too many pressure levels!");
108 }
109 } else
110 for (z = z0; z <= z1; z += dz) {
111 plev[nz] = P(z);
112 if ((++nz) >= NZ)
113 ERRMSG("Too many pressure levels!");
114 }
115
116 /* Set horizontal grid... */
117 if (dlon <= 0)
118 dlon = fabs(met->lon[1] - met->lon[0]);
119 if (dlat <= 0)
120 dlat = fabs(met->lat[1] - met->lat[0]);
121
122 /* Average... */
123 for (iz = 0; iz < nz; iz++)
124 for (lon = lon0; lon <= lon1; lon += dlon)
125 for (lat = lat0; lat <= lat1; lat += dlat) {
126
127 /* Interpolate meteo data... */
129 INTPOL_SPACE_ALL(plev[iz], lon, lat);
130
131 /* Averaging... */
132 if (isfinite(t) && isfinite(u) && isfinite(v) && isfinite(w)) {
133 timem[iz] += met->time;
134 lonm[iz] += lon;
135 latm[iz] += lat;
136 zm[iz] += z;
137 tm[iz] += t;
138 um[iz] += u;
139 vm[iz] += v;
140 wm[iz] += w;
141 pvm[iz] += pv;
142 h2om[iz] += h2o;
143 o3m[iz] += o3;
144 lwcm[iz] += lwc;
145 rwcm[iz] += rwc;
146 iwcm[iz] += iwc;
147 swcm[iz] += swc;
148 ccm[iz] += cc;
149 psm[iz] += ps;
150 tsm[iz] += ts;
151 zsm[iz] += zs;
152 usm[iz] += us;
153 vsm[iz] += vs;
154 essm[iz] += ess;
155 nssm[iz] += nss;
156 shfm[iz] += shf;
157 lsmm[iz] += lsm;
158 sstm[iz] += sst;
159 pblm[iz] += pbl;
160 pctm[iz] += pct;
161 pcbm[iz] += pcb;
162 clm[iz] += cl;
163 if (isfinite(plfc) && isfinite(pel) && cape >= ctl.conv_cape
164 && (ctl.conv_cin <= 0 || cin < ctl.conv_cin)) {
165 plclm[iz] += plcl;
166 plfcm[iz] += plfc;
167 pelm[iz] += pel;
168 capem[iz] += cape;
169 cinm[iz] += cin;
170 npc[iz]++;
171 }
172 if (isfinite(pt)) {
173 ptm[iz] += pt;
174 ztm[iz] += zt;
175 ttm[iz] += tt;
176 h2otm[iz] += h2ot;
177 npt[iz]++;
178 }
179 o3cm[iz] += o3c;
180 rhm[iz] += RH(plev[iz], t, h2o);
181 rhicem[iz] += RHICE(plev[iz], t, h2o);
182 tdewm[iz] += TDEW(plev[iz], h2o);
183 ticem[iz] += TICE(plev[iz], h2o);
184 hno3m[iz] += clim_zm(&clim->hno3, met->time, lat, plev[iz]);
185 tnatm[iz] +=
186 nat_temperature(plev[iz], h2o,
187 clim_zm(&clim->hno3, met->time, lat, plev[iz]));
188 ohm[iz] += clim_oh(&ctl, clim, met->time, lon, lat, plev[iz]);
189 h2o2m[iz] += clim_zm(&clim->h2o2, met->time, lat, plev[iz]);
190 ho2m[iz] += clim_zm(&clim->ho2, met->time, lat, plev[iz]);
191 o1dm[iz] += clim_zm(&clim->o1d, met->time, lat, plev[iz]);
192 np[iz]++;
193 }
194 }
195 }
196
197 /* Create output file... */
198 LOG(1, "Write meteorological data file: %s", argv[2]);
199 if (!(out = fopen(argv[2], "w")))
200 ERRMSG("Cannot create file!");
201
202 /* Write header... */
204
205 /* Write data... */
206 fprintf(out, "\n");
207 for (iz = 0; iz < nz; iz++)
208 fprintf(out,
209 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
210 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
211 " %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %d\n",
212 timem[iz] / np[iz], Z(plev[iz]), lonm[iz] / np[iz],
213 latm[iz] / np[iz], plev[iz], tm[iz] / np[iz], um[iz] / np[iz],
214 vm[iz] / np[iz], wm[iz] / np[iz], h2om[iz] / np[iz],
215 o3m[iz] / np[iz], zm[iz] / np[iz], pvm[iz] / np[iz],
216 psm[iz] / np[iz], tsm[iz] / np[iz], zsm[iz] / np[iz],
217 usm[iz] / np[iz], vsm[iz] / np[iz], essm[iz] / np[iz],
218 nssm[iz] / np[iz], shfm[iz] / np[iz], lsmm[iz] / np[iz],
219 sstm[iz] / np[iz], ptm[iz] / npt[iz], ztm[iz] / npt[iz],
220 ttm[iz] / npt[iz], h2otm[iz] / npt[iz],
221 lwcm[iz] / np[iz], rwcm[iz] / np[iz], iwcm[iz] / np[iz],
222 swcm[iz] / np[iz], ccm[iz] / np[iz], clm[iz] / np[iz],
223 pctm[iz] / np[iz], pcbm[iz] / np[iz], plclm[iz] / npc[iz],
224 plfcm[iz] / npc[iz], pelm[iz] / npc[iz], capem[iz] / npc[iz],
225 cinm[iz] / npc[iz], rhm[iz] / np[iz], rhicem[iz] / np[iz],
226 tdewm[iz] / np[iz], ticem[iz] / np[iz], tnatm[iz] / np[iz],
227 hno3m[iz] / np[iz], ohm[iz] / np[iz], h2o2m[iz] / np[iz],
228 ho2m[iz] / np[iz], o1dm[iz] / np[iz], pblm[iz] / np[iz],
229 o3cm[iz] / np[iz], np[iz], npt[iz], npc[iz]);
230
231 /* Close file... */
232 fclose(out);
233
234 /* Free... */
235 free(clim);
236 free(met);
237
238 return EXIT_SUCCESS;
239}
#define NZ
Maximum number of altitudes.
Definition: met_prof.c:32
double clim_zm(const clim_zm_t *zm, const double t, const double lat, const double p)
Interpolates monthly mean zonal mean climatological variables.
Definition: mptrac.c:406
double nat_temperature(const double p, const double h2o, const double hno3)
Calculates the nitric acid trihydrate (NAT) temperature.
Definition: mptrac.c:6921
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.
Definition: mptrac.c:10899
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:5406
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...
Definition: mptrac.c:89
int mptrac_read_met(const char *filename, const ctl_t *ctl, const clim_t *clim, met_t *met, dd_t *dd)
Reads meteorological data from a file, supporting multiple formats and MPI broadcasting.
Definition: mptrac.c:6357
void mptrac_read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
Definition: mptrac.c:5466
#define INTPOL_SPACE_ALL(p, lon, lat)
Interpolate multiple meteorological variables in space.
Definition: mptrac.h:883
#define INTPOL_INIT
Initialize arrays for interpolation.
Definition: mptrac.h:833
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2043
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:1880
#define P(z)
Compute pressure at given altitude.
Definition: mptrac.h:1443
#define MET_HEADER
Write header for meteorological data file.
Definition: mptrac.h:1051
#define TICE(p, h2o)
Calculate frost point temperature (WMO, 2018).
Definition: mptrac.h:1759
#define RHICE(p, t, h2o)
Compute relative humidity over ice.
Definition: mptrac.h:1595
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:416
#define RH(p, t, h2o)
Compute relative humidity over water.
Definition: mptrac.h:1565
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1973
#define TDEW(p, h2o)
Calculate dew point temperature.
Definition: mptrac.h:1734
Climatological data.
Definition: mptrac.h:3487
clim_zm_t ho2
HO2 zonal means.
Definition: mptrac.h:3517
clim_zm_t hno3
HNO3 zonal means.
Definition: mptrac.h:3508
clim_zm_t o1d
O(1D) zonal means.
Definition: mptrac.h:3520
clim_zm_t h2o2
H2O2 zonal means.
Definition: mptrac.h:3514
Control parameters.
Definition: mptrac.h:2264
double conv_cape
CAPE threshold for convection module [J/kg].
Definition: mptrac.h:2816
double conv_cin
CIN threshold for convection module [J/kg].
Definition: mptrac.h:2819
Domain decomposition data structure.
Definition: mptrac.h:3720
Meteo data structure.
Definition: mptrac.h:3546
int np
Number of pressure levels.
Definition: mptrac.h:3558
double lon[EX]
Longitudes [deg].
Definition: mptrac.h:3564
double time
Time [s].
Definition: mptrac.h:3549
double lat[EY]
Latitudes [deg].
Definition: mptrac.h:3567
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3570
Here is the call graph for this function: