46 static char varname[
LEN];
48 static double lons[
EX], lats[
EY], *zm, *zs, *pm, *ps, *tm, *ts, *qm, *qs,
51 static float *tropo_z0, *tropo_p0, *tropo_t0, *tropo_q0, *tropo_o30;
53 static int ncid, varid, varid_z, varid_p, varid_t, varid_q, varid_o3, h2o,
54 o3, *n, *nt, ntime, nlon, nlat;
56 static size_t count[10], start[10];
80 ALLOC(tropo_z0,
float,
82 ALLOC(tropo_p0,
float,
84 ALLOC(tropo_t0,
float,
86 ALLOC(tropo_q0,
float,
88 ALLOC(tropo_o30,
float,
98 ERRMSG(
"Give parameters: <ctl> <clim.tab> <var> <tropo.nc>");
101 read_ctl(argv[1], argc, argv, &ctl);
104 for (
int iarg = 4; iarg < argc; iarg++) {
107 LOG(1,
"Read tropopause data: %s", argv[iarg]);
108 if (nc_open(argv[iarg], NC_NOWRITE, &ncid) != NC_NOERR)
109 ERRMSG(
"Cannot open file!");
121 sprintf(varname,
"%s_z", argv[3]);
122 NC(nc_inq_varid(ncid, varname, &varid_z));
123 sprintf(varname,
"%s_p", argv[3]);
124 NC(nc_inq_varid(ncid, varname, &varid_p));
125 sprintf(varname,
"%s_t", argv[3]);
126 NC(nc_inq_varid(ncid, varname, &varid_t));
127 sprintf(varname,
"%s_q", argv[3]);
128 h2o = (nc_inq_varid(ncid, varname, &varid_q) == NC_NOERR);
129 sprintf(varname,
"%s_o3", argv[3]);
130 o3 = (nc_inq_varid(ncid, varname, &varid_o3) == NC_NOERR);
134 count[1] = (size_t) nlat;
135 count[2] = (size_t) nlon;
138 for (
int it = 0; it < ntime; it++) {
141 start[0] = (size_t) it;
142 NC(nc_get_vara_float(ncid, varid_z, start, count, tropo_z0));
143 NC(nc_get_vara_float(ncid, varid_p, start, count, tropo_p0));
144 NC(nc_get_vara_float(ncid, varid_t, start, count, tropo_t0));
146 NC(nc_get_vara_float(ncid, varid_q, start, count, tropo_q0));
148 for (
int i = 0; i < nlon * nlat; i++)
151 NC(nc_get_vara_float(ncid, varid_o3, start, count, tropo_o30));
153 for (
int i = 0; i < nlon * nlat; i++)
157 for (
int i = 0; i < nlon * nlat; i++) {
159 if (isfinite(tropo_z0[i])
160 && isfinite(tropo_p0[i])
161 && isfinite(tropo_t0[i])
162 && (!h2o || isfinite(tropo_q0[i]))
163 && (!o3 || isfinite(tropo_o30[i]))) {
164 zm[i] += tropo_z0[i];
165 zs[i] +=
SQR(tropo_z0[i]);
166 pm[i] += tropo_p0[i];
167 ps[i] +=
SQR(tropo_p0[i]);
168 tm[i] += tropo_t0[i];
169 ts[i] +=
SQR(tropo_t0[i]);
170 qm[i] += tropo_q0[i];
171 qs[i] +=
SQR(tropo_q0[i]);
172 o3m[i] += tropo_o30[i];
173 o3s[i] +=
SQR(tropo_o30[i]);
184 for (
int i = 0; i < nlon * nlat; i++)
191 double aux = zs[i] / n[i] -
SQR(zm[i]);
192 zs[i] = aux > 0 ? sqrt(aux) : 0.0;
193 aux = ps[i] / n[i] -
SQR(pm[i]);
194 ps[i] = aux > 0 ? sqrt(aux) : 0.0;
195 aux = ts[i] / n[i] -
SQR(tm[i]);
196 ts[i] = aux > 0 ? sqrt(aux) : 0.0;
197 aux = qs[i] / n[i] -
SQR(qm[i]);
198 qs[i] = aux > 0 ? sqrt(aux) : 0.0;
199 aux = o3s[i] / n[i] -
SQR(o3m[i]);
200 o3s[i] = aux > 0 ? sqrt(aux) : 0.0;
204 LOG(1,
"Write tropopause climatological data: %s", argv[2]);
205 if (!(out = fopen(argv[2],
"w")))
206 ERRMSG(
"Cannot create file!");
210 "# $1 = longitude [deg]\n"
211 "# $2 = latitude [deg]\n"
212 "# $3 = tropopause height (mean) [km]\n"
213 "# $4 = tropopause pressure (mean) [hPa]\n"
214 "# $5 = tropopause temperature (mean) [K]\n"
215 "# $6 = tropopause water vapor (mean) [ppv]\n"
216 "# $7 = tropopause ozone (mean) [ppv]\n"
217 "# $8 = tropopause height (sigma) [km]\n"
218 "# $9 = tropopause pressure (sigma) [hPa]\n"
219 "# $10 = tropopause temperature (sigma) [K]\n"
220 "# $11 = tropopause water vapor (sigma) [ppv]\n"
221 "# $12 = tropopause ozone (sigma) [ppv]\n"
222 "# $13 = number of data points\n"
223 "# $14 = occurrence frequency [%%]\n");
226 for (
int ilat = 0; ilat < nlat; ilat++) {
228 for (
int ilon = 0; ilon < nlon; ilon++)
229 fprintf(out,
"%g %g %g %g %g %g %g %g %g %g %g %g %d %g\n",
230 lons[ilon], lats[ilat], zm[ilat * nlon + ilon],
231 pm[ilat * nlon + ilon], tm[ilat * nlon + ilon],
232 qm[ilat * nlon + ilon], o3m[ilat * nlon + ilon],
233 zs[ilat * nlon + ilon], ps[ilat * nlon + ilon],
234 ts[ilat * nlon + ilon], qs[ilat * nlon + ilon],
235 o3s[ilat * nlon + ilon], n[ilat * nlon + ilon],
236 100. * n[ilat * nlon + ilon] / nt[ilat * nlon + ilon]);
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.
MPTRAC library declarations.
#define LEN
Maximum length of ASCII data lines.
#define NC(cmd)
Execute a NetCDF command and check for errors.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define EY
Maximum number of latitudes for meteo data.
#define EX
Maximum number of longitudes for meteo data.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define SQR(x)
Compute the square of a value.
#define NC_INQ_DIM(dimname, ptr, min, max)
Inquire the length of a dimension in a NetCDF file.
#define LOG(level,...)
Print a log message with a specified logging level.
#define NC_GET_DOUBLE(varname, ptr, force)
Retrieve a double-precision variable from a NetCDF file.
int main(int argc, char *argv[])
#define NT
Maximum number of time steps.