#!/iag/bin/perl #-------------------------------------------------------------------------- # Program: avg-m51.pl # # Description: Process the intput-filename to time-stamp averages # # Usage: avg-m51.pl input_filename # # Inputs: input_filename File to be processed defaults # # Outputs: avg-m51.FFFF Processed file for temperature pods # avg-m51.AVG Processed file for calibration and 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 averages #-------------------------------------------------------------------- $c3 = int ($c3 / $count); $t3 = int ($t3 / $count); $c4 = int ($c4 / $count); $t4 = int ($t4 / $count); $c5 = int ($c5 / $count); $t5 = int ($t5 / $count); $c6 = int ($c6 / $count); $t6 = int ($t6 / $count); $c7 = int ($c7 / $count); $t7 = int ($t7 / $count); $c8 = int ($c8 / $count); $t8 = int ($t8 / $count); $c9 = int ($c9 / $count); $t9 = int ($t9 / $count); $c10 = int ($c10 / $count); $t10 = int ($t10 / $count); $c11 = int ($c11 / $count); $t11 = int ($t11 / $count); $c12 = int ($c12 / $count); $t12 = int ($t12 / $count); #-------------------------------------------------------------------- # Write needed output to file #-------------------------------------------------------------------- printf OUTFFFF "%9s %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12; printf OUT "%9s FFFF %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12; printf OUT "%9s 0000 %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12; } #-------------------------------------------------------------------- # Reinitialize the values #-------------------------------------------------------------------- $lastgmt = $gmt; $count = 0; ($t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12) = 0; ($c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12) = 0; } #-------------------------------------------------------------------- # Total the temperature readings #-------------------------------------------------------------------- if (($field[1] =~ /$FFFF/) && ($field[14] !~ /$FFFF/)) { $t3 += hex ($field[3]); $t4 += hex ($field[4]); $t5 += hex ($field[5]); $t6 += hex ($field[6]); $t7 += hex ($field[7]); $t8 += hex ($field[8]); $t9 += hex ($field[9]); $t10 += hex ($field[10]); $t11 += hex ($field[11]); $t12 += hex ($field[12]); } #-------------------------------------------------------------------- # Total the calibration registor readings #-------------------------------------------------------------------- if (($field[1] =~ /$OOOO/) && ($field[14] !~ /$FFFF/)) { $c3 += hex ($field[3]); $c4 += hex ($field[4]); $c5 += hex ($field[5]); $c6 += hex ($field[6]); $c7 += hex ($field[7]); $c8 += hex ($field[8]); $c9 += hex ($field[9]); $c10 += hex ($field[10]); $c11 += hex ($field[11]); $c12 += hex ($field[12]); $count++; } } #-------------------------------------------------------------------- # Handle the last date #-------------------------------------------------------------------- if ($count > 0) { #-------------------------------------------------------------------- # Calculate the averages #-------------------------------------------------------------------- $c3 = int ($c3 / $count); $t3 = int ($t3 / $count); $c4 = int ($c4 / $count); $t4 = int ($t4 / $count); $c5 = int ($c5 / $count); $t5 = int ($t5 / $count); $c6 = int ($c6 / $count); $t6 = int ($t6 / $count); $c7 = int ($c7 / $count); $t7 = int ($t7 / $count); $c8 = int ($c8 / $count); $t8 = int ($t8 / $count); $c9 = int ($c9 / $count); $t9 = int ($t9 / $count); $c10 = int ($c10 / $count); $t10 = int ($t10 / $count); $c11 = int ($c11 / $count); $t11 = int ($t11 / $count); $c12 = int ($c12 / $count); $t12 = int ($t12 / $count); #-------------------------------------------------------------------- # Write needed output to file #-------------------------------------------------------------------- printf OUTFFFF "%9s %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12; printf OUT "%9s FFFF %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12; printf OUT "%9s 0000 %04X %04X %04X %04X %04X %04X %04X %04X %04X %04X\n", $lastgmt, $c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12; } #-------------------------------------------------------------------------- # Close the files and exit #-------------------------------------------------------------------------- close (INP); close (OUTFFFF); close (OUT); exit; #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ # # initialize # #////////////////////////////////////////////////////////////////////////////// sub initialize { #--------------------------------------------------------------------------- # Verify command line #--------------------------------------------------------------------------- if ($#ARGV ne 0) { print "Usage: avg-m51.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 OUTFFFF, "> ./avg-m51.FFFF" || die "Couldn't open ./avg-m51.FFFF for output"; open OUT, "> ./avg-m51.AVG" || die "Couldn't open ./avg-m51.AVG for output"; #-------------------------------------------------------------------------- # Initialize values #-------------------------------------------------------------------------- $lastgmt = ""; $count = 0; ($t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $t12) = 0; ($c3, $c4, $c5, $c6, $c7, $c8, $c9, $c10, $c11, $c12) = 0; $FFFF = "FFFF"; $OOOO = "0000"; } #---initialize---#