#!/usr/bin/perl -w my $pkgdoc = <<'EOD'; #/**------------------------------------------------------------------- # @ file TC-parcer.pl # This script parses the fetched TC data from Dr. landsea's TC # reclassification project. # # @since 03/18/2008 # @usage TC-parcer.pl txtfile.txt # date: June 25, 2008 #--------------------------------------------------------------------*/ EOD # ## Pull arguments from the command line # use strict; use warnings; use Getopt::Long; if (@ARGV <1) { # if arg < 1 then print the pckdoc print $pkgdoc; exit -1; } my $txtfile = shift; # pulling arguments # ## Open text file with Dr. Landsea's data if not stop the program # open (DATA, $txtfile)||die "cannot open $txtfile for reading"; # ## Gather data from the title line which looks like: # ### 00065 08/16/1851 M=12 4 SNBR= 4 NOT NAMED XING=1 SSS=3 # while () { my ($CardNo, $MMDD, $YY, $TotalNo, $SNRB, $StormNo, $Name, $XING, $SSS)= m{^(\d+)\s+ (\d\d/\d\d) /(\d+)\s+ M=(\d+)\s+ (\d+)\s+ SNBR=\s*(\d+)\s+ (.+) \s* XING=(\d+)\s+ SSS=(d+) \s* $}x; $Name =~ s/NOT NAMED/NONAME/; # replacing NOT NAMED with NONAME $TotalNo = $TotalNo * 4; print "$MMDD $TotalNo $Name$StormNo-$YY $XING $SSS $CardNo\n"; last if $SSS !~ /[0-5]/; # skip to data lines } # ## Gather important data of the center of each storm # ### 00070 08/16*134 480 40 0*137 495 40 0*140 510 50 0*144 528 50 0* # while () { my ($CardNo, $MMDD, $Type, $LAT1, $LON1, $Vmax1, $Pmin1, $TET1, $LAT2, $LON2, $Vmax2, $Pmin2, $TET2, $LAT3, $LON3, $Vmax3, $Pmin3, $TET3, $LAT4, $LON4, $Vmax4, $Pmin4, $TET4) = m{^(\d+)\s+ (\d\d/\d\d)\s+ (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) (\d\d\d)\s+ (\d\d\d)\s+ (\d+)\s+ (\d+)\s+ (.+) \s* $}x; if ($TET1 = '*') {$TET1 = 'T';} if ($TET2 = '*') { $TET2 = 'T';} if ($TET3 = '*') { $TET3 = 'T';} if ($TET4 = '*') { $TET4 = 'T';} print "$MMDD 0000 $LAT1 $LON1 $Vmax1 $Pmin1 $TET1\n $MMDD 0600 $LAT2 $LON2 $Vmax2 $Pmin2 $TET2\n $MMDD 1200 $LAT3 $LON3 $Vmax3 $Pmin3 $TET3\n $MMDD 1800 $LAT4 $LON4 $Vmax4 $Pmin4 $TET4\n"; last if $TET4 !~ m/T|E$/; # end this storm's track } close (DATA);