MPTRAC
Functions
met_sample.c File Reference

Sample meteorological data at given geolocations. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

void usage (void)
 Print command-line help. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Sample meteorological data at given geolocations.

Definition in file met_sample.c.

Function Documentation

◆ usage()

void usage ( void  )

Print command-line help.

Definition at line 181 of file met_sample.c.

182 {
183
184 printf("\nMPTRAC met_sample tool.\n\n");
185 printf("Sample meteorological data at atmospheric particle locations.\n");
186 printf("\n");
187 printf("Usage:\n");
188 printf(" met_sample <ctl> <sample.tab> <atm_in> [KEY VALUE ...]\n");
189 printf("\n");
190 printf("Arguments:\n");
191 printf(" <ctl> Control file.\n");
192 printf(" <sample.tab> Output table.\n");
193 printf(" <atm_in> Atmospheric input file with sample locations.\n");
194 printf(" [KEY VALUE] Optional control parameters.\n");
195 printf("\nFurther information:\n");
196 printf(" Manual: https://slcs-jsc.github.io/mptrac/\n");
197}

◆ main()

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

Definition at line 39 of file met_sample.c.

41 {
42
43 ctl_t *ctl;
44
45 cache_t *cache;
46
47 clim_t *clim;
48
49 atm_t *atm;
50
51 depo_t *depo;
52
53 met_t *met0, *met1;
54
55 dd_t *dd;
56
57 FILE *out;
58
59 double h2o, h2ot, o3, lwc, rwc, iwc, swc, cc, p0, p1, ps, ts, zs, us, vs,
60 ess, nss, shf, lsm, sst, pbl, pt, pct, pcb, cl, plcl, plfc, pel,
61 cape, cin, o3c, pv, t, tt, u, v, w, z, zm, zref, zt, time_old = -999,
62 p_old = -999, lon_old = -999, lat_old = -999;
63
64 /* Print usage information... */
65 USAGE;
66
67 /* Check arguments... */
68 if (argc < 3)
69 ERRMSG("Missing or invalid command-line arguments.\n\n"
70 "Usage: met_sample <ctl> <sample.tab> <atm_in> [KEY VALUE ...]\n\n"
71 "Use -h for full help.");
72
73 /* Allocate... */
74 mptrac_alloc(&ctl, &cache, &clim, &met0, &met1, &atm, &depo, &dd);
75
76 /* Read control parameters... */
77 mptrac_read_ctl(argv[1], argc, argv, ctl);
78 const int geopot =
79 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GEOPOT", -1, "0", NULL);
80 const int grid_time =
81 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_TIME", -1, "0", NULL);
82 const int grid_z =
83 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_Z", -1, "0", NULL);
84 const int grid_lon =
85 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_LON", -1, "0", NULL);
86 const int grid_lat =
87 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_LAT", -1, "0", NULL);
88
89 /* Read climatological data... */
90 mptrac_read_clim(ctl, clim);
91
92 /* Read atmospheric data... */
93 if (!mptrac_read_atm(argv[3], ctl, atm))
94 ERRMSG("Cannot open file!");
95
96 /* Create output file... */
97 LOG(1, "Write meteorological data file: %s", argv[2]);
98 if (!(out = fopen(argv[2], "w")))
99 ERRMSG("Cannot create file!");
100
101 /* Write header... */
103
104 /* Loop over air parcels... */
105 for (int ip = 0; ip < atm->np; ip++) {
106
107 /* Get meteorological data... */
108 mptrac_get_met(ctl, clim, atm->time[ip], &met0, &met1, dd);
109
110 /* Set reference pressure for interpolation... */
112 double pref = atm->p[ip];
113 if (geopot) {
114 zref = Z(pref);
115 p0 = met0->p[0];
116 p1 = met0->p[met0->np - 1];
117 for (int it = 0; it < 24; it++) {
118 pref = 0.5 * (p0 + p1);
119 intpol_met_time_3d(met0, met0->z, met1, met1->z, atm->time[ip], pref,
120 atm->lon[ip], atm->lat[ip], &zm, ci, cw, 1);
121 if (zref > zm || !isfinite(zm))
122 p0 = pref;
123 else
124 p1 = pref;
125 }
126 pref = 0.5 * (p0 + p1);
127 }
128
129 /* Interpolate meteo data... */
130 INTPOL_TIME_ALL(atm->time[ip], pref, atm->lon[ip], atm->lat[ip]);
131
132 /* Make blank lines... */
133 if (ip == 0 || (grid_time && atm->time[ip] != time_old)
134 || (grid_z && atm->p[ip] != p_old)
135 || (grid_lon && atm->lon[ip] != lon_old)
136 || (grid_lat && atm->lat[ip] != lat_old))
137 fprintf(out, "\n");
138 time_old = atm->time[ip];
139 p_old = atm->p[ip];
140 lon_old = atm->lon[ip];
141 lat_old = atm->lat[ip];
142
143 /* Write data... */
144 fprintf(out,
145 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
146 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
147 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g 1 1 1\n",
148 atm->time[ip], Z(atm->p[ip]), atm->lon[ip], atm->lat[ip],
149 atm->p[ip], t, u, v, w, h2o, o3, z, pv, ps, ts, zs, us, vs,
150 ess, nss, shf, lsm,
151 sst, pt, zt, tt, h2ot, lwc, rwc, iwc, swc, cc, cl, pct, pcb, plcl,
152 plfc, pel, cape, cin, RH(atm->p[ip], t, h2o), RHICE(atm->p[ip], t,
153 h2o),
154 TDEW(atm->p[ip], h2o), TICE(atm->p[ip], h2o),
155 nat_temperature(atm->p[ip], h2o,
156 clim_zm(&clim->hno3, atm->time[ip], atm->lat[ip],
157 atm->p[ip])), clim_zm(&clim->hno3,
158 atm->time[ip],
159 atm->lat[ip],
160 atm->p[ip]),
161 clim_oh(ctl, clim, atm->time[ip], atm->lon[ip], atm->lat[ip],
162 atm->p[ip]), clim_zm(&clim->h2o2, atm->time[ip],
163 atm->lat[ip], atm->p[ip]),
164 clim_zm(&clim->ho2, atm->time[ip], atm->lat[ip], atm->p[ip]),
165 clim_zm(&clim->o1d, atm->time[ip], atm->lat[ip], atm->p[ip]), pbl,
166 o3c);
167 }
168
169 /* Close file... */
170 fclose(out);
171
172 /* Free... */
173 mptrac_free(ctl, cache, clim, met0, met1, atm, depo, dd);
174
175 return EXIT_SUCCESS;
176}
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
void intpol_met_time_3d(const met_t *met0, float array0[EX][EY][EP], const met_t *met1, float array1[EX][EY][EP], const double ts, const double p, const double lon, const double lat, double *var, int *ci, double *cw, const int init)
Interpolates meteorological data in 3D space and time.
Definition: mptrac.c:3112
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_get_met(ctl_t *ctl, clim_t *clim, const double t, met_t **met0, met_t **met1, dd_t *dd)
Retrieves meteorological data for the specified time.
Definition: mptrac.c:6458
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
int mptrac_read_atm(const char *filename, const ctl_t *ctl, atm_t *atm)
Reads air parcel data from a specified file into the given atmospheric structure.
Definition: mptrac.c:6608
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
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_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 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 INTPOL_TIME_ALL(time, p, lon, lat)
Interpolate multiple meteorological variables in time.
Definition: mptrac.h:1277
#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
Air parcel data.
Definition: mptrac.h:3565
double time[NP]
Time [s].
Definition: mptrac.h:3571
double lat[NP]
Latitude [deg].
Definition: mptrac.h:3580
double lon[NP]
Longitude [deg].
Definition: mptrac.h:3577
int np
Number of air parcels.
Definition: mptrac.h:3568
double p[NP]
Pressure [hPa].
Definition: mptrac.h:3574
Cache data structure.
Definition: mptrac.h:3620
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
Domain decomposition data structure.
Definition: mptrac.h:4023
Ground inventories of deposited radionuclides.
Definition: mptrac.h:3656
Meteo data structure.
Definition: mptrac.h:3846
int np
Number of pressure levels.
Definition: mptrac.h:3861
float z[EX][EY][EP]
Geopotential height [km].
Definition: mptrac.h:3960
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3873
Here is the call graph for this function: