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 ess, nss, shf, lsm, sst, pbl, pt, pct, pcb, cl, plcl, plfc, pel,
47 cape, cin, o3c, pv, t, tt, u, v, w, z, zm, zref, zt, time_old = -999,
48 p_old = -999, lon_old = -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 const int geopot =
63 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GEOPOT", -1, "0", NULL);
64 const int grid_time =
65 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_TIME", -1, "0", NULL);
66 const int grid_z =
67 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_Z", -1, "0", NULL);
68 const int grid_lon =
69 (int) scan_ctl(argv[1], argc, argv, "SAMPLE_GRID_LON", -1, "0", NULL);
70 const 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 %g"
130 " %g %g %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,
134 ess, nss, shf, lsm,
135 sst, pt, zt, tt, h2ot, lwc, rwc, iwc, swc, cc, cl, pct, pcb, plcl,
136 plfc, pel, cape, cin, RH(atm->p[ip], t, h2o), RHICE(atm->p[ip], t,
137 h2o),
138 TDEW(atm->p[ip], h2o), TICE(atm->p[ip], h2o),
139 nat_temperature(atm->p[ip], h2o,
140 clim_zm(&clim->hno3, atm->time[ip], atm->lat[ip],
141 atm->p[ip])), clim_zm(&clim->hno3,
142 atm->time[ip],
143 atm->lat[ip],
144 atm->p[ip]),
145 clim_oh(&ctl, clim, atm->time[ip], atm->lon[ip], atm->lat[ip],
146 atm->p[ip]), clim_zm(&clim->h2o2, atm->time[ip],
147 atm->lat[ip], atm->p[ip]),
148 clim_zm(&clim->ho2, atm->time[ip], atm->lat[ip], atm->p[ip]),
149 clim_zm(&clim->o1d, atm->time[ip], atm->lat[ip], atm->p[ip]), pbl,
150 o3c);
151 }
152
153 /* Close file... */
154 fclose(out);
155
156 /* Free... */
157 free(clim);
158 free(atm);
159 free(met0);
160 free(met1);
161
162 return EXIT_SUCCESS;
163}
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:1003
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:1652
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
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:4566
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_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 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 INTPOL_TIME_ALL(time, p, lon, lat)
Interpolate multiple meteorological variables in time.
Definition: mptrac.h:786
#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
Air parcel data.
Definition: mptrac.h:3147
double time[NP]
Time [s].
Definition: mptrac.h:3153
double lat[NP]
Latitude [deg].
Definition: mptrac.h:3162
double lon[NP]
Longitude [deg].
Definition: mptrac.h:3159
int np
Number of air parcels.
Definition: mptrac.h:3150
double p[NP]
Pressure [hPa].
Definition: mptrac.h:3156
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
Meteo data structure.
Definition: mptrac.h:3374
int np
Number of pressure levels.
Definition: mptrac.h:3386
float z[EX][EY][EP]
Geopotential height [km].
Definition: mptrac.h:3476
double p[EP]
Pressure levels [hPa].
Definition: mptrac.h:3398
Here is the call graph for this function: