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

void usage (void)
 Print command-line help. More...
 
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

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 254 of file met_prof.c.

255 {
256
257 printf("\nMPTRAC met_prof tool.\n\n");
258 printf("Extract vertical profiles from meteorological data.\n");
259 printf("\n");
260 printf("Usage:\n");
261 printf(" met_prof <ctl> <prof.tab> <met0> [<met1> ...]\n");
262 printf("\n");
263 printf("Arguments:\n");
264 printf(" <ctl> Control file.\n");
265 printf(" <prof.tab> Output table.\n");
266 printf(" <met*> Meteorological input files.\n");
267 printf("\nFurther information:\n");
268 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
269}

◆ main()

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

Definition at line 46 of file met_prof.c.

48 {
49
50 ctl_t ctl;
51
52 clim_t *clim;
53
54 met_t *met;
55
56 dd_t *dd;
57
58 FILE *out;
59
60 static double timem[NZ], z, lon, lonm[NZ], lat, latm[NZ], t, tm[NZ], u,
61 um[NZ], v, vm[NZ], w, wm[NZ], h2o, h2om[NZ], h2ot, h2otm[NZ], o3, o3m[NZ],
62 lwc, lwcm[NZ], rwc, rwcm[NZ], iwc, iwcm[NZ], swc, swcm[NZ], cc, ccm[NZ],
63 ps, psm[NZ], ts, tsm[NZ], zs, zsm[NZ], us, usm[NZ], vs, vsm[NZ],
64 ess, essm[NZ], nss, nssm[NZ], shf, shfm[NZ], lsm, lsmm[NZ],
65 sst, sstm[NZ], pbl, pblm[NZ], pt, ptm[NZ], pct, pctm[NZ], pcb,
66 pcbm[NZ], cl, clm[NZ], plcl, plclm[NZ], plfc, plfcm[NZ], pel, pelm[NZ],
67 cape, capem[NZ], cin, cinm[NZ], o3c, o3cm[NZ], tt, ttm[NZ], zm[NZ], zt,
68 ztm[NZ], pv, pvm[NZ], plev[NZ], rhm[NZ], rhicem[NZ], tdewm[NZ], ticem[NZ],
69 tnatm[NZ], hno3m[NZ], ohm[NZ], h2o2m[NZ], ho2m[NZ], o1dm[NZ];
70
71 static int iz, np[NZ], npc[NZ], npt[NZ], nz;
72
73 /* Allocate... */
74 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
75
76 /* Print usage information... */
77 USAGE;
78
79 /* Check arguments... */
80 if (argc < 4)
81 ERRMSG("Missing or invalid command-line arguments.\n\n"
82 "Usage: met_prof <ctl> <prof.tab> <met0> [<met1> ...]\n\n"
83 "Use -h for full help.");
84
85 /* Read control parameters... */
86 mptrac_read_ctl(argv[1], argc, argv, &ctl);
87 double z0 = scan_ctl(argv[1], argc, argv, "PROF_Z0", -1, "-999", NULL);
88 double z1 = scan_ctl(argv[1], argc, argv, "PROF_Z1", -1, "-999", NULL);
89 double dz = scan_ctl(argv[1], argc, argv, "PROF_DZ", -1, "-999", NULL);
90 double lon0 = scan_ctl(argv[1], argc, argv, "PROF_LON0", -1, "0", NULL);
91 double lon1 = scan_ctl(argv[1], argc, argv, "PROF_LON1", -1, "0", NULL);
92 double dlon = scan_ctl(argv[1], argc, argv, "PROF_DLON", -1, "-999", NULL);
93 double lat0 = scan_ctl(argv[1], argc, argv, "PROF_LAT0", -1, "0", NULL);
94 double lat1 = scan_ctl(argv[1], argc, argv, "PROF_LAT1", -1, "0", NULL);
95 double dlat = scan_ctl(argv[1], argc, argv, "PROF_DLAT", -1, "-999", NULL);
96
97 /* Read climatological data... */
98 mptrac_read_clim(&ctl, clim);
99
100 /* Loop over input files... */
101 for (int i = 3; i < argc; i++) {
102
103 /* Read meteorological data... */
104 if (!mptrac_read_met(argv[i], &ctl, clim, met, dd))
105 continue;
106
107 /* Set vertical grid... */
108 if (z0 < 0)
109 z0 = Z(met->p[0]);
110 if (z1 < 0)
111 z1 = Z(met->p[met->np - 1]);
112 nz = 0;
113 if (dz < 0) {
114 for (iz = 0; iz < met->np; iz++)
115 if (Z(met->p[iz]) >= z0 && Z(met->p[iz]) <= z1) {
116 plev[nz] = met->p[iz];
117 if ((++nz) >= NZ)
118 ERRMSG("Too many pressure levels!");
119 }
120 } else
121 for (z = z0; z <= z1; z += dz) {
122 plev[nz] = P(z);
123 if ((++nz) >= NZ)
124 ERRMSG("Too many pressure levels!");
125 }
126
127 /* Set horizontal grid... */
128 if (dlon <= 0)
129 dlon = fabs(met->lon[1] - met->lon[0]);
130 if (dlat <= 0)
131 dlat = fabs(met->lat[1] - met->lat[0]);
132
133 /* Average... */
134 for (iz = 0; iz < nz; iz++)
135 for (lon = lon0; lon <= lon1; lon += dlon)
136 for (lat = lat0; lat <= lat1; lat += dlat) {
137
138 /* Interpolate meteo data... */
140 INTPOL_SPACE_ALL(plev[iz], lon, lat);
141
142 /* Averaging... */
143 if (isfinite(t) && isfinite(u) && isfinite(v) && isfinite(w)) {
144 timem[iz] += met->time;
145 lonm[iz] += lon;
146 latm[iz] += lat;
147 zm[iz] += z;
148 tm[iz] += t;
149 um[iz] += u;
150 vm[iz] += v;
151 wm[iz] += w;
152 pvm[iz] += pv;
153 h2om[iz] += h2o;
154 o3m[iz] += o3;
155 lwcm[iz] += lwc;
156 rwcm[iz] += rwc;
157 iwcm[iz] += iwc;
158 swcm[iz] += swc;
159 ccm[iz] += cc;
160 psm[iz] += ps;
161 tsm[iz] += ts;
162 zsm[iz] += zs;
163 usm[iz] += us;
164 vsm[iz] += vs;
165 essm[iz] += ess;
166 nssm[iz] += nss;
167 shfm[iz] += shf;
168 lsmm[iz] += lsm;
169 sstm[iz] += sst;
170 pblm[iz] += pbl;
171 pctm[iz] += pct;
172 pcbm[iz] += pcb;
173 clm[iz] += cl;
174 if (isfinite(plfc) && isfinite(pel) && cape >= ctl.conv_cape
175 && (ctl.conv_cin <= 0 || cin < ctl.conv_cin)) {
176 plclm[iz] += plcl;
177 plfcm[iz] += plfc;
178 pelm[iz] += pel;
179 capem[iz] += cape;
180 cinm[iz] += cin;
181 npc[iz]++;
182 }
183 if (isfinite(pt)) {
184 ptm[iz] += pt;
185 ztm[iz] += zt;
186 ttm[iz] += tt;
187 h2otm[iz] += h2ot;
188 npt[iz]++;
189 }
190 o3cm[iz] += o3c;
191 rhm[iz] += RH(plev[iz], t, h2o);
192 rhicem[iz] += RHICE(plev[iz], t, h2o);
193 tdewm[iz] += TDEW(plev[iz], h2o);
194 ticem[iz] += TICE(plev[iz], h2o);
195 hno3m[iz] += clim_zm(&clim->hno3, met->time, lat, plev[iz]);
196 tnatm[iz] +=
197 nat_temperature(plev[iz], h2o,
198 clim_zm(&clim->hno3, met->time, lat, plev[iz]));
199 ohm[iz] += clim_oh(&ctl, clim, met->time, lon, lat, plev[iz]);
200 h2o2m[iz] += clim_zm(&clim->h2o2, met->time, lat, plev[iz]);
201 ho2m[iz] += clim_zm(&clim->ho2, met->time, lat, plev[iz]);
202 o1dm[iz] += clim_zm(&clim->o1d, met->time, lat, plev[iz]);
203 np[iz]++;
204 }
205 }
206 }
207
208 /* Create output file... */
209 LOG(1, "Write meteorological data file: %s", argv[2]);
210 if (!(out = fopen(argv[2], "w")))
211 ERRMSG("Cannot create file!");
212
213 /* Write header... */
215
216 /* Write data... */
217 fprintf(out, "\n");
218 for (iz = 0; iz < nz; iz++)
219 fprintf(out,
220 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
221 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
222 " %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %d\n",
223 timem[iz] / np[iz], Z(plev[iz]), lonm[iz] / np[iz],
224 latm[iz] / np[iz], plev[iz], tm[iz] / np[iz], um[iz] / np[iz],
225 vm[iz] / np[iz], wm[iz] / np[iz], h2om[iz] / np[iz],
226 o3m[iz] / np[iz], zm[iz] / np[iz], pvm[iz] / np[iz],
227 psm[iz] / np[iz], tsm[iz] / np[iz], zsm[iz] / np[iz],
228 usm[iz] / np[iz], vsm[iz] / np[iz], essm[iz] / np[iz],
229 nssm[iz] / np[iz], shfm[iz] / np[iz], lsmm[iz] / np[iz],
230 sstm[iz] / np[iz], ptm[iz] / npt[iz], ztm[iz] / npt[iz],
231 ttm[iz] / npt[iz], h2otm[iz] / npt[iz],
232 lwcm[iz] / np[iz], rwcm[iz] / np[iz], iwcm[iz] / np[iz],
233 swcm[iz] / np[iz], ccm[iz] / np[iz], clm[iz] / np[iz],
234 pctm[iz] / np[iz], pcbm[iz] / np[iz], plclm[iz] / npc[iz],
235 plfcm[iz] / npc[iz], pelm[iz] / npc[iz], capem[iz] / npc[iz],
236 cinm[iz] / npc[iz], rhm[iz] / np[iz], rhicem[iz] / np[iz],
237 tdewm[iz] / np[iz], ticem[iz] / np[iz], tnatm[iz] / np[iz],
238 hno3m[iz] / np[iz], ohm[iz] / np[iz], h2o2m[iz] / np[iz],
239 ho2m[iz] / np[iz], o1dm[iz] / np[iz], pblm[iz] / np[iz],
240 o3cm[iz] / np[iz], np[iz], npt[iz], npc[iz]);
241
242 /* Close file... */
243 fclose(out);
244
245 /* Free... */
246 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);
247
248 return EXIT_SUCCESS;
249}
#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:414
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, depo_t *depo, dd_t *dd)
Frees memory resources allocated for MPTRAC.
Definition: mptrac.c:6397
double nat_temperature(const double p, const double h2o, const double hno3)
Calculates the nitric acid trihydrate (NAT) temperature.
Definition: mptrac.c:8359
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:12462
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:6683
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 mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm, depo_t **depo, dd_t **dd)
Allocates and initializes memory resources for MPTRAC.
Definition: mptrac.c:6314
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:7767
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:6743
#define INTPOL_SPACE_ALL(p, lon, lat)
Interpolate multiple meteorological variables in space.
Definition: mptrac.h:1223
#define INTPOL_INIT
Initialize arrays for interpolation.
Definition: mptrac.h:1173
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:2405
#define USAGE
Print usage information on -h or --help.
Definition: mptrac.h:2212
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:2242
#define P(z)
Compute pressure at given altitude.
Definition: mptrac.h:1783
#define MET_HEADER
Write header for meteorological data file.
Definition: mptrac.h:1391
#define TICE(p, h2o)
Calculate frost point temperature (WMO, 2018).
Definition: mptrac.h:2099
#define RHICE(p, t, h2o)
Compute relative humidity over ice.
Definition: mptrac.h:1935
#define RH(p, t, h2o)
Compute relative humidity over water.
Definition: mptrac.h:1905
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:2335
#define TDEW(p, h2o)
Calculate dew point temperature.
Definition: mptrac.h:2074
Climatological data.
Definition: mptrac.h:3787
clim_zm_t ho2
HO2 zonal means.
Definition: mptrac.h:3817
clim_zm_t hno3
HNO3 zonal means.
Definition: mptrac.h:3808
clim_zm_t o1d
O(1D) zonal means.
Definition: mptrac.h:3820
clim_zm_t h2o2
H2O2 zonal means.
Definition: mptrac.h:3814
Control parameters.
Definition: mptrac.h:2493
double conv_cape
CAPE threshold for convection module [J/kg].
Definition: mptrac.h:3074
double conv_cin
CIN threshold for convection module [J/kg].
Definition: mptrac.h:3077
Domain decomposition data structure.
Definition: mptrac.h:4023
Meteo data structure.
Definition: mptrac.h:3846
int np
Number of pressure levels.
Definition: mptrac.h:3861
double lon[EX]
Longitudes [deg].
Definition: mptrac.h:3867
double time
Time [s].
Definition: mptrac.h:3849
double lat[EY]
Latitudes [deg].
Definition: mptrac.h:3870
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3873
Here is the call graph for this function: