#!/iag/bin/perl #-------------------------------------------------------------------------- # Program: avg-sst.pl # # Description: Process the intput-filename to time-stamp averages # # Usage: avg-sst.pl input_filename # # Inputs: input_filename File to be processed defaults # # Outputs: avg-sst.AVG Processed file for temperature pods # # Dependencies: # # Comments: # #-------------------------------------------------------------------------- initialize (); #-------------------------------------------------------------------------- # Loop through the file reading lines #-------------------------------------------------------------------------- while ($_ = ) { s/^\s+//; @field = split('\s+',$_); #-------------------------------------------------------------------------- # calculate the GMT time from first column #-------------------------------------------------------------------------- $day = hex ($field[0]) / 128.0; $jday = int ($day); $time = ($day - $jday) * 32.0; $hours = int ($time); $minutes = ($time - $hours) * 60; $gmt = sprintf "%03d/%02d:%02d", $jday, $hours, $minutes; #-------------------------------------------------------------------------- # If the date is not the same as the last one print out averages #-------------------------------------------------------------------------- if ($gmt ne $lastgmt) { if ($count > 0) { #-------------------------------------------------------------------- # Calculate the average #-------------------------------------------------------------------- $t1 = int ($t1 / $count); #-------------------------------------------------------------------- # Write needed output to file #-------------------------------------------------------------------- printf OUT "%9s %04X\n", $lastgmt, $t1; } #-------------------------------------------------------------------- # Reinitialize the values #-------------------------------------------------------------------- $lastgmt = $gmt; $count = 0; $t1 = 0; } #-------------------------------------------------------------------- # Total the temperature readings #-------------------------------------------------------------------- $t1 += hex ($field[2]); $count++; } #-------------------------------------------------------------------- # Handle the last date #-------------------------------------------------------------------- if ($count > 0) { #-------------------------------------------------------------------- # Calculate the average #-------------------------------------------------------------------- $t1 = int ($t1 / $count); #-------------------------------------------------------------------- # Write needed output to file #-------------------------------------------------------------------- printf OUT "%9s %04X\n", $lastgmt, $t1; } #-------------------------------------------------------------------------- # Close the files and exit #-------------------------------------------------------------------------- close (INP); close (OUT); exit; #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # initialize # #////////////////////////////////////////////////////////////////////////////// sub initialize { #--------------------------------------------------------------------------- # Verify command line #--------------------------------------------------------------------------- if ($#ARGV ne 0) { print "Usage: avg-sst.pl input_filename\n"; exit; } $infile = shift (@ARGV); #-------------------------------------------------------------------------- # open input file #-------------------------------------------------------------------------- open INP, "./$infile" || die "Couldn't open ./$infile for input"; #-------------------------------------------------------------------------- # open OUTPUT files #-------------------------------------------------------------------------- open OUT, "> ./avg-sst.AVG" || die "Couldn't open ./avg-sst.AVG for output"; #-------------------------------------------------------------------------- # Initialize values #-------------------------------------------------------------------------- $lastgmt = ""; $count = 0; $t1 = 0 } #---initialize---#