#!/iag/bin/perl #-------------------------------------------------------------------------- # Program: mksst.pl # # Description: Create the m2sst.dat file # # Usage: mksst.pl # # Inputs: File containing the dates from the .AVG file that # we want to use and the means for each (see README) # avg-sst.AVG File containing minute averaged data # # Outputs: m2sst.dat File that we will run through CALSH6 # # Dependencies: # # Comments: # #-------------------------------------------------------------------------- initialize (); #-------------------------------------------------------------------------- # Loop through the file reading lines #-------------------------------------------------------------------------- while ($_ = ) { s/^\s+//; @field = split('\s+',$_); #-------------------------------------------------------------------------- # check if this is the date we want #-------------------------------------------------------------------------- if ($field[0] =~ /$nxtdt/) { push @t1, $field[1]; # store in the temperature array last unless ($nxtdt = shift (@dates)); # Get the next date } } #-------------------------------------------------------------------------- # Make sure we don't have any dates left over #-------------------------------------------------------------------------- if ($#dates ge 0) { printf "We have the following dates not found;\n%s\n", join (", ", @dates); exit; } #-------------------------------------------------------------------------- # printout what the data #-------------------------------------------------------------------------- printf OUT "1 %d 1\n", $num_dates +1; printf OUT "%s\n", join (" ", @means); printf OUT "5102 2\n%s\n", join (" ", @t1); #-------------------------------------------------------------------------- # Close the files and exit #-------------------------------------------------------------------------- close (INP); close (OUT); print "\nFinished mksst.pl\n"; exit; #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # initialize # #////////////////////////////////////////////////////////////////////////////// sub initialize { #--------------------------------------------------------------------------- # Verify command line #--------------------------------------------------------------------------- if ($#ARGV ne 0) { print "Usage: mksst.pl \n"; exit; } $usrFile = shift (@ARGV); #-------------------------------------------------------------------------- # open the user data file #-------------------------------------------------------------------------- open DTS, "./$usrFile" || die "Couldn't open ./$usrFile for input"; #-------------------------------------------------------------------------- # open input file #-------------------------------------------------------------------------- open INP, "./avg-sst.AVG" || die "Couldn't open ./avg-sst.AVG for input"; #-------------------------------------------------------------------------- # open OUTPUT file #-------------------------------------------------------------------------- open OUT, "> ./m2sst.dat" || die "Couldn't open ./m2sst.dat for output"; #-------------------------------------------------------------------------- # Get all the dates and mean values #-------------------------------------------------------------------------- while () { s/^\s+//; @usrdat = split('\s+',$_); push (@dates, $usrdat[0]); push (@means, $usrdat[1]); } close (DTS); if ($#dates < 0) { die "The ./$usrFile file is incorrect"; } #-------------------------------------------------------------------------- # initialize the variables #-------------------------------------------------------------------------- $num_dates = $#dates; $nxtdt = shift (@dates); @t1 = (); } #---initialize---#