OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ctogd.c
Go to the documentation of this file.
1 /*
2  *----------------------------------------------------------------------
3  * @(#) ctogd.c 1.0 30 Jan 95 <shc>
4  * Copyright (c) 1995, CSIRO Division of Oceanography.
5  *----------------------------------------------------------------------
6  *
7  * ctogd --
8  *
9  * Rectangular (Cartesian) to geodetic coordinate conversion.
10  *
11  * Results:
12  *
13  * Given the rectangular (Cartesian) coordinates of an object,
14  * calculate its geodetic latitude, longitude, height and, optionally,
15  * the derivatives of these wrt rectangular. The GHA argument allows
16  * the Greenwich Hour Angle to be taken into account if desired.
17  * Algorithm and formulations are from GTDS manual, section 3.3.6.3.
18  * Yet again, GTDS is incorrect in its formulations of the partial
19  * derivatives. The ones here have been derived by analytically
20  * inverting the Jacobian for the geodetic to Cartesian conversion.
21  *
22  * Units are radians, metres and seconds.
23  *
24  * Lat, long and height are returned in GEOD. If "DGEOD" is
25  * non-NULL, the 3x3 Jacobian of geodetic coordinates wrt
26  * rectangular coordinates is returned in DGEOD.
27  *
28  * Side effects:
29  * None.
30  *
31  * History:
32  * 30 Jan 95 <shc>
33  * Converted from FORTRAN to C
34  *
35  *----------------------------------------------------------------------
36  */
37 
38 #include <math.h>
39 
40 #include "orbit.h"
41 #include "earth.h"
42 
43 #define EPS 1.0e-14 /* Convergence tolerance */
44 
45 void
46 ctogd(r, gha, geod, dgeod)
47 double r[3]; /* Rectangular coordinates of object (metres) */
48 double gha; /* Greenwich Hour Angle correction (radians) */
49 struct GEODETIC *geod; /* Geodetic coordinates of object (radians, metres) */
50 double dgeod[3][3]; /* Jacobian of (lat, lon, hgt) wrt (x, y, z) */
51 {
52 
53  double esq, eqrsq, zi, ziold, zib, enph, sinlat, en, h, eqr,
54  omesq, a, b;
55 
56  esq = FLT * (2.0 - FLT);
57  eqrsq = r[0] * r[0] + r[1] * r[1];
58  zi = -esq * r[2];
59 
60  do {
61  ziold = zi;
62  zib = r[2] - ziold;
63  enph = sqrt(eqrsq + zib * zib);
64  sinlat = zib / enph;
65  en = EQRAD / sqrt(1.0 - esq * sinlat * sinlat);
66  zi = -en * esq * sinlat;
67  } while (fabs(zi - ziold) > EPS * fabs(zi));
68 
69  /*
70  * Spacecraft latitude, longitude and height.
71  */
72 
73  geod->lat = asin(sinlat);
74  geod->lon = ANPI(atan2(r[1], r[0]) - gha);
75  geod->height = h = enph - en;
76 
77  /*
78  * Derivatives of latitude, longitude and height wrt Cartesian
79  * coordinates. First row is derivatives of latitude wrt
80  * x (dgeod[0][0])), y (dgeod[0][1]) and z (dgeod[0][2]). Second
81  * row is derivatives of longitude, third is derivatives of height.
82  */
83 
84  if (dgeod != NULL) {
85 
86  eqr = sqrt(eqrsq);
87  omesq = (1.0 - esq);
88  a = h + en * omesq / (1.0 - esq * sinlat * sinlat);
89  b = sinlat / (a * eqr);
90  dgeod[0][0] = -b * r[0];
91  dgeod[0][1] = -b * r[1];
92  dgeod[0][2] = eqr / (a * enph);
93 
94  dgeod[1][0] = -r[1] / eqrsq;
95  dgeod[1][1] = r[0] / eqrsq;
96  dgeod[1][2] = 0.0;
97 
98  dgeod[2][0] = r[0] / enph;
99  dgeod[2][1] = r[1] / enph;
100  dgeod[2][2] = r[2] / enph;
101 
102  }
103 }
int r
Definition: decode_rs.h:73
#define EQRAD
Definition: earth.h:33
double height
Definition: orbit.h:119
#define ANPI(X)
Definition: orbit.h:60
#define NULL
Definition: decode_rs.h:63
float h[MODELMAX]
Definition: atrem_corl1.h:131
double lon
Definition: orbit.h:118
data_t b[NROOTS+1]
Definition: decode_rs.h:77
#define fabs(a)
Definition: misc.h:93
void ctogd(r, double gha, struct GEODETIC *geod, dgeod)
Definition: ctogd.c:46
#define FLT
Definition: earth.h:31
PGE01 indicating that PGE02 PGE01 V6 for and PGE01 V2 for MOD03 were used to produce the granule By convention adopted in all MODIS Terra PGE02 code versions are The fourth digit of the PGE02 version denotes the LUT version used to produce the granule The source of the metadata environment variable ProcessingCenter was changed from a QA LUT value to the Process Configuration A sign used in error in the second order term was changed to a
Definition: HISTORY.txt:424
double lat
Definition: orbit.h:117
#define EPS
Definition: ctogd.c:43