47 {
48
50
51 FILE *out;
52
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;
57
58 static int iarg, ids, idx, ix, iy, iz, iz2,
60
61
63
64
65 if (argc < 5)
66 ERRMSG("Give parameters: <ctl> <var.tab> <sens.tab> "
67 "<gps1.nc> [<gps2.nx> ...]");
68
69
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);
79
80
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!");
87
88
89 if (argv[3][0] != '-') {
90 read_shape(argv[3], sz, se, &sn);
92 ERRMSG("Too many data points!");
93 }
94
95
96 for (iarg = 4; iarg < argc; iarg++) {
97
98
99 FILE *in;
100 if (!(in = fopen(argv[iarg], "r")))
101 continue;
102 else {
103 fclose(in);
105 }
106
107
108 for (ids = 0; ids < gps->
nds; ids++) {
109
110
111 if (!gsl_finite(gps->
th[ids]))
112 continue;
113
114
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])
119 w = 0;
120 else {
121 idx = locate_irr(sz, sn, gps->
z[ids][iz2]);
122 w =
123 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1],
125 }
126 if (gsl_finite(gps->
t[ids][iz2]) && gps->
pt[ids][iz2]) {
127 tw += w * gps->
t[ids][iz2];
128 wsum += w;
129 gps->
pt[ids][iz2] *= w;
130 wmax = GSL_MAX(w, wmax);
131 }
132 }
133 tw /= wsum;
134 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++)
135 gps->
pt[ids][iz2] /= wmax;
136 }
137
138
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)
144 continue;
145
146
147 mtime[ix][iy] += gps->
time[ids];
148 thmean[ix][iy] += gps->
th[ids];
149 twmean[ix][iy] += tw;
150 np[ix][iy]++;
151
152
153 for (iz2 = 0; iz2 < gps->
nz[ids]; iz2++) {
154
155
156 iz = (int) ((gps->
z[ids][iz2] - z0)
157 / (z1 - z0) * (double) nz);
158 if (iz < 0 || iz >= nz)
159 continue;
160
161
162 if (!gsl_finite(gps->
t[ids][iz2]) || !gsl_finite(gps->
pt[ids][iz2]))
163 continue;
164
165
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]);
171 n[ix][iy][iz]++;
172 }
173 }
174 }
175
176
177 for (ix = 0; ix < nx; ix++)
178 for (iy = 0; iy < ny; iy++) {
179
180
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];
185 } else {
186 mtime[ix][iy] = GSL_NAN;
187 thmean[ix][iy] = GSL_NAN;
188 twmean[ix][iy] = GSL_NAN;
189 }
190
191
192 for (iz = 0; iz < nz; iz++) {
193
194
195 gz[iz] = z0 + (iz + 0.5) / (double) nz *(
196 z1 - z0);
197 glon[ix] = lon0 + (ix + 0.5) / (double) nx *(
198 lon1 - lon0);
199 glat[iy] = lat0 + (iy + 0.5) / (double) ny *(
200 lat1 - lat0);
201
202
203 if (n[ix][iy][iz] > 0) {
204 tmean[ix][iy][iz]
205 /= (double) n[ix][iy][iz];
206 mean[ix][iy][iz]
207 /= (double) n[ix][iy][iz];
208 var[ix][iy][iz]
209 = var[ix][iy][iz] / (double) n[ix][iy][iz]
210 - gsl_pow_2(mean[ix][iy][iz]);
211 } else {
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;
217 }
218 }
219 }
220
221
222 printf("Write variance statistics: %s\n", argv[2]);
223 if (!(out = fopen(argv[2], "w")))
224 ERRMSG("Cannot create file!");
225
226
227 fprintf(out,
228 "# $1 = time [s]\n"
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");
241
242
243 for (iz = 0; iz < nz; iz++) {
244 for (iy = 0; iy < ny; iy++) {
245 if (iy == 0 || nx > 1)
246 fprintf(out, "\n");
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]);
253 }
254 }
255
256
257 fclose(out);
258
259
260 free(gps);
261
262 return EXIT_SUCCESS;
263}
void read_gps(char *filename, gps_t *gps)
Read GPS-RO data file.
#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].