41 {
42
44
46
48
50
52
53 FILE *out;
54
55 double h2o, h2ot, o3, lwc, rwc, iwc, swc, cc, p0, p1, ps, ts, zs, us, vs,
56 ess, nss, shf, lsm, sst, pbl, pt, pct, pcb, cl, plcl, plfc, pel,
57 cape, cin, o3c, pv, t, tt, u, v, w, z, zm, zref, zt, time_old = -999,
58 p_old = -999, lon_old = -999, lat_old = -999;
59
60
62
63
64 if (argc < 3)
65 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
66 "Usage: met_sample <ctl> <sample.tab> <atm_in> [KEY VALUE ...]\n\n"
67 "Use -h for full help.");
68
69
75
76
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
91
92
94 ERRMSG(
"Cannot open file!");
95
96
97 LOG(1,
"Write meteorological data file: %s", argv[2]);
98 if (!(out = fopen(argv[2], "w")))
99 ERRMSG(
"Cannot create file!");
100
101
103
104
105 for (
int ip = 0; ip < atm->
np; ip++) {
106
107
109
110
112 double pref = atm->
p[ip];
113 if (geopot) {
116 p1 = met0->
p[met0->
np - 1];
117 for (int it = 0; it < 24; it++) {
118 pref = 0.5 * (p0 + p1);
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
131
132
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];
140 lon_old = atm->
lon[ip];
141 lat_old = atm->
lat[ip];
142
143
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),
163 atm->
lat[ip], atm->
p[ip]),
166 o3c);
167 }
168
169
170 fclose(out);
171
172
173 free(clim);
174 free(atm);
175 free(met0);
176 free(met1);
177 free(dd);
178
179 return EXIT_SUCCESS;
180}
double clim_zm(const clim_zm_t *zm, const double t, const double lat, const double p)
Interpolates monthly mean zonal mean climatological variables.
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.
double nat_temperature(const double p, const double h2o, const double hno3)
Calculates the nitric acid trihydrate (NAT) temperature.
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.
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.
void mptrac_read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
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.
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...
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.
#define INTPOL_INIT
Initialize arrays for interpolation.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define USAGE
Print usage information on -h or --help.
#define Z(p)
Convert pressure to altitude.
#define MET_HEADER
Write header for meteorological data file.
#define TICE(p, h2o)
Calculate frost point temperature (WMO, 2018).
#define RHICE(p, t, h2o)
Compute relative humidity over ice.
#define INTPOL_TIME_ALL(time, p, lon, lat)
Interpolate multiple meteorological variables in time.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define RH(p, t, h2o)
Compute relative humidity over water.
#define LOG(level,...)
Print a log message with a specified logging level.
#define TDEW(p, h2o)
Calculate dew point temperature.
double lat[NP]
Latitude [deg].
double lon[NP]
Longitude [deg].
int np
Number of air parcels.
double p[NP]
Pressure [hPa].
clim_zm_t ho2
HO2 zonal means.
clim_zm_t hno3
HNO3 zonal means.
clim_zm_t o1d
O(1D) zonal means.
clim_zm_t h2o2
H2O2 zonal means.
Domain decomposition data structure.
int np
Number of pressure levels.
float z[EX][EY][EP]
Geopotential height [km].
double p[EP]
Pressure levels [hPa].