OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
alconfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME ALASKA CONFORMAL
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and Northing
5  for the Alaska Conformal projection. The longitude and latitude
6  must be in radians. The Easting and Northing values will
7  be returned in meters.
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 alconforint
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 
83 esphi = e * sin(lat_center);
84 chi = 2.0 * atan(tan((HALF_PI + lat_center)/2.0) *
85  pow(((1.0 - esphi)/(1.0 + esphi)),(e/2.0))) - HALF_PI;
86 sincos(chi,&sin_p26,&cos_p26);
87 
88 
89 /* Report parameters to the user
90  -----------------------------*/
91 gctp_print_title("ALASKA CONFORMAL");
92 gctp_print_radius2(r_major,r_minor);
93 gctp_print_cenlon(lon_center);
94 gctp_print_cenlat(lat_center);
95 gctp_print_offsetp(false_easting,false_northing);
96 return(OK);
97 }
98 
99 /* ALASKA CONFORMAL forward equations--mapping lat,long to x,y
100  ----------------------------------------------------------*/
101 long alconfor
102 (
103  double lon, /* (I) Longitude */
104  double lat, /* (I) Latitude */
105  double *x, /* (O) X projection coordinate */
106  double *y /* (O) Y projection coordinate */
107 )
108 
109 {
110 double dlon;
111 double sinlon,coslon;
112 double sinphi,cosphi;
113 double esphi;
114 double g;
115 double s;
116 double xp;
117 double yp;
118 double ar;
119 double ai;
120 double br;
121 double bi;
122 double arn = 0.0;
123 double ain = 0.0;
124 double chi;
125 double r;
126 long j;
127 
128 
129 /* Forward equations
130  -----------------*/
131 dlon = adjust_lon( lon - lon_center);
132 
133 /* caluclate x' and y' for Oblique Stereographic Proj for LAT/LONG
134 ----------------------------------------------------------------*/
135 sincos(dlon,&sinlon,&coslon);
136 esphi = e * sin(lat);
137 chi = 2.0 * atan(tan((HALF_PI + lat) / 2.0) *
138  pow(((1.0 - esphi) / (1.0 + esphi)),(e/2.0))) - HALF_PI;
139 sincos(chi,&sinphi,&cosphi);
140 g = sin_p26 * sinphi + cos_p26 * cosphi * coslon;
141 s = 2.0 / (1.0 + g);
142 xp = s * cosphi * sinlon;
143 yp = s * (cos_p26 * sinphi - sin_p26 * cosphi * coslon);
144 
145 /* Use Knuth algorithm for summing complex terms, to convert
146  Oblique Stereographic to Modified-Stereographic coord
147 ----------------------------------------------------------*/
148 r = xp + xp;
149 s = xp*xp + yp*yp;
150 ar = acoef[n];
151 ai = bcoef[n];
152 br = acoef[n -1];
153 bi = bcoef[n -1];
154 for (j =2; j <= n; j++)
155  {
156  arn = br + r * ar;
157  ain = bi + r * ai;
158  if (j < n)
159  {
160  br = acoef[n - j] - s * ar;
161  bi = bcoef[n - j] - s * ai;
162  ar = arn;
163  ai = ain;
164  }
165  }
166 br = -s * ar;
167 bi = -s * ai;
168 ar = arn;
169 ai = ain;
170 *x = (xp * ar - yp * ai + br) * r_major + false_easting;
171 *y = (yp * ar + xp * ai + bi) * r_major + false_northing;
172 
173 return(OK);
174 }
long alconfor(double lon, double lat, double *x, double *y)
Definition: alconfor.c:102
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
void gctp_print_cenlon(double A)
Definition: gctp_report.c:40
float * lat
long alconforint(double r_maj, double r_min, double false_east, double false_north)
Definition: alconfor.c:46
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define HALF_PI
Definition: proj_define.h:84
#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
#define sincos
Definition: proj_define.h:108
void gctp_print_radius2(double radius1, double radius2)
Definition: gctp_report.c:30
float * lon
data_t s[NROOTS]
Definition: decode_rs.h:75
void gctp_print_cenlat(double A)
Definition: gctp_report.c:57