OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
proj_molwinv.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME MOLLWEIDE
3 
4 PURPOSE: Transforms input Easting and Northing to longitude and
5  latitude for the Mollweide 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 D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb, 1993
12 S. Nelson, EROS Nov, 1993; fixed infinite loop at poles
13 
14 ALGORITHM REFERENCES
15 
16 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
17  U.S. Geological Survey Professional Paper 1453 , United State Government
18  Printing Office, Washington D.C., 1989.
19 
20 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
21  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
22  State Government Printing Office, Washington D.C., 1987.
23  *******************************************************************************/
24 #include "proj_cproj.h"
25 
26 /* Variables common to all subroutines in this code file
27  -----------------------------------------------------*/
28 static double lon_center; /* Center longitude (projection center) */
29 static double R; /* Radius of the earth (sphere) */
30 static double false_easting; /* x offset in meters */
31 static double false_northing; /* y offset in meters */
32 
33 /* Initialize the Mollweide projection
34  ------------------------------------*/
35 int molwinvint(r, center_long, false_east, false_north)
36 double r; /* (I) Radius of the earth (sphere) */
37 double center_long; /* (I) Center longitude */
38 double false_east; /* x offset in meters */
39 double false_north; /* y offset in meters */
40 {
41  /* Place parameters in static storage for common use
42  -------------------------------------------------*/
43  false_easting = false_east;
44  false_northing = false_north;
45  R = r;
46  lon_center = center_long;
47  return (OK);
48 }
49 
50 /* Mollweide inverse equations--mapping x,y to lat,long
51  ----------------------------------------------------*/
52 int molwinv(x, y, lon, lat)
53 double x; /* (I) X projection coordinate */
54 double y; /* (I) Y projection coordinate */
55 double *lon; /* (O) Longitude */
56 double *lat; /* (O) Latitude */
57 {
58  double adjust_lon(); /* Function to adjust longitude to -180 - 180 */
59  double theta;
60  double arg;
61 
62  /* Inverse equations
63  -----------------*/
64  x -= false_easting;
65  y -= false_northing;
66  arg = y / (1.4142135623731 * R);
67 
68  /* Because of division by zero problems, 'arg' can not be 1.0. Therefore
69  a number very close to one is used instead.
70  -------------------------------------------------------------------*/
71  if (fabs(arg) > 0.999999999999) arg = 0.999999999999;
72  theta = asin(arg);
73 
74  /*
75  *lon = adjust_lon(lon_center + (x / (0.900316316158 * R * cos(theta))));
76  */
77 
78  *lon = lon_center + (x / (0.900316316158 * R * cos(theta)));
79 
80  if ((*lon < (-PI)) || (*lon > PI))
81  return -1;
82 
83  if (*lon < (-PI)) *lon = -PI;
84  if (*lon > PI) *lon = PI;
85 
86  arg = (2.0 * theta + sin(2.0 * theta)) / PI;
87  if (fabs(arg) > 1.0)arg = 1.0;
88  *lat = asin(arg);
89  return (OK);
90 }
int r
Definition: decode_rs.h:73
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define PI
Definition: l3_get_org.c:6
#define OK
Definition: ancil.h:30
int molwinvint(double r, double center_long, double false_east, double false_north)
Definition: proj_molwinv.c:35
#define fabs(a)
Definition: misc.h:93
float * lon
#define R
Definition: make_L3_v1.1.c:96
int molwinv(double x, double y, double *lon, double *lat)
Definition: proj_molwinv.c:52