OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
proj_robfor.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME ROBINSON
3 
4 PURPOSE: Transforms input longitude and latitude to Easting and
5  Northing for the Robinson projection. The
6  longitude and latitude must be in radians. The Easting
7  and Northing values will be returned in meters.
8 
9 PROGRAMMER DATE
10 ---------- ----
11 T. Mittan March, 1993
12 
13 This function was adapted from the Lambert Azimuthal Equal Area projection
14 code (FORTRAN) in the General Cartographic Transformation Package software
15 which is available from the U.S. Geological Survey National Mapping Division.
16 
17 ALGORITHM REFERENCES
18 
19 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
20  The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
21 
22 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
23  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
24  State Government Printing Office, Washington D.C., 1987.
25 
26 3. "Software Documentation for GCTP General Cartographic Transformation
27  Package", U.S. Geological Survey National Mapping Division, May 1982.
28  *******************************************************************************/
29 #include "proj_cproj.h"
30 #include <stdint.h>
31 
32 /* Variables common to all subroutines in this code file
33  -----------------------------------------------------*/
34 static double lon_center; /* Center longitude (projection center) */
35 static double R; /* Radius of the earth (sphere) */
36 static double false_easting; /* x offset in meters */
37 static double false_northing; /* y offset in meters */
38 static double pr[21];
39 static double xlr[21];
40 
41 /* Initialize the ROBINSON projection
42  ---------------------------------*/
43 int robforint(r, center_long, false_east, false_north)
44 
45 double r; /* (I) Radius of the earth (sphere) */
46 double center_long; /* (I) Center longitude */
47 double false_east; /* x offset in meters */
48 double false_north; /* y offset in meters */
49 {
50  int32_t i;
51 
52  /* Place parameters in static storage for common use
53  -------------------------------------------------*/
54  R = r;
55  lon_center = center_long;
56  false_easting = false_east;
57  false_northing = false_north;
58 
59  pr[1] = -0.062;
60  xlr[1] = 0.9986;
61  pr[2] = 0.0;
62  xlr[2] = 1.0;
63  pr[3] = 0.062;
64  xlr[3] = 0.9986;
65  pr[4] = 0.124;
66  xlr[4] = 0.9954;
67  pr[5] = 0.186;
68  xlr[5] = 0.99;
69  pr[6] = 0.248;
70  xlr[6] = 0.9822;
71  pr[7] = 0.31;
72  xlr[7] = 0.973;
73  pr[8] = 0.372;
74  xlr[8] = 0.96;
75  pr[9] = 0.434;
76  xlr[9] = 0.9427;
77  pr[10] = 0.4958;
78  xlr[10] = 0.9216;
79  pr[11] = 0.5571;
80  xlr[11] = 0.8962;
81  pr[12] = 0.6176;
82  xlr[12] = 0.8679;
83  pr[13] = 0.6769;
84  xlr[13] = 0.835;
85  pr[14] = 0.7346;
86  xlr[14] = 0.7986;
87  pr[15] = 0.7903;
88  xlr[15] = 0.7597;
89  pr[16] = 0.8435;
90  xlr[16] = 0.7186;
91  pr[17] = 0.8936;
92  xlr[17] = 0.6732;
93  pr[18] = 0.9394;
94  xlr[18] = 0.6213;
95  pr[19] = 0.9761;
96  xlr[19] = 0.5722;
97  pr[20] = 1.0;
98  xlr[20] = 0.5322;
99 
100  for (i = 0; i < 21; i++)
101  xlr[i] *= 0.9858;
102 
103  return (OK);
104 }
105 
106 /* Robinson forward equations--mapping lat,long to x,y
107  ------------------------------------------------------------*/
108 int robfor(lon, lat, x, y)
109 double lon; /* (I) Longitude */
110 double lat; /* (I) Latitude */
111 double *x; /* (O) X projection coordinate */
112 double *y; /* (O) Y projection coordinate */
113 
114 {
115  double dlon;
116  double adjust_lon();
117  double p2;
118  int32_t ip1;
119 
120  /* Forward equations
121  -----------------*/
122  dlon = adjust_lon(lon - lon_center);
123  p2 = fabs(lat / 5.0 / .01745329252);
124  ip1 = (int32_t) (p2 - EPSLN);
125 
126  /* Stirling's interpolation formula (using 2nd Diff.)
127  ---------------------------------------------------*/
128  p2 -= (double) ip1;
129  *x = R * (xlr[ip1 + 2] + p2 * (xlr[ip1 + 3] - xlr[ip1 + 1]) / 2.0 +
130  p2 * p2 * (xlr[ip1 + 3] - 2.0 * xlr[ip1 + 2] + xlr[ip1 + 1]) / 2.0) *
131  dlon + false_easting;
132 
133  if (lat >= 0)
134  *y = R * (pr[ip1 + 2] + p2 * (pr[ip1 + 3] - pr[ip1 + 1]) / 2.0 + p2 * p2 *
135  (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1]) / 2.0) * PI / 2.0 +
136  false_northing;
137  else
138  *y = -R * (pr[ip1 + 2] + p2 * (pr[ip1 + 3] - pr[ip1 + 1]) / 2.0 + p2 * p2 *
139  (pr[ip1 + 3] - 2.0 * pr[ip1 + 2] + pr[ip1 + 1]) / 2.0) * PI / 2.0 +
140  false_northing;
141 
142  return (OK);
143 }
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
integer, parameter double
#define fabs(a)
Definition: misc.h:93
int robforint(double r, double center_long, double false_east, double false_north)
Definition: proj_robfor.c:43
int robfor(double lon, double lat, double *x, double *y)
Definition: proj_robfor.c:108
float * lon
#define R
Definition: make_L3_v1.1.c:96
int i
Definition: decode_rs.h:71
#define EPSLN
Definition: proj_define.h:86