#!/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 # Valid command line arguments include: # all - do all options (same as no argument) # summary - do only summaries, no ship data details # by_cruise - show cruise details sorted by cruise # by_date - show cruise sorted by date # $version="June 9, 2005/V1.31"; # R. Groman # Edited June 9, 2005. V1.31 Add check for underscore to skip over # non-cruise entries. rcg # Edited June 7, 2005. V1.30 Skip over non-cruises by assuming they # are not all capital letters for the project. Add STDOUT to # print here lines. rcg # Edited June 26, 2001. V1.20 Fix leap year computation. RCG # Edited June 23, 1999. V1.1 Replace listgb with list. RCG # Edited March 23, 1998. Initialize values; change /data to /data5. $option=$ARGV[0]; if ($option eq "all") {undef $option;} @month=("nd", "Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"); open (ERRORS, ">summarize_cruise_info.errors"); print STDOUT ("Content-type: text/html\n\n", "\n
**debug, object=$object\n\n"); $read_data="/data5/globec/bin/list -f -n -t -c $object "; #print STDOUT ("\n\n
**debug, read_data=$read_data\n\n"); $i=-1; foreach $record (`$read_data` ) { # print STDOUT "\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 STDOUT "\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; # Check for non cruise entries unless ($project[$i] eq uc $project[$i]) {next} if ($project[$i] =~ m/_/ ) {next} $brief_desc[$i]=~s/(^.*?)_.*/$1/; if ($brief_desc[$i] eq "long") {$brief_desc[$i]="mooring"} # print STDOUT ("\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 STDOUT ("
\n\n**debug, Number of days=$cruise_length[$i]\n\n"); $i++; } $number_cruises=$i; print STDOUT ("
| 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 STDOUT "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 STDOUT<<"EOF1";
| Total days | $total_by_year{$year} |
| Cruise | Start Date | End Date | " ; print STDOUT "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 STDOUT<<"EOF4";
| Total days | $total_by_year{$year} |
Today's date: $date\n";
print STDOUT ("
Program version: $version\n");
print STDOUT "
\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 STDOUT ("\n**debug, daysbetween, passed values=",$_[0],$_[1],$_[2],
# $_[3],$_[4],$_[5]);
$jdate1=&julian($_[0],$_[1],$_[2]);
$jdate2=&julian($_[3],$_[4],$_[5]);
#print STDOUT ("\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 STDOUT " \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 == int ($_[0]/4) and $_[0]/100 != int ($_[0]/100) ) {
# print STDOUT "
\n**debug julian, passed values: ",
# "$_[0], $_[1], $_[2]", "\n
";
$month[1]=29;
}
if( $_[0]/4 == int ($_[0]/4) and $_[0]/100 == int ($_[0]/100)
and $_[0]/400 == int ($_[0]/400) ) {
# print STDOUT "
\n**debug julian, passed values: ",
# "$_[0], $_[1], $_[2]", "\n
";
$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;
}
#-----------------------------------------------------------------------