GPS Code Collection
Functions
response.c File Reference

Determine response to wave perturbations. More...

#include "libgps.h"

Go to the source code of this file.

Functions

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

Detailed Description

Determine response to wave perturbations.

Definition in file response.c.

Function Documentation

◆ main()

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

Definition at line 32 of file response.c.

34 {
35
36 gps_t *gps;
37
38 FILE *out;
39
40 double lz, ptmax[NZ], var[NZ], w, wmax, se[NZ], sz[NZ], t0 = 10.0,
41 grid_zmin, grid_zmax, ham_dz, ham_dz2;
42
43 int idx, iphi, iz, iz2, nphi = 360, sn = 0, grid_nz;
44
45 /* Allocate... */
46 ALLOC(gps, gps_t, 1);
47
48 /* Check arguments... */
49 if (argc < 4)
50 ERRMSG("Give parameters: <ctl> <sens.tab> <response.tab>");
51
52 /* Get control parameters... */
53 grid_zmin = scan_ctl(argc, argv, "GRID_ZMIN", -1, "0", NULL);
54 grid_zmax = scan_ctl(argc, argv, "GRID_ZMAX", -1, "60", NULL);
55 grid_nz = (int) scan_ctl(argc, argv, "GRID_NZ", -1, "601", NULL);
56 ham_dz = scan_ctl(argc, argv, "HAM_DZ", -1, "6.0", NULL);
57 ham_dz2 = scan_ctl(argc, argv, "HAM_DZ2", -1, "0.4", NULL);
58
59 /* Read vertical sensitivity function... */
60 if (argv[2][0] != '-') {
61 read_shape(argv[2], sz, se, &sn);
62 if (sn > NZ)
63 ERRMSG("Too many data points!");
64 }
65
66 /* Create output file... */
67 printf("Write response data: %s\n", argv[3]);
68 if (!(out = fopen(argv[3], "w")))
69 ERRMSG("Cannot create file!");
70
71 /* Write header... */
72 fprintf(out,
73 "# $1 = vertical wavelength [km]\n"
74 "# $2 = altitude [km]\n"
75 "# $3 = response (amplitude) [%%]\n"
76 "# $4 = response (variance) [%%]\n");
77
78 /* Create profile... */
79 gps->nds = 1;
80 gps->nz[0] = grid_nz;
81 for (iz = 0; iz < gps->nz[0]; iz++)
82 gps->z[0][iz] =
83 LIN(0.0, grid_zmin, grid_nz - 1.0, grid_zmax, (double) iz);
84
85 /* Loop over vertical wavelength... */
86 for (lz = 0.1; lz <= 20.0; lz += 0.1) {
87
88 /* Write info... */
89 printf("Calculate %g km...\n", lz);
90
91 /* Initialize... */
92 for (iz = 0; iz < gps->nz[0]; iz++)
93 ptmax[iz] = var[iz] = 0;
94
95 /* Loop over phase... */
96 for (iphi = 0; iphi < nphi; iphi++) {
97
98 /* Create profile... */
99 for (iz = 0; iz < gps->nz[0]; iz++)
100 gps->t[0][iz] = 250.0 + t0 * sin(2. * M_PI / lz * gps->z[0][iz]
101 +
102 2. * M_PI * (double) iphi /
103 (double) nphi);
104
105 /* Get perturbations from vertical Hamming filter... */
106 if (ham_dz > 0)
107 hamming_low_pass(gps, ham_dz);
108
109 /* Use vertical Hamming filter to reduce noise... */
110 if (ham_dz2 > 0)
111 hamming_high_pass(gps, ham_dz2);
112
113 /* Multiply with vertical sensitivity function... */
114 if (argv[2][0] != '-') {
115 wmax = 0;
116 for (iz2 = 0; iz2 < gps->nz[0]; iz2++) {
117 if (gps->z[0][iz2] < sz[0] || gps->z[0][iz2] > sz[sn - 1])
118 w = 0;
119 else {
120 idx = locate_irr(sz, sn, gps->z[0][iz2]);
121 w =
122 LIN(sz[idx], se[idx], sz[idx + 1], se[idx + 1], gps->z[0][iz2]);
123 }
124 gps->pt[0][iz2] *= w;
125 wmax = GSL_MAX(w, wmax);
126 }
127 if (wmax > 0)
128 for (iz2 = 0; iz2 < gps->nz[0]; iz2++)
129 gps->pt[0][iz2] /= wmax;
130 }
131
132 /* Get response... */
133 for (iz = 0; iz < gps->nz[0]; iz++) {
134 ptmax[iz] = GSL_MAX(ptmax[iz], gps->pt[0][iz]);
135 var[iz] += gsl_pow_2(gps->pt[0][iz]) / nphi;
136 }
137 }
138
139 /* Write output... */
140 fprintf(out, "\n");
141 for (iz = 0; iz < gps->nz[0]; iz++)
142 fprintf(out, "%g %g %g %g\n", lz, gps->z[0][iz], ptmax[iz] / t0,
143 2.0 * var[iz] / gsl_pow_2(t0));
144 }
145
146 /* Close file... */
147 fclose(out);
148
149 /* Free... */
150 free(gps);
151
152 return EXIT_SUCCESS;
153}
void hamming_low_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to extract perturbations.
Definition: libgps.c:325
void hamming_high_pass(gps_t *gps, double dz)
Apply vertical Hamming filter to reduce noise.
Definition: libgps.c:382
#define NZ
Maximum number of altitudes per GPS-RO profile.
Definition: libgps.h:103
GPS-RO profile data.
Definition: libgps.h:153
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
int nds
Number of profiles.
Definition: libgps.h:156
double z[NDS][NZ]
Altitude [km].
Definition: libgps.h:165
Here is the call graph for this function: