AIRS Code Collection
map_ret.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
25#include "libairs.h"
26
27int main(
28 int argc,
29 char *argv[]) {
30
31 static ret_t ret;
32 static wave_t wave;
33
34 static double tbg[NDS], tabg[NDS];
35
36 FILE *out;
37
38 char set[LEN];
39
40 int ip;
41
42 /* Check arguments... */
43 if (argc < 4)
44 ERRMSG("Give parameters: <ctl> <airs.nc> <map.tab>");
45
46 /* Get control parameters... */
47 scan_ctl(argc, argv, "SET", -1, "full", set);
48 const double z0 = scan_ctl(argc, argv, "Z0", -1, "", NULL);
49 const int bg_poly_x =
50 (int) scan_ctl(argc, argv, "BG_POLY_X", -1, "5", NULL);
51 const int bg_poly_y =
52 (int) scan_ctl(argc, argv, "BG_POLY_Y", -1, "0", NULL);
53 const int bg_smooth_x =
54 (int) scan_ctl(argc, argv, "BG_SMOOTH_X", -1, "0", NULL);
55 const int bg_smooth_y =
56 (int) scan_ctl(argc, argv, "BG_SMOOTH_Y", -1, "0", NULL);
57 const int npscan = (int) scan_ctl(argc, argv, "NPSCAN", -1, "90", NULL);
58
59 /* Read AIRS data... */
60 read_retr(argv[2], &ret);
61
62 /* Get altitude index... */
63 for (ip = 0; ip <= ret.np; ip++) {
64 if (ip == ret.np)
65 ERRMSG("Altitude level not found!");
66 if (fabs(ret.z[0][ip] - z0) < 0.1)
67 break;
68 }
69
70 /* Compute background... */
71 ret2wave(&ret, &wave, 1, ip);
72 background_poly(&wave, bg_poly_x, bg_poly_y);
73 background_smooth(&wave, bg_smooth_x, bg_smooth_y);
74 for (int ix = 0; ix < wave.nx; ix++)
75 for (int iy = 0; iy < wave.ny; iy++)
76 tbg[iy * npscan + ix] = wave.bg[ix][iy];
77 ret2wave(&ret, &wave, 2, ip);
78 background_poly(&wave, bg_poly_x, bg_poly_y);
79 background_smooth(&wave, bg_smooth_x, bg_smooth_y);
80 for (int ix = 0; ix < wave.nx; ix++)
81 for (int iy = 0; iy < wave.ny; iy++)
82 tabg[iy * npscan + ix] = wave.bg[ix][iy];
83
84 /* Create output file... */
85 printf("Write AIRS map data: %s\n", argv[3]);
86 if (!(out = fopen(argv[3], "w")))
87 ERRMSG("Cannot create file!");
88
89 /* Write header... */
90 fprintf(out,
91 "# $1 = time (seconds since 01-JAN-2000, 00:00 UTC)\n"
92 "# $2 = altitude [km]\n"
93 "# $3 = longitude [deg]\n"
94 "# $4 = latitude [deg]\n"
95 "# $5 = pressure [hPa]\n"
96 "# $6 = temperature (retrieved) [K]\n"
97 "# $7 = temperature (retrieved) perturbation [K]\n"
98 "# $8 = temperature (a priori) [K]\n"
99 "# $9 = temperature (a priori) perturbation [K]\n");
100 fprintf(out,
101 "# $10 = temperature (total error) [K]\n"
102 "# $11 = temperature (noise error) [K]\n"
103 "# $12 = temperature (forward model error) [K]\n"
104 "# $13 = temperature (measurement content)\n"
105 "# $14 = temperature (resolution)\n" "# $15 = normalized chi^2\n");
106
107 /* Write data... */
108 for (int ids = 0; ids < ret.nds; ids++) {
109
110 /* Write new line... */
111 if (ids % npscan == 0)
112 fprintf(out, "\n");
113
114 /* Check data... */
115 if (ret.lon[ids][ip] < -180 || ret.lon[ids][ip] > 180
116 || ret.lat[ids][ip] < -90 || ret.lat[ids][ip] > 90
117 || ret.t[ids][ip] < 100 || ret.t[ids][ip] > 400)
118 continue;
119
120 /* Get ascending/descending flag... */
121 int asc = (ret.lat[ids > npscan ? ids : ids + npscan][0]
122 > ret.lat[ids > npscan ? ids - npscan : ids][0]);
123
124 /* Write data... */
125 if (set[0] == 'f' || (set[0] == 'a' && asc) || (set[0] == 'd' && !asc))
126 fprintf(out, "%.2f %g %g %g %g %g %g %g %g %g %g %g %g %g %g\n",
127 ret.time[ids][ip], ret.z[ids][ip],
128 ret.lon[ids][ip], ret.lat[ids][ip],
129 ret.p[ids][ip], ret.t[ids][ip], ret.t[ids][ip] - tbg[ids],
130 ret.t_apr[ids][ip], ret.t_apr[ids][ip] - tabg[ids],
131 ret.t_tot[ids][ip], ret.t_noise[ids][ip], ret.t_fm[ids][ip],
132 ret.t_cont[ids][ip], ret.t_res[ids][ip], ret.chisq[ids]);
133 }
134
135 /* Close file... */
136 fclose(out);
137
138 return EXIT_SUCCESS;
139}
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
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 ret2wave(ret_t *ret, wave_t *wave, int dataset, int ip)
Convert AIRS retrieval results to wave analysis struct.
Definition: libairs.c:1531
void read_retr(char *filename, ret_t *ret)
Read AIRS retrieval data.
Definition: libairs.c:1219
AIRS Code Collection library declarations.
#define NDS
Maximum number of data sets per granule.
Definition: libairs.h:99
int main(int argc, char *argv[])
Definition: map_ret.c:27
Retrieval results.
Definition: libairs.h:237
double t_apr[NDS][NPG]
Temperature (a priori data) [K].
Definition: libairs.h:264
double chisq[NDS]
Chi^2.
Definition: libairs.h:282
double t_noise[NDS][NPG]
Temperature (noise error) [K].
Definition: libairs.h:270
double lat[NDS][NPG]
Latitude [deg].
Definition: libairs.h:255
double t_cont[NDS][NPG]
Temperature (measurement content).
Definition: libairs.h:276
double t[NDS][NPG]
Temperature [K].
Definition: libairs.h:261
double t_fm[NDS][NPG]
Temperature (forward model error) [K].
Definition: libairs.h:273
double p[NDS][NPG]
Pressure [hPa].
Definition: libairs.h:258
double z[NDS][NPG]
Altitude [km].
Definition: libairs.h:249
double t_res[NDS][NPG]
Temperature (resolution).
Definition: libairs.h:279
int nds
Number of data sets.
Definition: libairs.h:240
double t_tot[NDS][NPG]
Temperature (total error) [K].
Definition: libairs.h:267
int np
Number of data points.
Definition: libairs.h:243
double time[NDS][NPG]
Time (seconds since 2000-01-01T00:00Z).
Definition: libairs.h:246
double lon[NDS][NPG]
Longitude [deg].
Definition: libairs.h:252
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 bg[WX][WY]
Background [K].
Definition: libairs.h:317