#!/usr/local/bin/perl # PERL program to list currently active storms # The input file is assumed to be sorted by time # Copyright (C) 1996 Thomas R. Metcalf # # This software is provided "as is" and is subject to change without # notice. No warranty of any kind is made with regard to this software, # including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose. The author shall # not be liable for any errors or for direct, indirect, special, # incidental or consequential damages in connection with the furnishing, # performance, or use of this software: use it at your own risk. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # require "/data1/WWW/Tropical/Bin/locations.pl"; %locations = &LOCATIONS(); $piover2 = atan2(1,0); $pi = $piover2*2; $dtor = $piover2/90; $GREP = '/bin/grep'; $RCP = '/usr/ucb/rcp'; $DATAFILTER = '/data1/WWW/Tropical/Bin/tcdata2html'; $CLIPFILTER = '/data1/WWW/Tropical/Bin/tcdata2clip'; $WMLFILTER = '/data1/WWW/Tropical/Bin/tcdata2wml'; $DATADIR = '/data1/WWW/Tropical/Data'; $CLIPDIR = '/data1/WWW/Tropical/HTML/Clip'; $WMLDIR = '/data1/WWW/Tropical/HTML/WML'; $DATE = 21; $ACTDATE = 23; $OBSTYPE = 20; $STOTYPE = 19; $LATITUDE = 5; $LONGITUDE = 7; $WIND = 16; $NS = 6; $EW = 8; $TNAME = 9; $TYEAR = 0; $TMONTH = 1; $TDAY = 2; $TTIME = 3; $oneday = 0.00273225; # Open input file if ($#ARGV == 0) { $tropfile = $ARGV[0]; } else { $tropfile = '-'; } open(TROPICAL,$tropfile) || die "Couldn't open $tropfile"; # Get current time ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; if ($year>=94) {$year+=1900;} else {$year+=2000;} $now = $year + ($yday+1 + ($hour/24.0))/366.0; $mon += 1; if ($mon < 10) {$mon="0"."$mon";} if ($mday < 10) {$mday="0"."$mday";} if ($hour < 10) {$hour="0"."$hour";} if ($min < 10) {$min="0"."$min";} # Scan the input file $found_one = 0; while () { s/ / /g; # Make sure there are no multiple spaces @line = split(/ /); if ($#line >= 23) { if ($line[$DATE] > ($now-$oneday) && $line[$OBSTYPE] eq "ACT") { $latest{$line[$TNAME]} = $_; $found_one = 1; } } } # Save the latest data if ($found_one && $tropfile ne '-') { foreach $key (sort(keys %latest)) { my $skey = substr($key,0,length($key)-3); system("$GREP \" $key\" $tropfile | $DATAFILTER > $DATADIR/$key.html"); system("$GREP \" $key\" $tropfile | $CLIPFILTER > $CLIPDIR/${skey}_history.html"); system("$GREP \" $key\" $tropfile | $WMLFILTER > $WMLDIR/${skey}_history.wml"); system("$GREP \" $key\" $tropfile > $DATADIR/$key"); } } # Print the latest storm data print "\n"; if ($found_one) { $~ = 'STDOUT'; $^ = 'STDOUT_TOP'; $longest_key = 4; # 4 is the minimum foreach $key (sort(keys %latest)) { if (length($key)-3 > $longest_key) {$longest_key = length($key)-3;} } $keycount = 0; $name_dash = ""; $name_space = ""; while (length($name_dash) < $longest_key) {$name_dash .= "-";} while ((length($name_space)+4) < $longest_key) {$name_space .= " ";} foreach $key (sort(keys %latest)) { @line = split(/ /,$latest{$key}); #print "$line[$TNAME] $line[$TYEAR] $line[$TMONTH] $line[$TDAY] $line[$TTIME] $line[$LATITUDE] $line[$NS] $line[$LONGITUDE] $line[$EW]"; ($name,$year,$month,$day,$hour,$minute)=split(/ /,$outline[$i]); $line[$TNAME] =~ /(.*)(\-\d\d)/; $name = "\U$1"; $fname = $key; $append_spaces = ""; while ((length($append_spaces)+length($name)) < $longest_key) { $append_spaces .= " "; } $wwwname = "\$name\".$append_spaces; $gifname = "\$name\".$append_spaces; $wind = $line[$WIND]; while (length($wind) < 3) {$wind = "0".$wind;} $wind = $wind." kts"; $year = $line[$TYEAR]; $month = $line[$TMONTH]; $day = $line[$TDAY]; $line[$TTIME] =~ /(\d+)\.(\d*)/; $hour = $1; $minute = $2; $lat = $line[$LATITUDE]; while (length($lat) < 4) {$lat = "0".$lat;} $lat .= $line[$NS]; $latnum = $line[$LATITUDE]; if ($line[$NS] =~ /S/i) {$latnum = -$latnum;} $lon = $line[$LONGITUDE]; while (length($lon) < 5) {$lon = "0".$lon;} $lon .= $line[$EW]; $lonnum = $line[$LONGITUDE]; if ($line[$EW] =~ /E/i) {$lonnum = -$lonnum;} $stotype = $line[$STOTYPE]; while (length($stotype) < 4) {$stotype .= " ";} $ocean = ""; if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 110 && $line[$LONGITUDE] >= 10) {$ocean .= "S Atlantic ";} if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 170 && $line[$LONGITUDE] >= 70) {$ocean .= "SE Pacific ";} if ($line[$NS] eq "N" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 110 && $line[$LONGITUDE] >= 10) {$ocean .= "Atlantic ";} if ($line[$NS] eq "N" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 80) {$ocean .= "NW Pacific ";} if ($line[$NS] eq "S" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 100) {$ocean .= "SW Pacific ";} if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 160) {$ocean .= "SW Pacific ";} if ($line[$NS] eq "N" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 80) {$ocean .= "NE Pacific ";} if ($line[$NS] eq "N" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 135 && $line[$LONGITUDE] >= 35) {$ocean .= "N Indian ";} if ($line[$NS] eq "S" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 135 && $line[$LONGITUDE] >= 35) {$ocean .= "S Indian ";} if (length($month) < 2) {$month = "0".$month;} if (length($day) < 2) {$day = "0".$day;} if (length($hour) < 2) {$hour = "0".$hour;} if (length($minute) < 2) {$minute = "0".$minute;} if (length($minute) < 2) {$minute = "0".$minute;} $date = $year."-".$month."-".$day; $time = $hour.":".$minute." UT"; $dmin = 999999.; $locstring = ""; $locstring1 = ""; $locstringtemp= ""; $obest = ""; foreach $oskey (keys(%secondbest)) {$secondbest{$oskey}="";} foreach $location (keys(%locations)) { if (!$location) {next;} my ($lat,$lon,$o,$dthresh) = split(/\s+/,$locations{$location},4); $lat = int($lat) + ($lat-int($lat))*100.0/60.0; $lon = int($lon) + ($lon-int($lon))*100.0/60.0; my ($d,$c) = &GCDISTANCE($lat,$lon,$latnum,$lonnum); if ($d < $dthresh) { my $tcourse = &DEG2DIRECTION($c); my $dint = int($d + 0.5); my $locstringtemp = "$dint nmi $tcourse of $location"; if ($obest eq "" || $d < $dmin) { # save old as the second best if ($obest ne "") { $secondbest{$obest} = $locstring; $dminsecond{$obest} = $dmin; } # set up best $dmin = $d; $obest = $o; $locstring = $locstringtemp; } elsif ($secondbest{$o} eq "" || $d < $dminsecond{$o}) { $secondbest{$o} = $locstringtemp; $dminsecond{$o} = $d; } } } $locstring1 = $secondbest{$obest}; if ($keycount == 0) { print "Type Name${name_space} Date Time Lat Lon Wind Tracking Charts\n"; print "---- $name_dash ---------- -------- ----- ------ ------- ---------------\n"; } print "$stotype $wwwname $date $time $lat $lon $wind $gifname $ocean\n"; $outlocation = $outlocation . "At $date $time, $name was $locstring and $locstring1\n"; ++$keycount; } print "\n$outlocation"; } else { $~ = 'STDOUT_NONE'; $^ = 'STDOUT_TOP_NONE'; $date = $year."-".$mon."-".$mday; $time = $hour.":".$min." UT"; write; } ################### FORMATS ################################### format STDOUT_TOP = Type Name Date Time Lat Lon Wind Location ---- ----------------- ---------- --------- ----- ------ ------- ------------ . format STDOUT = @<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<@<<<<<<<< @<<<< @<<<<< @<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $stotype,$wwwname, $date, $time, $lat, $lon,$wind, $ocean, $locstring, $locstring1 . format STDOUT_TOP_NONE = No current tropical cyclones (last update @<<<<<<<<<<@<<<<