OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
sphdz.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME SPHDZ
3 
4 PURPOSE: This function assigns values to the semimajor axis, semiminor
5  axis, and radius of sphere. If the spheroid 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 last value in the spheroid code array) and the
30  semiminor axis is set to zero.
31 
32  if a spheroid code is zero or greater, the semimajor and
33  semiminor axis are defined by the spheroid code, listed below
34  in the array assignment, and the radius is set to 6370997.0
35  (or 6371007.181 if the sphere number is 31).
36  If the spheroid code is greater than SPHDCT the default
37  spheroid, Clarke 1866, is used to define the semimajor
38  and semiminor axis and radius is set to 6370997.0.
39 
40  The algorithm to define the semiminor axis using the
41  eccentricity squared value is as follows:
42 
43  semiminor = sqrt(1.0 - ES) * semimajor where
44  ES = eccentricity squared
45 
46 
47 
48 ALGORITHM REFERENCES
49 
50 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
51  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
52  State Government Printing Office, Washington D.C., 1987.
53 
54 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
55  U.S. Geological Survey Professional Paper 1453 , United State Government
56  Printing Office, Washington D.C., 1989.
57 *******************************************************************************/
58 
59 /* Assign the radius value to the radius argument if a spheroid is assigned */
60 #define RADVAL 19
61 
62 #include "oli_cproj.h"
63 #include "oli_local.h"
64 
65  /* Semi-Major axis of supported Spheroids */
66 static double major[SPHDCT] = {
67  6378206.4, /* 0: Clarke 1866 (default) */
68  6378249.145, /* 1: Clarke 1880 */
69  6377397.155, /* 2: Bessel */
70  6378157.5, /* 3: International 1967 */
71  6378388.0, /* 4: International 1909 */
72  6378135.0, /* 5: WGS 72 */
73  6377276.3452, /* 6: Everest */
74  6378145.0, /* 7: WGS 66 */
75  6378137.0, /* 8: GRS 1980 */
76  6377563.396, /* 9: Airy */
77  6377304.063, /* 10: Modified Everest */
78  6377340.189, /* 11: Modified Airy */
79  6378137.0, /* 12: WGS 84 */
80  6378155.0, /* 13: Southeast Asia */
81  6378160.0, /* 14: Australian National */
82  6378245.0, /* 15: Krassovsky */
83  6378270.0, /* 16: Hough */
84  6378166.0, /* 17: Mercury 1960 */
85  6378150.0, /* 18: Modified Mercury 1968 */
86  6370997.0, /* 19: Sphere of Radius 6370997 meters*/
87  6377483.865, /* 20: Bessel 1841(Namibia) */
88  6377298.556, /* 21: Everest (Sabah & Sarawak) */
89  6377301.243, /* 22: Everest (India 1956) */
90  6377295.664, /* 23: Everest (Malaysia 1969) */
91  6377304.063, /* 24: Everest (Malay & Singapr 1948)*/
92  6377309.613, /* 25: Everest (Pakistan) */
93  6378388.0, /* 26: Hayford */
94  6378200.0, /* 27: Helmert 1906 */
95  6378160.000, /* 28: Indonesian 1974 */
96  6378160.0, /* 29: South American 1969 */
97  6378165.0, /* 30: WGS 60 */
98  6371007.181 /* 31: MODIS Sphere */
99 };
100 
101  /* Semi-Minor axis of supported Spheroids */
102 static double minor[SPHDCT] = {
103  6356583.8, /* 0: Clarke 1866 (default) */
104  6356514.86955, /* 1: Clarke 1880 */
105  6356078.96284, /* 2: Bessel */
106  6356772.2, /* 3: International 1967 */
107  6356911.94613, /* 4: International 1909 */
108  6356750.519915, /* 5: WGS 72 */
109  6356075.4133, /* 6: Everest */
110  6356759.769356, /* 7: WGS 66 */
111  6356752.31414, /* 8: GRS 1980 */
112  6356256.91, /* 9: Airy */
113  6356103.039, /* 10: Modified Everest */
114  6356034.448, /* 11: Modified Airy */
115  6356752.314245, /* 12: WGS 84 */
116  6356773.3205, /* 13: Southeast Asia */
117  6356774.719, /* 14: Australian National */
118  6356863.0188, /* 15: Krassovsky */
119  6356794.343479, /* 16: Hough */
120  6356784.283666, /* 17: Mercury 1960 */
121  6356768.337303, /* 18: Modified Mercury 1968 */
122  6370997.0, /* 19: Sphere of Radius 6370997 meters*/
123  6356165.382966, /* 20: Bessel 1841(Namibia) */
124  6356097.571445, /* 21: Everest (Sabah & Sarawak) */
125  6356100.228368, /* 22: Everest (India 1956) */
126  6356094.667915, /* 23: Everest (Malaysia 1969) */
127  6356103.038993, /* 24: Everest (Malay & Singapr 1948)*/
128  6356108.570542, /* 25: Everest (Pakistan) */
129  6356911.946128, /* 26: Hayford */
130  6356818.169, /* 27: Helmert 1906 */
131  6356774.504086, /* 28: Indonesian 1974 */
132  6356774.719, /* 29: South American 1969 */
133  6356783.287, /* 30: WGS 60 */
134  6371007.181 /* 31: MODIS Sphere */
135 };
136 
137 /* Finds the correct ellipsoid axis
138 ---------------------------------*/
139 
140 void sphdz
141 (
142  long isph, /* spheroid code number */
143  const double *parm, /* projection parameters */
144  double *r_major, /* major axis */
145  double *r_minor, /* minor axis */
146  double *radius /* radius */
147 )
148 {
149  double t_major; /* temporary major axis */
150  double t_minor; /* temporary minor axis */
151  long jsph; /* spheroid code number */
152 
153  if (isph < 0)
154  {
155  /* if the spheroid code is a negative number, get the semi-major and
156  semi-minor axis from the projection array
157  -----------------------------------------------------------------*/
158  t_major = fabs(parm[0]);
159  t_minor = fabs(parm[1]);
160 
161  if (t_major > 0.0)
162  {
163  if (t_minor > 1.0)
164  {
165  /* The semimajor axis and the semiminor axis are in the array,
166  assign them directly
167  -----------------------------------------------------------*/
168  *r_major = t_major;
169  *r_minor = t_minor;
170  *radius = t_major;
171  }
172  else if (t_minor > 0.0)
173  {
174  /* The semimajor axis and the eccentricity squared values are
175  in the array, therefore, the semiminor axis is computed
176  from the eccentricity squared value parm[1]
177  ----------------------------------------------------------*/
178  *r_major = t_major;
179  *radius = t_major;
180  *r_minor = (sqrt(1.0 - t_minor)) * t_major;
181  }
182  else
183  {
184  /* The semiminor axis is zero or less, assign the semimajor
185  axis to the semiminor axis.
186  --------------------------------------------------------*/
187  *r_major = t_major;
188  *radius = t_major;
189  *r_minor = t_major;
190  }
191  }
192  else if (t_minor > 0.0) /* t_major = 0 */
193  {
194  /* Assign Clarke 1866 semi-major and semi-minor axis
195  -------------------------------------------------*/
196  *r_major = major[0];
197  *radius = major[0];
198  *r_minor = minor[0];
199  }
200  else
201  {
202  /* Assign Spheroid radius to semi-major and semi-minor axis
203  --------------------------------------------------------*/
204  *r_major = major[RADVAL];
205  *radius = major[RADVAL];
206  *r_minor = major[RADVAL];
207  }
208  }
209  else /* isph >= 0 */
210  {
211  /* Use the spheroid code to assign the semi-major and semi-minor axis
212  -----------------------------------------------------------------*/
213  jsph = isph;
214 
215  if (jsph > (SPHDCT - 1))
216  {
217  /* The spheroid code is out of range, assign Clarke 1866
218  -----------------------------------------------------*/
219  GCTP_PRINT_ERROR("Invalid spheroid selection");
220  GCTP_PRINT_ERROR("Reset to 0");
221  jsph = 0;
222  }
223  /* Assign the radius argument to the standard radius value
224  -------------------------------------------------------*/
225  *r_major = major[jsph];
226  *r_minor = minor[jsph];
227 
228  /* for the projections that are only defined for a sphere, use sphere 19
229  unless the sphere is the MODIS sphere */
230  if (jsph != 31)
231  *radius = major[RADVAL];
232  else
233  *radius = major[jsph];
234  }
235 }
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
#define RADVAL
Definition: sphdz.c:60
void sphdz(long isph, const double *parm, double *r_major, double *r_minor, double *radius)
Definition: sphdz.c:141
#define fabs(a)
Definition: misc.h:93
void radius(double A)
Definition: proj_report.c:132
#define SPHDCT
Definition: oli_proj.h:16