AIRS Code Collection
noise_pert.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 static wave_t wave;
34
35 FILE *out;
36
37 char pertname[LEN];
38
39 double mu, nedt = -1e99;
40
41 /* Check arguments... */
42 if (argc < 4)
43 ERRMSG("Give parameters: <ctl> <pert.nc> <noise.tab>");
44
45 /* Read control parameters... */
46 scan_ctl(argc, argv, "PERTNAME", -1, "4mu", pertname);
47 int bsize = (int) scan_ctl(argc, argv, "BSIZE", -1, "-999", NULL);
48 const double maxvar = scan_ctl(argc, argv, "MAXVAR", -1, "-999", NULL);
49
50 /* Allocate... */
51 ALLOC(pert, pert_t, 1);
52
53 /* Read perturbation data... */
54 read_pert(argv[2], pertname, pert);
55
56 /* Set block size... */
57 if (bsize < 0)
58 bsize = pert->nxtrack;
59
60 /* Create file... */
61 printf("Write noise data: %s\n", argv[3]);
62 if (!(out = fopen(argv[3], "w")))
63 ERRMSG("Cannot create file!");
64
65 /* Write header... */
66 fprintf(out,
67 "# $1 = longitude [deg]\n"
68 "# $2 = latitude [deg]\n"
69 "# $3 = mean brightness temperature [K]\n"
70 "# $4 = noise estimate [K]\n\n");
71
72 /* Loop over granules... */
73 for (int itrack = 0; itrack < pert->ntrack; itrack += bsize) {
74
75 /* Convert retrieval data to wave struct... */
76 pert2wave(pert, &wave, itrack, itrack + bsize,
77 pert->nxtrack / 2 - bsize / 2, pert->nxtrack / 2 + bsize / 2);
78
79 /* Estimate noise... */
80 double nedt_old = nedt;
81 noise(&wave, &mu, &nedt);
82
83 /* Write output... */
84 if (maxvar <= 0
85 || fabs(200 * (nedt - nedt_old) / (nedt + nedt_old)) < maxvar)
86 fprintf(out, "%g %g %g %g\n", wave.lon[wave.nx / 2][wave.ny / 2],
87 wave.lat[wave.nx / 2][wave.ny / 2], mu, nedt);
88 }
89
90 /* Close file... */
91 fclose(out);
92
93 /* Free... */
94 free(pert);
95
96 return EXIT_SUCCESS;
97}
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 noise(wave_t *wave, double *mu, double *sig)
Estimate noise.
Definition: libairs.c:798
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
AIRS Code Collection library declarations.
int main(int argc, char *argv[])
Definition: noise_pert.c:28
Perturbation data.
Definition: libairs.h:205
int ntrack
Number of along-track values.
Definition: libairs.h:208
int nxtrack
Number of across-track values.
Definition: libairs.h:211
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 lon[WX][WY]
Longitude [deg].
Definition: libairs.h:302
double lat[WX][WY]
Latitude [deg].
Definition: libairs.h:305