Commit 6b2588b411c043ce30ad9574d5d15d2afc14e41a

Authored by unknown
1 parent 3f96f345
Exists in master

First commit after modification to make run on windows 7.

Showing 3 changed files with 108 additions and 50 deletions   Show diff stats
LogGen.pl
1   -#!/usr/bin/perl
  1 +
2 2  
3 3 # DEPENDENCIES
4 4 use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm
5 5  
6   -require "./sub_cruiseinfo.pl" ;
7   -require "./sub_getgps.pl" ;
  6 +require "sub_cruiseinfo.pl" ;
  7 +require "sub_getgps.pl" ;
8 8  
9 9 # HEADER AND INSTRUCTIONS
10   -print "========== ========== ========== LogGen ========== ========== ==========\n\n" ;
  10 +print "========== ========== ========== LogGen ========== ========== ==========\r\n\r\n" ;
11 11  
12 12 # ACQUIRE CRUISE INFORMATION
13 13 # cruise name
14 14 print ">> Enter cruise name : " ;
15 15 chop($name = <STDIN>) ;
16   -print "\n" ;
  16 +print "\r\n" ;
17 17  
18 18 # set cruise directory
19 19 print ">> Enter cruise directory : " ;
20 20 chop($folder = <STDIN>) ;
21   -print "\n" ;
22   -
23   -# SETUP GPS
24   -($gps,$gpson,$gpsport,$gpsbaud) = sub_getgps() ;
  21 +print "\r\n" ;
25 22  
26 23 # ASK FOR or READ CRUISE INFO
27   -($ops,$sts,$numops,$numsts,$headerstring,$stslat,$stslon) = sub_cruiseinfo($name,$folder,$gpson,$gpsport,$gpsbaud) ;
  24 +($ops,$sts,$gps,$gpson,$numops,$numsts,$headerstring,$stslat,$stslon) = sub_cruiseinfo() ;
28 25  
29 26 # SET PRINTING FORMAT
30   -$frmt = "%6s;%10.5f;%10.5f;%20s;%s\n" ;
  27 +$frmt = "%6s;%10.5f;%10.5f;%20s;%s\r\n" ;
31 28  
32 29 # DISPLAY AVAILABLE STATIONS and OPERATIONS
33   -print ">> AVAILABLE OPERATIONS ARE:\n";
34   -foreach $line (@ops) { print ">> $line\n"; }
35   -print ">> ---\n\n" ;
36   -print ">> PLANNED STATIONS ARE:\n";
37   -foreach $line (@sts) { print ">> $line\n"; }
38   -print ">> ---\n\n" ;
  30 +print ">> AVAILABLE OPERATIONS ARE:\r\n";
  31 +foreach $line (@ops) { print ">> $line\r\n"; }
  32 +print ">> ---\r\n\r\n" ;
  33 +print ">> PLANNED STATIONS ARE:\r\n";
  34 +foreach $line (@sts) { print ">> $line\r\n"; }
  35 +print ">> ---\r\n\r\n" ;
39 36  
40 37 # INITIAL VALUES
41 38 $pre = ">" ;
42 39 $cus = "none" ;
43 40  
44 41 # DEFAULT START HEADER
45   -print "=============================================================================================\n" ;
46   -print "===== $headerstring =====\n" ;
47   -print "=============================================================================================\n\n> " ;
  42 +print "=============================================================================================\r\n" ;
  43 +print "===== $headerstring =====\r\n" ;
  44 +print "=============================================================================================\r\n\r\n> " ;
48 45  
49 46 # RUNNING LOOP TO ADD TO CRUISE DATA FILE
50 47 while (<STDIN>) {
... ... @@ -66,8 +63,8 @@ while (&lt;STDIN&gt;) {
66 63 if ($ew =~ /W/i) { $lon*=-1 ; }
67 64 } else {
68 65 # if no gps is used be we are on station, these coordinates a written
69   - $lon = %stslon{$cus} ;
70   - $lat = %stslat{$cus} ;
  66 + $lon = $stslon{$cus} ;
  67 + $lat = $stslat{$cus} ;
71 68 }
72 69  
73 70 # THIS IS THE EXIT COMMAND
... ... @@ -80,38 +77,38 @@ while (&lt;STDIN&gt;) {
80 77 $cus = $line[1] ;
81 78 $pre = ">>" ;
82 79 if (not $gpson) {
83   - $lon = %stslon{$cus} ;
84   - $lat = %stslat{$cus} ;
  80 + $lon = $stslon{$cus} ;
  81 + $lat = $stslat{$cus} ;
85 82 }
86   - print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
87   - print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
88   - print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
  83 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\r\n" ;
  84 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\r\n" ;
  85 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\r\n$pre " ;
89 86 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
90 87  
91 88 } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station
92 89 $cus = "none" ;
93   - print "$pre\t\t\tEND OF STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n>\n>\n> " ;
  90 + print "$pre\t\t\tEND OF STATION\t $line[1],\t\t\t TIME : $mmddHHMM\r\n>\r\n>\r\n> " ;
94 91 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
95 92 $pre = ">" ;
96 93  
97 94 } else { # case : we are currently at a different station
98 95 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cus ;
99   - print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ;
  96 + print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\r\n>\r\n>\r\n" ;
100 97 $cus = $line[1] ;
101 98 if (not $gpson) {
102   - $lon = %stslon{$cus} ;
103   - $lat = %stslat{$cus} ;
  99 + $lon = $stslon{$cus} ;
  100 + $lat = $stslat{$cus} ;
104 101 }
105   - print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
106   - print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
107   - print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
  102 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\r\n" ;
  103 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\r\n" ;
  104 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\r\n$pre " ;
108 105 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
109 106 }
110 107 }
111 108 # THIS IS A NEW LEG ENTRY
112 109 elsif ($line[0] =~ /lg/) {
113 110 $cul++ ;
114   - print ">\tNOW RECORDING LEG $cul\n> " ;
  111 + print ">\tNOW RECORDING LEG $cul\r\n> " ;
115 112 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$cul ;
116 113 }
117 114  
... ... @@ -119,9 +116,9 @@ while (&lt;STDIN&gt;) {
119 116 elsif ($line[0] =~ /op/) {
120 117 foreach $op (@ops) {
121 118 if ($line[1] =~ /$op/) {
122   - print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n" ;
123   - print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
124   - print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
  119 + print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\r\n" ;
  120 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\r\n" ;
  121 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\r\n$pre " ;
125 122 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
126 123 }
127 124 }
... ... @@ -129,12 +126,12 @@ while (&lt;STDIN&gt;) {
129 126  
130 127 # THIS IS A COMMENT ENTRY
131 128 elsif ($line[0] =~ /cm/) {
132   - print "$pre\t\t\tCOMMENT : $line[1] \n$pre " ;
  129 + print "$pre\t\t\tCOMMENT : $line[1] \r\n$pre " ;
133 130 printf OUT $frmt,$line[0],$lat,$lon,$isotime,$line[1] ;
134 131 }
135 132  
136 133 # UNRECOGNIZED INPUT
137   - else {print "$pre UNDEFINED INPUT \n$pre " ;}
  134 + else {print "$pre UNDEFINED INPUT \r\n$pre " ;}
138 135  
139 136 }
140 137  
... ...
readme.md 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +HEARDER INFO for .out files
  2 +
  3 +LINE 1 : Cruise info
  4 +LINE 2 : Cruise folder path
  5 +LINE 3 : GPS feature on or off (1 or 0)
  6 +LINE 4 : GPS serial port name
  7 +LINE 5 : GPS serial port baud rate
  8 +LINE 6 : Number of operation types (N)
  9 +LINE 7 : First operation type
  10 +LINE 7+N : Last operation type
  11 +LINE 7+N+1 : Number of stations (M)
  12 +LINE 7+N+2 : First station name;station latitude;station longitude
  13 +LINE 7+N+2+M : Last station name;station latitude;station longitude
  14 +LINE 7+N+3+M : Sequential current leg number
  15 +LINE 7+N+4+M : Column titles
  16 +LINE 7+N+5+M : Start of data entries
  17 +
  18 +COLUMN DEFINITIONS
  19 +
  20 +COL 0 = entry type (station,operation,comment) (string)
  21 +COL 1 = latitude in decimal degrees (float)
  22 +COL 2 = longitude in decimal degrees (float)
  23 +COL 3 = time in ISOXXXX standard yyyy-mm-ddTHH:MM:SSZ (string)
  24 +COL 4 = entry value (station name, ..., comment) (string)
  25 +
... ...
sub_cruiseinfo.pl
1 1 sub sub_cruiseinfo {
2 2  
3   - $name = $_[0] ;
4   - $folder = $_[1] ;
5   -
6 3 # does this cruise already have a mission log?
7   - if (-e "$folder/LogGen/$name.out") {
8   - # Open the file handle to append
9   - # Get the stations
10   - # Get the operations
  4 + if (-e "$folder\\LogGen\\$name.out") {
  5 +
  6 + # Open the file for reading
  7 + open(OUT,"$folder\\LogGen\\$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
  8 +
  9 + # Read header and store in an array
  10 + while (<OUT>) {
  11 + if ( $_ !~ /\#/) {last;}
  12 + chop($_) ;
  13 + $str = substr $_, 2 ;
  14 + push(@header,$str) ; }
  15 + close(OUT) ;
  16 +
  17 + $gpson = $header[2] ;
  18 + $gpsport = $header[3] ;
  19 + $gpsbaud = $header[4] ;
  20 + $numops = $header[5] ;
  21 +
  22 + # Get the operations
  23 + for ($ii=0;$ii<$numops;$ii++) {
  24 + push(@ops,$header[6+$ii]) ; }
  25 +
  26 + $numsts = $header[6+$numops] ;
  27 +
  28 + # Get the stations and their coordinates
  29 + for ($ii=0;$ii<$numsts;$ii++) {
  30 + @hl = split(/;/,$header[6+$numops+1+$ii]) ;
  31 + push(@sts,$hl[0]) ;
  32 + $stslon{$hl[0]} = $hl[2] ;
  33 + $stslat{$hl[0]} = $hl[1] ;
  34 + }
  35 + $stslon{"none"} = "NaN" ;
  36 + $stslat{"none"} = "NaN" ;
  37 +
  38 + $headerstring = "Continuing operations log for $name cruise" ;
  39 +
  40 + #Close the file handle and open for appending
  41 + close(OUT) ;
  42 + open(OUT,">>$folder\\LogGen\\$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
11 43  
12 44 } else { # this cruise does not already have an output file
13 45 # MANAGE FILE HANDLES
14 46 # create and open the outfile handle
15   - open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
  47 + open(OUT,">$folder\\LogGen\\$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
16 48 print ">> Enter operations, end with CTRL-d : " ;
17 49  
18 50 # operations to be conducted
... ... @@ -37,6 +69,10 @@ sub sub_cruiseinfo {
37 69 }
38 70 print "\n" ;
39 71  
  72 +
  73 + # Ask for gps and connect if needed
  74 + ($gps,$gpson,$gpsport,$gpsbaud) = sub_getgps() ;
  75 +
40 76 # Manually enter GPS values for stations if no GPS is used
41 77 if (not $gpson) {
42 78 for ($ii=0;$ii<$numsts;$ii++) {
... ... @@ -61,7 +97,7 @@ sub sub_cruiseinfo {
61 97 for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii];$stslat{$sts[$ii]};$stslon{$sts[$ii]}\n" ; }
62 98 print OUT "\# 0\n" ;
63 99 $cul = 0 ;
64   - @coltitles = ("\#type","longitude","latitude","yyyy-mm-ddTHH:MM:SSZ","value") ;
  100 + @coltitles = ("\#type","latitude","longitude","yyyy-mm-ddTHH:MM:SSZ","value") ;
65 101 printf OUT "%5s;%10s;%10s;%20s;%s\n",@coltitles ;
66 102  
67 103 $headerstring = "Starting operations log for $name cruise" ;
... ... @@ -69,7 +105,7 @@ sub sub_cruiseinfo {
69 105 }
70 106  
71 107 # RETURN NEEDED VALUES
72   - return (\@ops,\@sts,$numops,$numsts,$headerstring,\%stslat,\%stslon) ;
  108 + return (\@ops,\@sts,$gps,$gpson,$numops,$numsts,$headerstring,\%stslat,\%stslon) ;
73 109  
74 110  
75 111 }
... ...