Debian Codegraph @

gctp/src/sphdz.c

raw
1 /*******************************************************************************
2 NAME SPHDZ
3
4 PURPOSE: This function assigns values to the semimajor axis, semiminor
5 axis, and radius of sphere. If the datum code is negative,
6 the first two values in the parameter array (parm) are used
7 to define the values as follows:
8
9 --If parm[0] is a non-zero value and parm[1] is greater than
10 one, the semimajor axis and radius are set to parm[0] and
11 the semiminor axis is set to parm[1].
12
13 --If parm[0] is nonzero and parm[1] is greater than zero but
14 less than or equal to one, the semimajor axis and radius
15 are set to parm[0] and the semiminor axis is computed
16 from the eccentricity squared value parm[1]. This
17 algorithm is given below.
18
19 --If parm[0] is nonzero and parm[1] is equal to zero, the
20 semimajor axis, radius, and semiminor axis are set to
21 parm[0].
22
23 --If parm[0] equals zero and parm[1] is greater than zero,
24 the default Clarke 1866 is used to assign values to the
25 semimajor axis, radius and semiminor axis.
26
27 --If parm[0] and parm[1] equals zero, the semimajor axis
28 and radius are set to 6370997.0 (This value is represented
29 as the next to last value in the datum code array) and the
30 semiminor axis is set to zero. For datum (-20), used for
31 BCEA and/or CEA projections, the
32 corresponding values will be 6371228.0 m.
33
34 if a datum code is zero or greater, the semimajor and
35 semiminor axis are defined by the datum code as found
36 in Table A and the radius is set to 6370997.0 (except for
37 datum code of 20, where it will be 6371228.0). If the
38 datum code is greater than DATMCT+1 the default datum,
39 Clarke 1866, is used to define the semimajor
40 and semiminor axis and radius is set to 6370997.0 (except for
41 datum code of 20, where it will be 6371228.0).
42
43 The algorithm to define the semiminor axis using the
44 eccentricity squared value is as follows:
45
46 semiminor = sqrt(1.0 - ES) * semimajor where
47 ES = eccentricity squared
48
49 Table A:
50 SUPPORTED DATUMS
51
52 0: Clarke 1866 (default) 1: Clarke 1880
53 2: Bessel 3: International 1967
54 4: International 1909 5: WGS 72
55 6: Everest 7: WGS 66
56 8: GRS 1980/WGS 84 9: Airy
57 10: Modified Everest 11: Modified Airy
58 12: Walbeck 13: Southeast Asia
59 14: Australian National 15: Krassovsky
60 16: Hough 17: Mercury 1960
61 18: Modified Mercury 1968 19: Sphere of Radius
62 6370997 meters
63 20: Sphere of Radius 21: Sphere of Radius
64 6371228 meters 6371007.181 meters
65 22: Hughes 1980
66
67 Note: Datum code of 20 is added by Abe Taaheri for 25 km global EASE grid that
68 assumes an earth radius of 6371228 meters.
69
70 Note: Datum code of 21 is added by Sharon Ni for MODIS Sinusoidal data that assumes
71 an earth radius of 6371007.181 meters.
72
73 Note: Datum code of 22 is added by Abe Taaheri for Hughes 1980 datum used in AMSR_E Sea Ice
74 products (Semi Major Axis 6378273.0 meters, Semi Minor Axis 6356889.4485 meters)
75
76 PROGRAMMER DATE
77 ---------- ----
78 T. Mittan MARCH, 1993
79
80 ALGORITHM REFERENCES
81
82 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
83 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
84 State Government Printing Office, Washington D.C., 1987.
85
86 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
87 U.S. Geological Survey Professional Paper 1453 , United State Government
88 Printing Office, Washington D.C., 1989.
89 *******************************************************************************/
90 #include <stdio.h>
91 #include <stdlib.h>
92 #include "cproj.h"
93 #include "proj.h"
94
95 static double major[23] = {6378206.4, 6378249.145, 6377397.155, 6378157.5,
96 6378388.0, 6378135.0, 6377276.3452, 6378145.0,
97 6378137.0, 6377563.396, 6377304.063, 6377340.189,
98 6378137.0, 6378155.0, 6378160.0, 6378245.0,
99 6378270.0, 6378166.0, 6378150.0,
100 6370997.0, 6371228.0, 6371007.181, 6378273.0};
101
102 static double minor[23] = {6356583.8, 6356514.86955, 6356078.96284, 6356772.2,
103 6356911.94613, 6356750.519915, 6356075.4133,
104 6356759.769356, 6356752.31414, 6356256.91,
105 6356103.039, 6356034.448, 6356752.314245,
106 6356773.3205, 6356774.719, 6356863.0188,
107 6356794.343479, 6356784.283666, 6356768.337303,
108 6370997.0, 6371228.0, 6371007.181, 6356889.4485};
109
110
111 /* Finds the correct ellipsoid axis
112 ---------------------------------*/
113
114 int sphdz(
115 long isph, /* spheroid code number also known as datum */
116 double *parm, /* projection parameters */
117 double *r_major, /* major axis */
118 double *r_minor, /* minor axis */
119 double *radius) /* radius */
120 {
121
122 double t_major; /* temporary major axis */
123 double t_minor; /* temporary minor axis */
124 long jsph; /* spheroid code number */
125
126 if (isph < 0)
127 {
128 t_major = fabs(parm[0]);
129 t_minor = fabs(parm[1]);
130
131 if (t_major > 0.0)
132 {
133 if (t_minor > 1.0)
134 {
135 *r_major = t_major;
136 *r_minor = t_minor;
137 *radius = t_major;
138 }
139 else
140 if (t_minor > 0.0)
141 {
142 *r_major = t_major;
143 *radius = t_major;
144 *r_minor = (sqrt(1.0 - t_minor)) * t_major;
145 }
146 else
147 {
148 *r_major = t_major;
149 *radius = t_major;
150 *r_minor = t_major;
151 }
152 }
153 else /* t_major <= 0 */
154 if (t_minor > 0.0)
155 {
156 *r_major = major[0];
157 *radius = major[0];
158 *r_minor = minor[0];
159 }
160 else /* t_minor <= 0 */
161 if(isph == -22 ) /*Hughes 1980 */
162 {
163 *r_major = major[DATMCT+ 2];
164 *radius = major[DATMCT+ 2];
165 *r_minor = minor[DATMCT+ 2];
166 }
167 else if(isph == -21 ) /* MODIS Sphere*/
168 {
169 *r_major = major[DATMCT + 1];
170 *radius = major[DATMCT + 1];
171 *r_minor = 6371007.181;
172 }
173 else
174 if(isph == -20 ) /*BCEA or CEA */
175 {
176 *r_major = major[DATMCT];
177 *radius = major[DATMCT];
178 *r_minor = 6371228.0;
179 }
180 else
181 {
182 *r_major = major[DATMCT - 1];
183 *radius = major[DATMCT - 1];
184 *r_minor = 6370997.0;
185 }
186 }
187 else /* isph >= 0 */
188 {
189 jsph = labs(isph);
190 if (jsph > 22)
191 {
192 p_error("Invalid spheroid selection","INFORMATIONAL");
193 p_error("Reset to 0","INFORMATIONAL");
194 isph = 1;
195 jsph = 0;
196 }
197 else
198 if (jsph == 22) /* check for Hughes 1980*/
199 {
200 *r_major = major[jsph];
201 *r_minor = minor[jsph];
202 *radius = major[DATMCT - 1]; /* standard sphere */
203 }
204 else
205 if (jsph == 21) /* check for the Modis sphere*/
206 {
207 *r_major = major[jsph];
208 *r_minor = minor[jsph];
209 *radius = major[jsph];
210 }
211 else
212 if (jsph == 20) /* BCEA defaults to spherical earth with radius 6371228.0 */
213 {
214 *r_major = major[jsph];
215 *r_minor = minor[jsph];
216 *radius = major[DATMCT];
217 }
218 else
219 {
220 *r_major = major[jsph];
221 *r_minor = minor[jsph];
222 *radius = major[DATMCT - 1]; /* standard sphere */
223 }
224 }
225 return(OK);
226 }