#!/usr/bin/perl
# trim_PEDR_table.pl -- This program reads in a MOLA PEDR ASCII table, 
# and removes the headers as well as all data columns except latitude, 
# longitude, and topography. The output is to stdout.

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

$usage = "trim_PEDR_table.pl -a <PEDR ASCII table>";

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

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

while(<PEDRTABLE>) {

   $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

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