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

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

Detailed Description

Sample meteorological data at given geolocations.

Definition in file met_sample.c.

Function Documentation

◆ main()

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

Definition at line 31 of file met_sample.c.

33 {
34
35 ctl_t ctl;
36
37 clim_t *clim;
38
39 atm_t *atm;
40
41 met_t *met0, *met1;
42
43 FILE *out;
44
45 double h2o, h2ot, o3, lwc, rwc, iwc, swc, cc, p0, p1, ps, ts, zs, us, vs,
46 lsm, sst, pbl, pt, pct, pcb, cl, plcl, plfc, pel, cape, cin, o3c, pv, t,
47 tt, u, v, w, z, zm, zref, zt, time_old = -999, p_old = -999, lon_old =
48 -999, lat_old = -999;
49
50 /* Check arguments... */
51 if (argc < 3)
52 ERRMSG("Give parameters: <ctl> <sample.tab> <atm_in>");
53
54 /* Allocate... */
55 ALLOC(clim, clim_t, 1);
56 ALLOC(atm, atm_t, 1);
57 ALLOC(met0, met_t, 1);
58 ALLOC(met1, met_t, 1);
59
60 /* Read control parameters... */
61 read_ctl(argv[1], argc, argv, &ctl);
62 int geopot =
63 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GEOPOT", -1, "0", NULL);
64 int grid_time =
65 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_TIME", -1, "0", NULL);
66 int grid_z =
67 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_Z", -1, "0", NULL);
68 int grid_lon =
69 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_LON", -1, "0", NULL);
70 int grid_lat =
71 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_LAT", -1, "0", NULL);
72
73 /* Read climatological data... */
74 read_clim(&ctl, clim);
75
76 /* Read atmospheric data... */
77 if (!read_atm(argv[3], &ctl, atm))
78 ERRMSG("Cannot open file!");
79
80 /* Create output file... */
81 LOG(1, "Write meteorological data file: %s", argv[2]);
82 if (!(out = fopen(argv[2], "w")))
83 ERRMSG("Cannot create file!");
84
85 /* Write header... */
87
88 /* Loop over air parcels... */
89 for (int ip = 0; ip < atm->np; ip++) {
90
91 /* Get meteorological data... */
92 get_met(&ctl, clim, atm->time[ip], &met0, &met1);
93
94 /* Set reference pressure for interpolation... */
96 double pref = atm->p[ip];
97 if (geopot) {
98 zref = Z(pref);
99 p0 = met0->p[0];
100 p1 = met0->p[met0->np - 1];
101 for (int it = 0; it < 24; it++) {
102 pref = 0.5 * (p0 + p1);
103 intpol_met_time_3d(met0, met0->z, met1, met1->z, atm->time[ip], pref,
104 atm->lon[ip], atm->lat[ip], &zm, ci, cw, 1);
105 if (zref > zm || !isfinite(zm))
106 p0 = pref;
107 else
108 p1 = pref;
109 }
110 pref = 0.5 * (p0 + p1);
111 }
112
113 /* Interpolate meteo data... */
114 INTPOL_TIME_ALL(atm->time[ip], pref, atm->lon[ip], atm->lat[ip]);
115
116 /* Make blank lines... */
117 if (ip == 0 || (grid_time && atm->time[ip] != time_old)
118 || (grid_z && atm->p[ip] != p_old)
119 || (grid_lon && atm->lon[ip] != lon_old)
120 || (grid_lat && atm->lat[ip] != lat_old))
121 fprintf(out, "\n");
122 time_old = atm->time[ip];
123 p_old = atm->p[ip];
124 lon_old = atm->lon[ip];
125 lat_old = atm->lat[ip];
126
127 /* Write data... */
128 fprintf(out,
129 "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
130 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g"
131 " %g %g %g %g %g %g %g %g %g %g %g %g %g %g 1 1 1\n",
132 atm->time[ip], Z(atm->p[ip]), atm->lon[ip], atm->lat[ip],
133 atm->p[ip], t, u, v, w, h2o, o3, z, pv, ps, ts, zs, us, vs, lsm,
134 sst, pt, zt, tt, h2ot, lwc, rwc, iwc, swc, cc, cl, pct, pcb, plcl,
135 plfc, pel, cape, cin, RH(atm->p[ip], t, h2o), RHICE(atm->p[ip], t,
136 h2o),
137 TDEW(atm->p[ip], h2o), TICE(atm->p[ip], h2o),
138 nat_temperature(atm->p[ip], h2o,
139 clim_zm(&clim->hno3, atm->time[ip], atm->lat[ip],
140 atm->p[ip])), clim_zm(&clim->hno3,
141 atm->time[ip],
142 atm->lat[ip],
143 atm->p[ip]),
144 clim_oh(&ctl, clim, atm->time[ip], atm->lon[ip], atm->lat[ip],
145 atm->p[ip]), clim_zm(&clim->h2o2, atm->time[ip],
146 atm->lat[ip], atm->p[ip]),
147 clim_zm(&clim->ho2, atm->time[ip], atm->lat[ip], atm->p[ip]),
148 clim_zm(&clim->o1d, atm->time[ip], atm->lat[ip], atm->p[ip]), pbl,
149 o3c);
150 }
151
152 /* Close file... */
153 fclose(out);
154
155 /* Free... */
156 free(clim);
157 free(atm);
158 free(met0);
159 free(met1);
160
161 return EXIT_SUCCESS;
162}
void get_met(ctl_t *ctl, clim_t *clim, const double t, met_t **met0, met_t **met1)
Retrieves meteorological data for the specified time.
Definition: mptrac.c:1004
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
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:1653
double nat_temperature(const double p, const double h2o, const double hno3)
Calculates the nitric acid trihydrate (NAT) temperature.
Definition: mptrac.c:4191
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:8098
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:4805
int 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:4215
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:4473
#define INTPOL_INIT
Initialize arrays for interpolation.
Definition: mptrac.h:676
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:1901
#define Z(p)
Convert pressure to altitude.
Definition: mptrac.h:1726
#define MET_HEADER
Write header for meteorological data file.
Definition: mptrac.h:888
#define TICE(p, h2o)
Calculate frost point temperature (WMO, 2018).
Definition: mptrac.h:1605
#define RHICE(p, t, h2o)
Compute relative humidity over ice.
Definition: mptrac.h:1441
#define INTPOL_TIME_ALL(time, p, lon, lat)
Interpolate multiple meteorological variables in time.
Definition: mptrac.h:777
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
Definition: mptrac.h:347
#define RH(p, t, h2o)
Compute relative humidity over water.
Definition: mptrac.h:1411
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1831
#define TDEW(p, h2o)
Calculate dew point temperature.
Definition: mptrac.h:1580
Air parcel data.
Definition: mptrac.h:3120
double time[NP]
Time [s].
Definition: mptrac.h:3126
double lat[NP]
Latitude [deg].
Definition: mptrac.h:3135
double lon[NP]
Longitude [deg].
Definition: mptrac.h:3132
int np
Number of air parcels.
Definition: mptrac.h:3123
double p[NP]
Pressure [hPa].
Definition: mptrac.h:3129
Climatological data.
Definition: mptrac.h:3282
clim_zm_t ho2
HO2 zonal means.
Definition: mptrac.h:3312
clim_zm_t hno3
HNO3 zonal means.
Definition: mptrac.h:3303
clim_zm_t o1d
O(1D) zonal means.
Definition: mptrac.h:3315
clim_zm_t h2o2
H2O2 zonal means.
Definition: mptrac.h:3309
Control parameters.
Definition: mptrac.h:2155
Meteo data structure.
Definition: mptrac.h:3341
int np
Number of pressure levels.
Definition: mptrac.h:3353
float z[EX][EY][EP]
Geopotential height [km].
Definition: mptrac.h:3434
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3365
Here is the call graph for this function: