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