#!/usr/local/bin/perl -w # nepctd_level0.pl # Serve NEP ctd data. Based on mocness_ctd scripts. # Sets up level 0 for CTD data object. # Bob Groman # October 15, 1999. V1.0 $version="v1.00/October 15, 1999"; # looks at all the files in the /data/NEP/Data and other places # processing all the files in finds. # # sets up info required for the next level based # on results of files lists and initial header data # in the data files # # Passed parameter # $ARGV[0] = data type, e.g. nep1. (At this time, there is only # one type of data type. # Assumptions; # 1. Directories looked at only contain subdirectories with # relevant data. #some definitions $| = 1; # top level data directories @top_datadir=("/data/NEP/Data"); $script_loc = "/data/NEP/Scripts"; # script location dir $i_am_level=0; $script_name="nepctd_level1.pl"; $fieldnames_level[0]="/data/NEP/Support/fieldnames_level0"; $fieldnames_level[1]="/data/NEP/Support/fieldnames_level1"; $fieldnames_level[2]="/data/NEP/Support/fieldnames_level2"; #$nep1patterns="/data/NEP/Support/nep1patterns"; Not needed yet $error="&x"; $warning="#"; $datatype=uc $ARGV[0]; print STDOUT ("#Displayed by $0, $version, data type is $datatype\n"); #if ($datatype eq "NEP1" ) { # open PATTERN, $nep1patterns or # die "#$0 could not read $nep1patterns patterns file, $!"; # @pattern=; # chomp @pattern; # print STDOUT "#**debug, numb patterns=$#pattern, patterns=@pattern\n"; # close PATTERN; #} else { # print STDOUT "#$0 cannot recognize datatype=$datatype"; # exit 0; #} $data = (); foreach $top_datadir (@top_datadir) { # print STDOUT "\n**#debug, top_datadir=$top_datadir"; chdir($top_datadir) or die "#Cannot change to $top_datadir directory"; opendir DATADIR, $top_datadir or die "#Cannot open directory $top_datadir"; @cruise_dir = grep -d, readdir DATADIR; foreach $cruise_dir (@cruise_dir) { # get filenames $cruise_id = uc $cruise_dir; # print STDOUT "\n#**debug,cruise_dir=$cruise_dir\n"; $ctd_dir = $top_datadir . "/" . $cruise_dir; if (! -e $ctd_dir or ! -d $ctd_dir ) {next;} if ( $cruise_dir =~ /^\./ ) {next;} # print STDOUT "#**debug,ctd=$ctd_dir\n"; @datafile=<$ctd_dir/*>; if ( $#datafile < 0 ) {next;} $datafile=$datafile[0]; FILEOKAY: open(PROFILE, $datafile) or die "#Could not open data file $datafile, error=$!"; # print STDOUT "\n#**debug, opening file=$datafile\n"; $cruise=$cruise_id; $year_local="nd"; READDATA: while() { chomp ; unless( m/^h/ or m/^#/ ) { last READDATA } if( m/^h Time/ ) { $year_local = $_; $year_local =~ s/.*\/(\d\d\d\d).*$/$1/; last; } else { next;} } # print STDOUT ("#**debug, year_local=$year_local\n"); if ($year_local ne "nd" ) { if ($year_local < 30 ) { $year_local+=2000; } elsif ($year_local < 100 ) { $year_local+=1900; } } $string = "(" . $script_loc . "/" . $script_name . " " . $ctd_dir . " " . $datatype . " " . uc $cruise . " " . $year_local . ")"; $dataline = $cruise . "\t" . $year_local. "\t" . $string . "\n"; push @data, $dataline; } } # headers - 3 o/p by level0 Read from files for ($i=$i_am_level; $i <= $#fieldnames_level; $i=$i+1) { unless (open FIELDNAMES, $fieldnames_level[$i] ) { &sendmessage ($error, "Could not get $0 field names from $fieldnames_level[$i]", "Error=$!"); exit 0; } @fieldnames=; close FIELDNAMES; chomp (@fieldnames); foreach $variable (@fieldnames) { print STDOUT "$variable\t" unless (index $variable, "#") >= 0; } print STDOUT "\n"; } foreach $line (sort @data) { print STDOUT $line; } undef $error; undef $warning; exit 0; #--------------------------------------------------------------------------- sub sendmessage { #Send a message to the user. #The message sent will be in the strings $_[1] and $_[2] #The prefix string is in $_[0] my ( @args, $mailfile, $message0, $message1, $prefix, $who); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); $prefix=$_[0]; $message0=$_[1]; $message1=$_[2]; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); if ($year > 97 and $year < 100 ) {$year = $year + 1900; } $mon++; if ($mon < 10) { $mon = "0" . $mon; } if ($mday < 10) {$mday = "0" . $mday; } if ($hour < 10) { $hour = "0" . $hour; } if ($min < 10) { $min = "0" . $min; } if ($sec < 10) { $sec = "0" . $sec; } $mailfile=">/tmp/sendmess" . $year . $yday . $hour . $min . $sec . ".tmp"; if ( open TEMPFILE, $mailfile) { if ( exists $ENV{'REMOTE_HOST'} ) {$who=$ENV{'REMOTE_HOST'} ; } elsif (exists $ENV{'REMOTE_ADDR'} ) {$who=$ENV{'REMOTE_ADDR'} ; } else {$who="not available"; } print TEMPFILE ("Message from $0\n"); print TEMPFILE (" Date of message: $year/$mon/$mday $hour:$min\n"); print TEMPFILE (" From: $who\n"); print TEMPFILE (" $message0\n"); print TEMPFILE (" $message1\n"); close TEMPFILE; `/usr/bin/mail -w dmo\@globec.whoi.edu <$mailfile`; unlink $mailfile; } print STDOUT ($prefix,"Message from $0\n"); print STDOUT ($prefix," Date of message: $year/$mon/$mday $hour:$min\n"); print STDOUT ($prefix," $message0\n"); print STDOUT ($prefix," $message1\n"); return; }