66 static double p2[1000], t[1000], t2[1000], z[1000], z2[1000], lat_mean,
69 static int hist_max[1000], hist_min[1000], hist_mean[1000], hist_sig[1000],
70 nhist_max, nhist_min, nhist_mean, nhist_sig, np;
73 mptrac_alloc(NULL, NULL, &clim, &met, NULL, NULL, NULL, &dd);
80 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
81 "Usage: met_lapse <ctl> <lapse.tab> <met0> [<met1> ...]\n\n"
82 "Use -h for full help.");
87 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_DZ", -1,
"20", NULL);
89 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_LAT0", -1,
"-90", NULL);
91 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_LAT1", -1,
"90", NULL);
93 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_Z0", -1,
"0", NULL);
95 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_Z1", -1,
"100", NULL);
97 (int)
scan_ctl(argv[1], argc, argv,
"LAPSE_INTPOL", -1,
"1", NULL);
103 for (
int i = 3; i < argc; i++) {
110 for (
int iz = 0; iz < met->
np; iz++)
111 z[iz] =
Z(met->
p[iz]);
112 for (
int iz = 0; iz <= 250; iz++) {
113 z2[iz] = 0.0 + 0.1 * iz;
118 for (
int ix = 0; ix < met->
nx; ix++)
119 for (
int iy = 0; iy < met->
ny; iy++) {
122 if (met->
lat[iy] < lat0 || met->
lat[iy] > lat1)
126 for (
int iz = 0; iz < met->
np; iz++)
127 t[iz] = met->
t[ix][iy][iz];
131 for (
int iz = 0; iz <= 250; iz++) {
133 t2[iz] =
LIN(z[idx], t[idx], z[idx + 1], t[idx + 1], z2[iz]);
137 for (
int iz = 0; iz <= 250; iz++) {
140 if (z2[iz] < z0 || z2[iz] > z1)
144 if (p2[iz] > met->
ps[ix][iy])
148 lat_mean += met->
lat[iy];
154 double lapse_max = -1e99, lapse_min = 1e99, lapse_mean =
156 for (
int iz2 = iz + 1; iz2 <= iz + dz; iz2++) {
158 MAX(
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]), lapse_max);
160 MIN(
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]), lapse_min);
161 lapse_mean +=
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]);
162 lapse_sig +=
SQR(
LAPSE(p2[iz], t2[iz], p2[iz2], t2[iz2]));
165 lapse_mean /= nlapse;
166 lapse_sig = sqrt(
MAX(lapse_sig / nlapse -
SQR(lapse_mean), 0));
170 if (idx >= 0 && idx <
IDXMAX) {
176 if (idx >= 0 && idx <
IDXMAX) {
182 if (idx >= 0 && idx <
IDXMAX) {
188 if (idx >= 0 && idx <
IDXMAX) {
197 LOG(1,
"Write lapse rate data: %s", argv[2]);
198 if (!(out = fopen(argv[2],
"w")))
199 ERRMSG(
"Cannot create file!");
203 "# $1 = mean altitude [km]\n"
204 "# $2 = mean latitude [deg]\n"
205 "# $3 = lapse rate [K/km]\n"
206 "# $4 = counts of maxima per bin\n"
207 "# $5 = total number of maxima\n"
208 "# $6 = normalized frequency of maxima\n"
209 "# $7 = counts of minima per bin\n"
210 "# $8 = total number of minima\n"
211 "# $9 = normalized frequency of minima\n"
212 "# $10 = counts of means per bin\n"
213 "# $11 = total number of means\n"
214 "# $12 = normalized frequency of means\n"
215 "# $13 = counts of sigmas per bin\n"
216 "# $14 = total number of sigmas\n"
217 "# $15 = normalized frequency of sigmas\n\n");
220 double nmax_max = 0, nmax_min = 0, nmax_mean = 0, nmax_sig = 0;
221 for (
int idx = 0; idx <
IDXMAX; idx++) {
222 nmax_max =
MAX(hist_max[idx], nmax_max);
223 nmax_min =
MAX(hist_min[idx], nmax_min);
224 nmax_mean =
MAX(hist_mean[idx], nmax_mean);
225 nmax_sig =
MAX(hist_sig[idx], nmax_sig);
227 for (
int idx = 0; idx <
IDXMAX; idx++)
229 "%g %g %g %d %d %g %d %d %g %d %d %g %d %d %g\n",
231 hist_max[idx], nhist_max,
232 (
double) hist_max[idx] / (
double) nmax_max, hist_min[idx],
233 nhist_min, (
double) hist_min[idx] / (
double) nmax_min,
234 hist_mean[idx], nhist_mean,
235 (
double) hist_mean[idx] / (
double) nmax_mean, hist_sig[idx],
236 nhist_sig, (
double) hist_sig[idx] / (
double) nmax_sig);
242 mptrac_free(NULL, NULL, clim, met, NULL, NULL, NULL, dd);
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.
void spline(const double *x, const double *y, const int n, const double *x2, double *y2, const int n2, const int method)
Performs spline interpolation or linear interpolation.
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_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.