LogGen.pl 4.05 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" ;

# ASK FOR or READ CRUISE INFO
($ops,$sts,$gps,$gpson,$numops,$numsts,$headerstring,$stslat,$stslon) = sub_cruiseinfo() ;

# SET PRINTING FORMAT
$frmt = "%6s;%10.5f;%10.5f;%20s;%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" ;

# INITIAL VALUES
$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] ;
	$isotime  = sprintf "%s-%02s-%02sT%02s:%02s:%02sZ",reverse @time[0..5] ;

	# POLL GPS FOR COORDINATES
	if ($gpson) {
		# if gps is used, actual values are written
		($ns,$lat,$ew,$lon) = $gps->get_position ;
		if ($ns =~ /S/i) { $lat*=-1 ; }
		if ($ew =~ /W/i) { $lon*=-1 ; }
	 } else {
		# if no gps is used be we are on station, these coordinates a written 
		$lon = %stslon{$cus} ;
		$lat = %stslat{$cus} ;
	} 

	# 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   = ">>" ;
			if (not $gpson) { 
				$lon = %stslon{$cus} ;
				$lat = %stslat{$cus} ;
			}
			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],$lat,$lon,$isotime,$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],$lat,$lon,$isotime,$line[1] ;
			$pre = ">" ;

		} else {					# case : we are currently at a different station
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cus ;
			print "$pre\t\t\tEND OF STATION\t	$cus,\t\t\t	TIME : $mmddHHMM\n>\n>\n" ;
			$cus = $line[1] ;
			if (not $gpson) { 
				$lon = %stslon{$cus} ;
				$lat = %stslat{$cus} ;
			}
			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],$lat,$lon,$isotime,$line[1] ;
		}
	}
	# THIS IS A NEW LEG ENTRY
	elsif ($line[0] =~ /lg/) {
		$cul++ ;
		print ">\tNOW RECORDING LEG $cul\n> " ; 
		printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cul ;
	}

	# 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 " ;
				printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
			}
		}	
	}

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

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

}

# CLOSE FILE HANDLES
close(OUT) ;