#!/usr/bin/perl -w ######################################################################## ######################################################################## # # This program is developed to be placed in cron and run as close to # (but after) the top of the hour as possible -- within the first minute # if possible. # # The first part will automatically check for new zone forecasts as well # as state forecasts to have them on file incase the posted WILL # forecasts become too old. # # The second part determines whether the posted WILL forecast is too # old. It would then replace the forecast page with weather service # information. # Program by Dan Bramer 5/24/1999 UIUC ######################################################################## ######################################################################## # First we have to get the time so that we can go look for new forecasts. # This is becuase even if the forecast doesn't time out, we need to have # the latest forecast available incase it does. if (-d "/home/ice/a/www/fcst/forecasts") { chdir("/home/ice/a/www/fcst/forecasts"); } $cuoutfile = ">nwscu.txt"; $iloutfile = ">nwsil.txt"; $inoutfile = ">nwsin.txt"; $lscommand = `ls -l ../output`; print STDOUT "\n\n"; $filechecklist = `ls -lrt /home/flood/prods/fcst/FPUS*`; @filearray = split("\n",$filechecklist); $i = 0; while ($i <= $#filearray) { if ($filearray[$i] =~ /FPUS53\_KILX_/) { $filecuindexer = $i; } if ($filearray[$i] =~ /FPUS63\_KILX_/) { $fileilindexer = $i; } if ($filearray[$i] =~ /FPUS63\_KIND_/) { $fileinindexer = $i; } $i++; } #print $filearray[$filecuindexer]."\n"; #print $filearray[$fileilindexer]."\n"; #print $filearray[$fileinindexer]."\n"; @goodcufile = split(" +",$filearray[$filecuindexer]); @goodilfile = split(" +",$filearray[$fileilindexer]); @goodinfile = split(" +",$filearray[$fileinindexer]); $cufile = $goodcufile[8]; $ilfile = $goodilfile[8]; $infile = $goodinfile[8]; #$cufile = "/home/squall/prods/fcst/FPUS53_KILX_1999070709"; #$infile = "/home/data/prods/fcst/FPUS63_KIND_1999070616"; print "FILENAME=".$cufile."\n"; print "FILENAME=".$ilfile."\n"; print "FILENAME=".$infile."\n"; # Now we know what the file should look like, go and get it. $kcmiflag = 0; $cutext = ""; $iltext = ""; $intext = ""; ############################ # Now that we have the files we need, go one # by one and figure which files to go after. ############################ if (-e $cufile) { open (CUINFILE,$cufile); print "IL Zone Forecast Found\n"; print "Must check for Champaign inclusion...\n"; $i = 0; while() { $culist[$i]=$_; $i++; } close (CUINFILE); $i = 0; while ($i <= $#culist) { if ($culist[$i] =~ /FPUS53 KILX/i) { # $kcmiref=$i+3; while ($i <= $#culist) { if ($culist[$i] =~ /^national weather service/i) { if ($culist[$i+1] =~ /^[0-9+]/) { $kcmiref1 = $i } } if ($culist[$i] =~ /champaign/i) { $kcmiflag = 1; # $kcmiref1 = $kcmiref; $kcmiref2 = $i; } $i++; } } $i++; } if ($kcmiflag == 1) { print "CHAMPAIGN FORECAST FOUND\n"; $j = $kcmiref1; $cutext .= $culist[$j]; $j++; $cutext .= $culist[$j]; $j++; $cutext .= $culist[$j]; $j++; $j = $kcmiref2; # while ($j<=$#culist) { while ($culist[$j] !~ /^\$\$/) { if (($culist[$j] =~ /3 to 5/i) || ($culist[$j] =~ /extended/i)) { # last; } # print STDOUT $culist[$j]."\n"; $cutext .= $culist[$j]; $j++; } open (CUOUTFILE,$cuoutfile)||die "nope"; # print $cutext; print CUOUTFILE $cutext; close (CUOUTFILE); } else { print "NO CHAMPAIGN FORECAST\n"; } } else { print "NO CU FILE FOUND\n"; } #################################### # Illinois if (-e $ilfile) { open (ILINFILE,$ilfile); print "IL State Forecast Found\n"; $i = 0; while () { if ($_ =~ /FPUS63 KLOT/i) { $kilref=$i; } $illist[$i]=$_; $i++; } $j = $kilref; while ($j<=$#illist-2) { # print STDOUT $illist[$j]; if ($illist[$j+1] =~ /^\$\$/) { # $j=$#illist-1; last; } $iltext .= $illist[$j]; $j++; } close (ILINFILE); open (ILOUTFILE,$iloutfile); # print $iltext; print ILOUTFILE $iltext; close (ILOUTFILE); } else { print "NO IL FILE FOUND\n"; } #################################### #################################### # Indiana $exflag=0; if (-e $infile) { open (ININFILE,$infile); print "IN State Forecast Found\n"; $i = 0; while () { # print $i; if ($_ =~ /FPUS63 KIND/i) { $kinref=$i; } $inlist[$i]=$_; # print $_; $i++; } $j = $kinref; while ($j<$#inlist-2) { if ($inlist[$j+1] =~ /^\$\$/) { last; } if (($inlist[$j] !~ /^.[a-zA-Z0-9 ]/)&&($exflag==1)) { # print STDOUT "Blank Line Coming...Must be end of forecast\n"; # print STDOUT "Line is: ".$inlist[$j]; # print STDOUT "Previous line is: ".$inlist[$j-1]; last; } if ($inlist[$j] =~ /extended/i) { $exflag = 1; } $intext .= $inlist[$j]; $j++; } close (ININFILE); open (INOUTFILE,$inoutfile); # print $intext; print INOUTFILE $intext; close (INOUTFILE); } else { print "NO IN FILE FOUND\n"; } #exit(1); ######################################################################## # check to see if the forecast is too old ######################################################################## $flag=0; $actualline = `date`; #$actualline="Mon May 01 08:00:21 CDT 1999"; #print "\nDATE=".$actualline."\n"; @actualdate=split(/ +/,$actualline); #$mon=$actualdate[1]; $dnum=$actualdate[2]; $newtime=$actualdate[3]; @actualtime=split(/:/,$newtime); $actualhh=$actualtime[0]; print "ACTUALTIME=".$actualhh."\n"; #$lscommand="-rw-r--r-- 1 bramer mohan 214 Apr 30 23:38 c-u_fcst.txt"; @lsarray=split(/\n/,$lscommand); $i = 0; $olddnum="32"; while($i<=$#lsarray) { if ($lsarray[$i] =~ /history\.txt/) { print $lsarray[$i]."\n"; @filedate = split(/ +/,$lsarray[$i]); $oldtime = $filedate[7]; $olddnum = $filedate[6]; $oldmon = $filedate[5]; @filetime=split(/:/,$oldtime); $filehh=$filetime[0]; } $i++; } if ($olddnum=="32") { $flag=1; } $filehh++; print "FILETIME=".$filehh."\n"; $hhseparation = $actualhh-$filehh; print "DNUM=".$dnum."\n"; print "OLDDNUM=".$olddnum."\n"; $ddseparation = $dnum-$olddnum; if ($ddseparation < 0) { if ($oldmon=~/Jan/){$nummondays = 31;} if ($oldmon=~/Feb/){$nummondays = 28;} if ($oldmon=~/Mar/){$nummondays = 31;} if ($oldmon=~/Apr/){$nummondays = 30;} if ($oldmon=~/May/){$nummondays = 31;} if ($oldmon=~/Jun/){$nummondays = 30;} if ($oldmon=~/Jul/){$nummondays = 31;} if ($oldmon=~/Aug/){$nummondays = 31;} if ($oldmon=~/Sep/){$nummondays = 30;} if ($oldmon=~/Oct/){$nummondays = 31;} if ($oldmon=~/Nov/){$nummondays = 30;} if ($oldmon=~/Dec/){$nummondays = 31;} $dnum = $dnum + $nummondays; } $ddseparation = $dnum-$olddnum; print "DAY SEPARATION=".$ddseparation."\n"; if ($ddseparation >= 2) { $flag = 1; print "More than two days apart\n"; } if (($ddseparation == 1)&&(($filehh<=17)||($actualhh>=8))) { $flag = 1; print "Trick case\n"; } if ($hhseparation<0) { $actualhh+=24; $hhseparation = $actualhh-$filehh; } print "HOUR SEPARATION=".$hhseparation."\n"; if ($hhseparation >= 6) { $flag=1; print "Simple old result\n"; } #print "ACTUALMONTH=".$mon."\n"; #print "FILEMONTH=".$oldmon."\n"; #if (($separation <6) && (($olddnum<$dnum)||($oldmon !~ $mon))) { # $flag=1; #} ######################################################################## # Replace the old file (if necessary) ######################################################################## if ($flag==1) { print "TIME TO INSERT NWS TEXT\n\n"; system("/home/ice/a/www/fcst/admin/automate.pl"); } # always do this system("/home/ice/a/www/fcst/admin/automate_state_ext.pl");