OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
molwfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME MOLLWEIDE
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the MOllweide projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
8 
9 ALGORITHM REFERENCES
10 
11 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
12  U.S. Geological Survey Professional Paper 1453 , United State Government
13  Printing Office, Washington D.C., 1989.
14 
15 2. 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 #include "oli_cproj.h"
20 #include "oli_local.h"
21 
22 /* Variables common to all subroutines in this code file
23  -----------------------------------------------------*/
24 static double lon_center; /* Center longitude (projection center) */
25 static double R; /* Radius of the earth (sphere) */
26 static double false_easting; /* x offset in meters */
27 static double false_northing; /* y offset in meters */
28 
29 /* Initialize the Mollweide projection
30  ------------------------------------*/
31 long molwforint
32 (
33  double r, /* (I) Radius of the earth (sphere) */
34  double center_long, /* (I) Center longitude */
35  double false_east, /* x offset in meters */
36  double false_north /* y offset in meters */
37 )
38 {
39 /* Place parameters in static storage for common use
40  -------------------------------------------------*/
41 false_easting = false_east;
42 false_northing = false_north;
43 R = r;
44 lon_center = center_long;
45 
46 /* Report parameters to the user
47  -----------------------------*/
48 gctp_print_title("MOLLWEIDE");
50 gctp_print_cenlon(center_long);
52 return(OK);
53 }
54 
55 /* Mollweide forward equations--mapping lat,long to x,y
56  ----------------------------------------------------*/
57 long molwfor
58 (
59  double lon, /* (I) Longitude */
60  double lat, /* (I) Latitude */
61  double *x, /* (O) X projection coordinate */
62  double *y /* (O) Y projection coordinate */
63 )
64 {
65 double delta_lon; /* Delta longitude (Given longitude - center */
66 double theta;
67 double delta_theta;
68 double con;
69 long i;
70 
71 /* Forward equations
72  -----------------*/
73 delta_lon = adjust_lon(lon - lon_center);
74 theta = lat;
75 con = PI * sin(lat);
76 
77 /* Iterate using the Newton-Raphson method to find theta
78  -----------------------------------------------------*/
79 for (i=0;;i++)
80  {
81  delta_theta = -(theta + sin(theta) - con)/ (1.0 + cos(theta));
82  theta += delta_theta;
83  if (fabs(delta_theta) < EPSLN) break;
84  if (i >= 50)
85  {
86  GCTP_PRINT_ERROR("Iteration failed to converge");
87  return(241);
88  }
89  }
90 theta /= 2.0;
91 
92 /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
93  this is done here because of precision problems with "cos(theta)"
94  --------------------------------------------------------------------------*/
95 if (PI/2 - fabs(lat) < EPSLN)
96  delta_lon =0;
97 *x = 0.900316316158 * R * delta_lon * cos(theta) + false_easting;
98 *y = 1.4142135623731 * R * sin(theta) + false_northing;
99 return(OK);
100 }
int r
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
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
long molwfor(double lon, double lat, double *x, double *y)
Definition: molwfor.c:58
float * lat
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define PI
Definition: l3_get_org.c:6
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
long molwforint(double r, double center_long, double false_east, double false_north)
Definition: molwfor.c:32
#define fabs(a)
Definition: misc.h:93
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define R
Definition: make_L3_v1.1.c:96
int i
Definition: decode_rs.h:71
#define EPSLN
Definition: proj_define.h:86