Debian Codegraph @

gctp/src/psinv.c

raw
1 /*******************************************************************************
2 NAME POLAR STEREOGRAPHIC
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Polar Stereographic projection. The
6 Easting and Northing must be in meters. The longitude
7 and latitude values will be returned in radians.
8
9 PROGRAMMER DATE
10 ---------- ----
11 T. Mittan 2-26-93
12
13 ALGORITHM REFERENCES
14
15 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
16 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
17 State Government Printing Office, Washington D.C., 1987.
18
19 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
20 U.S. Geological Survey Professional Paper 1453 , United State Government
21 Printing Office, Washington D.C., 1989.
22 *******************************************************************************/
23 #include <stdio.h>
24 #include "cproj.h"
25
26 /* Variables common to all subroutines in this code file
27 -----------------------------------------------------*/
28 static double r_major; /* major axis */
29 static double r_minor; /* minor axis */
30 static double e; /* eccentricity */
31 static double e4; /* e4 calculated from eccentricity*/
32 static double center_lon; /* center longitude */
33 static double center_lat; /* center latitude */
34 static double fac; /* sign variable */
35 static double ind; /* flag variable */
36 static double mcs; /* small value m */
37 static double tcs; /* small value t */
38 static double false_northing; /* y offset in meters */
39 static double false_easting; /* x offset in meters */
40
41 /* Initialize the Polar Stereographic projection
42 --------------------------------------------*/
43 int psinvint(
44 double r_maj, /* major axis */
45 double r_min, /* minor axis */
46 double c_lon, /* center longitude */
47 double c_lat, /* center latitude */
48 double false_east, /* x offset in meters */
49 double false_north) /* y offset in meters */
50
51 {
52 double temp; /* temporary variable */
53 double con1; /* temporary angle */
54 double sinphi; /* sin value */
55 double cosphi; /* cos value */
56 double es; /* eccentricity squared */
57
58 r_major = r_maj;
59 r_minor = r_min;
60 false_easting = false_east;
61 false_northing = false_north;
62 temp = r_minor / r_major;
63 es = 1.0 - SQUARE(temp);
64 e = sqrt(es);
65 e4 = e4fn(e);
66 center_lon = c_lon;
67 center_lat = c_lat;
68
69 if (c_lat < 0)
70 fac = -1.0;
71 else
72 fac = 1.0;
73 ind = 0;
74 if (fabs(fabs(c_lat) - HALF_PI) > EPSLN)
75 {
76 ind = 1;
77 con1 = fac * center_lat;
78 tsincos(con1,&sinphi,&cosphi);
79 mcs = msfnz(e,sinphi,cosphi);
80 tcs = tsfnz(e,con1,sinphi);
81 }
82 /* Report parameters to the user
83 -----------------------------*/
84 ptitle("POLAR STEREOGRAPHIC");
85 radius2(r_major, r_minor);
86 cenlon(center_lon);
87 offsetp(false_east,false_north);
88
89 return(OK);
90 }
91
92 /* Polar Stereographic inverse equations--mapping x,y to lat/long
93 --------------------------------------------------------------*/
94 int psinv(
95 double x, /* (O) X projection coordinate */
96 double y, /* (O) Y projection coordinate */
97 double *lon, /* (I) Longitude */
98 double *lat) /* (I) Latitude */
99
100 {
101 double rh; /* height above ellipsiod */
102 double ts; /* small value t */
103 double temp; /* temporary variable */
104 long flag; /* error flag */
105
106 flag = 0;
107 x = (x - false_easting) * fac;
108 y = (y - false_northing) *fac;
109 rh = sqrt(x * x + y * y);
110 if (ind != 0)
111 ts = rh * tcs/(r_major * mcs);
112 else
113 ts = rh * e4 / (r_major * 2.0);
114 *lat = fac * phi2z(e,ts,&flag);
115 if (flag != 0)
116 return(flag);
117 if (rh == 0)
118 *lon = fac * center_lon;
119 else
120 {
121 temp = atan2(x, -y);
122 *lon = adjust_lon(fac *temp + center_lon);
123 }
124
125 return(OK);
126 }