LogGen.pl 3.98 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
# SETUP GPS
24
($gps,$gpson,$gpsport,$gpsbaud) = sub_getgps() ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
25

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

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

32
33
34
35
36
37
38
39
# 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" ;

40
41
42
43
44
45
# INITIAL VALUES
$pre   = ">" ;
$cus   = "none"  ;
$culon = "NaN" ;
$culat = "NaN" ;

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
46
47
48
49
50

# DEFAULT START HEADER
print "=============================================================================================\n" ;
print "=====			$headerstring				=====\n" ;
print "=============================================================================================\n\n> " ;
51
52
53
54

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

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

Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
58
	# POLL COMPUTER FOR TIME
59
	@time     = localtime ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
60
61
	$time[4]++ ; $time[5]+=1900 ;
	$mmddHHMM = sprintf "%02d/%02d  %02d:%02d",  @time[4], @time[3], @time[2], @time[1] ;
62
	$isotime  = sprintf "%s-%02s-%02sT%02s:%02s:%02sZ",reverse @time[0..5] ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
63
64

	# POLL GPS FOR COORDINATES
65
66
67
68
69
70
71
72
73
74
	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 = $culon ;
		$lat = $culat ;
	} 
75
76

	# THIS IS THE EXIT COMMAND
77
	if  ( $line[0] =~ /exit/) {last;} 
78
79
80
81
82
83
84

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

		if      ( $cus =~ /none/ ) { 			# case : we are currently off station
			$cus = $line[1] ;
			$pre = ">>" ;
85
86
87
			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 " ;
88
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
89
90
91
92

		} 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> " ;
93
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
94
95
96
			$pre = ">" ;

		} else {					# case : we are currently at a different station
97
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cus ;
98
99
			print "$pre\t\t\tEND OF STATION\t	$cus,\t\t\t	TIME : $mmddHHMM\n>\n>\n" ;
			$cus = $line[1] ;
100
101
102
			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 " ;
103
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
104
105
		}
	}
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
106
107
108
	# THIS IS A NEW LEG ENTRY
	elsif ($line[0] =~ /lg/) {
		$cul++ ;
109
		print ">\tNOW RECORDING LEG $cul\n> " ; 
110
		printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cul ;
Jean-Luc Shaw's avatar
Jean-Luc Shaw committed
111
	}
112
113
114
115
116

	# THIS IS AN OPERATION ENTRY
	elsif ($line[0] =~ /op/) {
		foreach $op (@ops) {
			if ($line[1] =~ /$op/) {
117
118
119
				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 " ;
120
				printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
121
122
123
124
125
126
127
			}
		}	
	}

	# THIS IS A  COMMENT   ENTRY
	elsif  ($line[0] =~ /cm/) {
			print "$pre\t\t\tCOMMENT : $line[1] \n$pre " ;  
128
			printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
129
130
131
132
133
134
135
136
137
138
	}

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

}

# CLOSE FILE HANDLES
close(OUT) ;