AIRS Code Collection
events.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 pert_t *pert;
33
34 static wave_t *wave;
35
36 static FILE *out;
37
38 static char pertname[LEN];
39
40 const int dtrack = 15, dxtrack = 15;
41
42 /* Check arguments... */
43 if (argc < 4)
44 ERRMSG("Give parameters: <ctl> <events.tab> <pert1.nc> [<pert2.nc> ...]");
45
46 /* Get control parameters... */
47 scan_ctl(argc, argv, "PERTNAME", -1, "4mu", pertname);
48 const int bg_poly_x =
49 (int) scan_ctl(argc, argv, "BG_POLY_X", -1, "0", NULL);
50 const int bg_poly_y =
51 (int) scan_ctl(argc, argv, "BG_POLY_Y", -1, "0", NULL);
52 const int bg_smooth_x =
53 (int) scan_ctl(argc, argv, "BG_SMOOTH_X", -1, "0", NULL);
54 const int bg_smooth_y =
55 (int) scan_ctl(argc, argv, "BG_SMOOTH_Y", -1, "0", NULL);
56 const double gauss_fwhm = scan_ctl(argc, argv, "GAUSS_FWHM", -1, "0", NULL);
57 const double var_dh = scan_ctl(argc, argv, "VAR_DH", -1, "0", NULL);
58 const double varmin = scan_ctl(argc, argv, "VARMIN", -1, "", NULL);
59 const double dt230 = scan_ctl(argc, argv, "DT230", -1, "0.16", NULL);
60 const double nu = scan_ctl(argc, argv, "NU", -1, "2345.0", NULL);
61
62 /* Alloc... */
63 ALLOC(pert, pert_t, 1);
64
65 /* Create file... */
66 printf("Write event data: %s\n", argv[2]);
67 if (!(out = fopen(argv[2], "w")))
68 ERRMSG("Cannot create file!");
69
70 /* Write header... */
71 fprintf(out,
72 "# $1 = time [s]\n"
73 "# $2 = longitude [deg]\n"
74 "# $3 = latitude [deg]\n" "# $4 = maximum variance [K^2]\n\n");
75
76 /* Loop over perturbation files... */
77 for (int iarg = 3; iarg < argc; iarg++) {
78
79 /* Read perturbation data... */
80 FILE *in;
81 if (!(in = fopen(argv[iarg], "r")))
82 continue;
83 else {
84 fclose(in);
85 read_pert(argv[iarg], pertname, pert);
86 }
87
88 /* Recalculate background and perturbations... */
89 if (bg_poly_x > 0 || bg_poly_y > 0 ||
90 bg_smooth_x > 0 || bg_smooth_y > 0 || gauss_fwhm > 0 || var_dh > 0) {
91
92 /* Allocate... */
93 ALLOC(wave, wave_t, 1);
94
95 /* Convert to wave analysis struct... */
96 pert2wave(pert, wave, 0, pert->ntrack - 1, 0, pert->nxtrack - 1);
97
98 /* Estimate background... */
99 background_poly(wave, bg_poly_x, bg_poly_y);
100 background_smooth(wave, bg_smooth_x, bg_smooth_y);
101
102 /* Gaussian filter... */
103 gauss(wave, gauss_fwhm);
104
105 /* Compute variance... */
106 variance(wave, var_dh);
107
108 /* Copy data... */
109 for (int ix = 0; ix < wave->nx; ix++)
110 for (int iy = 0; iy < wave->ny; iy++) {
111 pert->pt[iy][ix] = wave->pt[ix][iy];
112 pert->var[iy][ix] = wave->var[ix][iy];
113 }
114
115 /* Free... */
116 free(wave);
117 }
118
119 /* Apply noise correction... */
120 if (dt230 > 0)
121 for (int itrack = 0; itrack < pert->ntrack; itrack++)
122 for (int ixtrack = 0; ixtrack < pert->nxtrack; ixtrack++) {
123 const double nesr = PLANCK(230.0 + dt230, nu) - PLANCK(230.0, nu);
124 const double tbg =
125 pert->bt[itrack][ixtrack] - pert->pt[itrack][ixtrack];
126 const double nedt = BRIGHT(PLANCK(tbg, nu) + nesr, nu) - tbg;
127 pert->var[itrack][ixtrack] -= gsl_pow_2(nedt);
128 }
129
130 /* Find local maxima... */
131 for (int itrack = 0; itrack < pert->ntrack; itrack += 2 * dtrack)
132 for (int ixtrack = dxtrack / 2; ixtrack < pert->nxtrack;
133 ixtrack += 2 * dxtrack) {
134
135 /* Init... */
136 double varmax = 0;
137 int itrackmax = -999;
138 int ixtrackmax = -999;
139
140 /* Loop over box... */
141 for (int itrack2 = itrack;
142 itrack2 < GSL_MIN(itrack + dtrack, pert->ntrack); itrack2++)
143 for (int ixtrack2 = ixtrack;
144 ixtrack2 < GSL_MIN(ixtrack + dxtrack, pert->nxtrack);
145 ixtrack2++)
146 if (pert->var[itrack2][ixtrack2] >= varmax) {
147 varmax = pert->var[itrack2][ixtrack2];
148 itrackmax = itrack2;
149 ixtrackmax = ixtrack2;
150 }
151
152 /* Report event... */
153 if (itrackmax >= 0 && ixtrackmax >= 0 && varmax >= varmin)
154 fprintf(out, "%.2f %g %g %g\n",
155 pert->time[itrackmax][ixtrackmax],
156 pert->lon[itrackmax][ixtrackmax],
157 pert->lat[itrackmax][ixtrackmax],
158 pert->var[itrackmax][ixtrackmax]);
159 }
160 }
161
162 /* Close file... */
163 fclose(out);
164
165 /* Free... */
166 free(pert);
167
168 return EXIT_SUCCESS;
169}
int main(int argc, char *argv[])
Definition: events.c:28
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 BRIGHT(rad, nu)
Compute brightness temperature.
Definition: jurassic.h:126
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:237
#define ALLOC(ptr, type, n)
Allocate memory.
Definition: jurassic.h:121
#define PLANCK(T, nu)
Compute Planck function.
Definition: jurassic.h:183
void background_smooth(wave_t *wave, int npts_x, int npts_y)
Smooth background.
Definition: libairs.c:176
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 gauss(wave_t *wave, double fwhm)
Apply Gaussian filter to perturbations...
Definition: libairs.c:579
AIRS Code Collection library declarations.
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 bt[PERT_NTRACK][PERT_NXTRACK]
Brightness temperature (4 or 15 micron) [K].
Definition: libairs.h:226
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