53 static double lon0, lon1, lat0, lat1, z0, z1, mean[
GX][
GY][
GZ],
56 tmean[
GX][
GY][
GZ], twmean[
GX][
GY], se[
NZ], sz[
NZ], tw, w, wmax, wsum;
58 static int iarg, ids, idx, ix, iy, iz, iz2,
66 ERRMSG(
"Give parameters: <ctl> <var.tab> <sens.tab> "
67 "<gps1.nc> [<gps2.nx> ...]");
70 z0 = scan_ctl(argc, argv,
"Z0", -1,
"0", NULL);
71 z1 = scan_ctl(argc, argv,
"Z1", -1,
"60", NULL);
72 nz = (int) scan_ctl(argc, argv,
"NZ", -1,
"6", NULL);
73 lon0 = scan_ctl(argc, argv,
"LON0", -1,
"-180", NULL);
74 lon1 = scan_ctl(argc, argv,
"LON1", -1,
"180", NULL);
75 nx = (int) scan_ctl(argc, argv,
"NX", -1,
"72", NULL);
76 lat0 = scan_ctl(argc, argv,
"LAT0", -1,
"-90", NULL);
77 lat1 = scan_ctl(argc, argv,
"LAT1", -1,
"90", NULL);
78 ny = (int) scan_ctl(argc, argv,
"NY", -1,
"36", NULL);
81 if (nx < 1 || nx >
GX)
82 ERRMSG(
"Set 1 <= GX <= MAX!");
83 if (ny < 1 || ny >
GY)
84 ERRMSG(
"Set 1 <= GY <= MAX!");
85 if (nz < 1 || nz >
GZ)
86 ERRMSG(
"Set 1 <= GZ <= MAX!");
89 if (argv[3][0] !=
'-') {
90 read_shape(argv[3], sz, se, &sn);
92 ERRMSG(
"Too many data points!");
96 for (iarg = 4; iarg < argc; iarg++) {
100 if (!(in = fopen(argv[iarg],
"r")))
108 for (ids = 0; ids < gps->
nds; ids++) {
111 if (!gsl_finite(gps->
th[ids]))
115 if (argv[3][0] !=
'-') {
116 tw = wsum = wmax = 0;
117 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++) {
118 if (gps->
z[ids][iz2] < sz[0] || gps->
z[ids][iz2] > sz[sn - 1])
121 idx = locate_irr(sz, sn, gps->
z[ids][iz2]);
123 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1],
126 if (gsl_finite(gps->
t[ids][iz2]) && gps->
pt[ids][iz2]) {
127 tw += w * gps->
t[ids][iz2];
129 gps->
pt[ids][iz2] *= w;
130 wmax = GSL_MAX(w, wmax);
134 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++)
135 gps->
pt[ids][iz2] /= wmax;
139 ix = (int) ((gps->
lon[ids][gps->
nz[ids] / 2] - lon0)
140 / (lon1 - lon0) * (
double) nx);
141 iy = (int) ((gps->
lat[ids][gps->
nz[ids] / 2] - lat0)
142 / (lat1 - lat0) * (
double) ny);
143 if (ix < 0 || ix >= nx || iy < 0 || iy >= ny)
147 mtime[ix][iy] += gps->
time[ids];
148 thmean[ix][iy] += gps->
th[ids];
149 twmean[ix][iy] += tw;
153 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++) {
156 iz = (int) ((gps->
z[ids][iz2] - z0)
157 / (z1 - z0) * (
double) nz);
158 if (iz < 0 || iz >= nz)
162 if (!gsl_finite(gps->
t[ids][iz2]) || !gsl_finite(gps->
pt[ids][iz2]))
166 tmean[ix][iy][iz] += gps->
t[ids][iz2];
167 mean[ix][iy][iz] += gps->
pt[ids][iz2];
168 var[ix][iy][iz] += gsl_pow_2(gps->
pt[ids][iz2]);
169 max[ix][iy][iz] = GSL_MAX(max[ix][iy][iz], gps->
pt[ids][iz2]);
170 min[ix][iy][iz] = GSL_MIN(min[ix][iy][iz], gps->
pt[ids][iz2]);
177 for (ix = 0; ix < nx; ix++)
178 for (iy = 0; iy < ny; iy++) {
181 if (np[ix][iy] > 0) {
182 mtime[ix][iy] /= (double) np[ix][iy];
183 thmean[ix][iy] /= (double) np[ix][iy];
184 twmean[ix][iy] /= (double) np[ix][iy];
186 mtime[ix][iy] = GSL_NAN;
187 thmean[ix][iy] = GSL_NAN;
188 twmean[ix][iy] = GSL_NAN;
192 for (iz = 0; iz < nz; iz++) {
195 gz[iz] = z0 + (iz + 0.5) / (
double) nz *(
197 glon[ix] = lon0 + (ix + 0.5) / (
double) nx *(
199 glat[iy] = lat0 + (iy + 0.5) / (
double) ny *(
203 if (n[ix][iy][iz] > 0) {
205 /= (double) n[ix][iy][iz];
207 /= (double) n[ix][iy][iz];
209 = var[ix][iy][iz] / (double) n[ix][iy][iz]
210 - gsl_pow_2(mean[ix][iy][iz]);
212 tmean[ix][iy][iz] = GSL_NAN;
213 mean[ix][iy][iz] = GSL_NAN;
214 var[ix][iy][iz] = GSL_NAN;
215 min[ix][iy][iz] = GSL_NAN;
216 max[ix][iy][iz] = GSL_NAN;
222 printf(
"Write variance statistics: %s\n", argv[2]);
223 if (!(out = fopen(argv[2],
"w")))
224 ERRMSG(
"Cannot create file!");
229 "# $2 = altitude [km]\n"
230 "# $3 = longitude [deg]\n"
231 "# $4 = latitude [deg]\n"
232 "# $5 = number of profiles\n"
233 "# $6 = number of data points\n"
234 "# $7 = mean perturbation [K]\n"
235 "# $8 = minimum perturbation [K]\n"
236 "# $9 = maximum perturbation [K]\n"
237 "# $10 = variance [K^2]\n"
238 "# $11 = mean temperature [K]\n"
239 "# $12 = mean weighted temperature [K]\n"
240 "# $13 = mean tropopause height [km]\n");
243 for (iz = 0; iz < nz; iz++) {
244 for (iy = 0; iy < ny; iy++) {
245 if (iy == 0 || nx > 1)
247 for (ix = 0; ix < nx; ix++)
248 fprintf(out,
"%.2f %g %g %g %d %d %g %g %g %g %g %g %g\n",
249 mtime[ix][iy], gz[iz], glon[ix], glat[iy],
250 np[ix][iy], n[ix][iy][iz], mean[ix][iy][iz],
251 min[ix][iy][iz], max[ix][iy][iz], var[ix][iy][iz],
252 tmean[ix][iy][iz], twmean[ix][iy], thmean[ix][iy]);
void read_gps(char *filename, gps_t *gps)
Read GPS-RO data file.
GPS Code Collection library declarations.
#define NZ
Maximum number of altitudes per GPS-RO profile.
double time[NDS]
Time (seconds since 2000-01-01T00:00Z).
double pt[NDS][NZ]
Temperature perturbation [K].
double t[NDS][NZ]
Temperature [K].
int nz[NDS]
Number of altitudes per profile.
double lon[NDS][NZ]
Longitude [deg].
int nds
Number of profiles.
double th[NDS]
Tropopause height [km].
double z[NDS][NZ]
Altitude [km].
double lat[NDS][NZ]
Latitude [deg].
int main(int argc, char *argv[])