[8673] | 1 | /*!\file Xy2llx.cpp
|
---|
| 2 | */
|
---|
| 3 |
|
---|
| 4 | #include "./Xy2llx.h"
|
---|
[8698] | 5 | #include "../../include/include.h"
|
---|
[8673] | 6 | #include "../../shared/shared.h"
|
---|
[8698] | 7 | #include <math.h>
|
---|
[8673] | 8 |
|
---|
[8698] | 9 | int Xy2llx(double* lat, double* lon, double* x, double* y, int ncoord, int sgn){
|
---|
[8673] | 10 | /* This is a cpp conversion of the following:
|
---|
| 11 | %XY2LL - converts xy to lat long
|
---|
| 12 | %
|
---|
| 13 | % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
|
---|
| 14 | % latitude and longitude Stereographic (X,Y) coordinates for the polar
|
---|
| 15 | % regions.
|
---|
| 16 | % Author: Michael P. Schodlok, December 2003 (map2xy.m)
|
---|
| 17 | %
|
---|
| 18 | % Usage:
|
---|
| 19 | % [lat,lon] = xy2ll(x,y,sgn);
|
---|
| 20 | % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
|
---|
| 21 | %
|
---|
| 22 | % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
|
---|
| 23 | % -1 : south latitude (default is mer=0 lat=71)
|
---|
| 24 | */
|
---|
[8715] | 25 | double central_meridian,standard_parallel;
|
---|
[8673] | 26 |
|
---|
[8715] | 27 | Xy2lldef(¢ral_meridian,&standard_parallel,sgn);
|
---|
[8673] | 28 |
|
---|
[8715] | 29 | return(Xy2llx(lat,lon,x,y,ncoord,sgn,central_meridian,standard_parallel));
|
---|
[8673] | 30 | }
|
---|
| 31 |
|
---|
[8698] | 32 | int Xy2llx(double* lat, double* lon, double* x, double* y, int ncoord, int sgn, double central_meridian, double standard_parallel){
|
---|
[8673] | 33 | /* This is a cpp conversion of the following:
|
---|
| 34 | %XY2LL - converts xy to lat long
|
---|
| 35 | %
|
---|
| 36 | % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
|
---|
| 37 | % latitude and longitude Stereographic (X,Y) coordinates for the polar
|
---|
| 38 | % regions.
|
---|
| 39 | % Author: Michael P. Schodlok, December 2003 (map2xy.m)
|
---|
| 40 | %
|
---|
| 41 | % Usage:
|
---|
| 42 | % [lat,lon] = xy2ll(x,y,sgn);
|
---|
| 43 | % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
|
---|
| 44 | %
|
---|
| 45 | % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
|
---|
| 46 | % -1 : south latitude (default is mer=0 lat=71)
|
---|
| 47 | */
|
---|
| 48 |
|
---|
[8689] | 49 | int i,iret=0;
|
---|
[8673] | 50 | double delta,slat;
|
---|
[8715] | 51 | double cde,re,ex2,ex;
|
---|
[8673] | 52 | double sl,rho,cm,T,chi;
|
---|
| 53 |
|
---|
[8698] | 54 | if((sgn!=1) && (sgn!=-1)) _error_("Sign should be either +1 or -1.\n");
|
---|
[8673] | 55 |
|
---|
| 56 | delta = central_meridian;
|
---|
| 57 | slat = standard_parallel;
|
---|
| 58 |
|
---|
| 59 | /* Conversion constant from degrees to radians */
|
---|
| 60 | cde = 57.29577951;
|
---|
| 61 | /* Radius of the earth in meters */
|
---|
| 62 | re = 6378.273*pow(10.,3.);
|
---|
| 63 | /* Eccentricity of the Hughes ellipsoid squared */
|
---|
[8698] | 64 | ex2 = 0.006693883;
|
---|
[8673] | 65 | /* Eccentricity of the Hughes ellipsoid */
|
---|
[8698] | 66 | ex = sqrt(ex2);
|
---|
[8673] | 67 |
|
---|
| 68 | /* loop over all the coordinate pairs */
|
---|
[8698] | 69 | for(i=0; i<ncoord; i++){
|
---|
| 70 | sl = slat*PI/180.;
|
---|
| 71 | cm = cos(sl)/sqrt(1.0-ex2*(pow(sin(sl),2.)));
|
---|
| 72 | rho= sqrt(pow(x[i],2.) + pow(y[i],2.));
|
---|
| 73 | T = tan((PI/4.0) - (sl/2.0))/pow(((1.0-ex*sin(sl))/(1.0+ex*sin(sl))),(ex/2.0));
|
---|
[8673] | 74 |
|
---|
[8698] | 75 | if(fabs(slat-90.) < 1.e-5)
|
---|
| 76 | T =rho*sqrt(pow((1.+ex),(1.+ex))*pow((1.-ex),(1.-ex)))/2./re;
|
---|
[8673] | 77 | else
|
---|
[8698] | 78 | T =rho*T/(re*cm);
|
---|
[8673] | 79 |
|
---|
[8698] | 80 | chi = (PI / 2.0) - 2.0 * atan(T);
|
---|
[8673] | 81 | lat[i] = chi + ((ex2 / 2.0) + (5.0 * pow(ex2,2.0) / 24.0) + (pow(ex2,3.0) / 12.0)) *
|
---|
| 82 | sin(2.0 * chi) + ((7.0 * pow(ex2,2.0) / 48.0) + (29.0 * pow(ex2,3.0) / 240.0)) *
|
---|
| 83 | sin(4.0 * chi) + (7.0 * pow(ex2,3.0) / 120.0) * sin(6.0 * chi) ;
|
---|
| 84 |
|
---|
| 85 | lat[i] = (double)sgn * lat[i];
|
---|
| 86 | lon[i] = atan2((double)sgn * x[i],-(double)sgn * y[i]);
|
---|
| 87 | lon[i] = (double)sgn * lon[i];
|
---|
| 88 |
|
---|
[8698] | 89 | if(rho <= 0.1){
|
---|
[8673] | 90 | lat[i] = 90. * (double)sgn;
|
---|
| 91 | lon[i] = 0.0;
|
---|
[8689] | 92 | iret=1;
|
---|
[8673] | 93 | }
|
---|
| 94 |
|
---|
[8715] | 95 | lon[i] = lon[i] * 180. / PI;
|
---|
| 96 | lat[i] = lat[i] * 180. / PI;
|
---|
[8673] | 97 | lon[i] = lon[i] - delta;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[8689] | 100 | return(iret);
|
---|
[8673] | 101 | }
|
---|
[8715] | 102 |
|
---|
| 103 | void Xy2lldef(double* pdelta, double* pslat, int sgn){
|
---|
| 104 | /* This is a cpp conversion of the following:
|
---|
| 105 | %XY2LL - converts xy to lat long
|
---|
| 106 | %
|
---|
| 107 | % Converts Polar Stereographic (X,Y) coordinates for the polar regions to
|
---|
| 108 | % latitude and longitude Stereographic (X,Y) coordinates for the polar
|
---|
| 109 | % regions.
|
---|
| 110 | % Author: Michael P. Schodlok, December 2003 (map2xy.m)
|
---|
| 111 | %
|
---|
| 112 | % Usage:
|
---|
| 113 | % [lat,lon] = xy2ll(x,y,sgn);
|
---|
| 114 | % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel);
|
---|
| 115 | %
|
---|
| 116 | % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70)
|
---|
| 117 | % -1 : south latitude (default is mer=0 lat=71)
|
---|
| 118 | */
|
---|
| 119 | bool flag=true;
|
---|
| 120 |
|
---|
| 121 | /* Get central_meridian and standard_parallel depending on hemisphere */
|
---|
| 122 | if (sgn == 1) {
|
---|
| 123 | *pdelta= 45;
|
---|
| 124 | *pslat = 70;
|
---|
| 125 | _printf_(flag,"Warning: expecting coordinates in polar stereographic (Std Latitude: 70N Meridian: 45).\n");
|
---|
| 126 | }
|
---|
| 127 | else if (sgn == -1) {
|
---|
| 128 | *pdelta= 0;
|
---|
| 129 | *pslat = 71;
|
---|
| 130 | _printf_(flag,"Warning: expecting coordinates in polar stereographic (Std Latitude: 71S Meridian: 0).\n");
|
---|
| 131 | }
|
---|
| 132 | else _error_("Sign should be either +1 or -1.\n");
|
---|
| 133 |
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|