#!/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. # $DATADIR = '/data1/WWW/Tropical/Data'; $CLIPDIR = '/data1/WWW/Tropical/HTML/Clip'; require "/data1/WWW/Tropical/Bin/locations.pl"; $piover2 = atan2(1,0); $pi = $piover2*2; $dtor = $piover2/90; $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; $GUST = 17; $COURSE = 10; $SPEED = 12; $PRESSURE = 14; $PRESSTYPE = 15; $oneday = 0.00273225; # Clean up CLIPDIR if (opendir(CLIPDIR,"$CLIPDIR")) { @stormfiles = grep {-M "$CLIPDIR/$_" > 14 && -f "$CLIPDIR/$_"} readdir(CLIPDIR); # Over 14 days old closedir(CLIPDIR); @stormfiles = grep {$_ = $CLIPDIR . "\/" . $_} @stormfiles; # Add path unlink @stormfiles; } # Open input file if ($#ARGV == 0) { $tropfile = $ARGV[0]; } else { $tropfile = '-'; } open(TROPICAL,$tropfile) || die "Couldn't open $tropfile"; # Open output file open(HTMLFILE,">"."$CLIPDIR/index.html") || die "Couldn't open $CLIPDIR/index.html"; # 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; } } } # Get the relative locations %locations = &LOCATIONS(); $ocean_abbrev{NWP} = "NW Pacific"; $ocean_abbrev{SWP} = "SW Pacific"; $ocean_abbrev{NEP} = "NE Pacific"; $ocean_abbrev{SEP} = "SE Pacific"; $ocean_abbrev{NIN} = "N Indian"; $ocean_abbrev{SIN} = "S Indian"; $ocean_abbrev{NAT} = "Atlantic"; $ocean_abbrev{SAT} = "S Atlantic"; $ocean_abbrev{CNP} = "N Pacific"; # Print the latest storm data $html_header = <<"HEADER_END"; Tropical Storms

Current Tropical Storms Worldwide:

HEADER_END $html_footer = <<"FOOTER_END";


Home | Strike Probs

Warning! These data may not be accurate. FOOTER_END $html_table_header = <<"TABLE_HEADER_END"; TABLE_HEADER_END $html_table_footer = <<"TABLE_FOOTER_END";
TABLE_FOOTER_END printf HTMLFILE "$html_header\n"; printf HTMLFILE "$html_table_header\n"; if ($found_one) { 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"; $wind = int($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;} $latns = $line[$NS]; $lon = $line[$LONGITUDE]; while (length($lon) < 5) {$lon = "0".$lon;} $lonew = $line[$EW]; $lonnum = $line[$LONGITUDE]; $latnum = $line[$LATITUDE]; if ($line[$NS] =~ /S/i) {$latnum = -$latnum;} else {$latnum = +$latnum;} if ($line[$EW] =~ /E/i) {$lonnum = -$lonnum;} else {$lonnum = +$lonnum;} $stotype = $line[$STOTYPE]; $gust = int($line[$GUST]); $gust .= " kts"; $course = $line[$COURSE]; $speed = $line[$SPEED]; if (!($course =~ /\?/)) { $direction = &DEG2DIRECTION($course); $course .= ' True'; } else {$direction = '???';} if (!($speed =~ /\?/)) { $speed = int($line[$SPEED]); $speed .= " kts"; } $pressure = $line[$PRESSURE]; $pressure .= " ".$line[$PRESSTYPE]; my @ocean; if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 110 && $line[$LONGITUDE] >= 10) {push @ocean,"SAT";} if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 170 && $line[$LONGITUDE] >= 70) {push @ocean,"SEP";} if ($line[$NS] eq "N" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 110 && $line[$LONGITUDE] >= 10) {push @ocean,"NAT";} if ($line[$NS] eq "N" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 80) {push @ocean,"NWP";} if ($line[$NS] eq "S" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 100) {push @ocean,"SWP";} if ($line[$NS] eq "S" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 160) {push @ocean,"SWP";} if ($line[$NS] eq "N" && $line[$EW] eq "W" && $line[$LONGITUDE] <= 180 && $line[$LONGITUDE] >= 80) {push @ocean,"NEP";} if ($line[$NS] eq "N" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 135 && $line[$LONGITUDE] >= 35) {push @ocean,"NIN";} if ($line[$NS] eq "S" && $line[$EW] eq "E" && $line[$LONGITUDE] <= 135 && $line[$LONGITUDE] >= 35) {push @ocean,"SIN";} 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"; $latmin = int(($lat-int($lat))*60); $lonmin = int(($lon-int($lon))*60); while (length($latmin) < 2) {$latmin = "0".$latmin;} while (length($lonmin) < 2) {$lonmin = "0".$lonmin;} $lat = int($lat)."°".$latmin."´"." ".$latns; $lon = int($lon)."°".$lonmin."´"." ".$lonew; $dmin = 999999.; $locstring = ""; $locstring1 = ""; $locstringtemp= ""; foreach $location (keys(%locations)) { 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 ($#ocean > 0 && grep($_ eq $obest,@ocean)) { $ocean = $ocean_abbrev{$obest}; } else { $ocean = $ocean_abbrev{$ocean[0]}; } #print join(" ",($ocean,$name,@ocean,"|",$obest,"\n")); printf HTMLFILE "\n"; printf HTMLFILE " $stotype\n"; printf HTMLFILE " $name\n"; printf HTMLFILE " $ocean\n"; printf HTMLFILE "\n"; $storm_html_header = <<"STORM_HEADER_END"; $name $date $time

STORM_HEADER_END $storm_html_footer = <<"STORM_FOOTER_END"; STORM_FOOTER_END $storm_html_body = <<"STORM_BODY_END";

$stotype $name ($ocean)


$date $time

$locstring
$locstring1

STORM_BODY_END if (open(STORMFILE,">"."$CLIPDIR/${name}.html")) { printf STORMFILE $storm_html_header; printf STORMFILE $storm_html_body; if (!($speed =~ /\?/) && !($direction =~ /\?/)) { printf STORMFILE "\n"; printf STORMFILE " \n"; } if (!($pressure =~ /\?/)) { printf STORMFILE "\n"; printf STORMFILE " \n"; } printf STORMFILE "
Latitude $lat
Longitude $lon
Wind $wind
Gusts $gust
Motion\n"; printf STORMFILE " $direction at $speed\n"; printf STORMFILE "
Pressure\n"; printf STORMFILE " $pressure\n"; printf STORMFILE "
\n"; printf STORMFILE "


Home | \n"; printf STORMFILE "History~2k | \n"; printf STORMFILE "Strike Probs\n"; printf STORMFILE "

Warning!These data may not be accurate\n"; printf STORMFILE $storm_html_footer; close STORMFILE; } #printf HTMLFILE "$stotype $wwwname $date $time $lat $lon $wind $gifname $ocean\n"; } printf HTMLFILE "\n"; } else { $date = $year."-".$mon."-".$mday; $time = $hour.":".$min." UT"; printf HTMLFILE "\n"; printf HTMLFILE " No current tropical cyclones\n"; printf HTMLFILE "\n"; printf HTMLFILE "\n"; printf HTMLFILE " (last update $date $time)\n"; printf HTMLFILE "\n"; } printf HTMLFILE "$html_table_footer\n"; printf HTMLFILE "$html_footer\n"; close HTMLFILE; exit;