﻿


function CoordConvertNewClass_JS() {

    this.x_out = 0;
    this.y_out = 0;

    this.l_out = 0;
    this.f_out = 0;
    
    var c__3 = 3;
    var c__1 = 1;
    var c__5 = 5;
    var c_b8 = 0.0;
    var c_b19 = 1.5;


    var z_out;

    function flhxyz_(fi, lambd, altim, a, e)
    {

        /* System generated locals */
        var d__1;
        /* Local variables */
        var n;
        /* Computing 2nd power */
        d__1 = Math.sin(fi);
        n = a / Math.sqrt(1 - e * (d__1 * d__1));
        x_out = (n + altim) * Math.cos(fi) * Math.cos(lambd);
        y_out = (n + altim) * Math.cos(fi) * Math.sin(lambd);
        z_out = ((1 - e) * n + altim) * Math.sin(fi);
        return;
    } /* flhxyz_ */


    var r0_out;
    var n0_out;
    var e1_out;
//    function hatt_(lat0, long0, lat, long__)
//    {
//        /* System generated locals */
//        var d__1, d__2, d__3, d__4, d__5, d__6;
//        /* Local variables */
//        var a, e, e1, n0, r0, diflat, diflon;
//        /*   hatt projection subroutine */
//        /*   greek datum - bessel */
//        a = 6377397.155;
//        e = .0066743722;
//        radius_(a, e, lat0);
//        r0 = r0_out;
//        n0 = n0_out;
//        e1 = e1_out;
//        
//        diflat = lat - lat0;
//        diflon = long__ - long0;
//        /* Computing 2nd power */
//        d__1 = Math.sin(lat0);
//        /* Computing 2nd power */
//        d__2 = diflat;
//        /* Computing 2nd power */
//        d__3 = Math.sin(lat0);
//        /* Computing 3rd power */
//        d__4 = diflon;
//        x_out = n0 * Math.cos(lat0) * diflon - r0 * Math.sin(lat0) * diflat * diflon - r0 *
//              Math.cos(lat0) * (e1 * 9.0 * (d__1 * d__1) + 2.0) * diflon * (d__2 *
//              d__2) / 6.0 - n0 * Math.cos(lat0) * (d__3 * d__3) * (d__4 * (d__4 *
//              d__4)) / 6.0;

//       /* Computing 2nd power */
//        d__1 = diflon;
//        /* Computing 2nd power */
//        d__2 = r0;
//        /* Computing 2nd power */
//        d__3 = diflat;
//        /* Computing 2nd power */
//        d__4 = Math.sin(lat0);
//        /* Computing 4th power */
//        d__5 = Math.pow(Math.cos(lat0), 2);//, d__5 *= d__5;
//        /* Computing 2nd power */
//        d__6 = diflon;
//        y_out = r0 * diflat + n0 * Math.cos(lat0) * Math.sin(lat0) * (d__1 * d__1) / 2 +
//              d__2 * d__2 * 3 * e1 * Math.sin(lat0) * Math.cos(lat0) * (d__3 * d__3) /
//              2.0 / n0 + r0 * (1 - d__4 * d__4 * 4.0 + e1 * (d__5 * d__5)) *
//              diflat * (d__6 * d__6) / 6.0;
//        return;
//    } /* hatt_ */


    
    function invhat_(f0, l0, x, y)
    {
        /* System generated locals */
        var d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
        /* Local variables */
        var a, e, e1, n0, r0;
        a = 6377397.155;
        e = .0066743722;
        radius_(a, e, f0);
        r0 = r0_out;
        n0 = n0_out;
        e1 = e1_out;
        /* Computing 2nd power */
        d__1 = x;
        /* Computing 2nd power */
        d__2 = Math.cos(f0);
        /* Computing 2nd power */
        d__3 = y;
        /* Computing 2nd power */
        d__4 = Math.tan(f0);
        /* Computing 2nd power */
        d__5 = Math.cos(f0);
        /* Computing 2nd power */
        d__6 = Math.sin(f0);
        /* Computing 2nd power */
        d__7 = x;
        /* Computing 2nd power */
        d__8 = n0;
        f = f0 + y / r0 - Math.tan(f0) * (d__1 * d__1) / (r0 * 2 * n0) - e1 * 3 *
              Math.tan(f0) * (d__2 * d__2) * (d__3 * d__3) / (r0 * 2 * n0) - (d__4 *
               d__4 * 3 + 1 + e1 * (d__5 * d__5) - e1 * 9 * (d__6 * d__6)) * (
              d__7 * d__7) * y / (r0 * 6 * (d__8 * d__8));
        /* Computing 2nd power */
        d__1 = n0;
        /* Computing 3rd power */
        d__2 = x;
        /* Computing 2nd power */
        d__3 = Math.tan(f0);
        /* Computing 3rd power */
        d__4 = n0;
        /* Computing 2nd power */
        d__5 = Math.tan(f0);
        /* Computing 2nd power */
        d__6 = Math.cos(f0);
        /* Computing 2nd power */
        d__7 = y;
        /* Computing 3rd power */
        d__8 = n0;
        l = l0 + x / (n0 * Math.cos(f0)) + x * y * Math.tan(f0) / (d__1 * d__1 * Math.cos(
              f0)) - d__2 * (d__2 * d__2) * (d__3 * d__3) / (d__4 * (d__4 *
              d__4) * 3 * Math.cos(f0)) + (d__5 * d__5 * 3 + 1 + e1 * (d__6 * d__6))
               * x * (d__7 * d__7) / (d__8 * (d__8 * d__8) * 3 * Math.cos(f0));
        return;
    } /* invhat_ */

    function radius_(a,  e,  lat)
    {
        var r__;
        var n;
        var e1;
        /* System generated locals */
        var d__1, d__2;
        e1 = e / (1 - e);
        /* Computing 2nd power */
        d__2 = Math.sin(lat);
        d__1 = 1 - e * (d__2 * d__2);
        r__ = a * (1 - e) / Math.pow(d__1, c_b19); //gvernar pow_dd??
        /* Computing 2nd power */
        d__1 = Math.sin(lat);
        n = a / Math.sqrt(1 - e * (d__1 * d__1));
        
        r0_out=r__;
        n0_out=n;
        e1_out=e1;
        return;
    } /* radius_ */



    var east_out;
    var nort_out;
    var g_out;
    var k_out;
    
    function tmp_(lat, long__, a, e)
    {
        var east;
        var nort;
        var g;
        var k;
     
        /* System generated locals */
        var d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10,d__11, d__12;
        /* Local variables */
        var n, r__, x, y;
        var e1, m0, m2, m4, m6, diflon, merlen;

        /*   Transverse Mercator Projection Subroutine */
        /*   New Geodetic Greek Datum - NGGD '88 , Stantard Meridian 24 deg E */
        /*       a=6378388.d0    * ED50 Parameters */
        /*       e=.00672267d0 */
        /*     a=6378137d0     * New greek geoedetic datum parameters */
        /*     e=.0066943800d0 */
        /* The ellipsoid parameters are read in the calling sequence of the tmp */
        /* routine */
        diflon = long__ - .41887902047863906;
        radius_(a, e, lat);
        r__ = r0_out;
        n = n0_out;
        e1 = e1_out;

        /* Computing 3rd power */
        d__1 = Math.cos(lat);
        /* Computing 2nd power */
        d__2 = Math.tan(lat);
        /* Computing 2nd power */
        d__3 = Math.cos(lat);
        /* Computing 3rd power */
        d__4 = diflon;
        /* Computing 5th power */
        d__5 = Math.cos(lat);
        d__6 = d__5;
        d__5 *= d__5;
        /* Computing 2nd power */
        d__7 = Math.tan(lat);
        /* Computing 4th power */
        d__8 = Math.tan(lat); d__8 *= d__8;
        /* Computing 2nd power */
        d__9 = Math.cos(lat);
        /* Computing 2nd power */
        d__10 = Math.sin(lat);
        /* Computing 5th power */
        d__11 = diflon; d__12 = d__11; d__11 *= d__11;
        x = n * Math.cos(lat) * diflon + n * (d__1 * (d__1 * d__1)) * (1 - d__2 *
              d__2 + e1 * (d__3 * d__3)) * (d__4 * (d__4 * d__4)) / 6 + n * (
              d__6 * (d__5 * d__5)) * (5 - d__7 * d__7 * 18 + d__8 * d__8 + e1 *
               14 * (d__9 * d__9) - e1 * 58 * (d__10 * d__10)) * (d__12 * (
              d__11 * d__11)) / 120;
              
        merid_(a, e, lat);
        merlen = merlen_out;
        m0 = m0_out;
        m2 = m2_out;
        m4 = m4_out;
        m6 = m6_out;

        
        /* Computing 2nd power */
        d__1 = diflon;
        /* Computing 3rd power */
        d__2 = Math.cos(lat);
        /* Computing 2nd power */
        d__3 = Math.tan(lat);
        /* Computing 2nd power */
        d__4 = Math.cos(lat);
        /* Computing 4th power */
        d__5 = diflon; d__5 *= d__5;
        /* Computing 5th power */
        d__6 = Math.cos(lat); d__7 = d__6; d__6 *= d__6;
        /* Computing 2nd power */
        d__8 = Math.tan(lat);
        /* Computing 4th power */
        d__9 = Math.tan(lat); d__9 *= d__9;
        /* Computing 6th power */
        d__10 = diflon; d__10 *= d__10;
        y = merlen + n * Math.cos(lat) * Math.sin(lat) * (d__1 * d__1) / 2 + n * Math.sin(lat)
               * (d__2 * (d__2 * d__2)) * (5 - d__3 * d__3 + e1 * 9 * (d__4 *
              d__4)) * (d__5 * d__5) / 24 + n * Math.sin(lat) * (d__7 * (d__6 *
              d__6)) * (61 - d__8 * d__8 * 58 + d__9 * d__9) * (d__10 * (d__10 *
               d__10)) / 720.0;
        east = x * .9996 + 5e5;
        nort = y * .9996;
        /* Computing 2nd power */
        d__1 = Math.cos(lat);
        /* Computing 2nd power */
        d__2 = Math.cos(lat);
        /* Computing 2nd power */
        d__3 = e1;
        /* Computing 4th power */
        d__4 = Math.cos(lat); d__4 *= d__4;
        /* Computing 3rd power */
        d__5 = diflon;
        /* Computing 4th power */
        d__6 = Math.cos(lat); d__6 *= d__6;
        /* Computing 2nd power */
        d__7 = Math.tan(lat);
        /* Computing 5th power */
        d__8 = diflon; d__9 = d__8; d__8 *= d__8;
        g = Math.sin(lat) * diflon + Math.sin(lat) * (d__1 * d__1) * (e1 * 3 * (d__2 *
              d__2) + 1 + d__3 * d__3 * 2 * (d__4 * d__4)) * (d__5 * (d__5 *
              d__5)) / 3 + Math.sin(lat) * (d__6 * d__6) * (2 - d__7 * d__7) * (
              d__9 * (d__8 * d__8)) / 15;
        /* Computing 2nd power */
        d__1 = Math.cos(lat);
        /* Computing 2nd power */
        d__2 = Math.cos(lat);
        /* Computing 2nd power */
        d__3 = diflon;
        /* Computing 4th power */
        d__4 = Math.cos(lat); d__4 *= d__4;
        /* Computing 2nd power */
        d__5 = Math.tan(lat);
        /* Computing 2nd power */
        d__6 = Math.cos(lat);
        /* Computing 4th power */
        d__7 = diflon; d__7 *= d__7;
        k = d__1 * d__1 * (e1 * (d__2 * d__2) + 1) * (d__3 * d__3) / 2 + 1 +
              d__4 * d__4 * (1 - d__5 * d__5 * 4 + e1 * 14 * (d__6 * d__6)) * (
              d__7 * d__7) / 24;
        k *= .9996;
        
        east_out=east;
        nort_out=nort;
        g_out=g;
        k_out=k;
        return;
    } /* tmp_ */


    var merlen_out;
    var m0_out;
    var m2_out;
    var m4_out;
    var m6_out;

    function merid_(a, e, lat)
    {
        var merlen;
        var m0;
        var m2;
        var m4;
        var m6;
    
        /* System generated locals */
        var d__1, d__2;
        /* length of meridian arc is calculated from equator */
        /* Computing 2nd power */
        d__1 = e;
        /* Computing 3rd power */
        d__2 = e;
        m0 = a * (1.0 - e / 4.0 - d__1 * d__1 * 3.0 / 64.0 - d__2 * (d__2 * d__2) *
               5.0 / 256.0);
        /* Computing 2nd power */
        d__1 = e;
        /* Computing 3rd power */
        d__2 = e;
        m2 = a * 3.0 * (e + d__1 * d__1 / 4.0 + d__2 * (d__2 * d__2) * 15.0 /
              128.0) / 8.0;
        /* Computing 2nd power */
        d__1 = e;
        /* Computing 3rd power */
        d__2 = e;
        m4 = a * 15.0 * (d__1 * d__1 + d__2 * (d__2 * d__2) * 3.0 / 4.0) / 256.0;
        /* Computing 3rd power */
        d__1 = e;
        m6 = a * 35 * (d__1 * (d__1 * d__1)) / 3072;
        merlen = m0 * lat - m2 * Math.sin(lat * 2.0) + m4 * Math.sin(lat * 4.0) - m6 *
               Math.sin(lat * 6.0);
               
        merlen_out=merlen;
        m0_out=m0;
        m2_out=m2;
        m4_out=m4;
        m6_out=m6;

        return;
    } /* merid_ */



//    function merid1_(a, e, lat,  merlen, m0, m2, m4, m6)
//    {
//        /* System generated locals */
//        var d__1, d__2;
//       /* Computing 2nd power */
//        d__1 = e;
//        /* Computing 3rd power */
//        d__2 = e;
//        m0 = e * 3 / 4 + 1 + d__1 * d__1 * 45 / 64 + d__2 * (d__2 * d__2) * 175/ 256;
//        /* Computing 2nd power */
//        d__1 = e;
//        /* Computing 3rd power */
//        d__2 = e;
//        m2 = e * 3 / 8 + d__1 * d__1 * 15 / 32 + d__2 * (d__2 * d__2) * 525 /1024;
//        /* Computing 2nd power */
//        d__1 = e;
//        /* Computing 3rd power */
//        d__2 = e;
//        m4 = d__1 * d__1 * 15 / 256 + d__2 * (d__2 * d__2) * 105 / 1024;
//        /* Computing 3rd power */
//        d__1 = e;
//        m6 = d__1 * (d__1 * d__1) * 35 / 3072;
//        merlen = a * (1 - e) * (m0 * lat - m2 * Math.sin(lat * 2) + m4 * Math.sin(
//              lat * 4) - m6 * Math.sin(lat * 6));
//        return;
//    } /* merid1_ */



    var f_out;
    var l_out;
    var h_out;
    function xyzflh_(a,  e,  x,  y,z__)
    {
        /* System generated locals */
        var d__1, d__2;
        /* Local variables */
        var n, p, st, xt, tanlat, lat;
        f = 0.0;
        h__ = 0.0;
        l = Math.atan2(y, x);
        n = a;
        p = Math.sqrt(x * x + y * y);

        do
        {
            tanlat = z__ * (n + h__) / (p * (n * (1 - e) + h__));
            lat = Math.atan(tanlat);
            /* Computing 2nd power */
            d__1 = Math.sin(lat);
            n = a / Math.sqrt(1 - e * (d__1 * d__1));
            /* Computing 2nd power */
            d__1 = p;
            /* Computing 2nd power */
            d__2 = z__ + n * e * Math.sin(lat);
            h__ = Math.sqrt(d__1 * d__1 + d__2 * d__2) - n;
            xt = (n + h__) * Math.cos(lat) * Math.cos(l);
            d__1 = x - xt;
            st = Math.abs(d__1);
        }
        while (st > .005)
        
        f = lat;
        
        f_out = f;
        l_out = l;
        h_out = h__;
        return;
    } /* xyzflh_ */


    var latout_out;
    var long___out

    function invtmp_(a, e, x, y,cm)
    {
        var latout;
        var long__;
        /* System generated locals */
        var d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10,
              d__11, d__12, d__13, d__14, d__15;
        /* Local variables */
        var tval, long0, c__, f = 0, n, r__;
        var e1, k0, m0, m2, m4, m6, t1, t2, v1, v2, t3, y1, fe,merlen;
        c__ = .017453292519943295;
        long0 = cm * c__;
        fe = 5e5;
        k0 = .9996;
        merid_(a, e, f);
        merlen = merlen_out;
        m0 = m0_out;
        m2 = m2_out;
        m4 = m4_out;
        m6 = m6_out;
        
        f = y / (k0 * m0);
        while(true)
        {
            merid_(a, e, f);
            merlen = merlen_out;
            m0 = m0_out;
            m2 = m2_out;
            m4 = m4_out;
            m6 = m6_out;

            y1 = k0 * merlen;
            /*        write(*,*)y1,y,y1-y */
            d__1 = y1 - y;
            tval = Math.abs(d__1);
            if (tval < .001)
               break;
            v1 = merlen - y / k0;
            v2 = m0 - m2 * 2.0 * Math.cos(f * 2.0) + m4 * 4.0 * Math.cos(f * 4.0) - m6 * 6.0 * Math.cos(f* 6.0);
            f -= v1 / v2;
        }
        radius_(a, e, f);
        r__ = r0_out;
        n = n0_out;
        e1 = e1_out;
        /* Computing 2nd power */
        d__1 = x - fe;
        /* Computing 2nd power */
        d__2 = k0;
        t1 = f - Math.tan(f) * (d__1 * d__1) / (d__2 * d__2 * 2.0 * n * r__);
        /* Computing 2nd power */
        d__1 = Math.tan(f);
        /* Computing 2nd power */
        d__2 = Math.cos(f);
        /* Computing 2nd power */
        d__3 = e1;
        /* Computing 4th power */
        d__4 = Math.cos(f); d__4 *= d__4;
        /* Computing 2nd power */
        d__5 = Math.sin(f);
        /* Computing 4th power */
        d__6 = x - fe; d__6 *= d__6;
        /* Computing 4th power */
        d__7 = k0; d__7 *= d__7;
        /* Computing 3rd power */
        d__8 = n;
        t2 = Math.tan(f) * (d__1 * d__1 * 3.0 + 5.0 + e1 * (d__2 * d__2) - d__3 * d__3 *
              4.0 * (d__4 * d__4) - e1 * 9.0 * (d__5 * d__5)) * (d__6 * d__6) / (
              d__7 * d__7 * 24.0 * (d__8 * (d__8 * d__8)) * r__);
        /* Computing 2nd power */
        d__1 = Math.tan(f);
        /* Computing 2nd power */
        d__2 = Math.cos(f);
        /* Computing 4th power */
        d__3 = Math.tan(f); d__3 *= d__3;
        /* Computing 2nd power */
        d__4 = Math.sin(f);
        /* Computing 5th power */
        d__5 = n; d__6 = d__5; d__5 *= d__5;
        /* Computing 6th power */
        d__7 = k0; d__7 *= d__7;
        t3 = Math.tan(f) * (d__1 * d__1 * 90.0 + 61.0 + e1 * 46.0 * (d__2 * d__2) + d__3 *
               d__3 * 45.0 - e1 * 252.0 * (d__4 * d__4)) / (d__6 * (d__5 * d__5) *
               720.0 * r__ * (d__7 * (d__7 * d__7)));
        /* Computing 6th power */
        d__1 = x - fe; d__1 *= d__1;
        latout = t1 + t2 - t3 * (d__1 * (d__1 * d__1));
        /* Computing 2nd power */
        d__1 = Math.tan(f);
        /* Computing 2nd power */
        d__2 = Math.cos(f);
        /* Computing 3rd power */
        d__3 = x - fe;
        /* Computing 3rd power */
        d__4 = n;
        /* Computing 3rd power */
        d__5 = k0;
        /* Computing 2nd power */
        d__6 = Math.tan(f);
        /* Computing 4th power */
        d__7 = Math.tan(f); d__7 *= d__7;
        /* Computing 2nd power */
        d__8 = Math.cos(f);
        /* Computing 2nd power */
        d__9 = Math.sin(f);
        /* Computing 5th power */
        d__10 = x - fe; d__11 = d__10; d__10 *= d__10;
        /* Computing 5th power */
        d__12 = n; d__13 = d__12; d__12 *= d__12;
        /* Computing 5th power */
        d__14 = k0; d__15 = d__14; d__14 *= d__14;
        long__ = cm * c__ + (x - fe) / (n * Math.cos(f) * k0) - (d__1 * d__1 * 2.0 +
              1.0 + e1 * (d__2 * d__2)) * (d__3 * (d__3 * d__3)) / (d__4 * (d__4
              * d__4) * 6.0 * Math.cos(f) * (d__5 * (d__5 * d__5))) + (d__6 * d__6 *
              28.0 + 5.0 + d__7 * d__7 * 24.0 + e1 * 6.0 * (d__8 * d__8) + e1 * 8.0 *
               (d__9 * d__9)) * (d__11 * (d__10 * d__10)) / (d__13 * (d__12 *
              d__12) * 120.0 * Math.cos(f) * (d__15 * (d__14 * d__14)));
              
        latout_out = latout;
        long___out = long__;
        return;
    } /* invtmp_ */


    this.ComputeLF2XY = ComputeLF2XY;
    function ComputeLF2XY(l_in, f_in)
    {
        var c__ = .017453292519943295;
        /* REMEMBER TO CHECK THE PARAMETERS IN THE FOLLOWING LINES */
        /*       a=6377397.155d0  * Bessel parameters */
        /*       e=0.0066943800d0 */
        /*       **************** ED50 parameters */
        var aed50 = 6378388.0;
        var eed50 = .00672267;
        /*       open(1,file='ed50-egs.prn',status='unknown') */
        /*       **************** NGGD parameters */
        var angd = 6378137.0;
        var engd = .00669438;
        /*       write(*,*) 'ENTER Id Lat Long(DD,MM,SS.ssss)' */
        var lonsec = 0.0;
        var latsec = 0.0;
        var rlat = l_in * c__;
        var rlong = f_in * c__;
        var x, y, z__;
        flhxyz_(rlat, rlong, c_b8, angd, engd);
        x = x_out;
        y = y_out;
        z__ = z_out;
        
        /* NEW UPDATED PARAMETERS BELOW !!!!!! */
        var dx = 199.723;
        var dy = -74.03;
        var dz = -246.018;
        x += dx;
        y += dy;
        z__ += dz;
        var rlatn, rlongn, alt, gon, kap;
        xyzflh_(angd, engd, x, y, z__);
        rlatn = f_out;
        rlongn = l_out;
        alt = h_out;
        
        tmp_(rlatn, rlongn, angd, engd);
        this.x_out = east_out;
        this.y_out = nort_out;
        gon = g_out;
        kap = k_out;
    }


    this.ComputeXY2LF = ComputeXY2LF;
    function ComputeXY2LF(x_in, y_in)
    {
        var c__ = .017453292519943295;
        /* REMEMBER TO CHECK THE PARAMETERS IN THE FOLLOWING LINES */
        /*       a=6377397.155d0  * Bessel parameters */
        /*       e=0.0066943800d0 */
        /*       **************** ED50 parameters */
        var aed50 = 6378388.0;
        var eed50 = 0.00672267;
        /*       open(1,file='ed50-egs.prn',status='unknown') */
        /*       **************** NGGD parameters */
        var angd = 6378137.0;
        var engd = 0.00669438;
        var cm = 24.0;
        var latout, long__, a = 0, e = 0;
        var x, y, z__;
        invtmp_(angd, engd, x_in, y_in, cm);
        latout = latout_out;
        long__ = long___out;
        
        flhxyz_(latout, long__, c_b8, angd, engd);
        x = x_out;
        y = y_out;
        z__ = z_out;

        /* NEW UPDATED PARAMETERS BELOW These Parameters are from EGSA87 to WGS84 !!!!!! */
        var dx = -199.723;
        var dy = 74.03;
        var dz = 246.018;
        x += dx;
        y += dy;
        z__ += dz;
        var rlatn, rlongn, alt;
        xyzflh_(angd, engd, x, y, z__);
        rlatn = f_out;
        rlongn = l_out;
        alt = h_out;
        
        //tmp_(&rlatn, &rlongn, &angd, &engd, &xti, &yti, &gon, &kap);
        /*     Transformation of Lat,Long from radians to Decimal degrees */
        this.l_out = rlatn / c__;
        this.f_out = rlongn / c__;
    }
}