#!/usr/bin/perl
#  edit_MOLA_table.pl -- Similar to edit_PEDR_table.pl, but only outputs
#  latitudes and longitudes    

use Getopt::Std;
getopts('a:b:c:d:e:');

$usage = "edit_MOLA_table.pl -a <MOLA ASCII table> -b <minimum longitude> -c <maximum longitude> -d <minimum latitude> -e <maximum latitude>";

if (! ($opt_a && $opt_b && $opt_c && $opt_d && $opt_e)) { die "\nUsage: $usage\n\n"; }

open(MOLATABLE,"$opt_a") || die "Could not open file.\n";

while(<MOLATABLE>) {

  $line = $_;

  if ( $line =~ /^(\S+)\s+(\S+)\s/ ) {  #Grab the first two columns of data

     $longitude = $1;     
     $latitude = $2;
 

     if (( $longitude >= $opt_b ) && ( $longitude <= $opt_c ) && ( $latitude >= $opt_d ) && ( $latitude <= $opt_e )) {      #Check if the longitude and latitude
                                            #are within specified parameters
        print "$longitude\t$latitude\t1\n"; }   

  }

}

