TropicalCyclone/ForecastAdvisory.pm

filter: Statementstmt 91.3% 244 / 267 Branchbran 59.3% 51 / 86 Conditioncond 51.8% 14 / 27 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 79.5% 323 / 406 CC 54 SCAR 38.8
CC
54
Cov
81%
extract_atcf
67.9
new
6.0
_parseIotachs
5.0
CRAP 48.5
↑ Summary TropicalCyclone/Storm.pm »
1 package Weather::NHC::TropicalCyclone::ForecastAdvisory;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Date::Calc;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Util::H2O::More qw/baptise/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 5 ▶ my ( $pkg, %self ) = @_;
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
11  
12 # input_file and input_text are mutually exclusive via the contructor
13 5 ▶ if ( not( exists $self{input_file} or exists $self{input_text} ) or ( exists $self{input_file} and exists $self{input_text} ) or not exists $self{output_file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self{"input_file"} || exists $self{"input_text"} or exists $self{"input_file"} and exists $self{"input_text"} or not exists $self{"output_file"}) 2 2 4
Condition100%12/12
not exists $self{"input_file"} || exists $self{"input_text"} or exists $self{"input_file"} and exists $self{"input_text"} or not exists $self{"output_file"}
l!l&&r!l&&!r
212
not exists $self{"input_file"} || exists $self{"input_text"} or exists $self{"input_file"} and exists $self{"input_text"}
l!l&&r!l&&!r
113
exists $self{'input_file'} || exists $self{'input_text'}
l!l&&r!l&&!r
311
exists $self{"input_file"} and exists $self{"input_text"}
!ll&&!rl&&r
121
MC/DC80%4/5
not exists $self{"input_file"} || exists $self{"input_text"} or exists $self{"input_file"} and exists $self{"input_text"} or not exists $self{"output_file"}
exists $self{'input_file'} exists $self{'input_text'} exists $self{"input_file"} exists $self{"input_text"} not exists $self{"output_file"}
Truth table45%5/11
not(A || B) or C and D or not(E)
A= exists $self{'input_file'}B= exists $self{'input_text'}C= exists $self{"input_file"}D= exists $self{"input_text"}E= not exists $self{"output_file"}
ABCDEresult
00XXX1
1X11X1
0111X1
1X0X11
1X1011
010X11
011011
1X0X00
1X1000
010X00
011000
14 3 die qq{Constructor requires specifying the 'input_file' xor 'input_text', and 'output_file' parameters.\n};
15 }
16 2 my @fields = (qw/input_file input_text output_file as_atcf/);
17 2 my $self = baptise -recurse, \%self, $pkg, @fields;
18 2 return $self;
19 }
20  
21 sub extract_and_save_atcf {
22 2 ▶ my $self = shift;
Subroutine extract_and_save_atcf: called CC=1 SCAR=0.0
Pod undocumented
23 2 $self->extract_atcf;
24 2 return $self->save_atcf;
25 }
26  
27 sub save_atcf {
28 4 ▶ my $self = shift;
Subroutine save_atcf: called CC=2 SCAR=7.0
Pod undocumented
29 4 ▶ open( my $fh, q{>}, $self->output_file ) || die qq{Failed to open output ATCF file} . $self->output_file . qq{ : $!.\n};
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->output_file or die 'Failed to open output ATCF file' . $self->output_file . " : $!.\n" 0 4 4
30 4 my $output_ref = $self->as_atcf;
31 4 print $fh join( qq{\n}, @$output_ref );
32 4 close $fh;
33 4 return $self->output_file;
34 }
35  
36 sub extract_atcf {
37 4 ▶ my $self = shift;
Subroutine extract_atcf: called CC=44 SCAR=42.2
Pod undocumented
38  
39 4 my @lines = ();
40  
41 ADVISORY_SOURCE:
42 4 ▶ if ( $self->input_file ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->input_file) { } 2 2 4
elsif ($self->input_text) { } 2 0 2
43 2 ▶ open( my $INPUT, q{<}, $self->input_file ) || die q{Failed to open forecast advisory file} . $self->input_file . qq{ for conversion to ATCF format: $!.\n};
Branch: 1 branch
BranchTrueFalseTotal
open my $INPUT, "<", $self->input_file or die 'Failed to open forecast advisory file' . $self->input_file . " for conversion to ATCF format: $!.\n" 0 2 2
44 2 @lines = (<$INPUT>);
45 2 close $INPUT;
46 }
47 elsif ( $self->input_text ) {
48 2 @lines = split /\n/, $self->input_text;
49 }
50  
51 4 my @output = (); # accumulate content for $output, do write at the very end
52  
53 # parse rss reports from Nat'l Hurricane Center Atlantic Marine Forecast
54 # Advisory. NHC Mail (Atlantic Marine)
55 # <mail-storm-atlan-marine@seahorse.nhc.noaa.gov> See:
56 # http://www.nhc.noaa.gov/signup.shtml and select the following list: Atlantic
57 # Marine (Forecast/Advisories and updates ONLY)
58  
59 # BASIN,CY,YYYYMMDDHH,TECHNUM,TECH,TAU,LatN/S,LonE/W,VMAX,MSLP,TY,RAD,WINDCODE,RAD1,RAD2,RAD3,RAD4,RADP,RRP,MRD,GUSTS,EYE,SUBREGION,MAXSEAS,INITIALS,DIR,SPEED,STORMNAME,DEPTH,SEAS,SEASCODE,SEAS1,SEAS2,SEAS3,SEAS4
60 #
61 # 1 1 1 1 1 1 1 1 1 1
62 # 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
63 #01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
64 #AL, 01, 2009052912, 03, OFCL, 0, 393N, 649W, 30, 1006, TD, 34, NEQ, 0, 0, 0, 0, 0, 0, 40, 40, 0, , 0, TBK, 65, 17, , , 12, NEQ, 60, 60, 0, 0
65 4 my $template = "_BASIN_, 01, 2009010100, , OFCL, 0, 000N, 000W, 30, 0, , 34, NEQ, 0, 0, 0, 0, 0, 0, 0, 40, 0, , 0, TBK, 65, 17, , , 12, NEQ, 60, 60, 0, 0";
66 4 my %month_lookup = ( dummy => '00', JAN => '01', FEB => '02', MAR => '03', APR => '04', MAY => '05', JUN => '06', JUL => '07', AUG => '08', SEP => '09', OCT => '10', NOV => '11', DEC => '12' );
67  
68 # These are the data we are extracting
69 4 my $pressure;
70 4 my $storm_class = "";
71 4 my $storm_name;
72 my $storm_basin;
73 4 my $storm_number;
74 4 my $adv_num;
75 4 my $storm_year;
76 4 my $nowcast_year;
77 4 my $forecast_year;
78 4 my $nowcast_month;
79 4 my $forecast_month;
80 4 my $nowcast_day;
81 4 my $forecast_day;
82 4 my $nowcast_hour;
83 4 my $forecast_hour;
84 4 my $date_time;
85 4 my $forecast_date_time;
86 4 my $nowcast_date_time;
87 4 my $nowcast_max_wind;
88 4 my $forecast_max_wind;
89 4 my $atcf_line = $template;
90 4 my $lat;
91 my $lon;
92 4 my $vmax;
93 4 my $gusts; # in kt
94 4 my $center_direction = 65;
95 4 my $center_speed = 17;
96  
97 4 my $body_ref = \@lines;
98 4 my $cnt = @{$body_ref};
99 #
100 4 my @match = ();
101  
102 # Get the NHC Number
103 # NWS TPC/NATIONAL HURRICANE CENTER MIAMI FL AL172005
104 4 @match = grep /(?:AL|EP|CP|WP|IO|SH|LS)\d{2}\d{4}$/, @{$body_ref};
105 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
106 4 ▶ if ( $match[0] =~ /(AL|EP|CP|WP|IO|SH|LS)(\d{2})(\d{4})$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /(AL|EP|CP|WP|IO|SH|LS)(\d{2})(\d{4})$/) 4 0 4
107 4 $storm_basin = $1;
108 4 $storm_number = $2;
109 4 $storm_year = $3;
110 }
111 4 ▶ die qq{NO NHC NUMBER/YEAR\n} if not $storm_number or not $storm_year or not $storm_basin;
Branch: 1 branch
BranchTrueFalseTotal
unless $storm_number and $storm_year and $storm_basin 0 4 4
Condition33%2/6
$storm_number and $storm_year and $storm_basin
!ll&&!rl&&r
004
$storm_number and $storm_year
!ll&&!rl&&r
004
MC/DC0%0/3
$storm_number and $storm_year and $storm_basin
$storm_number $storm_year $storm_basin
Truth table25%1/4
A and B and C
A= $storm_numberB= $storm_yearC= $storm_basin
ABCresult
0XX0
10X0
1100
1111
112 }
113 4 $atcf_line =~ s/_BASIN_/$storm_basin/;
114 4 my $storm_number_str = sprintf( "%02d", $storm_number );
115 4 substr( $atcf_line, 4, 2 ) = $storm_number_str;
116  
117 # Date format
118 # 1500Z THU SEP 02 2004
119 # July 18th TD 2. HAS CHANGED
120 # NOTE NOTE NOW! 1500 UTC TUE JUL 18 2006
121 4 ▶ if ( $storm_year > 2005 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storm_year > 2005) { } 4 0 4
122 4 @match = grep /^\d{4} .+ \d{4}$/, @{$body_ref};
123 }
124 else {
125 0 @match = grep /^\d{4}Z .+ \d{4}$/, @{$body_ref};
126 }
127 #
128 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
129 4 $date_time = $match[0];
130 4 chomp $date_time;
131 4 my @vals = split( ' ', $date_time );
132 4 $nowcast_hour = substr( $vals[0], 0, 2 );
133 4 ▶ if ( $storm_year > 2005 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storm_year > 2005) { } 4 0 4
134 4 $nowcast_year = $vals[5];
135 4 $nowcast_month = $month_lookup{ $vals[3] };
136 4 $nowcast_day = $vals[4];
137 }
138 else {
139 0 $nowcast_year = $vals[4];
140 0 $nowcast_month = $month_lookup{ $vals[2] };
141 0 $nowcast_day = $vals[3];
142 }
143 4 $nowcast_date_time = $nowcast_year . $nowcast_month . $nowcast_day . $nowcast_hour;
144 4 substr( $atcf_line, 8, 10 ) = sprintf( "%10d", $nowcast_date_time );
145 }
146  
147 # advisory number does not appear in the ATCF format
148 4 @match = grep /FORECAST.+ADVISORY NUMBER/, @{$body_ref};
149  
150 # HURRICANE FRANCES ADVISORY NUMBER 40
151 # HURRICANE FRANCES FORECAST/ADVISORY NUMBER 37
152 # HURRICANE FRANCES FORECAST/ADVISORY NUMBER 37...CORRECTED
153 # HURRICANE FRANCES SPECIAL FORECAST/ADVISORY NUMBER 37
154 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) { } 4 0 4
155 4 ▶ if ( $match[0] =~ /^(.+)\s+FORECAST.+ADVISORY NUMBER\s+(\d{1,3})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /^(.+)\s+FORECAST.+ADVISORY NUMBER\s+(\d{1,3})/) 4 0 4
156 4 $storm_name = $1;
157 4 $adv_num = $2;
158 4 $storm_name =~ s/SPECIAL//;
159 }
160 }
161 else {
162 0 @match = grep /ADVISORY NUMBER/, @{$body_ref};
163 0 ▶ if ( $match[0] =~ /^(.+)\s+ADVISORY NUMBER\s+(\d{1,3})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /^(.+)\s+ADVISORY NUMBER\s+(\d{1,3})/) 0 0 0
164 0 $storm_name = $1;
165 0 $adv_num = $2;
166 }
167 }
168 4 my @tmp = split( ' ', $storm_name );
169 4 ▶ if ( $tmp[0] eq 'HURRICANE' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($tmp[0] eq 'HURRICANE') { } 4 0 4
elsif ($tmp[0] eq 'POTENTIAL') { } 0 0 0
elsif ($tmp[0] eq 'TROPICAL' or $tmp[0] eq 'SUBTROPICAL' or $tmp[0] eq 'REMNANTS' or $tmp[0] eq 'POST-TROPICAL') { } 0 0 0
170 4 $storm_class = $tmp[0];
171 4 $storm_name = $tmp[1];
172 }
173 elsif ( $tmp[0] eq 'POTENTIAL' ) {
174 0 $storm_class = "$tmp[0] $tmp[1] $tmp[2]";
175 0 $storm_name = $tmp[3];
176 }
177 ▶ elsif ( $tmp[0] eq 'TROPICAL' or $tmp[0] eq 'SUBTROPICAL' or $tmp[0] eq 'REMNANTS' or $tmp[0] eq 'POST-TROPICAL' ) {
Condition0%0/9
$tmp[0] eq "TROPICAL" or $tmp[0] eq "SUBTROPICAL" or $tmp[0] eq "REMNANTS" or $tmp[0] eq "POST-TROPICAL"
l!l&&r!l&&!r
000
$tmp[0] eq "TROPICAL" or $tmp[0] eq "SUBTROPICAL" or $tmp[0] eq "REMNANTS"
l!l&&r!l&&!r
000
$tmp[0] eq "TROPICAL" or $tmp[0] eq "SUBTROPICAL"
l!l&&r!l&&!r
000
MC/DC0%0/4
$tmp[0] eq "TROPICAL" or $tmp[0] eq "SUBTROPICAL" or $tmp[0] eq "REMNANTS" or $tmp[0] eq "POST-TROPICAL"
$tmp[0] eq "TROPICAL" $tmp[0] eq "SUBTROPICAL" $tmp[0] eq "REMNANTS" $tmp[0] eq "POST-TROPICAL"
Truth table0%0/5
A or B or C or D
A= $tmp[0] eq "TROPICAL"B= $tmp[0] eq "SUBTROPICAL"C= $tmp[0] eq "REMNANTS"D= $tmp[0] eq "POST-TROPICAL"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
178  
179 # SUBTROPICAL is rare. see 2007 01
180 0 $storm_class = "$tmp[0] $tmp[1]";
181 0 $storm_name = $tmp[2];
182 }
183 4 substr( $atcf_line, 148, 10 ) = sprintf( "%10s", $storm_name );
184 4 my $adv_num_str = sprintf( "%02d", $adv_num );
185 4 my $adv_num_url_str = sprintf( "%03d", $adv_num );
186  
187 # HURRICANE CENTER LOCATED NEAR 23.4N 73.9W AT 02/1500Z
188 # or
189 #TROPICAL DEPRESSION DISSIPATING NEAR 29.0N 70.0W AT 24/2100Z
190 # or
191 # TROPICAL DEPRESSION CENTER LOCATED NEAR 11.2N 36.0W AT 25/0300Z
192 4 @match = grep /(CENTER LOCATED|DISSIPATING) NEAR/, @{$body_ref};
193 4 my $ns_hem = "N";
194 4 my $ew_hem = "W";
195 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
196 4 ▶ if ( $match[0] =~ /CENTER LOCATED NEAR\s+(\d{1,3}\.\d{1,2})([N|S])\s+(\d{1,3}\.\d{1,2})([E|W])\s+AT/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /CENTER LOCATED NEAR\s+(\d{1,3}\.\d{1,2})([N|S])\s+(\d{1,3}\.\d{1,2})([E|W])\s+AT/) 4 0 4
197 4 $lat = $1;
198 4 $ns_hem = $2;
199 4 $lon = $3;
200 4 $ew_hem = $4;
201 }
202 4 ▶ if ( $match[0] =~ /DISSIPATING NEAR\s+(\d{1,3}\.\d{1,2})([N|S])\s+(\d{1,3}\.\d{1,2})([E|W])\s+AT/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /DISSIPATING NEAR\s+(\d{1,3}\.\d{1,2})([N|S])\s+(\d{1,3}\.\d{1,2})([E|W])\s+AT/) 0 4 4
203 0 $lat = $1;
204 0 $ns_hem = $2;
205 0 $lon = $3;
206 0 $ew_hem = $4;
207 }
208 }
209  
210 4 my $nowcast_lat = sprintf( "%4d$ns_hem", $lat * 10 );
211 4 my $nowcast_lon = sprintf( "%4d$ew_hem", $lon * 10 );
212 4 substr( $atcf_line, 34, 5 ) = sprintf( "%5s", $nowcast_lat );
213 4 substr( $atcf_line, 41, 5 ) = sprintf( "%5s", $nowcast_lon );
214  
215 #PRESENT MOVEMENT TOWARD THE NORTH-NORTHWEST OR 330 DEGREES AT 9 KT
216 4 @match = grep /^PRESENT MOVEMENT TOWARD THE/, @{$body_ref};
217 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
218 4 ▶ if ( $match[0] =~ /PRESENT MOVEMENT TOWARD THE.+OR\s+(\d{1,3})\s+DEGREES AT\s+(\d{1,2})\s+KT/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /PRESENT MOVEMENT TOWARD THE.+OR\s+(\d{1,3})\s+DEGREES AT\s+(\d{1,2})\s+KT/) 4 0 4
219 4 $center_direction = $1;
220 4 $center_speed = $2;
221 }
222 4 substr( $atcf_line, 138, 4 ) = sprintf( "%4d", $center_direction );
223 4 substr( $atcf_line, 143, 4 ) = sprintf( "%4d", $center_speed );
224 }
225  
226 4 @match = grep /^ESTIMATED MINIMUM CENTRAL PRESSURE/, @{$body_ref};
227 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
228 4 ▶ if ( $match[0] =~ /^ESTIMATED MINIMUM CENTRAL PRESSURE\s+(.+)\s+MB/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /^ESTIMATED MINIMUM CENTRAL PRESSURE\s+(.+)\s+MB/) 4 0 4
229 4 $pressure = $1;
230 }
231 }
232 4 substr( $atcf_line, 53, 4 ) = sprintf( "%4d", $pressure );
233  
234 #MAX SUSTAINED WINDS 25 KT WITH GUSTS TO 35 KT.
235 #MAX SUSTAINED WINDS 125 KT WITH GUSTS TO 155 KT.
236  
237 4 @match = grep /^MAX SUSTAINED WINDS/, @{$body_ref};
238  
239 4 ▶ if (@match) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match) 4 0 4
240 4 ▶ if ( $match[0] =~ /^MAX SUSTAINED WINDS\s+(\d{1,4}) KT WITH GUSTS TO\s+(\d{1,4})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match[0] =~ /^MAX SUSTAINED WINDS\s+(\d{1,4}) KT WITH GUSTS TO\s+(\d{1,4})/) 4 0 4
241 4 $vmax = $1;
242 4 $gusts = $2;
243 }
244 }
245  
246 4 substr( $atcf_line, 47, 4 ) = sprintf( "%4d", $vmax );
247 4 substr( $atcf_line, 113, 4 ) = sprintf( "%4d", $gusts );
248 4 my $forecast_atcf_filename = lc($storm_name) . "_advisory_" . $adv_num_str . ".fst";
249 #
250 # collect nowcast wind radii, if any
251 4 my $isotachs_found = 0;
252 4 my @isotachs;
253 4 for my $i ( 0 ... $#{$body_ref} ) {
254 76 ▶ if ( @{$body_ref}[$i] =~ /^MAX SUSTAINED WINDS/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$body_ref;}[$i] =~ /^MAX SUSTAINED WINDS/) 4 72 76
255  
256 #64 KT....... 45NE 30SE 20SW 30NW.
257 #50 KT.......120NE 75SE 60SW 75NW.
258 #34 KT.......175NE 120SE 120SW 120NW.
259 4 $i++;
260 4 while (1) {
261 16 ▶ if ( @{$body_ref}[$i] =~ /^(\d{1,2}) KT\.{7}\s{0,}(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$body_ref;}[$i] =~ /^(\d{1,2}) KT\.{7}\s{0,}(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]/) { } 12 4 16
262 12 $isotachs_found++;
263 12 my @wind_radii = ( $1, $2, $3, $4, $5 );
264 12 push @isotachs, @wind_radii;
265 }
266 else {
267 4 last;
268 }
269 12 $i++;
270 }
271 4 ▶ for ( my $j = $isotachs_found; $j > 0; $j-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > 0) 12 4 16
272 12 ▶ for ( my $k = 0; $k < 4; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < 4) 48 12 60
273 48 my $starting_pos = 72 + ( $k * 6 );
274 48 my $list_pos = 1 + $k + ( 5 * ( $j - 1 ) );
275  
276 # fill in wind radii
277 48 substr( $atcf_line, $starting_pos, 5 ) = sprintf( "%5d", $isotachs[$list_pos] );
278  
279 # fill in isotach
280 48 substr( $atcf_line, 63, 3 ) = sprintf( "%3d", $isotachs[ 5 * ( $j - 1 ) ] );
281 }
282 12 push @output, $atcf_line;
283 }
284 4 ▶ unless ($isotachs_found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isotachs_found) 0 4 4
285 0 push @output, $atcf_line;
286 }
287 4 last;
288 }
289 }
290  
291 # FORECAST tracks and points
292 # FORECAST VALID 10/0000Z 21.5N 84.5W FORECASTs have a bizzare date format:
293 # dd/hhmm BUT near end of the month say 31/0000 the forecast dates switch to
294 # 01/0000, 01/12000 so we need to check for this and increment the month.
295 4 my $forecast_period = 0;
296 4 $forecast_year = $nowcast_year;
297 4 $forecast_month = $nowcast_month;
298 4 $forecast_day = $nowcast_day;
299 4 $forecast_hour = $nowcast_hour;
300 4 my $i = 0;
301 4 ▶ while ( $i < $#{$body_ref} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#{$body_ref;}) 184 4 188
302 184 ▶ if ( @{$body_ref}[$i] =~ /^(FORECAST|OUTLOOK) VALID/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$body_ref;}[$i] =~ /^(FORECAST|OUTLOOK) VALID/) 32 152 184
303 32 my $atcf_line = $template;
304 32 $atcf_line =~ s/_BASIN_/$storm_basin/;
305  
306 # jgf20160105: fill in the storm number
307 32 substr( $atcf_line, 4, 2 ) = $storm_number_str;
308  
309 # fill in the nowcast time
310 32 substr( $atcf_line, 8, 10 ) = sprintf( "%10d", $nowcast_date_time );
311  
312 # fill in the storm name
313 32 substr( $atcf_line, 148, 10 ) = sprintf( "%10s", $storm_name );
314 32 my $line = @{$body_ref}[$i];
315 32 chomp $line;
316  
317 # if the storm will dissipate, there is no more data to process
318 32 ▶ if ( $line =~ /DISSIPATED/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /DISSIPATED/) 0 32 32
319 0 last;
320 }
321 32 ▶ if ( $line =~ /^(FORECAST|OUTLOOK) VALID\s+(\d{2})\/(\d{4})Z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[^(FORECAST|OUTLOOK) VALID\s+(\d{2})/(\d{4})Z]) 32 0 32
322 32 $forecast_day = $2;
323 32 $forecast_hour = substr( $3, 0, 2 );
324 }
325 32 ▶ if ( $line =~ /Z\s+(\d{1,2}\.\d{1,2})([N|S])\s+(\d{1,2}\.\d{1,2})([E|W])/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /Z\s+(\d{1,2}\.\d{1,2})([N|S])\s+(\d{1,2}\.\d{1,2})([E|W])/) 32 0 32
326 32 $lat = $1;
327 32 $ns_hem = $2;
328 32 $lon = $3;
329 32 $ew_hem = $4;
330 }
331 32 my $forecast_lat = sprintf( "%4d$ns_hem", $lat * 10 );
332 32 my $forecast_lon = sprintf( "%4d$ew_hem", $lon * 10 );
333 32 substr( $atcf_line, 34, 5 ) = sprintf( "%5s", $forecast_lat );
334 32 substr( $atcf_line, 41, 5 ) = sprintf( "%5s", $forecast_lon );
335  
336 # Get the next line
337 # MAX WIND 30 KT...GUSTS 40 KT.
338 32 $i++;
339 32 $line = @{$body_ref}[$i];
340 32 chomp $line;
341 32 ▶ if ( $line =~ /^MAX WIND\s+(\d{1,4}) KT\.\.\.GUSTS\s+(\d{1,4}) KT\./ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^MAX WIND\s+(\d{1,4}) KT\.\.\.GUSTS\s+(\d{1,4}) KT\./) 32 0 32
342 32 $vmax = $1;
343 32 $gusts = $2;
344 }
345 32 substr( $atcf_line, 47, 4 ) = sprintf( "%4d", $vmax );
346 32 substr( $atcf_line, 113, 4 ) = sprintf( "%4d", $gusts );
347 32 $forecast_date_time = sprintf( "%04d%02d%02d%02d", $forecast_year, $forecast_month, $forecast_day, $forecast_hour );
348  
349 # check to see if we have crossed into the next month
350 32 ▶ if ( $forecast_date_time < $nowcast_date_time ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forecast_date_time < $nowcast_date_time) 0 32 32
351 0 $forecast_month++;
352 0 ▶ if ( $forecast_month > 12 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($forecast_month > 12) 0 0 0
353 0 $forecast_month = 1;
354 }
355 }
356  
357 # Determine the time in hours (forecast period) between the current
358 # forecast and the nowcast time
359 32 ( my $ddays, my $dhrs, my $dsec ) = Date::Calc::Delta_DHMS( $nowcast_year, $nowcast_month, $nowcast_day, $nowcast_hour, 0, 0, $forecast_year, $forecast_month, $forecast_day, $forecast_hour, 0, 0 );
360 32 my $forecast_period = $ddays * 24 + $dhrs;
361 32 substr( $atcf_line, 29, 4 ) = sprintf( "%4d", $forecast_period );
362  
363 # Get the next line and parse the isotachs
364 32 $i++;
365 32 ( $i, my $output_ref ) = _parseIotachs( $body_ref, $i, $atcf_line );
366 32 push @output, @$output_ref;
367 }
368 184 $i++;
369 }
370  
371 # save in instance's internal field
372 4 $self->{as_atcf} = \@output;
373  
374 # return array reference for convenience
375 4 return $self->as_atcf;
376 }
377  
378 sub _parseIotachs {
379 32 ▶ my ( $body_ref, $i, $atcf_line ) = @_;
Subroutine _parseIotachs: called CC=5 SCAR=16.1
380 32 my $isotachs_found = 0;
381 32 my @isotachs = ();
382 32 my @output = ();
383 32 while (1) {
384  
385 #64 KT... 45NE 30SE 20SW 30NW.
386 96 ▶ if ( @{$body_ref}[$i] =~ /^(\d{1,2}) KT\.{3}\s{0,}(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$body_ref;}[$i] =~ /^(\d{1,2}) KT\.{3}\s{0,}(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]\s+(\d{1,3})[N|S][E|W]/) { } 64 32 96
387 64 $isotachs_found++;
388 64 my @wind_radii = ( $1, $2, $3, $4, $5 );
389 64 push @isotachs, @wind_radii;
390 }
391 else {
392 32 last;
393 }
394 64 $i++;
395 }
396 32 ▶ for ( my $j = $isotachs_found; $j > 0; $j-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > 0) 64 32 96
397 64 ▶ for ( my $k = 0; $k < 4; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < 4) 256 64 320
398 256 my $starting_pos = 72 + ( $k * 6 );
399 256 my $list_pos = 1 + $k + ( 5 * ( $j - 1 ) );
400  
401 # fill in wind radii
402 256 substr( $atcf_line, $starting_pos, 5 ) = sprintf( "%5d", $isotachs[$list_pos] );
403  
404 # fill in isotach
405 256 substr( $atcf_line, 63, 3 ) = sprintf( "%3d", $isotachs[ 5 * ( $j - 1 ) ] );
406 }
407 64 push @output, $atcf_line;
408 }
409 32 ▶ unless ($isotachs_found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($isotachs_found) 8 24 32
410 8 push @output, $atcf_line;
411 }
412 32 return ( $i, \@output );
413 }
414  
415 1 1;
416  
417 __END__
↑ Summary TropicalCyclone/Storm.pm »