OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
eqconinv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME EQUIDISTANT CONIC
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Equidistant Conic projection. The
6  Easting and Northing must be in meters. The longitude
7  and latitude values will be returned in radians.
8 
9 ALGORITHM REFERENCES
10 
11 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
12  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
13  State Government Printing Office, Washington D.C., 1987.
14 
15 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
16  U.S. Geological Survey Professional Paper 1453 , United State Government
17  Printing Office, Washington D.C., 1989.
18 *******************************************************************************/
19 #include "oli_cproj.h"
20 #include "oli_local.h"
21 
22 /* Variables common to all subroutines in this code file
23  -----------------------------------------------------*/
24 static double r_major; /* major axis */
25 static double r_minor; /* minor axis */
26 static double lon_center; /* Center longitude (projection center) */
27 static double e0,e1,e2,e3; /* eccentricity constants */
28 static double e,es; /* eccentricity constants */
29 static double ml0; /* small value m */
30 static double false_northing; /* y offset in meters */
31 static double false_easting; /* x offset in meters */
32 static double ns;
33 static double g;
34 static double rh;
35 
36 
37 /* Initialize the Equidistant Conic projection
38  ------------------------------------------*/
39 long eqconinvint
40 (
41  double r_maj, /* major axis */
42  double r_min, /* minor axis */
43  double lat1, /* latitude of standard parallel*/
44  double lat2, /* latitude of standard parallel*/
45  double center_lon, /* center longitude */
46  double center_lat, /* center latitude */
47  double false_east, /* x offset in meters */
48  double false_north, /* y offset in meters */
49  long mode /* which format is present A B */
50 )
51 {
52 double temp; /* temporary variable */
53 double sinphi,cosphi; /* sin and cos values */
54 double ms1,ms2;
55 double ml1,ml2;
56 
57 /* Place parameters in static storage for common use
58  -------------------------------------------------*/
59 r_major = r_maj;
60 r_minor = r_min;
61 lon_center = center_lon;
62 false_northing = false_north;
63 false_easting = false_east;
64 
65 temp = r_minor / r_major;
66 es = 1.0 - SQUARE(temp);
67 e = sqrt(es);
68 e0 = gctp_calc_e0(es);
69 e1 = gctp_calc_e1(es);
70 e2 = gctp_calc_e2(es);
71 e3 = gctp_calc_e3(es);
72 
73 sincos(lat1,&sinphi,&cosphi);
74 ms1 = gctp_calc_small_radius(e,sinphi,cosphi);
75 ml1 = gctp_calc_dist_from_equator(e0, e1, e2, e3, lat1);
76 
77 /* format B
78 ---------*/
79 if (mode != 0)
80  {
81  if (fabs(lat1 + lat2) < EPSLN)
82  {
83  GCTP_PRINT_ERROR("Standard Parallels on opposite sides of equator");
84  return(81);
85  }
86  sincos(lat2,&sinphi,&cosphi);
87  ms2 = gctp_calc_small_radius(e,sinphi,cosphi);
88  ml2 = gctp_calc_dist_from_equator(e0, e1, e2, e3, lat2);
89  if (fabs(lat1 - lat2) >= EPSLN)
90  ns = (ms1 - ms2) / (ml2 - ml1);
91  else
92  ns = sinphi;
93  }
94 else
95  ns = sinphi;
96 g = ml1 + ms1/ns;
97 ml0 = gctp_calc_dist_from_equator(e0, e1, e2, e3, center_lat);
98 rh = r_major * (g - ml0);
99 
100 
101 /* Report parameters to the user
102  -----------------------------*/
103 if (mode != 0)
104  {
105  gctp_print_title("EQUIDISTANT CONIC");
106  gctp_print_radius2(r_major, r_minor);
107  gctp_print_stanparl(lat1,lat2);
108  gctp_print_cenlonmer(lon_center);
109  gctp_print_origin(center_lat);
110  gctp_print_offsetp(false_easting,false_northing);
111  }
112 else
113  {
114  gctp_print_title("EQUIDISTANT CONIC");
115  gctp_print_radius2(r_major, r_minor);
116  gctp_print_stparl1(lat1);
117  gctp_print_cenlonmer(lon_center);
118  gctp_print_origin(center_lat);
119  gctp_print_offsetp(false_easting,false_northing);
120  }
121 
122 return(OK);
123 }
124 
125 
126 /* Equidistant Conic inverse equations--mapping x,y to lat/long
127  -----------------------------------------------------------*/
128 long eqconinv
129 (
130  double x, /* (O) X projection coordinate */
131  double y, /* (O) Y projection coordinate */
132  double *lon, /* (I) Longitude */
133  double *lat /* (I) Latitude */
134 )
135 {
136 
137 double rh1;
138 double ml;
139 double con;
140 double theta;
141 long flag;
142 
143 /* Inverse equations
144  -----------------*/
145 flag = 0;
146 x -= false_easting;
147 y = rh - y + false_northing;
148 if (ns >= 0)
149  {
150  rh1 = sqrt(x * x + y * y);
151  con = 1.0;
152  }
153 else
154  {
155  rh1 = -sqrt(x * x + y * y);
156  con = -1.0;
157  }
158 theta = 0.0;
159 if (rh1 != 0.0)
160  theta = atan2(con * x, con * y);
161 ml = g - rh1 / r_major;
162 *lat = phi3z(ml,e0,e1,e2,e3,&flag);
163 *lon = adjust_lon(lon_center + theta / ns);
164 
165 if (flag != 0)
166  return(flag);
167 else
168  return(OK);
169 }
#define SQUARE(x)
Definition: proj_define.h:99
void gctp_print_origin(double A)
Definition: gctp_report.c:65
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
double gctp_calc_e2(double x)
Definition: gctp_utility.c:139
README for MOD_PR02AQUA(AQUA) Version to set to For disabling creating and output data sets when in night mode
Definition: README.txt:96
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
void gctp_print_stparl1(double A)
Definition: gctp_report.c:83
double adjust_lon(double x)
Definition: proj_cproj.c:349
long eqconinv(double x, double y, double *lon, double *lat)
Definition: eqconinv.c:129
void gctp_print_stanparl(double A, double B)
Definition: gctp_report.c:73
double gctp_calc_e0(double x)
Definition: gctp_utility.c:125
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
double gctp_calc_e3(double x)
Definition: gctp_utility.c:146
double gctp_calc_e1(double x)
Definition: gctp_utility.c:132
#define sincos
Definition: proj_define.h:108
void gctp_print_radius2(double radius1, double radius2)
Definition: gctp_report.c:30
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
double phi3z(double ml, double e0, double e1, double e2, double e3, int32_t *flag)
Definition: proj_cproj.c:186
double gctp_calc_small_radius(double eccent, double sinphi, double cosphi)
Definition: gctp_utility.c:253
#define fabs(a)
Definition: misc.h:93
float * lon
long eqconinvint(double r_maj, double r_min, double lat1, double lat2, double center_lon, double center_lat, double false_east, double false_north, long mode)
Definition: eqconinv.c:40
double gctp_calc_dist_from_equator(double e0, double e1, double e2, double e3, double phi)
Definition: gctp_utility.c:187
#define EPSLN
Definition: proj_define.h:86