#!/usr/bin/perl

use Getopt::Std;
getopt('f:');

$usage = "161_72scale.pl -f <MOLA 3-column file>";

if (! $opt_f  ) { die "\nUsage: $usage\n\n"; }

open(FILE,"$opt_f") || die "Could not open file.\n";

while(<FILE>) {

	$line = $_;
        if ( $line =~ /^(.\d+\.\d+)\s+(\S+)\s+(\S+)\s/ ) {
           #Grab the first three columns of data

           $longitude = $1;
           $latitude = $2;
           $topography = $3;
  
           if ( $longitude =~ /\s(\d+\.\d+)/ )  {
               $longitude = $1; }   #Removes the whitespace from longitude

           if ( $longitude =~ /^161(\.\d+)/ )  {  
              $longitude= 0+$1;  }
           if ( $longitude =~ /^162(\.\d+)/ )  {
              $longitude= 1+$1; }
           if ( $longitude =~ /^163(\.\d+)/ )  {
              $longitude= 2+$1;  }
           if ( $longitude =~ /^164(\.\d+)/ )  {
              $longitude= 3+$1;  }
           if ( $longitude =~ /^165(\.\d+)/ )  {
              $longitude= 4+$1;  }
           if ( $longitude =~ /^166(\.\d+)/ )  {
              $longitude= 5+$1;  }
 

           if ( $latitude =~ /72(\.\d+)/ )  {
              $latitude= 0+$1;  }
           if ( $latitude =~ /73(\.\d+)/ )  {
              $latitude= 1+$1;  }

           if ($longitude <= 6)  { $longitude = $longitude /6; } else { $longitude = ($longitude - 161) / 6; }
           if ($latitude <=2) { $latitude  = $latitude / 2; } else { $latitude = ($latitude - 72) /2; }
           $longitude = $longitude * 6000;
           $latitude = $latitude * 2000;  


           print "$longitude\t$latitude\t$topography\n"; 

         }

}

close (<FILE>);
	
