eval 'exec perl -w -S $0 ${1+"$@"}'
    if 0;


#
# Converts unemap .txt files to Lammers tab delimited .txt files
#
# Essentially, remove first row and column and make tab delimited
#		

use strict;
use warnings;
use Getopt::Long;

#
# GetOptions from command line
#

my @usageline;
my $FILENAME;


$usageline[0]= "\n";
$usageline[1]= "txt2lammers.pl\n";
$usageline[2]= "  -inputfile   []\n";
$usageline[3]= "  -outputfile  [output.txt]\n";
$usageline[4]= "  -help\n";


my $usage = join (" ", @usageline);
my %options = ();
my @opt_specs = 
(
	"inputfile=s",
	"outpufile=s",
	"help",
);

GetOptions(\%options, @opt_specs); #splits the options from argv
if ($options{help})
{
    print "$usage \n";
    exit(0);
};

if(%options == 0) 
{
  print "$usage \n";
  exit(0);
}


if(@ARGV != 0 || %options == 0) 
{
  print "Unknown options were specified ...\n  @ARGV \n\n";
  print "$usage \n" if ($options{help});
  exit(0);
}



# 
#
# Setup the option flags
#
my $INPUTFILE  = defined($options{"inputfile"})  ? $options{"inputfile"}  : "--";
my $OUTPUTFILE = defined($options{"outputfile"}) ? $options{"outputfile"} : "output.txt";


#
# -------------------------------------------------------------------------
#


$FILENAME="$OUTPUTFILE";
open (OUTFILE,">$FILENAME") || die "Can't Open $FILENAME: $!\n";

$FILENAME="$INPUTFILE";
open (INFILE,"<$FILENAME") || die "Can't Open $FILENAME: $!\n";


$_=<INFILE>; # ignore the first line

while( <INFILE>) 
{
    my @LINE=split(" ");
    shift @LINE; #remove the first element (the time)

    #print with tab delimited
    printf OUTFILE join("\t",@LINE) . "\n";
}


