Ice Sheet System Model  4.18
Code documentation
Functions
latlong.h File Reference

prototypes for latlong.h More...

Go to the source code of this file.

Functions

int Ll2xyx (double *x, double *y, double *lat, double *lon, int ncoord, int sgn)
 
int Ll2xyx (double *x, double *y, double *lat, double *lon, int ncoord, int sgn, double central_meridian, double standard_parallel)
 
void Ll2xydef (double *pdelta, double *pslat, int sgn)
 
int Xy2llx (double *lat, double *lon, double *x, double *y, int ncoord, int sgn)
 
int Xy2llx (double *lat, double *lon, double *x, double *y, int ncoord, int sgn, double central_meridian, double standard_parallel)
 
void Xy2lldef (double *pdelta, double *pslat, int sgn)
 

Detailed Description

prototypes for latlong.h

Definition in file latlong.h.

Function Documentation

◆ Ll2xyx() [1/2]

int Ll2xyx ( double *  x,
double *  y,
double *  lat,
double *  lon,
int  ncoord,
int  sgn 
)

Definition at line 8 of file Ll2xyx.cpp.

8  {
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 }

◆ Ll2xyx() [2/2]

int Ll2xyx ( double *  x,
double *  y,
double *  lat,
double *  lon,
int  ncoord,
int  sgn,
double  central_meridian,
double  standard_parallel 
)

Definition at line 30 of file Ll2xyx.cpp.

30  {
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 }

◆ Ll2xydef()

void Ll2xydef ( double *  pdelta,
double *  pslat,
int  sgn 
)

Definition at line 93 of file Ll2xyx.cpp.

93  {
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 }

◆ Xy2llx() [1/2]

int Xy2llx ( double *  lat,
double *  lon,
double *  x,
double *  y,
int  ncoord,
int  sgn 
)

Definition at line 8 of file Xy2llx.cpp.

8  {
9 /* This is a cpp conversion of the following:
10 %XY2LL - converts xy to lat long
11 %
12 % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
13 % latitude and longitude Stereographic (X,Y) coordinates for the polar
14 % regions.
15 % Author: Michael P. Schodlok, December 2003 (map2xy.m)
16 %
17 % Usage:
18 % [lat,lon] = xy2ll(x,y,sgn);
19 % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
20 %
21 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
22 % -1 : south latitude (default is mer=0 lat=71)
23 */
24  double central_meridian,standard_parallel;
25 
26  Xy2lldef(&central_meridian,&standard_parallel,sgn);
27 
28  return(Xy2llx(lat,lon,x,y,ncoord,sgn,central_meridian,standard_parallel));
29 }

◆ Xy2llx() [2/2]

int Xy2llx ( double *  lat,
double *  lon,
double *  x,
double *  y,
int  ncoord,
int  sgn,
double  central_meridian,
double  standard_parallel 
)

Definition at line 31 of file Xy2llx.cpp.

31  {
32 /* This is a cpp conversion of the following:
33 %XY2LL - converts xy to lat long
34 %
35 % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
36 % latitude and longitude Stereographic (X,Y) coordinates for the polar
37 % regions.
38 % Author: Michael P. Schodlok, December 2003 (map2xy.m)
39 %
40 % Usage:
41 % [lat,lon] = xy2ll(x,y,sgn);
42 % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
43 %
44 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
45 % -1 : south latitude (default is mer=0 lat=71)
46 */
47 
48  int i,iret=0;
49  double delta,slat;
50  double re,ex2,ex;
51  double sl,rho,cm,T,chi;
52 
53  if((sgn!=1) && (sgn!=-1)) _error_("Sign should be either +1 or -1.\n");
54 
55  delta = central_meridian;
56  slat = standard_parallel;
57 
58  /* Radius of the earth in meters */
59  re = 6378.273e+3;
60  /* Eccentricity of the Hughes ellipsoid squared */
61  ex2 = 0.006693883;
62  /* Eccentricity of the Hughes ellipsoid */
63  ex = sqrt(ex2);
64 
65  /* loop over all the coordinate pairs */
66  for(i=0; i<ncoord; i++){
67  sl = slat*PI/180.;
68  cm = cos(sl)/sqrt(1.0-ex2*(pow(sin(sl),2)));
69  rho= sqrt(pow(x[i],2) + pow(y[i],2));
70  T = tan((PI/4.0) - (sl/2.0))/pow(((1.0-ex*sin(sl))/(1.0+ex*sin(sl))),(ex/2.0));
71 
72  if(fabs(slat-90.) < 1.e-5)
73  T =rho*sqrt(pow((1.+ex),(1.+ex))*pow((1.-ex),(1.-ex)))/2./re;
74  else
75  T =rho*T/(re*cm);
76 
77  chi = (PI / 2.0) - 2.0 * atan(T);
78  lat[i] = chi + ((ex2 / 2.0) + (5.0 * pow(ex2,2.0) / 24.0) + (pow(ex2,3.0) / 12.0)) *
79  sin(2.0 * chi) + ((7.0 * pow(ex2,2.0) / 48.0) + (29.0 * pow(ex2,3.0) / 240.0)) *
80  sin(4.0 * chi) + (7.0 * pow(ex2,3.0) / 120.0) * sin(6.0 * chi) ;
81 
82  lat[i] = (double)sgn * lat[i];
83  lon[i] = atan2((double)sgn * x[i],-(double)sgn * y[i]);
84  lon[i] = (double)sgn * lon[i];
85 
86  if(rho <= 0.1){
87  lat[i] = 90. * (double)sgn;
88  lon[i] = 0.0;
89  iret=1;
90  }
91 
92  lon[i] = lon[i] * 180. / PI;
93  lat[i] = lat[i] * 180. / PI;
94  lon[i] = lon[i] - delta;
95  }
96 
97  return(iret);
98 }

◆ Xy2lldef()

void Xy2lldef ( double *  pdelta,
double *  pslat,
int  sgn 
)

Definition at line 100 of file Xy2llx.cpp.

100  {
101 /* This is a cpp conversion of the following:
102 %XY2LL - converts xy to lat long
103 %
104 % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
105 % latitude and longitude Stereographic (X,Y) coordinates for the polar
106 % regions.
107 % Author: Michael P. Schodlok, December 2003 (map2xy.m)
108 %
109 % Usage:
110 % [lat,lon] = xy2ll(x,y,sgn);
111 % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
112 %
113 % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
114 % -1 : south latitude (default is mer=0 lat=71)
115 */
116  bool flag=true;
117 
118  /* Get central_meridian and standard_parallel depending on hemisphere */
119  if (sgn == 1) {
120  *pdelta= 45;
121  *pslat = 70;
122  if(flag) _printf0_("Warning: expecting coordinates in polar stereographic (Std Latitude: 70N Meridian: 45).\n");
123  }
124  else if (sgn == -1) {
125  *pdelta= 0;
126  *pslat = 71;
127  if(flag) _printf0_("Warning: expecting coordinates in polar stereographic (Std Latitude: 71S Meridian: 0).\n");
128  }
129  else _error_("Sign should be either +1 or -1.\n");
130 
131  return;
132 }
_printf0_
#define _printf0_(StreamArgs)
Definition: Print.h:29
Xy2lldef
void Xy2lldef(double *pdelta, double *pslat, int sgn)
Definition: Xy2llx.cpp:100
Xy2llx
int Xy2llx(double *lat, double *lon, double *x, double *y, int ncoord, int sgn)
Definition: Xy2llx.cpp:8
Ll2xydef
void Ll2xydef(double *pdelta, double *pslat, int sgn)
Definition: Ll2xyx.cpp:93
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