AIRS Code Collection
sampling.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 double x0[3], x1[3], x2[3];
35
36 /* Check arguments... */
37 if (argc < 3)
38 ERRMSG("Give parameters: <ctl> <pert.nc>");
39
40 /* Allocate... */
41 ALLOC(pert, pert_t, 1);
42
43 /* Read perturbation data... */
44 read_pert(argv[2], "4mu", pert);
45
46 /* Init... */
47 double dmin = 1e100;
48 double dmax = -1e100;
49 double dmu = 0;
50 int n = 0;
51
52 /* Get swath width... */
53 for (int itrack = 0; itrack < pert->ntrack; itrack++) {
54 geo2cart(0, pert->lon[itrack][0], pert->lat[itrack][0], x0);
55 geo2cart(0, pert->lon[itrack][pert->nxtrack - 1],
56 pert->lat[itrack][pert->nxtrack - 1], x1);
57 double d = 2. * RE * asin(DIST(x0, x1) / (2. * RE));
58 dmin = GSL_MIN(dmin, d);
59 dmax = GSL_MAX(dmax, d);
60 dmu += d;
61 n++;
62 }
63
64 /* Write output... */
65 printf("\nmean_swath_width= %.1f km\n", dmu / n);
66 printf("minimum_swath_width= %.1f km\n", dmin);
67 printf("maximum_swath_width= %.1f km\n", dmax);
68
69 /* Init... */
70 dmin = 1e100;
71 dmax = -1e100;
72 dmu = 0;
73 n = 0;
74
75 /* Get across-track sampling distances... */
76 for (int itrack = 0; itrack < pert->ntrack; itrack++) {
77 for (int ixtrack = 0; ixtrack < pert->nxtrack - 1; ixtrack++) {
78 geo2cart(0, pert->lon[itrack][ixtrack], pert->lat[itrack][ixtrack], x0);
79 geo2cart(0, pert->lon[itrack][ixtrack + 1],
80 pert->lat[itrack][ixtrack + 1], x1);
81 double d = 2. * RE * asin(DIST(x0, x1) / (2. * RE));
82 dmin = GSL_MIN(dmin, d);
83 dmax = GSL_MAX(dmax, d);
84 dmu += d;
85 n++;
86 }
87 }
88
89 /* Write output... */
90 printf("\nmean_across_track_sampling_distance= %.1f km\n", dmu / n);
91 printf("minimum_across_track_sampling_distance= %.1f km\n", dmin);
92 printf("maximum_across_track_sampling_distance= %.1f km\n", dmax);
93
94 /* Init... */
95 dmin = 1e100;
96 dmax = -1e100;
97 dmu = 0;
98 n = 0;
99
100 /* Get along-track sampling distances... */
101 for (int itrack = 0; itrack < pert->ntrack - 1; itrack++) {
102 for (int ixtrack = 0; ixtrack < pert->nxtrack; ixtrack++) {
103 geo2cart(0, pert->lon[itrack][ixtrack], pert->lat[itrack][ixtrack], x0);
104 geo2cart(0, pert->lon[itrack + 1][ixtrack],
105 pert->lat[itrack + 1][ixtrack], x1);
106 double d = 2. * RE * asin(DIST(x0, x1) / (2. * RE));
107 dmin = GSL_MIN(dmin, d);
108 dmax = GSL_MAX(dmax, d);
109 dmu += d;
110 n++;
111 }
112 }
113
114 /* Write output... */
115 printf("\nmean_along_track_sampling_distance= %.1f km\n", dmu / n);
116 printf("minimum_along_track_sampling_distance= %.1f km\n", dmin);
117 printf("maximum_along_track_sampling_distance= %.1f km\n", dmax);
118
119 /* Init... */
120 dmin = 1e100;
121 dmax = -1e100;
122 dmu = 0;
123 n = 0;
124
125 /* Get angle between along-track and across-track direction... */
126 for (int itrack = 0; itrack < pert->ntrack - 1; itrack++) {
127 geo2cart(0, pert->lon[itrack][pert->nxtrack / 2],
128 pert->lat[itrack][pert->nxtrack / 2], x0);
129 geo2cart(0, pert->lon[itrack][pert->nxtrack / 2 + 1],
130 pert->lat[itrack][pert->nxtrack / 2 + 1], x1);
131 geo2cart(0, pert->lon[itrack + 1][pert->nxtrack / 2],
132 pert->lat[itrack + 1][pert->nxtrack / 2], x2);
133 for (int i = 0; i < 3; i++) {
134 x1[i] -= x0[i];
135 x2[i] -= x0[i];
136 }
137 double d = acos(DOTP(x1, x2) / (NORM(x1) * NORM(x2))) * 180. / M_PI;
138 dmin = GSL_MIN(dmin, d);
139 dmax = GSL_MAX(dmax, d);
140 dmu += d;
141 n++;
142 }
143
144 /* Write output... */
145 printf("\nmean_across_track_angle= %.1f deg\n", dmu / n);
146 printf("minimum_across_track_angle= %.1f deg\n", dmin);
147 printf("maximum_across_track_angle= %.1f deg\n", dmax);
148
149 /* Free... */
150 free(pert);
151
152 return EXIT_SUCCESS;
153}
void geo2cart(const double z, const double lon, const double lat, double *x)
Convert geolocation to Cartesian coordinates.
Definition: jurassic.c:3500
#define RE
Mean radius of Earth [km].
Definition: jurassic.h:299
#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 DIST(a, b)
Compute Cartesian distance between two vectors.
Definition: jurassic.h:134
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: sampling.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
double lon[PERT_NTRACK][PERT_NXTRACK]
Longitude [deg].
Definition: libairs.h:217
double lat[PERT_NTRACK][PERT_NXTRACK]
Latitude [deg].
Definition: libairs.h:220