AIRS Code Collection
overpass.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 Functions...
30 ------------------------------------------------------------ */
31
32/* Write results to file. */
33void write_results(
34 FILE * out,
35 pert_t * pert,
36 int track0,
37 int xtrack0,
38 int orb,
39 double dmin,
40 double obsz);
41
42/* ------------------------------------------------------------
43 Main...
44 ------------------------------------------------------------ */
45
46int main(
47 int argc,
48 char *argv[]) {
49
50 static pert_t *pert;
51
52 FILE *out;
53
54 char pertname[LEN];
55
56 double dmin = 1e100, x0[3], x1[3];
57
58 int orb = 0, track0 = 0, xtrack0 = 0;
59
60 /* Check arguments... */
61 if (argc < 6)
62 ERRMSG("Give parameters: <ctl> <pert.nc> <lon0> <lat0> <overpass.tab>");
63
64 /* Get arguments... */
65 const double lon0 = atof(argv[3]);
66 const double lat0 = atof(argv[4]);
67
68 /* Get control parameters... */
69 scan_ctl(argc, argv, "PERTNAME", -1, "4mu", pertname);
70 const double orblat = scan_ctl(argc, argv, "ORBLAT", -1, "0", NULL);
71 const double rmax = scan_ctl(argc, argv, "RMAX", -1, "100", NULL);
72 const double obsz = scan_ctl(argc, argv, "OBSZ", -1, "", NULL);
73
74 /* Allocate... */
75 ALLOC(pert, pert_t, 1);
76
77 /* Read perturbation data... */
78 read_pert(argv[2], pertname, pert);
79
80 /* Get Cartesian coordinates... */
81 geo2cart(0, lon0, lat0, x0);
82
83 /* Create file... */
84 printf("Write overpass data file: %s\n", argv[5]);
85 if (!(out = fopen(argv[5], "w")))
86 ERRMSG("Cannot create file!");
87
88 /* Write header... */
89 fprintf(out,
90 "# $1 = time (seconds since 2000-01-01T00:00Z)\n"
91 "# $2 = time (string)\n"
92 "# $3 = longitude [deg]\n"
93 "# $4 = latitude [deg]\n"
94 "# $5 = along-track index\n"
95 "# $6 = across-track index\n"
96 "# $7 = orbit number\n"
97 "# $8 = ascending (1=yes, 0=no)\n"
98 "# $9 = scan angle [deg]\n" "# $10 = distance [km]\n\n");
99
100 /* Find nearest footprint... */
101 for (int track = 0; track < pert->ntrack; track++) {
102
103 /* Check for new orbit... */
104 if (track > 0)
105 if (pert->lat[track - 1][pert->nxtrack / 2] <= orblat
106 && pert->lat[track][pert->nxtrack / 2] >= orblat) {
107
108 /* Write results... */
109 if (sqrt(dmin) <= rmax)
110 write_results(out, pert, track0, xtrack0, orb, dmin, obsz);
111
112 /* Set counters... */
113 dmin = 1e100;
114 orb++;
115 }
116
117 /* Check distance of footprints... */
118 for (int xtrack = 0; xtrack < pert->nxtrack; xtrack++) {
119 geo2cart(0, pert->lon[track][xtrack], pert->lat[track][xtrack], x1);
120 if (DIST2(x0, x1) < dmin) {
121 dmin = DIST2(x0, x1);
122 track0 = track;
123 xtrack0 = xtrack;
124 }
125 }
126 }
127
128 /* Write results for last orbit... */
129 if (sqrt(dmin) <= rmax)
130 write_results(out, pert, track0, xtrack0, orb, dmin, obsz);
131
132 /* Close file... */
133 fclose(out);
134
135 /* Free... */
136 free(pert);
137
138 return EXIT_SUCCESS;
139}
140
141/*****************************************************************************/
142
144 FILE *out,
145 pert_t *pert,
146 int track0,
147 int xtrack0,
148 int orb,
149 double dmin,
150 double obsz) {
151
152 double xf[3], xs[3], xsf[3], remain;
153
154 int year, mon, day, hour, min, sec;
155
156 /* Calculate scan angle... */
157 geo2cart(0, pert->lon[track0][xtrack0], pert->lat[track0][xtrack0], xf);
158 geo2cart(0, pert->lon[track0][pert->nxtrack / 2],
159 pert->lat[track0][pert->nxtrack / 2], xsf);
160 geo2cart(obsz, pert->lon[track0][pert->nxtrack / 2],
161 pert->lat[track0][pert->nxtrack / 2], xs);
162 for (int i = 0; i < 3; i++) {
163 xf[i] -= xs[i];
164 xsf[i] -= xs[i];
165 }
166 double alpha = 180. / M_PI * acos(DOTP(xf, xsf) / NORM(xf) / NORM(xsf));
167 if (xtrack0 < pert->nxtrack / 2)
168 alpha = -alpha;
169
170 /* Get ascending/descending flag... */
171 int asc = (pert->lat[track0 > 0 ? track0 : track0 + 1][pert->nxtrack / 2]
172 > pert->lat[track0 >
173 0 ? track0 - 1 : track0][pert->nxtrack / 2]);
174
175 /* Write results... */
176 jsec2time(pert->time[track0][xtrack0], &year, &mon, &day,
177 &hour, &min, &sec, &remain);
178 fprintf(out,
179 "%.2f %d-%02d-%02dT%02d:%02d:%02dZ %g %g %d %d %d %d %g %g\n",
180 pert->time[track0][xtrack0], year, mon, day, hour, min, sec,
181 pert->lon[track0][xtrack0], pert->lat[track0][xtrack0],
182 track0, xtrack0, orb, asc, alpha, sqrt(dmin));
183}
void jsec2time(const double jsec, int *year, int *mon, int *day, int *hour, int *min, int *sec, double *remain)
Convert seconds to date.
Definition: jurassic.c:3971
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
void geo2cart(const double z, const double lon, const double lat, double *x)
Convert geolocation to Cartesian coordinates.
Definition: jurassic.c:3500
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:383
#define DOTP(a, b)
Compute dot product of two vectors.
Definition: jurassic.h:141
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:237
#define NORM(a)
Compute norm of a vector.
Definition: jurassic.h:180
#define ALLOC(ptr, type, n)
Allocate memory.
Definition: jurassic.h:121
#define DIST2(a, b)
Compute squared distance between two vectors.
Definition: jurassic.h:137
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: overpass.c:46
void write_results(FILE *out, pert_t *pert, int track0, int xtrack0, int orb, double dmin, double obsz)
Definition: overpass.c:143
Perturbation data.
Definition: libairs.h:205
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