public long convertPolarStereographicToGeodetic(double Easting,double Northing){
  double dy=0, dx=0;
  double rho=0;
  double t;
  double PHI, sin_PHI;
  double tempPHI=0.0;
  double essin;
  double pow_es;
  double delta_radius;
  long Error_Code=POLAR_NO_ERROR;
  double min_easting=Polar_False_Easting - Polar_Delta_Easting;
  double max_easting=Polar_False_Easting + Polar_Delta_Easting;
  double min_northing=Polar_False_Northing - Polar_Delta_Northing;
  double max_northing=Polar_False_Northing + Polar_Delta_Northing;
  if (Easting > max_easting || Easting < min_easting) {
    Error_Code|=POLAR_EASTING_ERROR;
  }
  if (Northing > max_northing || Northing < min_northing) {
    Error_Code|=POLAR_NORTHING_ERROR;
  }
  if (Error_Code == POLAR_NO_ERROR) {
    dy=Northing - Polar_False_Northing;
    dx=Easting - Polar_False_Easting;
    rho=Math.sqrt(dx * dx + dy * dy);
    delta_radius=Math.sqrt(Polar_Delta_Easting * Polar_Delta_Easting + Polar_Delta_Northing * Polar_Delta_Northing);
    if (rho > delta_radius) {
      Error_Code|=POLAR_RADIUS_ERROR;
    }
  }
  if (Error_Code == POLAR_NO_ERROR) {
    if ((dy == 0.0) && (dx == 0.0)) {
      Latitude=PI_OVER_2;
      Longitude=Polar_Origin_Long;
    }
 else {
      if (Southern_Hemisphere != 0) {
        dy*=-1.0;
        dx*=-1.0;
      }
      if (Math.abs(Math.abs(Polar_Origin_Lat) - PI_OVER_2) > 1.0e-10)       t=rho * tc / (Polar_a_mc);
 else       t=rho * e4 / (two_Polar_a);
      PHI=PI_OVER_2 - 2.0 * Math.atan(t);
      while (Math.abs(PHI - tempPHI) > 1.0e-10) {
        tempPHI=PHI;
        sin_PHI=Math.sin(PHI);
        essin=es * sin_PHI;
        pow_es=Math.pow((1.0 - essin) / (1.0 + essin),es_OVER_2);
        PHI=PI_OVER_2 - 2.0 * Math.atan(t * pow_es);
      }
      Latitude=PHI;
      Longitude=Polar_Origin_Long + Math.atan2(dx,-dy);
      if (Longitude > PI)       Longitude-=TWO_PI;
 else       if (Longitude < -PI)       Longitude+=TWO_PI;
      if (Latitude > PI_OVER_2)       Latitude=PI_OVER_2;
 else       if (Latitude < -PI_OVER_2)       Latitude=-PI_OVER_2;
      if (Longitude > PI)       Longitude=PI;
 else       if (Longitude < -PI)       Longitude=-PI;
    }
    if (Southern_Hemisphere != 0) {
      Latitude*=-1.0;
      Longitude*=-1.0;
    }
  }
  return (Error_Code);
}

public long convertPolarStereographicToGeodetic ( double Easting , double Northing ) { double dy = 0 , dx = 0 ; double rho = 0 ; double t ; double PHI , sin_PHI ; double tempPHI = 0.0 ; double essin ; double pow_es ; double delta_radius ; long Error_Code = POLAR_NO_ERROR ; double min_easting = Polar_False_Easting - Polar_Delta_Easting ; double max_easting = Polar_False_Easting + Polar_Delta_Easting ; double min_northing = Polar_False_Northing - Polar_Delta_Northing ; double max_northing = Polar_False_Northing + Polar_Delta_Northing ; if ( Easting > max_easting || Easting < min_easting ) { Error_Code |= POLAR_EASTING_ERROR ; } if ( Northing > max_northing || Northing < min_northing ) { Error_Code |= POLAR_NORTHING_ERROR ; } if ( Error_Code == POLAR_NO_ERROR ) { dy = Northing - Polar_False_Northing ; dx = Easting - Polar_False_Easting ; rho = Math . sqrt ( dx * dx + dy * dy ) ; delta_radius = Math . sqrt ( Polar_Delta_Easting * Polar_Delta_Easting + Polar_Delta_Northing * Polar_Delta_Northing ) ; if ( rho > delta_radius ) { Error_Code |= POLAR_RADIUS_ERROR ; } } if ( Error_Code == POLAR_NO_ERROR ) { if ( ( dy == 0.0 ) && ( dx == 0.0 ) ) { Latitude = PI_OVER_2 ; Longitude = Polar_Origin_Long ; } else { if ( Southern_Hemisphere != 0 ) { dy *= - 1.0 ; dx *= - 1.0 ; } if ( Math . abs ( Math . abs ( Polar_Origin_Lat ) - PI_OVER_2 ) > 1.0e-10 ) t = rho * tc / ( Polar_a_mc ) ; else t = rho * e4 / ( two_Polar_a ) ; PHI = PI_OVER_2 - 2.0 * Math . atan ( t ) ; while ( Math . abs ( PHI - tempPHI ) > 1.0e-10 ) { tempPHI = PHI ; sin_PHI = Math . sin ( PHI ) ; essin = es * sin_PHI ; pow_es = Math . pow ( ( 1.0 - essin ) / ( 1.0 + essin ) , es_OVER_2 ) ; PHI = PI_OVER_2 - 2.0 * Math . atan ( t * pow_es ) ; } Latitude = PHI ; Longitude = Polar_Origin_Long + Math . atan2 ( dx , - dy ) ; if ( Longitude > PI ) Longitude -= TWO_PI ; else if ( Longitude < - PI ) Longitude += TWO_PI ; if ( Latitude > PI_OVER_2 ) Latitude = PI_OVER_2 ; else if ( Latitude < - PI_OVER_2 ) Latitude = - PI_OVER_2 ; if ( Longitude > PI ) Longitude = PI ; else if ( Longitude < - PI ) Longitude = - PI ; } if ( Southern_Hemisphere != 0 ) { Latitude *= - 1.0 ; Longitude *= - 1.0 ; } } return ( Error_Code ) ; }
the function convert_polar_stereographic_to_geodetic converts polar stereographic coordinates ( easting and northing ) to geodetic coordinates ( latitude and longitude ) according to the current ellipsoid and polar stereographic projection parameters . if any errors occur , the code ( s ) are returned by the function , otherwise polar_no_error is returned .
