30 {
31
33
34 FILE *in, *out;
35
36 static double ptmin, ptmax, se[
NZ], sz[
NZ], w, wmax, wsum2 = 1.0, var;
37
38 static int iarg, ids, idx, iz, sn;
39
40
42
43
44 if (argc < 5)
45 ERRMSG("Give parameters: <ctl> <events.tab> <sens.tab> "
46 "<gps1.nc> [<gps2.nc> ...]");
47
48
49 printf("Write event data: %s\n", argv[2]);
50 if (!(out = fopen(argv[2], "w")))
51 ERRMSG("Cannot create file!");
52
53
54 fprintf(out,
55 "# $1 = time [s]\n"
56 "# $2 = longitude [deg]\n"
57 "# $3 = latitude [deg]\n"
58 "# $4 = minimum perturbation [K]\n"
59 "# $5 = maximum perturbation [K]\n"
60 "# $6 = temperature variance [K^2]\n\n");
61
62
63 if (argv[3][0] != '-') {
64 read_shape(argv[3], sz, se, &sn);
66 ERRMSG("Too many data points!");
67 }
68
69
70 for (iarg = 4; iarg < argc; iarg++) {
71
72
73 if (!(in = fopen(argv[iarg], "r")))
74 continue;
75 else {
76 fclose(in);
78 }
79
80
81 for (ids = 0; ids < gps->
nds; ids++) {
82
83
84 if (!gsl_finite(gps->
th[ids]))
85 continue;
86
87
88 if (argv[3][0] != '-') {
89 wmax = wsum2 = 0;
90 for (iz = 0; iz < gps->
nz[ids]; iz++) {
91 if (gps->
z[ids][iz] < sz[0] || gps->
z[ids][iz] > sz[sn - 1])
92 w = 0;
93 else {
94 idx = locate_irr(sz, sn, gps->
z[ids][iz]);
95 w =
96 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1],
98 }
99 if (gsl_finite(gps->
t[ids][iz]) && gps->
pt[ids][iz]) {
100 gps->
pt[ids][iz] *= w;
101 wmax = GSL_MAX(w, wmax);
102 wsum2 += gsl_pow_2(w);
103 }
104 }
105 for (iz = 0; iz < gps->
nz[ids]; iz++)
106 gps->
pt[ids][iz] /= wmax;
107 wsum2 /= gsl_pow_2(wmax);
108 }
109
110
111 ptmin = ptmax = var = 0;
112 for (iz = 0; iz < gps->
nz[ids]; iz++)
113 if (gsl_finite(gps->
pt[ids][iz])) {
114 ptmin = GSL_MIN(ptmin, gps->
pt[ids][iz]);
115 ptmax = GSL_MAX(ptmax, gps->
pt[ids][iz]);
116 var += gsl_pow_2(gps->
pt[ids][iz]) / wsum2;
117 }
118
119
120 fprintf(out,
"%.2f %g %g %g %g %g\n", gps->
time[ids],
121 gps->
lon[ids][gps->
nz[ids] / 2],
122 gps->
lat[ids][gps->
nz[ids] / 2], ptmin, ptmax, var);
123 }
124 }
125
126
127 fclose(out);
128
129
130 free(gps);
131
132 return EXIT_SUCCESS;
133}
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].