/*!\file Xy2llx.cpp */ #include "./Xy2llx.h" #include "../../shared/shared.h" #include "../../include/include.h" #include "../../toolkits/toolkits.h" #include "../../EnumDefinitions/EnumDefinitions.h" int Xy2llx(double* lat, double* lon, double* x, double* y, int ncoord, int sgn){ /* This is a cpp conversion of the following: %XY2LL - converts xy to lat long % % Converts Polar Stereographic (X,Y) coordinates for the polar regions to % latitude and longitude Stereographic (X,Y) coordinates for the polar % regions. % Author: Michael P. Schodlok, December 2003 (map2xy.m) % % Usage: % [lat,lon] = xy2ll(x,y,sgn); % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel); % % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70) % -1 : south latitude (default is mer=0 lat=71) */ double delta,slat; bool flag=false; /* Get central_meridian and standard_parallel depending on hemisphere */ if (sgn == 1) { delta = 45; slat = 70; _printf_(flag,"Warning: expecting coordinates in polar stereographic (Std Latitude: 70N Meridian: 45)"); } else if (sgn == -1) { delta = 0; slat = 71; _printf_(flag,"Warning: expecting coordinates in polar stereographic (Std Latitude: 71S Meridian: 0)"); } else _error_("Sign should be either +1 or -1"); return(Xy2llx(lat,lon, x,y,ncoord, sgn,delta,slat)); } int Xy2llx(double* lat, double* lon, double* x, double* y, int ncoord, int sgn, double central_meridian, double standard_parallel){ /* This is a cpp conversion of the following: %XY2LL - converts xy to lat long % % Converts Polar Stereographic (X,Y) coordinates for the polar regions to % latitude and longitude Stereographic (X,Y) coordinates for the polar % regions. % Author: Michael P. Schodlok, December 2003 (map2xy.m) % % Usage: % [lat,lon] = xy2ll(x,y,sgn); % [lat,lon] = xy2ll(x,y,sgn,central_meridian,standard_parallel); % % - sgn = Sign of latitude +1 : north latitude (default is mer=45 lat=70) % -1 : south latitude (default is mer=0 lat=71) */ int i; double delta,slat; double cde,re,ex2,ex,pi; double sl,rho,cm,T,chi; if ((sgn != 1) && (sgn != -1)) _error_("Sign should be either +1 or -1"); delta = central_meridian; slat = standard_parallel; /* Conversion constant from degrees to radians */ cde = 57.29577951; /* Radius of the earth in meters */ re = 6378.273*pow(10.,3.); /* Eccentricity of the Hughes ellipsoid squared */ ex2 = .006693883; /* Eccentricity of the Hughes ellipsoid */ ex = sqrt(ex2); /* pi is not defined in cpp */ pi = 4.*atan(1.); /* loop over all the coordinate pairs */ for (i=0; i