3 This is the TRMM Office Radar Software Library.
4 Copyright (C) 1996, 1997
6 Space Applications Corporation
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with this library; if not, write to the Free
21 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 # define M_PI 3.14159265358979323846
28 # define M_PI_2 1.57079632679489661923
29 /* Earth radius in km. */
30 double Re = (6374.0*4.0/3.0);
32 /********************************************************************/
34 /* RSL_set_earth_rad(double new_Re) */
36 /* By: Dennis Flanigan */
37 /* Applied Research Corporation */
39 /********************************************************************/
40 void RSL_set_earth_radius(double new_Re)
45 /*********************************************************************/
47 /* void RSL_get_gr_slantr_h */
48 /* *gr - ground range in KM. */
49 /* *slantr - slant range in KM. */
50 /* *h - height in KM. */
52 /* By: John Merritt */
54 /*********************************************************************/
55 void RSL_get_gr_slantr_h(Ray *ray, int i, float *gr, float *slantr, float *h)
57 *gr = *slantr = *h = 0.0;
58 if (ray == NULL) return;
59 *slantr = i * ray->h.gate_size + ray->h.range_bin1;
60 *slantr /= 1000; /* meters to km */
61 RSL_get_groundr_and_h(*slantr, ray->h.elev, gr, h);
65 /*********************************************************************/
67 /* RSL_get_groundr_and_h(sr, elev, &gr, &h) */
69 /* By: John Merritt */
70 /* Space Applications Corporation */
72 /*********************************************************************/
73 void RSL_get_groundr_and_h(float slant_r, float elev, float *gr, float *h)
76 * slant_r - slant range, along the beam, in km.
77 * elev - elevation angle, in degrees.
80 * gr - Ground range in km.
81 * h - Height of data point above earth, in km.
86 if (slant_r == 0.0) {*h = 0; *gr = 0; return;}
88 H = sqrt( pow(Re,2.0) + pow(slant_r,2.0) - 2*Re*slant_r*cos(elev*M_PI/180.0));
90 GR = Re * acos( ( pow(Re,2.0) + pow(H,2.0) - pow(slant_r,2.0)) / (2 * Re * H));
102 /*********************************************************************/
104 /* RSL_get_slantr_and_elev(gr, h, &r, &e) */
106 /* By: John Merritt */
107 /* Space Applications Corporation */
110 /*********************************************************************/
111 void RSL_get_slantr_and_elev(float gr, float h, float *slant_r, float *elev)
114 * gr - Ground range in km.
115 * h - Height of data point above earth, in km.
118 * slant_r - slant range, along the beam, in km.
119 * elev - elevation angle, in degrees.
122 /* This equation lifted from Dennis Flanigan's rsph.c code. */
124 double slant_r_2; /* Slant range squared. */
128 if (gr == 0) {*slant_r = 0; *elev = 0; return;}
132 slant_r_2 = pow(Re,2.0) + pow(h,2.0) - (2*Re*h*cos(gr/Re));
133 SLANTR = sqrt(slant_r_2);
135 ELEV = acos( (pow(Re,2.0) + slant_r_2 - pow(h,2.0)) / (2*Re*(SLANTR)));
144 /*********************************************************************/
146 /* RSL_get_slantr_and_h(gr, elev, &sr, &h) */
148 /* By: John Merritt */
149 /* Space Applications Corporation */
152 /*********************************************************************/
153 void RSL_get_slantr_and_h(float gr, float elev, float *slant_r, float *h)
156 * gr - Ground range in km.
157 * elev - elevation angle, in degrees.
160 * slant_r - slant range, along the beam, in km.
161 * h - Height of data point above earth, in km.
171 if (gr == 0) {*slant_r = 0; *h = 0; return;}
173 ELEV = elev*M_PI/180.0;
174 ALPHA = ELEV + M_PI_2; /* Elev angle + 90 */
176 BETA = M_PI - (ALPHA + GAMMA); /* Angle made by Re+h and slant */
177 SLANTR = Re*(sin(GAMMA)/sin(BETA));
178 A = Re*sin(ALPHA)/sin(BETA);
180 *h = (float) (A - Re);
181 *slant_r = (float)SLANTR;