LogGen.pl 4.09 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
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

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

# does this cruise already have a mission log?
if (-e "$folder/LogGen/$name.out") {
	# Open the file handle to append
	# Get the stations
	# Get the operations

} else { # this cruise does not already have an output file
# MANAGE FILE HANDLES 
	# create and open the outfile handle 
	open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n")  ;
	print ">> Enter operations, 		end with CTRL-d		: " ;
	
	# operations to be conducted
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
33
	$numops = 0 ;
34
35
36
37
	while ( <STDIN> ) {
		chop($_) ;
		push(@ops,$_) ;
		print ">> 							: " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
38
		$numops++ ;
39
40
41
42
43
	}
	print "\n" ;
	
	
	# stations to be visited 
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
44
	$numsts = 0 ;
45
46
47
48
49
	print ">> Enter stations names, 	end with CTRL-d		: " ;
	while (<STDIN>) {
		chop($_) ;
		push(@sts,$_) ;
		print ">> 							: " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
50
		$numsts++ ;
51
52
	}
	print "\n\n\n" ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66

	# print header to outputfile
	print OUT "\# $name\n" ;
	print OUT "\# $folder\n" ;
	print OUT "\# $numops\n" ;
	for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
	print OUT "\# $numsts\n" ;
	for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }
	print OUT "\# 0\n" ;
	$cul = 0 ;	
	print OUT "\# Type lon     lat     yyyy mm dd HH MM SS Name\n" ;

	$headerstring = "Starting operations log for $name cruise" ;

67
68
}

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

72
73
74
75
76
77
78
79
80
81
82
# 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
83
84
85
86
87

# DEFAULT START HEADER
print "=============================================================================================\n" ;
print "=====			$headerstring				=====\n" ;
print "=============================================================================================\n\n> " ;
88
89
90
91
92

# RUNNING LOOP TO ADD TO CRUISE DATA FILE

while (<STDIN>) {

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
93
	# POLL COMPUTER FOR TIME
94
	@time     = localtime ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
95
96
97
98
	$time[4]++ ; $time[5]+=1900 ;
	$mmddHHMM = sprintf "%02d/%02d  %02d:%02d",  @time[4], @time[3], @time[2], @time[1] ;

	# POLL GPS FOR COORDINATES
99
100
101
102
103
104
105
106
107
108
109
110
111
112

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

	# THIS IS THE EXIT COMMAND
	if  ( $_ =~ /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$pre " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
113
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
114
115
116
117

		} 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
118
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
119
120
121
			$pre = ">" ;

		} else {					# case : we are currently at a different station
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
122
			printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
123
124
125
			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$pre " ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
126
			printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
127
128
		}
	}
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
129
130
131
132
133
	# THIS IS A NEW LEG ENTRY
	elsif ($line[0] =~ /lg/) {
		$cul++ ;
		print ">\tNOW RECORDING LEG $cul\n> " ;
	}
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

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