Commit 12e7b467875914086ac534e76f06de97f7c222f3

Authored by Jean-Luc Shaw
1 parent b5cf52ac
Exists in master

Writing text to output.

Showing 1 changed file with 42 additions and 13 deletions   Show diff stats
LogGen.pl
1 1 #!/usr/bin/perl
2 2  
  3 +# DEPENDENCIES
  4 +use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm
3 5  
4 6 # HEADER AND INSTRUCTIONS
5 7 print "========== ========== ========== LogGen ========== ========== ==========\n\n" ;
... ... @@ -28,24 +30,45 @@ if (-e "$folder/LogGen/$name.out") {
28 30 print ">> Enter operations, end with CTRL-d : " ;
29 31  
30 32 # operations to be conducted
  33 + $numops = 0 ;
31 34 while ( <STDIN> ) {
32 35 chop($_) ;
33 36 push(@ops,$_) ;
34 37 print ">> : " ;
  38 + $numops++ ;
35 39 }
36 40 print "\n" ;
37 41  
38 42  
39 43 # stations to be visited
  44 + $numsts = 0 ;
40 45 print ">> Enter stations names, end with CTRL-d : " ;
41 46 while (<STDIN>) {
42 47 chop($_) ;
43 48 push(@sts,$_) ;
44 49 print ">> : " ;
  50 + $numsts++ ;
45 51 }
46 52 print "\n\n\n" ;
  53 +
  54 + # print header to outputfile
  55 + print OUT "\# $name\n" ;
  56 + print OUT "\# $folder\n" ;
  57 + print OUT "\# $numops\n" ;
  58 + for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
  59 + print OUT "\# $numsts\n" ;
  60 + for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }
  61 + print OUT "\# 0\n" ;
  62 + $cul = 0 ;
  63 + print OUT "\# Type lon lat yyyy mm dd HH MM SS Name\n" ;
  64 +
  65 + $headerstring = "Starting operations log for $name cruise" ;
  66 +
47 67 }
48 68  
  69 +# SET PRINTING FORMAT
  70 +$frmt = " \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ;
  71 +
49 72 # DISPLAY AVAILABLE STATIONS and OPERATIONS
50 73  
51 74 print ">> AVAILABLE OPERATIONS ARE:\n";
... ... @@ -55,27 +78,24 @@ print &quot;&gt;&gt; PLANNED STATIONS ARE:\n&quot;;
55 78 foreach $line (@sts) { print ">> $line\n"; }
56 79 print ">> ---\n\n" ;
57 80  
58   -
59   -
60   -
61   -
62   -
63   -# DEFAULT START HEADER
64   -print "======================================================================================================\n" ;
65   -print "===== START =====\n" ;
66   -print "======================================================================================================\n\n" ;
67   -print "> LEG 001\n> " ;
68   -
69 81 $pre = ">" ;
70 82 $cus = "none" ;
71   -$cul = "1" ;
  83 +
  84 +# DEFAULT START HEADER
  85 +print "=============================================================================================\n" ;
  86 +print "===== $headerstring =====\n" ;
  87 +print "=============================================================================================\n\n> " ;
72 88  
73 89 # RUNNING LOOP TO ADD TO CRUISE DATA FILE
74 90  
75 91 while (<STDIN>) {
76 92  
  93 + # POLL COMPUTER FOR TIME
77 94 @time = localtime ;
78   - $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4]+1, @time[3], @time[2], @time[1] ;
  95 + $time[4]++ ; $time[5]+=1900 ;
  96 + $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4], @time[3], @time[2], @time[1] ;
  97 +
  98 + # POLL GPS FOR COORDINATES
79 99  
80 100 chop( $_ ) ;
81 101 @line = split( "=", $_ ) ;
... ... @@ -90,18 +110,27 @@ while (&lt;STDIN&gt;) {
90 110 $cus = $line[1] ;
91 111 $pre = ">>" ;
92 112 print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ;
  113 + printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
93 114  
94 115 } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station
95 116 $cus = "none" ;
96 117 print "$pre\t\t\tEND OF STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n>\n>\n> " ;
  118 + printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
97 119 $pre = ">" ;
98 120  
99 121 } else { # case : we are currently at a different station
  122 + printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
100 123 print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ;
101 124 $cus = $line[1] ;
102 125 print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ;
  126 + printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
103 127 }
104 128 }
  129 + # THIS IS A NEW LEG ENTRY
  130 + elsif ($line[0] =~ /lg/) {
  131 + $cul++ ;
  132 + print ">\tNOW RECORDING LEG $cul\n> " ;
  133 + }
105 134  
106 135 # THIS IS AN OPERATION ENTRY
107 136 elsif ($line[0] =~ /op/) {
... ...