public long convertTransverseMercatorToGeodetic(double Easting,double Northing){
  double c;
  double de;
  double dlam;
  double eta;
  double eta2;
  double eta3;
  double eta4;
  double ftphi;
  int i;
  double sn;
  double sr;
  double t;
  double tan2;
  double tan4;
  double t10;
  double t11;
  double t12;
  double t13;
  double t14;
  double t15;
  double t16;
  double t17;
  double tmd;
  double tmdo;
  long Error_Code=TRANMERC_NO_ERROR;
  if ((Easting < (TranMerc_False_Easting - TranMerc_Delta_Easting)) || (Easting > (TranMerc_False_Easting + TranMerc_Delta_Easting))) {
    Error_Code|=TRANMERC_EASTING_ERROR;
  }
  if ((Northing < (TranMerc_False_Northing - TranMerc_Delta_Northing)) || (Northing > (TranMerc_False_Northing + TranMerc_Delta_Northing))) {
    Error_Code|=TRANMERC_NORTHING_ERROR;
  }
  if (Error_Code == TRANMERC_NO_ERROR) {
    tmdo=TranMerc_ap * TranMerc_Origin_Lat - TranMerc_bp * Math.sin(2.0 * TranMerc_Origin_Lat) + TranMerc_cp * Math.sin(4.0 * TranMerc_Origin_Lat) - TranMerc_dp * Math.sin(6.0 * TranMerc_Origin_Lat) + TranMerc_ep * Math.sin(8.0 * TranMerc_Origin_Lat);
    tmd=tmdo + (Northing - TranMerc_False_Northing) / TranMerc_Scale_Factor;
    sr=TranMerc_a * (1.e0 - TranMerc_es) / Math.pow(Math.sqrt(1.e0 - TranMerc_es * Math.pow(Math.sin(0.e0),2)),3);
    ftphi=tmd / sr;
    for (i=0; i < 5; i++) {
      t10=TranMerc_ap * ftphi - TranMerc_bp * Math.sin(2.0 * ftphi) + TranMerc_cp * Math.sin(4.0 * ftphi) - TranMerc_dp * Math.sin(6.0 * ftphi) + TranMerc_ep * Math.sin(8.0 * ftphi);
      sr=TranMerc_a * (1.e0 - TranMerc_es) / Math.pow(Math.sqrt(1.e0 - TranMerc_es * Math.pow(Math.sin(ftphi),2)),3);
      ftphi=ftphi + (tmd - t10) / sr;
    }
    sr=TranMerc_a * (1.e0 - TranMerc_es) / Math.pow(Math.sqrt(1.e0 - TranMerc_es * Math.pow(Math.sin(ftphi),2)),3);
    sn=TranMerc_a / Math.sqrt(1.e0 - TranMerc_es * Math.pow(Math.sin(ftphi),2));
    c=Math.cos(ftphi);
    t=Math.tan(ftphi);
    tan2=t * t;
    tan4=tan2 * tan2;
    eta=TranMerc_ebs * Math.pow(c,2);
    eta2=eta * eta;
    eta3=eta2 * eta;
    eta4=eta3 * eta;
    de=Easting - TranMerc_False_Easting;
    if (Math.abs(de) < 0.0001)     de=0.0;
    t10=t / (2.e0 * sr * sn* Math.pow(TranMerc_Scale_Factor,2));
    t11=t * (5.e0 + 3.e0 * tan2 + eta - 4.e0 * Math.pow(eta,2) - 9.e0 * tan2 * eta) / (24.e0 * sr * Math.pow(sn,3)* Math.pow(TranMerc_Scale_Factor,4));
    t12=t * (61.e0 + 90.e0 * tan2 + 46.e0 * eta + 45.E0 * tan4 - 252.e0 * tan2 * eta - 3.e0 * eta2 + 100.e0 * eta3 - 66.e0 * tan2 * eta2 - 90.e0 * tan4 * eta + 88.e0 * eta4 + 225.e0 * tan4 * eta2 + 84.e0 * tan2 * eta3 - 192.e0 * tan2 * eta4) / (720.e0 * sr * Math.pow(sn,5)* Math.pow(TranMerc_Scale_Factor,6));
    t13=t * (1385.e0 + 3633.e0 * tan2 + 4095.e0 * tan4 + 1575.e0 * Math.pow(t,6)) / (40320.e0 * sr * Math.pow(sn,7)* Math.pow(TranMerc_Scale_Factor,8));
    Latitude=ftphi - Math.pow(de,2) * t10 + Math.pow(de,4) * t11 - Math.pow(de,6) * t12 + Math.pow(de,8) * t13;
    t14=1.e0 / (sn * c * TranMerc_Scale_Factor);
    t15=(1.e0 + 2.e0 * tan2 + eta) / (6.e0 * Math.pow(sn,3) * c* Math.pow(TranMerc_Scale_Factor,3));
    t16=(5.e0 + 6.e0 * eta + 28.e0 * tan2 - 3.e0 * eta2 + 8.e0 * tan2 * eta + 24.e0 * tan4 - 4.e0 * eta3 + 4.e0 * tan2 * eta2 + 24.e0 * tan2 * eta3) / (120.e0 * Math.pow(sn,5) * c* Math.pow(TranMerc_Scale_Factor,5));
    t17=(61.e0 + 662.e0 * tan2 + 1320.e0 * tan4 + 720.e0 * Math.pow(t,6)) / (5040.e0 * Math.pow(sn,7) * c* Math.pow(TranMerc_Scale_Factor,7));
    dlam=de * t14 - Math.pow(de,3) * t15 + Math.pow(de,5) * t16 - Math.pow(de,7) * t17;
    Longitude=TranMerc_Origin_Long + dlam;
    if (Math.abs(Latitude) > (90.0 * PI / 180.0))     Error_Code|=TRANMERC_NORTHING_ERROR;
    if ((Longitude) > (PI)) {
      Longitude-=(2 * PI);
      if (Math.abs(Longitude) > PI)       Error_Code|=TRANMERC_EASTING_ERROR;
    }
    if (Math.abs(dlam) > (9.0 * PI / 180) * Math.cos(Latitude)) {
      Error_Code|=TRANMERC_LON_WARNING;
    }
    if (Latitude > 1.0e10)     Error_Code|=TRANMERC_LON_WARNING;
  }
  return (Error_Code);
}

public long convertTransverseMercatorToGeodetic ( double Easting , double Northing ) { double c ; double de ; double dlam ; double eta ; double eta2 ; double eta3 ; double eta4 ; double ftphi ; int i ; double sn ; double sr ; double t ; double tan2 ; double tan4 ; double t10 ; double t11 ; double t12 ; double t13 ; double t14 ; double t15 ; double t16 ; double t17 ; double tmd ; double tmdo ; long Error_Code = TRANMERC_NO_ERROR ; if ( ( Easting < ( TranMerc_False_Easting - TranMerc_Delta_Easting ) ) || ( Easting > ( TranMerc_False_Easting + TranMerc_Delta_Easting ) ) ) { Error_Code |= TRANMERC_EASTING_ERROR ; } if ( ( Northing < ( TranMerc_False_Northing - TranMerc_Delta_Northing ) ) || ( Northing > ( TranMerc_False_Northing + TranMerc_Delta_Northing ) ) ) { Error_Code |= TRANMERC_NORTHING_ERROR ; } if ( Error_Code == TRANMERC_NO_ERROR ) { tmdo = TranMerc_ap * TranMerc_Origin_Lat - TranMerc_bp * Math . sin ( 2.0 * TranMerc_Origin_Lat ) + TranMerc_cp * Math . sin ( 4.0 * TranMerc_Origin_Lat ) - TranMerc_dp * Math . sin ( 6.0 * TranMerc_Origin_Lat ) + TranMerc_ep * Math . sin ( 8.0 * TranMerc_Origin_Lat ) ; tmd = tmdo + ( Northing - TranMerc_False_Northing ) / TranMerc_Scale_Factor ; sr = TranMerc_a * ( 1.e0 - TranMerc_es ) / Math . pow ( Math . sqrt ( 1.e0 - TranMerc_es * Math . pow ( Math . sin ( 0.e0 ) , 2 ) ) , 3 ) ; ftphi = tmd / sr ; for ( i = 0 ; i < 5 ; i ++ ) { t10 = TranMerc_ap * ftphi - TranMerc_bp * Math . sin ( 2.0 * ftphi ) + TranMerc_cp * Math . sin ( 4.0 * ftphi ) - TranMerc_dp * Math . sin ( 6.0 * ftphi ) + TranMerc_ep * Math . sin ( 8.0 * ftphi ) ; sr = TranMerc_a * ( 1.e0 - TranMerc_es ) / Math . pow ( Math . sqrt ( 1.e0 - TranMerc_es * Math . pow ( Math . sin ( ftphi ) , 2 ) ) , 3 ) ; ftphi = ftphi + ( tmd - t10 ) / sr ; } sr = TranMerc_a * ( 1.e0 - TranMerc_es ) / Math . pow ( Math . sqrt ( 1.e0 - TranMerc_es * Math . pow ( Math . sin ( ftphi ) , 2 ) ) , 3 ) ; sn = TranMerc_a / Math . sqrt ( 1.e0 - TranMerc_es * Math . pow ( Math . sin ( ftphi ) , 2 ) ) ; c = Math . cos ( ftphi ) ; t = Math . tan ( ftphi ) ; tan2 = t * t ; tan4 = tan2 * tan2 ; eta = TranMerc_ebs * Math . pow ( c , 2 ) ; eta2 = eta * eta ; eta3 = eta2 * eta ; eta4 = eta3 * eta ; de = Easting - TranMerc_False_Easting ; if ( Math . abs ( de ) < 0.0001 ) de = 0.0 ; t10 = t / ( 2.e0 * sr * sn * Math . pow ( TranMerc_Scale_Factor , 2 ) ) ; t11 = t * ( 5.e0 + 3.e0 * tan2 + eta - 4.e0 * Math . pow ( eta , 2 ) - 9.e0 * tan2 * eta ) / ( 24.e0 * sr * Math . pow ( sn , 3 ) * Math . pow ( TranMerc_Scale_Factor , 4 ) ) ; t12 = t * ( 61.e0 + 90.e0 * tan2 + 46.e0 * eta + 45.E0 * tan4 - 252.e0 * tan2 * eta - 3.e0 * eta2 + 100.e0 * eta3 - 66.e0 * tan2 * eta2 - 90.e0 * tan4 * eta + 88.e0 * eta4 + 225.e0 * tan4 * eta2 + 84.e0 * tan2 * eta3 - 192.e0 * tan2 * eta4 ) / ( 720.e0 * sr * Math . pow ( sn , 5 ) * Math . pow ( TranMerc_Scale_Factor , 6 ) ) ; t13 = t * ( 1385.e0 + 3633.e0 * tan2 + 4095.e0 * tan4 + 1575.e0 * Math . pow ( t , 6 ) ) / ( 40320.e0 * sr * Math . pow ( sn , 7 ) * Math . pow ( TranMerc_Scale_Factor , 8 ) ) ; Latitude = ftphi - Math . pow ( de , 2 ) * t10 + Math . pow ( de , 4 ) * t11 - Math . pow ( de , 6 ) * t12 + Math . pow ( de , 8 ) * t13 ; t14 = 1.e0 / ( sn * c * TranMerc_Scale_Factor ) ; t15 = ( 1.e0 + 2.e0 * tan2 + eta ) / ( 6.e0 * Math . pow ( sn , 3 ) * c * Math . pow ( TranMerc_Scale_Factor , 3 ) ) ; t16 = ( 5.e0 + 6.e0 * eta + 28.e0 * tan2 - 3.e0 * eta2 + 8.e0 * tan2 * eta + 24.e0 * tan4 - 4.e0 * eta3 + 4.e0 * tan2 * eta2 + 24.e0 * tan2 * eta3 ) / ( 120.e0 * Math . pow ( sn , 5 ) * c * Math . pow ( TranMerc_Scale_Factor , 5 ) ) ; t17 = ( 61.e0 + 662.e0 * tan2 + 1320.e0 * tan4 + 720.e0 * Math . pow ( t , 6 ) ) / ( 5040.e0 * Math . pow ( sn , 7 ) * c * Math . pow ( TranMerc_Scale_Factor , 7 ) ) ; dlam = de * t14 - Math . pow ( de , 3 ) * t15 + Math . pow ( de , 5 ) * t16 - Math . pow ( de , 7 ) * t17 ; Longitude = TranMerc_Origin_Long + dlam ; if ( Math . abs ( Latitude ) > ( 90.0 * PI / 180.0 ) ) Error_Code |= TRANMERC_NORTHING_ERROR ; if ( ( Longitude ) > ( PI ) ) { Longitude -= ( 2 * PI ) ; if ( Math . abs ( Longitude ) > PI ) Error_Code |= TRANMERC_EASTING_ERROR ; } if ( Math . abs ( dlam ) > ( 9.0 * PI / 180 ) * Math . cos ( Latitude ) ) { Error_Code |= TRANMERC_LON_WARNING ; } if ( Latitude > 1.0e10 ) Error_Code |= TRANMERC_LON_WARNING ; } return ( Error_Code ) ; }
the function convert_transverse_mercator_to_geodetic converts transverse mercator projection ( easting and northing ) coordinates to geodetic ( latitude and longitude ) coordinates , according to the current ellipsoid and transverse mercator projection parameters . if any errors occur , the error code ( s ) are returned by the function , otherwise tranmerc_no_error is returned .
