JURASSIC
Functions
zenith.c File Reference

Create observation geometry for zenith observations. More...

#include "jurassic.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Create observation geometry for zenith observations.

Definition in file zenith.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 27 of file zenith.c.

29 {
30
31 static ctl_t ctl;
32 static obs_t obs;
33
34 /* Check arguments... */
35 if (argc < 3)
36 ERRMSG("Give parameters: <ctl> <obs>");
37
38 /* Read control parameters... */
39 read_ctl(argc, argv, &ctl);
40 const double t0 = scan_ctl(argc, argv, "T0", -1, "0", NULL);
41 const double t1 = scan_ctl(argc, argv, "T1", -1, "0", NULL);
42 const double dt = scan_ctl(argc, argv, "DT", -1, "1", NULL);
43 const double vpz = scan_ctl(argc, argv, "VPZ", -1, "700", NULL);
44 const double theta0 = scan_ctl(argc, argv, "THETA0", -1, "-90.0", NULL);
45 const double theta1 = scan_ctl(argc, argv, "THETA1", -1, "90.0", NULL);
46 const double dtheta = scan_ctl(argc, argv, "DTHETA", -1, "3.0", NULL);
47 const double obsz = scan_ctl(argc, argv, "OBSZ", -1, "0", NULL);
48
49 /* Set distances... */
50 const double ro = RE + obsz; /* observer radius */
51 const double rv = RE + vpz; /* shell radius */
52
53 /* Create measurement geometry... */
54 for (double t = t0; t <= t1; t += dt) {
55 for (double theta = theta0; theta <= theta1 + 1e-12; theta += dtheta) {
56
57 /* Check number of ray paths... */
58 if ((obs.nr) >= NR)
59 ERRMSG("Too many rays!");
60
61 /* Auxilary variables... */
62 const double th = DEG2RAD(theta);
63 const double sth = sin(th);
64 const double cth = cos(th);
65
66 /*
67 Ray in local x-z plane:
68 A = (0, 0, ro)
69 u = (sin(th), 0, cos(th)) (|u|=1)
70 P(s) = A + s u, s >= 0
71
72 Intersect with sphere |P| = rv:
73 s^2 + 2 ro cos(th) s + (ro^2 - rv^2) = 0
74 Discriminant:
75 disc = rv^2 - ro^2 sin^2(th)
76 */
77 double disc = rv * rv - ro * ro * sth * sth;
78 if (disc < 0.0) {
79 if (disc > -1e-12 * rv * rv)
80 disc = 0.0; // tolerate tiny negatives
81 else
82 continue;
83 }
84
85 /* If disc < 0, ray misses the shell: skip this ray */
86 if (disc < 0.0)
87 continue;
88
89 /* Two intersections along the ray... */
90 const double sq = sqrt(disc);
91 const double s1 = -ro * cth - sq;
92 const double s2 = -ro * cth + sq;
93
94 /* Choose nearest forward intersection (smallest s >= 0)... */
95 double s = DBL_MAX;
96 if (s1 >= 0.0)
97 s = s1;
98 if (s2 >= 0.0 && s2 < s)
99 s = s2;
100
101 /* If both are behind observer, skip... */
102 if (s == DBL_MAX)
103 continue;
104
105 /* Intersection point B in local x-z plane... */
106 const double bx = s * sth;
107 const double bz = ro + s * cth;
108
109 /*
110 Central angle beta = angle between OA (z-axis) and OB.
111 In this local frame, OA is +z. For points in x-z plane:
112 beta = atan2(bx, bz)
113 This preserves sign (north/south) consistent with theta sign.
114 */
115 const double beta = atan2(bx, bz);
116
117 /* Set observer and view point... */
118 obs.time[obs.nr] = t;
119 obs.obsz[obs.nr] = obsz;
120 obs.vpz[obs.nr] = vpz;
121
122 /* Stored as "view point latitude-like" angle for this 2-D meridional setup... */
123 obs.vplat[obs.nr] = RAD2DEG(beta);
124
125 /* Increment ray path counter... */
126 obs.nr++;
127 }
128 }
129
130 /* Write observation data... */
131 write_obs(NULL, argv[2], &ctl, &obs);
132
133 return EXIT_SUCCESS;
134}
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
Definition: jurassic.c:5450
void write_obs(const char *dirname, const char *filename, const ctl_t *ctl, const obs_t *obs)
Write observation data to an output file in ASCII or binary format.
Definition: jurassic.c:7541
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:6380
#define RE
Mean radius of Earth [km].
Definition: jurassic.h:189
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: jurassic.h:1194
#define DEG2RAD(deg)
Convert degrees to radians.
Definition: jurassic.h:425
#define RAD2DEG(rad)
Convert radians to degrees.
Definition: jurassic.h:991
#define NR
Maximum number of ray paths.
Definition: jurassic.h:253
Control parameters.
Definition: jurassic.h:1297
Observation geometry and radiance data.
Definition: jurassic.h:1523
double vpz[NR]
View point altitude [km].
Definition: jurassic.h:1541
double vplat[NR]
View point latitude [deg].
Definition: jurassic.h:1547
double obsz[NR]
Observer altitude [km].
Definition: jurassic.h:1532
double time[NR]
Time (seconds since 2000-01-01T00:00Z).
Definition: jurassic.h:1529
int nr
Number of ray paths.
Definition: jurassic.h:1526
Here is the call graph for this function: