AIRS Code Collection
spec_ana.c
Go to the documentation of this file.
1/*
2 This file is part of the AIRS Code Collection.
3
4 the AIRS 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 AIRS 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 AIRS Code Collection. If not, see
16 <http://www.gnu.org/licenses/>.
17
18 Copyright (C) 2019-2025 Forschungszentrum Juelich GmbH
19*/
20
26#include "libairs.h"
27
28int main(
29 int argc,
30 char *argv[]) {
31
32 static wave_t *wave;
33 static pert_t *pert;
34
35 FILE *out;
36
37 char method[LEN], filename[LEN], pertname[LEN];
38
39 double Amax, phimax, lhmax, kxmax, kymax, alphamax, betamax, chisq;
40
41 /* Check arguments... */
42 if (argc < 4)
43 ERRMSG("Give parameters: <ctl> <pert.nc> <spec.tab>");
44
45 /* Get control parameters... */
46 scan_ctl(argc, argv, "PERTNAME", -1, "4mu", pertname);
47 const int track0 = (int) scan_ctl(argc, argv, "TRACK0", -1, "", NULL);
48 const int track1 = (int) scan_ctl(argc, argv, "TRACK1", -1, "", NULL);
49 const int xtrack0 = (int) scan_ctl(argc, argv, "XTRACK0", -1, "0", NULL);
50 const int xtrack1 = (int) scan_ctl(argc, argv, "XTRACK1", -1, "89", NULL);
51 const int strack = (int) scan_ctl(argc, argv, "STRACK", -1, "15", NULL);
52 const int sxtrack = (int) scan_ctl(argc, argv, "SXTRACK", -1, "15", NULL);
53 const int dtrack = (int) scan_ctl(argc, argv, "DTRACK", -1, "5", NULL);
54 const int dxtrack = (int) scan_ctl(argc, argv, "DXTRACK", -1, "5", NULL);
55 const int inter_x = (int) scan_ctl(argc, argv, "INTER_X", -1, "0", NULL);
56 const int bg_poly_x =
57 (int) scan_ctl(argc, argv, "BG_POLY_X", -1, "5", NULL);
58 const int bg_poly_y =
59 (int) scan_ctl(argc, argv, "BG_POLY_Y", -1, "0", NULL);
60 const int bg_smooth_x =
61 (int) scan_ctl(argc, argv, "BG_SMOOTH_X", -1, "0", NULL);
62 const int bg_smooth_y =
63 (int) scan_ctl(argc, argv, "BG_SMOOTH_Y", -1, "0", NULL);
64 const double var_dh = scan_ctl(argc, argv, "VAR_DH", -1, "100.0", NULL);
65 const double lxymax = scan_ctl(argc, argv, "LXYMAX", -1, "1000.0", NULL);
66 const double dlxy = scan_ctl(argc, argv, "DLXY", -1, "10.0", NULL);
67 scan_ctl(argc, argv, "METHOD", -1, "P", method);
68 const int output = (int) scan_ctl(argc, argv, "OUTPUT", -1, "1", NULL);
69
70 /* Allocate... */
71 ALLOC(pert, pert_t, 1);
72 ALLOC(wave, wave_t, 1);
73
74 /* Read perturbation data... */
75 read_pert(argv[2], pertname, pert);
76
77 /* Convert to wave analysis struct... */
78 pert2wave(pert, wave, 0, pert->ntrack - 1, 0, pert->nxtrack - 1);
79
80 /* Estimate background... */
81 background_poly(wave, bg_poly_x, bg_poly_y);
82 background_smooth(wave, bg_smooth_x, bg_smooth_y);
83
84 /* Compute variance... */
85 variance(wave, var_dh);
86
87 /* Copy data... */
88 for (int ix = 0; ix < wave->nx; ix++)
89 for (int iy = 0; iy < wave->ny; iy++) {
90 pert->pt[iy][ix] = wave->pt[ix][iy];
91 pert->var[iy][ix] = wave->var[ix][iy];
92 }
93
94 /* Interpolate to regular grid... */
95 intpol_x(wave, inter_x);
96
97 /* Create output file... */
98 printf("Write spectral data: %s\n", argv[3]);
99 if (!(out = fopen(argv[3], "w")))
100 ERRMSG("Cannot create file!");
101
102 /* Write header... */
103 fprintf(out,
104 "# $1 = time (seconds since 01-JAN-2000, 00:00 UTC)\n"
105 "# $2 = longitude [deg]\n"
106 "# $3 = latitude [deg]\n"
107 "# $4 = amplitude [K]\n"
108 "# $5 = phase [deg]\n"
109 "# $6 = horizontal wavelength [km]\n"
110 "# $7 = wavenumber x [1/km]\n"
111 "# $8 = wavenumber y [1/km]\n"
112 "# $9 = rotation angle alpha [deg]\n"
113 "# $10 = rotation angle beta [deg]\n");
114 fprintf(out,
115 "# $11 = chi^2 of fit [K^2]\n"
116 "# $12 = along-track index minimum\n"
117 "# $13 = along-track index maximum\n"
118 "# $14 = across-track index minimum\n"
119 "# $15 = across-track index maximum\n"
120 "# $16 = box size x\n" "# $17 = box size y\n\n");
121
122 /* Loop over blocks... */
123 for (int track = track0; track <= track1 - strack + 1; track += dtrack)
124 for (int xtrack = xtrack0; xtrack <= xtrack1 - sxtrack + 1;
125 xtrack += dxtrack) {
126
127 /* Write info... */
128 printf("Analyze track = %d and xtrack = %d ...\n", track, xtrack);
129
130 /* Convert to wave analysis struct... */
131 pert2wave(pert, wave, track, track + strack - 1,
132 xtrack, xtrack + sxtrack - 1);
133
134 /* Get wave characteristics... */
135 if (method[0] == 'p' || method[0] == 'P') {
136 sprintf(filename, "period_%d_%d.tab", track, xtrack);
137 period(wave, lxymax, dlxy, &Amax, &phimax, &lhmax, &kxmax, &kymax,
138 &alphamax, &betamax, output ? filename : NULL);
139 } else if (method[0] == 'f' || method[0] == 'F') {
140 sprintf(filename, "fft_%d_%d.tab", track, xtrack);
141 fft(wave, &Amax, &phimax, &lhmax, &kxmax, &kymax,
142 &alphamax, &betamax, output ? filename : NULL);
143 } else
144 ERRMSG("Unkown method!");
145
146 /* Evaluate fit... */
147 fit_wave(wave, Amax, phimax, kxmax, kymax, &chisq);
148
149 /* Save wave struct... */
150 if (output) {
151 sprintf(filename, "wave_%d_%d.tab", track, xtrack);
152 write_wave(filename, wave);
153 }
154
155 /* Write results... */
156 fprintf(out, "%.2f %g %g %g %g %g %g %g %g %g %g %d %d %d %d %d %d\n",
157 pert->time[track + strack / 2][xtrack + sxtrack / 2],
158 pert->lon[track + strack / 2][xtrack + sxtrack / 2],
159 pert->lat[track + strack / 2][xtrack + sxtrack / 2],
160 Amax, phimax, lhmax, kxmax, kymax, alphamax, betamax,
161 chisq, track, track + strack - 1,
162 xtrack, xtrack + sxtrack - 1, wave->nx, wave->ny);
163 }
164
165 /* Close file... */
166 fclose(out);
167
168 /* Free... */
169 free(pert);
170 free(wave);
171
172 return EXIT_SUCCESS;
173}
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 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 pert2wave(pert_t *pert, wave_t *wave, int track0, int track1, int xtrack0, int xtrack1)
Convert radiance perturbation data to wave analysis struct.
Definition: libairs.c:999
void read_pert(char *filename, char *pertname, pert_t *pert)
Read radiance perturbation data.
Definition: libairs.c:1137
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
AIRS Code Collection library declarations.
int main(int argc, char *argv[])
Definition: spec_ana.c:28
Perturbation data.
Definition: libairs.h:205
double var[PERT_NTRACK][PERT_NXTRACK]
Brightness temperature variance (4 or 15 micron) [K].
Definition: libairs.h:232
double pt[PERT_NTRACK][PERT_NXTRACK]
Brightness temperature perturbation (4 or 15 micron) [K].
Definition: libairs.h:229
double time[PERT_NTRACK][PERT_NXTRACK]
Time (seconds since 2000-01-01T00:00Z).
Definition: libairs.h:214
int ntrack
Number of along-track values.
Definition: libairs.h:208
int nxtrack
Number of across-track values.
Definition: libairs.h:211
double lon[PERT_NTRACK][PERT_NXTRACK]
Longitude [deg].
Definition: libairs.h:217
double lat[PERT_NTRACK][PERT_NXTRACK]
Latitude [deg].
Definition: libairs.h:220
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 var[WX][WY]
Variance [K].
Definition: libairs.h:323
double pt[WX][WY]
Perturbation [K].
Definition: libairs.h:320