<?php     # -*- PHP -*-
$OTHERURI="kkj-wgs84.php?LANG=other";
$NOCACHE=1;
require("../include/head1.inc");

langfilt('FI:
FI:Viestikallion työkaluja: KKJ/WGS84/Maidenhead
EN:Viestikallio Tools: KKJ/WGS84/Maidenhead');
require("../include/head2.inc");
langfilt('FI:
FI:Viestikallion työkaluja: KKJ/WGS84/Maidenhead
EN:Viestikallio Tools: KKJ/WGS84/Maidenhead');
include("../include/head3.inc");
include("../include/menu.inc");

printf("<TABLE><TR><TD>\n");


if ($HTTP_GET_VARS["SOURCE"] != "" || $HTTP_GET_VARS["source"] != "") {
    printf("\n<FONT SIZE=1>\n");
    highlight_file("kkj-wgs84.php");
    printf("</FONT>\n");
    printf("</TD></TR></TABLE><P><HR><P>Matti Aarnio" .
         " - OH2MQK &lt;matti.aarnio&#64;zmailer.org&gt;\n");
    include("../include/base.inc");
    include("../include/foot.inc"); 
    exit;
}


require("kkj-funcs.php");
require("geodinver.php");
require("maidenheadfuncs.php");


$DoTest = 0;
if ($HTTP_GET_VARS["TEST"] != "" || $HTTP_GET_VARS["test"] != "") {
    $DoTest = 1;
}
$DoKKJ  = 0;
$DoLaLo = 0;
$DoLaLoWGS = 0;
$Debug  = 0;
$DoMaidenhead = 0;

if ($HTTP_GET_VARS["DO-KKJ"] != "" || $HTTP_GET_VARS["do-kkj"] != "") {
    $DoKKJ = 1;
}
if ($HTTP_POST_VARS["DO-KKJ"] != "" || $HTTP_POST_VARS["do-kkj"] != "") {
    $DoKKJ = 1;
}
if ($HTTP_GET_VARS["DO-LALO"] != "" || $HTTP_GET_VARS["do-lalo"] != "") {
    $DoLaLo = 1;
}
if ($HTTP_POST_VARS["DO-LALO"] != "" || $HTTP_POST_VARS["do-lalo"] != "") {
    $DoLaLo = 1;
}
if ($HTTP_GET_VARS["DOWLALO"] != "" || $HTTP_GET_VARS["dowlalo"] != "") {
    $DoLaLo = 1;
    $DoLaLoWGS = 1;
}
if ($HTTP_POST_VARS["DOWLALO"] != "" || $HTTP_POST_VARS["dowlalo"] != "") {
    $DoLaLo = 1;
    $DoLaLoWGS = 1;
}

$MHDIGITS = 0 + $HTTP_POST_VARS["MHDIGITS"];
if ($MHDIGITS == "") {
    $MHDIGITS = 0 + $HTTP_GET_VARS["MHDIGITS"];
}
if ($MHDIGITS == "") {
    $MHDIGITS = 0 + $HTTP_GET_VARS["mhdigits"];
}

if ($MHDIGITS == 0) {
    $MHDIGITS = 10;
}


if ($HTTP_GET_VARS["DO-MH"] != "" || $HTTP_GET_VARS["do-mh"] != "") {
    $DoMaidenhead = 1;
}
if ($HTTP_POST_VARS["DO-MH"] != "" || $HTTP_POST_VARS["do-mh"] != "") {
    $DoMaidenhead = 1;
}

if ($HTTP_GET_VARS["Debug"] != "") {
    $Debug = 1;
}
if ($HTTP_POST_VARS["Debug"] != "") {
    $Debug = 1;
}

if ($Debug) {                   # TEST TEST!

    echo("<FONT SIZE=1><PRE>\n");
    echo("---------- Headers  --------------\n");
    $headers = getallheaders();
    for(reset($headers); $key = key($headers); next($headers)) {
        echo("$key = $headers[$key]\n");
    }
    echo("---------- GET VARS --------------\n");
    $headers = $HTTP_GET_VARS;
    for(reset($headers); $key = key($headers); next($headers)) {
        echo("$key = $headers[$key]\n");
    }
    echo("---------- POST VARS -------------\n");
    $headers = $HTTP_POST_VARS;
    for(reset($headers); $key = key($headers); next($headers)) {
        echo("$key = $headers[$key]\n");
    }
    echo("----------------------------------\n");
    echo("</PRE></FONT>\n");
}


$KKJin[X] = $HTTP_POST_VARS["KKJP"];
$KKJin[Y] = $HTTP_POST_VARS["KKJI"];
if ($KKJin[X] == "") {
    $KKJin[X] = $HTTP_GET_VARS["KKJP"];
    $KKJin[Y] = $HTTP_GET_VARS["KKJI"];
}

if ($KKJin[X] == "") {
    $KKJin[X] = "6500000.000";
    $KKJin[Y] = "3500000.000";
}

$WGSMH  = $HTTP_POST_VARS["WGSMH"];
if ($WGSMH == "")
    $WGSMH  = $HTTP_GET_VARS["WGSMH"];

$KKJin[La] = $HTTP_POST_VARS["KKJLAT"];
$KKJin[Lo] = $HTTP_POST_VARS["KKJLONG"];

if ($KKJin[La] == "") {
    $KKJin[La] = $HTTP_GET_VARS["KKJLAT"];
    $KKJin[Lo] = $HTTP_GET_VARS["KKJLONG"];
}

if ($KKJin[La] == "") {
    $KKJin[La] = "60  0  0.00000";
    $KKJin[Lo] = "27  0  0.00000";
}

$WGSin[La] = $HTTP_POST_VARS["WGSLAT"];
$WGSin[Lo] = $HTTP_POST_VARS["WGSLONG"];

if ($WGSin[La] == "") {
    $WGSin[La] = $HTTP_GET_VARS["WGSLAT"];
    $WGSin[Lo] = $HTTP_GET_VARS["WGSLONG"];
}

if ($WGSin[La] == "") {
    $WGSin[La] = "60  0  0.00000";
    $WGSin[Lo] = "27  0  0.00000";
}

#
#   printf("\nInput:  KKJP = '%s'    KKJI = '%s'\n",
#          $KKJ[X],$KKJ[Y]);
#
#   echo("</PRE>\n");

########  TEST STUFF ########

function KKJ_LaLo_test($la1,$la2,$la3,
                       $lo1,$lo2,$lo3,$P0,$I0) {

    $WGS[La]  = deg2rad(dms2deg($la1,$la2,$la3));
    $WGS[Lo]  = deg2rad(dms2deg($lo1,$lo2,$lo3));

    printf("\nTEST CASE:  %s  %s\n",
           fmtdms($WGS[La],1), fmtdms($WGS[Lo],0));

    global $Long0;
    global $ZoneNumber;

    $ED5w = WGSLaLo_to_WGSxy($WGS, $ZoneNumber, $Long0);
    $KKJ  = WGSxy_to_KKJ($ED5w);

#         $ED5w = KKJLaLo_to_KKJxy($WGS,$Long0);
#         $KKJ  = ED50xy_to_KKJ($ED5w);

    printf("   ED50w   P = %8.1f    I = %8.1f\n",
           $ED5w[X], $ED5w[Y]);
    printf("   KKJ     P = %8.1f    I = %8.1f\n",
           $KKJ[X],  $KKJ[Y]);
        
    printf("Should be: P =  %.3f  I =  %.3f\n",
           $P0,$I0);
    printf("          dP = %8.3f dI = %8.3f\n",
           $KKJ[X]-$P0,$KKJ[Y]-$I0);
}

if ($DoTest) {

    echo("<PRE>\n\n");
    echo("  Testing the algorithms:\n");
    printf("TEST CASE:  N  60°44'25.5072\"".
           "  E 26°10'35.6438\"\n");


    $ED50[La] = deg2rad(dms2deg( 60,44,25.5072));
    $ED50[Lo] = deg2rad(dms2deg( 26,10,35.6438));
    $WGS[La]  = deg2rad(dms2deg( 60,44,26.6   ));
    $WGS[Lo]  = deg2rad(dms2deg( 26,10,24.2   ));

    printf("  fmt:      %s  %s\n",
           fmtdms($ED50[La],1), fmtdms($ED50[Lo],0));
    printf("  fmt:      %s  %s\n",
           fmtdms($WGS[La],1),  fmtdms($WGS[Lo],0));

    $ED5  = KKJLaLo_to_KKJxy($ED50, $ZoneNumber, $Long0);
    $ED5w = WGSLaLo_to_WGSxy($WGS,  $ZoneNumber, $Long0);
    $KKJ  = ED50xy_to_KKJ($ED5);

    printf("   WGSxy   P = %8.1f    I = %8.1f\n",
           $ED5w[X], $ED5w[Y]);
    printf("   KKJ     P = %8.1f    I = %8.1f\n",
           $KKJ[X],  $KKJ[Y]);
    printf("   ED50xy  P = %8.1f    I = %8.1f\n",
           $ED5[X],  $ED5[Y]);
    $P0 = 6737009.924; $I0 = 3455081.597;
    printf("Should be: P =  %.3f  I =  %.3f\n",
           $P0,$I0);
    printf("          dP = %8.3f dI = %8.3f\n",
           $ED5[X]-$P0,$ED5[Y]-$I0);


    KKJ_LaLo_test(63,46, 4.7071, 27,38,30.5830, 7074280.405, 3531837.668);
    KKJ_LaLo_test(60,13, 2.8760, 24,23,40.1880, 6681284.022, 3355761.859);

    KKJ_LaLo_test(60, 0, 0.0001, 20, 0, 0.0000, 6674883.03,  3110054.63 );
    KKJ_LaLo_test(60, 0, 0.0001, 27, 0, 0.0000, 6654203.70,  3500168.98 );
    KKJ_LaLo_test(60, 0, 0.0001, 32, 0, 0.0000, 6664747.91,  3778993.05 );


    KKJ_LaLo_test(70, 0, 0.0001, 20, 0, 0.0000, 7784451.51,  3233376.02 );
    KKJ_LaLo_test(70, 0, 0.0001, 27, 0, 0.0000, 7769113.61,  3500171.81 );
    KKJ_LaLo_test(70, 0, 0.0001, 32, 0, 0.0000, 7776941.00,  3690918.66 );

    printf("\n</PRE>\n");
    
    printf("</TD></TR></TABLE><P><HR><P>Matti Aarnio" .
         " - OH2MQK &lt;matti.aarnio&#64;zmailer.org&gt;\n");
    include("../include/base.inc");
    include("../include/foot.inc"); 
    exit;
}                               # end of '$DoTest'

?>


<P>

<HR><A NAME="KKJ-PI"></A>
<?php intlinks(); ?>
<FORM ACTION="kkj-wgs84.php#KKJ-PI" METHOD=POST>
<?php langfilt('
FI: <H3>KKJ P/I koordinaatit:</H3>
FI: <I>Määritelty vain Suomen alueella!</I>
EN: <H3>KKJ P/I coordinates:</H3>
EN: <I>Defined only within Finland!</I>'); ?><P>
<I>&nbsp;&nbsp;Format: 60000000.000 3500000.000</I> <P>
&nbsp;&nbsp; P:
  <INPUT TYPE="text" NAME="KKJP" SIZE=12
         VALUE="<?php echo("$KKJin[X]"); ?>">
&nbsp;&nbsp; I:
  <INPUT TYPE="text" NAME="KKJI" SIZE=12
         VALUE="<?php echo("$KKJin[Y]"); ?>">
<P>
  &nbsp;&nbsp;&nbsp;&nbsp;MH code: <?php  form_mh_digits($MHDIGITS); ?>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Debug:
  <INPUT TYPE="checkbox" NAME="Debug"<?php if($Debug)echo(" CHECKED"); ?>>
<BR>
<INPUT TYPE="submit" NAME="DO-KKJ" VALUE="<?php langfilt('FI:
FI:Muunna KKJ-&gt;WGS84/MH
EN:Convert KKJ-&gt;WGS84/MH') ?>">
</FORM>
<?php

# Input mode: KKJ P/I

if ($DoKKJ) {

    echo("<HR WIDTH=\"49%\" ALIGN=CENTER>");

    echo("KKJ-P/I -&gt; WGS84/MH:");


    $ZoneNumber = (integer)($KKJin[Y]/1000000.0);
    $Long0 = 0.0;
    switch ($ZoneNumber) {
    case 1:
        $Long0 = 21.0;
        break;
    case 2:
        $Long0 = 24.0;
        break;
    case 3:
        $Long0 = 27.0;
        break;
    case 4:
        $Long0 = 30.0;
        break;
    default:
        break;
    }

    if ($LANG == "fi") {
        printf("&nbsp;&nbsp;Kaistanumero: %d &nbsp; Keskimeridiaani: %d° Itään\n",
               $ZoneNumber, $Long0);
    } else {
        printf("&nbsp;&nbsp;Zone number: %d &nbsp; Mid Line Meridian: %d° East\n",
               $ZoneNumber, $Long0);
    }

    $Long0 = deg2rad($Long0);

    printf("<PRE>\n");

    if ($Long0 == 0.0 || ($KKJin[X] < 6600000 || $KKJin[X] > 7900000))
        echo("<FONT COLOR=RED>BAD INPUT! BAD INPUT!</FONT>\n");


#   $ED50w = KKJ_to_WGSxy($KKJin);
#
#   printf("  ED50[P] = %.1f  ED50[I] = %.1f\n",
#         $ED50w[X],$ED50w[Y]);
#
##  $KKJin[Y] -= $IOffset;
##  $ED50 = KKJ_to_WGSxy($KKJin);
##  $ED50[Y] += $IOffset;
##  printf(" Meridian I offset: %.0f\n",$IOffset);
##  printf("  ED50[P] = %.1f  ED50[I] = %.1f\n",
##       $ED50[X],$ED50[Y]);

    $KKJz = KKJxy_to_KKJlalo($KKJin, $ZoneNumber, $Long0);

    # $WGS  = KKJxy_to_WGSlalo($KKJin, $KKJz, $ZoneNumber, $Long0);
    $WGS = KKJlalo_to_WGSlalo($KKJz);

    WithinFinland($WGS,1);

    echo("\n");

    printf("KKJ:    %s  %s\n",
           fmtdms($KKJz[La],1), fmtdms($KKJz[Lo],0));
    printf("KKJ:    %s  %s\n",
           fmtdmm($KKJz[La],1), fmtdmm($KKJz[Lo],0));
    printf("KKJ:    %s  %s\n",
           fmtddd($KKJz[La],1), fmtddd($KKJz[Lo],0));

    echo("\n");

    printf("WGS84:  %s  %s\n",
           fmtdms($WGS[La],1), fmtdms($WGS[Lo],0));
    printf("WGS84:  %s  %s\n",
           fmtdmm($WGS[La],1), fmtdmm($WGS[Lo],0));
    printf("WGS84:  %s  %s\n",
           fmtddd($WGS[La],1), fmtddd($WGS[Lo],0));

    echo("\n");

    $ZN = $ZoneNumber; $LL0 = $Long0;

    langfilt('FI:
FI:</PRE>KKJ kaistoittain: (KKJ-N/E -&gt; KKJ-P/I)<BR>
FI:Keskimeridianit kaistoittain: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>
EN:</PRE>In all KKJ zones: (KKJ-N/E -&gt; KKJ-P/I)<BR>
EN:Midmeridians by zones: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>');

    for ($ZoneNumber = 1; $ZoneNumber < 5; ++$ZoneNumber) {

        #   if ($ZoneNumber == $ZN) continue;

        $Long0 = deg2rad($ZoneNumber*3.0 + 18.0);

        $KKJw = KKJLaLo_to_KKJxy($KKJz, $ZoneNumber, $Long0);

        printf("%s %d  P = %8.3f  I = %8.3f\n",
               ($LANG == "fi") ? "Kaista  " : "KKJ Zone",
               $ZoneNumber, $KKJw[X],  $KKJw[Y]);
        if ($ZoneNumber == $ZN) {
            printf(" Delta:         %8.3f      %8.3f\n",
                   $KKJw[X]-$KKJin[X], $KKJw[Y]-$KKJin[Y]);
        }

    }


#       $ZoneNumber = $ZN; $Long0 = $LL0;
#
#       if ($LANG == "fi") {
#           echo("\n</PRE>Tarkastuslasku: (WGS84 -&gt; KKJ)<PRE>\n");
#       } else {
#           echo("\n</PRE>Verification: (WGS84 -&gt; KKJ)<PRE>\n");
#       }
#       $KKJw = WGSLaLo_to_WGSxy($WGS, $ZoneNumber, $Long0);
#       $KKJv = WGSxy_to_KKJ($KKJw);
#
#       printf("   KKJ      P = %8.3f  I = %8.3f\n",
#              $KKJv[X],  $KKJv[Y]);
#       printf("   Delta        %8.3f      %8.3f\n",
#              $KKJv[X] - $KKJ[X], $KKJv[Y] - $KKJ[Y]);

    echo("\n");

    $MH = LaLo_to_maidenhead($WGS);
    $hMH = highlight_mh($MH, $MHDIGITS);
    printf("WGS <A HREF=\"maidenheadfuncs.php?source=1\">Maidenhead</A>:  %s\n",
           $hMH);

    $kkjMH = LaLo_to_maidenhead($KKJz);
    $kkjhMH = highlight_mh($kkjMH, $MHDIGITS);
    printf("(KKJ Maidenhead: %s)\n",$kkjhMH);

    echo("\n");

    mh_edge_distance($WGS, $MH);

    echo("</PRE>\n");

}                               # End if '$DoKKJ' 

?>


<P>

<HR><A NAME="KKJ-LALO"></A>
<?php intlinks(); ?>
<P>
<FORM ACTION="kkj-wgs84.php#KKJ-LALO" METHOD=POST>
<?php langfilt('FI:
FI: <H3>KKJ maantieteelliset koordinaatit:</H3>
FI: <I>Määritelty vain Suomen alueella!</I><P>
FI: Maantieteellisillä koordinaateilla pohjoinen ja itä ovat positiivisia,
FI: etelä ja länsi ovat negatiivisia.
EN: <H3>KKJ geographic coordinates:</H3>
EN: <I>Defined only within Finland!</I><P>
EN: With the geographic coordinates north and east are positive,
EN: south and west are negative.'); ?><P>
<I>&nbsp;&nbsp;Format: dd mm ss.ssss  /  dd mm.mmmmmm / dd.dddddddd</I> <P>
&nbsp;&nbsp;
<?php langfilt('FI:Leveysaste:
EN:Latitude:'); ?>
  <INPUT TYPE="text" NAME="KKJLAT" SIZE=14
         VALUE="<?php echo("$KKJin[La]"); ?>">
&nbsp;&nbsp;
<?php langfilt('FI:Pituusaste:
EN:Longitude:'); ?>
  <INPUT TYPE="text" NAME="KKJLONG" SIZE=14
         VALUE="<?php echo("$KKJin[Lo]"); ?>">
<P>
 &nbsp;&nbsp;&nbsp;&nbsp;MH code:
<?php  form_mh_digits($MHDIGITS); ?>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Debug:
  <INPUT TYPE="checkbox" NAME="Debug"<?php if($Debug)echo(" CHECKED"); ?>>
<BR>
<INPUT TYPE="submit" NAME="DO-LALO" VALUE="<?php langfilt('FI:
FI:Muunna KKJ-&gt;WGS84/MH
EN:Convert KKJ-&gt;WGS84/MH') ?>">
</FORM>
<?php

# Input mode: KKJ Lat/Long

if ($DoLaLo && !$DoLaLoWGS) {

    echo("<HR WIDTH=\"49%\" ALIGN=CENTER>");

    echo("KKJ Lat/Long -&gt; P/I\n");

    echo("<PRE>\n\n");

    $Lat  = deg2rad(parsedms($KKJin[La]));
    $Long = deg2rad(parsedms($KKJin[Lo]));

    printf("KKJ:    %s  %s\n",
           fmtdms($Lat,1), fmtdms($Long,0));
    printf("KKJ:    %s  %s\n",
           fmtdmm($Lat,1), fmtdmm($Long,0));
    printf("KKJ:    %s  %s\n",
           fmtddd($Lat,1), fmtddd($Long,0));

    $KKJlalo[La] = $Lat;
    $KKJlalo[Lo] = $Long;

    WithinFinland($KKJlalo,1);

    langfilt('FI:
FI:</PRE>KKJ kaistoittain: (KKJ-N/E -&gt; KKJ-P/I)<BR>
FI:Keskimeridianit kaistoittain: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>
EN:</PRE>In all KKJ zones: (KKJ-N/E -&gt; KKJ-P/I)<BR>
EN:Midmeridians by zones: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>');

    for ($i = 1; $i < 5; ++$i) {

        $Long0 = deg2rad($i * 3.0 + 18.0);
        $KKJ = KKJLaLo_to_KKJxy($KKJlalo, $i, $Long0);

        printf("%s %d  P = %8.3f  I = %8.3f\n",
               ($LANG == "fi") ? "Kaista  " : "KKJ Zone",
               $i, $KKJ[X],  $KKJ[Y]);
    }

    echo("\n");

    $WGS = KKJlalo_to_WGSlalo($KKJlalo);

    printf("WGS84:  %s  %s\n",
           fmtdms($WGS[La],1), fmtdms($WGS[Lo],0));
    printf("WGS84:  %s  %s\n",
           fmtdmm($WGS[La],1), fmtdmm($WGS[Lo],0));
    printf("WGS84:  %s  %s\n",
           fmtddd($WGS[La],1), fmtddd($WGS[Lo],0));

    echo("\n");

    $MH = LaLo_to_maidenhead($WGS);
    $hMH = highlight_mh($MH, $MHDIGITS);
    printf("WGS <A HREF=\"maidenheadfuncs.php?source=1\">Maidenhead</A>:  %s\n",
           $hMH);

    $kkjMH = LaLo_to_maidenhead($KKJlalo);
    $kkjhMH = highlight_mh($kkjMH, $MHDIGITS);
    printf("(KKJ Maidenhead: %s)\n", $kkjhMH);

    echo("\n");

    mh_edge_distance($WGS, $MH);

    echo("</PRE>\n");
}

?>

<P>

<HR><A NAME="WGS-LALO"></A>
<?php intlinks(1); ?>
<P>
<FORM ACTION="kkj-wgs84.php#WGS-LALO" METHOD=POST>
<?php langfilt('FI:
FI: <H3>WGS84 maantieteelliset koordinaatit:</H3>
FI: <I>Maailmanlaajuinen.</I><P>
FI: Maantieteellisillä koordinaateilla pohjoinen ja itä ovat positiivisia,
FI: etelä ja länsi ovat negatiivisia.
EN: <H3>WGS84 geographic coordinates:</H3>
EN: <I>Global scope.</I><P>
EN: With the geographic coordinates north and east are positive,
EN: south and west are negative.');  ?><P>
<I>&nbsp;&nbsp;Format: dd mm ss.ssss  /  dd mm.mmmmmm / dd.dddddddd</I> <P>
&nbsp;&nbsp;
<?php langfilt('FI:Leveysaste:
EN:Latitude:'); ?>
  <INPUT TYPE="text" NAME="WGSLAT" SIZE=14
         VALUE="<?php echo("$WGSin[La]"); ?>">
&nbsp;&nbsp;
<?php langfilt('FI:Pituusaste:
EN:Longitude:'); ?>
  <INPUT TYPE="text" NAME="WGSLONG" SIZE=14
         VALUE="<?php echo("$WGSin[Lo]"); ?>">
<P>
 &nbsp;&nbsp;&nbsp;&nbsp;MH code:
<?php  form_mh_digits($MHDIGITS); ?>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Debug:
  <INPUT TYPE="checkbox" NAME="Debug"<?php if($Debug)echo(" CHECKED"); ?>>
<BR>
<INPUT TYPE="submit" NAME="DOWLALO" VALUE="<?php langfilt('FI:
FI:Muunna WGS84-&gt;KKJ/MH
EN:Convert WGS84-&gt;KKJ/MH') ?>">
</FORM>
<?php

# Input mode:  WGS84 Lat/Long

if ($DoLaLoWGS) {

    echo("<HR WIDTH=\"49%\" ALIGN=CENTER>");


    echo("WGS Lat/Long -&gt; KKJ P/I\n");

    echo("<PRE>\n\n");

    $Lat  = deg2rad(parsedms($WGSin[La]));
    $Long = deg2rad(parsedms($WGSin[Lo]));

    printf("WGS:    %s  %s\n",
           fmtdms($Lat,1), fmtdms($Long,0));
    printf("WGS:    %s  %s\n",
           fmtdmm($Lat,1), fmtdmm($Long,0));
    printf("WGS:    %s  %s\n",
           fmtddd($Lat,1), fmtddd($Long,0));

    $WGS[La] = $Lat;
    $WGS[Lo] = $Long;

    if (WithinFinland($WGS,1)) {

        $KKJlalo = WGSlalo_to_KKJlalo($WGS);

    langfilt('FI:
FI:</PRE>KKJ kaistoittain: (KKJ-N/E -&gt; KKJ-P/I)<BR>
FI:Keskimeridianit kaistoittain: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>
EN:</PRE>In all KKJ zones: (KKJ-N/E -&gt; KKJ-P/I)<BR>
EN:Midmeridians by zones: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>');

        for ($i = 1; $i < 5; ++$i) {

            $Long0 = deg2rad($i * 3.0 + 18.0);
            $KKJ = KKJLaLo_to_KKJxy($KKJlalo, $i, $Long0);

            printf("%s %d  P = %8.3f  I = %8.3f\n",
                   ($LANG == "fi") ? "Kaista  " : "KKJ Zone",
                   $i, $KKJ[X],  $KKJ[Y]);
        }

        echo("\n");

        printf("KKJ:  %s  %s\n",
               fmtdms($KKJlalo[La],1), fmtdms($KKJlalo[Lo],0));
        printf("KKJ:  %s  %s\n",
               fmtdmm($KKJlalo[La],1), fmtdmm($KKJlalo[Lo],0));
        printf("KKJ:  %s  %s\n",
               fmtddd($KKJlalo[La],1), fmtddd($KKJlalo[Lo],0));

    }

    echo("\n");

    $MH = LaLo_to_maidenhead($WGS);
    $hMH = highlight_mh($MH, $MHDIGITS);
    printf("<A HREF=\"maidenheadfuncs.php?source=1\">Maidenhead</A>:  %s\n",
           $hMH);

    if (WithinFinland($WGS,1)) {
    $kkjMH = LaLo_to_maidenhead($KKJlalo);
    $kkjhMH = highlight_mh($kkjMH, $MHDIGITS);
    printf("(KKJ Maidenhead: %s)\n", $kkjhMH);
    }

    echo("\n");

    mh_edge_distance($WGS, $MH);

    echo("</PRE>\n");
}

?>
<P>

<HR><A NAME="Maidenhead"></A>
<?php intlinks(1); ?>
<P>
<FORM ACTION="kkj-wgs84.php#Maidenhead" METHOD=POST>
<?php langfilt('FI:
FI: <H3>WGS84 Maidenhead:</H3>
FI: <I>Maailmanlaajuinen ruudukko.</I><P>
FI: <A HREF="maidenheadfuncs.php?source=1">[A-R][A-R][0-9][0-9][A-X][A-X][0-9][0-9][A-X][A-X]...<BR>
FI: <I>([Pit][Lev][Pit][Lev][Pit][Lev]...)</I></A>
EN:  <H3>Maidenhead:</H3>
EN: <I>Global scope grid.</I><P>
EN: <A HREF="maidenheadfuncs.php?source=1">[A-R][A-R][0-9][0-9][A-X][A-X][0-9][0-9][A-X][A-X]...<BR>
EN: <I>([Lon][Lat][Lon][Lat][Lon][Lat]...)</I></A>

<P>
  <I>&nbsp;&nbsp;
FI:Esimerkkejä:
EN:Examples:

"KP30" / "KP30CR" / "KP30CR56" / "KP30CR56HF"</I>
<P>
&nbsp;&nbsp; Maidenhead:'); ?>
  <INPUT TYPE="text" NAME="WGSMH" SIZE=18
         VALUE="<?php echo("$WGSMH"); ?>">
<P>
<!--  &nbsp;&nbsp;&nbsp;&nbsp;MH code:
     <?php  form_mh_digits($MHDIGITS); ?> -->
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Debug:
  <INPUT TYPE="checkbox" NAME="Debug"<?php if($Debug)echo(" CHECKED"); ?>>
<BR>
<INPUT TYPE="submit" NAME="DO-MH" VALUE="<?php langfilt('FI:
FI:Muunna MH-&gt;WGS84/KKJ
EN:Convert MH-&gt;WGS84/KKJ') ?>">
</FORM>
<P>
<?php

# Input mode:  MAIDENHEAD

if ($DoMaidenhead) {


    echo("<HR WIDTH=\"49%\" ALIGN=CENTER>");

    echo("MAIDENHEAD -&gt; WGS84 / KKJ\n");
    echo("<PRE>\n\n");

    if ($LANG == "fi")
        printf("Syöte: '%s'\n\n", $WGSMH);
    else
        printf("Input: '%s'\n\n", $WGSMH);

    $MH = parsemaidenhead($WGSMH);
    $MHDIGITS = strlen($WGSMH);

    if ($MH[La] && $MH[Lo] && $MH[dLa] && $MH[dLo]) {


    langfilt('FI:
FI:Ruudun keskikohta:
EN:Grid square centre:

');

        printf("  WGS84:  %s  %s\n",
               fmtdms($MH[La],1), fmtdms($MH[Lo],0));
        printf("  WGS84:  %s  %s\n",
               fmtdmm($MH[La],1), fmtdmm($MH[Lo],0));
        printf("  WGS84:  %s  %s\n",
               fmtddd($MH[La],1), fmtddd($MH[Lo],0));

        echo("\n");

    langfilt('FI:
FI:Ruudun puolikorkeus/puolileveys:
EN:Grid square half-height/half-width:

');

        printf("  Delta:  %s  %s\n",
               fmtdms($MH[dLa],1), fmtdms($MH[dLo],0));
        printf("  Delta:  %s  %s\n",
               fmtdmm($MH[dLa],1), fmtdmm($MH[dLo],0));
        printf("  Delta:  %s  %s\n",
               fmtddd($MH[dLa],1), fmtddd($MH[dLo],0));

        echo("\n");

        $KKJtest[La] = $MH[La];
        $KKJtest[Lo] = deg2rad(27.0);
        $KKJ3 = KKJLaLo_to_KKJxy($KKJtest, 3, deg2rad(27.0));
        $KKJtestP[La] = $KKJtest[La] + $MH[dLa];
        $KKJtestP[Lo] = $KKJtest[Lo];
        $KKJtest3 = KKJLaLo_to_KKJxy($KKJtest, 3, deg2rad(27.0));
        $KKJtestI[La] = $KKJtest[La];
        $KKJtestI[Lo] = $KKJtest[Lo] + $MH[dLo];
        $KKJtest3P = KKJLaLo_to_KKJxy($KKJtestP, 3, deg2rad(27.0));
        $KKJtest3I = KKJLaLo_to_KKJxy($KKJtestI, 3, deg2rad(27.0));


        printmhdimensions($KKJtest3P[X] - $KKJ3[X],
                          $KKJtest3I[Y] - $KKJ3[Y]);


    langfilt('FI:
FI:<P ALIGN=CENTER><IMG SRC=mh-ruutu.gif></P>
EN:<P ALIGN=CENTER><IMG SRC=mh-square.gif></P>

');


        mh_edge_distance($MH, $WGSMH); # WARNING!
        # DIFFERENT TO ALL OTHER INSTANCES!

        echo("\n");

        if (WithinFinland($MH,1)) {

            $KKJlalo = WGSlalo_to_KKJlalo($MH);

            printf("KKJ:    %s  %s\n",
                   fmtdms($KKJlalo[La],1), fmtdms($KKJlalo[Lo],0));
            printf("KKJ:    %s  %s\n",
                   fmtdmm($KKJlalo[La],1), fmtdmm($KKJlalo[Lo],0));
            printf("KKJ:    %s  %s\n",
                   fmtddd($KKJlalo[La],1), fmtddd($KKJlalo[Lo],0));


    langfilt('FI:
FI:</PRE>KKJ kaistoittain: (KKJ-N/E -&gt; KKJ-P/I)<BR>
FI:Keskimeridianit kaistoittain: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>
EN:</PRE>In all KKJ zones: (KKJ-N/E -&gt; KKJ-P/I)<BR>
EN:Midmeridians by zones: 1: 21° &nbsp; 2: 24° &nbsp; 3: 27° &nbsp; 4: 30°<PRE>');

            for ($i = 1; $i < 5; ++$i) {

                $Long0 = deg2rad($i * 3.0 + 18.0);
                $KKJ = KKJLaLo_to_KKJxy($KKJlalo, $i, $Long0);

                printf("%s %d  P = %8.3f  I = %8.3f\n",
                       ($LANG == "fi") ? "Kaista  " : "KKJ Zone",
                       $i, $KKJ[X],  $KKJ[Y]);
            }


        printf("\n");

    langfilt('**:
EN:</PRE>In case the input had wrong base coordinates:<PRE>
FI:</PRE>Jos inputissa olikin koordinaatistovikaa:<PRE>');

        # What if... the input was in KKJ ?
        $WGS = KKJlalo_to_WGSlalo($MH);
        $MH = LaLo_to_maidenhead($WGS);
        $hMH = highlight_mh($MH, $MHDIGITS);
        printf("KKJ->WGS Maidenhead:  %s\n", $hMH);

        $kkjMH = LaLo_to_maidenhead($KKJlalo);
        $kkjhMH = highlight_mh($kkjMH, $MHDIGITS);
        printf("(WGS->KKJ Maidenhead: %s)\n", $kkjhMH);

        }

    } else {
        echo("  ** INVALID INPUT ??? **\n\n");
    }

    echo("</PRE>\n");
}

?>

<P>
<HR>
<P>

<?php require("selitykset.php"); ?>

<P>
<HR>
<P>

<?php langfilt('

FI:<H3>Tämä työkalu koostuu useista lähdekoodimoduleista:</H3>
EN:<H3>This tool consists of following source components:</H3>

<UL>
 <LI><A HREF="kkj-wgs84.php?source=1">kkj-wgs84.php</A>:
FI:        Pääkoodi
EN:        The main code itself

 <LI><A HREF="kkj-funcs.php?source=1">kkj-funcs.php</A>:
FI:        Koordinaatistokäsittelyä, yms. yhteisiä juttuja
EN:        Common stuff, coordinate transformations, HTML things, etc.

 <LI><A HREF="maidenheadfuncs.php?source=1">maidenheadfuncs.php</A>:
FI:        Maidenhead hilan käsittelyä
EN:        Maidenhead grid coordinate processing

 <LI><A HREF="geodinver.php?source=1">geodinver.php</A>:
FI:        Geodeettisen käänteistehtävän matematiikka
FI:        (Haetaan etäisyys ja atsimuutit kahdelle annetulle
FI:        pisteelle ellipsoidilla.)
EN:        Mathematics for the "geodetic inverse" problem.
EN:        (Finding distance and Azimuth between two points
EN:         on an ellipsoid.)

 <LI><A HREF="selitykset.php?source=1">selitykset.php</A>:
FI:        Yllä näkyvät selitystekstit.
EN:        Explanations seen above...

</UL>
<P>
<HR>
<P>
');
include("../include/sign-oh2mqk.inc");

printf("<P></TD></TR></TABLE>\n");

include("../include/base.inc");
require("../include/foot.inc");
?>

Matti Aarnio - OH2MQK <matti.aarnio@zmailer.org>

 

Valid HTML 4.01! 	  	Z Elisa Communications
This page is Links enhanced for additional browsing pleasure.

