OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
alconinv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME ALASKA CONFORMAL
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Alaska Conformal projection. The
6  Easting and Northing must be in meters. The longitude
7  and latitude values will be returned in radians.
8 
9 This function was adapted from the Alaska Conformal projection code
10 (FORTRAN) in the General Cartographic Transformation Package software
11 which is available from the U.S. Geological Survey National Mapping Division.
12 
13 ALGORITHM REFERENCES
14 
15 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
16  The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
17 
18 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
19  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
20  State Government Printing Office, Washington D.C., 1987.
21 
22 3. "Software Documentation for GCTP General Cartographic Transformation
23  Package", U.S. Geological Survey National Mapping Division, May 1982.
24 *******************************************************************************/
25 #include "oli_cproj.h"
26 #include "oli_local.h"
27 
28 /* Variables common to all subroutines in this code file
29  -----------------------------------------------------*/
30 static double r_major; /* major axis */
31 static double r_minor; /* minor axis */
32 static double lon_center; /* Center longitude (projection center) */
33 static double lat_center; /* center latitude */
34 static double false_easting; /* x offset in meters */
35 static double false_northing; /* y offset in meters */
36 static double acoef[7];
37 static double bcoef[7];
38 static double sin_p26;
39 static double cos_p26;
40 static double e;
41 static long n;
42 
43 /* Initialize the ALASKA CONFORMAL projection
44  -----------------------------------------*/
45 long alconinvint
46 (
47  double r_maj, /* Major axis */
48  double r_min, /* Minor axis */
49  double false_east, /* x offset in meters */
50  double false_north /* y offset in meters */
51 )
52 {
53 double es;
54 double chi;
55 double esphi;
56 
57 /* Place parameters in static storage for common use
58  -------------------------------------------------*/
59 r_major = r_maj;
60 r_minor = r_min;
61 false_easting = false_east;
62 false_northing = false_north;
63 lon_center = -152.0 * D2R;
64 lat_center = 64.0 * D2R;
65 n = 6;
66 
67 es = .006768657997291094;
68 e = sqrt(es);
69 
70  acoef[1]= 0.9945303;
71  acoef[2]= 0.0052083;
72  acoef[3]= 0.0072721;
73  acoef[4]= -0.0151089;
74  acoef[5]= 0.0642675;
75  acoef[6]= 0.3582802;
76  bcoef[1]= 0.0;
77  bcoef[2]= -.0027404;
78  bcoef[3]= 0.0048181;
79  bcoef[4]= -0.1932526;
80  bcoef[5]= -0.1381226;
81  bcoef[6]= -0.2884586;
82 esphi = e * sin(lat_center);
83 chi = 2.0 * atan(tan((HALF_PI + lat_center)/2.0) *
84  pow(((1.0 - esphi)/(1.0 + esphi)),(e/2.0))) - HALF_PI;
85 sincos(chi,&sin_p26,&cos_p26);
86 
87 
88 /* Report parameters to the user
89  -----------------------------*/
90 gctp_print_title("ALASKA CONFORMAL");
91 gctp_print_radius2(r_major,r_minor);
92 gctp_print_cenlon(lon_center);
93 gctp_print_cenlat(lat_center);
94 gctp_print_offsetp(false_easting,false_northing);
95 return(OK);
96 }
97 
98 /* ALASKA CONFORMAL inverse equations--mapping x,y to lat/long
99  ----------------------------------------------------------*/
100 long alconinv
101 (
102  double x, /* (O) X projection coordinate */
103  double y, /* (O) Y projection coordinate */
104  double *lon, /* (I) Longitude */
105  double *lat /* (I) Latitude */
106 )
107 
108 {
109 double esphi;
110 double r;
111 double s;
112 double br;
113 double bi;
114 double ai;
115 double ar;
116 double ci;
117 double cr;
118 double di;
119 double dr;
120 double arn = 0.0;
121 double ain = 0.0;
122 double crn;
123 double cin;
124 double fxyr;
125 double fxyi;
126 double fpxyr;
127 double fpxyi;
128 double xp,yp;
129 double den;
130 double dxp;
131 double dyp;
132 double ds;
133 double z;
134 double cosz;
135 double sinz;
136 double rh;
137 double chi;
138 double dphi;
139 double phi;
140 long j;
141 long nn;
142 
143 /* Inverse equations
144  -----------------*/
145 x = (x - false_easting) / r_major;
146 y = (y - false_northing) / r_major;
147 xp = x;
148 yp = y;
149 nn = 0;
150 
151 /* Use Knuth algorithm for summing complex terms, to convert Modified-
152  Stereographic conformal to Oblique Stereographic coordinates.
153 --------------------------------------------------------------------*/
154 do
155  {
156  r = xp + xp;
157  s = xp * xp + yp * yp;
158  ar = acoef[n];
159  ai = bcoef[n];
160  br = acoef[n -1];
161  bi = bcoef[n - 1];
162  cr = (double) (n) * ar;
163  ci = (double) (n) * ai;
164  dr = (double) (n -1) * br;
165  di = (double) (n -1) * bi;
166 
167  for (j = 2; j <= n; j++)
168  {
169  arn = br + r * ar;
170  ain = bi + r * ai;
171  if (j < n)
172  {
173  br = acoef[n -j] - s * ar;
174  bi = bcoef[n - j] - s * ai;
175  ar = arn;
176  ai = ain;
177  crn = dr + r * cr;
178  cin = di + r * ci;
179  dr = (double) (n - j) * acoef[n -j] - s * cr;
180  di = (double) (n - j) * bcoef[n -j] - s * ci;
181  cr = crn;
182  ci = cin;
183  }
184  }
185  br = -s * ar;
186  bi = -s * ai;
187  ar = arn;
188  ai = ain;
189  fxyr = xp * ar - yp * ai + br - x;
190  fxyi = yp * ar + xp * ai + bi - y;
191  fpxyr = xp * cr - yp * ci + dr;
192  fpxyi = yp * cr + xp * ci + ci;
193  den = fpxyr * fpxyr + fpxyi * fpxyi;
194  dxp = -(fxyr * fpxyr + fxyi * fpxyi) / den;
195  dyp = -(fxyi * fpxyr - fxyr * fpxyi) / den;
196  xp = xp + dxp;
197  yp = yp + dyp;
198  ds = fabs(dxp) + fabs(dyp);
199  nn++;
200  if (nn > 20)
201  {
202  GCTP_PRINT_ERROR("Too many iterations in inverse");
203  return(235);
204  }
205  }
206 while (ds > EPSLN);
207 
208 /* convert Oblique Stereographic coordinates to LAT/LONG
209 ------------------------------------------------------*/
210 rh = sqrt(xp * xp + yp * yp);
211 z = 2.0 * atan(rh / 2.0);
212 sincos(z,&sinz,&cosz);
213 *lon = lon_center;
214 if (fabs(rh) <= EPSLN)
215  {
216  *lat = lat_center;
217  return(OK);
218  }
219 chi = asinz(cosz * sin_p26 + (yp * sinz * cos_p26) / rh);
220 nn = 0;
221 phi = chi;
222 do
223  {
224  esphi = e * sin(phi);
225  dphi = 2.0 * atan(tan((HALF_PI + chi) / 2.0) *
226  pow(((1.0 + esphi) / (1.0 - esphi)),(e / 2.0))) - HALF_PI - phi;
227  phi += dphi;
228  nn++;
229  if (nn > 20)
230  {
231  GCTP_PRINT_ERROR("Too many iterations in inverse");
232  return(236);
233  }
234  }
235 while(fabs(dphi) > EPSLN);
236 
237 *lat = phi;
238 *lon = adjust_lon (lon_center + atan2((xp * sinz), (rh * cos_p26 * cosz - yp *
239  sin_p26 * sinz)));
240 
241 
242 return(OK);
243 }
int r
Definition: decode_rs.h:73
int j
Definition: decode_rs.h:73
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
long alconinvint(double r_maj, double r_min, double false_east, double false_north)
Definition: alconinv.c:46
void gctp_print_cenlon(double A)
Definition: gctp_report.c:40
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define HALF_PI
Definition: proj_define.h:84
long alconinv(double x, double y, double *lon, double *lat)
Definition: alconinv.c:101
#define D2R
Definition: proj_define.h:91
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
integer, parameter double
#define sincos
Definition: proj_define.h:108
void gctp_print_radius2(double radius1, double radius2)
Definition: gctp_report.c:30
#define fabs(a)
Definition: misc.h:93
data_t den
Definition: decode_rs.h:74
float * lon
data_t s[NROOTS]
Definition: decode_rs.h:75
double asinz(double con)
Definition: proj_cproj.c:67
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57
#define EPSLN
Definition: proj_define.h:86