#!/usr/local/bin/perl -w # summarize_cruise_info.pl #Reads the inventory file and generates an html formatted summary of #the U.S. GLOBEC Georges Bank and related cruises # May 16, 1997 # R. Groman @month=("nd", "Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"); open (ERRORS, ">summarize_cruise_info.errors"); print ("Content-type: text/html\n\n", "\n
**debug, object=$object\n\n"); $read_data="/data/globec/bin/listgb -f -n -t -c $object "; #print ("\n\n
**debug, read_data=$read_data\n\n"); $i=-1; foreach $record (`$read_data` ) { # print "\n\n
**debug, record=$record\n"; if ( $i == -1) { #skip past variable list $i++; next; } chomp($record); $record=~ s/\t/ /g; $record=~ s/^ +//; @fields = split (/ +/, $record); # print "\n\n
**debug, fields=@fields"; ($project[$i],$platform[$i],$year_p_start[$i],$month_p_start[$i], $day_p_start[$i],$year_p_end[$i],$month_p_end[$i], $day_p_end[$i],$name_prin[$i],$brief_desc[$i]) = @fields; $brief_desc[$i]=~s/(^.*?)_.*/$1/; if ($brief_desc[$i] eq "long") {$brief_desc[$i]="mooring"} # print ("\n\n
**debug, \n\tproject[$i]=$project[$i]\n\t", # "platform=$platform[$i]\n\t", # "start date: $year_p_start[$i],$month_p_start[$i],", # "$day_p_start[$i]\n\tend date: $year_p_end[$i],$month_p_end[$i],", # "$day_p_end[$i]","\n\tbrief_desc[$i]=$brief_desc[$i]", # "\n\tname_prin[$i]=$name_prin[$i]\n\n"); $cruise_length[$i]=&daysbetween($year_p_start[$i],$month_p_start[$i], $day_p_start[$i],$year_p_end[$i],$month_p_end[$i], $day_p_end[$i]); # print ("
\n\n**debug, Number of days=$cruise_length[$i]\n\n"); $i++; } $number_cruises=$i; print ("
| Platform | Days at Sea |
|---|---|
| $value | $total_by_platform{$value} |
| Total days | $program_total_days |
| Brief description | Days at Sea |
|---|---|
| $value | $total_by_brief_desc{$value} |
| Total days | $program_total_days |
| Year | Days at Sea |
|---|---|
| $value | $total_by_year{$value} |
| Total days | $program_total_days |
| Cruise | Start Date | End Date | " ; print "PI Name | Brief Description | Days at Sea |
|---|---|---|---|---|---|
| $project[$i] | $month[$month_p_start[$i]] $day_p_start[$i], $year_p_start[$i] | $month[$month_p_end[$i]] $day_p_end[$i], $year_p_end[$i] | $name_prin[$i] | $brief_desc[$i] | $cruise_length[$i] | EOF } } print <<"EOF1";
| Total days | $total_by_year{$year} |
| Cruise | Start Date | End Date | " ; print "PI Name | Brief Description | Days at Sea |
|---|---|---|---|---|---|
| $project[$i] | $month[$month_p_start[$i]] $day_p_start[$i], $year_p_start[$i] | $month[$month_p_end[$i]] $day_p_end[$i], $year_p_end[$i] | $name_prin[$i] | $brief_desc[$i] | $cruise_length[$i] | EOF3 if (defined $length_over1{$j} ) { $i=$length_over1{$j}; undef $length_over1{$j}; goto REPRINT; } elsif (defined $length_over2{$j} ) { $i=$length_over2{$j}; undef $length_over2{$j}; goto REPRINT; } } print <<"EOF4";
| Total days | $total_by_year{$year} |
Today's date: $date\n"; print "
\n"; #---------------------------------------------------------------------- sub daysbetween { #Compute the number of days between the year1, month1, day1, year2, month2, #day2 values specied in the call. Date 2 mudy be after (later) #than date 1. # Limitations: dates can be no more than one year appart my ($jdate1,$jdate2,$diff); #print ("\n**debug, daysbetween, passed values=",$_[0],$_[1],$_[2], # $_[3],$_[4],$_[5]); $jdate1=&julian($_[0],$_[1],$_[2]); $jdate2=&julian($_[3],$_[4],$_[5]); #print ("\n\n**debug daysbetween, jdate1=$jdate1 and jdate2=$jdate2\n\n"); if ($_[0] > $_[3] || ($_[0] == $_[3] && $_[1] > $_[4]) || ($_[0] == $_[3] && $_[1] == $_[4] && $_[2] > $_[5]) ) { print ERRORS ("\n\n%%daysbetween error, date 2 before date 1\n\t", $_[0]," ", $_[1]," ", $_[2]," ", $_[3]," ", $_[4]," ", $_[5], "\n\tReturn zero value.\n\n"); return 0; } #Check if year change if ($_[0] == $_[3]) { return $jdate2 - $jdate1 + 1; } elsif ( abs($_[0] - $_[3]) > 1) { print ERRORS ("\n\n%%daysbetween limitation, cannot handle more than one year", " difference between dates \n\t", $_[0]," ", $_[1]," ", $_[2]," ", $_[3]," ", $_[4]," ", $_[5]), "\n\tReturn zero value.\n\n"; return 0; } else { $diff=365 - $jdate1 + $jdate2 + 1; if (($_[0] % 4) == 0 && ($_[0] % 1000) != 0) {$diff++}; } return $diff; } #----------------------------------------------------------------------- sub julian { #Computes pseudo julian day bassed for year, month, day passed parameters #print " \n**debug julian, passed values: $_[0], $_[1], $_[2]\n"; my ($i, $julian, @month ); unless ( $_[0] > 0 && $_[1] > 0 && $_[1] < 13 && $_[2] > 0 && $_[2] < 32) { print ERRORS ("\n%%Error in julian, illegal date: $_[0], $_[1], $_[2]\n"); print ("\tReturning zero value"); return 0; } @month=(31,28,31,30,31,30,31,31,30,31,30,31); $julian=$_[2]; if ($_[1] == 1) {return $julian}; if( $_[0] % 4 && ($_[0] % 1000) != 0) { $month[1]=29; } for ($i=0; $i < $_[1]-1; $i++) { $julian=$julian + $month[$i]; } return $julian; } #----------------------------------------------------------------------- sub numerically{ #Used by sort to sort numerically $a <=> $b; } #-----------------------------------------------------------------------