#
# perl script for netstumbler summary export files to import in Mappoint 2001 German Version
#
# wardriving.ch
# 
# release 1.0
#
#
#################
#
# file selection
#
#################

print "Enter filename: ";
my $filename =<>;
chomp $filename;
my $outputfile = ">Processed".$filename;
open IN, $filename or die "Cannot open ".$filename." for reading";
open OUT, $outputfile or die "Cannot open ".$outputfile." for writing";

#################
#
# file selection
#
# Writing Header Map-Point German needs: Breitengrad Längengrad Name Name2
#
#################

print "Processing............\n";
print OUT "Breitengrad\tLängengrad\tName\tName2\n";

#################
#
# read / processing / write Data
#
#################

while (<IN>)
{
chomp;
   if (m/^#/) 
      {
      print "Found a header line - skipping.\n";
      }
   else
      {
      ($Lat, $Long, $SSID, $MAC) = (split /\t/)[0,1,2,4]; 
      chomp $Lat, $Long, $SSID, $MAC;
      $Lat=~s/N /+/;   # replace N<SPACE> to +
      $Lat=~s/S /-/;   # replace S<SPACE> to -
      $Long=~s/W /-/;  # replace W<SPACE> to -
      $Long=~s/E /+/;  # replace E<SPACE> to +
      $SSID=~s/\(//;
      $SSID=~s/\)//;
      $MAC=~s/\(//;
      $MAC=~s/\)//;
      chomp $MAC, $SSID;

 
      print $Lat,"\t", $Long, "\t", $SSID,"\t", $MAC,"\n";
      print OUT $Lat,"\t", $Long, "\t", $SSID,"\t", $MAC,"\n";
      }
} 
#################
#
# cleanup
#
#################
print "Finished!\n";
close IN;
close OUT;
