JURASSIC
raytrace.c
Go to the documentation of this file.
1/*
2 This file is part of JURASSIC.
3
4 JURASSIC is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 JURASSIC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with JURASSIC. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright (C) 2003-2026 Forschungszentrum Juelich GmbH
18*/
19
25#include "jurassic.h"
26
27/* ------------------------------------------------------------
28 Functions...
29 ------------------------------------------------------------ */
30
32static void usage(
33 void);
34
35/* ------------------------------------------------------------
36 Main...
37 ------------------------------------------------------------ */
38
39int main(
40 int argc,
41 char *argv[]) {
42
43 static atm_t atm;
44 static ctl_t ctl;
45 static los_t los;
46 static obs_t obs;
47
48 FILE *out;
49
50 char filename[2 * LEN], losbase[LEN];
51
52 double u[NG];
53
54 /* Print usage information... */
55 USAGE;
56
57 /* Check arguments... */
58 if (argc < 5)
59 ERRMSG("Missing or invalid command-line arguments.\n\n"
60 "Usage: raytrace <ctl> <obs> <atm> <raytrace.tab> [KEY VALUE ...]\n\n"
61 "Use -h for full help.");
62
63 /* Read control parameters... */
64 read_ctl(argc, argv, &ctl);
65
66 /* Get basenames... */
67 scan_ctl(argc, argv, "LOSBASE", -1, "los", losbase);
68
69 /* Read observation geometry... */
70 read_obs(NULL, argv[2], &ctl, &obs, 0);
71
72 /* Read atmospheric data... */
73 read_atm(NULL, argv[3], &ctl, &atm, 0);
74
75 /* Write info... */
76 LOG(1, "Write raytrace data: %s", argv[4]);
77
78 /* Create file... */
79 if (!(out = fopen(argv[4], "w")))
80 ERRMSG("Cannot create file!");
81
82 /* Write header... */
83 fprintf(out,
84 "# $1 = time (seconds since 2000-01-01T00:00Z)\n"
85 "# $2 = observer altitude [km]\n"
86 "# $3 = observer longitude [deg]\n"
87 "# $4 = observer latitude [deg]\n"
88 "# $5 = view point altitude [km]\n"
89 "# $6 = view point longitude [deg]\n"
90 "# $7 = view point latitude [deg]\n"
91 "# $8 = tangent point altitude [km]\n"
92 "# $9 = tangent point longitude [deg]\n"
93 "# $10 = tangent point latitude [deg]\n"
94 "# $11 = ray path index\n" "# $12 = ray path length [km]\n");
95 for (int ig = 0; ig < ctl.ng; ig++)
96 fprintf(out, "# $%d = %s column density [molec/cm^2]\n",
97 13 + ig, ctl.emitter[ig]);
98 fprintf(out, "\n");
99
100 /* Loop over rays... */
101 for (int ir = 0; ir < obs.nr; ir++) {
102
103 /* Raytracing... */
104 raytrace(&ctl, &atm, &obs, &los, ir);
105
106 /* Set filename data... */
107 sprintf(filename, "%s.%d.tab", losbase, ir);
108
109 /* Write info... */
110 LOG(1, "Write LOS data: %s", filename);
111
112 /* Create file... */
113 FILE *out2;
114 if (!(out2 = fopen(filename, "w")))
115 ERRMSG("Cannot create file!");
116
117 /* Write header... */
118 fprintf(out2,
119 "# $1 = time (seconds since 2000-01-01T00:00Z)\n"
120 "# $2 = altitude [km]\n"
121 "# $3 = longitude [deg]\n"
122 "# $4 = latitude [deg]\n"
123 "# $5 = pressure [hPa]\n" "# $6 = temperature [K]\n");
124 for (int ig = 0; ig < ctl.ng; ig++)
125 fprintf(out2, "# $%d = %s volume mixing ratio [ppv]\n",
126 7 + ig, ctl.emitter[ig]);
127 for (int iw = 0; iw < ctl.nw; iw++)
128 fprintf(out2, "# $%d = extinction (window %d) [km^-1]\n",
129 7 + ctl.ng + iw, iw);
130 fprintf(out2, "\n");
131
132 /* Write data... */
133 for (int ip = 0; ip < los.np; ip++) {
134 fprintf(out2, "%.2f %g %g %g %g %g", obs.time[ir], los.z[ip],
135 los.lon[ip], los.lat[ip], los.p[ip], los.t[ip]);
136 for (int ig = 0; ig < ctl.ng; ig++)
137 fprintf(out2, " %g", los.q[ip][ig]);
138 for (int iw = 0; iw < ctl.nw; iw++)
139 fprintf(out2, " %g", los.k[ip][iw]);
140 fprintf(out2, "\n");
141 }
142
143 /* Close file... */
144 fclose(out2);
145
146 /* Get column densities... */
147 double s = 0;
148 for (int ig = 0; ig < ctl.ng; ig++)
149 u[ig] = 0;
150 for (int ip = 0; ip < los.np; ip++) {
151 s += los.ds[ip];
152 for (int ig = 0; ig < ctl.ng; ig++)
153 u[ig] += los.u[ip][ig];
154 }
155
156 /* Write summary data... */
157 fprintf(out, "%.2f %g %g %g %g %g %g %g %g %g %d %g",
158 obs.time[ir], obs.obsz[ir], obs.obslon[ir], obs.obslat[ir],
159 obs.vpz[ir], obs.vplon[ir], obs.vplat[ir],
160 obs.tpz[ir], obs.tplon[ir], obs.tplat[ir], ir, s);
161 for (int ig = 0; ig < ctl.ng; ig++)
162 fprintf(out, " %g", u[ig]);
163 fprintf(out, "\n");
164 }
165
166 /* Close file... */
167 fclose(out);
168
169 return EXIT_SUCCESS;
170}
171
172/*****************************************************************************/
173
174static void usage(
175 void) {
176 printf("\nJURASSIC ray-tracing tool.\n\n");
177 printf("Determine atmospheric line-of-sight paths and write a summary\n");
178 printf("table plus one LOS profile file per ray.\n\n");
179 printf("Usage:\n");
180 printf(" raytrace <ctl> <obs> <atm> <raytrace.tab> [KEY VALUE ...]\n\n");
181 printf("Arguments:\n");
182 printf(" <ctl> Control file.\n");
183 printf(" <obs> Observation geometry input file.\n");
184 printf(" <atm> Atmospheric state input file.\n");
185 printf(" <raytrace.tab> Output summary table for traced rays.\n");
186 printf(" [KEY VALUE] Optional control parameters.\n\n");
187 printf("Tool-specific control parameters:\n");
188 printf(" LOSBASE <name> Basename for per-ray LOS output files.\n\n");
189 printf("Common control parameters:\n");
190 printf(" ATMFMT, OBSFMT Input file formats.\n");
191 printf(" NG, EMITTER[i] Active emitters.\n");
192 printf
193 (" ND, NU[i] Spectral channels in observation files.\n");
194 printf(" NW, WINDOW[i] Extinction-window layout.\n");
195 printf(" REFRAC, RAYDS, RAYDZ Ray-tracing settings.\n\n");
196 printf("Further information:\n");
197 printf(" Manual: https://slcs-jsc.github.io/jurassic/\n");
198}
void usage(void)
Print command-line help.
Definition: formod.c:163
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:5516
void raytrace(const ctl_t *ctl, const atm_t *atm, obs_t *obs, los_t *los, const int ir)
Perform line-of-sight (LOS) ray tracing through the atmosphere.
Definition: jurassic.c:4965
void read_obs(const char *dirname, const char *filename, const ctl_t *ctl, obs_t *obs, int profile)
Read observation data from an input file.
Definition: jurassic.c:5810
void read_atm(const char *dirname, const char *filename, const ctl_t *ctl, atm_t *atm, int profile)
Read atmospheric input data from a file.
Definition: jurassic.c:5193
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scan control file or command-line arguments for a configuration variable.
Definition: jurassic.c:6612
JURASSIC library declarations.
#define LEN
Maximum length of ASCII data lines.
Definition: jurassic.h:268
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1325
#define USAGE
Print usage information on -h or --help.
Definition: jurassic.h:1206
#define NG
Maximum number of emitters.
Definition: jurassic.h:298
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: jurassic.h:1255
int main(int argc, char *argv[])
Definition: raytrace.c:39
Atmospheric profile data.
Definition: jurassic.h:1375
Control parameters.
Definition: jurassic.h:1428
int nw
Number of spectral windows.
Definition: jurassic.h:1455
int ng
Number of emitters.
Definition: jurassic.h:1431
char emitter[NG][LEN]
Name of each emitter.
Definition: jurassic.h:1434
Line-of-sight data.
Definition: jurassic.h:1595
double z[NLOS]
Altitude [km].
Definition: jurassic.h:1601
double q[NLOS][NG]
Volume mixing ratio [ppv].
Definition: jurassic.h:1616
double lon[NLOS]
Longitude [deg].
Definition: jurassic.h:1604
double ds[NLOS]
Segment length [km].
Definition: jurassic.h:1628
int np
Number of LOS points.
Definition: jurassic.h:1598
double u[NLOS][NG]
Column density [molecules/cm^2].
Definition: jurassic.h:1631
double lat[NLOS]
Latitude [deg].
Definition: jurassic.h:1607
double k[NLOS][ND]
Extinction [km^-1].
Definition: jurassic.h:1619
double t[NLOS]
Temperature [K].
Definition: jurassic.h:1613
double p[NLOS]
Pressure [hPa].
Definition: jurassic.h:1610
Observation geometry and radiance data.
Definition: jurassic.h:1657
double tplon[NR]
Tangent point longitude [deg].
Definition: jurassic.h:1687
double vpz[NR]
View point altitude [km].
Definition: jurassic.h:1675
double vplat[NR]
View point latitude [deg].
Definition: jurassic.h:1681
double obslon[NR]
Observer longitude [deg].
Definition: jurassic.h:1669
double obslat[NR]
Observer latitude [deg].
Definition: jurassic.h:1672
double obsz[NR]
Observer altitude [km].
Definition: jurassic.h:1666
double tplat[NR]
Tangent point latitude [deg].
Definition: jurassic.h:1690
double vplon[NR]
View point longitude [deg].
Definition: jurassic.h:1678
double time[NR]
Time (seconds since 2000-01-01T00:00Z).
Definition: jurassic.h:1663
double tpz[NR]
Tangent point altitude [km].
Definition: jurassic.h:1684
int nr
Number of ray paths.
Definition: jurassic.h:1660