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++) {
99 if (!(in = fopen(argv[iarg],
"r")))
107 for (ids = 0; ids < gps->
nds; ids++) {
110 if (!gsl_finite(gps->
th[ids]))
114 if (argv[3][0] !=
'-') {
115 tw = wsum = wmax = 0;
116 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++) {
117 if (gps->
z[ids][iz2] < sz[0] || gps->
z[ids][iz2] > sz[sn - 1])
120 idx = locate_irr(sz, sn, gps->
z[ids][iz2]);
122 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1],
125 if (gsl_finite(gps->
t[ids][iz2]) && gps->
pt[ids][iz2]) {
126 tw += w * gps->
t[ids][iz2];
128 gps->
pt[ids][iz2] *= w;
129 wmax = GSL_MAX(w, wmax);
133 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++)
134 gps->
pt[ids][iz2] /= wmax;
138 ix = (int) ((gps->
lon[ids][gps->
nz[ids] / 2] - lon0)
139 / (lon1 - lon0) * (
double) nx);
140 iy = (int) ((gps->
lat[ids][gps->
nz[ids] / 2] - lat0)
141 / (lat1 - lat0) * (
double) ny);
142 if (ix < 0 || ix >= nx || iy < 0 || iy >= ny)
146 mtime[ix][iy] += gps->
time[ids];
147 thmean[ix][iy] += gps->
th[ids];
148 twmean[ix][iy] += tw;
152 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++) {
155 iz = (int) ((gps->
z[ids][iz2] - z0)
156 / (z1 - z0) * (
double) nz);
157 if (iz < 0 || iz >= nz)
161 if (!gsl_finite(gps->
t[ids][iz2]) || !gsl_finite(gps->
pt[ids][iz2]))
165 tmean[ix][iy][iz] += gps->
t[ids][iz2];
166 mean[ix][iy][iz] += gps->
pt[ids][iz2];
167 var[ix][iy][iz] += gsl_pow_2(gps->
pt[ids][iz2]);
168 max[ix][iy][iz] = GSL_MAX(max[ix][iy][iz], gps->
pt[ids][iz2]);
169 min[ix][iy][iz] = GSL_MIN(min[ix][iy][iz], gps->
pt[ids][iz2]);
176 for (ix = 0; ix < nx; ix++)
177 for (iy = 0; iy < ny; iy++) {
180 if (np[ix][iy] > 0) {
181 mtime[ix][iy] /= (double) np[ix][iy];
182 thmean[ix][iy] /= (double) np[ix][iy];
183 twmean[ix][iy] /= (double) np[ix][iy];
185 mtime[ix][iy] = GSL_NAN;
186 thmean[ix][iy] = GSL_NAN;
187 twmean[ix][iy] = GSL_NAN;
191 for (iz = 0; iz < nz; iz++) {
194 gz[iz] = z0 + (iz + 0.5) / (
double) nz *(
196 glon[ix] = lon0 + (ix + 0.5) / (
double) nx *(
198 glat[iy] = lat0 + (iy + 0.5) / (
double) ny *(
202 if (n[ix][iy][iz] > 0) {
204 /= (double) n[ix][iy][iz];
206 /= (double) n[ix][iy][iz];
208 = var[ix][iy][iz] / (double) n[ix][iy][iz]
209 - gsl_pow_2(mean[ix][iy][iz]);
211 tmean[ix][iy][iz] = GSL_NAN;
212 mean[ix][iy][iz] = GSL_NAN;
213 var[ix][iy][iz] = GSL_NAN;
214 min[ix][iy][iz] = GSL_NAN;
215 max[ix][iy][iz] = GSL_NAN;
221 printf(
"Write variance statistics: %s\n", argv[2]);
222 if (!(out = fopen(argv[2],
"w")))
223 ERRMSG(
"Cannot create file!");
228 "# $2 = altitude [km]\n"
229 "# $3 = longitude [deg]\n"
230 "# $4 = latitude [deg]\n"
231 "# $5 = number of profiles\n"
232 "# $6 = number of data points\n"
233 "# $7 = mean perturbation [K]\n"
234 "# $8 = minimum perturbation [K]\n"
235 "# $9 = maximum perturbation [K]\n"
236 "# $10 = variance [K^2]\n"
237 "# $11 = mean temperature [K]\n"
238 "# $12 = mean weighted temperature [K]\n"
239 "# $13 = mean tropopause height [km]\n");
242 for (iz = 0; iz < nz; iz++) {
243 for (iy = 0; iy < ny; iy++) {
244 if (iy == 0 || nx > 1)
246 for (ix = 0; ix < nx; ix++)
247 fprintf(out,
"%.2f %g %g %g %d %d %g %g %g %g %g %g %g\n",
248 mtime[ix][iy], gz[iz], glon[ix], glat[iy],
249 np[ix][iy], n[ix][iy][iz], mean[ix][iy][iz],
250 min[ix][iy][iz], max[ix][iy][iz], var[ix][iy][iz],
251 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[])