Return to Snippet

Revision: 15731
at July 15, 2009 04:41 by vinocui


Initial Code
#!/path/to/perl
# [email protected]
# 2009/7/15
# tool for calibrate latitude & longitude in *.map files generated
# by TrekBuddy_Atlas_Creator_v1.1

my $line;
my $argc = @ARGV;

#   Actual:     N39°4'21.9"  E117°15'49.6"
#   Google Map: N39°4'26.3"  E117°16'13.6"

my $version = "090715";
print "cb: calibrate .map file the TrekBuddy_Atlas_Creator_v1.1 generated.\n";
my $bar = "VERSION: $version, vinocui\@gmail.com, twitter.com/vinocui\n";
if ($argc != 5){
    print $bar, "\n";
    print "Usage:\n";
    print "  " . __FILE__ . " ActualN ActualE MapN MapE xxx.map\n";
    print "  " . __FILE__ . " 39D4M21.9 117D15M49.6 39D4M26.3 117D16M13.6 xxx.map\n";
    print "39D4M21.9 means 39°4\'21.9\"\n";
    print "\nDescriptions: 
  ActualN: Actual North latitude
  ActualE: East longitude
     MapN: the North latitude of the right point in your Trekbuddy
     MapE: the East latitude of the right point in your Trekbbuddy.\n";

    exit 1;
}

$mapfile = $ARGV[4];
# A: Actual, M: Map. n:North, e: East
# 0,1,2,3 --> AN, AE, MN, ME.
my @D = ();
my @M = ();
my @S = ();

for($i = 0; $i < 4; $i++){
    my ($d, $a) = split(/D/, $ARGV[$i]);
    $D[$i] = $d;
    my ($m, $s) = split(/M/, $a);
    $M[$i] = $m;
    $S[$i] = $s;
    print $D[$i] . "°" . $M[$i] . '\'' . $S[$i] . '"'. "\n";
}

# A: Actual, M: Map. n:North, e: East
# 0,1,2,3 --> AN, AE, MN, ME.
my $nMcb = ($S[0]/60.0 + $M[0]) - ($S[2]/60.0 + $M[2]);
my $eMcb = ($S[1]/60.0 + $M[1]) - ($S[3]/60.0 + $M[3]);
my $nDcb = ($S[0]/60.0 + $M[0])/60.0 - ($S[2]/60.0 + $M[2])/60.0;
my $eDcb = ($S[1]/60.0 + $M[1])/60.0 - ($S[3]/60.0 + $M[3])/60.0;
print "N: ", $nMcb, "\'\n";
print "E: ", $eMcb, "\'\n";
print "N: ", $nDcb, "°\n";
print "E: ", $eDcb, "°\n";

open (INFILE, $mapfile ) or die "Could not open file";
open (BACKUPFILE, ">$mapfile.bak" ) or die "Could not open file";
select(BACKUPFILE);
while (my $line = <INFILE>){
    print $line;
}
close (BACKUPFILE);
close (INFILE);

open (INFILE, "$mapfile.bak" ) or die "Could not open file";
open (OUTFILE, ">$mapfile");
while (my $line = <INFILE>) {
    if($line =~ /Point01|Point02|Point03|Point04/g){
	my @segs = split(/\,/, $line);
	print $segs[7] . "N, " . $segs[10]. "E\n";

	for(my $i; $i<@segs; $i++){
	    my $v = 0.0;
	    if($i == 7){
		$segs[$i] = sprintf("%.6f", $segs[$i] + $nMcb);
	    }elsif($i == 10 ){
		$segs[$i] = sprintf("%.6f", $segs[$i] + $eMcb);
	    }
	    print OUTFILE $segs[$i];
	    if($i != (@segs - 1))
	    {
		print OUTFILE ",";
	    }
	}
	next;
    }

    if($line =~ /MMPLL/g){
	my @segs = split(/\,/, $line);
	chomp($segs[3]);
	print $segs[2], "E, " . $segs[3] . "N\n"; 
	for(my $i = 0; $i < @segs; $i++){
	    if ($i == 2){
		$segs[$i] = sprintf("%.6f", $segs[$i] + $eDcb);
	    }elsif($i == 3){
		$segs[$i] = sprintf("%.6f", $segs[$i] + $nDcb);
	    }
	    print OUTFILE $segs[$i];
	    if($i != (@segs - 1))
	    {
		print OUTFILE ",";
	    }else{
		print OUTFILE "\n";
	    }
	}
	next;
    }
    print OUTFILE $line;
}
close (INFILE);
close (OUTFILE);

Initial URL


Initial Description
OZIexplorer is hard to calibrate maps. And I need a tool to calibrate the .map files generated from TrekBuddy_Atlas_Creator_v1.1. So I wrote it.

Initial Title
Tool for calibrate latitude & longitude for OZI map file

Initial Tags


Initial Language
Perl