OB.DAAC Logo
NASA Logo
Ocean Color Science Software

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