GPS Code Collection
Functions
events.c File Reference

Analyze events in GPS data. More...

#include "libgps.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Analyze events in GPS data.

Definition in file events.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 28 of file events.c.

30 {
31
32 gps_t *gps;
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 /* 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 if (!(in = fopen(argv[iarg], "r")))
74 continue;
75 else {
76 fclose(in);
77 read_gps(argv[iarg], gps);
78 }
79
80 /* Loop over profiles... */
81 for (ids = 0; ids < gps->nds; ids++) {
82
83 /* Check tropopause height... */
84 if (!gsl_finite(gps->th[ids]))
85 continue;
86
87 /* Multiply with vertical sensitivity function... */
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],
97 gps->z[ids][iz]);
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 /* Get minimum and maximum perturbation... */
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 /* Write output... */
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 /* Close file... */
127 fclose(out);
128
129 /* Free... */
130 free(gps);
131
132 return EXIT_SUCCESS;
133}
void read_gps(char *filename, gps_t *gps)
Read GPS-RO data file.
Definition: libgps.c:611
#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
Here is the call graph for this function: