#!/usr/local/bin/perl # 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. # use Socket; if ($#ARGV != 1) { $SERVER = "metlab1.met.fsu.edu"; $PATH = '/weather/HURR'; } else { $SERVER = $ARGV[0]; $PATH = $ARGV[1]; } $PORT = "70"; # # Connect to the server # local($sockaddr,$here,$there,$response,$tries) = ("Snc4x8"); #$here = pack($sockaddr,2,0,&getaddress("localhost")); $there = pack($sockaddr,2,$PORT,&getaddress($SERVER)); local($proto); $proto = getprotobyname('tcp'); die "$0 $SERVER socket: $!\n" if (!socket(SOCK,PF_INET,SOCK_STREAM,$proto)); #die "$0 $SERVER socket: $!\n" if (!socket(SOCK,2,1,6)); die "$0 $SERVER connect: $!\n" if (!connect(SOCK,$there)); select(SOCK); $| = 1; select(STDOUT); $| = 1; # make unbuffered # # Initialize # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime; $mon += 1; @mondays = (31,28,31,30,31,30,31,31,30,31,30,31); if ($year % 4 == 0) { $mondays[1]+=1;} # Look for files which are +3 or -13 hours from now. The -13 gives 3 chances # to read each 6 hour update. The +3 is just for security. $lower = -13; $upper = +3; for ($dhour=$lower; $dhour<=$upper; ++$dhour) { $h = $hour+$dhour; $d = $mday; $m = $mon; $y = $year; while ($h < 0) { $h += 24; $d -= 1; if ($d < 1) { $m -= 1; if ($m < 1) { $m = 12; $y -= 1; if ($y < 0) {$y=99;} } $d = $mondays[$m-1]; } } while ($h > 24) { $h -= 24; $d += 1; if ($d > $mondays[$m-1]) { $d = 1; $m += 1; if ($m > 12) { $m = 1; $y += 1; if ($y > 99) {$y=0;} } } } if ($h < 10) {$h = "0"."$h";} if ($d < 10) {$d = "0"."$d";} if ($m < 10) {$m = "0"."$m";} if ($y < 10) {$y = "0"."$y";} $filetest[$dhour-$lower] = $y.$m.$d.$h # The file names to look for } # # Get the list of files to grab # printf SOCK "1/$PATH\n"; # get directory list $curline = ""; $fpointer = 0; LINE: while (read(SOCK,$c,1)) { if ($c eq "\n") { # Newline -> Check for match, start new line foreach $test (@filetest) { if ($curline =~ /($test\.(KNHC|KMIA|PHNL|PGTW|KGWC|RODN|HURR|PHNC|ABRF|JOINT_TYPHOON_WARNING_CENTER|NATIONAL_HURRICANE_CENTER|CANADIAN_HURRICANE_CENTRE|Naval_Western_Oceanography_Center))/i) { $filelist[$fpointer] = "$1"; ++$fpointer; } } if ($curline =~ /((WT|TP|WH)[A-Z][A-Z]\d\d\.(KNHC|KMIA|PHNL|PGTW|KGWC|RODN|HURR|PHNC|ABRF|JOINT_TYPHOON_WARNING_CENTER|NATIONAL_HURRICANE_CENTER|CANADIAN_HURRICANE_CENTRE|Naval_Western_Oceanography_Center))/i) { $filelist[$fpointer] = "$1"; ++$fpointer; } $curline = ""; next LINE; } if ($c eq "\r") { next LINE; } # Return -> ignore $curline .= $c; # Else add char to current line } # # Print the files which were found in the directory listing # foreach $fname (@filelist) { if ($fname ne "") { shutdown(SOCK,2); close(SOCK); die "$0 $SERVER socket: $!\n" if (!socket(SOCK,PF_INET,SOCK_STREAM,$proto)); #die "$0 $SERVER socket: $!\n" if (!socket(SOCK,2,1,6)); die "$0 $SERVER connect: $!\n" if (!connect(SOCK,$there)); select(SOCK); $| = 1; select(STDOUT); $| = 1; # make unbuffered printf SOCK "0/$PATH/$fname\n"; $curline = ""; while (read(SOCK,$c,1)) { if ($c eq "\n") { # Newline -> print, start new line $curline =~ s/\cC/NNNN/; $curline =~ s/\cA/NNNN/; print $curline, "\n"; $curline = ""; next; } if ($c eq "\r") { next; } # Return -> ignore $curline .= $c; # Else add char to current line } print $curline, "\n"; } } # # Clean up and done # shutdown(SOCK,2); close(SOCK); exit(0); ##################################################### sub getaddress { local($host) = @_; local(@ary); @ary = gethostbyname($host); return(unpack("C4",$ary[4])); } ###############################################################