LogGen.pl 3.42 KB
Newer Older
1
2
#!/usr/bin/perl 

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
3
4
# DEPENDENCIES
use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm
5

6
7
8
require "./sub_cruiseinfo.pl" ;
require "./sub_getgps.pl" ;

9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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" ;

23
24
# SETUP GPS
$gps = sub_getgps() ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
25

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

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
29
30
31
# SET PRINTING FORMAT
$frmt = "  \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ;

32
33
34
35
36
37
38
39
40
41
# 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"  ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
42
43
44
45
46

# DEFAULT START HEADER
print "=============================================================================================\n" ;
print "=====			$headerstring				=====\n" ;
print "=============================================================================================\n\n> " ;
47
48
49
50

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

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

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
54
	# POLL COMPUTER FOR TIME
55
	@time     = localtime ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
56
57
58
59
	$time[4]++ ; $time[5]+=1900 ;
	$mmddHHMM = sprintf "%02d/%02d  %02d:%02d",  @time[4], @time[3], @time[2], @time[1] ;

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

	# THIS IS THE EXIT COMMAND
63
	if  ( $line[0] =~ /exit/) {last;} 
64
65
66
67
68
69
70

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

		if      ( $cus =~ /none/ ) { 			# case : we are currently off station
			$cus = $line[1] ;
			$pre = ">>" ;
71
72
73
			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 " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
74
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
75
76
77
78

		} 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> " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
79
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
80
81
82
			$pre = ">" ;

		} else {					# case : we are currently at a different station
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
83
			printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
84
85
			print "$pre\t\t\tEND OF STATION\t	$cus,\t\t\t	TIME : $mmddHHMM\n>\n>\n" ;
			$cus = $line[1] ;
86
87
88
			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 " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
89
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
90
91
		}
	}
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
92
93
94
	# THIS IS A NEW LEG ENTRY
	elsif ($line[0] =~ /lg/) {
		$cul++ ;
95
		print ">\tNOW RECORDING LEG $cul\n> " ; 
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
96
	}
97
98
99
100
101

	# THIS IS AN OPERATION ENTRY
	elsif ($line[0] =~ /op/) {
		foreach $op (@ops) {
			if ($line[1] =~ /$op/) {
102
103
104
				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 " ;
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
			}
		}	
	}

	# 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) ;