GPS Code Collection
events.c
Go to the documentation of this file.
1/*
2 This file is part of the GPS Code Collection.
3
4 the GPS Code Collections is free software: you can redistribute it
5 and/or modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation, either version 3 of
7 the License, or (at your option) any later version.
8
9 The GPS Code Collection is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with the GPS Code Collection. If not, see
16 <http://www.gnu.org/licenses/>.
17
18 Copyright (C) 2019-2025 Forschungszentrum Juelich GmbH
19*/
20
26#include "libgps.h"
27
28int main(
29 int argc,
30 char *argv[]) {
31
32 gps_t *gps;
33
34 FILE *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 /* Allocate... */
41 ALLOC(gps, gps_t, 1);
42
43 /* Check arguments... */
44 if (argc < 5)
45 ERRMSG("Give parameters: <ctl> <events.tab> <sens.tab> "
46 "<gps1.nc> [<gps2.nc> ...]");
47
48 /* Create file... */
49 printf("Write event data: %s\n", argv[2]);
50 if (!(out = fopen(argv[2], "w")))
51 ERRMSG("Cannot create file!");
52
53 /* Write header... */
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 /* Read vertical sensitivity function... */
63 if (argv[3][0] != '-') {
64 read_shape(argv[3], sz, se, &sn);
65 if (sn > NZ)
66 ERRMSG("Too many data points!");
67 }
68
69 /* Loop over data files... */
70 for (iarg = 4; iarg < argc; iarg++) {
71
72 /* Read gps data... */
73 FILE *in;
74 if (!(in = fopen(argv[iarg], "r")))
75 continue;
76 else {
77 fclose(in);
78 read_gps(argv[iarg], gps);
79 }
80
81 /* Loop over profiles... */
82 for (ids = 0; ids < gps->nds; ids++) {
83
84 /* Check tropopause height... */
85 if (!gsl_finite(gps->th[ids]))
86 continue;
87
88 /* Multiply with vertical sensitivity function... */
89 if (argv[3][0] != '-') {
90 wmax = wsum2 = 0;
91 for (iz = 0; iz < gps->nz[ids]; iz++) {
92 if (gps->z[ids][iz] < sz[0] || gps->z[ids][iz] > sz[sn - 1])
93 w = 0;
94 else {
95 idx = locate_irr(sz, sn, gps->z[ids][iz]);
96 w =
97 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1],
98 gps->z[ids][iz]);
99 }
100 if (gsl_finite(gps->t[ids][iz]) && gps->pt[ids][iz]) {
101 gps->pt[ids][iz] *= w;
102 wmax = GSL_MAX(w, wmax);
103 wsum2 += gsl_pow_2(w);
104 }
105 }
106 for (iz = 0; iz < gps->nz[ids]; iz++)
107 gps->pt[ids][iz] /= wmax;
108 wsum2 /= gsl_pow_2(wmax);
109 }
110
111 /* Get minimum and maximum perturbation... */
112 ptmin = ptmax = var = 0;
113 for (iz = 0; iz < gps->nz[ids]; iz++)
114 if (gsl_finite(gps->pt[ids][iz])) {
115 ptmin = GSL_MIN(ptmin, gps->pt[ids][iz]);
116 ptmax = GSL_MAX(ptmax, gps->pt[ids][iz]);
117 var += gsl_pow_2(gps->pt[ids][iz]) / wsum2;
118 }
119
120 /* Write output... */
121 fprintf(out, "%.2f %g %g %g %g %g\n", gps->time[ids],
122 gps->lon[ids][gps->nz[ids] / 2],
123 gps->lat[ids][gps->nz[ids] / 2], ptmin, ptmax, var);
124 }
125 }
126
127 /* Close file... */
128 fclose(out);
129
130 /* Free... */
131 free(gps);
132
133 return EXIT_SUCCESS;
134}
int main(int argc, char *argv[])
Definition: events.c:28
void read_gps(char *filename, gps_t *gps)
Read GPS-RO data file.
Definition: libgps.c:632
GPS Code Collection library declarations.
#define NZ
Maximum number of altitudes per GPS-RO profile.
Definition: libgps.h:103
GPS-RO profile data.
Definition: libgps.h:153
double time[NDS]
Time (seconds since 2000-01-01T00:00Z).
Definition: libgps.h:162
double pt[NDS][NZ]
Temperature perturbation [K].
Definition: libgps.h:183
double t[NDS][NZ]
Temperature [K].
Definition: libgps.h:177
int nz[NDS]
Number of altitudes per profile.
Definition: libgps.h:159
double lon[NDS][NZ]
Longitude [deg].
Definition: libgps.h:168
int nds
Number of profiles.
Definition: libgps.h:156
double th[NDS]
Tropopause height [km].
Definition: libgps.h:186
double z[NDS][NZ]
Altitude [km].
Definition: libgps.h:165
double lat[NDS][NZ]
Latitude [deg].
Definition: libgps.h:171