LogGen.pl 3.42 KB
#!/usr/bin/perl 

# DEPENDENCIES
use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm

require "./sub_cruiseinfo.pl" ;
require "./sub_getgps.pl" ;

# HEADER AND INSTRUCTIONS
print "========== ========== ==========  LogGen ========== ==========  ==========\n\n" ;

# ACQUIRE CRUISE INFORMATION
# cruise name
print ">> Enter cruise name					: " ;
chop($name = <STDIN>) ;
print "\n" ;

# set cruise directory
print ">> Enter cruise directory				: " ;
chop($folder = <STDIN>) ;
print "\n" ;

# SETUP GPS
$gps = sub_getgps() ;

# ASK FOR or READ CRUISE INFO
($ops,$sts,$numops,$numsts,$headerstring) = sub_cruiseinfo($name,$folder) ;

# SET PRINTING FORMAT
$frmt = "  \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ;

# DISPLAY AVAILABLE STATIONS and OPERATIONS 
print ">> AVAILABLE OPERATIONS ARE:\n";
foreach $line (@ops) { print ">>	$line\n"; }
print ">>	---\n\n" ;
print ">> PLANNED STATIONS     ARE:\n";
foreach $line (@sts) { print ">>	$line\n"; }
print ">>	---\n\n" ;

$pre = ">" ;
$cus = "none"  ;

# DEFAULT START HEADER
print "=============================================================================================\n" ;
print "=====			$headerstring				=====\n" ;
print "=============================================================================================\n\n> " ;

# RUNNING LOOP TO ADD TO CRUISE DATA FILE
while (<STDIN>) {

	chop( $_ ) ;
	@line = split( "=", $_ ) ;

	# POLL COMPUTER FOR TIME
	@time     = localtime ;
	$time[4]++ ; $time[5]+=1900 ;
	$mmddHHMM = sprintf "%02d/%02d  %02d:%02d",  @time[4], @time[3], @time[2], @time[1] ;

	# POLL GPS FOR COORDINATES
	($ns,$lat,$ew,$lon) = $gps->get_position ; 

	# THIS IS THE EXIT COMMAND
	if  ( $line[0] =~ /exit/) {last;} 

	# THIS IS A STATION ENTRY
	elsif ($line[0] =~ /st/) {

		if      ( $cus =~ /none/ ) { 			# case : we are currently off station
			$cus = $line[1] ;
			$pre = ">>" ;
			print "$pre\t\tNOW RECORDING STATION\t	$line[1],\t\t\t	TIME : $mmddHHMM\n" ;
			print "$pre\t\t\t\t\t\t\t\t\t\tLON  : $lon\n" ;
			print "$pre\t\t\t\t\t\t\t\t\t\tLAT  : $lat\n$pre " ;
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;

		} elsif ($cus =~ /$line[1]/) { 			# case : we are currently at this station
			$cus = "none" ;
			print "$pre\t\t\tEND OF STATION\t	$line[1],\t\t\t	TIME : $mmddHHMM\n>\n>\n> " ;
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
			$pre = ">" ;

		} else {					# case : we are currently at a different station
			printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
			print "$pre\t\t\tEND OF STATION\t	$cus,\t\t\t	TIME : $mmddHHMM\n>\n>\n" ;
			$cus = $line[1] ;
			print "$pre\t\tNOW RECORDING STATION\t	$line[1],\t\t\t	TIME : $mmddHHMM\n" ;
			print "$pre\t\t\t\t\t\t\t\t\t\tLON  : $lon\n" ;
			print "$pre\t\t\t\t\t\t\t\t\t\tLAT  : $lat\n$pre " ;
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
		}
	}
	# THIS IS A NEW LEG ENTRY
	elsif ($line[0] =~ /lg/) {
		$cul++ ;
		print ">\tNOW RECORDING LEG $cul\n> " ; 
	}

	# THIS IS AN OPERATION ENTRY
	elsif ($line[0] =~ /op/) {
		foreach $op (@ops) {
			if ($line[1] =~ /$op/) {
				print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n" ;
				print "$pre\t\t\t\t\t\t\t\t\t\tLON  : $lon\n" ;
				print "$pre\t\t\t\t\t\t\t\t\t\tLAT  : $lat\n$pre " ;
			}
		}	
	}

	# THIS IS A  COMMENT   ENTRY
	elsif  ($line[0] =~ /cm/) {
			print "$pre\t\t\tCOMMENT : $line[1] \n$pre " ;  
	}

	# UNRECOGNIZED INPUT
	else {print "$pre UNDEFINED INPUT \n$pre " ;} 

}

# CLOSE FILE HANDLES
close(OUT) ;