Commit b5cf52aca98d7b8234cf470a6bc14fc297b27617

Authored by Jean-Luc Shaw
0 parents
Exists in master

Initial commit. Still need to implement writing to the outfile, formatting comme…

…nts, suppressing STDIN for comments, and writing operations and stations to the file header before we can call this functionnal. It is also still pretty ugly.
Showing 1 changed file with 127 additions and 0 deletions   Show diff stats
LogGen.pl 0 → 100644
  1 +++ a/LogGen.pl
... ... @@ -0,0 +1,127 @@
  1 +#!/usr/bin/perl
  2 +
  3 +
  4 +# HEADER AND INSTRUCTIONS
  5 +print "========== ========== ========== LogGen ========== ========== ==========\n\n" ;
  6 +
  7 +# ACQUIRE CRUISE INFORMATION
  8 +# cruise name
  9 +print ">> Enter cruise name : " ;
  10 +chop($name = <STDIN>) ;
  11 +print "\n" ;
  12 +
  13 +# set cruise directory
  14 +print ">> Enter cruise directory : " ;
  15 +chop($folder = <STDIN>) ;
  16 +print "\n" ;
  17 +
  18 +# does this cruise already have a mission log?
  19 +if (-e "$folder/LogGen/$name.out") {
  20 + # Open the file handle to append
  21 + # Get the stations
  22 + # Get the operations
  23 +
  24 +} else { # this cruise does not already have an output file
  25 +# MANAGE FILE HANDLES
  26 + # create and open the outfile handle
  27 + open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
  28 + print ">> Enter operations, end with CTRL-d : " ;
  29 +
  30 + # operations to be conducted
  31 + while ( <STDIN> ) {
  32 + chop($_) ;
  33 + push(@ops,$_) ;
  34 + print ">> : " ;
  35 + }
  36 + print "\n" ;
  37 +
  38 +
  39 + # stations to be visited
  40 + print ">> Enter stations names, end with CTRL-d : " ;
  41 + while (<STDIN>) {
  42 + chop($_) ;
  43 + push(@sts,$_) ;
  44 + print ">> : " ;
  45 + }
  46 + print "\n\n\n" ;
  47 +}
  48 +
  49 +# DISPLAY AVAILABLE STATIONS and OPERATIONS
  50 +
  51 +print ">> AVAILABLE OPERATIONS ARE:\n";
  52 +foreach $line (@ops) { print ">> $line\n"; }
  53 +print ">> ---\n\n" ;
  54 +print ">> PLANNED STATIONS ARE:\n";
  55 +foreach $line (@sts) { print ">> $line\n"; }
  56 +print ">> ---\n\n" ;
  57 +
  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 +$pre = ">" ;
  70 +$cus = "none" ;
  71 +$cul = "1" ;
  72 +
  73 +# RUNNING LOOP TO ADD TO CRUISE DATA FILE
  74 +
  75 +while (<STDIN>) {
  76 +
  77 + @time = localtime ;
  78 + $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4]+1, @time[3], @time[2], @time[1] ;
  79 +
  80 + chop( $_ ) ;
  81 + @line = split( "=", $_ ) ;
  82 +
  83 + # THIS IS THE EXIT COMMAND
  84 + if ( $_ =~ /exit/) {last;}
  85 +
  86 + # THIS IS A STATION ENTRY
  87 + elsif ($line[0] =~ /st/) {
  88 +
  89 + if ( $cus =~ /none/ ) { # case : we are currently off station
  90 + $cus = $line[1] ;
  91 + $pre = ">>" ;
  92 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ;
  93 +
  94 + } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station
  95 + $cus = "none" ;
  96 + print "$pre\t\t\tEND OF STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n>\n>\n> " ;
  97 + $pre = ">" ;
  98 +
  99 + } else { # case : we are currently at a different station
  100 + print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ;
  101 + $cus = $line[1] ;
  102 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ;
  103 + }
  104 + }
  105 +
  106 + # THIS IS AN OPERATION ENTRY
  107 + elsif ($line[0] =~ /op/) {
  108 + foreach $op (@ops) {
  109 + if ($line[1] =~ /$op/) {
  110 + print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n$pre " ;
  111 + }
  112 + }
  113 + }
  114 +
  115 + # THIS IS A COMMENT ENTRY
  116 + elsif ($line[0] =~ /cm/) {
  117 + print "$pre\t\t\tCOMMENT : $line[1] \n$pre " ;
  118 + }
  119 +
  120 + # UNRECOGNIZED INPUT
  121 + else {print "$pre UNDEFINED INPUT \n$pre " ;}
  122 +
  123 +}
  124 +
  125 +# CLOSE FILE HANDLES
  126 +close(OUT) ;
  127 +
... ...