AIRS Code Collection
extract.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
28/* ------------------------------------------------------------
29 Global variables...
30 ------------------------------------------------------------ */
31
32/* List of AIRS channels (don't change). */
33int airs_chan[L1_NCHAN] = { 54, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
34 2035, 2036, 2040, 2041, 2052, 2053, 2054, 2055,
35 2067, 2075, 2076, 2077, 2078, 2079, 2080, 2081,
36 2082, 2086, 2088, 2089, 2091, 2092, 2093
37};
38
39/* ------------------------------------------------------------
40 Functions...
41 ------------------------------------------------------------ */
42
43/* Convert geopotential height to geometric altitude. */
44double gph2z(
45 double gph);
46
47/* ------------------------------------------------------------
48 Main...
49 ------------------------------------------------------------ */
50
51int main(
52 int argc,
53 char *argv[]) {
54
55 static airs_rad_gran_t airs_rad_gran;
56 static airs_ret_gran_t airs_ret_gran;
57
58 static airs_l1_t l1;
59 static airs_l2_t l2;
60
61 /* Check arguments... */
62 if (argc != 4)
63 ERRMSG("Give parameters: <airs_l1_file> <airs_l2_file> <out.nc>");
64
65 /* Check Level-1 filename... */
66 if (argv[1][0] != '-') {
67
68 /* Read data... */
69 printf("Read AIRS Level-1 file: %s\n", argv[1]);
70 airs_rad_rdr(argv[1], &airs_rad_gran);
71
72 /* Flag bad data... */
73 for (int track = 0; track < AIRS_RAD_GEOTRACK; track++)
74 for (int xtrack = 0; xtrack < AIRS_RAD_GEOXTRACK; xtrack++)
75 for (int ichan = 0; ichan < L1_NCHAN; ichan++)
76 if ((airs_rad_gran.state[track][xtrack] != 0)
77 || (airs_rad_gran.ExcludedChans[airs_chan[ichan]] > 2)
78 || (airs_rad_gran.CalChanSummary[airs_chan[ichan]] & 8)
79 || (airs_rad_gran.CalChanSummary[airs_chan[ichan]] & (32 + 64))
80 || (airs_rad_gran.CalFlag[track][airs_chan[ichan]] & 16))
81 airs_rad_gran.radiances[track][xtrack][airs_chan[ichan]]
82 = GSL_NAN;
83
84 /* Copy data to struct... */
85 for (int track = 0; track < AIRS_RAD_GEOTRACK; track++)
86 for (int xtrack = 0; xtrack < AIRS_RAD_GEOXTRACK; xtrack++) {
87 l1.time[track][xtrack]
88 = airs_rad_gran.Time[track][xtrack] - 220838400.;
89 l1.lon[track][xtrack]
90 = airs_rad_gran.Longitude[track][xtrack];
91 l1.lat[track][xtrack]
92 = airs_rad_gran.Latitude[track][xtrack];
93 l1.sat_z[track]
94 = airs_rad_gran.satheight[track];
95 l1.sat_lon[track]
96 = airs_rad_gran.sat_lon[track];
97 l1.sat_lat[track]
98 = airs_rad_gran.sat_lat[track];
99 for (int ichan = 0; ichan < L1_NCHAN; ichan++) {
100 l1.nu[ichan]
101 = airs_rad_gran.nominal_freq[airs_chan[ichan]];
102 l1.rad[track][xtrack][ichan]
103 = airs_rad_gran.radiances[track][xtrack][airs_chan[ichan]] *
104 0.001f;
105 }
106 }
107
108 /* Write netCDF file... */
109 write_l1(argv[3], &l1);
110 }
111
112 /* Check Level-2 filename... */
113 if (argv[2][0] != '-') {
114
115 /* Read data... */
116 printf("Read AIRS Level-2 file: %s\n", argv[2]);
117 airs_ret_rdr(argv[2], &airs_ret_gran);
118
119 /* Flag bad data... */
120 for (int track = 0; track < AIRS_RET_GEOTRACK; track++)
121 for (int xtrack = 0; xtrack < AIRS_RET_GEOXTRACK; xtrack++)
122 for (int lay = 1; lay < AIRS_RET_STDPRESSURELAY; lay++)
123 if (airs_ret_gran.GP_Height[track][xtrack][lay] <= -9000.
124 || airs_ret_gran.TAirStd[track][xtrack][lay] <= -9000.) {
125 airs_ret_gran.GP_Height[track][xtrack][lay] = GSL_NAN;
126 airs_ret_gran.TAirStd[track][xtrack][lay] = GSL_NAN;
127 }
128
129 /* Save data in struct... */
130 for (int track = 0; track < AIRS_RET_GEOTRACK; track++)
131 for (int xtrack = 0; xtrack < AIRS_RET_GEOXTRACK; xtrack++)
132 for (int lay = 1; lay < AIRS_RET_STDPRESSURELAY; lay++) {
133 l2.time[track][xtrack]
134 = airs_ret_gran.Time[track][xtrack] - 220838400.;
135 l2.z[track][xtrack][lay - 1]
136 = airs_ret_gran.GP_Height[track][xtrack][lay] / 1000.;
137 l2.lon[track][xtrack]
138 = airs_ret_gran.Longitude[track][xtrack];
139 l2.lat[track][xtrack]
140 = airs_ret_gran.Latitude[track][xtrack];
141 l2.p[lay - 1]
142 = airs_ret_gran.pressStd[lay];
143 l2.t[track][xtrack][lay - 1]
144 = airs_ret_gran.TAirStd[track][xtrack][lay];
145 }
146
147 /* Convert geopotential heights to geometric heights... */
148 for (int track = 0; track < L2_NTRACK; track++)
149 for (int xtrack = 0; xtrack < L2_NXTRACK; xtrack++)
150 for (int lay = 0; lay < L2_NLAY; lay++)
151 l2.z[track][xtrack][lay]
152 = gph2z(l2.z[track][xtrack][lay]);
153
154 /* Write netCDF file... */
155 write_l2(argv[3], &l2);
156 }
157
158 return EXIT_SUCCESS;
159}
160
161/*****************************************************************************/
162
163double gph2z(
164 double gph) {
165
166 double a = 3.086e-3;
167
168 return G0 / a - sqrt(gsl_pow_2(G0 / a) - 2 * G0 * gph / a);
169}
#define L2_NXTRACK
Definition: diff_apr.c:61
#define L2_NLAY
Definition: diff_apr.c:55
#define L1_NCHAN
Definition: diff_apr.c:46
#define L2_NTRACK
Definition: diff_apr.c:58
int main(int argc, char *argv[])
Definition: extract.c:51
double gph2z(double gph)
Definition: extract.c:163
int airs_chan[L1_NCHAN]
Definition: extract.c:33
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:237
#define G0
Standard gravity [m/s^2].
Definition: jurassic.h:274
void write_l2(char *filename, airs_l2_t *l2)
Write AIRS Level-2 data.
Definition: libairs.c:1692
void write_l1(char *filename, airs_l1_t *l1)
Write AIRS Level-1 data.
Definition: libairs.c:1634
AIRS Code Collection library declarations.
AIRS Level-1 data.
Definition: libairs.h:153
double lon[L1_NTRACK][L1_NXTRACK]
Footprint longitude [deg].
Definition: libairs.h:159
double nu[L1_NCHAN]
Channel frequencies [cm^-1].
Definition: libairs.h:174
double sat_lon[L1_NTRACK]
Satellite longitude [deg].
Definition: libairs.h:168
double time[L1_NTRACK][L1_NXTRACK]
Time (seconds since 2000-01-01T00:00Z).
Definition: libairs.h:156
float rad[L1_NTRACK][L1_NXTRACK][L1_NCHAN]
Radiance [W/(m^2 sr cm^-1)].
Definition: libairs.h:177
double sat_z[L1_NTRACK]
Satellite altitude [km].
Definition: libairs.h:165
double lat[L1_NTRACK][L1_NXTRACK]
Footprint latitude [deg].
Definition: libairs.h:162
double sat_lat[L1_NTRACK]
Satellite latitude [deg].
Definition: libairs.h:171
AIRS Level-2 data.
Definition: libairs.h:182
double time[L2_NTRACK][L2_NXTRACK]
Time (seconds since 2000-01-01T00:00Z).
Definition: libairs.h:185
double p[L2_NLAY]
Pressure [hPa].
Definition: libairs.h:197
double z[L2_NTRACK][L2_NXTRACK][L2_NLAY]
Geopotential height [km].
Definition: libairs.h:188
double t[L2_NTRACK][L2_NXTRACK][L2_NLAY]
Temperature [K].
Definition: libairs.h:200
double lat[L2_NTRACK][L2_NXTRACK]
Latitude [deg].
Definition: libairs.h:194
double lon[L2_NTRACK][L2_NXTRACK]
Longitude [deg].
Definition: libairs.h:191