source: issm/trunk/src/c/shared/LatLong/Ll2xyx.cpp@ 16137

Last change on this file since 16137 was 16137, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 16135

File size: 3.9 KB
Line 
1/*!\file Ll2xyx.cpp
2 */
3
4#include "../../shared/shared.h"
5#include "./latlong.h"
6#include <math.h>
7
8int 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
30int 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 cde,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 /* Conversion constant from degrees to radians */
58 cde = 57.29577951;
59 /* Radius of the earth in meters */
60 re = 6378.273*1.e3;
61 /* Eccentricity of the Hughes ellipsoid squared */
62 ex2 = 0.006693883;
63 /* Eccentricity of the Hughes ellipsoid */
64 ex = sqrt(ex2);
65
66 /* loop over all the coordinate pairs */
67 for(i=0; i<ncoord; i++){
68 latitude = fabs(lat[i]) * PI/180.;
69 longitude = (lon[i] + delta) * PI/180.;
70
71 /* compute X and Y in grid coordinates. */
72 T = tan(PI/4.-latitude/2.) / pow(((1.-ex*sin(latitude))/(1.+ex*sin(latitude))),(ex/2.));
73
74 if ((90. - slat) < 1.e-5)
75 rho = 2.*re*T/sqrt(pow((1.+ex),(1.+ex))*pow((1.-ex),(1.-ex)));
76 else {
77 sl = slat*PI/180.;
78 tc = tan(PI/4.-sl/2.)/pow(((1.-ex*sin(sl))/(1.+ex*sin(sl))),(ex/2.));
79 mc = cos(sl)/sqrt(1.0-ex2*(pow(sin(sl),2)));
80 rho = re*mc*T/tc;
81 }
82
83 y[i]= -rho*(double)sgn*cos(sgn*longitude);
84 x[i]= rho*(double)sgn*sin(sgn*longitude);
85
86 if (latitude>= PI/2.){
87 x[i] = 0.0;
88 y[i] = 0.0;
89 iret=1;
90 }
91 }
92 return(iret);
93}
94
95void Ll2xydef(double* pdelta, double* pslat, int sgn){
96/* This is a cpp conversion of the following:
97%LL2XY - converts lat long to polar stereographic
98%
99% Converts from geodetic latitude and longitude to Polar
100% Stereographic (X,Y) coordinates for the polar regions.
101% Author: Michael P. Schodlok, December 2003 (map2ll)
102%
103% Usage:
104% [x,y] = ll2xy(lat,lon,sgn)
105% [x,y] = ll2xy(lat,lon,sgn,central_meridian,standard_parallel)
106%
107% - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
108% -1 : south latitude (default is mer=0 lat=71)
109*/
110 bool flag=true;
111
112 /* Get central_meridian and standard_parallel depending on hemisphere */
113 if (sgn == 1) {
114 *pdelta= 45;
115 *pslat = 70;
116 if(flag) _printf0_("Info: creating coordinates in polar stereographic (Std Latitude: 70N Meridian: 45).\n");
117 }
118 else if (sgn == -1) {
119 *pdelta= 0;
120 *pslat = 71;
121 if(flag) _printf0_("Info: creating coordinates in polar stereographic (Std Latitude: 71S Meridian: 0).\n");
122 }
123 else _error_("Sign should be either +1 or -1.\n");
124
125 return;
126}
Note: See TracBrowser for help on using the repository browser.