#!/usr/bin/perl #-------------------- # # Program Name: dailysum2.cgi # # Created by: Steven Fierro # Unix and Networking Specialist # Millersville University # # For use by the Meteorology Department of MU # # Activation Date: April 1997 # Revised: April 30, 1997 # May 02, 1997 # May 05, 1997 # May 09, 1997 # May 12, 1997 # May 16, 1997 # June 04, 1997 # June 11, 1997 # June 23, 1997 # # Copyright 1997; all rights reserved. #-------------------- # # This program is designed to take weather data collected # via RainWise equipment and software and create a daily # summary for display through a WWW browser in tabular form. # This program will run via cron, but can be run at anytime. # # Due to the need to deal with the local Lancaster newspaper, # two copies of this program have been created. This one is # used to allow the paper to get un-offical max/min values # so they can go to press by 11:00. # # This program will be run at 10:30pm. #-------------------- #------ Here's where the fun begins ------# #------ # Variable initialization #------ chop($systime = `date '+%I:%M'`); # Determine the system time chop($AP = `date '+%p'`); # Determine AM or PM ($ap = $AP) =~ tr/A-Z/a-z/; # Turn uppercase $AP to lowercase $ap #@DATA = `tail -2500 /var/data/tower/weather.dat`; # Obtain the data @DATA = `tail -2501 /data/wls8000/weather.TXT | head -2500`; $start = ""; # used to obtain starting rain value. $last = ""; # used to obtain ending rain value. $basemax = -99; # used as base to determine max temp. $basemin = 99; # used as base to determine min temp. $basewind = 0; # used as base to determine peak wind speed. # Array used to obtain the month name for year-to-date max/min temps %MONTHS = ( '01', 'January', '02', 'February', '03', 'March', '04', 'April', '05', 'May', '06', 'June', '07', 'July', '08', 'August', '09', 'September', '10', 'October', '11', 'November', '12', 'December', ); chop($year = `date '+%Y'`); # Determine the current year chop($monthnum = `date '+%m'`); # Determine the current month number chop($day = `date '+%d'`); # Determine the current day of the month chop($rainfile = `date '+$monthnum%y-cumrain.txt'`); # Determine rainfall file chop($yearfile = `date '+%Y-cumrain.txt'`); # Determine yearly rain file chop($outfile = `date '+$monthnum%y.html'`); # Setup output file chop($yearrain = `cat $yearfile`); # Get the current yearly rainfall chop($cumrain = `cat $rainfile`); # Get the current cumulative rainfall chop($infomax = `cat $year-max.txt`); # Get year to date max info ($blank, $yrmaxtemp, $yrmaxmon, $yrmaxday) = split(/ /, $infomax); chop($infomin = `cat $year-min.txt`); # Get year to date min info ($blank, $yrmintemp, $yrminmon, $yrminday) = split(/ /, $infomin); open(OUTPUT, ">> $outfile"); # Prepare filehandle for output #------ # Scan through @DATA and process the info for $day #------ foreach $element (@DATA) { @line = split(" ",$element); $numfields = scalar @line; # if($numfields eq 12) { #skip lines with bad data ($time, $date, $winddir, $windspd, $solar, $intemp, $outtemp, $rh, $barometer, $rainday, $rainmon, $raintot) = split(" ", $element); if($numfields eq 12 && $outtemp < 106) { #skip lines with bad data # strip off units chop $solar; chop $intemp; chop $outtemp; chop $rh; chop $barometer; substr($windspd, -3) = ""; # make integers of the temperature and wind speed data $outtemp = int($outtemp); $windspd = int($windspd); # strip off juk at end of rain data substr($rainday, -2) = ""; substr($rainmon, -2) = ""; substr($raintot, -4) = ""; # strip off year from the date substr($date, -3) = ""; #$time2 = substr($time,1); # Get rid of leading " from time #$date2 = substr($date,1); # Get rid of leading " from date $time2 = $time; $date2 = $date; # put daily rain info in variable used in original script. $rain = $rainday; ($mon, $d) = split('/', $date2); # Used to look only at the if ($mon == $monthnum && $d == $day) { # data in @DATA that matches if ($start eq "") { # $day. Then find the $start = $rain; # max/min/peak values. } &correctdata(); $last = $rain; } } # end of if numfields } # End of foreach loop $dailyrain = $last - $start; # Calculate daily rainfall $monthrain = $cumrain + $dailyrain; # Calculate monthly rainfall $yearrain = $yearrain + $dailyrain; # Calculate yearly rainfall open(RAIN, "> $rainfile"); # Keep track of the monthly rainfall printf RAIN "%2.2f\n", $monthrain; # in a file for future use close RAIN; open(YEAR, "> $yearfile"); # Keep track of the yearly rainfall printf YEAR "%2.2f\n", $yearrain; # in a file for future use close YEAR; #------ # Verify if the new max/min values are greater/lesser than yearly total # to date. #------ if ($basemax > $yrmaxtemp) { $yrmaxtemp = $basemax; $yrmaxmon = $MONTHS{$monthnum}; $yrmaxday = $day; open(YRMAX, "> $year-max.txt"); print YRMAX "$yrmaxtemp $yrmaxmon $yrmaxday\n"; close YRMAX; } if ($basemin < $yrmintemp) { $yrmintemp = $basemin; $yrminmon = $MONTHS{$monthnum}; $yrminday = $day; open(YRMIN, "> $year-min.txt"); print YRMIN "$yrmintemp $yrminmon $yrminday\n"; close YRMIN; } #------ # Store the aquired information to $outfile #------ chomp $monthnum; chomp $day; chomp $basemax; chomp $maxtime; chomp $basemin; chomp $mintime; chomp $basewdir; chomp $wintime; chomp $basewind; chomp $dailyrain; printf OUTPUT "\nAs of $systime$ap:
$monthnum/$day$basemax
($maxtime)$basemin
($mintime)$basewdir
($wintime)$basewind
($wintime)%2.2f\n\n\n", $dailyrain; #------ # Subroutine to use to determine the max and min temps and peak wind speed # for valid data (i.e. data from @DATA that matches is for $day. #------ sub correctdata { if ($outtemp > $basemax) { $basemax = $outtemp; $maxtime = $time2; } if ($outtemp < $basemin) { $basemin = $outtemp; $mintime = $time2; } if ($windspd > $basewind) { $basewind = $windspd; $basewdir = $winddir; $wintime = $time2; } } # End of subroutine #------ # Final procedures #------ close OUTPUT; $date = `date +%Y%m%d%H%M`; open OUT, ">finishedmsg2"; print OUT "Dailysum2 run finished on $date"; $host = `hostname`; print OUT "Hostname is $host\n"; $processes = `ps -ef`; print OUT "process snapshot is:\n"; print OUT "$processes\n"; close OUT; #$cmd = "/bin/mail -s 'Dailysum2 output' david.fitzgerald\@millersville.edu < finishedmsg2"; #system($cmd);