Ice Sheet System Model  4.18
Code documentation
Ll2xyx.cpp
Go to the documentation of this file.
1 
4 #include "../../shared/shared.h"
5 #include "./latlong.h"
6 #include <math.h>
7 
8 int Ll2xyx(double* x, double* y, double* lat, double* lon, int ncoord, int sgn){
9 /* This is a cpp conversion of the following:
10 %LL2XY - converts lat long to polar stereographic
11 %
12 % Converts from geodetic latitude and longitude to Polar
13 % Stereographic (X,Y) coordinates for the polar regions.
14 % Author: Michael P. Schodlok, December 2003 (map2ll)
15 %
16 % Usage:
17 % [x,y] = ll2xy(lat,lon,sgn)
18 % [x,y] = ll2xy(lat,lon,sgn,central_meridian,standard_parallel)
19 %
20 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
21 % -1 : south latitude (default is mer=0 lat=71)
22 */
23  double central_meridian,standard_parallel;
24 
25  Ll2xydef(&central_meridian,&standard_parallel,sgn);
26 
27  return(Ll2xyx(x,y,lat,lon,ncoord,sgn,central_meridian,standard_parallel));
28 }
29 
30 int Ll2xyx(double* x, double* y, double* lat, double* lon, int ncoord, int sgn, double central_meridian, double standard_parallel){
31 /* This is a cpp conversion of the following:
32 %LL2XY - converts lat long to polar stereographic
33 %
34 % Converts from geodetic latitude and longitude to Polar
35 % Stereographic (X,Y) coordinates for the polar regions.
36 % Author: Michael P. Schodlok, December 2003 (map2ll)
37 %
38 % Usage:
39 % [x,y] = ll2xy(lat,lon,sgn)
40 % [x,y] = ll2xy(lat,lon,sgn,central_meridian,standard_parallel)
41 %
42 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
43 % -1 : south latitude (default is mer=0 lat=71)
44 */
45 
46  int i,iret=0;
47  double delta,slat;
48  double re,ex2,ex;
49  double latitude,longitude;
50  double T,rho,sl,tc,mc;
51 
52  if((sgn!=1) && (sgn!=-1)) _error_("Sign should be either +1 or -1.\n");
53 
54  delta = central_meridian;
55  slat = standard_parallel;
56 
57  /* Radius of the earth in meters */
58  re = 6378.273*1.e3;
59  /* Eccentricity of the Hughes ellipsoid squared */
60  ex2 = 0.006693883;
61  /* Eccentricity of the Hughes ellipsoid */
62  ex = sqrt(ex2);
63 
64  /* loop over all the coordinate pairs */
65  for(i=0; i<ncoord; i++){
66  latitude = fabs(lat[i]) * PI/180.;
67  longitude = (lon[i] + delta) * PI/180.;
68 
69  /* compute X and Y in grid coordinates. */
70  T = tan(PI/4.-latitude/2.) / pow(((1.-ex*sin(latitude))/(1.+ex*sin(latitude))),(ex/2.));
71 
72  if ((90. - slat) < 1.e-5)
73  rho = 2.*re*T/sqrt(pow((1.+ex),(1.+ex))*pow((1.-ex),(1.-ex)));
74  else {
75  sl = slat*PI/180.;
76  tc = tan(PI/4.-sl/2.)/pow(((1.-ex*sin(sl))/(1.+ex*sin(sl))),(ex/2.));
77  mc = cos(sl)/sqrt(1.0-ex2*(pow(sin(sl),2)));
78  rho = re*mc*T/tc;
79  }
80 
81  y[i]= -rho*(double)sgn*cos(sgn*longitude);
82  x[i]= rho*(double)sgn*sin(sgn*longitude);
83 
84  if (latitude>= PI/2.){
85  x[i] = 0.0;
86  y[i] = 0.0;
87  iret=1;
88  }
89  }
90  return(iret);
91 }
92 
93 void Ll2xydef(double* pdelta, double* pslat, int sgn){
94 /* This is a cpp conversion of the following:
95 %LL2XY - converts lat long to polar stereographic
96 %
97 % Converts from geodetic latitude and longitude to Polar
98 % Stereographic (X,Y) coordinates for the polar regions.
99 % Author: Michael P. Schodlok, December 2003 (map2ll)
100 %
101 % Usage:
102 % [x,y] = ll2xy(lat,lon,sgn)
103 % [x,y] = ll2xy(lat,lon,sgn,central_meridian,standard_parallel)
104 %
105 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
106 % -1 : south latitude (default is mer=0 lat=71)
107 */
108  bool flag=true;
109 
110  /* Get central_meridian and standard_parallel depending on hemisphere */
111  if (sgn == 1) {
112  *pdelta= 45;
113  *pslat = 70;
114  if(flag) _printf0_("Info: creating coordinates in polar stereographic (Std Latitude: 70N Meridian: 45).\n");
115  }
116  else if (sgn == -1) {
117  *pdelta= 0;
118  *pslat = 71;
119  if(flag) _printf0_("Info: creating coordinates in polar stereographic (Std Latitude: 71S Meridian: 0).\n");
120  }
121  else _error_("Sign should be either +1 or -1.\n");
122 
123  return;
124 }
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
Ll2xydef
void Ll2xydef(double *pdelta, double *pslat, int sgn)
Definition: Ll2xyx.cpp:93
latlong.h
prototypes for latlong.h
PI
const double PI
Definition: constants.h:11
_error_
#define _error_(StreamArgs)
Definition: exceptions.h:49
Ll2xyx
int Ll2xyx(double *x, double *y, double *lat, double *lon, int ncoord, int sgn)
Definition: Ll2xyx.cpp:8