AIRS Code Collection
Functions
spec_synth.c File Reference

Spectral analysis of synthetic data. More...

#include "libairs.h"

Go to the source code of this file.

Functions

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

Detailed Description

Spectral analysis of synthetic data.

Definition in file spec_synth.c.

Function Documentation

◆ main()

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

Definition at line 28 of file spec_synth.c.

30 {
31
32 static wave_t *wave;
33
34 FILE *out;
35
36 char method[LEN], filename[LEN];
37
38 double Amax, phimax, lhmax, kxmax, kymax, alphamax, betamax, chisq;
39
40 /* Check arguments... */
41 if (argc < 3)
42 ERRMSG("Give parameters: <ctl> <spec.tab>");
43
44 /* Get control parameters... */
45 const int nx = (int) scan_ctl(argc, argv, "NX", -1, "256", NULL);
46 const int ny = (int) scan_ctl(argc, argv, "NY", -1, "256", NULL);
47 const double sx = scan_ctl(argc, argv, "SX", -1, "1000.0", NULL);
48 const double sy = scan_ctl(argc, argv, "SY", -1, "1000.0", NULL);
49 const double amp = scan_ctl(argc, argv, "AMP", -1, "1.0", NULL);
50 const double phi = scan_ctl(argc, argv, "PHI", -1, "0.0", NULL);
51 const double lx0 = scan_ctl(argc, argv, "LX0", -1, "100.0", NULL);
52 const double lx1 = scan_ctl(argc, argv, "LX1", -1, "100.0", NULL);
53 const double dlx = scan_ctl(argc, argv, "DLX", -1, "10.0", NULL);
54 const double ly0 = scan_ctl(argc, argv, "LY0", -1, "200.0", NULL);
55 const double ly1 = scan_ctl(argc, argv, "LY1", -1, "200.0", NULL);
56 const double dly = scan_ctl(argc, argv, "DLY", -1, "10.0", NULL);
57 const double fwhm = scan_ctl(argc, argv, "FWHM", -1, "0.0", NULL);
58 const int inter_x = (int) scan_ctl(argc, argv, "INTER_X", -1, "0", NULL);
59 const int bg_poly_x =
60 (int) scan_ctl(argc, argv, "BG_POLY_X", -1, "5", NULL);
61 const int bg_poly_y =
62 (int) scan_ctl(argc, argv, "BG_POLY_Y", -1, "0", NULL);
63 const int bg_smooth_x =
64 (int) scan_ctl(argc, argv, "BG_SMOOTH_X", -1, "0", NULL);
65 const int bg_smooth_y =
66 (int) scan_ctl(argc, argv, "BG_SMOOTH_Y", -1, "0", NULL);
67 const double var_dh = scan_ctl(argc, argv, "VAR_DH", -1, "100.0", NULL);
68 const double lxymax = scan_ctl(argc, argv, "LXYMAX", -1, "1000.0", NULL);
69 const double dlxy = scan_ctl(argc, argv, "DLXY", -1, "10.0", NULL);
70 scan_ctl(argc, argv, "METHOD", -1, "P", method);
71 const int output = (int) scan_ctl(argc, argv, "OUTPUT", -1, "1", NULL);
72
73 /* Allocate... */
74 ALLOC(wave, wave_t, 1);
75
76 /* Create output file... */
77 printf("Write spectral data: %s\n", argv[2]);
78 if (!(out = fopen(argv[2], "w")))
79 ERRMSG("Cannot create file!");
80
81 /* Write header... */
82 fprintf(out,
83 "# $1 = real amplitude [K]\n"
84 "# $2 = real phase [deg]\n"
85 "# $3 = real horizontal wavelength [km]\n"
86 "# $4 = real wavelength x [km]\n"
87 "# $5 = real wavelength y [km]\n"
88 "# $6 = real rotation angle alpha [deg]\n");
89 fprintf(out,
90 "# $7 = amplitude [K]\n"
91 "# $8 = phase [deg]\n"
92 "# $9 = horizontal wavelength [km]\n"
93 "# $10 = wavelength x [km]\n"
94 "# $11 = wavelength y [km]\n"
95 "# $12 = rotation angle alpha [deg]\n"
96 "# $13 = rotation angle beta [deg]\n"
97 "# $14 = chi^2 of fit [K^2]\n"
98 "# $15 = box size x\n" "# $16 = box size y\n");
99
100 /* Set grid... */
101 wave->nx = nx;
102 wave->ny = ny;
103 for (int ix = 0; ix < wave->nx; ix++)
104 for (int iy = 0; iy < wave->ny; iy++) {
105 wave->x[ix] = sx / (nx - 1.) * ix - sx / 2.;
106 wave->y[iy] = sy / (ny - 1.) * iy - sy / 2.;
107 }
108
109 /* Loop over wavelengths... */
110 for (double lx = lx0; lx <= lx1; lx += dlx) {
111
112 /* Write output... */
113 fprintf(out, "\n");
114
115 /* Loop over wavelengths... */
116 for (double ly = ly0; ly <= ly1; ly += dly) {
117
118 /* Write info... */
119 printf("Analyze lx = %g km and ly = %g km...\n", lx, ly);
120
121 /* Get horizontal wavelength... */
122 double lh =
123 2 * M_PI / sqrt(gsl_pow_2(2 * M_PI / lx) + gsl_pow_2(2 * M_PI / ly));
124
125 /* Get propagation direction in xy-plane... */
126 double alpha = 90. - 180. / M_PI * atan2(2 * M_PI / lx, 2 * M_PI / ly);
127
128 /* Create wave field... */
129 create_wave(wave, amp, lx, ly, phi, fwhm);
130
131 /* Estimate background... */
132 background_poly(wave, bg_poly_x, bg_poly_y);
133 background_smooth(wave, bg_smooth_x, bg_smooth_y);
134
135 /* Compute variance... */
136 variance(wave, var_dh);
137
138 /* Interpolate to regular grid... */
139 intpol_x(wave, inter_x);
140
141 /* Get wave characteristics... */
142 if (method[0] == 'p' || method[0] == 'P') {
143 sprintf(filename, "period_%g_%g.tab", lx, ly);
144 period(wave, lxymax, dlxy, &Amax, &phimax, &lhmax, &kxmax, &kymax,
145 &alphamax, &betamax, output ? filename : NULL);
146 } else if (method[0] == 'f' || method[0] == 'F') {
147 sprintf(filename, "fft_%g_%g.tab", lx, ly);
148 fft(wave, &Amax, &phimax, &lhmax, &kxmax, &kymax,
149 &alphamax, &betamax, output ? filename : NULL);
150 } else
151 ERRMSG("Unkown method!");
152
153 /* Evaluate fit... */
154 fit_wave(wave, Amax, phimax, kxmax, kymax, &chisq);
155
156 /* Save wave struct... */
157 sprintf(filename, "wave_%g_%g.tab", lx, ly);
158 if (output)
159 write_wave(filename, wave);
160
161 /* Write results... */
162 fprintf(out, "%g %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d\n",
163 amp, phi, lh, lx, ly, alpha, Amax, phimax, lhmax,
164 2 * M_PI / kxmax, 2 * M_PI / kymax, alphamax, betamax,
165 chisq, wave->nx, wave->ny);
166 }
167 }
168
169 /* Close file... */
170 fclose(out);
171
172 /* Free... */
173 free(wave);
174
175 return EXIT_SUCCESS;
176}
double scan_ctl(int argc, char *argv[], const char *varname, int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
Definition: jurassic.c:5114
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:383
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:237
#define ALLOC(ptr, type, n)
Allocate memory.
Definition: jurassic.h:121
void fit_wave(wave_t *wave, double amp, double phi, double kx, double ky, double *chisq)
Evaluate wave fit...
Definition: libairs.c:354
void create_wave(wave_t *wave, double amp, double lx, double ly, double phi, double fwhm)
Add linear wave pattern...
Definition: libairs.c:275
void background_smooth(wave_t *wave, int npts_x, int npts_y)
Smooth background.
Definition: libairs.c:176
void intpol_x(wave_t *wave, int n)
Interpolate to regular grid in x-direction.
Definition: libairs.c:648
void fft(wave_t *wave, double *Amax, double *phimax, double *lhmax, double *kxmax, double *kymax, double *alphamax, double *betamax, char *filename)
Calculate 2-D FFT...
Definition: libairs.c:419
void background_poly(wave_t *wave, int dim_x, int dim_y)
Get background based on polynomial fits.
Definition: libairs.c:126
void variance(wave_t *wave, double dh)
Compute local variance.
Definition: libairs.c:1584
void write_wave(char *filename, wave_t *wave)
Write wave analysis data.
Definition: libairs.c:1741
void period(wave_t *wave, double lxymax, double dlxy, double *Amax, double *phimax, double *lhmax, double *kxmax, double *kymax, double *alphamax, double *betamax, char *filename)
Compute periodogram.
Definition: libairs.c:842
Wave analysis data.
Definition: libairs.h:287
int nx
Number of across-track values.
Definition: libairs.h:290
int ny
Number of along-track values.
Definition: libairs.h:293
double x[WX]
Across-track distance [km].
Definition: libairs.h:308
double y[WY]
Along-track distance [km].
Definition: libairs.h:311
Here is the call graph for this function: