blib/lib/Geo/BUFR.pm

filter: Statementstmt 84.0% 2459 / 2927 Branchbran 63.3% 1298 / 2050 Conditioncond 55.1% 382 / 693 MC/DCmcdc 29.6% 125 / 422 Subroutinesub 86.3% 127 / 147 Podpod 0.0% 0 / 94 totaltotal 69.3% 4391 / 6333 CC 1315 SCAR 51.0
CC
1315
Cov
73%
_apply_operator_descriptor
1099.1
_extract_compressed_value
218.0
_decode_bitstream
199.7
CRAP 163.7
« blib/script/bufralter.pl ↑ Summary blib/lib/Geo/bufrextract.pl »
1 package Geo::BUFR;
2  
3 # Copyright (C) 2010-2025 MET Norway
4 #
5 # This module is free software; you can redistribute it and/or
6 # modify it under the same terms as Perl itself.
7  
8 =begin General_remarks
9  
10 Some general remarks on variables
11 ---------------------------------
12  
13 @data = data array
14 @desc = descriptor array
15  
16 These 2 arrays are in one to one correspondence, but note that some C
17 descriptors (2.....) are included in @desc even though there is no
18 associated data value in message (the corresponding element in @data
19 is set to ''). These descriptors without value are printed in
20 dumpsection4 without line number, to distinguish them from 'real' data
21 descriptors.
22  
23 $idesc = index of descriptor in @desc (and @data)
24 $bm_idesc = index of bit mapped descriptor in @data (and @desc, see below)
25  
26 Variables related to bit maps:
27  
28 $self->{BUILD_BITMAP}
29 $self->{BITMAP_INDEX}
30 $self->{NUM_BITMAPS}
31 $self->{BACKWARD_DATA_REFERENCE}
32  
33 These are explained in sub new
34  
35 $self->{BITMAP_OPERATORS}
36  
37 Reference to an array containing operators in BUFR table C which are
38 associated with bit maps, i.e. one of 22[2-5]000 and 232000; the
39 operator being added when it is met in section 3 in message. Note that
40 an operator may occur multiple times, which is why we have to use an
41 array, not a hash.
42  
43 $self->{CURRENT_BITMAP}
44  
45 Reference to an array which contains the indexes of data values for
46 which data is marked as present in 031031 in the current used bit map.
47 E.g. [2,3,6] if bitmap = 1100110.
48  
49 $self->{BITMAP_START}
50  
51 Array containing for each bit map the index of the first element
52 descriptor for which the bit map relates.
53  
54 $self->{BITMAPS}
55  
56 Reference to an array, one element added for each bit map operator in
57 $self->{BITMAP_OPERATORS} and each subset (although for compression we
58 assume all subset have identical bitmaps and operate with subset 0
59 only, i.e. $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] instead of
60 ...->[$isub]), the element being a reference to an array containing
61 consecutive pairs of indexes ($idesc, $bm_idesc), used to look up in
62 @data and @desc arrays for the value/descriptor and corresponding bit
63 mapped value/descriptor.
64  
65 $self->{REUSE_BITMAP}
66  
67 Gets defined when 237000 is met, undefined if 237255 or 235000 is met.
68 Originally for each subset (but defined for subset 0 only if
69 compression) set to reference an array of the indexes of data values
70 to which the last used bitmap relates (fetched from $self->{BITMAPS}),
71 then shifted as the new element in $self->{BITMAPS} is built up.
72  
73 For operator 222000 ('Quality information follows') the bit mapped
74 descriptor should be a 033-descriptor. For 22[3-5]/232 the bit mapped
75 value should be the data value of the 22[3-5]255/232255 descriptors
76 following the operator in BUFR section 3, with bit mapped descriptor
77 $desc[bm_idesc] equal to $desc[$idesc] (with data width and reference
78 value changed for 225255)
79  
80 =end General_remarks
81  
82 =cut
83  
84 79 require 5.006;
85 79 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 79 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
87 79 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
88 79 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
89 79 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
90 79 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
91 79 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
92 79 ▶use Time::Local qw(timegm);
Subroutine BEGIN: called CC=1 SCAR=0.0
93 # Also requires Storable if sub copy_from() is called
94  
95 79 require DynaLoader;
96 79 our @ISA = qw(DynaLoader);
97 79 our $VERSION = '1.41';
98  
99 # This loads BUFR.so, the compiled version of BUFR.xs, which
100 # contains bitstream2dec, bitstream2ascii, dec2bitstream,
101 # ascii2bitstream and null2bitstream
102 79 bootstrap Geo::BUFR $VERSION;
103  
104  
105 # Some package globals
106 79 our $Verbose = 0;
107  
108 # $Verbose or $self->{VERBOSE} > 0 leads to the following output, all
109 # except for level 6 on lines starting with 'BUFR.pm: ':
110 # 1 -> B,C,D tables used (full path)
111 # 2 -> Identifying stages of processing, displaying length of sections
112 # and some additional data from section 1 and 3
113 # 3 -> All descriptors and values extracted
114 # 4 -> Operator specific information, including delayed replication
115 # and repetition
116 # 5 -> BUFR compression specific information
117 # 6 -> Calling dumpsection0,1,3
118  
119 79 our $Spew = 0; # To avoid the overhead of subroutine calls to _spew
120 # (which is called a lot), $Spew is set to 1 if global
121 # $Verbose or at least one object VERBOSE is set > 1.
122 # This should speed up execution a bit in the common
123 # situation when no verbose output (except possibly
124 # the BUFR tables used) is requested
125 79 our $Nodata = 0; # If set to true will prevent decoding of section 4
126 79 our $Noqc = 0; # If set to true will prevent decoding (or encoding) of
127 # any descriptors after 222000 is met
128 79 our $Reuse_current_ahl = 0;
129 # If set to true will cause cet_current_ahl() to return
130 # last AHL extracted and not undef if currently
131 # processed BUFR message has no (immediately preceding)
132 # AHL
133 79 our $Strict_checking = 0; # Ignore recoverable errors in BUFR format
134 # met during decoding. User might set
135 # $Strict_checking to 1: Issue warning
136 # (carp) but continue decoding, or to 2:
137 # Croak instead of carp
138  
139 # The next 2 operators are separated for readability. Public interface should
140 # provide only set_show_all_operators() to set both of these (to the same value)
141 79 our $Show_all_operators = 0; # = 0: show just the most informative C operators in dumpsection4
142 # = 1: show all operators (as far as possible)
143 79 our $Show_replication = 0; # = 0: don't include replication descriptors (F=1) in dumpsection4
144 # = 1: include replication descriptors(F=1) in dumpsection4,
145 # with X in FXY replaced with actual number X' of replicated descriptors.
146 # X' is replaced by 0 if X' > 99
147  
148 79 our %BUFR_table;
149 # Keys: PATH -> full path to the chosen directory of BUFR tables
150 # FORMAT -> supported formats are BUFRDC and ECCODES
151 # B$version -> hash containing the B table $BUFR_table/B$version
152 # key: element descriptor (6 digits)
153 # value: a \0 separated string containing the B table fields
154 # $name, $unit, $scale, $refval, $bits
155 # C$version -> hash containing the C table $BUFR_table/C$version
156 # key: table B descriptor (6 digits) of the code/flag table
157 # value: a new hash, with keys the possible values listed in
158 # the code table, the value the corresponding text
159 # D$version -> hash containing the D table $BUFR_table/D$version
160 # key: sequence descriptor
161 # value: a space separated string containing the element
162 # descriptors (6 digits) the sequence descriptor expands to
163 79 $BUFR_table{FORMAT} = 'BUFRDC'; # Default. Might in the future be changed to ECCODES
164  
165 79 our %Descriptors_already_expanded;
166 # Keys: Text string "$table_version $unexpanded_descriptors"
167 # Values: Space separated string of expanded descriptors
168  
169 sub _croak {
170 7 ▶ my $msg = shift;
Subroutine _croak: called CC=1 SCAR=0.0
171 7 croak "BUFR.pm ERROR: $msg";
172 }
173  
174 ## Carp or croak (or ignore) according to value of $Strict_checking
175 sub _complain {
176 55 ▶ my $msg = shift;
Subroutine _complain: called CC=3 SCAR=11.0
177 55 ▶ if ($Strict_checking == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking == 1) { } 8 47 55
elsif ($Geo::BUFR::Strict_checking > 1) { } 7 40 47
178 8 carp "BUFR.pm WARNING: $msg";
179 } elsif ($Strict_checking > 1) {
180 7 croak "BUFR.pm ERROR: $msg";
181 }
182 48 return;
183 }
184  
185 sub _spew {
186 2222 ▶ my $self = shift;
Subroutine _spew: called CC=6 SCAR=17.9
187 2222 my $level = shift;
188 2222 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 2015 207 2222
189 # Global $Verbose overrides object VERBOSE
190 2015 ▶ return if $level > $self->{VERBOSE} && $level > $Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $level > $self->{"VERBOSE"} and $level > $Geo::BUFR::Verbose 1961 54 2015
Condition66%2/3
$level > $self->{"VERBOSE"} and $level > $Geo::BUFR::Verbose
!ll&&!rl&&r
0541961
MC/DC50%1/2
$level > $self->{"VERBOSE"} and $level > $Geo::BUFR::Verbose
$level > $self->{"VERBOSE"} $level > $Geo::BUFR::Verbose
Truth table66%2/3
A and B
A= $level > $self->{"VERBOSE"}B= $level > $Geo::BUFR::Verbose
ABresult
0X0
100
111
191 } else {
192 207 ▶ return if $level > $Verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $level > $Geo::BUFR::Verbose 203 4 207
193 }
194 58 my $format = shift;
195 58 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 30 28 58
196 30 printf "BUFR.pm: $format\n", @_;
197 } else {
198 28 print "BUFR.pm: $format\n";
199 }
200 58 return;
201 }
202  
203 ## Object constructor
204 sub new {
205 84 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.4
Pod undocumented
206 84 my $self = {};
207 84 $self->{VERBOSE} = 0;
208 84 $self->{CURRENT_MESSAGE} = 0;
209 84 $self->{CURRENT_SUBSET} = 0;
210 84 $self->{BUILD_BITMAP} = 0; # Will be set to 1 if a bit map needs to
211 # be built
212 84 $self->{BITMAP_INDEX} = 0; # Used for building up bit maps; will
213 # be incremented for each 031031
214 # encountered, then reset to 0 when bit
215 # map is finished built
216 84 $self->{NUM_BITMAPS} = 0; # Will be incremented each time an
217 # operator descriptor which uses a bit
218 # map is encountered in section 3
219 84 $self->{BACKWARD_DATA_REFERENCE} = 1; # Number the first bitmap in
220 # a possible sequence of bitmaps which
221 # relate to the same scope of data
222 # descriptors. Starts as 1 when (or
223 # rather before) the first bitmap is
224 # constructed, will then be reset to
225 # the number of the next bitmap to be
226 # constructed each time 235000 is met
227 84 $self->{NUM_CHANGE_OPERATORS} = 0; # Will be incremented for
228 # each of the operators CHANGE_WIDTH,
229 # CHANGE_CCITTIA5_WIDTH, CHANGE_SCALE,
230 # CHANGE_REFERENCE_VALUE (actually
231 # NEW_REFVAL_OF), CHANGE_SRW and
232 # DIFFERENCE_STATISTICAL_VALUE in effect
233  
234 # If number of arguments is odd, first argument is expected to be
235 # a string containing the BUFR message(s)
236 84 ▶ if (@_ % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 5 79 84
237 5 $self->{IN_BUFFER} = shift;
238 }
239  
240 # This part is not documented in the POD. Better to remove it?
241 84 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 84 84
242 0 my $parameter = shift;
243 0 my $value = shift;
244 0 $self->{$parameter} = $value;
245 }
246 84 ▶ bless $self, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0840
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
247 84 return $self;
248 }
249  
250 ## Copy contents of the bufr object in first argument. With no extra
251 ## arguments, will copy (clone) everything. With 'metadata' as second
252 ## argument, will copy just the metadata in section 0, 1 and 3 (and
253 ## all of section 2 if present)
254 sub copy_from {
255 5 ▶ my $self = shift;
Subroutine copy_from: called CC=12 SCAR=40.6
Pod undocumented
256 5 my $bufr = shift;
257 5 ▶ _croak("First argument to copy_from must be a Geo::BUFR object")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bufr eq "Geo::BUFR" 0 5 5
258 unless ref($bufr) eq 'Geo::BUFR';
259 5 ▶ my $what = shift || 'all';
Condition50%1/2
shift() || 'all'
l!l
50
MC/DC0%0/1
shift() || 'all'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
260 5 ▶ if ($what eq 'metadata') {
Branch: 2 branches
BranchTrueFalseTotal
if ($what eq 'metadata') { } 5 0 5
elsif ($what eq 'all') { } 0 0 0
261 5 for (qw(
262 BUFR_EDITION
263 MASTER_TABLE CENTRE SUBCENTRE UPDATE_NUMBER OPTIONAL_SECTION
264 DATA_CATEGORY INT_DATA_SUBCATEGORY LOC_DATA_SUBCATEGORY
265 MASTER_TABLE_VERSION LOCAL_TABLE_VERSION YEAR MONTH DAY
266 HOUR MINUTE SECOND LOCAL_USE DATA_SUBCATEGORY YEAR_OF_CENTURY
267 NUM_SUBSETS OBSERVED_DATA COMPRESSED_DATA DESCRIPTORS_UNEXPANDED
268 SEC2_STREAM
269 )) {
270 125 ▶ if (exists $bufr->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $bufr->{$_}) { } 125 0 125
271 125 $self->{$_} = $bufr->{$_};
272 } else {
273 # This cleanup might be necessary if BUFR edition changes
274 0 ▶ delete $self->{$_} if exists $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$_} 0 0 0
275 }
276 }
277 } elsif ($what eq 'all') {
278 0 %$self = ();
279 0 ▶ while (my ($key, $value) = each %{$bufr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$bufr;}) 0 0 0
280 0 ▶ if ($key eq 'FILEHANDLE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($key eq 'FILEHANDLE') { } 0 0 0
elsif (ref $value and not $key =~ /[BCD]_TABLE/) { } 0 0 0
281 # If a file has been associated with the copied
282 # object, make a new filehandle rather than just
283 # copying the reference
284 0 $self->fopen($bufr->{FILENAME});
285 ▶ } elsif (ref($value) and $key !~ /[BCD]_TABLE/) {
Condition0%0/3
ref $value and not $key =~ /[BCD]_TABLE/
!ll&&!rl&&r
000
MC/DC0%0/2
ref $value and not $key =~ /[BCD]_TABLE/
ref $value not $key =~ /[BCD]_TABLE/
Truth table0%0/3
A and not(B)
A= ref $valueB= not $key =~ /[BCD]_TABLE/
ABresult
0X0
100
111
286 # Copy the whole structure, not merely the reference.
287 # Using Clone would be cheaper, but unfortunately
288 # Clone is not a core module, while Storable is
289 0 require Storable;
290 0 import Storable qw(dclone);
291 0 $self->{$key} = dclone($value);
292 } else {
293 0 $self->{$key} = $value;
294 }
295 }
296 } else {
297 0 _croak("Don't recognize second argument '$what' to copy_from()");
298 }
299 5 return 1;
300 }
301  
302  
303 ## Set debug level. Also set $Spew to true if debug level > 1 is set
304 ## (we don't bother to reset $Spew to 0 if all debug levels later are
305 ## reset to 0 or 1)
306 sub set_verbose {
307 14 ▶ my $self = shift;
Subroutine set_verbose: called CC=3 SCAR=11.3
Pod undocumented
308 14 my $verbose = shift;
309 14 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 14 14
310 # Just myself
311 0 $self->{VERBOSE} = $verbose;
312 0 $self->_spew(2, "Verbosity level for object set to %d", $verbose);
313 } else {
314 # Whole class
315 14 $Verbose = $verbose;
316 14 Geo::BUFR->_spew(2, "Verbosity level for class set to %d", $verbose);
317 }
318 14 ▶ $Spew = $verbose if $verbose > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 1 1 13 14
319 14 return 1;
320 }
321  
322 ## Turn off (or on) decoding of section 4
323 sub set_nodata {
324 9 ▶ my $self = shift;
Subroutine set_nodata: called CC=2 SCAR=6.9
Pod undocumented
325 9 my $n = shift;
326 9 ▶ $Nodata = defined $n ? $n : 1; # Default is 1
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 8 1 9
327 9 Geo::BUFR->_spew(2, "Nodata set to %d", $Nodata);
328 9 return 1;
329 }
330  
331 ## Turn off (or on) decoding of quality information
332 sub set_noqc {
333 1 ▶ my $self = shift;
Subroutine set_noqc: called CC=2 SCAR=7.0
Pod undocumented
334 1 my $n = shift;
335 1 ▶ $Noqc = defined $n ? $n : 1; # Default is 1
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 1 1
336 1 Geo::BUFR->_spew(2, "Noqc set to %d", $Noqc);
337 1 return 1;
338 }
339  
340 ## Require strict checking of BUFR format
341 sub set_strict_checking {
342 40 ▶ my $self = shift;
Subroutine set_strict_checking: called CC=2 SCAR=7.0
Pod undocumented
343 40 my $n = shift;
344 40 ▶ _croak "Value for strict checking not provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 40 40
345 unless defined $n;
346 40 $Strict_checking = $n;
347 40 Geo::BUFR->_spew(2, "Strict_checking set to %d", $Strict_checking);
348 40 return 1;
349 }
350  
351 ## Show replication descriptors (with X in FXY replaced by actual
352 ## number of descriptors replicated, adjusted to 0 if > 99) and all
353 ## data description operators when calling dumpsection4
354 sub set_show_all_operators {
355 3 ▶ my $self = shift;
Subroutine set_show_all_operators: called CC=2 SCAR=7.0
Pod undocumented
356 3 my $n = shift;
357 3 ▶ $Show_all_operators = defined $n ? $n : 1; # Default is 1
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 3 0 3
358 3 $Show_replication = $Show_all_operators;
359 3 Geo::BUFR->_spew(2, "Show_all_operators set to %d", $Show_all_operators);
360 3 return 1;
361 }
362  
363 ## Accessor methods for BUFR sec0-3 ##
364 sub get_bufr_length {
365 0 ▶ my $self = shift;
Subroutine get_bufr_length: not called CC=2 SCAR=17.9
Pod undocumented
366 0 ▶ return defined $self->{BUFR_LENGTH} ? $self->{BUFR_LENGTH} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'BUFR_LENGTH'} ? : 0 0 0
367 }
368 sub set_bufr_edition {
369 7 ▶ my ($self, $bufr_edition) = @_;
Subroutine set_bufr_edition: called CC=5 SCAR=17.8
Pod undocumented
370 7 ▶ _croak "BUFR edition number not provided in set_bufr_edition"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bufr_edition 0 7 7
371 unless defined $bufr_edition;
372 7 ▶ _croak "BUFR edition number must be an integer, is '$bufr_edition'"
Branch: 1 branch
BranchTrueFalseTotal
unless $bufr_edition =~ /^\d+$/ 0 7 7
373 unless $bufr_edition =~ /^\d+$/;
374 7 ▶ _croak "Not an allowed value for BUFR edition number: $bufr_edition"
Branch: 1 branch
BranchTrueFalseTotal
unless $bufr_edition >= 0 and $bufr_edition < 5 0 7 7
Condition33%1/3
$bufr_edition >= 0 and $bufr_edition < 5
!ll&&!rl&&r
007
MC/DC0%0/2
$bufr_edition >= 0 and $bufr_edition < 5
$bufr_edition >= 0 $bufr_edition < 5
Truth table33%1/3
A and B
A= $bufr_edition >= 0B= $bufr_edition < 5
ABresult
0X0
100
111
375 unless $bufr_edition >= 0 and $bufr_edition < 5;
376 # BUFR edition 0 is in fact in use in ECMWF MARS archive
377 7 $self->{BUFR_EDITION} = $bufr_edition;
378 7 return 1;
379 }
380 sub get_bufr_edition {
381 3 ▶ my $self = shift;
Subroutine get_bufr_edition: called CC=2 SCAR=7.2
Pod undocumented
382 3 ▶ return defined $self->{BUFR_EDITION} ? $self->{BUFR_EDITION} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'BUFR_EDITION'} ? : 3 0 3
383 }
384 sub set_master_table {
385 4 ▶ my ($self, $master_table) = @_;
Subroutine set_master_table: called CC=4 SCAR=14.5
Pod undocumented
386 4 ▶ _croak "BUFR master table not provided in set_master_table"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $master_table 0 4 4
387 unless defined $master_table;
388 4 ▶ _croak "BUFR master table must be an integer, is '$master_table'"
Branch: 1 branch
BranchTrueFalseTotal
unless $master_table =~ /^\d+$/ 0 4 4
389 unless $master_table =~ /^\d+$/;
390 # Max value that can be stored in 1 byte is 255
391 4 ▶ _croak "BUFR master table exceeds limit 255, is '$master_table'"
Branch: 1 branch
BranchTrueFalseTotal
if $master_table > 255 0 4 4
392 if $master_table > 255;
393 4 $self->{MASTER_TABLE} = $master_table;
394 4 return 1;
395 }
396 sub get_master_table {
397 0 ▶ my $self = shift;
Subroutine get_master_table: not called CC=2 SCAR=17.9
Pod undocumented
398 0 ▶ return defined $self->{MASTER_TABLE} ? $self->{MASTER_TABLE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MASTER_TABLE'} ? : 0 0 0
399 }
400 sub set_centre {
401 7 ▶ my ($self, $centre) = @_;
Subroutine set_centre: called CC=4 SCAR=14.5
Pod undocumented
402 7 ▶ _croak "Originating/generating centre not provided in set_centre"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $centre 0 7 7
403 unless defined $centre;
404 7 ▶ _croak "Originating/generating centre must be an integer, is '$centre'"
Branch: 1 branch
BranchTrueFalseTotal
unless $centre =~ /^\d+$/ 0 7 7
405 unless $centre =~ /^\d+$/;
406 # Max value that can be stored in 2 bytes is 65535
407 7 ▶ _croak "Originating/generating centre exceeds limit 65535, is '$centre'"
Branch: 1 branch
BranchTrueFalseTotal
if $centre > 65535 0 7 7
408 if $centre > 65535;
409 7 $self->{CENTRE} = $centre;
410 7 return 1;
411 }
412 sub get_centre {
413 0 ▶ my $self = shift;
Subroutine get_centre: not called CC=2 SCAR=17.9
Pod undocumented
414 0 ▶ return defined $self->{CENTRE} ? $self->{CENTRE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CENTRE'} ? : 0 0 0
415 }
416 sub set_subcentre {
417 7 ▶ my ($self, $subcentre) = @_;
Subroutine set_subcentre: called CC=4 SCAR=14.5
Pod undocumented
418 7 ▶ _croak "Originating/generating subcentre not provided in set_subcentre"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subcentre 0 7 7
419 unless defined $subcentre;
420 7 ▶ _croak "Originating/generating subcentre must be an integer, is '$subcentre'"
Branch: 1 branch
BranchTrueFalseTotal
unless $subcentre =~ /^\d+$/ 0 7 7
421 unless $subcentre =~ /^\d+$/;
422 7 ▶ _croak "Originating/generating subcentre exceeds limit 65535, is '$subcentre'"
Branch: 1 branch
BranchTrueFalseTotal
if $subcentre > 65535 0 7 7
423 if $subcentre > 65535;
424 7 $self->{SUBCENTRE} = $subcentre;
425 7 return 1;
426 }
427 sub get_subcentre {
428 0 ▶ my $self = shift;
Subroutine get_subcentre: not called CC=2 SCAR=17.9
Pod undocumented
429 0 ▶ return defined $self->{SUBCENTRE} ? $self->{SUBCENTRE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'SUBCENTRE'} ? : 0 0 0
430 }
431 sub set_update_sequence_number {
432 7 ▶ my ($self, $update_number) = @_;
Subroutine set_update_sequence_number: called CC=4 SCAR=14.5
Pod undocumented
433 7 ▶ _croak "Update sequence number not provided in set_update_sequence_number"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $update_number 0 7 7
434 unless defined $update_number;
435 7 ▶ _croak "Update sequence number must be a nonnegative integer, is '$update_number'"
Branch: 1 branch
BranchTrueFalseTotal
unless $update_number =~ /^\d+$/ 0 7 7
436 unless $update_number =~ /^\d+$/;
437 7 ▶ _croak "Update sequence number exceeds limit 255, is '$update_number'"
Branch: 1 branch
BranchTrueFalseTotal
if $update_number > 255 0 7 7
438 if $update_number > 255;
439 7 $self->{UPDATE_NUMBER} = $update_number;
440 7 return 1;
441 }
442 sub get_update_sequence_number {
443 2 ▶ my $self = shift;
Subroutine get_update_sequence_number: called CC=2 SCAR=7.2
Pod undocumented
444 2 ▶ return defined $self->{UPDATE_NUMBER} ? $self->{UPDATE_NUMBER} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'UPDATE_NUMBER'} ? : 2 0 2
445 }
446 sub set_optional_section {
447 4 ▶ my ($self, $optional_section) = @_;
Subroutine set_optional_section: called CC=4 SCAR=15.2
Pod undocumented
448 4 ▶ _croak "Optional section (0 or 1) not provided in set_optional_section"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $optional_section 0 4 4
449 unless defined $optional_section;
450 4 ▶ _croak "Optional section must be 0 or 1, is '$optional_section'"
Branch: 1 branch
BranchTrueFalseTotal
unless $optional_section eq 0 or $optional_section eq 1 0 4 4
Condition33%1/3
$optional_section eq 0 or $optional_section eq 1
l!l&&r!l&&!r
400
MC/DC0%0/2
$optional_section eq 0 or $optional_section eq 1
$optional_section eq 0 $optional_section eq 1
Truth table33%1/3
A or B
A= $optional_section eq 0B= $optional_section eq 1
ABresult
1X1
011
000
451 unless $optional_section eq '0' or $optional_section eq '1';
452 4 $self->{OPTIONAL_SECTION} = $optional_section;
453 4 return 1;
454 }
455 sub get_optional_section {
456 0 ▶ my $self = shift;
Subroutine get_optional_section: not called CC=2 SCAR=17.9
Pod undocumented
457 0 ▶ return defined $self->{OPTIONAL_SECTION} ? $self->{OPTIONAL_SECTION} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'OPTIONAL_SECTION'} ? : 0 0 0
458 }
459 sub set_data_category {
460 7 ▶ my ($self, $data_category) = @_;
Subroutine set_data_category: called CC=4 SCAR=14.5
Pod undocumented
461 7 ▶ _croak "Data category not provided in set_data_category"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_category 0 7 7
462 unless defined $data_category;
463 7 ▶ _croak "Data category must be an integer, is '$data_category'"
Branch: 1 branch
BranchTrueFalseTotal
unless $data_category =~ /^\d+$/ 0 7 7
464 unless $data_category =~ /^\d+$/;
465 7 ▶ _croak "Data category exceeds limit 255, is '$data_category'"
Branch: 1 branch
BranchTrueFalseTotal
if $data_category > 255 0 7 7
466 if $data_category > 255;
467 7 $self->{DATA_CATEGORY} = $data_category;
468 7 return 1;
469 }
470 sub get_data_category {
471 24 ▶ my $self = shift;
Subroutine get_data_category: called CC=2 SCAR=7.2
Pod undocumented
472 24 ▶ return defined $self->{DATA_CATEGORY} ? $self->{DATA_CATEGORY} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'DATA_CATEGORY'} ? : 24 0 24
473 }
474 sub set_int_data_subcategory {
475 3 ▶ my ($self, $int_data_subcategory) = @_;
Subroutine set_int_data_subcategory: called CC=4 SCAR=14.5
Pod undocumented
476 3 ▶ _croak "International data subcategory not provided in set_int_data_subcategory"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $int_data_subcategory 0 3 3
477 unless defined $int_data_subcategory;
478 3 ▶ _croak "International data subcategory must be an integer, is '$int_data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
unless $int_data_subcategory =~ /^\d+$/ 0 3 3
479 unless $int_data_subcategory =~ /^\d+$/;
480 3 ▶ _croak "International data subcategory exceeds limit 255, is '$int_data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
if $int_data_subcategory > 255 0 3 3
481 if $int_data_subcategory > 255;
482 3 $self->{INT_DATA_SUBCATEGORY} = $int_data_subcategory;
483 3 return 1;
484 }
485 sub get_int_data_subcategory {
486 1 ▶ my $self = shift;
Subroutine get_int_data_subcategory: called CC=2 SCAR=7.2
Pod undocumented
487 1 ▶ return defined $self->{INT_DATA_SUBCATEGORY} ? $self->{INT_DATA_SUBCATEGORY} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'INT_DATA_SUBCATEGORY'} ? : 0 1 1
488 }
489 sub set_loc_data_subcategory {
490 3 ▶ my ($self, $loc_data_subcategory) = @_;
Subroutine set_loc_data_subcategory: called CC=4 SCAR=14.5
Pod undocumented
491 3 ▶ _croak "Local subcategory not provided in set_loc_data_subcategory"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $loc_data_subcategory 0 3 3
492 unless defined $loc_data_subcategory;
493 3 ▶ _croak "Local data subcategory must be an integer, is '$loc_data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
unless $loc_data_subcategory =~ /^\d+$/ 0 3 3
494 unless $loc_data_subcategory =~ /^\d+$/;
495 3 ▶ _croak "Local data subcategory exceeds limit 255, is '$loc_data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
if $loc_data_subcategory > 255 0 3 3
496 if $loc_data_subcategory > 255;
497 3 $self->{LOC_DATA_SUBCATEGORY} = $loc_data_subcategory;
498 3 return 1;
499 }
500 sub get_loc_data_subcategory {
501 1 ▶ my $self = shift;
Subroutine get_loc_data_subcategory: called CC=2 SCAR=7.2
Pod undocumented
502 1 ▶ return defined $self->{LOC_DATA_SUBCATEGORY} ? $self->{LOC_DATA_SUBCATEGORY} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'LOC_DATA_SUBCATEGORY'} ? : 0 1 1
503 }
504 sub set_data_subcategory {
505 5 ▶ my ($self, $data_subcategory) = @_;
Subroutine set_data_subcategory: called CC=4 SCAR=14.5
Pod undocumented
506 5 ▶ _croak "Data subcategory not provided in set_data_subcategory"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_subcategory 0 5 5
507 unless defined $data_subcategory;
508 5 ▶ _croak "Data subcategory must be an integer, is '$data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
unless $data_subcategory =~ /^\d+$/ 0 5 5
509 unless $data_subcategory =~ /^\d+$/;
510 5 ▶ _croak "Data subcategory exceeds limit 255, is '$data_subcategory'"
Branch: 1 branch
BranchTrueFalseTotal
if $data_subcategory > 255 0 5 5
511 if $data_subcategory > 255;
512 5 $self->{DATA_SUBCATEGORY} = $data_subcategory;
513 5 return 1;
514 }
515 sub get_data_subcategory {
516 3 ▶ my $self = shift;
Subroutine get_data_subcategory: called CC=2 SCAR=7.2
Pod undocumented
517 3 ▶ return defined $self->{DATA_SUBCATEGORY} ? $self->{DATA_SUBCATEGORY} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'DATA_SUBCATEGORY'} ? : 3 0 3
518 }
519 sub set_master_table_version {
520 6 ▶ my ($self, $master_table_version) = @_;
Subroutine set_master_table_version: called CC=4 SCAR=14.5
Pod undocumented
521 6 ▶ _croak "Master table version not provided in set_master_table_version"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $master_table_version 0 6 6
522 unless defined $master_table_version;
523 6 ▶ _croak "BUFR master table version must be an integer, is '$master_table_version'"
Branch: 1 branch
BranchTrueFalseTotal
unless $master_table_version =~ /^\d+$/ 0 6 6
524 unless $master_table_version =~ /^\d+$/;
525 6 ▶ _croak "BUFR master table version exceeds limit 255, is '$master_table_version'"
Branch: 1 branch
BranchTrueFalseTotal
if $master_table_version > 255 0 6 6
526 if $master_table_version > 255;
527 6 $self->{MASTER_TABLE_VERSION} = $master_table_version;
528 6 return 1;
529 }
530 sub get_master_table_version {
531 0 ▶ my $self = shift;
Subroutine get_master_table_version: not called CC=2 SCAR=17.9
Pod undocumented
532 return defined $self->{MASTER_TABLE_VERSION}
533 0 ▶ ? $self->{MASTER_TABLE_VERSION} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MASTER_TABLE_VERSION'} ? : 0 0 0
534 }
535 sub set_local_table_version {
536 6 ▶ my ($self, $local_table_version) = @_;
Subroutine set_local_table_version: called CC=4 SCAR=14.5
Pod undocumented
537 6 ▶ _croak "Local table version not provided in set_local_table_version"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_table_version 0 6 6
538 unless defined $local_table_version;
539 6 ▶ _croak "Local table version must be an integer, is '$local_table_version'"
Branch: 1 branch
BranchTrueFalseTotal
unless $local_table_version =~ /^\d+$/ 0 6 6
540 unless $local_table_version =~ /^\d+$/;
541 6 ▶ _croak "Local table version exceeds limit 255, is '$local_table_version'"
Branch: 1 branch
BranchTrueFalseTotal
if $local_table_version > 255 0 6 6
542 if $local_table_version > 255;
543 6 $self->{LOCAL_TABLE_VERSION} = $local_table_version;
544 6 return 1;
545 }
546 sub get_local_table_version {
547 0 ▶ my $self = shift;
Subroutine get_local_table_version: not called CC=2 SCAR=17.9
Pod undocumented
548 return defined $self->{LOCAL_TABLE_VERSION}
549 0 ▶ ? $self->{LOCAL_TABLE_VERSION} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'LOCAL_TABLE_VERSION'} ? : 0 0 0
550 }
551 sub set_year_of_century {
552 4 ▶ my ($self, $year_of_century) = @_;
Subroutine set_year_of_century: called CC=5 SCAR=17.2
Pod undocumented
553 4 ▶ _croak "Year of century not provided in set_year_of_century"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year_of_century 0 4 4
554 unless defined $year_of_century;
555 4 ▶ _croak "Year of century must be an integer, is '$year_of_century'"
Branch: 1 branch
BranchTrueFalseTotal
unless $year_of_century =~ /^\d+$/ 0 4 4
556 unless $year_of_century =~ /^\d+$/;
557 4 ▶ _complain "year_of_century > 100 in set_year_of_century: $year_of_century"
Branch: 1 branch
BranchTrueFalseTotal
if $year_of_century > 100 0 4 4
558 if $year_of_century > 100;
559 # A common mistake is to set year_of_century for year 2000 to 0, should be 100
560 4 ▶ $self->{YEAR_OF_CENTURY} = $year_of_century == 0 ? 100 : $year_of_century;
Branch: 1 branch
BranchTrueFalseTotal
$year_of_century == 0 ? : 0 4 4
561 4 return 1;
562 }
563 sub get_year_of_century {
564 2 ▶ my $self = shift;
Subroutine get_year_of_century: called CC=4 SCAR=16.4
Pod undocumented
565 2 ▶ if (defined $self->{YEAR_OF_CENTURY}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'YEAR_OF_CENTURY'}) { } 0 2 2
elsif (defined $self->{'YEAR'}) { } 2 0 2
566 0 return $self->{YEAR_OF_CENTURY};
567 } elsif (defined $self->{YEAR}) {
568 2 my $yy = $self->{YEAR} % 100;
569 2 ▶ return $yy == 0 ? 100 : $yy;
Branch: 1 branch
BranchTrueFalseTotal
$yy == 0 ? : 0 2 2
570 } else {
571 0 return undef;
572 }
573 }
574 sub set_year {
575 4 ▶ my ($self, $year) = @_;
Subroutine set_year: called CC=4 SCAR=14.5
Pod undocumented
576 4 ▶ _croak "Year not provided in set_year"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year 0 4 4
577 unless defined $year;
578 4 ▶ _croak "Year must be an integer, is '$year'"
Branch: 1 branch
BranchTrueFalseTotal
unless $year =~ /^\d+$/ 0 4 4
579 unless $year =~ /^\d+$/;
580 4 ▶ _croak "Year exceeds limit 65535, is '$year'"
Branch: 1 branch
BranchTrueFalseTotal
if $year > 65535 0 4 4
581 if $year > 65535;
582 4 $self->{YEAR} = $year;
583 4 return 1;
584 }
585 sub get_year {
586 1 ▶ my $self = shift;
Subroutine get_year: called CC=2 SCAR=7.2
Pod undocumented
587 1 ▶ return defined $self->{YEAR} ? $self->{YEAR} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'YEAR'} ? : 1 0 1
588 }
589 sub set_month {
590 7 ▶ my ($self, $month) = @_;
Subroutine set_month: called CC=5 SCAR=17.8
Pod undocumented
591 7 ▶ _croak "Month not provided in set_month"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $month 0 7 7
592 unless defined $month;
593 7 ▶ _croak "Month must be an integer, is '$month'"
Branch: 1 branch
BranchTrueFalseTotal
unless $month =~ /^\d+$/ 0 7 7
594 unless $month =~ /^\d+$/;
595 7 ▶ _complain "Month must be 1-12 in set_month, is '$month'"
Branch: 1 branch
BranchTrueFalseTotal
if $month == 0 or $month > 12 0 7 7
Condition33%1/3
$month == 0 or $month > 12
l!l&&r!l&&!r
007
MC/DC0%0/2
$month == 0 or $month > 12
$month == 0 $month > 12
Truth table33%1/3
A or B
A= $month == 0B= $month > 12
ABresult
1X1
011
000
596 if $month == 0 || $month > 12;
597 7 $self->{MONTH} = $month;
598 7 return 1;
599 }
600 sub get_month {
601 0 ▶ my $self = shift;
Subroutine get_month: not called CC=2 SCAR=17.9
Pod undocumented
602 0 ▶ return defined $self->{MONTH} ? $self->{MONTH} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MONTH'} ? : 0 0 0
603 }
604 sub set_day {
605 7 ▶ my ($self, $day) = @_;
Subroutine set_day: called CC=5 SCAR=17.8
Pod undocumented
606 7 ▶ _croak "Day not provided in set_day"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $day 0 7 7
607 unless defined $day;
608 7 ▶ _croak "Day must be an integer, is '$day'"
Branch: 1 branch
BranchTrueFalseTotal
unless $day =~ /^\d+$/ 0 7 7
609 unless $day =~ /^\d+$/;
610 7 ▶ _complain "Day must be 1-31 in set_day, is '$day'"
Branch: 1 branch
BranchTrueFalseTotal
if $day == 0 or $day > 31 0 7 7
Condition33%1/3
$day == 0 or $day > 31
l!l&&r!l&&!r
007
MC/DC0%0/2
$day == 0 or $day > 31
$day == 0 $day > 31
Truth table33%1/3
A or B
A= $day == 0B= $day > 31
ABresult
1X1
011
000
611 if $day == 0 || $day > 31;
612 7 $self->{DAY} = $day;
613 7 return 1;
614 }
615 sub get_day {
616 0 ▶ my $self = shift;
Subroutine get_day: not called CC=2 SCAR=17.9
Pod undocumented
617 0 ▶ return defined $self->{DAY} ? $self->{DAY} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'DAY'} ? : 0 0 0
618 }
619 sub set_hour {
620 7 ▶ my ($self, $hour) = @_;
Subroutine set_hour: called CC=4 SCAR=14.5
Pod undocumented
621 7 ▶ _croak "Hour not provided in set_hour"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hour 0 7 7
622 unless defined $hour;
623 7 ▶ _croak "Hour must be an integer, is '$hour'"
Branch: 1 branch
BranchTrueFalseTotal
unless $hour =~ /^\d+$/ 0 7 7
624 unless $hour =~ /^\d+$/;
625 7 ▶ _complain "Hour must be 0-23 in set_hour, is '$hour'"
Branch: 1 branch
BranchTrueFalseTotal
if $hour > 23 0 7 7
626 if $hour > 23;
627 7 $self->{HOUR} = $hour;
628 7 return 1;
629 }
630 sub get_hour {
631 0 ▶ my $self = shift;
Subroutine get_hour: not called CC=2 SCAR=17.9
Pod undocumented
632 0 ▶ return defined $self->{HOUR} ? $self->{HOUR} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'HOUR'} ? : 0 0 0
633 }
634 sub set_minute {
635 7 ▶ my ($self, $minute) = @_;
Subroutine set_minute: called CC=4 SCAR=14.5
Pod undocumented
636 7 ▶ _croak "Minute not provided in set_minute"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $minute 0 7 7
637 unless defined $minute;
638 7 ▶ _croak "Minute must be an integer, is '$minute'"
Branch: 1 branch
BranchTrueFalseTotal
unless $minute =~ /^\d+$/ 0 7 7
639 unless $minute =~ /^\d+$/;
640 7 ▶ _complain "Minute must be 0-59 in set_minute, is '$minute'"
Branch: 1 branch
BranchTrueFalseTotal
if $minute > 59 0 7 7
641 if $minute > 59;
642 7 $self->{MINUTE} = $minute;
643 7 return 1;
644 }
645 sub get_minute {
646 0 ▶ my $self = shift;
Subroutine get_minute: not called CC=2 SCAR=17.9
Pod undocumented
647 0 ▶ return defined $self->{MINUTE} ? $self->{MINUTE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MINUTE'} ? : 0 0 0
648 }
649 sub set_second {
650 3 ▶ my ($self, $second) = @_;
Subroutine set_second: called CC=4 SCAR=14.5
Pod undocumented
651 3 ▶ _croak "Second not provided in set_second"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $second 0 3 3
652 unless defined $second;
653 3 ▶ _croak "Second must be an integer, is '$second'"
Branch: 1 branch
BranchTrueFalseTotal
unless $second =~ /^\d+$/ 0 3 3
654 unless $second =~ /^\d+$/;
655 3 ▶ _complain "Second must be 0-59 in set_second, is '$second'"
Branch: 1 branch
BranchTrueFalseTotal
if $second > 59 0 3 3
656 if $second > 59;
657 3 $self->{SECOND} = $second;
658 3 return 1;
659 }
660 sub get_second {
661 1 ▶ my $self = shift;
Subroutine get_second: called CC=2 SCAR=7.2
Pod undocumented
662 1 ▶ return defined $self->{SECOND} ? $self->{SECOND} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'SECOND'} ? : 0 1 1
663 }
664 sub set_local_use {
665 0 ▶ my ($self, $local_use) = @_;
Subroutine set_local_use: not called CC=2 SCAR=17.9
Pod undocumented
666 0 ▶ _croak "Local use not provided in set_local use"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $local_use 0 0 0
667 unless defined $local_use;
668 0 $self->{LOCAL_USE} = $local_use;
669 0 return 1;
670 }
671 sub get_local_use {
672 0 ▶ my $self = shift;
Subroutine get_local_use: not called CC=2 SCAR=17.9
Pod undocumented
673 0 ▶ return defined $self->{LOCAL_USE} ? $self->{LOCAL_USE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'LOCAL_USE'} ? : 0 0 0
674 }
675 sub set_number_of_subsets {
676 6 ▶ my ($self, $number_of_subsets) = @_;
Subroutine set_number_of_subsets: called CC=4 SCAR=14.5
Pod undocumented
677 6 ▶ _croak "Number of subsets not provided in set_number_of_subsets"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number_of_subsets 0 6 6
678 unless defined $number_of_subsets;
679 6 ▶ _croak "Number of subsets must be an integer, is '$number_of_subsets'"
Branch: 1 branch
BranchTrueFalseTotal
unless $number_of_subsets =~ /^\d+$/ 0 6 6
680 unless $number_of_subsets =~ /^\d+$/;
681 6 ▶ _croak "Number of subsets exceeds limit 65535, is '$number_of_subsets'"
Branch: 1 branch
BranchTrueFalseTotal
if $number_of_subsets > 65535 0 6 6
682 if $number_of_subsets > 65535;
683 6 $self->{NUM_SUBSETS} = $number_of_subsets;
684 6 return 1;
685 }
686 sub get_number_of_subsets {
687 5 ▶ my $self = shift;
Subroutine get_number_of_subsets: called CC=2 SCAR=7.2
Pod undocumented
688 5 ▶ return defined $self->{NUM_SUBSETS} ? $self->{NUM_SUBSETS} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'NUM_SUBSETS'} ? : 5 0 5
689 }
690 sub set_observed_data {
691 5 ▶ my ($self, $observed_data) = @_;
Subroutine set_observed_data: called CC=4 SCAR=14.5
Pod undocumented
692 5 ▶ _croak "Observed data (0 or 1) not provided in set_observed_data"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $observed_data 0 5 5
693 unless defined $observed_data;
694 5 ▶ _croak "Observed data must be 0 or 1, is '$observed_data'"
Branch: 1 branch
BranchTrueFalseTotal
unless $observed_data eq 0 or $observed_data eq 1 0 5 5
Condition66%2/3
$observed_data eq 0 or $observed_data eq 1
l!l&&r!l&&!r
140
MC/DC0%0/2
$observed_data eq 0 or $observed_data eq 1
$observed_data eq 0 $observed_data eq 1
Truth table66%2/3
A or B
A= $observed_data eq 0B= $observed_data eq 1
ABresult
1X1
011
000
695 unless $observed_data eq '0' or $observed_data eq '1';
696 5 $self->{OBSERVED_DATA} = $observed_data;
697 5 return 1;
698 }
699 sub get_observed_data {
700 0 ▶ my $self = shift;
Subroutine get_observed_data: not called CC=2 SCAR=17.9
Pod undocumented
701 0 ▶ return defined $self->{OBSERVED_DATA} ? $self->{OBSERVED_DATA} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'OBSERVED_DATA'} ? : 0 0 0
702 }
703 sub set_compressed_data {
704 7 ▶ my ($self, $compressed_data) = @_;
Subroutine set_compressed_data: called CC=7 SCAR=23.8
Pod undocumented
705 7 ▶ _croak "Compressed data (0 or 1) not provided in set_compressed_data"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $compressed_data 0 7 7
706 unless defined $compressed_data;
707 7 ▶ _croak "Compressed data must be 0 or 1, is '$compressed_data'"
Branch: 1 branch
BranchTrueFalseTotal
unless $compressed_data eq 0 or $compressed_data eq 1 0 7 7
Condition33%1/3
$compressed_data eq 0 or $compressed_data eq 1
l!l&&r!l&&!r
700
MC/DC0%0/2
$compressed_data eq 0 or $compressed_data eq 1
$compressed_data eq 0 $compressed_data eq 1
Truth table33%1/3
A or B
A= $compressed_data eq 0B= $compressed_data eq 1
ABresult
1X1
011
000
708 unless $compressed_data eq '0' or $compressed_data eq '1';
709 _complain "Not allowed to use compression for one subset messages!"
710 if $compressed_data
711 7 ▶ and defined $self->{NUM_SUBSETS} and $self->{NUM_SUBSETS} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $compressed_data and defined $self->{"NUM_SUBSETS"} and $self->{"NUM_SUBSETS"} == 1 0 7 7
Condition33%2/6
$compressed_data and defined $self->{"NUM_SUBSETS"} and $self->{"NUM_SUBSETS"} == 1
!ll&&!rl&&r
700
$compressed_data and defined $self->{"NUM_SUBSETS"}
!ll&&!rl&&r
700
MC/DC0%0/3
$compressed_data and defined $self->{"NUM_SUBSETS"} and $self->{"NUM_SUBSETS"} == 1
$compressed_data defined $self->{"NUM_SUBSETS"} $self->{"NUM_SUBSETS"} == 1
Truth table25%1/4
A and B and C
A= $compressed_dataB= defined $self->{"NUM_SUBSETS"}C= $self->{"NUM_SUBSETS"} == 1
ABCresult
0XX0
10X0
1100
1111
712 7 $self->{COMPRESSED_DATA} = $compressed_data;
713 7 return 1;
714 }
715 sub get_compressed_data {
716 0 ▶ my $self = shift;
Subroutine get_compressed_data: not called CC=2 SCAR=17.9
Pod undocumented
717 0 ▶ return defined $self->{COMPRESSED_DATA} ? $self->{COMPRESSED_DATA} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'COMPRESSED_DATA'} ? : 0 0 0
718 }
719 sub set_descriptors_unexpanded {
720 4 ▶ my ($self, $descriptors_unexpanded) = @_;
Subroutine set_descriptors_unexpanded: called CC=2 SCAR=7.0
Pod undocumented
721 4 ▶ _croak "Unexpanded descriptors not provided in set_descriptors_unexpanded"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $descriptors_unexpanded 0 4 4
722 unless defined $descriptors_unexpanded;
723 4 $self->{DESCRIPTORS_UNEXPANDED} = $descriptors_unexpanded;
724 4 return 1;
725 }
726 sub get_descriptors_unexpanded {
727 0 ▶ my $self = shift;
Subroutine get_descriptors_unexpanded: not called CC=2 SCAR=17.9
Pod undocumented
728 return defined $self->{DESCRIPTORS_UNEXPANDED}
729 0 ▶ ? $self->{DESCRIPTORS_UNEXPANDED} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'DESCRIPTORS_UNEXPANDED'} ? : 0 0 0
730 }
731 #############################################
732 ## End of accessor methods for BUFR sec0-3 ##
733 #############################################
734  
735 sub get_current_subset_number {
736 182 ▶ my $self = shift;
Subroutine get_current_subset_number: called CC=2 SCAR=7.2
Pod undocumented
737 182 ▶ return defined $self->{CURRENT_SUBSET} ? $self->{CURRENT_SUBSET} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CURRENT_SUBSET'} ? : 182 0 182
738 }
739  
740 sub get_current_message_number {
741 117 ▶ my $self = shift;
Subroutine get_current_message_number: called CC=2 SCAR=7.2
Pod undocumented
742 117 ▶ return defined $self->{CURRENT_MESSAGE} ? $self->{CURRENT_MESSAGE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CURRENT_MESSAGE'} ? : 117 0 117
743 }
744  
745 sub get_current_ahl {
746 168 ▶ my $self = shift;
Subroutine get_current_ahl: called CC=2 SCAR=6.9
Pod undocumented
747 168 ▶ return defined $self->{CURRENT_AHL} ? $self->{CURRENT_AHL} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CURRENT_AHL'} ? : 117 51 168
748 }
749  
750 sub get_current_gts_starting_line {
751 7 ▶ my $self = shift;
Subroutine get_current_gts_starting_line: called CC=2 SCAR=7.2
Pod undocumented
752 7 ▶ return defined $self->{CURRENT_GTS_STARTING_LINE} ? $self->{CURRENT_GTS_STARTING_LINE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CURRENT_GTS_STARTING_LINE'} ? : 7 0 7
753 }
754  
755 sub get_current_gts_eom {
756 7 ▶ my $self = shift;
Subroutine get_current_gts_eom: called CC=2 SCAR=6.9
Pod undocumented
757 7 ▶ return defined $self->{CURRENT_GTS_EOM} ? $self->{CURRENT_GTS_EOM} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'CURRENT_GTS_EOM'} ? : 5 2 7
758 }
759  
760 sub set_filter_cb {
761 7 ▶ my $self = shift;
Subroutine set_filter_cb: called CC=2 SCAR=7.3
Pod undocumented
762 7 my $cb = shift;
763  
764 7 ▶ if (ref $cb eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cb eq 'CODE') { } 7 0 7
765 7 $self->{FILTER_CB} = $cb;
766 7 @{$self->{FILTER_ARGS}} = ($self, @_);
767 } else {
768 0 $self->{FILTER_CB} = undef;
769 0 delete $self->{FILTER_ARGS};
770 }
771 7 return 1;
772 }
773  
774 sub is_filtered {
775 57 ▶ my $self = shift;
Subroutine is_filtered: called CC=2 SCAR=6.9
Pod undocumented
776 57 ▶ return defined $self->{IS_FILTERED} ? $self->{IS_FILTERED} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'IS_FILTERED'} ? : 50 7 57
777 }
778  
779 sub bad_bufrlength {
780 46 ▶ my $self = shift;
Subroutine bad_bufrlength: called CC=2 SCAR=7.2
Pod undocumented
781 46 ▶ return defined $self->{BAD_LENGTH} ? $self->{BAD_LENGTH} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'BAD_LENGTH'} ? : 46 0 46
782 }
783  
784 sub set_tableformat {
785 67 ▶ my $self = shift;
Subroutine set_tableformat: called CC=4 SCAR=14.2
Pod undocumented
786  
787 67 my $format = shift;
788 67 ▶ _croak "Table format not provided. Possible values are BUFRDC and ECCODES"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format 0 67 67
789 unless defined $format;
790 67 ▶ _croak "Supported table formats are BUFRDC and ECCODES"
Branch: 1 branch
BranchTrueFalseTotal
unless uc $format eq "BUFRDC" or uc $format eq "ECCODES" 0 67 67
Condition66%2/3
uc $format eq "BUFRDC" or uc $format eq "ECCODES"
l!l&&r!l&&!r
5890
MC/DC0%0/2
uc $format eq "BUFRDC" or uc $format eq "ECCODES"
uc $format eq "BUFRDC" uc $format eq "ECCODES"
Truth table66%2/3
A or B
A= uc $format eq "BUFRDC"B= uc $format eq "ECCODES"
ABresult
1X1
011
000
791 unless uc($format) eq 'BUFRDC' || uc($format) eq 'ECCODES';
792 67 $BUFR_table{FORMAT} = uc($format);
793 67 Geo::BUFR->_spew(2, "BUFR table format set to %s", $BUFR_table{FORMAT});
794 67 return 1;
795 }
796  
797 sub get_tableformat {
798 8 ▶ my $self = shift;
Subroutine get_tableformat: called CC=2 SCAR=7.2
Pod undocumented
799 8 ▶ return exists $BUFR_table{FORMAT} ? $BUFR_table{FORMAT} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $Geo::BUFR::BUFR_table{'FORMAT'} ? : 8 0 8
800 }
801  
802 ## Set the path for BUFR table files
803 ## Usage: Geo::BUFR->set_tablepath(directory_list)
804 ## where directory_list is a list of colon-separated strings.
805 ## Example: Geo::BUFR->set_tablepath("/foo/bar:/foo/baz", "/some/where/else")
806 sub set_tablepath {
807 70 ▶ my $self = shift;
Subroutine set_tablepath: called CC=1 SCAR=0.0
Pod undocumented
808  
809 70 $BUFR_table{PATH} = join ":", map {split /:/} @_;
810 70 Geo::BUFR->_spew(2, "BUFR table path set to %s", $BUFR_table{PATH});
811 70 return 1;
812 }
813  
814 sub get_tablepath {
815 0 ▶ my $self = shift;
Subroutine get_tablepath: not called CC=3 SCAR=24.8
Pod undocumented
816  
817 0 ▶ if (exists $BUFR_table{PATH}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Geo::BUFR::BUFR_table{'PATH'}) { } 0 0 0
818 0 ▶ return wantarray ? split(/:/, $BUFR_table{PATH}) : $BUFR_table{PATH};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
819 } else {
820 0 return '';
821 }
822 }
823  
824 ## Return table version from table if provided, or else from section 1
825 ## information in BUFR message. For BUFRDC, this is a stripped down
826 ## version of table name. For ECCODES, this is last path of table
827 ## location (e.g. '0/wmo/29'), and a stringified list of two such
828 ## paths (master and local) if local tables are used
829 ## (e.g. '0/wmo/29,0/local/8/78/236'). Returns undef/empty list if
830 ## impossible to determine table version.
831 sub get_table_version {
832 127 ▶ my $self = shift;
Subroutine get_table_version: called CC=15 SCAR=28.5
Pod undocumented
833 127 my $table = shift;
834  
835 127 ▶ if ($table) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table) 25 102 127
836 25 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 16 9 25
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 9 0 9
837 # First check if this actually is an attempt to load an ECCODES table
838 16 ▶ if ($table =~ /wmo/ || $table =~ /local/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($table =~ /wmo/ or $table =~ /local/) 0 16 16
Condition33%1/3
$table =~ /wmo/ or $table =~ /local/
l!l&&r!l&&!r
0016
MC/DC0%0/2
$table =~ /wmo/ or $table =~ /local/
$table =~ /wmo/ $table =~ /local/
Truth table33%1/3
A or B
A= $table =~ /wmo/B= $table =~ /local/
ABresult
1X1
011
000
839 0 _croak("$table cannot be a BUFRDC table. "
840 . "Did you forget to set tableformat to ECCODES?");
841 }
842 16 (my $version = $table) =~ s/^(?:[BCD]?)(.*?)(?:\.TXT)?$/$1/;
843 16 return $version;
844 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
845 # Mainly meant to catch attempts to load a BUFRDC table
846 # with tableformat mistakingly set to ECCODES
847 9 ▶ _croak("$table cannot be an ecCodes table")
Branch: 1 branch
BranchTrueFalseTotal
unless $table =~ /wmo/ or $table =~ /local/ 0 9 9
Condition66%2/3
$table =~ /wmo/ or $table =~ /local/
l!l&&r!l&&!r
720
MC/DC0%0/2
$table =~ /wmo/ or $table =~ /local/
$table =~ /wmo/ $table =~ /local/
Truth table66%2/3
A or B
A= $table =~ /wmo/B= $table =~ /local/
ABresult
1X1
011
000
848 unless ($table =~ /wmo/ || $table =~ /local/);
849 9 return $table;
850 }
851 }
852  
853 # No table provided. Decide version from section 1 information.
854 # First check that the necessary metadata exist
855 102 foreach my $metadata (qw(MASTER_TABLE LOCAL_TABLE_VERSION
856 CENTRE SUBCENTRE)) {
857 408 ▶ return undef if ! defined $self->{$metadata};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$metadata} 0 408 408
858 }
859  
860 # If master table version, use centre 0 and subcentre 0 (in ECMWF
861 # BUFRDC this is the convention from version 320 onwards)
862 102 my $centre = $self->{CENTRE};
863 102 my $subcentre = $self->{SUBCENTRE};
864 102 my $local_table_version = $self->{LOCAL_TABLE_VERSION};
865 102 ▶ if ($local_table_version == 0 || $local_table_version == 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_table_version == 0 or $local_table_version == 255) 26 76 102
Condition66%2/3
$local_table_version == 0 or $local_table_version == 255
l!l&&r!l&&!r
26076
MC/DC50%1/2
$local_table_version == 0 or $local_table_version == 255
$local_table_version == 0 $local_table_version == 255
Truth table66%2/3
A or B
A= $local_table_version == 0B= $local_table_version == 255
ABresult
1X1
011
000
866 26 $centre = 0;
867 26 $subcentre = 0;
868 26 $local_table_version = 0;
869 }
870  
871 102 my $master_table = $self->{MASTER_TABLE};
872 102 my $master_table_version = $self->{MASTER_TABLE_VERSION};
873 102 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 93 9 102
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 9 0 9
874 # naming convention used in BUFRDC version >= 000270
875 93 return sprintf "%03d%05d%05d%03d%03d",
876 $master_table,$subcentre,$centre,$master_table_version,$local_table_version;
877 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
878 9 ▶ if ($local_table_version == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local_table_version == 0) { } 0 9 9
879 0 return catfile($master_table,'wmo',$master_table_version);
880 } else {
881 9 return catfile($master_table,'wmo',$master_table_version) . ',' .
882 catfile($master_table,'local',$local_table_version,$centre,$subcentre);
883 }
884 }
885 }
886  
887 # Return table version for the latest master table found in tablepath,
888 # in the same format as get_table_version. For use when master table
889 # version is not known, e.g. in bufrresolve.pl.
890 sub get_max_table_version {
891 2 ▶ my ($self) = @_;
Subroutine get_max_table_version: called CC=13 SCAR=37.3
Pod undocumented
892  
893 _croak "BUFR table path not set, did you forget to call set_tablepath()?"
894 2 ▶ unless $BUFR_table{PATH};
Branch: 1 branch
BranchTrueFalseTotal
unless $Geo::BUFR::BUFR_table{"PATH"} 0 2 2
895  
896 2 my $max_version = 0;
897 2 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 0 2 2
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 2 0 2
898 0 foreach my $tabledir (split /:/, $BUFR_table{PATH}) {
899 0 ▶ opendir(my $dh, $tabledir) || _croak "Couldn't open $tabledir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $tabledir or _croak("Couldn't open ${tabledir}: $!") 0 0 0
900 0 my @btables = sort grep { /^B0000000000000\d{3}000.TXT/ } readdir $dh;
901 0 closedir $dh;
902 0 ▶ my $version = substr($btables[-1], 14, 3)
Condition0%0/3
substr($btables[-1], 14, 3) || _croak('Wrong tablepath or tableformat?')
l!l&&r!l&&!r
000
MC/DC0%0/2
substr($btables[-1], 14, 3) || _croak('Wrong tablepath or tableformat?')
substr($btables[-1], 14, 3) _croak('Wrong tablepath or tableformat?')
Truth table0%0/3
A || B
A= substr($btables[-1], 14, 3)B= _croak('Wrong tablepath or tableformat?')
ABresult
1X1
011
000
903 || _croak "Wrong tablepath or tableformat?";
904 0 ▶ if ($version > $max_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version > $max_version) 0 0 0
905 0 $max_version = $version;
906 }
907 }
908  
909 0 ▶ _croak "No WMO master table found" unless $max_version;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_version 0 0 0
910  
911 0 return '0000000000000' . $max_version . '000';
912  
913 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
914 2 foreach my $tabledir (split /:/, $BUFR_table{PATH}) {
915 2 my $dir = catfile($tabledir,'0/wmo');
916 2 ▶ opendir(my $dh, $dir) || _croak "Cannot open $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or _croak("Cannot open ${dir}: $!") 0 2 2
917 2 my @files = sort {$a <=> $b} grep { /^[0-9]+$/ } readdir $dh;
918 2 closedir $dh;
919  
920 2 my $version = $files[-1];
921 2 ▶ if ($version > $max_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version > $max_version) 2 0 2
922 2 $max_version = $version;
923 }
924 }
925  
926 2 ▶ _croak "No WMO master table found" unless $max_version;
Branch: 1 branch
BranchTrueFalseTotal
unless $max_version 0 2 2
927  
928 2 return catfile('0', 'wmo', $max_version);
929 }
930 }
931  
932 # Search through $BUFR_table{PATH} to find first path for which $fname
933 # exists, or (for BUFRDC) if no such path exists, first path for which the
934 # corresponding master file exists, in which case
935 # $self->{LOCAL_TABLES_NOT_FOUND} is set to the local table initially
936 # searched for (this variable should be undefined as soon as the
937 # message is finished processing). Returns empty list if no such path
938 # could be found, else returns the path and the table name for which
939 # path was found.
940 sub _locate_table {
941 163 ▶ my ($self,$fname) = @_;
Subroutine _locate_table: called CC=6 SCAR=18.0
942  
943 _croak "BUFR table path not set, did you forget to call set_tablepath()?"
944 163 ▶ unless $BUFR_table{PATH};
Branch: 1 branch
BranchTrueFalseTotal
unless $Geo::BUFR::BUFR_table{"PATH"} 0 163 163
945  
946 163 my $path;
947 163 foreach (split /:/, $BUFR_table{PATH}) {
948 163 ▶ if (-e catfile($_, $fname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile($_, $fname)) 146 17 163
949 146 $path = $_;
950 146 $path =~ s|/$||;
951 146 return ($path,$fname);
952 }
953 }
954  
955 17 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{"FORMAT"} eq "BUFRDC") 8 9 17
956 # Path couldn't be found for $fname. Then try again for master table
957 8 my $master_table;
958 8 ($master_table,$path) = $self->_locate_master_table($fname);
959 8 ▶ if ($path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 8 0 8
960 8 $self->{LOCAL_TABLES_NOT_FOUND} = $fname;
961 8 return ($path,$master_table);
962 }
963 }
964  
965 # No table found
966 9 return;
967 }
968  
969 # Return master table and path corresponding to local table $fname, or
970 # empty list if $fname actually is a master table or if no path for the
971 # master table could be found.
972 sub _locate_master_table {
973 8 ▶ my ($self,$fname) = @_;
Subroutine _locate_master_table: called CC=9 SCAR=27.3
974  
975 8 my $master_table;
976 8 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 8 0 8
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 0 0 0
977 8 ▶ _croak("$fname is not a valid name for BUFRDC tables")
Branch: 1 branch
BranchTrueFalseTotal
if length $fname < 20 0 8 8
978 if length($fname) < 20;
979 8 $master_table = substr($fname,0,4) . '00000' . '00000'
980 . substr($fname,14,3) . '000.TXT';
981 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
982 0 foreach my $metadata (qw(MASTER_TABLE MASTER_TABLE_VERSION)) {
983 0 ▶ return if ! defined $self->{$metadata};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$metadata} 0 0 0
984 }
985 0 $master_table = catfile($self->{MASTER_TABLE},'wmo',$self->{MASTER_TABLE_VERSION});
986 }
987 8 ▶ return if ($master_table eq $fname); # Already tried
Branch: 1 branch
BranchTrueFalseTotal
if $master_table eq $fname 0 8 8
988  
989 8 my $path;
990 8 foreach (split /:/, $BUFR_table{PATH}) {
991 8 ▶ if (-e catfile($_, $master_table)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile($_, $master_table)) 8 0 8
992 8 $path = $_;
993 8 $path =~ s|/$||;
994 8 return ($master_table,$path);
995 }
996 }
997 0 return;
998 }
999  
1000 ## Read in a B table file into a hash, e.g.
1001 ## $B_table{'001001'} = "WMO BLOCK NUMBER\0NUMERIC\0 0\0 0\0 7"
1002 ## where the B table values for 001001 are \0 (NUL) separated
1003 sub _read_B_table_bufrdc {
1004 61 ▶ my ($self,$version) = @_;
Subroutine _read_B_table_bufrdc: called CC=8 SCAR=20.9
1005  
1006 61 my $fname = "B$version.TXT";
1007 61 ▶ my ($path,$tname) = $self->_locate_table($fname)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->_locate_table($fname) or _croak(qq[Couldn't find BUFR table $fname in $Geo::BUFR::BUFR_table{"PATH"}.] . ' Wrong tablepath?') 0 61 61
1008 or _croak "Couldn't find BUFR table $fname in $BUFR_table{PATH}."
1009 . " Wrong tablepath?";
1010  
1011 # If we are forced to try master table because local table
1012 # couldn't be found, check if this might already have been loaded
1013 61 ▶ if ($tname ne $fname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tname ne $fname) 4 57 61
1014 4 my $master_version = substr($tname,1,-4);
1015 4 ▶ return $BUFR_table{"B$master_version"} if exists $BUFR_table{"B$master_version"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Geo::BUFR::BUFR_table{"B$master_version"} 0 4 4
1016 }
1017  
1018 61 my $tablefile = catfile($path,$tname);
1019 61 ▶ open(my $TABLE, '<', $tablefile)
Branch: 1 branch
BranchTrueFalseTotal
open my $TABLE, "<", $tablefile or _croak("Couldn't open BUFR table B ${tablefile}: $!") 0 61 61
1020 or _croak "Couldn't open BUFR table B $tablefile: $!";
1021 61 my $txt = "Reading table $tablefile";
1022 $txt .= " (since local table " . $self->{LOCAL_TABLES_NOT_FOUND}
1023 61 ▶ . " couldn't be found)" if $self->{LOCAL_TABLES_NOT_FOUND};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOCAL_TABLES_NOT_FOUND"} 4 57 61
1024 61 $self->_spew(1, "%s", $txt);
1025  
1026 61 my %B_table;
1027 61 ▶ while (<$TABLE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $TABLE)) 83814 61 83875
1028 83814 my ($s1,$fxy,$s2,$name,$s3,$unit,$s4,$scale,$s5,$refval,$s6,$bits)
1029 = unpack('AA6AA64AA24AA3AA12AA3', $_);
1030 83814 ▶ next unless defined $bits;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bits 0 83814 83814
1031 83814 $name =~ s/\s+$//;
1032 83814 $refval =~ s/-\s+(\d+)/-$1/; # Remove blanks between minus sign and value
1033 83814 $B_table{$fxy} = join "\0", $name, $unit, $scale, $refval, $bits;
1034 }
1035 # When installing Geo::BUFR on Windows Vista with Strawberry Perl,
1036 # close sometimes returned an empty string. Therefore removed
1037 # check on return value for close.
1038 61 close $TABLE; # or _croak "Closing $tablefile failed: $!";
1039  
1040 61 $BUFR_table{"B$version"} = \%B_table;
1041 61 return \%B_table;
1042 }
1043  
1044 sub _read_B_table_eccodes {
1045 14 ▶ my ($self,$version) = @_;
Subroutine _read_B_table_eccodes: called CC=8 SCAR=20.9
1046  
1047 14 my ($path,$tname) = $self->_locate_table(catfile($version,'element.table'));
1048  
1049 14 ▶ if (! $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 4 10 14
1050 4 ▶ if ($version =~ /wmo/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /wmo/) { } 0 4 4
1051 0 _croak "Couldn't find BUFR table " . catfile($version,'element.table')
1052 . " in $BUFR_table{PATH}. Wrong tablepath?";
1053 } else {
1054 # This might actually not be an error, since local table
1055 # might be provided for D only. But if later a local
1056 # element descriptor is requested, we should complain
1057 4 $self->{LOCAL_TABLES_NOT_FOUND} = $version;
1058 4 return;
1059 }
1060 }
1061 10 my $tablefile = catfile($path,$tname);
1062  
1063 10 ▶ open(my $TABLE, '<', $tablefile)
Branch: 1 branch
BranchTrueFalseTotal
open my $TABLE, "<", $tablefile or _croak("Couldn't open BUFR table B ${tablefile}: $!") 0 10 10
1064 or _croak "Couldn't open BUFR table B $tablefile: $!";
1065 10 $self->_spew(1, "Reading table %s", $tablefile);
1066  
1067 10 my %B_table;
1068 10 ▶ while (<$TABLE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $TABLE)) 3902 10 3912
1069 # Skip comments (expexted to be in first line only)
1070 3902 ▶ next if /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^#/ 10 3892 3902
1071  
1072 # $rest is crex_unit|crex_scale|crex_width
1073 3892 my ($code,$abbreviation,$type,$name,$unit,$scale,$reference,$width,$rest)
1074 = split /[|]/;
1075 3892 ▶ next unless defined $width; # shouldn't happen
Branch: 1 branch
BranchTrueFalseTotal
unless defined $width 0 3892 3892
1076 3892 ▶ $unit = 'CCITTIA5' if $unit eq 'CCITT IA5';
Branch: 1 branch
BranchTrueFalseTotal
if $unit eq "CCITT IA5" 258 3634 3892
1077 3892 $B_table{$code} = join "\0", $name, $unit, $scale, $reference, $width;
1078 }
1079 10 close $TABLE;
1080  
1081 10 $BUFR_table{"B$version"} = \%B_table;
1082 10 return \%B_table;
1083 }
1084  
1085 ## Reads a D table file into a hash, e.g.
1086 ## $D_table->{307080} = '301090 302031 ...'
1087 ## There are two different types of lines in D*.TXT, e.g.
1088 ## 307080 13 301090 BUFR template for synoptic reports
1089 ## 302031
1090 ## We choose to ignore the number of lines in expansion (here 13)
1091 ## because this number is sometimes in error. Instead we consider a
1092 ## line starting with 5 spaces to be of the second type above, else of
1093 ## the first type
1094 sub _read_D_table_bufrdc {
1095 61 ▶ my ($self,$version) = @_;
Subroutine _read_D_table_bufrdc: called CC=9 SCAR=22.1
1096  
1097 61 my $fname = "D$version.TXT";
1098 61 ▶ my ($path,$tname) = $self->_locate_table($fname)
Branch: 1 branch
BranchTrueFalseTotal
() = $self->_locate_table($fname) or _croak(qq[Couldn't find BUFR table $fname in $Geo::BUFR::BUFR_table{"PATH"}.] . 'Wrong tablepath?') 0 61 61
1099 or _croak "Couldn't find BUFR table $fname in $BUFR_table{PATH}."
1100 . "Wrong tablepath?";
1101  
1102 # If we are forced to try master table because local table
1103 # couldn't be found, check if this might already have been loaded
1104 61 ▶ if ($tname ne $fname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tname ne $fname) 4 57 61
1105 4 my $master_version = substr($tname,1,-4);
1106 4 ▶ return $BUFR_table{"D$master_version"} if exists $BUFR_table{"D$master_version"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Geo::BUFR::BUFR_table{"D$master_version"} 0 4 4
1107 }
1108  
1109 61 my $tablefile = catfile($path,$tname);
1110 61 ▶ open(my $TABLE, '<', $tablefile)
Branch: 1 branch
BranchTrueFalseTotal
open my $TABLE, "<", $tablefile or _croak("Couldn't open BUFR table D ${tablefile}: $!") 0 61 61
1111 or _croak "Couldn't open BUFR table D $tablefile: $!";
1112 61 my $txt = "Reading table $tablefile";
1113 $txt .= " (since local table " . $self->{LOCAL_TABLES_NOT_FOUND}
1114 61 ▶ . " couldn't be found)" if $self->{LOCAL_TABLES_NOT_FOUND};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOCAL_TABLES_NOT_FOUND"} 4 57 61
1115 61 $self->_spew(1, "%s", $txt);
1116  
1117 61 my (%D_table, $alias);
1118 61 ▶ while (my $line = <$TABLE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $TABLE)) 226371 61 226432
1119 226371 $line =~ s/\s+$//;
1120 226371 ▶ next if $line =~ /^\s*$/; # Blank line
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 226371 226371
1121  
1122 226371 ▶ if (substr($line,0,5) eq ' ' x 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($line, 0, 5) eq ' ') { } 201117 25254 226371
1123 201117 $line =~ s/^\s+//;
1124 201117 $D_table{$alias} .= " $line";
1125 } else {
1126 25254 $line =~ s/^\s+//;
1127 # In table version 17 a descriptor with more than 100
1128 # entries occurs, causing no space between alias and
1129 # number of entries (so split /\s+/ doesn't work)
1130 25254 my ($ali, $skip, $desc) = unpack('A6A4A6', $line);
1131 25254 $alias = $ali;
1132 25254 $D_table{$alias} = $desc;
1133 }
1134 }
1135 61 close $TABLE; # or _croak "Closing $tablefile failed: $!";
1136  
1137 61 $BUFR_table{"D$version"} = \%D_table;
1138 61 return \%D_table;
1139 }
1140  
1141 sub _read_D_table_eccodes {
1142 14 ▶ my ($self,$version) = @_;
Subroutine _read_D_table_eccodes: called CC=8 SCAR=20.9
1143  
1144 14 my ($path,$tname) = $self->_locate_table(catfile($version,'sequence.def'));
1145  
1146 14 ▶ if (! $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 5 9 14
1147 5 ▶ if ($version =~ /wmo/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /wmo/) { } 0 5 5
1148 0 _croak "Couldn't find BUFR table " . catfile($version,'sequence.def')
1149 . " in $BUFR_table{PATH}. Wrong tablepath?";
1150 } else {
1151 # This might actually not be an error, since local table
1152 # might be provided for B only. But if later a local
1153 # sequence descriptor is requested, we should complain
1154 5 $self->{LOCAL_TABLES_NOT_FOUND} = $version;
1155 }
1156 5 return;
1157 }
1158 9 my $tablefile = catfile($path,$tname);
1159  
1160 9 ▶ open(my $TABLE, '<', $tablefile)
Branch: 1 branch
BranchTrueFalseTotal
open my $TABLE, "<", $tablefile or _croak("Couldn't open BUFR table B ${tablefile}: $!") 0 9 9
1161 or _croak "Couldn't open BUFR table B $tablefile: $!";
1162 9 $self->_spew(1, "Reading table %s", $tablefile);
1163  
1164 ## sequence.def is expected to contain lines like
1165 #"301196" = [ 301011, 301013, 301021 ]
1166 ## which should be converted to
1167 # 301196 3 301011
1168 # 301013
1169 # 301021
1170 ## Must also handle descriptors spanning more than one line, like
1171 #"301046" = [ 001007, 001012, 002048, 021119, 025060, 202124, 002026, 002027, 202000, 005040
1172 # ]
1173 ## and
1174 #"301058" = [ 301011, 301012, 201152, 202135, 004006, 202000, 201000, 301021, 020111, 020112,
1175 # 020113, 020114, 020115, 020116, 020117, 020118, 020119, 025035, 020121, 020122,
1176 # 020123, 020124, 025175, 020023, 025063, 202136, 201136, 002121, 201000, 202000,
1177 # 025061, 002184, 002189, 025036, 101000, 031002, 301059 ]
1178 9 my %D_table;
1179 my $txt;
1180 9 ▶ while (<$TABLE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $TABLE)) 1698 9 1707
1181 1698 ▶ if (substr($_,0,1) eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, 0, 1) eq '"') { } 1410 288 1698
1182 # New sequence descriptor, parse and store the previous
1183 1410 ▶ _parse_sequence(\%D_table,$txt) if $txt;
Branch: 1 branch
BranchTrueFalseTotal
if $txt 1401 9 1410
1184 1410 chomp;
1185 1410 $txt = $_;
1186 } else {
1187 288 chomp;
1188 288 $txt .= $_;
1189 }
1190 }
1191 9 ▶ _parse_sequence(\%D_table,$txt) if $txt;
Branch: 1 branch
BranchTrueFalseTotal
if $txt 9 0 9
1192  
1193 9 close $TABLE; # or _croak "Closing $tablefile failed: $!";
1194  
1195 9 $BUFR_table{"D$version"} = \%D_table;
1196 9 return \%D_table;
1197 }
1198  
1199 sub _parse_sequence {
1200 1410 ▶ my ($Dtable, $txt) = @_;
Subroutine _parse_sequence: called CC=2 SCAR=6.9
1201  
1202 1410 my ($seq, $rest) = ($txt =~ /^"(\d{6})" = \[(.*)\]/);
1203 1410 my @list = split(/,/, $rest);
1204 1410 foreach (@list) {
1205 9486 s/^ +//;
1206 9486 s/ +$//;
1207 }
1208 1410 $Dtable->{$seq} = join(' ', @list);
1209 }
1210  
1211 ## Read the flag and code tables, which in ECMWF BUFRDC tables are
1212 ## put in tables C$version.TXT (not to be confused with BUFR C tables,
1213 ## which contain the operator descriptors). Note that even though
1214 ## number of code values and number of lines are included in the
1215 ## tables, we choose to ignore them, because these values are often
1216 ## found to be in error. Instead we trust that the text starts at
1217 ## fixed positions in file. Returns reference to the C table, or undef
1218 ## if failing to open table file.
1219 sub _read_C_table {
1220 9 ▶ my ($self,$version) = @_;
Subroutine _read_C_table: called CC=21 SCAR=32.9
1221  
1222 # For ECCODES loading 2 different codetables directories might be necessary
1223 9 ▶ if ($BUFR_table{FORMAT} eq 'ECCODES') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES") 3 6 9
1224 3 ▶ if ($version =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /,/) { } 0 3 3
1225 0 my ($master, $local) = (split /,/, $version);
1226 0 $self->_read_C_table_eccodes($master);
1227 0 return $self->_read_C_table_eccodes($local);
1228 } else {
1229 3 return $self->_read_C_table_eccodes($version);
1230 }
1231 }
1232  
1233 # Rest of code is for BUFRDC
1234 6 my $fname = "C$version.TXT";
1235 6 my ($path,$tname) = $self->_locate_table($fname);
1236 6 ▶ return undef unless $path;
Branch: 1 branch
BranchTrueFalseTotal
unless $path 0 6 6
1237  
1238 # If we are forced to try master table because local table
1239 # couldn't be found, check if this might already have been loaded
1240 6 ▶ if ($tname ne $fname) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tname ne $fname) 0 6 6
1241 0 my $master_version = substr($tname,1,-4);
1242 0 ▶ return $BUFR_table{"C$master_version"} if exists $BUFR_table{"C$master_version"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Geo::BUFR::BUFR_table{"C$master_version"} 0 0 0
1243 }
1244  
1245 6 my $tablefile = catfile($path,$tname);
1246 6 ▶ open(my $TABLE, '<', $tablefile)
Branch: 1 branch
BranchTrueFalseTotal
open my $TABLE, "<", $tablefile or _croak("Couldn't open BUFR table C ${tablefile}: $!") 0 6 6
1247 or _croak "Couldn't open BUFR table C $tablefile: $!";
1248 6 my $txt = "Reading table $tablefile";
1249 $txt .= " (since local table " . $self->{LOCAL_TABLES_NOT_FOUND}
1250 6 ▶ . " couldn't be found)" if $self->{LOCAL_TABLES_NOT_FOUND};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOCAL_TABLES_NOT_FOUND"} 0 6 6
1251 6 $self->_spew(1, "%s", $txt);
1252  
1253 6 my (%C_table, $table, $value);
1254 6 ▶ while (my $line = <$TABLE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $TABLE)) 28506 6 28512
1255 28506 $line =~ s/\s+$//;
1256 28506 ▶ next if $line =~ /^\s*$/; # Blank line
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 28506 28506
1257  
1258 28506 ▶ if (substr($line,0,15) eq ' ' x 15) {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($line, 0, 15) eq ' ') { } 3210 25296 28506
elsif (substr($line, 0, 10) eq ' ') { } 23292 2004 25296
1259 3210 $line =~ s/^\s+//;
1260 3210 ▶ next if $line eq 'NOT DEFINED' || $line eq 'RESERVED';
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "NOT DEFINED" or $line eq "RESERVED" 0 3210 3210
Condition33%1/3
$line eq "NOT DEFINED" or $line eq "RESERVED"
l!l&&r!l&&!r
003210
MC/DC0%0/2
$line eq "NOT DEFINED" or $line eq "RESERVED"
$line eq "NOT DEFINED" $line eq "RESERVED"
Truth table33%1/3
A or B
A= $line eq "NOT DEFINED"B= $line eq "RESERVED"
ABresult
1X1
011
000
1261 3210 $C_table{$table}{$value} .= $line . "\n";
1262 } elsif (substr($line,0,10) eq ' ' x 10) {
1263 23292 $line =~ s/^\s+//;
1264 23292 my ($val, $nlines, $txt) = split /\s+/, $line, 3;
1265 23292 $value = $val+0;
1266 23292 ▶ next if !defined $txt || $txt eq 'NOT DEFINED' || $txt eq 'RESERVED';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED" 312 22974 23286
Condition83%5/6
not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED"
l!l&&r!l&&!r
631222974
not defined $txt or $txt eq "NOT DEFINED"
l!l&&r!l&&!r
6023286
MC/DC66%2/3
not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED"
not defined $txt $txt eq "NOT DEFINED" $txt eq "RESERVED"
Truth table75%3/4
not(A) or B or C
A= not defined $txtB= $txt eq "NOT DEFINED"C= $txt eq "RESERVED"
ABCresult
1XX1
01X1
0011
0000
1267 22974 $C_table{$table}{$value} .= $txt . "\n";
1268 } else {
1269 2004 my ($tbl, $nval, $val, $nlines, $txt) = split /\s+/, $line, 5;
1270 2004 $table = sprintf "%06d", $tbl;
1271 # For tables listed 2 or more times, use last instance only.
1272 # This prevents $txt to be duplicated in $C_table{$table}{$value}
1273 2004 ▶ undef $C_table{$table} if defined $C_table{$table};
Branch: 1 branch
BranchTrueFalseTotal
if defined $C_table{$table} 12 1992 2004
1274 2004 $value = $val+0;
1275 2004 ▶ next if !defined $txt || $txt eq 'NOT DEFINED' || $txt eq 'RESERVED';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED" 174 1830 2004
Condition50%3/6
not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED"
l!l&&r!l&&!r
01741830
not defined $txt or $txt eq "NOT DEFINED"
l!l&&r!l&&!r
002004
MC/DC33%1/3
not defined $txt or $txt eq "NOT DEFINED" or $txt eq "RESERVED"
not defined $txt $txt eq "NOT DEFINED" $txt eq "RESERVED"
Truth table50%2/4
not(A) or B or C
A= not defined $txtB= $txt eq "NOT DEFINED"C= $txt eq "RESERVED"
ABCresult
1XX1
01X1
0011
0000
1276 1830 $C_table{$table}{$value} = $txt . "\n";
1277 }
1278 }
1279 6 close $TABLE; # or _croak "Closing $tablefile failed: $!";
1280  
1281 6 $BUFR_table{"C$version"} = \%C_table;
1282 6 return \%C_table;
1283 }
1284  
1285 sub _read_C_table_eccodes {
1286 7 ▶ my ($self,$version) = @_;
Subroutine _read_C_table_eccodes: called CC=15 SCAR=31.5
1287  
1288 7 my ($path,$tname) = $self->_locate_table(catfile($version,'codetables'));
1289  
1290 7 ▶ if (! $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path) 0 7 7
1291 0 ▶ if ($version =~ /wmo/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /wmo/) { } 0 0 0
1292 0 ▶ _croak "Couldn't find BUFR table " . catfile($version,'element.table')
Branch: 1 branch
BranchTrueFalseTotal
if not $path and $version =~ /wmo/ 0 0 0
Condition0%0/3
not $path and $version =~ /wmo/
!ll&&!rl&&r
000
MC/DC0%0/2
not $path and $version =~ /wmo/
not $path $version =~ /wmo/
Truth table0%0/3
not(A) and B
A= not $pathB= $version =~ /wmo/
ABresult
0X0
100
111
1293 . " in $BUFR_table{PATH}. Wrong tablepath?"
1294 if (! $path && $version =~ /wmo/);
1295 } else {
1296 # This might actually not be an error, if none of the
1297 # local descriptors are of type code or flag table. So
1298 # prefer to keep silent in this case.
1299 0 return;
1300 }
1301 }
1302  
1303 7 my $tabledir = catfile($path,$tname);
1304  
1305 7 ▶ opendir(my $dh, $tabledir) || _croak "Couldn't open $tabledir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $tabledir or _croak("Couldn't open ${tabledir}: $!") 0 7 7
1306 7 my @table_files = grep { /table$/ } readdir $dh;
1307 7 closedir($dh);
1308 7 ▶ $self->_spew(1, "Reading tables in %s", $tabledir) if @table_files;
Branch: 1 branch
BranchTrueFalseTotal
if @table_files 7 0 7
1309  
1310 7 my %C_table;
1311 7 foreach my $table_file (@table_files) {
1312 21 my ($table) = ($table_file =~ /(\d+)\.table$/);
1313 21 ▶ die "Unexpected name of table file: $table_file" unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 0 21 21
1314 21 $table = sprintf "%06d", $table;
1315  
1316 21 ▶ open my $IN, '<', catfile($tabledir, $table_file)
Branch: 1 branch
BranchTrueFalseTotal
open my $IN, "<", catfile($tabledir, $table_file) or _croak("Couldn't open ${table_file}: $!") 0 21 21
1317 or _croak "Couldn't open $table_file: $!";
1318 21 ▶ while (<$IN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $IN)) 443 21 464
1319 443 chomp;
1320 443 my ($num, $val, $txt) = split(/ /, $_, 3);
1321 443 ▶ _complain("Unexpected: first 2 fields in $table_file in $tabledir are unequal: $num $val")
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and $num ne $val 0 443 443
Condition66%2/3
$Geo::BUFR::Strict_checking and $num ne $val
!ll&&!rl&&r
2611820
MC/DC0%0/2
$Geo::BUFR::Strict_checking and $num ne $val
$Geo::BUFR::Strict_checking $num ne $val
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= $num ne $val
ABresult
0X0
100
111
1322 if ($Strict_checking and $num ne $val);
1323  
1324 # Fix a common problem in ecCodes codetables with long
1325 # lines, hopefully not changing valid use of '"' in local
1326 # tables (e.g. 8/78/0/codetables/8198.table: ""Nebenamtliche"" measurement
1327 443 $txt =~ s/(?<!")" +//;
1328 ## $txt =~ s/" +//;
1329  
1330 443 $C_table{$table}{$val} = $txt . "\n";
1331 }
1332  
1333 _complain("$table_file in $tabledir is empty!")
1334 21 ▶ if ($Strict_checking and not $C_table{$table});
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and not $C_table{$table} 0 21 21
Condition66%2/3
$Geo::BUFR::Strict_checking and not $C_table{$table}
!ll&&!rl&&r
1290
MC/DC0%0/2
$Geo::BUFR::Strict_checking and not $C_table{$table}
$Geo::BUFR::Strict_checking not $C_table{$table}
Truth table66%2/3
A and not(B)
A= $Geo::BUFR::Strict_checkingB= not $C_table{$table}
ABresult
0X0
100
111
1335 21 close $IN;
1336 }
1337  
1338 7 $BUFR_table{"C$version"} = \%C_table;
1339 7 return \%C_table;
1340 }
1341  
1342 sub _get_tableid_eccodes {
1343 0 ▶ my $table_file = shift;
Subroutine _get_tableid_eccodes: not called CC=1 SCAR=6.9
1344 0 my ($id) = ($table_file =~ /(\d+)\.table$/);
1345 0 return $id;
1346 }
1347  
1348  
1349 sub load_BDtables {
1350 104 ▶ my $self = shift;
Subroutine load_BDtables: called CC=14 SCAR=27.7
Pod undocumented
1351 104 ▶ my $table = shift || '';
Condition100%2/2
shift() || ''
l!l
1094
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
1352  
1353 104 ▶ my $version = $self->{TABLE_VERSION} = $self->get_table_version($table)
Branch: 1 branch
BranchTrueFalseTotal
my $version = $self->{"TABLE_VERSION"} = $self->get_table_version($table) or _croak("Not enough info to decide which tables to load") 0 104 104
1354 or _croak "Not enough info to decide which tables to load";
1355  
1356 104 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 95 9 104
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 9 0 9
1357 95 ▶ $self->{B_TABLE} = $BUFR_table{"B$version"} || $self->_read_B_table_bufrdc($version);
Condition66%2/3
$Geo::BUFR::BUFR_table{"B$version"} || $self->_read_B_table_bufrdc($version)
l!l&&r!l&&!r
34610
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"B$version"} || $self->_read_B_table_bufrdc($version)
$Geo::BUFR::BUFR_table{"B$version"} $self->_read_B_table_bufrdc($version)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"B$version"}B= $self->_read_B_table_bufrdc($version)
ABresult
1X1
011
000
1358 95 ▶ $self->{D_TABLE} = $BUFR_table{"D$version"} || $self->_read_D_table_bufrdc($version);
Condition66%2/3
$Geo::BUFR::BUFR_table{"D$version"} || $self->_read_D_table_bufrdc($version)
l!l&&r!l&&!r
34610
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"D$version"} || $self->_read_D_table_bufrdc($version)
$Geo::BUFR::BUFR_table{"D$version"} $self->_read_D_table_bufrdc($version)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"D$version"}B= $self->_read_D_table_bufrdc($version)
ABresult
1X1
011
000
1359 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
1360 9 ▶ if ($version =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /,/) { } 7 2 9
1361 7 my ($master, $local) = (split /,/, $version);
1362 7 ▶ $self->{B_TABLE} = $BUFR_table{"B$master"} || $self->_read_B_table_eccodes($master);
Condition66%2/3
$Geo::BUFR::BUFR_table{"B$master"} || $self->_read_B_table_eccodes($master)
l!l&&r!l&&!r
250
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"B$master"} || $self->_read_B_table_eccodes($master)
$Geo::BUFR::BUFR_table{"B$master"} $self->_read_B_table_eccodes($master)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"B$master"}B= $self->_read_B_table_eccodes($master)
ABresult
1X1
011
000
1363 7 ▶ $self->{D_TABLE} = $BUFR_table{"D$master"} || $self->_read_D_table_eccodes($master);
Condition66%2/3
$Geo::BUFR::BUFR_table{"D$master"} || $self->_read_D_table_eccodes($master)
l!l&&r!l&&!r
250
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"D$master"} || $self->_read_D_table_eccodes($master)
$Geo::BUFR::BUFR_table{"D$master"} $self->_read_D_table_eccodes($master)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"D$master"}B= $self->_read_D_table_eccodes($master)
ABresult
1X1
011
000
1364  
1365 # Append local table to the master table (should work even if empty)
1366 7 ▶ my $local_Btable = (exists($BUFR_table{"B$local"})) ? $BUFR_table{"B$local"}
Branch: 1 branch
BranchTrueFalseTotal
exists $Geo::BUFR::BUFR_table{"B$local"} ? : 0 7 7
1367 : $self->_read_B_table_eccodes($local);
1368 7 @{$self->{B_TABLE}}{ keys %$local_Btable } = values %$local_Btable;
1369 7 ▶ my $local_Dtable = (exists($BUFR_table{"D$local"})) ? $BUFR_table{"D$local"}
Branch: 1 branch
BranchTrueFalseTotal
exists $Geo::BUFR::BUFR_table{"D$local"} ? : 0 7 7
1370 : $self->_read_D_table_eccodes($local);
1371 7 @{$self->{D_TABLE}}{ keys %$local_Dtable } = values %$local_Dtable;;
1372  
1373 } else {
1374 2 ▶ $self->{B_TABLE} = $BUFR_table{"B$version"} || $self->_read_B_table_eccodes($version);
Condition33%1/3
$Geo::BUFR::BUFR_table{"B$version"} || $self->_read_B_table_eccodes($version)
l!l&&r!l&&!r
020
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"B$version"} || $self->_read_B_table_eccodes($version)
$Geo::BUFR::BUFR_table{"B$version"} $self->_read_B_table_eccodes($version)
Truth table33%1/3
A || B
A= $Geo::BUFR::BUFR_table{"B$version"}B= $self->_read_B_table_eccodes($version)
ABresult
1X1
011
000
1375 2 ▶ $self->{D_TABLE} = $BUFR_table{"D$version"} || $self->_read_D_table_eccodes($version);
Condition66%2/3
$Geo::BUFR::BUFR_table{"D$version"} || $self->_read_D_table_eccodes($version)
l!l&&r!l&&!r
011
MC/DC50%1/2
$Geo::BUFR::BUFR_table{"D$version"} || $self->_read_D_table_eccodes($version)
$Geo::BUFR::BUFR_table{"D$version"} $self->_read_D_table_eccodes($version)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"D$version"}B= $self->_read_D_table_eccodes($version)
ABresult
1X1
011
000
1376 }
1377 }
1378 104 return $version;
1379 }
1380  
1381 sub load_Ctable {
1382 15 ▶ my $self = shift;
Subroutine load_Ctable: called CC=18 SCAR=40.4
Pod undocumented
1383 15 ▶ my $table = shift || '';
Condition50%1/2
shift() || ''
l!l
150
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
1384  
1385 15 ▶ my $version = $self->get_table_version($table) || '';
Condition50%1/2
$self->get_table_version($table) || ''
l!l
150
MC/DC0%0/1
$self->get_table_version($table) || ''
$self->get_table_version($table)
Truth table50%1/2
A
A= $self->get_table_version($table)
Aresult
11
00
1386  
1387 15 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 15 0 15
1388 15 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 9 6 15
elsif ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES') { } 6 0 6
1389 9 ▶ $self->{C_TABLE} = $BUFR_table{"C$version"} || $self->_read_C_table($version);
Condition66%2/3
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table($version)
l!l&&r!l&&!r
360
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table($version)
$Geo::BUFR::BUFR_table{"C$version"} $self->_read_C_table($version)
Truth table66%2/3
A || B
A= $Geo::BUFR::BUFR_table{"C$version"}B= $self->_read_C_table($version)
ABresult
1X1
011
000
1390 } elsif ($BUFR_table{FORMAT} eq 'ECCODES') {
1391 6 ▶ if ($version =~ /,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /,/) { } 3 3 6
1392 3 my ($master, $local) = (split /,/, $version);
1393 3 ▶ $self->{C_TABLE} = $BUFR_table{"$master"} || $self->_read_C_table($master);
Condition33%1/3
$Geo::BUFR::BUFR_table{"$master"} || $self->_read_C_table($master)
l!l&&r!l&&!r
030
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"$master"} || $self->_read_C_table($master)
$Geo::BUFR::BUFR_table{"$master"} $self->_read_C_table($master)
Truth table33%1/3
A || B
A= $Geo::BUFR::BUFR_table{"$master"}B= $self->_read_C_table($master)
ABresult
1X1
011
000
1394  
1395 # Append local table to the master table (should work even if empty)
1396 3 ▶ my $local_Ctable = (exists($BUFR_table{"C$local"})) ? $BUFR_table{"C$local"}
Branch: 1 branch
BranchTrueFalseTotal
exists $Geo::BUFR::BUFR_table{"C$local"} ? : 2 1 3
1397 : $self->_read_C_table_eccodes($local);
1398 3 @{$self->{C_TABLE}}{ keys %$local_Ctable } = values %$local_Ctable;
1399  
1400 } else {
1401 3 ▶ $self->{C_TABLE} = $BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version);
Condition33%1/3
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version)
l!l&&r!l&&!r
030
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version)
$Geo::BUFR::BUFR_table{"C$version"} $self->_read_C_table_eccodes($version)
Truth table33%1/3
A || B
A= $Geo::BUFR::BUFR_table{"C$version"}B= $self->_read_C_table_eccodes($version)
ABresult
1X1
011
000
1402 }
1403 }
1404 }
1405  
1406 15 ▶ if (not $self->{C_TABLE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"C_TABLE"}) 0 15 15
1407 # Was not able to load $table. Try latest master table instead.
1408 0 ▶ $version = $self->get_max_table_version()
Condition0%0/3
$self->get_max_table_version || _croak('No master tables found in tablepath')
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_max_table_version || _croak('No master tables found in tablepath')
$self->get_max_table_version _croak('No master tables found in tablepath')
Truth table0%0/3
A || B
A= $self->get_max_table_versionB= _croak('No master tables found in tablepath')
ABresult
1X1
011
000
1409 || _croak "No master tables found in tablepath";
1410 0 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 0 0 0
1411 0 ▶ $self->{C_TABLE} = $BUFR_table{"C$version"} || $self->_read_C_table($version);
Condition0%0/3
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table($version)
l!l&&r!l&&!r
000
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table($version)
$Geo::BUFR::BUFR_table{"C$version"} $self->_read_C_table($version)
Truth table0%0/3
A || B
A= $Geo::BUFR::BUFR_table{"C$version"}B= $self->_read_C_table($version)
ABresult
1X1
011
000
1412 } else {
1413 0 ▶ $self->{C_TABLE} = $BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version);
Condition0%0/3
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version)
l!l&&r!l&&!r
000
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"C$version"} || $self->_read_C_table_eccodes($version)
$Geo::BUFR::BUFR_table{"C$version"} $self->_read_C_table_eccodes($version)
Truth table0%0/3
A || B
A= $Geo::BUFR::BUFR_table{"C$version"}B= $self->_read_C_table_eccodes($version)
ABresult
1X1
011
000
1414 }
1415 }
1416 15 ▶ if (not $self->{C_TABLE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"C_TABLE"}) 0 15 15
1417 0 ▶ if ($BUFR_table{FORMAT} eq 'BUFRDC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC') { } 0 0 0
1418 0 _croak "Unable to load C table (C$version.TXT)";
1419 } else {
1420 0 _croak "Unable to load codetables for $version";
1421 }
1422 }
1423  
1424 15 return $version;
1425 }
1426  
1427  
1428 ## Specify BUFR file to read
1429 sub fopen {
1430 39 ▶ my $self = shift;
Subroutine fopen: called CC=5 SCAR=16.6
Pod undocumented
1431 39 ▶ my $filename = shift
Branch: 1 branch
BranchTrueFalseTotal
my $filename = shift() or _croak("fopen() called without an argument") 0 39 39
1432 or _croak "fopen() called without an argument";
1433 39 ▶ _croak "File $filename doesn't exist!" unless -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 39 39
1434 39 ▶ _croak "$filename is not a plain file" unless -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $filename 0 39 39
1435  
1436 # Open file for reading
1437 39 $self->{FILEHANDLE} = new FileHandle;
1438 39 ▶ open $self->{FILEHANDLE}, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"FILEHANDLE"}, "<", $filename or _croak("Couldn't open file $filename for reading") 0 39 39
1439 or _croak "Couldn't open file $filename for reading";
1440  
1441 39 $self->_spew(2, "File %s opened for reading", $filename);
1442  
1443 # For some OS this is necessary
1444 39 binmode $self->{FILEHANDLE};
1445  
1446 39 $self->{FILENAME} = $filename;
1447 39 return 1;
1448 }
1449  
1450 sub fclose {
1451 40 ▶ my $self = shift;
Subroutine fclose: called CC=3 SCAR=11.0
Pod undocumented
1452 40 ▶ if ($self->{FILEHANDLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"FILEHANDLE"}) 37 3 40
1453 close $self->{FILEHANDLE}
1454 37 ▶ or _croak "Couldn't close BUFR file opened by fopen()";
Branch: 1 branch
BranchTrueFalseTotal
close $self->{"FILEHANDLE"} or _croak("Couldn't close BUFR file opened by fopen()") 0 37 37
1455 37 $self->_spew(2, "Closed file %s", $self->{FILENAME});
1456 }
1457 40 delete $self->{FILEHANDLE};
1458 40 delete $self->{FILENAME};
1459 # Much more might be considered deleted here, but usually the bufr
1460 # object goes out of scope immediately after a fclose anyway
1461 40 return 1;
1462 }
1463  
1464 sub eof {
1465 236 ▶ my $self = shift;
Subroutine eof: called CC=2 SCAR=6.9
Pod undocumented
1466 236 ▶ return ($self->{EOF} || 0);
Condition100%2/2
$self->{'EOF'} || 0
l!l
3233
MC/DC100%1/1
$self->{'EOF'} || 0
$self->{'EOF'}
Truth table100%2/2
A
A= $self->{'EOF'}
Aresult
11
00
1467 }
1468  
1469 # Go to start of input buffer or start of file associated with the object
1470 sub rewind {
1471 6 ▶ my $self = shift;
Subroutine rewind: called CC=4 SCAR=14.1
Pod undocumented
1472 6 ▶ if (exists $self->{FILEHANDLE}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'FILEHANDLE'}) { } 4 2 6
elsif (not $self->{'IN_BUFFER'}) { } 0 2 2
1473 4 ▶ seek $self->{FILEHANDLE}, 0, 0 or _croak "Cannot seek: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek $self->{"FILEHANDLE"}, 0, 0 or _croak("Cannot seek: $!") 0 4 4
1474 } elsif (! $self->{IN_BUFFER}) {
1475 0 _croak "Cannot rewind: no file or input buffer associated with this object";
1476 }
1477 6 $self->{CURRENT_MESSAGE} = 0;
1478 6 $self->{CURRENT_SUBSET} = 0;
1479 6 delete $self->{START_POS};
1480 6 delete $self->{POS};
1481 6 delete $self->{EOF};
1482 6 return 1;
1483 }
1484  
1485 ## Read in next BUFR message from file if $self->{FILEHANDLE} is set,
1486 ## else from $self->{IN_BUFFER} (string argument to
1487 ## constructor). Decodes section 0 and sets $self->{START_POS} to
1488 ## start of message and $self->{POS} to end of BUFR message (or after
1489 ## first 8 bytes of truncated/corrupt BUFR message for which we still
1490 ## want to attempt decoding). $self->{CURRENT_AHL} is updated if a GTS
1491 ## ahl is found (implemented for file reading only) and similarly for
1492 ## $self->{CURRENT_GTS_STARTING_LINE}, and $self->{EOF} is set if no
1493 ## more 'BUFR' in file/buffer. Croaks if an error occurs when reading
1494 ## BUFR message.
1495  
1496 ## Returns BUFR message from section 1 on, or undef if no BUFR message
1497 ## is found.
1498 sub _read_message {
1499 199 ▶ my $self = shift;
Subroutine _read_message: called CC=27 SCAR=33.6
1500  
1501 199 ▶ my $filehandle = $self->{FILEHANDLE} ? $self->{FILEHANDLE} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'FILEHANDLE'} ? : 185 14 199
1502 199 ▶ my $in_buffer = $self->{IN_BUFFER} ? $self->{IN_BUFFER} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'IN_BUFFER'} ? : 14 185 199
1503 199 ▶ _croak "_read_message: Neither BUFR file nor BUFR text is given"
Branch: 1 branch
BranchTrueFalseTotal
unless $filehandle or $in_buffer 0 199 199
Condition66%2/3
$filehandle or $in_buffer
l!l&&r!l&&!r
185140
MC/DC0%0/2
$filehandle or $in_buffer
$filehandle $in_buffer
Truth table66%2/3
A or B
A= $filehandleB= $in_buffer
ABresult
1X1
011
000
1504 unless $filehandle or $in_buffer;
1505  
1506 # Locate next 'BUFR' and set $pos to this position in file/string,
1507 # also finding corresponding GTS ahl and starting line if exists
1508 # (for file only). Possibly sets $self->{EOF}
1509 199 ▶ my $pos = defined $self->{POS} ? $self->{POS} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'POS'} ? : 152 47 199
1510 199 my ($ahl, $gts_start);
1511 199 ($pos, $ahl, $gts_start) = $self->_find_next_BUFR($filehandle, $in_buffer, $pos, '');
1512 199 ▶ return if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 43 156 199
1513 156 ▶ if ($ahl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ahl) { } 99 57 156
1514 99 $self->{CURRENT_AHL} = $ahl;
1515 99 ▶ if ($gts_start) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gts_start) 60 39 99
1516 60 $self->{CURRENT_GTS_STARTING_LINE} = $gts_start;
1517 60 $self->{GTS_CURRENT_EOM} = undef;
1518 }
1519 } else {
1520 57 $self->{CURRENT_AHL} = undef;
1521 57 $self->{CURRENT_GTS_STARTING_LINE} = undef;
1522 }
1523  
1524 # Remember start position of BUFR message in case we need to
1525 # rewind later because length of BUFR cannot be trusted
1526 156 $self->{START_POS} = $pos;
1527  
1528 # Report (if verbose setting) where we found the BUFR message
1529 156 ▶ $self->_spew(2, "BUFR message at position %d", $pos) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 154 156
1530  
1531 # Read (rest) of Section 0 (length of BUFR message and edition number)
1532 156 my $sec0; # Section 0 is BUFR$sec0
1533 156 ▶ if ($filehandle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle) { } 144 12 156
1534 144 ▶ if ((read $filehandle, $sec0, 8) != 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($filehandle, $sec0, 8) != 8) 0 144 144
1535 0 $self->{EOF} = 1;
1536 0 _croak "Error reading section 0 in file '$self->{FILENAME}', position "
1537 . tell($filehandle);
1538 }
1539 144 $sec0 = substr $sec0, 4;
1540 } else {
1541 12 ▶ if (length($in_buffer) < $pos+8) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $in_buffer < $pos + 8) 0 12 12
1542 0 $self->{EOF} = 1;
1543 0 _croak "Error reading section 0: this is not a BUFR message?"
1544 }
1545 12 $sec0 = substr $in_buffer, $pos+4, 4;
1546 }
1547 156 $self->{SEC0_STREAM} = "BUFR$sec0";
1548  
1549 # Extract length and edition number
1550 156 my ($length, $edition) = unpack 'NC', "\0$sec0";
1551 156 $self->{BUFR_LENGTH} = $length;
1552 156 $self->{BUFR_EDITION} = $edition;
1553 156 ▶ $self->_spew(2, "Message length: %d, Edition: %d", $length, $edition) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 154 156
1554 156 ▶ _croak "Cannot handle BUFR edition $edition" if $edition < 2 || $edition > 4;
Branch: 1 branch
BranchTrueFalseTotal
if $edition < 2 or $edition > 4 1 155 156
Condition66%2/3
$edition < 2 or $edition > 4
l!l&&r!l&&!r
01155
MC/DC50%1/2
$edition < 2 or $edition > 4
$edition < 2 $edition > 4
Truth table66%2/3
A or B
A= $edition < 2B= $edition > 4
ABresult
1X1
011
000
1555  
1556 # Read rest of BUFR message (section 1-5)
1557 155 my $msg;
1558 155 my $msgisOK = 1;
1559 155 ▶ if ($filehandle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle) { } 143 12 155
1560 143 ▶ if ((read $filehandle, $msg, $length-8) != $length-8) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($filehandle, $msg, $length - 8) != $length - 8) { } 1 142 143
1561 # Probably a corrupt or truncated BUFR message. We choose
1562 # to decode as much as possible (maybe the length in
1563 # section 0 is all that is wrong), but obviously we cannot
1564 # trust the stated length of BUFR message, so reset
1565 # position of filehandle to just after section 0
1566 1 $self->{BAD_LENGTH} = 1;
1567 1 $msgisOK = 0;
1568 1 seek $filehandle, $pos+8, 0;
1569 _complain("File %s not big enough to contain the stated"
1570 1 . "length of BUFR message", $self->{FILENAME});
1571 1 $pos += 8;
1572 } else {
1573 142 $pos = tell($filehandle);
1574 142 ▶ if (substr($msg, -4) ne '7777') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($msg, -4) ne 7777) 36 106 142
1575 36 $self->{BAD_LENGTH} = 1;
1576 36 _complain("BUFR length in sec 0 can't be correct, "
1577 . "last 4 bytes are not '7777'");
1578 }
1579 }
1580 } else {
1581 12 ▶ if (length($in_buffer) < $pos+$length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $in_buffer < $pos + $length) { } 0 12 12
1582 0 $self->{BAD_LENGTH} = 1;
1583 0 $msgisOK = 0;
1584 0 _complain("Buffer not big enough to contain the stated "
1585 . "length of BUFR message");
1586 0 $msg = substr $in_buffer, $pos+8, $length-8;
1587 0 $pos += 8;
1588 } else {
1589 12 $msg = substr $in_buffer, $pos+8, $length-8;
1590 12 $pos += $length;
1591 12 ▶ if (substr($msg, -4) ne '7777') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($msg, -4) ne 7777) 3 9 12
1592 3 $self->{BAD_LENGTH} = 1;
1593 3 _complain("BUFR length in sec 0 can't be correct, "
1594 . "last 4 bytes are not '7777'");
1595 }
1596 }
1597 }
1598 155 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 2 153 155
1599 2 ▶ if ($msgisOK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msgisOK) { } 2 0 2
1600 2 $self->_spew(2, "Successfully read BUFR message; position now %d", $pos);
1601 } else {
1602 0 $self->_spew(2, "Resetting position to %d", $pos);
1603 }
1604 }
1605  
1606 # Reset $self->{POS} to end of BUFR message (or after first 8
1607 # bytes of truncated/corrupt BUFR message)
1608 155 $self->{POS} = $pos;
1609  
1610 # And then advance past GTS end of message if found
1611 155 my $gts_eom;
1612 155 ▶ if ($filehandle && ! $self->{BAD_LENGTH}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle and not $self->{"BAD_LENGTH"}) 106 49 155
Condition100%3/3
$filehandle and not $self->{"BAD_LENGTH"}
!ll&&!rl&&r
1237106
MC/DC100%2/2
$filehandle and not $self->{"BAD_LENGTH"}
$filehandle not $self->{"BAD_LENGTH"}
Truth table100%3/3
A and not(B)
A= $filehandleB= not $self->{"BAD_LENGTH"}
ABresult
0X0
100
111
1613 106 ▶ if ((read $filehandle, $gts_eom, 4) == 4 && $gts_eom eq "\r\r\n\003") {
Branch: 1 branch
BranchTrueFalseTotal
if (read($filehandle, $gts_eom, 4) == 4 and $gts_eom eq "\r\r\n\cC") { } 33 73 106
Condition100%3/3
read($filehandle, $gts_eom, 4) == 4 and $gts_eom eq "\r\r\n\3"
!ll&&!rl&&r
274633
MC/DC100%2/2
read($filehandle, $gts_eom, 4) == 4 and $gts_eom eq "\r\r\n\3"
read($filehandle, $gts_eom, 4) == 4 $gts_eom eq "\r\r\n\3"
Truth table100%3/3
A and B
A= read($filehandle, $gts_eom, 4) == 4B= $gts_eom eq "\r\r\n\3"
ABresult
0X0
100
111
1614 33 $self->{CURRENT_GTS_EOM} = $gts_eom;
1615 33 $self->{POS} +=4;
1616 } else {
1617 # return to end of message position
1618 73 seek $filehandle, $pos, 0;
1619 }
1620 }
1621  
1622 155 return $msg;
1623 }
1624  
1625 # Note that our definition av AHL and GTS starting line differs
1626 # slightly from that of the Manual on the GTS PART II. OPERATIONAL
1627 # PROCEDURES FOR THE GLOBAL TELECOMMUNICATION SYSTEM (2.3.1 and 2.3.2)
1628 # in that the Abbreviated heading in the Manual starts with \r\r\n
1629 # which we have chosen to consider belonging to (the end of) the GTS
1630 # starting line.
1631  
1632 79 my $gts_start_regexp = qr{\001\r\r\n\d{3,5}\r\r\n};
1633 # Allow both 3 and 5 digits channel sequence number
1634  
1635 79 my $ahl_regex = qr{[A-Z]{4}\d\d [A-Z]{4} \d{6}(?: (?:(?:RR|CC|AA|PA)[A-Z])| COR| RTD)?};
1636 # BBB=Pxx (segmentation) was allowed until 2007, but at least one
1637 # centre still uses PAA as of 2014. COR and RTD shouldn't be
1638 # allowed (from ?), but are still used
1639  
1640 ## Advance to first occurrence of 'BUFR', or to the possibly preceding
1641 ## GTS envelope if this is requested in $at. Returns the new position
1642 ## and (if called in array context) the possibly preceding ahl and gts
1643 ## starting line. If no 'BUFR' is found, sets $self->{EOF} and returns
1644 ## -1 for the new position.
1645 sub _find_next_BUFR {
1646 213 ▶ my $self = shift;
Subroutine _find_next_BUFR: called CC=20 SCAR=31.6
1647 213 my ($filehandle, $in_buffer, $pos, $at) = @_;
1648  
1649 213 my ($new_pos, $ahl, $gts_start);
1650 213 ▶ if ($filehandle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle) { } 199 14 213
1651 199 my $oldeol = $/;
1652 199 $/ = "BUFR";
1653 199 ▶ my $slurp = <$filehandle> || ' ';
Condition100%2/2
readline $filehandle || ' '
l!l
16237
MC/DC100%1/1
readline $filehandle || ' '
readline $filehandle
Truth table100%2/2
A
A= readline $filehandle
Aresult
11
00
1654 199 $/ = $oldeol;
1655 199 ▶ if (CORE::eof($filehandle) or substr($slurp,-4) ne 'BUFR') {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::eof $filehandle or substr($slurp, -4) ne 'BUFR') { } 41 158 199
Condition66%2/3
CORE::eof $filehandle or substr($slurp, -4) ne "BUFR"
l!l&&r!l&&!r
410158
MC/DC50%1/2
CORE::eof $filehandle or substr($slurp, -4) ne "BUFR"
CORE::eof $filehandle substr($slurp, -4) ne "BUFR"
Truth table66%2/3
A or B
A= CORE::eof $filehandleB= substr($slurp, -4) ne "BUFR"
ABresult
1X1
011
000
1656 41 $self->{EOF} = 1;
1657 } else {
1658 # Get the GTS ahl (TTAAii CCCC DTG [BBB]) before 'BUFR',
1659 # if present. Use '\n+' not '\n' since adding an extra
1660 # '\n' in bulletin has been seen. Allow also for not
1661 # including \r\r (which might be how the bulletin file was
1662 # prepared originally, or might catch cases where ahl is
1663 # mistakingly included twice)
1664 158 my $reset = 4;
1665 158 ▶ if ($slurp =~ /(${gts_start_regexp}?)(${ahl_regex})((?:\r\r)?\n+BUFR)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slurp =~ /($gts_start_regexp?)($ahl_regex)((?:\r\r)?\n+BUFR)$/) 102 56 158
1666 102 ▶ $gts_start = $1 || '';
Condition100%2/2
$1 || ''
l!l
5646
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
1667 102 $ahl = $2;
1668 102 ▶ $reset = length($gts_start) + length($2) + length($3) if $at eq 'at_ahl';
Branch: 1 branch
BranchTrueFalseTotal
if $at eq "at_ahl" 9 93 102
1669  
1670 102 ▶ $self->_spew(2,"GTS ahl found: %s%s", $gts_start, $ahl) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 102 102
1671 }
1672 # Reset position of filehandle to just before 'BUFR', or
1673 # if requested, before possible preceding AHL
1674 158 seek($filehandle, -$reset, 1);
1675 158 $new_pos = tell $filehandle;
1676 }
1677 } else {
1678 14 $new_pos = index($in_buffer, 'BUFR', $pos);
1679 14 ▶ if ($new_pos < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_pos < 0) { } 2 12 14
1680 2 $self->{EOF} = 1;
1681 } else {
1682 12 ▶ if (substr($in_buffer, $pos, $new_pos - $pos)
Branch: 1 branch
BranchTrueFalseTotal
if (substr($in_buffer, $pos, $new_pos - $pos) =~ /($gts_start_regexp?)($ahl_regex)((?:\r\r)?\n+)$/) 6 6 12
1683 =~ /(${gts_start_regexp}?)(${ahl_regex})((?:\r\r)?\n+)$/) {
1684 6 ▶ $gts_start = $1 || '';
Condition100%2/2
$1 || ''
l!l
51
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
Aresult
11
00
1685 6 $ahl = $2;
1686 6 ▶ $self->_spew(2,"GTS ahl found: %s%s", $gts_start, $ahl) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 6 6
1687 6 ▶ if ($at eq 'at_ahl') {
Branch: 1 branch
BranchTrueFalseTotal
if ($at eq "at_ahl") 0 6 6
1688 0 $new_pos -= length($gts_start) + length($2) + length($3);
1689 }
1690 }
1691 }
1692 }
1693  
1694 213 ▶ if ($self->{EOF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"EOF"}) 43 170 213
1695 43 ▶ if ($pos == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos == 0) 0 43 43
1696 0 ▶ if ($filehandle) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filehandle) { } 0 0 0
1697 $self->_spew(2,"No BUFR message in file %s", $self->{FILENAME})
1698 0 ▶ if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
1699 } else {
1700 0 ▶ $self->_spew(2, "No BUFR message found") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
1701 }
1702 }
1703 43 return -1;
1704 }
1705  
1706 170 ▶ return wantarray ? ($new_pos, $ahl, $gts_start) : $new_pos;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 156 14 170
1707 }
1708  
1709 ## Returns the BUFR message in raw (binary) form, '' if errors encountered
1710 sub get_bufr_message {
1711 26 ▶ my $self = shift;
Subroutine get_bufr_message: called CC=9 SCAR=25.9
Pod undocumented
1712  
1713 26 ▶ if ($self->{BAD_LENGTH} || $self->{ERROR_IN_MESSAGE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BAD_LENGTH"} or $self->{"ERROR_IN_MESSAGE"}) 0 26 26
Condition33%1/3
$self->{"BAD_LENGTH"} or $self->{"ERROR_IN_MESSAGE"}
l!l&&r!l&&!r
0026
MC/DC0%0/2
$self->{"BAD_LENGTH"} or $self->{"ERROR_IN_MESSAGE"}
$self->{"BAD_LENGTH"} $self->{"ERROR_IN_MESSAGE"}
Truth table33%1/3
A or B
A= $self->{"BAD_LENGTH"}B= $self->{"ERROR_IN_MESSAGE"}
ABresult
1X1
011
000
1714 0 $self->_spew(2, "Skipping erroneous BUFR message");
1715 0 return '';
1716 }
1717 26 ▶ if (!$self->{FILEHANDLE} && !$self->{IN_BUFFER}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"FILEHANDLE"} or $self->{"IN_BUFFER"}) 0 26 26
Condition66%2/3
$self->{"FILEHANDLE"} or $self->{"IN_BUFFER"}
l!l&&r!l&&!r
2150
MC/DC0%0/2
$self->{"FILEHANDLE"} or $self->{"IN_BUFFER"}
$self->{"FILEHANDLE"} $self->{"IN_BUFFER"}
Truth table66%2/3
A or B
A= $self->{"FILEHANDLE"}B= $self->{"IN_BUFFER"}
ABresult
1X1
011
000
1718 0 $self->_spew(2, "No file or input buffer associated with this object");
1719 0 return '';
1720 }
1721 26 ▶ if (!exists $self->{START_POS} || !$self->{BUFR_LENGTH}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"START_POS"} and $self->{"BUFR_LENGTH"}) 0 26 26
Condition33%1/3
exists $self->{"START_POS"} and $self->{"BUFR_LENGTH"}
!ll&&!rl&&r
0026
MC/DC0%0/2
exists $self->{"START_POS"} and $self->{"BUFR_LENGTH"}
exists $self->{"START_POS"} $self->{"BUFR_LENGTH"}
Truth table33%1/3
A and B
A= exists $self->{"START_POS"}B= $self->{"BUFR_LENGTH"}
ABresult
0X0
100
111
1722 0 $self->_spew(2, "No bufr message to return");
1723 0 return '';
1724 }
1725  
1726 26 my $msg;
1727 26 ▶ if (exists $self->{FILEHANDLE}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'FILEHANDLE'}) { } 21 5 26
elsif (exists $self->{'IN_BUFFER'}) { } 5 0 5
1728 21 my $fh = $self->{FILEHANDLE};
1729 21 my $old_pos = tell($fh);
1730 21 seek($fh, $self->{START_POS}, 0);
1731 21 read($fh, $msg, $self->{BUFR_LENGTH});
1732 21 seek($fh, $old_pos, 0);
1733 21 $self->_spew(2, "BUFR message extracted from file");
1734 } elsif (exists $self->{IN_BUFFER}) {
1735 5 $msg = substr $self->{IN_BUFFER}, $self->{START_POS}, $self->{BUFR_LENGTH};
1736 5 $self->_spew(2, "BUFR message extracted");
1737 }
1738  
1739 26 return $msg;
1740 }
1741  
1742 ## Decode section 1 to 5. Section 0 is already decoded in _read_message.
1743 sub _decode_sections {
1744 155 ▶ my $self = shift;
Subroutine _decode_sections: called CC=47 SCAR=41.1
1745 155 my $msg = shift;
1746  
1747 155 $self->{BUFR_STREAM} = $msg;
1748 155 $self->{SEC1_STREAM} = undef;
1749 155 $self->{SEC2_STREAM} = undef;
1750 155 $self->{SEC3_STREAM} = undef;
1751 155 $self->{SEC4_STREAM} = undef;
1752 155 $self->{SEC5_STREAM} = undef;
1753  
1754 # Breaking the rule that all debugging should be on lines starting
1755 # with 'BUFR.pm:', therefore using $verbose=6
1756 155 ▶ $self->_spew(6, "%s", $self->dumpsection0()) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1757  
1758 ## Decode Section 1 (Identification Section) ##
1759  
1760 155 ▶ $self->_spew(2, "Decoding section 1") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1761  
1762 # Extract Section 1 information
1763 155 ▶ if ($self->{BUFR_EDITION} < 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'BUFR_EDITION'} < 4) { } 38 117 155
elsif ($self->{'BUFR_EDITION'} == 4) { } 117 0 117
1764 # N means 4 byte integer, so put an extra null byte ('\0') in
1765 # front of string to get first 3 bytes as integer
1766 38 my @sec1 = unpack 'NC14', "\0" . $self->{BUFR_STREAM};
1767  
1768 # Check that stated length of section 1 makes sense
1769 38 ▶ _croak "Length of section 1 too small (< 17): $sec1[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $sec1[0] < 17 0 38 38
1770 if $sec1[0] < 17;
1771 _croak "Rest of BUFR message shorter (" . length($self->{BUFR_STREAM})
1772 . " bytes) than stated length of section 1 ($sec1[0] bytes)"
1773 38 ▶ if $sec1[0] > length($self->{BUFR_STREAM});
Branch: 1 branch
BranchTrueFalseTotal
if $sec1[0] > length $self->{"BUFR_STREAM"} 0 38 38
1774  
1775 38 push @sec1, (unpack 'a*', substr $self->{BUFR_STREAM},17,$sec1[0]-17);
1776 38 $self->{SEC1_STREAM} = substr $self->{BUFR_STREAM}, 0, $sec1[0];
1777 38 $self->{BUFR_STREAM} = substr $self->{BUFR_STREAM}, $sec1[0];
1778 38 $self->{SEC1} = \@sec1;
1779 38 $self->{MASTER_TABLE} = $sec1[1];
1780 38 $self->{SUBCENTRE} = $sec1[2];
1781 38 $self->{CENTRE} = $sec1[3];
1782 38 $self->{UPDATE_NUMBER} = $sec1[4];
1783 38 $self->{OPTIONAL_SECTION} = vec($sec1[5] & 0x80,0,1); # 1. bit
1784 38 $self->{DATA_CATEGORY} = $sec1[6];
1785 38 $self->{DATA_SUBCATEGORY} = $sec1[7];
1786 38 $self->{MASTER_TABLE_VERSION} = $sec1[8];
1787 38 $self->{LOCAL_TABLE_VERSION} = $sec1[9];
1788 38 $self->{YEAR_OF_CENTURY} = $sec1[10];
1789 38 $self->{MONTH} = $sec1[11];
1790 38 $self->{DAY} = $sec1[12];
1791 38 $self->{HOUR} = $sec1[13];
1792 38 $self->{MINUTE} = $sec1[14];
1793 38 $self->{LOCAL_USE} = $sec1[15];
1794 # In case previous message was edition 4
1795 38 foreach my $key (qw(INT_DATA_SUBCATEGORY LOC_DATA_SUBCATEGORY
1796 YEAR SECOND)) {
1797 152 undef $self->{$key};
1798 }
1799 } elsif ($self->{BUFR_EDITION} == 4) {
1800 117 my @sec1 = unpack 'NCnnC7nC5', "\0" . $self->{BUFR_STREAM};
1801  
1802 # Check that stated length of section 1 makes sense
1803 117 ▶ _croak "Length of section 1 too small (< 22): $sec1[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $sec1[0] < 22 0 117 117
1804 if $sec1[0] < 22;
1805 _croak "Rest of BUFR message shorter (" . length($self->{BUFR_STREAM})
1806 . " bytes) than stated length of section 1 ($sec1[0] bytes)"
1807 117 ▶ if $sec1[0] > length($self->{BUFR_STREAM});
Branch: 1 branch
BranchTrueFalseTotal
if $sec1[0] > length $self->{"BUFR_STREAM"} 0 117 117
1808  
1809 117 push @sec1, (unpack 'a*', substr $self->{BUFR_STREAM},22,$sec1[0]-22);
1810 117 $self->{SEC1_STREAM} = substr $self->{BUFR_STREAM}, 0, $sec1[0];
1811 117 $self->{BUFR_STREAM} = substr $self->{BUFR_STREAM}, $sec1[0];
1812 117 $self->{SEC1} = \@sec1;
1813 117 $self->{MASTER_TABLE} = $sec1[1];
1814 117 $self->{CENTRE} = $sec1[2];
1815 117 $self->{SUBCENTRE} = $sec1[3];
1816 117 $self->{UPDATE_NUMBER} = $sec1[4];
1817 117 $self->{OPTIONAL_SECTION} = vec($sec1[5] & 0x80,0,1); # 1. bit
1818 117 $self->{DATA_CATEGORY} = $sec1[6];
1819 117 $self->{INT_DATA_SUBCATEGORY} = $sec1[7];
1820 117 $self->{LOC_DATA_SUBCATEGORY} = $sec1[8];
1821 117 $self->{MASTER_TABLE_VERSION} = $sec1[9];
1822 117 $self->{LOCAL_TABLE_VERSION} = $sec1[10];
1823 117 $self->{YEAR} = $sec1[11];
1824 117 $self->{MONTH} = $sec1[12];
1825 117 $self->{DAY} = $sec1[13];
1826 117 $self->{HOUR} = $sec1[14];
1827 117 $self->{MINUTE} = $sec1[15];
1828 117 $self->{SECOND} = $sec1[16];
1829 117 ▶ $self->{LOCAL_USE} = ($sec1[0] > 22) ? $sec1[17] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sec1[0] > 22 ? : 0 117 117
1830 # In case previous message was edition 3 or lower
1831 117 foreach my $key (qw(DATA_SUBCATEGORY YEAR_OF_CENTURY)) {
1832 234 undef $self->{$key};
1833 }
1834 }
1835 $self->_spew(2, "BUFR edition: %d Optional section: %d Update sequence number: %d",
1836 155 ▶ $self->{BUFR_EDITION}, $self->{OPTIONAL_SECTION}, $self->{UPDATE_NUMBER}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1837 155 ▶ $self->_spew(6, "%s", $self->dumpsection1()) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1838  
1839 155 ▶ $self->_validate_datetime() if ($Strict_checking);
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking 21 134 155
1840  
1841 ## Decode Section 2 (Optional Section) if present ##
1842  
1843 155 ▶ $self->_spew(2, "Decoding section 2") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1844  
1845 155 ▶ if ($self->{OPTIONAL_SECTION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'OPTIONAL_SECTION'}) { } 0 155 155
1846 0 my @sec2 = unpack 'N', "\0" . $self->{BUFR_STREAM};
1847  
1848 # Check that stated length of section 2 makes sense
1849 0 ▶ _croak "Length of section 2 too small (< 4): $sec2[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $sec2[0] < 4 0 0 0
1850 if $sec2[0] < 4;
1851 _croak "Rest of BUFR message shorter (" . length($self->{BUFR_STREAM})
1852 . " bytes) than stated length of section 2 ($sec2[0] bytes)"
1853 0 ▶ if $sec2[0] > length($self->{BUFR_STREAM});
Branch: 1 branch
BranchTrueFalseTotal
if $sec2[0] > length $self->{"BUFR_STREAM"} 0 0 0
1854  
1855 0 push @sec2, substr $self->{BUFR_STREAM}, 4, $sec2[0]-4;
1856 0 $self->{SEC2_STREAM} = substr $self->{BUFR_STREAM}, 0, $sec2[0];
1857 0 $self->{BUFR_STREAM} = substr $self->{BUFR_STREAM}, $sec2[0];
1858 0 $self->{SEC2} = \@sec2;
1859 0 ▶ $self->_spew(2, "Length of section 2: %d", $sec2[0]) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
1860 } else {
1861 155 $self->{SEC2} = undef;
1862 155 $self->{SEC2_STREAM} = undef;
1863 }
1864  
1865 ## Decode Section 3 (Data Description Section) ##
1866  
1867 155 ▶ $self->_spew(2, "Decoding section 3") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1868  
1869 155 my @sec3 = unpack 'NCnC', "\0".$self->{BUFR_STREAM};
1870  
1871 # Check that stated length of section 3 makes sense
1872 155 ▶ _croak "Length of section 3 too small (< 8): $sec3[0]"
Branch: 1 branch
BranchTrueFalseTotal
if $sec3[0] < 8 0 155 155
1873 if $sec3[0] < 8;
1874 _croak "Rest of BUFR message shorter (" . length($self->{BUFR_STREAM})
1875 . " bytes) than stated length of section 3 ($sec3[0] bytes)"
1876 155 ▶ if $sec3[0] > length($self->{BUFR_STREAM});
Branch: 1 branch
BranchTrueFalseTotal
if $sec3[0] > length $self->{"BUFR_STREAM"} 0 155 155
1877  
1878 155 push @sec3, substr $self->{BUFR_STREAM},7,($sec3[0]-7)&0x0ffe; # $sec3[0]-7 will be reduced by one if odd integer,
1879 # so will not push last byte if length of sec3 is even,
1880 # which might happen for BUFR edition < 4 (padding byte)
1881 155 $self->{SEC3_STREAM} = substr $self->{BUFR_STREAM}, 0, $sec3[0];
1882 155 $self->{BUFR_STREAM} = substr $self->{BUFR_STREAM}, $sec3[0];
1883  
1884 155 $self->{SEC3} = \@sec3;
1885 155 $self->{NUM_SUBSETS} = $sec3[2];
1886 155 $self->{OBSERVED_DATA} = vec($sec3[3] & 0x80,0,1); # extract 1. bit
1887 155 $self->{COMPRESSED_DATA} = vec($sec3[3] & 0x40,1,1); # extract 2. bit
1888 155 ▶ $self->_spew(2, "Length of section 3: %d", $sec3[0]) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1889 $self->_spew(2, "Number of subsets: %d Observed data: %d Compressed data: %d",
1890 155 ▶ $self->{NUM_SUBSETS}, $self->{OBSERVED_DATA}, $self->{COMPRESSED_DATA}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 153 155
1891 _complain("0 subsets in BUFR message")
1892 155 ▶ if ($Strict_checking and $self->{NUM_SUBSETS} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and $self->{"NUM_SUBSETS"} == 0 0 155 155
Condition66%2/3
$Geo::BUFR::Strict_checking and $self->{"NUM_SUBSETS"} == 0
!ll&&!rl&&r
134210
MC/DC0%0/2
$Geo::BUFR::Strict_checking and $self->{"NUM_SUBSETS"} == 0
$Geo::BUFR::Strict_checking $self->{"NUM_SUBSETS"} == 0
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= $self->{"NUM_SUBSETS"} == 0
ABresult
0X0
100
111
1893 155 ▶ _complain("Bits 3-8 in octet 7 in section 3 are not 0 (octet 7 = $sec3[3])")
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and ($sec3[3] & 63) != 0 0 155 155
Condition66%2/3
$Geo::BUFR::Strict_checking and ($sec3[3] & 63) != 0
!ll&&!rl&&r
134210
MC/DC0%0/2
$Geo::BUFR::Strict_checking and ($sec3[3] & 63) != 0
$Geo::BUFR::Strict_checking ($sec3[3] & 63) != 0
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= ($sec3[3] & 63) != 0
ABresult
0X0
100
111
1894 if ($Strict_checking and ($sec3[3] & 0x3f) != 0);
1895 155 ▶ if ($Spew == 6 || $Nodata) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew == 6 or $Geo::BUFR::Nodata) 67 88 155
Condition66%2/3
$Geo::BUFR::Spew == 6 or $Geo::BUFR::Nodata
l!l&&r!l&&!r
06788
MC/DC50%1/2
$Geo::BUFR::Spew == 6 or $Geo::BUFR::Nodata
$Geo::BUFR::Spew == 6 $Geo::BUFR::Nodata
Truth table66%2/3
A or B
A= $Geo::BUFR::Spew == 6B= $Geo::BUFR::Nodata
ABresult
1X1
011
000
1896 67 my @unexpanded = _int2fxy(unpack 'n*', $self->{SEC3}[4]);
1897 67 ▶ $self->{DESCRIPTORS_UNEXPANDED} = @unexpanded ?
Branch: 1 branch
BranchTrueFalseTotal
@unexpanded ? : 67 0 67
1898 join(' ', @unexpanded) : '';
1899 67 $self->_spew(6, "%s", $self->dumpsection3());
1900 }
1901  
1902 $self->{IS_FILTERED} = defined $self->{FILTER_CB}
1903 155 ▶ ? $self->{FILTER_CB}->(@{$self->{FILTER_ARGS}}) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'FILTER_CB'} ? : 56 99 155
1904 155 ▶ return if $self->{IS_FILTERED} || $Nodata;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"IS_FILTERED"} or $Geo::BUFR::Nodata 86 69 155
Condition100%3/3
$self->{"IS_FILTERED"} or $Geo::BUFR::Nodata
l!l&&r!l&&!r
315569
MC/DC100%2/2
$self->{"IS_FILTERED"} or $Geo::BUFR::Nodata
$self->{"IS_FILTERED"} $Geo::BUFR::Nodata
Truth table100%3/3
A or B
A= $self->{"IS_FILTERED"}B= $Geo::BUFR::Nodata
ABresult
1X1
011
000
1905  
1906 ## Decode Section 4 (Data Section) ##
1907  
1908 69 ▶ $self->_spew(2, "Decoding section 4") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 67 69
1909  
1910 69 my $sec4_len = unpack 'N', "\0$self->{BUFR_STREAM}";
1911 69 ▶ $self->_spew(2, "Length of section 4: %d", $sec4_len) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 67 69
1912  
1913 # Check that stated length of section 4 makes sense
1914 69 ▶ _croak "Length of section 4 too small (< 4): $sec4_len"
Branch: 1 branch
BranchTrueFalseTotal
if $sec4_len < 4 0 69 69
1915 if $sec4_len < 4;
1916 _croak "Rest of BUFR message (" . length($self->{BUFR_STREAM}) . " bytes)"
1917 . " shorter than stated length of section 4 ($sec4_len bytes)."
1918 . " Probably the BUFR message is truncated"
1919 69 ▶ if $sec4_len > length($self->{BUFR_STREAM});
Branch: 1 branch
BranchTrueFalseTotal
if $sec4_len > length $self->{"BUFR_STREAM"} 1 68 69
1920  
1921 68 $self->{SEC4_STREAM} = substr $self->{BUFR_STREAM}, 0, $sec4_len;
1922 68 $self->{SEC4_RAWDATA} = substr $self->{BUFR_STREAM}, 4, $sec4_len-4;
1923 68 $self->{BUFR_STREAM} = substr $self->{BUFR_STREAM}, $sec4_len;
1924  
1925 ## Decode Section 5 (End Section) ##
1926  
1927 68 ▶ $self->_spew(2, "Decoding section 5") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 66 68
1928  
1929 # Next 4 characters should be '7777' and these should be end of
1930 # message, but allow more characters (i.e. length of message in
1931 # section 0 has been set too big) if $Strict_checking not set
1932 68 my $str = $self->{BUFR_STREAM};
1933 68 my $len = length($str);
1934 68 ▶ if ($len > 4
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 4 or $len == 4 and substr($str, 0, 4) ne 7777) 5 63 68
Condition66%4/6
$len > 4 or $len == 4 and substr($str, 0, 4) ne 7777
l!l&&r!l&&!r
0563
$len == 4 and substr($str, 0, 4) ne 7777
!ll&&!rl&&r
0635
MC/DC33%1/3
$len > 4 or $len == 4 and substr($str, 0, 4) ne 7777
$len > 4 $len == 4 substr($str, 0, 4) ne 7777
Truth table50%2/4
A or B and C
A= $len > 4B= $len == 4C= substr($str, 0, 4) ne 7777
ABCresult
1XX1
0111
00X0
0100
1935 || ($len == 4 && substr($str,0,4) ne '7777')) {
1936 my $err_msg = "Section 5 is not '7777' but the $len"
1937 . " characters (in hex): "
1938 5 . join(' ', map {sprintf "0x%02X", $_} unpack('C*', $str));
1939 5 ▶ if ($len > 4 && substr($str,0,4) eq '7777') {
Branch: 2 branches
BranchTrueFalseTotal
if ($len > 4 and substr($str, 0, 4) eq '7777') { } 0 5 5
elsif ($len == 4 and substr($str, 0, 4) ne '7777') { } 5 0 5
Condition33%1/3
$len > 4 and substr($str, 0, 4) eq 7777
!ll&&!rl&&r
500
MC/DC0%0/2
$len > 4 and substr($str, 0, 4) eq 7777
$len > 4 substr($str, 0, 4) eq 7777
Truth table33%1/3
A and B
A= $len > 4B= substr($str, 0, 4) eq 7777
ABresult
0X0
100
111
1940 0 _complain($err_msg);
1941 ▶ } elsif ($len == 4 && substr($str,0,4) ne '7777') {
Condition33%1/3
$len == 4 and substr($str, 0, 4) ne 7777
!ll&&!rl&&r
005
MC/DC0%0/2
$len == 4 and substr($str, 0, 4) ne 7777
$len == 4 substr($str, 0, 4) ne 7777
Truth table33%1/3
A and B
A= $len == 4B= substr($str, 0, 4) ne 7777
ABresult
0X0
100
111
1942 5 _croak($err_msg);
1943 }
1944 }
1945  
1946 63 return;
1947 }
1948  
1949 ## Read next BUFR message and decode. Set $self->{ERROR_IN_MESSAGE} if
1950 ## anything goes seriously wrong, so that sub next_observation can use
1951 ## this to skip to next message if user chooses to trap the call to
1952 ## next_observation in an eval and then calls next_observation again.
1953 sub _next_message {
1954 199 ▶ my $self = shift;
Subroutine _next_message: called CC=18 SCAR=29.0
1955  
1956 199 ▶ $self->_spew(2, "Reading next BUFR message") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 4 195 199
1957  
1958 199 $self->{ERROR_IN_MESSAGE} = 0;
1959 199 $self->{BAD_LENGTH} = 0;
1960  
1961 199 my $msg;
1962 199 eval {
1963 # Read BUFR message and decode section 0 (needed to get length
1964 # of message)
1965 199 $msg = $self->_read_message();
1966  
1967 # Unpack section 1-5
1968 198 ▶ $self->_decode_sections($msg) if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 155 43 198
1969 };
1970 199 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 192 199
1971 7 $self->{ERROR_IN_MESSAGE} = 1;
1972 7 $self->{CURRENT_MESSAGE}++;
1973 7 die $@; # Could use croak, but then 2 "at ... line ..." will
1974 # be printed to STDERR
1975 }
1976 192 ▶ if (!$msg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($msg) 43 149 192
1977 # Nothing to decode. $self->{EOF} should have been set
1978 43 ▶ $self->_spew(2, "No more BUFR messages found") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 41 43
1979 43 return;
1980 }
1981  
1982 149 $self->{CURRENT_MESSAGE}++;
1983  
1984 149 ▶ return if $Nodata || $self->{IS_FILTERED};
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Nodata or $self->{"IS_FILTERED"} 86 63 149
Condition100%3/3
$Geo::BUFR::Nodata or $self->{"IS_FILTERED"}
l!l&&r!l&&!r
671963
MC/DC100%2/2
$Geo::BUFR::Nodata or $self->{"IS_FILTERED"}
$Geo::BUFR::Nodata $self->{"IS_FILTERED"}
Truth table100%3/3
A or B
A= $Geo::BUFR::NodataB= $self->{"IS_FILTERED"}
ABresult
1X1
011
000
1985  
1986 # Load the relevant code tables
1987 63 my $table_version;
1988 63 eval { $table_version = $self->load_BDtables() };
1989 63 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 63 63
1990 0 $self->{ERROR_IN_MESSAGE} = 1;
1991 0 die $@;
1992 }
1993  
1994 # Get the data descriptors and expand them
1995 63 my @unexpanded = _int2fxy(unpack 'n*', $self->{SEC3}[4]);
1996 63 ▶ _croak "No data description in section 3" if !defined $unexpanded[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $unexpanded[0] 0 63 63
1997 # Using master table because local tables couldn't be found is
1998 # risky, so catch missing descriptors here to be able to give
1999 # informative error messages
2000 63 ▶ $self->_check_descriptors(\@unexpanded) if $self->{LOCAL_TABLES_NOT_FOUND};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOCAL_TABLES_NOT_FOUND"} 4 59 63
2001 63 $self->{DESCRIPTORS_UNEXPANDED} = join ' ', @unexpanded;
2002 63 ▶ $self->_spew(2, "Unexpanded data descriptors: %s", $self->{DESCRIPTORS_UNEXPANDED}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 61 63
2003  
2004 63 ▶ $self->_spew(2, "Expanding data descriptors") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 61 63
2005 63 my $alias = "$table_version " . $self->{DESCRIPTORS_UNEXPANDED};
2006 63 ▶ if (exists $Descriptors_already_expanded{$alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Geo::BUFR::Descriptors_already_expanded{$alias}) { } 24 39 63
2007 24 $self->{DESCRIPTORS_EXPANDED} = $Descriptors_already_expanded{$alias};
2008 } else {
2009 39 eval {
2010 $Descriptors_already_expanded{$alias} = $self->{DESCRIPTORS_EXPANDED}
2011 39 = join " ", _expand_descriptors($self->{D_TABLE}, @unexpanded);
2012 };
2013 39 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 39 39
2014 0 $self->{ERROR_IN_MESSAGE} = 1;
2015 0 die $@;
2016 }
2017 }
2018  
2019 # Unpack data from bitstream
2020 63 ▶ $self->_spew(2, "Unpacking data") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 61 63
2021 63 eval {
2022 63 ▶ if ($self->{COMPRESSED_DATA}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'COMPRESSED_DATA'}) { } 23 40 63
2023 23 $self->_decompress_bitstream();
2024 } else {
2025 40 $self->_decode_bitstream();
2026 }
2027 };
2028 63 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 7 56 63
2029 7 $self->{ERROR_IN_MESSAGE} = 1;
2030 7 die $@;
2031 }
2032  
2033 56 return;
2034 }
2035  
2036 ## Check if all element and sequence descriptors given are found in
2037 ## B/D-tables (but skip check for those preceded by 206-operator)
2038 sub _check_descriptors {
2039 4 ▶ my ($self,$unexpanded) = @_;
Subroutine _check_descriptors: called CC=9 SCAR=25.9
2040  
2041 4 my $B_table = $self->{B_TABLE};
2042 4 my $D_table = $self->{D_TABLE};
2043 4 my $skip_next = 0;
2044 4 foreach my $id (@{$unexpanded}) {
2045 # Skip descriptors preceded by 206-operator
2046 30 ▶ if ($skip_next) {
Branch: 3 branches
BranchTrueFalseTotal
if ($skip_next) { } 2 28 30
elsif (substr($id, 0, 3) eq '206') { } 2 26 28
elsif (substr($id, 0, 1) eq '0' and not exists $B_table->{$id} or substr($id, 0, 1) eq '3' and not exists $D_table->{$id}) { } 0 41 41
2047 2 $skip_next = 0;
2048 } elsif (substr($id,0,3) eq '206') {
2049 2 $skip_next = 1;
2050 ▶ } elsif ( (substr($id,0,1) eq '0' && ! exists $B_table->{$id})
Condition55%5/9
substr($id, 0, 1) eq 0 and not exists $B_table->{$id} or substr($id, 0, 1) eq 3 and not exists $D_table->{$id}
l!l&&r!l&&!r
0026
substr($id, 0, 1) eq 0 and not exists $B_table->{$id}
!ll&&!rl&&r
14120
substr($id, 0, 1) eq 3 and not exists $D_table->{$id}
!ll&&!rl&&r
15110
MC/DC0%0/4
substr($id, 0, 1) eq 0 and not exists $B_table->{$id} or substr($id, 0, 1) eq 3 and not exists $D_table->{$id}
substr($id, 0, 1) eq 0 not exists $B_table->{$id} substr($id, 0, 1) eq 3 not exists $D_table->{$id}
Truth table42%3/7
A and not(B) or C and not(D)
A= substr($id, 0, 1) eq 0B= not exists $B_table->{$id}C= substr($id, 0, 1) eq 3D= not exists $D_table->{$id}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
2051 || (substr($id,0,1) eq '3' && ! exists $D_table->{$id}) ) {
2052 my $version = ($BUFR_table{FORMAT} eq 'BUFRDC')
2053 ? substr($self->{LOCAL_TABLES_NOT_FOUND},1,-4)
2054 0 ▶ : $self->{LOCAL_TABLES_NOT_FOUND};
Branch: 1 branch
BranchTrueFalseTotal
$Geo::BUFR::BUFR_table{'FORMAT'} eq 'BUFRDC' ? : 0 0 0
2055 0 undef $BUFR_table{"B$version"};
2056 0 undef $BUFR_table{"D$version"};
2057 0 $self->{ERROR_IN_MESSAGE} = 1;
2058 0 _croak("Data descriptor $id is not in master table."
2059 . " You need to get the local tables B/D$version.TXT");
2060 }
2061 }
2062 4 return;
2063 }
2064  
2065 ## Get next observation, i.e. next subset in current BUFR message or
2066 ## first subset in next message. Returns (reference to) data and
2067 ## descriptors, or empty list if either no observation is found (in
2068 ## which case $self->{EOF} should have been set) or if decoding of
2069 ## section 4 is not requested (in which case all of sections 0-3 have
2070 ## been decoded in next message).
2071 sub next_observation {
2072 234 ▶ my $self = shift;
Subroutine next_observation: called CC=17 SCAR=28.5
Pod undocumented
2073  
2074 234 ▶ $self->_spew(2, "Fetching next observation") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 6 228 234
2075  
2076 # If an error occurred during decoding of previous message, we
2077 # don't know if stated length in section 0 is to be trusted,
2078 # so rewind to next 'BUFR', or setting EOF if no such exists
2079 234 ▶ if ($self->{ERROR_IN_MESSAGE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ERROR_IN_MESSAGE"}) 14 220 234
2080 # First rewind to right after 'BUFR' in previous (faulty)
2081 # message. We cannot go further if file/buffer starts as
2082 # 'BUFRBUFR'
2083 14 my $pos = $self->{START_POS} + 4;
2084 14 ▶ seek($self->{FILEHANDLE}, $pos, 0) if $self->{FILEHANDLE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"FILEHANDLE"} 14 0 14
2085 14 ▶ $self->_spew(2, "Error in processing BUFR message (check STDERR for "
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 14 14
2086 . "details), rewinding to next 'BUFR'") if $Spew;
2087 # Prepare for (a possible) next call to _read_message by
2088 # advancing to next 'BUFR', not skipping a preceding ahl
2089 my $new_pos = $self->_find_next_BUFR($self->{FILEHANDLE},
2090 14 $self->{IN_BUFFER},$pos,'at_ahl');
2091 14 ▶ if ($self->{EOF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'EOF'}) { } 0 14 14
2092 0 ▶ $self->_spew(2, "Last BUFR message (reached end of file)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
2093 0 return;
2094 } else {
2095 14 $self->{POS} = $new_pos;
2096 }
2097 }
2098  
2099 # Read next BUFR message
2100 234 ▶ if ($self->{CURRENT_MESSAGE} == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CURRENT_MESSAGE"} == 0 or $self->{"ERROR_IN_MESSAGE"} or $self->{"CURRENT_SUBSET"} >= $self->{"NUM_SUBSETS"}) 152 35 187
Condition100%6/6
$self->{"CURRENT_MESSAGE"} == 0 or $self->{"ERROR_IN_MESSAGE"} or $self->{"CURRENT_SUBSET"} >= $self->{"NUM_SUBSETS"}
l!l&&r!l&&!r
6113835
$self->{"CURRENT_MESSAGE"} == 0 or $self->{"ERROR_IN_MESSAGE"}
l!l&&r!l&&!r
4714173
MC/DC100%3/3
$self->{"CURRENT_MESSAGE"} == 0 or $self->{"ERROR_IN_MESSAGE"} or $self->{"CURRENT_SUBSET"} >= $self->{"NUM_SUBSETS"}
$self->{"CURRENT_MESSAGE"} == 0 $self->{"ERROR_IN_MESSAGE"} $self->{"CURRENT_SUBSET"} >= $self->{"NUM_SUBSETS"}
Truth table100%4/4
A or B or C
A= $self->{"CURRENT_MESSAGE"} == 0B= $self->{"ERROR_IN_MESSAGE"}C= $self->{"CURRENT_SUBSET"} >= $self->{"NUM_SUBSETS"}
ABCresult
1XX1
01X1
0011
0000
2101 or $self->{ERROR_IN_MESSAGE}
2102 or $self->{CURRENT_SUBSET} >= $self->{NUM_SUBSETS}) {
2103  
2104 199 $self->{CURRENT_SUBSET} = 0;
2105 # The bit maps must be rebuilt for each message
2106 199 undef $self->{BITMAPS};
2107 199 undef $self->{BITMAP_OPERATORS};
2108 199 undef $self->{BITMAP_START};
2109 199 undef $self->{REUSE_BITMAP};
2110 199 $self->{NUM_BITMAPS} = 0;
2111 199 $self->{BACKWARD_DATA_REFERENCE} = 1;
2112 # Some more tidying after decoding of previous message might
2113 # be necessary
2114 199 $self->{NUM_CHANGE_OPERATORS} = 0;
2115 199 undef $self->{CHANGE_WIDTH};
2116 199 undef $self->{CHANGE_CCITTIA5_WIDTH};
2117 199 undef $self->{CHANGE_SCALE};
2118 199 undef $self->{CHANGE_REFERENCE_VALUE};
2119 199 undef $self->{NEW_REFVAL_OF};
2120 199 undef $self->{CHANGE_SRW};
2121 199 undef $self->{ADD_ASSOCIATED_FIELD};
2122 199 undef $self->{LOCAL_TABLES_NOT_FOUND};
2123 199 undef $self->{DATA};
2124 199 undef $self->{DESC};
2125 # Note that we should NOT undef metadata in section 1-3 here,
2126 # since if the next call (_next_message) finds no more
2127 # messages, we don't want to lose the metadata of the last
2128 # valid message extracted. sub join_subsets is based on this
2129 # assumption
2130  
2131 199 $self->_next_message();
2132 185 ▶ return if $self->{EOF};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"EOF"} 43 142 185
2133  
2134 142 ▶ if ($Nodata || $self->{IS_FILTERED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Nodata or $self->{"IS_FILTERED"}) 86 56 142
Condition100%3/3
$Geo::BUFR::Nodata or $self->{"IS_FILTERED"}
l!l&&r!l&&!r
671956
MC/DC100%2/2
$Geo::BUFR::Nodata or $self->{"IS_FILTERED"}
$Geo::BUFR::Nodata $self->{"IS_FILTERED"}
Truth table100%3/3
A or B
A= $Geo::BUFR::NodataB= $self->{"IS_FILTERED"}
ABresult
1X1
011
000
2135 # Make a simple check that section 4 and 5 are complete
2136 86 ▶ if ($self->{BAD_LENGTH}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BAD_LENGTH"}) 34 52 86
2137 # We could have set $self->{ERROR_IN_MESSAGE} here and
2138 # let next_observation() take care of the rewinding.
2139 # But we don't want error messages to be displayed if
2140 # e.g. message is to be filtered
2141 34 $self->{POS} = $self->{START_POS} + 4;
2142 34 ▶ seek($self->{FILEHANDLE}, $self->{POS}, 0) if $self->{FILEHANDLE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"FILEHANDLE"} 31 3 34
2143 $self->_spew(2, "Possibly truncated message found (last 4 bytes"
2144 . " are not '7777'), so rewinding to position %d",
2145 34 ▶ $self->{POS}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 34 34
2146 }
2147 # This will ensure next call to next_observation to read next message
2148 86 $self->{CURRENT_SUBSET} = $self->{NUM_SUBSETS};
2149 86 return;
2150 }
2151 }
2152  
2153 91 $self->{CURRENT_SUBSET}++;
2154  
2155 # Return references to data and descriptor arrays
2156 91 ▶ if ($self->{COMPRESSED_DATA}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'COMPRESSED_DATA'}) { } 40 51 91
2157 return ($self->{DATA}[$self->{CURRENT_SUBSET}],
2158 40 $self->{DESC});
2159 } else {
2160 return ($self->{DATA}[$self->{CURRENT_SUBSET}],
2161 51 $self->{DESC}[$self->{CURRENT_SUBSET}]);
2162 }
2163 }
2164  
2165 # Dumping contents of a subset (including section 0, 1 and 3 if this is
2166 # first subset) in a BUFR message, also displaying message number and
2167 # ahl (if found) and subset number
2168 sub dumpsections {
2169 0 ▶ my $self = shift;
Subroutine dumpsections: not called CC=9 SCAR=45.0
Pod undocumented
2170 0 my $data = shift;
2171 0 my $descriptors = shift;
2172 0 ▶ my $options = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
2173  
2174 0 ▶ my $width = $options->{width} || 15;
Condition0%0/2
$options->{'width'} || 15
l!l
00
MC/DC0%0/1
$options->{'width'} || 15
$options->{'width'}
Truth table0%0/2
A
A= $options->{'width'}
Aresult
11
00
2175 0 ▶ my $bitmap = exists $options->{bitmap} ? $options->{bitmap} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{'bitmap'} ? : 0 0 0
2176  
2177 0 my $current_subset_number = $self->get_current_subset_number();
2178 0 my $current_message_number = $self->get_current_message_number();
2179 0 ▶ my $current_ahl = $self->get_current_ahl() || '';
Condition0%0/2
$self->get_current_ahl || ''
l!l
00
MC/DC0%0/1
$self->get_current_ahl || ''
$self->get_current_ahl
Truth table0%0/2
A
A= $self->get_current_ahl
Aresult
11
00
2180  
2181 0 my $txt;
2182 0 ▶ if ($current_subset_number == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_subset_number == 1) 0 0 0
2183 0 $txt = "\nMessage $current_message_number";
2184 0 ▶ $txt .= defined $current_ahl ? " $current_ahl\n" : "\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $current_ahl ? : 0 0 0
2185 0 $txt .= $self->dumpsection0() . $self->dumpsection1() . $self->dumpsection3();
2186 }
2187  
2188 # If this is last message and there is a BUFR formatting error
2189 # caught by user with eval, we might end up here with current
2190 # subset number 0 (and no section 4 to dump)
2191 0 ▶ if ($current_subset_number > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_subset_number > 0) 0 0 0
2192 0 $txt .= "\nSubset $current_subset_number\n";
2193 0 ▶ $txt .= $bitmap ? $self->dumpsection4_with_bitmaps($data,$descriptors,
Branch: 1 branch
BranchTrueFalseTotal
$bitmap ? : 0 0 0
2194 $current_subset_number,$width)
2195 : $self->dumpsection4($data,$descriptors,$width);
2196 }
2197  
2198 0 return $txt;
2199 }
2200  
2201 sub dumpsection0 {
2202 46 ▶ my $self = shift;
Subroutine dumpsection0: called CC=2 SCAR=7.0
Pod undocumented
2203 _croak "BUFR object not properly initialized to call dumpsection0. "
2204 46 ▶ . "Did you forget to call next_observation()?" unless $self->{BUFR_LENGTH};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"BUFR_LENGTH"} 0 46 46
2205  
2206 46 my $txt = <<"EOT";
2207  
2208 Section 0:
2209 Length of BUFR message: $self->{BUFR_LENGTH}
2210 BUFR edition: $self->{BUFR_EDITION}
2211 EOT
2212 46 return $txt;
2213 }
2214  
2215 sub dumpsection1 {
2216 46 ▶ my $self = shift;
Subroutine dumpsection1: called CC=5 SCAR=16.5
Pod undocumented
2217 _croak "BUFR object not properly initialized to call dumpsection1. "
2218 46 ▶ . "Did you forget to call next_observation()?" unless $self->{SEC1_STREAM};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"SEC1_STREAM"} 0 46 46
2219  
2220 46 my $txt;
2221 46 ▶ if ($self->{BUFR_EDITION} < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'BUFR_EDITION'} < 4) { } 28 18 46
2222 28 $txt = <<"EOT";
2223  
2224 Section 1:
2225 28 Length of section: @{[ length $self->{SEC1_STREAM} ]}
2226 BUFR master table: $self->{MASTER_TABLE}
2227 Originating subcentre: $self->{SUBCENTRE}
2228 Originating centre: $self->{CENTRE}
2229 Update sequence number: $self->{UPDATE_NUMBER}
2230 Optional section present: $self->{OPTIONAL_SECTION}
2231 Data category (table A): $self->{DATA_CATEGORY}
2232 Data subcategory: $self->{DATA_SUBCATEGORY}
2233 Master table version number: $self->{MASTER_TABLE_VERSION}
2234 Local table version number: $self->{LOCAL_TABLE_VERSION}
2235 Year of century: $self->{YEAR_OF_CENTURY}
2236 Month: $self->{MONTH}
2237 Day: $self->{DAY}
2238 Hour: $self->{HOUR}
2239 Minute: $self->{MINUTE}
2240 EOT
2241 } else {
2242 18 $txt = <<"EOT";
2243  
2244 Section 1:
2245 18 Length of section: @{[ length $self->{SEC1_STREAM} ]}
2246 BUFR master table: $self->{MASTER_TABLE}
2247 Originating centre: $self->{CENTRE}
2248 Originating subcentre: $self->{SUBCENTRE}
2249 Update sequence number: $self->{UPDATE_NUMBER}
2250 Optional section present: $self->{OPTIONAL_SECTION}
2251 Data category (table A): $self->{DATA_CATEGORY}
2252 International data subcategory: $self->{INT_DATA_SUBCATEGORY}
2253 Local data subcategory: $self->{LOC_DATA_SUBCATEGORY}
2254 Master table version number: $self->{MASTER_TABLE_VERSION}
2255 Local table version number: $self->{LOCAL_TABLE_VERSION}
2256 Year: $self->{YEAR}
2257 Month: $self->{MONTH}
2258 Day: $self->{DAY}
2259 Hour: $self->{HOUR}
2260 Minute: $self->{MINUTE}
2261 Second: $self->{SECOND}
2262 EOT
2263 }
2264 # Last part of section 1: "Reserved for local use by ADP centres"
2265 # is considered so uninteresting (and rare), that it is displayed
2266 # only if verbose >= 2, in a _spew statement. Note that for BUFR
2267 # edition < 4 there is always one byte here (to make an even
2268 # number of bytes in section 1).
2269 0 $self->_spew(2, "Reserved for local use: 0x@{[unpack('H*', $self->{LOCAL_USE})]}")
2270 46 ▶ if $self->{LOCAL_USE} and length $self->{LOCAL_USE} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"LOCAL_USE"} and length $self->{"LOCAL_USE"} > 1 0 46 46
Condition66%2/3
$self->{"LOCAL_USE"} and length $self->{"LOCAL_USE"} > 1
!ll&&!rl&&r
18280
MC/DC0%0/2
$self->{"LOCAL_USE"} and length $self->{"LOCAL_USE"} > 1
$self->{"LOCAL_USE"} length $self->{"LOCAL_USE"} > 1
Truth table66%2/3
A and B
A= $self->{"LOCAL_USE"}B= length $self->{"LOCAL_USE"} > 1
ABresult
0X0
100
111
2271  
2272 46 return $txt;
2273 }
2274  
2275 sub dumpsection2 {
2276 0 ▶ my $self = shift;
Subroutine dumpsection2: not called CC=4 SCAR=30.0
Pod undocumented
2277 0 ▶ return '' if not defined $self->{SEC2};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"SEC2"} 0 0 0
2278  
2279 0 my $sec2_code_ref = shift;
2280 0 ▶ _croak "dumpsection2: no code ref provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sec2_code_ref and ref $sec2_code_ref eq "CODE" 0 0 0
Condition0%0/3
defined $sec2_code_ref and ref $sec2_code_ref eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $sec2_code_ref and ref $sec2_code_ref eq "CODE"
defined $sec2_code_ref ref $sec2_code_ref eq "CODE"
Truth table0%0/3
A and B
A= defined $sec2_code_refB= ref $sec2_code_ref eq "CODE"
ABresult
0X0
100
111
2281 unless defined $sec2_code_ref && ref($sec2_code_ref) eq 'CODE';
2282  
2283 0 my $txt = <<"EOT";
2284  
2285 Section 2:
2286 0 Length of section: @{[ length $self->{SEC2_STREAM} ]}
2287 EOT
2288  
2289 0 return $txt . $sec2_code_ref->($self->{SEC2_STREAM}) . "\n";
2290 }
2291  
2292 sub dumpsection3 {
2293 111 ▶ my $self = shift;
Subroutine dumpsection3: called CC=3 SCAR=11.2
Pod undocumented
2294 _croak "BUFR object not properly initialized to call dumpsection3. "
2295 111 ▶ . "Did you forget to call next_observation()?" unless $self->{SEC3_STREAM};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"SEC3_STREAM"} 0 111 111
2296 111 ▶ $self->{DESCRIPTORS_UNEXPANDED} ||= '';
Condition50%1/2
$self->{"DESCRIPTORS_UNEXPANDED"} ||= ""
l!l
1110
MC/DC0%0/1
$self->{"DESCRIPTORS_UNEXPANDED"} ||= ""
$self->{"DESCRIPTORS_UNEXPANDED"}
Truth table50%1/2
A
A= $self->{"DESCRIPTORS_UNEXPANDED"}
Aresult
11
00
2297  
2298 111 my $txt = <<"EOT";
2299  
2300 Section 3:
2301 111 Length of section: @{[ length $self->{SEC3_STREAM} ]}
2302 Number of data subsets: $self->{NUM_SUBSETS}
2303 Observed data: $self->{OBSERVED_DATA}
2304 Compressed data: $self->{COMPRESSED_DATA}
2305 Data descriptors unexpanded: $self->{DESCRIPTORS_UNEXPANDED}
2306 EOT
2307 111 return $txt;
2308 }
2309  
2310 sub dumpsection4 {
2311 64 ▶ my $self = shift;
Subroutine dumpsection4: called CC=26 SCAR=33.6
Pod undocumented
2312 64 my $data = shift;
2313 64 my $descriptors = shift;
2314 64 ▶ my $width = shift || 15; # Optional argument
Condition50%1/2
shift() || 15
l!l
640
MC/DC0%0/1
shift() || 15
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2315 # Since last (optional) argument to dumpsection() is an anonymous
2316 # hash, check that this is not mistakenly applied here also
2317 64 ▶ _croak "Last optional argument to dumpsection4 should be integer"
Branch: 1 branch
BranchTrueFalseTotal
if ref $width or not $width =~ /^\d+$/ 0 64 64
Condition33%1/3
ref $width or not $width =~ /^\d+$/
l!l&&r!l&&!r
0064
MC/DC0%0/2
ref $width or not $width =~ /^\d+$/
ref $width not $width =~ /^\d+$/
Truth table33%1/3
A or not(B)
A= ref $widthB= not $width =~ /^\d+$/
ABresult
1X1
011
000
2318 if ref($width) || $width !~ /^\d+$/;
2319  
2320 64 my $txt = "\n";
2321 64 my $B_table = $self->{B_TABLE};
2322 # Add the artificial descriptor for associated field
2323 64 $B_table->{999999} = "ASSOCIATED FIELD\0NUMERIC";
2324 64 ▶ my $C_table = $self->{C_TABLE} || '';
Condition100%2/2
$self->{'C_TABLE'} || ''
l!l
559
MC/DC100%1/1
$self->{'C_TABLE'} || ''
$self->{'C_TABLE'}
Truth table100%2/2
A
A= $self->{'C_TABLE'}
Aresult
11
00
2325 64 my $idx = 0;
2326 64 my $line_no = 0; # Precede each line with a line number, except
2327 # for replication descriptors and for operator
2328 # descriptors with no data value in section 4
2329 ID:
2330 64 foreach my $id (@{$descriptors}) {
2331 7341 ▶ my $value = defined $data->[$idx] ? $data->[$idx] : 'missing';
Branch: 1 branch
BranchTrueFalseTotal
defined $data->[$idx] ? : 4397 2944 7341
2332 7341 $idx++;
2333 7341 my $f = substr($id, 0, 1);
2334 7341 ▶ if ($f == 1) {
Branch: 4 branches
BranchTrueFalseTotal
if ($f == 1) { } 16 7325 7341
elsif ($f == 2) { } 149 7176 7325
elsif ($f == 9 and $id != 999999) { } 4 7172 7176
elsif ($id == 31031) { } 439 6733 7172
2335 16 $txt .= sprintf " %6d\n", $id;
2336 16 next ID;
2337 } elsif ($f == 2) {
2338 149 ▶ if ($id =~ /^205/) { # Character information operator
Branch: 1 branch
BranchTrueFalseTotal
if ($id =~ /^205/) { } 0 149 149
2339 0 $txt .= sprintf "%6d %06d %${width}.${width}s %s\n",
2340 ++$line_no, $id, $value, "CHARACTER INFORMATION";
2341 0 next ID;
2342 } else {
2343 149 my $operator_name = _get_operator_name($id);
2344 149 ▶ if ($operator_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator_name) 149 0 149
2345 149 $txt .= sprintf " %06d %${width}.${width}s %s\n",
2346 $id, "", $operator_name;
2347 }
2348 149 next ID;
2349 }
2350 ▶ } elsif ($f == 9 && $id != 999999) {
Condition100%3/3
$f == 9 and $id != 999999
!ll&&!rl&&r
7152204
MC/DC100%2/2
$f == 9 and $id != 999999
$f == 9 $id != 999999
Truth table100%3/3
A and B
A= $f == 9B= $id != 999999
ABresult
0X0
100
111
2351 4 $txt .= sprintf "%6d %06d %${width}.${width}s %s %06d\n",
2352 ++$line_no, $id, $value, 'NEW REFERENCE VALUE FOR', $id - 900000;
2353 4 next ID;
2354 } elsif ($id == 31031) { # This is the only data descriptor
2355 # where all bits set to one should
2356 # not be rendered as missing value
2357 # (for replication/repetition factors in
2358 # class 31 $value has been adjusted already)
2359 439 ▶ $value = 1 if $value eq 'missing';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "missing" 393 46 439
2360 }
2361 _croak "Data descriptor $id is not present in BUFR table B"
2362 7172 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 7172 7172
2363 7172 my ($name, $unit, $bits) = (split /\0/, $B_table->{$id})[0,1,4];
2364 # Code or flag table number equals $id, so no need to display this in [unit]
2365 7172 my $short_unit = $unit;
2366 7172 my $unit_start = uc(substr($unit, 0, 4));
2367 7172 ▶ if ($unit_start eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit_start eq 'CODE') { } 1322 5850 7172
elsif ($unit_start eq 'FLAG') { } 626 5224 5850
2368 1322 $short_unit = 'CODE TABLE';
2369 } elsif ($unit_start eq 'FLAG') {
2370 626 $short_unit = 'FLAG TABLE';
2371 }
2372 7172 $txt .= sprintf "%6d %06d %${width}.${width}s %s\n",
2373 ++$line_no, $id, $value, "$name [$short_unit]";
2374  
2375 # Check for illegal flag value
2376 7172 ▶ if ($Strict_checking && $short_unit eq 'FLAG TABLE' && $bits > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1) 27 7145 7172
Condition83%5/6
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1
!ll&&!rl&&r
7145027
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE"
!ll&&!rl&&r
3692345327
MC/DC66%2/3
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1
$Geo::BUFR::Strict_checking $short_unit eq "FLAG TABLE" $bits > 1
Truth table75%3/4
A and B and C
A= $Geo::BUFR::Strict_checkingB= $short_unit eq "FLAG TABLE"C= $bits > 1
ABCresult
0XX0
10X0
1100
1111
2377 27 ▶ if ($value ne 'missing' && $value % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne "missing" and $value % 2) 0 27 27
Condition33%1/3
$value ne "missing" and $value % 2
!ll&&!rl&&r
2700
MC/DC0%0/2
$value ne "missing" and $value % 2
$value ne "missing" $value % 2
Truth table33%1/3
A and B
A= $value ne "missing"B= $value % 2
ABresult
0X0
100
111
2378 0 $bits += 0; # get rid of spaces
2379 0 my $max_value = 2**$bits - 1;
2380 0 _complain("$id - $value: rightmost bit $bits is set indicating missing value"
2381 . " but then value should be $max_value");
2382 }
2383 }
2384  
2385 # Resolve flag and code table values if code table is loaded
2386 # (but don't bother about 031031 - too much uninformative output)
2387 7172 ▶ if ($C_table && $id != 31031 && $value ne 'missing') {
Branch: 1 branch
BranchTrueFalseTotal
if ($C_table and $id != 31031 and $value ne "missing") 329 6843 7172
Condition100%6/6
$C_table and $id != 31031 and $value ne "missing"
!ll&&!rl&&r
6676167329
$C_table and $id != 31031
!ll&&!rl&&r
66688496
MC/DC100%3/3
$C_table and $id != 31031 and $value ne "missing"
$C_table $id != 31031 $value ne "missing"
Truth table100%4/4
A and B and C
A= $C_tableB= $id != 31031C= $value ne "missing"
ABCresult
0XX0
10X0
1100
1111
2388 329 my $num_spaces = $width + 18;
2389 329 $txt .= _get_code_table_txt($id,$value,$unit,$B_table,$C_table,$num_spaces)
2390 }
2391 }
2392 64 return $txt;
2393 }
2394  
2395 # Operators which should always be displayed in dumpsection4
2396 79 my %OPERATOR_NAME_A =
2397 ( 222000 => 'QUALITY INFORMATION FOLLOW',
2398 223000 => 'SUBSTITUTED VALUES FOLLOW',
2399 224000 => 'FIRST ORDER STATISTICS FOLLOW',
2400 225000 => 'DIFFERENCE STATISTICAL VALUES FOLLOW',
2401 232000 => 'REPLACE/RETAINED VALUES FOLLOW',
2402 235000 => 'CANCEL BACKWARD DATA REFERENCE',
2403 236000 => 'DEFINE DATA PRESENT BIT MAP',
2404 237000 => 'USE PREVIOUSLY DEFINED BIT MAP',
2405 );
2406 # Operators which should normally not be displayed in dumpsection4
2407 79 my %OPERATOR_NAME_B =
2408 ( 201000 => 'CANCEL CHANGE DATA WIDTH',
2409 202000 => 'CANCEL CHANGE SCALE',
2410 203000 => 'CANCEL CHANGE REFERENCE VALUES',
2411 207000 => 'CANCEL INCREASE SCALE, REFERENCE VALUE AND DATA WIDTH',
2412 208000 => 'CANCEL CHANGE WIDTH OF CCITT IA5 FIELD',
2413 203255 => 'STOP CHANGING REFERENCE VALUES',
2414 223255 => 'SUBSTITUTED VALUES MARKER OPERATOR',
2415 224255 => 'FIRST ORDER STATISTICAL VALUES MARKER OPERATOR',
2416 225255 => 'DIFFERENCE STATISTICAL STATISTICAL VALUES MARKER OPERATOR',
2417 232255 => 'REPLACED/RETAINED VALUES MARKER OPERATOR',
2418 237255 => 'CANCEL DEFINED DATA PRESENT BIT MAP',
2419 );
2420 # Operator classes which should normally not be displayed in dumpsection4
2421 79 my %OPERATOR_NAME_C =
2422 ( 201 => 'CHANGE DATA WIDTH',
2423 202 => 'CHANGE SCALE',
2424 203 => 'CHANGE REFERENCE VALUES',
2425 204 => 'ADD ASSOCIATED FIELD',
2426 # This one is displayed, treated specially (and named CHARACTER INFORMATION)
2427 ## 205 => 'SIGNIFY CHARACTER',
2428 206 => 'SIGNIFY DATA WIDTH FOR THE IMMEDIATELY FOLLOWING LOCAL DESCRIPTOR',
2429 207 => 'INCREASE SCALE, REFERENCE VALUE AND DATA WIDTH',
2430 208 => 'CHANGE WIDTH OF CCITT IA5 FIELD',
2431 221 => 'DATA NOT PRESENT',
2432 );
2433 sub _get_operator_name {
2434 149 ▶ my $id = shift;
Subroutine _get_operator_name: called CC=5 SCAR=16.2
2435 149 my $operator_name = '';
2436 149 ▶ if ($OPERATOR_NAME_A{$id}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($OPERATOR_NAME_A{$id}) { } 35 114 149
elsif ($Geo::BUFR::Show_all_operators) { } 114 0 114
2437 35 $operator_name = $OPERATOR_NAME_A{$id}
2438 } elsif ($Show_all_operators) {
2439 114 ▶ if ($OPERATOR_NAME_B{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OPERATOR_NAME_B{$id}) { } 36 78 114
2440 36 $operator_name = $OPERATOR_NAME_B{$id}
2441 } else {
2442 78 my $fx = substr $id, 0, 3;
2443 78 ▶ if ($OPERATOR_NAME_C{$fx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($OPERATOR_NAME_C{$fx}) 78 0 78
2444 78 $operator_name = $OPERATOR_NAME_C{$fx};
2445 }
2446 }
2447 }
2448 149 return $operator_name;
2449 }
2450  
2451 ## Display bit mapped values on same line as the original value. This
2452 ## offer a much shorter and easier to read dump of section 4 when bit
2453 ## maps has been used (i.e. for 222000 quality information, 223000
2454 ## substituted values, 224000 first order statistics, 225000
2455 ## difference statistics, 232000 replaced/retained values). '*******'
2456 ## is displayed if data is not present in bit map (bit set to 1 in
2457 ## 031031 or data not covered by the 031031 descriptors), 'missing' is
2458 ## displayed if value is missing. But note that we miss other
2459 ## descriptors like 001031 and 001032 if these come after 222000 etc
2460 ## with the current implementation. And there are more shortcomings,
2461 ## described in CAVEAT section in POD for bufrread.pl
2462 sub dumpsection4_with_bitmaps {
2463 7 ▶ my $self = shift;
Subroutine dumpsection4_with_bitmaps: called CC=26 SCAR=36.7
Pod undocumented
2464 7 my $data = shift;
2465 7 my $descriptors = shift;
2466 7 my $isub = shift;
2467 7 ▶ my $width = shift || 15; # Optional argument
Condition50%1/2
shift() || 15
l!l
70
MC/DC0%0/1
shift() || 15
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
2468  
2469 # If no bit maps call the ordinary dumpsection4
2470 7 ▶ if (not defined $self->{BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"BITMAPS"}) 0 7 7
2471 0 return $self->dumpsection4($data, $descriptors, $width);
2472 }
2473  
2474 # $Show_all_operators must be turned off for this sub to work correctly
2475 7 ▶ _croak "Cannot dump section 4 properly with bitmaps"
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Show_all_operators 0 7 7
2476 . " when Show_all_operators is set" if $Show_all_operators;
2477  
2478 # The kind of bit maps (i.e. the operator descriptors) used in BUFR message
2479 7 my @bitmap_desc = @{ $self->{BITMAP_OPERATORS} };
2480  
2481 7 my @bitmap_array; # Will contain for each bit map a reference to a hash with
2482 # key: index (in data and descriptor arrays) for data value
2483 # value: index for bit mapped value
2484  
2485 # For compressed data all subsets use same bit map (we assume)
2486 7 ▶ $isub = 0 if $self->{COMPRESSED_DATA};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"COMPRESSED_DATA"} 2 5 7
2487  
2488 7 my $txt = "\n";
2489 7 my $space = ' ';
2490 7 my $line = $space x (17 + $width);
2491 7 foreach my $bitmap_num (0..$#bitmap_desc) {
2492 16 $line .= " $bitmap_desc[$bitmap_num]";
2493 # Convert the sequence of ($data_idesc,$bitmapped_idesc) pairs into a hash
2494 16 my %hash = @{ $self->{BITMAPS}->[$bitmap_num + 1]->[$isub] };
2495 16 $bitmap_array[$bitmap_num] = \%hash;
2496 }
2497 # First make a line showing the operator descriptors using bit maps
2498 7 $txt .= "$line\n";
2499  
2500 7 my $B_table = $self->{B_TABLE};
2501 # Add the artificial descriptor for associated field
2502 7 $B_table->{999999} = "ASSOCIATED FIELD\0Numeric";
2503 7 ▶ my $C_table = $self->{C_TABLE} || '';
Condition50%1/2
$self->{'C_TABLE'} || ''
l!l
07
MC/DC0%0/1
$self->{'C_TABLE'} || ''
$self->{'C_TABLE'}
Truth table50%1/2
A
A= $self->{'C_TABLE'}
Aresult
11
00
2504  
2505 7 my $idx = 0;
2506 # Loop over data descriptors
2507 ID:
2508 7 foreach my $id (@{$descriptors}) {
2509 # Stop printing when the bit map part starts
2510 641 ▶ last ID if (substr($id,0,1) eq '2'
Branch: 1 branch
BranchTrueFalseTotal
if substr($id, 0, 1) eq 2 and $id =~ /^22[2-5]/ || $id =~ /^232/ 7 634 641
Condition50%3/6
substr($id, 0, 1) eq 2 and $id =~ /^22[2-5]/ || $id =~ /^232/
!ll&&!rl&&r
63470
$id =~ /^22[2-5]/ or $id =~ /^232/
l!l&&r!l&&!r
700
MC/DC0%0/3
substr($id, 0, 1) eq 2 and $id =~ /^22[2-5]/ || $id =~ /^232/
substr($id, 0, 1) eq 2 $id =~ /^22[2-5]/ $id =~ /^232/
Truth table25%1/4
A and B or C
A= substr($id, 0, 1) eq 2B= $id =~ /^22[2-5]/C= $id =~ /^232/
ABCresult
0XX0
1000
11X1
1011
2511 and ($id =~ /^22[2-5]/ || $id =~ /^232/));
2512  
2513 # Get the data value
2514 634 ▶ my $value = defined $data->[$idx] ? $data->[$idx] : 'missing';
Branch: 1 branch
BranchTrueFalseTotal
defined $data->[$idx] ? : 379 255 634
2515 _croak "Data descriptor $id is not present in BUFR table B"
2516 634 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 634 634
2517 634 my ($name, $unit, $bits) = (split /\0/, $B_table->{$id})[0,1,4];
2518 634 $line = sprintf "%6d %06d %${width}.${width}s ",
2519 $idx+1, $id, $value;
2520  
2521 # Then get the corresponding bit mapped values, using '*******'
2522 # if 'data not present' in bit map
2523 634 my $max_len = 7;
2524 634 foreach my $bitmap_num (0..$#bitmap_desc) {
2525 1618 my $val;
2526 1618 ▶ if ($bitmap_array[$bitmap_num]->{$idx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bitmap_array[$bitmap_num]{$idx}) { } 268 1350 1618
2527 # data marked as 'data present' in bitmap
2528 268 my $bitmapped_idesc = $bitmap_array[$bitmap_num]->{$idx};
2529 268 ▶ $val = defined $data->[$bitmapped_idesc]
Branch: 1 branch
BranchTrueFalseTotal
defined $data->[$bitmapped_idesc] ? : 268 0 268
2530 ? $data->[$bitmapped_idesc] : 'missing';
2531 268 ▶ $max_len = length($val) if length($val) > $max_len;
Branch: 1 branch
BranchTrueFalseTotal
if length $val > $max_len 2 266 268
2532 } else {
2533 1350 $val = '*******';
2534 }
2535 # If $max_len has been increased, this might not always
2536 # print very pretty, but at least there is no truncation
2537 # of digits in value
2538 1618 $line .= sprintf " %${max_len}.${max_len}s", $val;
2539 }
2540 # Code or flag table number equals $id, so no need to display this in [unit]
2541 634 my $short_unit = $unit;
2542 634 my $unit_start = uc(substr($unit, 0, 4));
2543 634 ▶ if ($unit_start eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit_start eq 'CODE') { } 129 505 634
elsif ($unit_start eq 'FLAG') { } 24 481 505
2544 129 $short_unit = 'CODE TABLE';
2545 } elsif ($unit_start eq 'FLAG') {
2546 24 $short_unit = 'FLAG TABLE';
2547 }
2548 634 $line .= sprintf " %s\n", "$name [$short_unit]";
2549 634 $txt .= $line;
2550  
2551 # Check for illegal flag value
2552 634 ▶ if ($Strict_checking && $short_unit eq 'FLAG TABLE' && $bits > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1) 0 634 634
Condition33%2/6
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1
!ll&&!rl&&r
63400
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE"
!ll&&!rl&&r
63400
MC/DC0%0/3
$Geo::BUFR::Strict_checking and $short_unit eq "FLAG TABLE" and $bits > 1
$Geo::BUFR::Strict_checking $short_unit eq "FLAG TABLE" $bits > 1
Truth table25%1/4
A and B and C
A= $Geo::BUFR::Strict_checkingB= $short_unit eq "FLAG TABLE"C= $bits > 1
ABCresult
0XX0
10X0
1100
1111
2553 0 ▶ if ($value ne 'missing' and $value % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value ne "missing" and $value % 2) 0 0 0
Condition0%0/3
$value ne "missing" and $value % 2
!ll&&!rl&&r
000
MC/DC0%0/2
$value ne "missing" and $value % 2
$value ne "missing" $value % 2
Truth table0%0/3
A and B
A= $value ne "missing"B= $value % 2
ABresult
0X0
100
111
2554 0 my $max_value = 2**$bits - 1;
2555 0 $bits += 0; # get rid of spaces
2556 0 _complain("$id - $value: rightmost bit $bits is set indicating missing value"
2557 . " but then value should be $max_value");
2558 }
2559 }
2560  
2561 # Resolve flag and code table values if code table is loaded
2562 634 ▶ if ($C_table && $value ne 'missing') {
Branch: 1 branch
BranchTrueFalseTotal
if ($C_table and $value ne "missing") 0 634 634
Condition33%1/3
$C_table and $value ne "missing"
!ll&&!rl&&r
63400
MC/DC0%0/2
$C_table and $value ne "missing"
$C_table $value ne "missing"
Truth table33%1/3
A and B
A= $C_tableB= $value ne "missing"
ABresult
0X0
100
111
2563 0 my $num_spaces = $width + 19 + 7*@bitmap_desc;
2564 0 $txt .= _get_code_table_txt($id,$value,$unit,$B_table,$C_table,$num_spaces)
2565 }
2566 634 $idx++;
2567 }
2568 7 return $txt;
2569 }
2570  
2571 ## Return the text found in flag or code tables for value $value of
2572 ## descriptor $id. The empty string is returned if $unit is neither
2573 ## CODE TABLE nor FLAG TABLE, or if $unit is CODE TABLE but for this
2574 ## $value there is no text in C table. Returns a "... does not exist!"
2575 ## message if flag/code table is not found. If $check_illegal is
2576 ## defined, an 'Illegal value' message is returned if $value is bigger
2577 ## than allowed or has highest bit set without having all other bits
2578 ## set.
2579 sub _get_code_table_txt {
2580 332 ▶ my ($id,$value,$unit,$B_table,$C_table,$num_spaces,$check_illegal) = @_;
Subroutine _get_code_table_txt: called CC=17 SCAR=28.9
2581  
2582 332 my $txt = '';
2583 # Need case insensitive matching, since local tables from at least
2584 # DWD use 'Code table', not 'CODE TABLE', in the ECMWF ecCodes
2585 # distribution
2586 332 ▶ if ($unit =~ m/^CODE[ ]?TABLE/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit =~ /^CODE[ ]?TABLE/i) { } 32 300 332
elsif ($unit =~ /^FLAG[ ]?TABLE/i) { } 39 261 300
2587 32 my $code_table = sprintf "%06d", $id;
2588 return "Code table $code_table does not exist!\n"
2589 32 ▶ if ! exists $C_table->{$code_table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $C_table->{$code_table} 0 32 32
2590 32 ▶ if ($C_table->{$code_table}{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($C_table->{$code_table}{$value}) 31 1 32
2591 31 my @lines = split "\n", $C_table->{$code_table}{$value};
2592 31 foreach (@lines) {
2593 39 $txt .= sprintf "%s %s\n", ' ' x ($num_spaces), lc $_;
2594 }
2595 }
2596 } elsif ($unit =~ m/^FLAG[ ]?TABLE/i) {
2597 39 my $flag_table = sprintf "%06d", $id;
2598 return "Flag table $flag_table does not exist!\n"
2599 39 ▶ if ! exists $C_table->{$flag_table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $C_table->{$flag_table} 0 39 39
2600  
2601 39 my $width = (split /\0/, $B_table->{$flag_table})[4];
2602 39 $width += 0; # Get rid of spaces
2603 # Cannot handle more than 32 bits flags with current method
2604 39 ▶ _croak "Unable to handle > 32 bits flag; $id has width $width"
Branch: 1 branch
BranchTrueFalseTotal
if $width > 32 0 39 39
2605 if $width > 32;
2606  
2607 39 my $max_value = 2**$width - 1;
2608  
2609 39 ▶ if (defined $check_illegal and $value > $max_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $check_illegal and $value > $max_value) { } 0 39 39
elsif ($value == $max_value) { } 0 39 39
Condition66%2/3
defined $check_illegal and $value > $max_value
!ll&&!rl&&r
3630
MC/DC0%0/2
defined $check_illegal and $value > $max_value
defined $check_illegal $value > $max_value
Truth table66%2/3
A and B
A= defined $check_illegalB= $value > $max_value
ABresult
0X0
100
111
2610 0 $txt = "Illegal value: $value is bigger than maximum allowed ($max_value)\n";
2611 } elsif ($value == $max_value) {
2612 0 $txt = sprintf "%s=> %s", ' ' x ($num_spaces), "bit $width set:"
2613 . sprintf "%s %s\n", ' ' x ($num_spaces), "missing value\n";
2614 } else {
2615 # Convert to bitstring and localize the 1 bits
2616 39 my $binary = pack "N", $value; # Packed as 32 bits in big-endian order
2617 39 my $bitstring = substr unpack('B*',$binary), 32-$width;
2618 39 for my $i (1..$width) {
2619 750 ▶ if (substr($bitstring, $i-1, 1) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($bitstring, $i - 1, 1) == 1) 52 698 750
2620 52 $txt .= sprintf "%s=> %s", ' ' x ($num_spaces),
2621 "bit $i set";
2622 52 ▶ if ($C_table->{$flag_table}{$i}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($C_table->{$flag_table}{$i}) { } 50 2 52
2623 50 my @lines = split "\n", $C_table->{$flag_table}{$i};
2624 50 $txt .= ': ' . lc (shift @lines) . "\n";
2625 50 foreach (@lines) {
2626 0 $txt .= sprintf "%s %s\n", ' ' x ($num_spaces), lc $_;
2627 }
2628 } else {
2629 2 $txt .= "\n";
2630 }
2631 }
2632 }
2633 39 ▶ if (defined $check_illegal and $txt =~ /bit $width set/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check_illegal and $txt =~ /bit $width set/) 1 38 39
Condition100%3/3
defined $check_illegal and $txt =~ /bit $width set/
!ll&&!rl&&r
3621
MC/DC100%2/2
defined $check_illegal and $txt =~ /bit $width set/
defined $check_illegal $txt =~ /bit $width set/
Truth table100%3/3
A and B
A= defined $check_illegalB= $txt =~ /bit $width set/
ABresult
0X0
100
111
2634 1 $txt = "Illegal value ($value): bit $width is set indicating missing value,"
2635 . " but then value should be $max_value\n";
2636 }
2637 }
2638 }
2639 332 return $txt;
2640 }
2641  
2642 ## Convert from integer to descriptor
2643 sub _int2fxy {
2644 130 ▶ my @fxy = map {sprintf("%1d%02d%03d", ($_>>14)&0x3, ($_>>8)&0x3f, $_&0xff)} @_;
Subroutine _int2fxy: called CC=2 SCAR=6.9
2645 130 ▶ return @_ > 1 ? @fxy : $fxy[0];
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 84 46 130
2646 }
2647  
2648 ## Expand a list of descriptors using BUFR table D, also expanding
2649 ## simple replication but not delayed replication
2650 sub _expand_descriptors {
2651 1280 ▶ my $D_table = shift;
Subroutine _expand_descriptors: called CC=18 SCAR=29.4
2652 1280 my @expanded = ();
2653  
2654 1280 ▶ for (my $di = 0; $di < @_; $di++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($di < @_) 7005 1279 8284
2655 7005 my $descriptor = $_[$di];
2656 7005 ▶ _croak "$descriptor is not a BUFR descriptor"
Branch: 1 branch
BranchTrueFalseTotal
unless $descriptor =~ /^\d{6}$/ 0 7005 7005
2657 if $descriptor !~ /^\d{6}$/;
2658 7005 my $f = int substr($descriptor, 0, 1);
2659 7005 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 282 6723 7005
elsif ($f == 3) { } 932 5791 6723
2660 282 my $x = substr $descriptor, 1, 2; # Replicate next $x descriptors
2661 282 my $y = substr $descriptor, 3; # Number of replications
2662 282 ▶ if ($y > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y > 0) { } 173 109 282
2663 # Simple replication (replicate next x descriptors y times)
2664 173 ▶ _croak "Cannot expand: Not enough descriptors following "
Branch: 1 branch
BranchTrueFalseTotal
if $di + $x + 1 > @_ 0 173 173
2665 . "replication descriptor $descriptor (or there is "
2666 . "a problem in nesting of replication)" if $di+$x+1 > @_;
2667 173 my @r = ();
2668 173 push @r, @_[($di+1)..($di+$x)] for (1..$y);
2669 # Recursively expand replicated descriptors $y times
2670 173 my @s = ();
2671 173 ▶ @s = _expand_descriptors($D_table, @r) if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 173 0 173
2672 173 ▶ if ($Show_replication) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_replication) 5 168 173
2673 # Adjust x since replicated descriptors might have been expanded
2674 # Unfortunately _spew is not available here to report the x>99 -> x=0 hack
2675 5 ▶ my $z = @s/$y > 99 ? 0 : @s/$y;
Branch: 1 branch
BranchTrueFalseTotal
@s / $y > 99 ? : 0 5 5
2676 5 substr($_[$di], 1, 2) = sprintf "%02d", $z;
2677 5 push @expanded, $_[$di];
2678 }
2679 173 ▶ push @expanded, @s if @s;
Branch: 1 branch
BranchTrueFalseTotal
if @s 173 0 173
2680 173 $di += $x;
2681 } else {
2682 # Delayed replication. Next descriptor ought to be the
2683 # delayed descriptor replication (and data repetition)
2684 # factor, i.e. one of 0310(00|01|02|11|12), followed
2685 # by the x descriptors to be replicated
2686 109 ▶ if ($di+2 == @_ && $_[$di+1] =~ /^0310(00|01|02|11|12)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($di + 2 == @_ and $_[$di + 1] =~ /^0310(00|01|02|11|12)$/) 1 108 109
Condition66%2/3
$di + 2 == @_ and $_[$di + 1] =~ /^0310(00|01|02|11|12)$/
!ll&&!rl&&r
10801
MC/DC50%1/2
$di + 2 == @_ and $_[$di + 1] =~ /^0310(00|01|02|11|12)$/
$di + 2 == @_ $_[$di + 1] =~ /^0310(00|01|02|11|12)$/
Truth table66%2/3
A and B
A= $di + 2 == @_B= $_[$di + 1] =~ /^0310(00|01|02|11|12)$/
ABresult
0X0
100
111
2687 1 _complain "Missing the $x descriptors which should follow"
2688 . " $descriptor $_[$di+1]";
2689 1 push @expanded, @_[$di,$di+1];
2690 1 last;
2691 }
2692 108 ▶ _croak "Cannot expand: Not enough descriptors following delayed"
Branch: 1 branch
BranchTrueFalseTotal
if $di + $x + 1 > @_ 0 108 108
2693 . " replication descriptor $descriptor (or there is "
2694 . "a problem in nesting of replication)" if $di+$x+1 > @_;
2695 108 ▶ _croak "Cannot expand: Delayed replication descriptor "
Branch: 1 branch
BranchTrueFalseTotal
unless $_[$di + 1] =~ /^0310(00|01|02|11|12)$/ 0 108 108
2696 . "$descriptor is not followed by one of "
2697 . "0310(00|01|02|11|12) but by $_[$di+1]"
2698 if $_[$di+1] !~ /^0310(00|01|02|11|12)$/;
2699 108 my @r = @_[($di+2)..($di+$x+1)];
2700 # Here we just expand the D descriptors in the
2701 # descriptors to be replicated. The final expansion
2702 # using delayed replication factor has to wait until
2703 # data part is decoded
2704 108 my @s = ();
2705 108 ▶ @s = _expand_descriptors($D_table, @r) if @r;
Branch: 1 branch
BranchTrueFalseTotal
if @r 108 0 108
2706 # Must adjust x since replicated descriptors might have been expanded
2707 108 substr($_[$di], 1, 2) = sprintf "%02d", scalar @s;
2708 108 push @expanded, @_[$di,$di+1], @s;
2709 108 $di += 1+$x; # NOTE: 1 is added to $di on next iteration
2710 }
2711 281 next;
2712 } elsif ($f == 3) {
2713 _croak "No sequence descriptor $descriptor in BUFR table D"
2714 932 ▶ if not exists $D_table->{$descriptor};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $D_table->{$descriptor} 0 932 932
2715 # Expand recursively, if necessary
2716 push @expanded,
2717 932 _expand_descriptors($D_table, split /\s/, $D_table->{$descriptor});
2718 } else { # f=0,2
2719 5791 push @expanded, $descriptor;
2720 }
2721 }
2722  
2723 1280 return @expanded;
2724 }
2725  
2726 ## Return a text string suitable for printing information about the given
2727 ## BUFR table descriptors
2728 ##
2729 ## $how = 'fully': Expand all D descriptors fully into B descriptors,
2730 ## with name, unit, scale, reference value and width (each on a
2731 ## numbered line, except for replication operators which are not
2732 ## numbered).
2733 ##
2734 ## $how = 'partially': Like 'fully, but expand D descriptors only once
2735 ## and ignore replication.
2736 ##
2737 ## $how = 'noexpand': Like 'partially', but do not expand D
2738 ## descriptors at all.
2739 ##
2740 ## $how = 'simply': Like 'partially', but list the descriptors on one
2741 ## single line with no extra information provided.
2742 sub resolve_descriptor {
2743 6 ▶ my $self = shift;
Subroutine resolve_descriptor: called CC=25 SCAR=38.0
Pod undocumented
2744 6 my $how = shift;
2745 6 foreach (@_) {
2746 18 ▶ _croak("'$_' is not an integer argument to resolve_descriptor!")
Branch: 1 branch
BranchTrueFalseTotal
unless /^\d+$/ 0 18 18
2747 unless /^\d+$/;
2748 }
2749 6 my @desc = map { sprintf "%06d", $_ } @_;
2750  
2751 6 my @allowed_hows = qw( simply fully partially noexpand );
2752 _croak "First argument in resolve_descriptor must be one of"
2753 . " '@allowed_hows', is: '$how'"
2754 6 ▶ unless grep { $how eq $_ } @allowed_hows;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$how eq $_;} @allowed_hows 0 6 6
2755  
2756 6 ▶ if (! $self->{B_TABLE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"B_TABLE"}) 0 6 6
2757 0 ▶ if ($BUFR_table{FORMAT} eq 'ECCODES' && $self->{LOCAL_TABLES_NOT_FOUND}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES' and $self->{'LOCAL_TABLES_NOT_FOUND'}) { } 0 0 0
Condition0%0/3
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" and $self->{"LOCAL_TABLES_NOT_FOUND"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" and $self->{"LOCAL_TABLES_NOT_FOUND"}
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" $self->{"LOCAL_TABLES_NOT_FOUND"}
Truth table0%0/3
A and B
A= $Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES"B= $self->{"LOCAL_TABLES_NOT_FOUND"}
ABresult
0X0
100
111
2758 0 _croak "Local table " . $self->{LOCAL_TABLES_NOT_FOUND} . " couldn't be found,"
2759 . " or you might need to load WMO master table also?";
2760 } else {
2761 0 _croak "No B table is loaded - did you forget to call load_BDtables?";
2762 }
2763 }
2764 6 my $B_table = $self->{B_TABLE};
2765  
2766 # Some local tables are provided only for element descriptors, and
2767 # we might in fact not need the sequence descriptors for resolving
2768 6 my $D_table;
2769 6 my $need_Dtable = 0;
2770 6 foreach my $id (@desc) {
2771 18 ▶ if (substr($id,0,1) eq '3') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($id, 0, 1) eq 3) 8 10 18
2772 8 $need_Dtable = 1;
2773 }
2774 }
2775 6 ▶ if ($need_Dtable && ! $self->{D_TABLE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_Dtable and not $self->{'D_TABLE'}) { } 0 6 6
Condition66%2/3
$need_Dtable and not $self->{"D_TABLE"}
!ll&&!rl&&r
150
MC/DC0%0/2
$need_Dtable and not $self->{"D_TABLE"}
$need_Dtable not $self->{"D_TABLE"}
Truth table66%2/3
A and not(B)
A= $need_DtableB= not $self->{"D_TABLE"}
ABresult
0X0
100
111
2776 0 ▶ if ($BUFR_table{FORMAT} eq 'ECCODES' && $self->{LOCAL_TABLES_NOT_FOUND}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::BUFR_table{'FORMAT'} eq 'ECCODES' and $self->{'LOCAL_TABLES_NOT_FOUND'}) { } 0 0 0
Condition0%0/3
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" and $self->{"LOCAL_TABLES_NOT_FOUND"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" and $self->{"LOCAL_TABLES_NOT_FOUND"}
$Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES" $self->{"LOCAL_TABLES_NOT_FOUND"}
Truth table0%0/3
A and B
A= $Geo::BUFR::BUFR_table{"FORMAT"} eq "ECCODES"B= $self->{"LOCAL_TABLES_NOT_FOUND"}
ABresult
0X0
100
111
2777 0 _croak "Local table " . $self->{LOCAL_TABLES_NOT_FOUND} . " couldn't be found,"
2778 . " or you might need to load WMO master table also?";
2779 } else {
2780 0 _croak "No D table is loaded - did you forget to call load_BDtables?";
2781 }
2782 } else {
2783 # Could consider omitting this if $need_Dtable = 0 ...
2784 6 $D_table = $self->{D_TABLE};
2785 }
2786  
2787 6 my $txt = '';
2788  
2789 6 ▶ if ($how eq 'simply' or $how eq 'partially') {
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "simply" or $how eq "partially") 2 4 6
Condition100%3/3
$how eq "simply" or $how eq "partially"
l!l&&r!l&&!r
114
MC/DC100%2/2
$how eq "simply" or $how eq "partially"
$how eq "simply" $how eq "partially"
Truth table100%3/3
A or B
A= $how eq "simply"B= $how eq "partially"
ABresult
1X1
011
000
2790 2 my @expanded;
2791 2 foreach my $id (@desc) {
2792 2 my $f = substr $id, 0, 1;
2793 2 ▶ if ($f == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f == 3) { } 2 0 2
2794 _croak "$id is not in table D, unable to expand"
2795 2 ▶ unless $D_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless $D_table->{$id} 0 2 2
2796 2 push @expanded, split /\s/, $D_table->{$id};
2797 } else {
2798 0 push @expanded, $id;
2799 }
2800 }
2801 2 ▶ if ($how eq 'simply') {
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq 'simply') { } 1 1 2
2802 1 return $txt = "@expanded\n";
2803 } else {
2804 1 @desc = @expanded;
2805 }
2806 }
2807 5 ▶ if ($how eq 'fully') {
Branch: 1 branch
BranchTrueFalseTotal
if ($how eq "fully") 3 2 5
2808 3 ▶ if (@desc == 1 and $desc[0] =~ /^1/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@desc == 1 and $desc[0] =~ /^1/) { } 0 3 3
Condition33%1/3
@desc == 1 and $desc[0] =~ /^1/
!ll&&!rl&&r
030
MC/DC0%0/2
@desc == 1 and $desc[0] =~ /^1/
@desc == 1 $desc[0] =~ /^1/
Truth table33%1/3
A and B
A= @desc == 1B= $desc[0] =~ /^1/
ABresult
0X0
100
111
2809 # This is simply a replication descriptor; do not try to expand
2810 } else {
2811 3 @desc = _expand_descriptors($D_table, @desc);
2812 }
2813 }
2814  
2815 5 my $count = 0;
2816 5 foreach my $id (@desc) {
2817 166 ▶ if ($id =~ /^[123]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id =~ /^[123]/) { } 21 145 166
elsif ($B_table->{$id}) { } 145 0 145
2818 21 $txt .= sprintf " %06d\n", $id;
2819 } elsif ($B_table->{$id}) {
2820 145 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
2821 145 $txt .= sprintf "%3d %06d %s [%s] %d %d %d\n",
2822 ++$count,$id,$name,$unit,$scale,$refval,$width;
2823 } else {
2824 0 $txt .= sprintf "%3d %06d Not in table B\n",
2825 ++$count,$id;
2826 }
2827 }
2828 5 return $txt;
2829 }
2830  
2831 ## Return BUFR table B information for an element descriptor for the
2832 ## last table loaded, as an array of name, unit, scale, reference
2833 ## value and data width in bits. Returns false if the descriptor is
2834 ## not found or no data width is defined, or croaks if no table B has
2835 ## been loaded.
2836 sub element_descriptor {
2837 2 ▶ my $self = shift;
Subroutine element_descriptor: called CC=6 SCAR=18.8
Pod undocumented
2838 2 my $desc = shift;
2839 2 ▶ _croak "Argument to element_descriptor must be an integer\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $desc =~ /^\d+$/ 0 2 2
2840 unless $desc =~ /^\d+$/;
2841 2 $desc = sprintf "%06d", $desc;
2842 2 ▶ _croak "No BUFR B table loaded\n" unless defined $self->{B_TABLE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"B_TABLE"} 0 2 2
2843 2 ▶ return unless defined $self->{B_TABLE}->{$desc};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"B_TABLE"}{$desc} 1 1 2
2844 my ($name, $unit, $scale, $refval, $width)
2845 1 = split /\0/, $self->{B_TABLE}->{$desc};
2846 1 ▶ return unless defined $width && $width =~ /\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $width and $width =~ /\d+$/ 0 1 1
Condition33%1/3
defined $width and $width =~ /\d+$/
!ll&&!rl&&r
001
MC/DC0%0/2
defined $width and $width =~ /\d+$/
defined $width $width =~ /\d+$/
Truth table33%1/3
A and B
A= defined $widthB= $width =~ /\d+$/
ABresult
0X0
100
111
2847 1 return ($name, $unit, $scale+0, $refval+0, $width+0);
2848 }
2849  
2850 ## Return BUFR table D information for a sequence descriptor for the
2851 ## last table loaded, as a space separated string of the descriptors
2852 ## in the direct (nonrecursive) lookup in table D. Returns false if
2853 ## the sequence descriptor is not found, or croaks if no table D has
2854 ## been loaded.
2855 sub sequence_descriptor {
2856 3 ▶ my $self = shift;
Subroutine sequence_descriptor: called CC=5 SCAR=16.2
Pod undocumented
2857 3 my $desc = shift;
2858 3 ▶ _croak "Argument to element_descriptor must be an integer\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $desc =~ /^\d+$/ 0 3 3
2859 unless $desc =~ /^\d+$/;
2860 3 ▶ _croak "No BUFR D table loaded\n" unless defined $self->{D_TABLE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"D_TABLE"} 0 3 3
2861 3 ▶ return unless defined $self->{D_TABLE}->{$desc};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"D_TABLE"}{$desc} 1 2 3
2862 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
2863 1 return split / /, $self->{D_TABLE}->{$desc};
2864 } else {
2865 1 return $self->{D_TABLE}->{$desc};
2866 }
2867 }
2868  
2869 ## Return a text string telling which bits are set and the meaning of
2870 ## the bits set when $value is interpreted as a flag value, also
2871 ## checking for illegal values. The empty string is returned if $value=0.
2872 sub resolve_flagvalue {
2873 3 ▶ my $self = shift;
Subroutine resolve_flagvalue: called CC=3 SCAR=11.1
Pod undocumented
2874 3 my ($value, $flag_table, $table, $num_leading_spaces) = @_;
2875 3 ▶ _croak "Flag value can't be negative!\n" if $value < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 0 3 3
2876 3 ▶ $num_leading_spaces ||= 0; # Default value
Condition50%1/2
$num_leading_spaces ||= 0
l!l
03
MC/DC0%0/1
$num_leading_spaces ||= 0
$num_leading_spaces
Truth table50%1/2
A
A= $num_leading_spaces
Aresult
11
00
2877  
2878 3 $self->load_Ctable($table);
2879 3 my $C_table = $self->{C_TABLE};
2880  
2881 # Number of bits used for the flag is hard to extract from C
2882 # table; it is much easier to obtain from B table
2883 3 $self->load_BDtables($table);
2884 3 my $B_table = $self->{B_TABLE};
2885  
2886 3 my $unit = 'FLAG TABLE';
2887 3 return _get_code_table_txt($flag_table,$value,$unit,
2888 $B_table,$C_table,$num_leading_spaces,'check_illegal');
2889 }
2890  
2891 ## Return the contents of code table $code_table, or empty string if
2892 ## code table is not found
2893 sub dump_codetable {
2894 4 ▶ my $self = shift;
Subroutine dump_codetable: called CC=4 SCAR=13.9
Pod undocumented
2895 4 my ($code_table, $table) = @_;
2896 4 ▶ _croak("code_table '$code_table' is not a (positive) integer in dump_codetable()")
Branch: 1 branch
BranchTrueFalseTotal
unless $code_table =~ /^\d+$/ 0 4 4
2897 unless $code_table =~ /^\d+$/;
2898 4 $code_table = sprintf "%06d", $code_table;
2899  
2900 4 $self->load_Ctable($table);
2901 4 my $C_table = $self->{C_TABLE};
2902  
2903 4 ▶ return '' unless $C_table->{$code_table};
Branch: 1 branch
BranchTrueFalseTotal
unless $C_table->{$code_table} 1 3 4
2904  
2905 3 my $dump;
2906 3 foreach my $value (sort {$a <=> $b} keys %{ $C_table->{$code_table} }) {
2907 42 my $txt = $C_table->{$code_table}{$value};
2908 42 chomp $txt;
2909 42 $txt =~ s/\n/\n /g;
2910 42 $dump .= sprintf "%3d -> %s\n", $value, $txt;
2911 }
2912 3 return $dump;
2913 }
2914  
2915 ## Decode bitstream (data part of section 4) while working through the
2916 ## (expanded) descriptors in section 3. The final data and
2917 ## corresponding descriptors are put in $self->{DATA} and
2918 ## $self->{DESC} (indexed by subset number)
2919 sub _decode_bitstream {
2920 40 ▶ my $self = shift;
Subroutine _decode_bitstream: called CC=90 SCAR=53.0
2921 40 $self->{CODING} = 'DECODE';
2922 40 my $bitstream = $self->{SEC4_RAWDATA} . "\0\0\0\0";
2923 40 my $maxpos = 8*length($self->{SEC4_RAWDATA});
2924 40 my $pos = 0;
2925 40 my @operators;
2926 my $ref_values_ref; # Hash ref to reference values with descriptors as keys;
2927 # to be implemented later (not used yet)
2928 40 my @subset_data; # Will contain data values for subset 1,2...
2929 40 my @subset_desc; # Will contain the set of descriptors for subset 1,2...
2930 # expanded to be in one to one correspondance with the data
2931 40 my $repeat_X; # Set to number of descriptors to be repeated if
2932 # delayed descriptor and data repetition factor is
2933 # in effect
2934 40 my $repeat_factor; # Set to number of times descriptors (and data)
2935 # are to be repeated if delayed descriptor and
2936 # data repetition factor is in effect
2937 40 my @repeat_desc; # The descriptors to be repeated
2938 40 my @repeat_data; # The data to be repeated
2939 40 my $B_table = $self->{B_TABLE};
2940  
2941 # Has to fully expand @desc for each subset in turn, as delayed
2942 # replication factors might be different for each subset,
2943 # resulting in different full expansions. During the expansion the
2944 # effect of operator descriptors are taken into account, causing
2945 # most of them to be eliminated (unless $Show_all_operators is
2946 # set), so that @desc and the equivalent $subset_desc[$isub] ends
2947 # up being in one to one correspondence with the data values in
2948 # $subset_data[$isub] (the operators included having data value
2949 # '')
2950 40 S_LOOP: foreach my $isub (1..$self->{NUM_SUBSETS}) {
2951 53 ▶ $self->_spew(2, "Decoding subset number %d", $isub) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 4 49 53
2952  
2953 # Bit maps might vary from subset to subset, so must be rebuilt
2954 53 undef $self->{BITMAP_OPERATORS};
2955 53 undef $self->{BITMAP_START};
2956 53 undef $self->{REUSE_BITMAP};
2957 53 $self->{NUM_BITMAPS} = 0;
2958 53 $self->{BACKWARD_DATA_REFERENCE} = 1;
2959 53 $self->{NUM_CHANGE_OPERATORS} = 0;
2960  
2961 53 my @desc = split /\s/, $self->{DESCRIPTORS_EXPANDED};
2962  
2963 # Note: @desc as well as $idesc may be changed during this loop,
2964 # so we cannot use a foreach loop instead
2965 53 ▶ D_LOOP: for (my $idesc = 0; $idesc < @desc; $idesc++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) 7575 47 7622
2966 7666 my $id = $desc[$idesc];
2967 7666 my $f = substr($id,0,1);
2968 7666 my $x = substr($id,1,2)+0;
2969 7666 my $y = substr($id,3,3)+0;
2970  
2971 7666 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 76 7590 7666
elsif ($f == 2) { } 114 7476 7590
2972 76 ▶ if ($Show_replication) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_replication) 2 74 76
2973 2 push @{$subset_desc[$isub]}, $id;
2974 2 push @{$subset_data[$isub]}, '';
2975 2 ▶ $self->_spew(4, "X=0 in $id for F=1, might have been > 99 in expansion")
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew and $x == 0 0 2 2
Condition33%1/3
$Geo::BUFR::Spew and $x == 0
!ll&&!rl&&r
200
MC/DC0%0/2
$Geo::BUFR::Spew and $x == 0
$Geo::BUFR::Spew $x == 0
Truth table33%1/3
A and B
A= $Geo::BUFR::SpewB= $x == 0
ABresult
0X0
100
111
2976 if $Spew && $x == 0;
2977 }
2978 76 ▶ next D_LOOP if $y > 0; # Nothing more to do for normal replication
Branch: 1 branch
BranchTrueFalseTotal
if $y > 0 2 74 76
2979  
2980 74 ▶ if ($x == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0) 0 74 74
2981 0 _complain("Nonsensical replication of zero descriptors ($id)");
2982 0 $idesc++;
2983 0 next D_LOOP;
2984 }
2985  
2986 74 $_ = $desc[$idesc+1];
2987 _croak "$id Erroneous replication factor"
2988 74 ▶ unless /^0310(00|01|02|11|12)/ && exists $B_table->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless /^0310(00|01|02|11|12)/ and exists $B_table->{$_} 0 74 74
Condition33%1/3
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
!ll&&!rl&&r
0074
MC/DC0%0/2
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
/^0310(00|01|02|11|12)/ exists $B_table->{$_}
Truth table33%1/3
A and B
A= /^0310(00|01|02|11|12)/B= exists $B_table->{$_}
ABresult
0X0
100
111
2989  
2990 74 my $width = (split /\0/, $B_table->{$_})[-1];
2991 74 my $factor = bitstream2dec($bitstream, $pos, $width);
2992 74 $pos += $width;
2993 # Delayed descriptor replication factors (and
2994 # associated fields) are the only values in section 4
2995 # where all bits being 1 is not to be interpreted as a
2996 # missing value
2997 74 ▶ if (not defined $factor) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $factor) 0 74 74
2998 0 $factor = 2**$width - 1;
2999 }
3000 74 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 8 66 74
3001 8 ▶ if ($_ eq '031011' || $_ eq '031012') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq '031011' or $_ eq '031012') { } 0 8 8
Condition33%1/3
$_ eq "031011" or $_ eq "031012"
l!l&&r!l&&!r
008
MC/DC0%0/2
$_ eq "031011" or $_ eq "031012"
$_ eq "031011" $_ eq "031012"
Truth table33%1/3
A or B
A= $_ eq "031011"B= $_ eq "031012"
ABresult
1X1
011
000
3002 0 $self->_spew(4, "$_ Delayed repetition factor: %s", $factor);
3003 } else {
3004 8 $self->_spew(4, "$_ Delayed replication factor: %s", $factor);
3005 }
3006 }
3007 # Include the delayed replication in descriptor and data list
3008 74 splice @desc, $idesc++, 0, $_;
3009 74 push @{$subset_desc[$isub]}, $_;
3010 74 push @{$subset_data[$isub]}, $factor;
3011  
3012 74 ▶ if ($_ eq '031011' || $_ eq '031012') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "031011" or $_ eq "031012") 0 74 74
Condition33%1/3
$_ eq "031011" or $_ eq "031012"
l!l&&r!l&&!r
0074
MC/DC0%0/2
$_ eq "031011" or $_ eq "031012"
$_ eq "031011" $_ eq "031012"
Truth table33%1/3
A or B
A= $_ eq "031011"B= $_ eq "031012"
ABresult
1X1
011
000
3013 # For delayed repetition, descriptor *and* data are
3014 # to be repeated
3015 0 $repeat_X = $x;
3016 0 $repeat_factor = $factor;
3017 }
3018 74 my @r = ();
3019 74 ▶ push @r, @desc[($idesc+2)..($idesc+$x+1)] while $factor--;
Branch: 1 branch
BranchTrueFalseTotal
$factor-- and do { push @r, @desc[$idesc + 2 .. $idesc + $x + 1] } 785 74 859
3020 74 splice @desc, $idesc, 2+$x, @r;
3021  
3022 74 ▶ if ($repeat_factor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat_factor) { } 0 74 74
3023 # Skip to the last set to be repeated, which will
3024 # then be included $repeat_factor times
3025 0 $idesc += $x * ($repeat_factor - 1);
3026 0 ▶ $self->_spew(4, "Delayed repetition ($id $_ -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
3027 } else {
3028 74 ▶ $self->_spew(4, "Delayed replication ($id $_ -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 8 66 74
3029 }
3030 74 ▶ if ($idesc < @desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) { } 69 5 74
3031 69 redo D_LOOP;
3032 } else {
3033 5 last D_LOOP; # Might happen if delayed factor is 0
3034 }
3035  
3036 } elsif ($f == 2) {
3037 114 my $flow;
3038 my $bm_idesc;
3039 114 ($pos, $flow, $bm_idesc, @operators)
3040 = $self->_apply_operator_descriptor($id, $x, $y, $pos, $isub,
3041 $desc[$idesc+1], @operators);
3042 114 ▶ if ($flow eq 'redo_bitmap') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flow eq 'redo_bitmap') { } 22 92 114
elsif ($flow eq 'signify_character') { } 0 92 92
elsif ($flow eq 'no_value') { } 41 51 92
3043 # Data value is associated with the descriptor
3044 # defined by bit map. Remember original and new
3045 # index in descriptor array for the bit mapped
3046 # values ('dr' = data reference)
3047 22 my $dr_idesc;
3048 22 ▶ if (!defined $bm_idesc) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bm_idesc) { } 0 22 22
elsif (not $Geo::BUFR::Show_all_operators) { } 22 0 22
3049 0 $dr_idesc = shift @{$self->{REUSE_BITMAP}->[$isub]};
3050 } elsif (!$Show_all_operators) {
3051 22 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3052 + $bm_idesc;
3053 } else {
3054 0 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}];
3055 # Skip operator descriptors
3056 0 ▶ while ($bm_idesc-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bm_idesc-- > 0) 0 0 0
3057 0 $dr_idesc++;
3058 0 ▶ $dr_idesc++ while ($desc[$dr_idesc] >= 200000);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$dr_idesc] >= 200000 and do { ++$dr_idesc } 0 0 0
3059 }
3060 }
3061 22 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
3062 $dr_idesc, $idesc;
3063 22 ▶ if ($Show_all_operators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_all_operators) 0 22 22
3064 0 push @{$subset_desc[$isub]}, $id;
3065 0 push @{$subset_data[$isub]}, '';
3066 }
3067 22 $desc[$idesc] = $desc[$dr_idesc];
3068 22 redo D_LOOP;
3069 } elsif ($flow eq 'signify_character') {
3070 0 push @{$subset_desc[$isub]}, $id;
3071 # Extract ASCII string
3072 0 my $value = bitstream2ascii($bitstream, $pos, $y);
3073 0 $pos += 8*$y;
3074 # Trim string, also removing nulls
3075 0 $value = _trim($value, $id);
3076 0 push @{$subset_data[$isub]}, $value;
3077 0 next D_LOOP;
3078 } elsif ($flow eq 'no_value') {
3079 # Some operator descriptors ought to be included
3080 # in expanded descriptors even though they have no
3081 # corresponding data value, because they contain
3082 # valuable information to be displayed in
3083 # dumpsection4 (e.g. 222000 'Quality information follows')
3084 41 push @{$subset_desc[$isub]}, $id;
3085 41 push @{$subset_data[$isub]}, '';
3086 41 next D_LOOP;
3087 }
3088  
3089 51 ▶ if ($Show_all_operators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_all_operators) { } 8 43 51
3090 8 push @{$subset_desc[$isub]}, $id;
3091 8 push @{$subset_data[$isub]}, '';
3092 } else {
3093 # Remove operator descriptor from @desc
3094 43 splice @desc, $idesc--, 1;
3095 }
3096  
3097 51 ▶ next D_LOOP if $flow eq 'next';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "next" 42 9 51
3098 9 ▶ last D_LOOP if $flow eq 'last';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "last" 1 8 9
3099 8 ▶ if ($flow eq 'skip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($flow eq "skip") 8 0 8
3100 8 $idesc++;
3101 8 next D_LOOP;
3102 }
3103 }
3104  
3105 7476 ▶ if ($self->{CHANGE_REFERENCE_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CHANGE_REFERENCE_VALUE"}) 2 7474 7476
3106 # The data descriptor is to be associated with a new
3107 # reference value, which is fetched from data stream
3108 2 ▶ _croak "Change reference operator 203Y is not followed by element"
Branch: 1 branch
BranchTrueFalseTotal
if $f > 0 0 2 2
3109 . " descriptor, but $id" if $f > 0;
3110 2 my $num_bits = $self->{CHANGE_REFERENCE_VALUE};
3111 2 my $new_refval = bitstream2dec($bitstream, $pos, $num_bits);
3112 2 $pos += $num_bits;
3113 # Negative value if most significant bit is set (one's complement)
3114 2 ▶ $new_refval = $new_refval & (1<<$num_bits-1)
Branch: 1 branch
BranchTrueFalseTotal
$new_refval & 1 << $num_bits - 1 ? : 2 0 2
3115 ? -($new_refval & ((1<<$num_bits-1)-1))
3116 : $new_refval;
3117 2 ▶ $self->_spew(4, "$id * Change reference value: ".
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
$new_refval > 0 ? : 0 0 0
3118 ($new_refval > 0 ? "+" : "")."$new_refval") if $Spew;
3119 2 $self->{NEW_REFVAL_OF}{$id}{$isub} = $new_refval;
3120 # Identify new reference values by setting f=9
3121 2 push @{$subset_desc[$isub]}, $id + 900000;
3122 2 push @{$subset_data[$isub]}, $new_refval;
3123 2 next D_LOOP;
3124 }
3125  
3126 # If operator 204$y 'Add associated field is in effect',
3127 # each data value is preceded by $y bits which should be
3128 # decoded separately. We choose to provide a descriptor
3129 # 999999 in this case (like the ECMWF BUFRDC software)
3130 7474 ▶ if ($self->{ADD_ASSOCIATED_FIELD} and $id ne '031021') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021") 2 7472 7474
Condition100%3/3
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
!ll&&!rl&&r
747112
MC/DC100%2/2
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
$self->{"ADD_ASSOCIATED_FIELD"} $id ne "031021"
Truth table100%3/3
A and B
A= $self->{"ADD_ASSOCIATED_FIELD"}B= $id ne "031021"
ABresult
0X0
100
111
3131 # First extract associated field
3132 2 my $width = $self->{ADD_ASSOCIATED_FIELD};
3133 2 my $value = bitstream2dec($bitstream, $pos, $width);
3134 # All bits set to 1 for associated field is NOT
3135 # interpreted as missing value
3136 2 ▶ $value = 2**$width - 1 if ! defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 1 2
3137 2 $pos += $width;
3138 2 push @{$subset_desc[$isub]}, 999999;
3139 2 push @{$subset_data[$isub]}, $value;
3140 2 ▶ $self->_spew(4, "Added associated field: %s", $value) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
3141 }
3142  
3143 # We now have a "real" data descriptor
3144 7474 push @{$subset_desc[$isub]}, $id;
3145  
3146 # For quality information, if this relates to a bit map we
3147 # need to store index of the data ($data_idesc) for which
3148 # the quality information applies, as well as the new
3149 # index ($idesc) in the descriptor array for the bit
3150 # mapped values
3151 7474 ▶ if (substr($id,0,3) eq '033'
Branch: 1 branch
BranchTrueFalseTotal
if (substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000) 306 7168 7474
Condition83%5/6
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
!ll&&!rl&&r
71680306
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"}
!ll&&!rl&&r
712939306
MC/DC66%2/3
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
substr($id, 0, 3) eq "033" defined $self->{"BITMAP_OPERATORS"} $self->{"BITMAP_OPERATORS"}[-1] eq 222000
Truth table75%3/4
A and B and C
A= substr($id, 0, 3) eq "033"B= defined $self->{"BITMAP_OPERATORS"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 222000
ABCresult
0XX0
10X0
1100
1111
3152 && defined $self->{BITMAP_OPERATORS}
3153 && $self->{BITMAP_OPERATORS}->[-1] eq '222000') {
3154 306 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 120 186 306
3155 120 my $data_idesc = shift @{ $self->{REUSE_BITMAP}->[$isub] };
3156 120 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 120 120
3157 if not defined $data_idesc;
3158 120 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
3159 $data_idesc, $idesc;
3160 } else {
3161 186 my $data_idesc = shift @{ $self->{CURRENT_BITMAP} };
3162 186 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 186 186
3163 if not defined $data_idesc;
3164 186 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
3165 186 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3166 + $data_idesc, $idesc;
3167 }
3168 }
3169  
3170 # Find the relevant entry in BUFR table B
3171 _croak "Data descriptor $id is not present in BUFR table B"
3172 7474 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 7474 7474
3173 7474 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
3174 7474 ▶ $self->_spew(3, "%6s %-20s %s", $id, $unit, $name) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 455 7019 7474
3175  
3176 # Override Table B values if Data Description Operators are in effect
3177 7474 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0) 126 7348 7474
3178 126 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 102 24 126
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 1 46 47
Condition100%3/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
123102
MC/DC100%2/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table100%3/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
3179 102 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 0 102 102
3180 0 $scale += $self->{CHANGE_SRW};
3181 0 $width += int((10*$self->{CHANGE_SRW}+2)/3);
3182 0 $refval *= 10*$self->{CHANGE_SRW};
3183 } else {
3184 102 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 15 87 102
3185 102 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 17 85 102
3186 }
3187 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition66%2/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
2301
MC/DC50%1/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table66%2/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
3188 $width = $self->{CHANGE_CCITTIA5_WIDTH}
3189 1 }
3190 # To prevent autovivification (see perldoc -f exists) we
3191 # need this laborious test for defined
3192 $refval = $self->{NEW_REFVAL_OF}{$id}{$isub} if defined $self->{NEW_REFVAL_OF}{$id}
3193 126 ▶ && defined $self->{NEW_REFVAL_OF}{$id}{$isub};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub} 2 124 126
Condition66%2/3
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
!ll&&!rl&&r
12402
MC/DC50%1/2
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
defined $self->{"NEW_REFVAL_OF"}{$id} defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
Truth table66%2/3
A and B
A= defined $self->{"NEW_REFVAL_OF"}{$id}B= defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
ABresult
0X0
100
111
3194 # Difference statistical values use different width and reference value
3195 126 ▶ if ($self->{DIFFERENCE_STATISTICAL_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DIFFERENCE_STATISTICAL_VALUE"}) 0 126 126
3196 0 $width += 1;
3197 0 $refval = -2**$width;
3198 0 undef $self->{DIFFERENCE_STATISTICAL_VALUE};
3199 0 $self->{NUM_CHANGE_OPERATORS}--;
3200 }
3201 }
3202 7474 ▶ _croak "$id Data width <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 7474 7474
3203  
3204 7474 my $value;
3205 7474 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 55 7419 7474
3206 # Extract ASCII string
3207 55 ▶ _croak "Width for unit CCITTIA5 must be integer bytes\n"
Branch: 1 branch
BranchTrueFalseTotal
if $width % 8 0 55 55
3208 . "is $width bits for descriptor $id" if $width % 8;
3209 55 $value = bitstream2ascii($bitstream, $pos, $width/8);
3210 55 ▶ $self->_spew(3, " %s", defined $value ? $value : 'missing') if $Spew;
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 4 51 55
defined $value ? : 4 0 4
3211 # Trim string, also removing nulls
3212 55 $value = _trim($value, $id);
3213 } else {
3214 7419 $value = bitstream2dec($bitstream, $pos, $width);
3215 7419 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 4519 2900 7419
3216 # Compute and format decoded value
3217 4519 ($scale) = $scale =~ /(-?\d+)/; # untaint
3218 4519 ▶ $value = $scale <= 0 ? ($value + $refval)/10**$scale
Branch: 1 branch
BranchTrueFalseTotal
$scale <= 0 ? : 3199 1320 4519
3219 : sprintf "%.${scale}f", ($value + $refval)/10**$scale;
3220 }
3221 7419 ▶ $self->_spew(3, " %s", defined $value ? $value : 'missing') if $Spew;
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 451 6968 7419
defined $value ? : 202 249 451
3222 }
3223 7474 $pos += $width;
3224 7474 push @{$subset_data[$isub]}, $value;
3225 # $value = undef if missing value
3226  
3227 7474 ▶ if ($repeat_X) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat_X) 0 7474 7474
3228 # Delayed repetition factor (030011/030012) is in
3229 # effect, so descriptors and data are to be repeated
3230 0 push @repeat_desc, $id;
3231 0 push @repeat_data, $value;
3232 0 ▶ if (--$repeat_X == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$repeat_X == 0) 0 0 0
3233 # Store $repeat_factor repetitions of data and descriptors
3234 # (one repetition has already been included)
3235 0 ▶ while (--$repeat_factor) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$repeat_factor) 0 0 0
3236 0 push @{$subset_desc[$isub]}, @repeat_desc;
3237 0 push @{$subset_data[$isub]}, @repeat_data;
3238 }
3239 0 @repeat_desc = ();
3240 0 @repeat_data = ();
3241 }
3242 }
3243  
3244 7474 ▶ if ($id eq '031031' and $self->{BUILD_BITMAP}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id eq '031031' and $self->{'BUILD_BITMAP'}) { } 949 6525 7474
elsif ($self->{'BUILD_BITMAP'} and $self->{'BITMAP_INDEX'} > 0) { } 9 12579 12588
Condition66%2/3
$id eq "031031" and $self->{"BUILD_BITMAP"}
!ll&&!rl&&r
65250949
MC/DC50%1/2
$id eq "031031" and $self->{"BUILD_BITMAP"}
$id eq "031031" $self->{"BUILD_BITMAP"}
Truth table66%2/3
A and B
A= $id eq "031031"B= $self->{"BUILD_BITMAP"}
ABresult
0X0
100
111
3245 # Store the index of expanded descriptors if data is
3246 # marked as present in data present indicator: 0 is
3247 # 'present', 1 (undef value) is 'not present'. E.g.
3248 # bitmap = 1100110 => (2,3,6) is stored in $self->{CURRENT_BITMAP}
3249 949 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 208 741 949
3250 208 push @{$self->{CURRENT_BITMAP}}, $self->{BITMAP_INDEX};
3251 }
3252 949 $self->{BITMAP_INDEX}++;
3253 949 ▶ if ($self->{BACKWARD_DATA_REFERENCE} == $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} == $self->{"NUM_BITMAPS"}) 789 160 949
3254 789 my $numb = $self->{NUM_BITMAPS};
3255 789 ▶ if (!defined $self->{BITMAP_START}[$numb]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'BITMAP_START'}[$numb]) { } 8 781 789
3256 # Look up the element descriptor immediately
3257 # preceding the bitmap operator
3258 8 my $i = $idesc;
3259 8 ▶ $i-- while ($desc[$i] ne $self->{BITMAP_OPERATORS}->[-1]
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0 and do { --$i } 17 8 25
Condition66%2/3
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
!ll&&!rl&&r
8017
MC/DC50%1/2
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1]B= $i >= 0
ABresult
0X0
100
111
3260 && $i >=0);
3261 8 ▶ $i-- while ($desc[$i] > 100000 && $i >=0);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] > 100000 and $i >= 0 and do { --$i } 8 8 16
Condition66%2/3
$desc[$i] > 100000 and $i >= 0
!ll&&!rl&&r
808
MC/DC50%1/2
$desc[$i] > 100000 and $i >= 0
$desc[$i] > 100000 $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] > 100000B= $i >= 0
ABresult
0X0
100
111
3262 8 ▶ _croak "No element descriptor preceding bitmap" if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 8 8
3263 8 $self->{BITMAP_START}[$numb] = $i;
3264 } else {
3265 781 $self->{BITMAP_START}[$numb]--;
3266 _croak "Bitmap too big"
3267 781 ▶ if $self->{BITMAP_START}[$numb] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"BITMAP_START"}[$numb] < 0 0 781 781
3268 }
3269 }
3270 ▶ } elsif ($self->{BUILD_BITMAP} and $self->{BITMAP_INDEX} > 0) {
Condition100%3/3
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
!ll&&!rl&&r
60634539
MC/DC100%2/2
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
$self->{"BUILD_BITMAP"} $self->{"BITMAP_INDEX"} > 0
Truth table100%3/3
A and B
A= $self->{"BUILD_BITMAP"}B= $self->{"BITMAP_INDEX"} > 0
ABresult
0X0
100
111
3271 # We have finished building the bit map
3272 9 $self->{BUILD_BITMAP} = 0;
3273 9 $self->{BITMAP_INDEX} = 0;
3274 9 ▶ if ($self->{BACKWARD_DATA_REFERENCE} != $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} != $self->{"NUM_BITMAPS"}) 1 8 9
3275 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3276 1 = $self->{BITMAP_START}[$self->{BACKWARD_DATA_REFERENCE}];
3277 }
3278 }
3279 } # End D_LOOP
3280 } # END S_LOOP
3281  
3282 # Check that length of section 4 corresponds to what expected from section 3
3283 40 $self->_check_section4_length($pos,$maxpos);
3284  
3285 40 $self->{DATA} = \@subset_data;
3286 40 $self->{DESC} = \@subset_desc;
3287 40 return;
3288 }
3289  
3290 ## Decode bitstream (data part of section 4 encoded using BUFR
3291 ## compression) while working through the (expanded) descriptors in
3292 ## section 3. The final data and corresponding descriptors are put in
3293 ## $self->{DATA} and $self->{DESC} (the data indexed by subset number)
3294 sub _decompress_bitstream {
3295 23 ▶ my $self = shift;
Subroutine _decompress_bitstream: called CC=51 SCAR=48.5
3296 23 $self->{CODING} = 'DECODE';
3297 23 my $bitstream = $self->{SEC4_RAWDATA}."\0\0\0\0";
3298 23 my $nsubsets = $self->{NUM_SUBSETS};
3299 23 my $B_table = $self->{B_TABLE};
3300 23 my $maxpos = 8*length($self->{SEC4_RAWDATA});
3301 23 my $pos = 0;
3302 23 my @operators;
3303 my @subset_data; # Will contain data values for subset 1,2...,
3304 # i.e. $subset[$i] is a reference to an array
3305 # containing the data values for subset $i
3306 23 my @desc_exp; # Will contain the set of descriptors for one
3307 # subset, expanded to be in one to one
3308 # correspondance with the data, i.e. element
3309 # descriptors only
3310 23 my $repeat_X; # Set to number of descriptors to be repeated if
3311 # delayed descriptor and data repetition factor is
3312 # in effect. Will be decremented while (repeated)
3313 # data sets are extracted
3314 23 my $repeat_XX; # Like $repeat_X, but will not be decremented
3315 23 my $repeat_factor; # Set to number of times descriptors (and data)
3316 # are to be repeated if delayed descriptor and
3317 # data repetition factor is in effect
3318 23 my @repeat_desc; # The descriptors to be repeated
3319 23 my @repeat_data; # The data to be repeated (reference to an array
3320 # containing the data values for subset $i)
3321  
3322 23 ▶ _complain("Compression set in section 1 for one subset message")
Branch: 1 branch
BranchTrueFalseTotal
if $nsubsets == 1 10 13 23
3323 if $nsubsets == 1;
3324  
3325 18 $#subset_data = $nsubsets;
3326  
3327 18 my @desc = split /\s/, $self->{DESCRIPTORS_EXPANDED};
3328 # This will be further expanded to be in one to one correspondance
3329 # with the data, taking replication and table C operators into account
3330  
3331 # All subsets in a compressed BUFR message must have exactly the same
3332 # fully expanded section 3, i.e. all replications factors must be the same
3333 # in all subsets. So, as opposed to noncompressed messages, it is enough
3334 # to run through the set of descriptors once.
3335 18 ▶ D_LOOP: for (my $idesc = 0; $idesc < @desc; $idesc++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) 1737 16 1753
3336 1769 my $id = $desc[$idesc];
3337 1769 my $f = substr($id,0,1);
3338 1769 my $x = substr($id,1,2)+0;
3339 1769 my $y = substr($id,3,3)+0;
3340  
3341 1769 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 33 1736 1769
elsif ($f == 2) { } 80 1656 1736
3342 33 ▶ if ($Show_replication) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_replication) 7 26 33
3343 7 push @desc_exp, $id;
3344 7 foreach my $isub (1..$nsubsets) {
3345 14 push @{$subset_data[$isub]}, '';
3346 }
3347 7 ▶ $self->_spew(4, "X=0 in $id for F=1, might have been > 99 in expansion")
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew and $x == 0 0 7 7
Condition33%1/3
$Geo::BUFR::Spew and $x == 0
!ll&&!rl&&r
700
MC/DC0%0/2
$Geo::BUFR::Spew and $x == 0
$Geo::BUFR::Spew $x == 0
Truth table33%1/3
A and B
A= $Geo::BUFR::SpewB= $x == 0
ABresult
0X0
100
111
3348 if $Spew && $x == 0;
3349 }
3350 33 ▶ next D_LOOP if $y > 0; # Nothing more to do for normal replication
Branch: 1 branch
BranchTrueFalseTotal
if $y > 0 4 29 33
3351  
3352 29 ▶ if ($x == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0) 0 29 29
3353 0 _complain("Nonsensical replication of zero descriptors ($id)");
3354 0 $idesc++;
3355 0 next D_LOOP;
3356 }
3357  
3358 29 $_ = $desc[$idesc+1];
3359 _croak "$id Erroneous replication factor"
3360 29 ▶ unless /^0310(00|01|02|11|12)/ && exists $B_table->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless /^0310(00|01|02|11|12)/ and exists $B_table->{$_} 0 29 29
Condition33%1/3
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
!ll&&!rl&&r
0029
MC/DC0%0/2
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
/^0310(00|01|02|11|12)/ exists $B_table->{$_}
Truth table33%1/3
A and B
A= /^0310(00|01|02|11|12)/B= exists $B_table->{$_}
ABresult
0X0
100
111
3361  
3362 29 my $width = (split /\0/, $B_table->{$_})[-1];
3363 29 my $factor = bitstream2dec($bitstream, $pos, $width);
3364 29 $pos += $width + 6; # 6 bits for the bit count (which we
3365 # skip because we know it has to be 0
3366 # for delayed replication)
3367 # Delayed descriptor replication factors (and associated
3368 # fields) are the only values in section 4 where all bits
3369 # being 1 is not interpreted as a missing value
3370 29 ▶ if (not defined $factor) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $factor) 0 29 29
3371 0 $factor = 2**$width - 1;
3372 }
3373 # Include the delayed replication in descriptor and data list
3374 29 push @desc_exp, $_;
3375 29 splice @desc, $idesc++, 0, $_;
3376 29 foreach my $isub (1..$nsubsets) {
3377 74 push @{$subset_data[$isub]}, $factor;
3378 }
3379  
3380 29 ▶ if ($_ eq '031011' || $_ eq '031012') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq '031011' or $_ eq '031012') { } 0 29 29
Condition33%1/3
$_ eq "031011" or $_ eq "031012"
l!l&&r!l&&!r
0029
MC/DC0%0/2
$_ eq "031011" or $_ eq "031012"
$_ eq "031011" $_ eq "031012"
Truth table33%1/3
A or B
A= $_ eq "031011"B= $_ eq "031012"
ABresult
1X1
011
000
3381 # For delayed repetition, descriptor *and* data is
3382 # to be repeated
3383 0 $repeat_X = $repeat_XX = $x;
3384 0 $repeat_factor = $factor;
3385 0 ▶ $self->_spew(4, "$_ Delayed repetition factor: $factor") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 0 0
3386 } else {
3387 29 ▶ $self->_spew(4, "$_ Delayed replication factor: $factor") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 29 29
3388 }
3389 29 my @r = ();
3390 29 ▶ push @r, @desc[($idesc+2)..($idesc+$x+1)] while $factor--;
Branch: 1 branch
BranchTrueFalseTotal
$factor-- and do { push @r, @desc[$idesc + 2 .. $idesc + $x + 1] } 67 29 96
3391 29 splice @desc, $idesc, 2+$x, @r;
3392 29 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 29 29
3393 0 ▶ if ($repeat_factor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat_factor) { } 0 0 0
3394 0 $self->_spew(4, "$_ Delayed repetition ($id $_ -> @r)");
3395 } else {
3396 0 $self->_spew(4, "$_ Delayed replication ($id $_ -> @r)");
3397 }
3398 }
3399  
3400 29 ▶ if ($idesc < @desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) { } 29 0 29
3401 29 redo D_LOOP;
3402 } else {
3403 0 last D_LOOP; # Might happen if delayed factor is 0
3404 }
3405  
3406 } elsif ($f == 2) {
3407 80 my $flow;
3408 my $bm_idesc;
3409 80 ($pos, $flow, $bm_idesc, @operators)
3410 = $self->_apply_operator_descriptor($id, $x, $y, $pos, 0,
3411 $desc[$idesc+1], @operators);
3412 80 ▶ if ($flow eq 'redo_bitmap') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flow eq 'redo_bitmap') { } 3 77 80
elsif ($flow eq 'signify_character') { } 0 77 77
elsif ($flow eq 'no_value') { } 12 65 77
3413 # Data value is associated with the descriptor
3414 # defined by bit map. Remember original and new
3415 # index in descriptor array for the bit mapped
3416 # values ('dr' = data reference)
3417 3 my $dr_idesc;
3418 3 ▶ if (!defined $bm_idesc) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bm_idesc) { } 0 3 3
elsif (not $Geo::BUFR::Show_all_operators) { } 2 1 3
3419 0 $dr_idesc = shift @{ $self->{REUSE_BITMAP}->[0] };
3420 } elsif (!$Show_all_operators) {
3421 2 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3422 + $bm_idesc;
3423 } else {
3424 1 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}];
3425 # Skip operator descriptors
3426 1 ▶ while ($bm_idesc-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bm_idesc-- > 0) 2 1 3
3427 2 $dr_idesc++;
3428 2 ▶ $dr_idesc++ while ($desc[$dr_idesc] >= 200000);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$dr_idesc] >= 200000 and do { ++$dr_idesc } 2 2 4
3429 }
3430 }
3431 3 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
3432 $dr_idesc, $idesc;
3433 3 ▶ if ($Show_all_operators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_all_operators) 1 2 3
3434 1 push @desc_exp, $id;
3435 1 foreach my $isub (1..$nsubsets) {
3436 2 push @{$subset_data[$isub]}, '';
3437 }
3438 }
3439 3 $desc[$idesc] = $desc[$dr_idesc];
3440 3 redo D_LOOP;
3441 } elsif ($flow eq 'signify_character') {
3442 0 push @desc_exp, $id;
3443 0 $pos = $self->_extract_compressed_value($id, $idesc, $pos, $bitstream,
3444 $nsubsets, \@subset_data);
3445 0 next D_LOOP;
3446 } elsif ($flow eq 'no_value') {
3447 # Some operator descriptors ought to be included
3448 # in expanded descriptors even though they have no
3449 # corresponding data value, because they contain
3450 # valuable information to be displayed in
3451 # dumpsection4 (e.g. 222000 'Quality information follows')
3452 12 push @desc_exp, $id;
3453 12 foreach my $isub (1..$nsubsets) {
3454 24 push @{$subset_data[$isub]}, '';
3455 }
3456 12 next D_LOOP;
3457 }
3458  
3459 65 ▶ if ($Show_all_operators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_all_operators) { } 52 13 65
3460 52 push @desc_exp, $id;
3461 52 foreach my $isub (1..$nsubsets) {
3462 104 push @{$subset_data[$isub]}, '';
3463 }
3464 } else {
3465 # Remove operator descriptor from @desc
3466 13 splice @desc, $idesc--, 1;
3467 }
3468  
3469 65 ▶ next D_LOOP if $flow eq 'next';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "next" 65 0 65
3470 0 ▶ last D_LOOP if $flow eq 'last';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "last" 0 0 0
3471 0 ▶ if ($flow eq 'skip') {
Branch: 1 branch
BranchTrueFalseTotal
if ($flow eq "skip") 0 0 0
3472 0 $idesc++;
3473 0 next D_LOOP;
3474 }
3475 }
3476  
3477 1656 ▶ if ($self->{CHANGE_REFERENCE_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CHANGE_REFERENCE_VALUE"}) 1 1655 1656
3478 # The data descriptor is to be associated with a new
3479 # reference value, which is fetched from data stream
3480 1 ▶ _croak "Change reference operator 203Y is not followed by element"
Branch: 1 branch
BranchTrueFalseTotal
if $f > 0 0 1 1
3481 . " descriptor, but $id" if $f > 0;
3482 1 my $num_bits = $self->{CHANGE_REFERENCE_VALUE};
3483 1 my $new_refval = bitstream2dec($bitstream, $pos, $num_bits);
3484 1 $pos += $num_bits + 6;
3485 # Negative value if most significant bit is set (one's complement)
3486 1 ▶ $new_refval = $new_refval & (1<<$num_bits-1)
Branch: 1 branch
BranchTrueFalseTotal
$new_refval & 1 << $num_bits - 1 ? : 1 0 1
3487 ? -($new_refval & ((1<<$num_bits-1)-1))
3488 : $new_refval;
3489 1 ▶ $self->_spew(4, "$id * Change reference value: ".
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1 1
$new_refval > 0 ? : 0 0 0
3490 ($new_refval > 0 ? "+" : "")."$new_refval") if $Spew;
3491 1 $self->{NEW_REFVAL_OF}{$id} = $new_refval;
3492 # Identify new reference values by setting f=9
3493 1 push @desc_exp, $id + 900000;
3494 1 foreach my $isub (1..$nsubsets) {
3495 2 push @{$subset_data[$isub]}, $new_refval;
3496 }
3497 1 next D_LOOP;
3498 }
3499  
3500 # If operator 204$y 'Add associated field is in effect',
3501 # each data value is preceded by $y bits which should be
3502 # decoded separately. We choose to provide a descriptor
3503 # 999999 in this case (like the ECMWF BUFRDC software)
3504 1655 ▶ if ($self->{ADD_ASSOCIATED_FIELD} and $id ne '031021') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021") 9 1646 1655
Condition100%3/3
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
!ll&&!rl&&r
163799
MC/DC100%2/2
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
$self->{"ADD_ASSOCIATED_FIELD"} $id ne "031021"
Truth table100%3/3
A and B
A= $self->{"ADD_ASSOCIATED_FIELD"}B= $id ne "031021"
ABresult
0X0
100
111
3505 # First extract associated field
3506 9 push @desc_exp, 999999;
3507 9 $pos = $self->_extract_compressed_value(999999, $idesc, $pos, $bitstream,
3508 $nsubsets, \@subset_data);
3509 }
3510  
3511 # We now have a "real" data descriptor, so add it to the descriptor list
3512 1655 push @desc_exp, $id;
3513  
3514 1655 $pos = $self->_extract_compressed_value($id, $idesc, $pos, $bitstream,
3515 $nsubsets, \@subset_data, \@desc);
3516 1653 ▶ if ($repeat_X) {
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat_X) 0 1653 1653
3517 # Delayed repetition factor (030011/030012) is in
3518 # effect, so descriptors and data are to be repeated
3519 0 push @repeat_desc, $id;
3520 0 foreach my $isub (1..$nsubsets) {
3521 0 push @{$repeat_data[$isub]}, $subset_data[$isub]->[-1];
3522 }
3523 0 ▶ if (--$repeat_X == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$repeat_X == 0) 0 0 0
3524 # Store $repeat_factor repetitions of data and descriptors
3525 # (one repetition has already been included)
3526 0 ▶ while (--$repeat_factor) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$repeat_factor) 0 0 0
3527 0 push @desc_exp, @repeat_desc;
3528 0 foreach my $isub (1..$nsubsets) {
3529 0 push @{$subset_data[$isub]}, @{$repeat_data[$isub]};
3530 }
3531 0 $idesc += $repeat_XX;
3532 }
3533 0 @repeat_desc = ();
3534 0 @repeat_data = ();
3535 0 $repeat_XX = 0;
3536 }
3537 }
3538 }
3539  
3540 # Check that length of section 4 corresponds to what expected from section 3
3541 16 $self->_check_section4_length($pos,$maxpos);
3542  
3543 16 $self->{DATA} = \@subset_data;
3544 16 $self->{DESC} = \@desc_exp;
3545 16 return;
3546 }
3547  
3548 ## Extract the data values for descriptor $id (with index $idesc in
3549 ## the final expanded descriptor array) for each subset, into
3550 ## $subset_data_ref->[$isub], $isub = 1...$nsubsets (number of
3551 ## subsets). Extraction starts at position $pos in $bitstream.
3552 sub _extract_compressed_value {
3553 1664 ▶ my $self = shift;
Subroutine _extract_compressed_value: called CC=82 SCAR=53.8
3554 1664 my ($id, $idesc, $pos, $bitstream, $nsubsets, $subset_data_ref, $desc_ref) = @_;
3555 1664 my $B_table = $self->{B_TABLE};
3556  
3557 # For quality information, if this relates to a bit map we
3558 # need to store index of the data ($data_idesc) for which
3559 # the quality information applies, as well as the new
3560 # index ($idesc) in the descriptor array for the bit
3561 # mapped values
3562 1664 ▶ if (substr($id,0,3) eq '033'
Branch: 1 branch
BranchTrueFalseTotal
if (substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000) 30 1634 1664
Condition83%5/6
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
!ll&&!rl&&r
1634030
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"}
!ll&&!rl&&r
16102430
MC/DC66%2/3
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
substr($id, 0, 3) eq "033" defined $self->{"BITMAP_OPERATORS"} $self->{"BITMAP_OPERATORS"}[-1] eq 222000
Truth table75%3/4
A and B and C
A= substr($id, 0, 3) eq "033"B= defined $self->{"BITMAP_OPERATORS"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 222000
ABCresult
0XX0
10X0
1100
1111
3563 && defined $self->{BITMAP_OPERATORS}
3564 && $self->{BITMAP_OPERATORS}->[-1] eq '222000') {
3565 30 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 20 10 30
3566 20 my $data_idesc = shift @{ $self->{REUSE_BITMAP}->[0] };
3567 20 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 20 20
3568 if not defined $data_idesc;
3569 20 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
3570 $data_idesc, $idesc;
3571 } else {
3572 10 my $data_idesc = shift @{ $self->{CURRENT_BITMAP} };
3573 10 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 10 10
3574 if not defined $data_idesc;
3575 10 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
3576 10 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3577 + $data_idesc, $idesc;
3578 }
3579 }
3580  
3581 # Find the relevant entry in BUFR table B
3582 1664 my ($name,$unit,$scale,$refval,$width);
3583 1664 ▶ if ($id == 999999) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id == 999999) { } 9 1655 1664
elsif ($id =~ /^205(\d\d\d)/) { } 0 1655 1655
3584 9 $name = 'ASSOCIATED FIELD';
3585 9 $unit = 'NUMERIC';
3586 9 $scale = 0;
3587 9 $refval = 0;
3588 9 $width = $self->{ADD_ASSOCIATED_FIELD};
3589 } elsif ($id =~ /^205(\d\d\d)/) { # Signify character
3590 0 $name = 'CHARACTER INFORMATION';
3591 0 $unit = 'CCITTIA5';
3592 0 $scale = 0;
3593 0 $refval = 0;
3594 0 $width = 8*$1;
3595 } else {
3596 _croak "Data descriptor $id is not present in BUFR table B"
3597 1655 ▶ if not exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 1655 1655
3598 1655 ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
3599  
3600 # Override Table B values if Data Description Operators are in effect
3601 1655 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0) 22 1633 1655
3602 22 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 22 0 22
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 0 0 0
Condition33%1/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
0022
MC/DC0%0/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table33%1/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
3603 22 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 0 22 22
3604 0 $scale += $self->{CHANGE_SRW};
3605 0 $width += int((10*$self->{CHANGE_SRW}+2)/3);
3606 0 $refval *= 10*$self->{CHANGE_SRW};
3607 } else {
3608 22 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 13 9 22
3609 22 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 15 7 22
3610 }
3611 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition0%0/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table0%0/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
3612 $width = $self->{CHANGE_CCITTIA5_WIDTH}
3613 0 }
3614 22 ▶ $refval = $self->{NEW_REFVAL_OF}{$id} if defined $self->{NEW_REFVAL_OF}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} 1 21 22
3615 # Difference statistical values use different width and reference value
3616 22 ▶ if ($self->{DIFFERENCE_STATISTICAL_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DIFFERENCE_STATISTICAL_VALUE"}) 0 22 22
3617 0 $width += 1;
3618 0 $refval = -2**$width;
3619 0 undef $self->{DIFFERENCE_STATISTICAL_VALUE};
3620 0 $self->{NUM_CHANGE_OPERATORS}--;
3621 }
3622 }
3623 }
3624 1664 ▶ $self->_spew(3, "%6s %-20s %s", $id, $unit, $name) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1664 1664
3625 1664 ▶ _croak "$id Data width <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 1664 1664
3626  
3627 1664 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 12 1652 1664
3628 # Extract ASCII string ('minimum value')
3629 12 ▶ _croak "Width for unit CCITTIA5 must be integer bytes\n"
Branch: 1 branch
BranchTrueFalseTotal
if $width % 8 0 12 12
3630 . "is $width bits for descriptor $id" if $width % 8;
3631 12 my $minval = bitstream2ascii($bitstream, $pos, $width/8);
3632 12 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 12 12
3633 0 ▶ if ($minval eq "\0" x ($width/8)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($minval eq "\000" x ($width / 8)) { } 0 0 0
3634 0 $self->_spew(5, " Local reference value has all bits zero");
3635 } else {
3636 0 $self->_spew(5, " Local reference value: %s", $minval);
3637 }
3638 }
3639 12 $pos += $width;
3640 # Extract number of bytes for next subsets
3641 12 my $deltabytes = bitstream2dec($bitstream, $pos, 6);
3642 12 ▶ $self->_spew(5, " Increment width (bytes): %d", $deltabytes) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 12 12
3643 12 $pos += 6;
3644 12 ▶ if ($deltabytes && defined $minval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deltabytes and defined $minval) { } 7 5 12
Condition66%2/3
$deltabytes and defined $minval
!ll&&!rl&&r
507
MC/DC50%1/2
$deltabytes and defined $minval
$deltabytes defined $minval
Truth table66%2/3
A and B
A= $deltabytesB= defined $minval
ABresult
0X0
100
111
3645 # Extract compressed data for all subsets. According
3646 # to 94.6.3 (2) (i) in FM 94 BUFR, the first value for
3647 # character data shall be set to all bits zero
3648 7 my $nbytes = $width/8;
3649 7 ▶ _complain("Local reference value for compressed CCITTIA5 data "
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and $minval ne "\0" x $nbytes 4 3 7
Condition66%2/3
$Geo::BUFR::Strict_checking and $minval ne "\0" x $nbytes
!ll&&!rl&&r
304
MC/DC50%1/2
$Geo::BUFR::Strict_checking and $minval ne "\0" x $nbytes
$Geo::BUFR::Strict_checking $minval ne "\0" x $nbytes
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= $minval ne "\0" x $nbytes
ABresult
0X0
100
111
3650 . "hasn't all bits set to zero, but is '$minval'")
3651 if $Strict_checking and $minval ne "\0" x $nbytes;
3652 5 my $incr_values;
3653 5 foreach my $isub (1..$nsubsets) {
3654 23 my $string = bitstream2ascii($bitstream, $pos, $deltabytes);
3655 23 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 23 23
3656 0 ▶ $incr_values .= defined $string ? "$string," : ',';
Branch: 1 branch
BranchTrueFalseTotal
defined $string ? : 0 0 0
3657 }
3658 # Trim string, also removing nulls
3659 23 $string = _trim($string, $id);
3660 23 push @{$subset_data_ref->[$isub]}, $string;
3661 23 $pos += 8*$deltabytes;
3662 }
3663 5 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 5 5
3664 0 chop $incr_values;
3665 0 $self->_spew(5, " Increment values: %s", $incr_values);
3666 }
3667 } else {
3668 # If min value is defined => All subsets set to min value
3669 # If min value is undefined => Data in all subsets are undefined
3670 5 ▶ my $value = defined $minval ? $minval : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $minval ? : 5 0 5
3671 # Trim string, also removing nulls
3672 5 $value = _trim($value, $id);
3673 5 foreach my $isub (1..$nsubsets) {
3674 5 push @{$subset_data_ref->[$isub]}, $value;
3675 }
3676 5 $pos += $nsubsets*8*$deltabytes;
3677 }
3678 $self->_spew(3, " %s", join ',',
3679 10 ▶ map { defined($subset_data_ref->[$_][-1]) ?
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 10 10
defined $subset_data_ref->[$_][-1] ? : 0 0 0
3680 $subset_data_ref->[$_][-1] : 'missing'} 1..$nsubsets) if $Spew;
3681 } else {
3682 # Extract minimum value
3683 1652 my $minval = bitstream2dec($bitstream, $pos, $width);
3684 1652 ▶ $minval += $refval if defined $minval;
Branch: 1 branch
BranchTrueFalseTotal
if defined $minval 944 708 1652
3685 1652 $pos += $width;
3686 1652 ▶ $self->_spew(5, " Local reference value: %d", $minval) if $Spew && defined $minval;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew and defined $minval 0 1652 1652
Condition33%1/3
$Geo::BUFR::Spew and defined $minval
!ll&&!rl&&r
165200
MC/DC0%0/2
$Geo::BUFR::Spew and defined $minval
$Geo::BUFR::Spew defined $minval
Truth table33%1/3
A and B
A= $Geo::BUFR::SpewB= defined $minval
ABresult
0X0
100
111
3687  
3688 # Extract number of bits for next subsets
3689 1652 my $deltabits = bitstream2dec($bitstream, $pos, 6);
3690 1652 $pos += 6;
3691 1652 ▶ $self->_spew(5, " Increment width (bits): %d", $deltabits) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1652 1652
3692  
3693 1652 ▶ if ($deltabits && defined $minval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deltabits and defined $minval) { } 372 1280 1652
Condition66%2/3
$deltabits and defined $minval
!ll&&!rl&&r
12800372
MC/DC50%1/2
$deltabits and defined $minval
$deltabits defined $minval
Truth table66%2/3
A and B
A= $deltabitsB= defined $minval
ABresult
0X0
100
111
3694 # Extract compressed data for all subsets
3695 372 my $incr_values;
3696 372 foreach my $isub (1..$nsubsets) {
3697 1611 my $value = bitstream2dec($bitstream, $pos, $deltabits);
3698 1611 ▶ _complain("value " . ($value + $minval) . " in subset $isub for "
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and defined $value and $value + $minval > 2 ** $width 0 1611 1611
Condition83%5/6
$Geo::BUFR::Strict_checking and defined $value and $value + $minval > 2 ** $width
!ll&&!rl&&r
9156960
$Geo::BUFR::Strict_checking and defined $value
!ll&&!rl&&r
704211696
MC/DC0%0/3
$Geo::BUFR::Strict_checking and defined $value and $value + $minval > 2 ** $width
$Geo::BUFR::Strict_checking defined $value $value + $minval > 2 ** $width
Truth table75%3/4
A and B and C
A= $Geo::BUFR::Strict_checkingB= defined $valueC= $value + $minval > 2 ** $width
ABCresult
0XX0
10X0
1100
1111
3699 . "$id too big to be encoded without compression")
3700 if ($Strict_checking && defined $value &&
3701 ($value + $minval) > 2**$width);
3702 1611 ▶ $incr_values .= defined $value ? "$value," : ',' if $Spew;
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1611 1611
defined $value ? : 0 0 0
3703 1611 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 1310 301 1611
3704 # Compute and format decoded value
3705 1310 ($scale) = $scale =~ /(-?\d+)/; # untaint
3706 1310 ▶ $value = $scale <= 0 ? ($value + $minval)/10**$scale
Branch: 1 branch
BranchTrueFalseTotal
$scale <= 0 ? : 523 787 1310
3707 : sprintf "%.${scale}f", ($value + $minval)/10**$scale;
3708 }
3709 # All bits set to 1 for associated field is NOT
3710 # interpreted as missing value
3711 1611 ▶ if ($id == 999999 and ! defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 999999 and not defined $value) 0 1611 1611
Condition33%1/3
$id == 999999 and not defined $value
!ll&&!rl&&r
161100
MC/DC0%0/2
$id == 999999 and not defined $value
$id == 999999 not defined $value
Truth table33%1/3
A and not(B)
A= $id == 999999B= not defined $value
ABresult
0X0
100
111
3712 0 $value = 2**$width - 1;
3713 }
3714 1611 push @{$subset_data_ref->[$isub]}, $value;
3715 1611 $pos += $deltabits;
3716 }
3717 372 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 372 372
3718 0 chop $incr_values;
3719 0 $self->_spew(5, " Increment values: %s", $incr_values);
3720 }
3721 } else {
3722 # If minimum value is defined => All subsets set to minimum value
3723 # If minimum value is undefined => Data in all subsets are undefined
3724 1280 my $value;
3725 1280 ▶ if (defined $minval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minval) 572 708 1280
3726 # Compute and format decoded value
3727 572 ($scale) = $scale =~ /(-?\d+)/; # untaint
3728 572 ▶ $value = $scale <= 0 ? $minval/10**$scale
Branch: 1 branch
BranchTrueFalseTotal
$scale <= 0 ? : 469 103 572
3729 : sprintf "%.${scale}f", $minval/10**$scale;
3730 }
3731 # Exception: all bits set to 1 for associated field is NOT
3732 # interpreted as missing value
3733 1280 ▶ if ($id == 999999 and ! defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($id == 999999 and not defined $value) 9 1271 1280
Condition66%2/3
$id == 999999 and not defined $value
!ll&&!rl&&r
127109
MC/DC50%1/2
$id == 999999 and not defined $value
$id == 999999 not defined $value
Truth table66%2/3
A and not(B)
A= $id == 999999B= not defined $value
ABresult
0X0
100
111
3734 9 $value = 2**$width - 1;
3735 }
3736 1280 foreach my $isub (1..$nsubsets) {
3737 3101 push @{$subset_data_ref->[$isub]}, $value;
3738 }
3739 1280 ▶ $pos += $nsubsets*$deltabits if defined $deltabits;
Branch: 1 branch
BranchTrueFalseTotal
if defined $deltabits 1280 0 1280
3740 }
3741  
3742 # Bit maps need special treatment. We are only able to
3743 # handle those where all subsets have exactly the same
3744 # bit map with the present method.
3745 1652 ▶ if ($id eq '031031' and $self->{BUILD_BITMAP}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id eq '031031' and $self->{'BUILD_BITMAP'}) { } 115 1537 1652
elsif ($self->{'BUILD_BITMAP'} and $self->{'BITMAP_INDEX'} > 0) { } 4 3042 3046
Condition66%2/3
$id eq "031031" and $self->{"BUILD_BITMAP"}
!ll&&!rl&&r
15370115
MC/DC50%1/2
$id eq "031031" and $self->{"BUILD_BITMAP"}
$id eq "031031" $self->{"BUILD_BITMAP"}
Truth table66%2/3
A and B
A= $id eq "031031"B= $self->{"BUILD_BITMAP"}
ABresult
0X0
100
111
3746 115 ▶ _croak "$id: Unable to handle bit maps which differ between subsets"
Branch: 1 branch
BranchTrueFalseTotal
if $deltabits 0 115 115
3747 . " in compressed data" if $deltabits;
3748 # Store the index of expanded descriptors if data is
3749 # marked as present in data present indicator: 0 is
3750 # 'present', 1 (undef value) is 'not present'
3751 115 ▶ if (defined $minval) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minval) 13 102 115
3752 13 push @{$self->{CURRENT_BITMAP}}, $self->{BITMAP_INDEX};
3753 }
3754 115 $self->{BITMAP_INDEX}++;
3755 115 ▶ if ($self->{BACKWARD_DATA_REFERENCE} == $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} == $self->{"NUM_BITMAPS"}) 115 0 115
3756 115 my $numb = $self->{NUM_BITMAPS};
3757 115 ▶ if (!defined $self->{BITMAP_START}[$numb]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'BITMAP_START'}[$numb]) { } 4 111 115
3758 # Look up the element descriptor immediately
3759 # preceding the bitmap operator
3760 4 my $i = $idesc;
3761 4 ▶ $i-- while ($desc_ref->[$i] ne $self->{BITMAP_OPERATORS}->[-1]
Branch: 1 branch
BranchTrueFalseTotal
$desc_ref->[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0 and do { --$i } 11 4 15
Condition66%2/3
$desc_ref->[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
!ll&&!rl&&r
4011
MC/DC50%1/2
$desc_ref->[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
$desc_ref->[$i] ne $self->{"BITMAP_OPERATORS"}[-1] $i >= 0
Truth table66%2/3
A and B
A= $desc_ref->[$i] ne $self->{"BITMAP_OPERATORS"}[-1]B= $i >= 0
ABresult
0X0
100
111
3762 && $i >=0);
3763 4 ▶ $i-- while ($desc_ref->[$i] > 100000 && $i >=0);
Branch: 1 branch
BranchTrueFalseTotal
$desc_ref->[$i] > 100000 and $i >= 0 and do { --$i } 4 4 8
Condition66%2/3
$desc_ref->[$i] > 100000 and $i >= 0
!ll&&!rl&&r
404
MC/DC50%1/2
$desc_ref->[$i] > 100000 and $i >= 0
$desc_ref->[$i] > 100000 $i >= 0
Truth table66%2/3
A and B
A= $desc_ref->[$i] > 100000B= $i >= 0
ABresult
0X0
100
111
3764 4 ▶ _croak "No element descriptor preceding bitmap" if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 4 4
3765 4 $self->{BITMAP_START}[$numb] = $i;
3766 } else {
3767 111 ▶ if ($Show_all_operators) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Show_all_operators) { } 3 108 111
3768 3 my $i = $self->{BITMAP_START}[$numb] - 1;
3769 3 ▶ $i-- while ($desc_ref->[$i] > 100000 && $i >=0);
Branch: 1 branch
BranchTrueFalseTotal
$desc_ref->[$i] > 100000 and $i >= 0 and do { --$i } 2 3 5
Condition66%2/3
$desc_ref->[$i] > 100000 and $i >= 0
!ll&&!rl&&r
302
MC/DC50%1/2
$desc_ref->[$i] > 100000 and $i >= 0
$desc_ref->[$i] > 100000 $i >= 0
Truth table66%2/3
A and B
A= $desc_ref->[$i] > 100000B= $i >= 0
ABresult
0X0
100
111
3770 3 $self->{BITMAP_START}[$numb] = $i;
3771 } else {
3772 108 $self->{BITMAP_START}[$numb]--;
3773 }
3774 _croak "Bitmap too big"
3775 111 ▶ if $self->{BITMAP_START}[$numb] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"BITMAP_START"}[$numb] < 0 0 111 111
3776 }
3777 }
3778 ▶ } elsif ($self->{BUILD_BITMAP} and $self->{BITMAP_INDEX} > 0) {
Condition100%3/3
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
!ll&&!rl&&r
1509244
MC/DC100%2/2
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
$self->{"BUILD_BITMAP"} $self->{"BITMAP_INDEX"} > 0
Truth table100%3/3
A and B
A= $self->{"BUILD_BITMAP"}B= $self->{"BITMAP_INDEX"} > 0
ABresult
0X0
100
111
3779 # We have finished building the bit map
3780 4 $self->{BUILD_BITMAP} = 0;
3781 4 $self->{BITMAP_INDEX} = 0;
3782 4 ▶ if ($self->{BACKWARD_DATA_REFERENCE} != $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} != $self->{"NUM_BITMAPS"}) 0 4 4
3783 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
3784 0 = $self->{BITMAP_START}[$self->{BACKWARD_DATA_REFERENCE}];
3785 }
3786 }
3787 $self->_spew(3, " %s", join ' ',
3788 1652 ▶ map { defined($subset_data_ref->[$_][-1]) ?
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1652 1652
defined $subset_data_ref->[$_][-1] ? : 0 0 0
3789 $subset_data_ref->[$_][-1] : 'missing'} 1..$nsubsets) if $Spew;
3790 }
3791 1662 return $pos;
3792 }
3793  
3794 ## Takes a text $decoded_message as argument and returns BUFR messages
3795 ## which would give the same output as $decoded_message when running
3796 ## dumpsection0(), dumpsection1(), dumpsection3() and dumpsection4() in
3797 ## turn on each of the reencoded BUFR messages
3798 sub reencode_message {
3799 18 ▶ my $self = shift;
Subroutine reencode_message: called CC=27 SCAR=33.3
Pod undocumented
3800 18 my $decoded_message = shift;
3801 18 ▶ my $width = shift || 15; # Optional argument
Condition50%1/2
shift() || 15
l!l
180
MC/DC0%0/1
shift() || 15
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
3802 # Data values usually start at column 31, but if a $width
3803 # different from 15 was used in dumpsection4 you should use the
3804 # same value here
3805  
3806 18 my @lines = split /\n/, $decoded_message;
3807 18 my $bufr_messages = '';
3808 18 my $i = 0;
3809  
3810 18 ▶ MESSAGE: while ($i < @lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines) 36 0 36
3811 # Some tidying after decoding of previous message might be
3812 # necessary
3813 36 $self->{NUM_CHANGE_OPERATORS} = 0;
3814 36 undef $self->{CHANGE_WIDTH};
3815 36 undef $self->{CHANGE_CCITTIA5_WIDTH};
3816 36 undef $self->{CHANGE_SCALE};
3817 36 undef $self->{CHANGE_REFERENCE_VALUE};
3818 36 undef $self->{NEW_REFVAL_OF};
3819 36 undef $self->{CHANGE_SRW};
3820 36 undef $self->{ADD_ASSOCIATED_FIELD};
3821 36 undef $self->{BITMAPS};
3822 36 undef $self->{BITMAP_OPERATORS};
3823 36 undef $self->{REUSE_BITMAP};
3824 36 $self->{NUM_BITMAPS} = 0;
3825 # $self->{LOCAL_USE} is always set for BUFR edition < 4 in _encode_sec1
3826 36 undef $self->{LOCAL_USE};
3827  
3828 # Extract section 0 info
3829 36 ▶ $i++ while $lines[$i] !~ /^Section 0/ and $i < @lines-1;
Branch: 1 branch
BranchTrueFalseTotal
not $lines[$i] =~ /^Section 0/ and $i < @lines - 1 and do { ++$i } 54 36 90
Condition100%3/3
not $lines[$i] =~ /^Section 0/ and $i < @lines - 1
!ll&&!rl&&r
181854
MC/DC100%2/2
not $lines[$i] =~ /^Section 0/ and $i < @lines - 1
not $lines[$i] =~ /^Section 0/ $i < @lines - 1
Truth table100%3/3
not(A) and B
A= not $lines[$i] =~ /^Section 0/B= $i < @lines - 1
ABresult
0X0
100
111
3830 36 ▶ last MESSAGE if $i >= @lines-1; # Not containing any decoded BUFR message
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @lines - 1 18 18 36
3831 18 $i++; # Skip length of BUFR message
3832 18 ($self->{BUFR_EDITION}) = $lines[++$i]
3833 =~ /BUFR edition:\s+(\d+)/;
3834 _croak "BUFR edition number not provided or is not a number"
3835 18 ▶ unless defined $self->{BUFR_EDITION};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"BUFR_EDITION"} 0 18 18
3836  
3837 # Extract section 1 info
3838 18 ▶ $i++ while $lines[$i] !~ /^Section 1/;
Branch: 1 branch
BranchTrueFalseTotal
$lines[$i] =~ /^Section 1/ or do { ++$i } 36 18 54
3839 18 ▶ _croak "reencode_message: Don't find decoded section 1" if $i >= @lines;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @lines 0 18 18
3840 18 $i++; # Skip length of section 1
3841 18 ▶ if ($self->{BUFR_EDITION} < 4 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'BUFR_EDITION'} < 4) { } 11 7 18
elsif ($self->{'BUFR_EDITION'} == 4) { } 7 0 7
3842 11 ($self->{MASTER_TABLE}) = $lines[++$i]
3843 =~ /BUFR master table:\s+(\d+)/;
3844 11 ($self->{SUBCENTRE}) = $lines[++$i]
3845 =~ /Originating subcentre:\s+(\d+)/;
3846 11 ($self->{CENTRE}) = $lines[++$i]
3847 =~ /Originating centre:\s+(\d+)/;
3848 11 ($self->{UPDATE_NUMBER}) = $lines[++$i]
3849 =~ /Update sequence number:\s+(\d+)/;
3850 11 ($self->{OPTIONAL_SECTION}) = $lines[++$i]
3851 =~ /Optional section present:\s+(\d+)/;
3852 11 ($self->{DATA_CATEGORY}) = $lines[++$i]
3853 =~ /Data category \(table A\):\s+(\d+)/;
3854 11 ($self->{DATA_SUBCATEGORY}) = $lines[++$i]
3855 =~ /Data subcategory:\s+(\d+)/;
3856 11 ($self->{MASTER_TABLE_VERSION}) = $lines[++$i]
3857 =~ /Master table version number:\s+(\d+)/;
3858 11 ($self->{LOCAL_TABLE_VERSION}) = $lines[++$i]
3859 =~ /Local table version number:\s+(\d+)/;
3860 11 ($self->{YEAR_OF_CENTURY}) = $lines[++$i]
3861 =~ /Year of century:\s+(\d+)/;
3862 11 ($self->{MONTH}) = $lines[++$i]
3863 =~ /Month:\s+(\d+)/;
3864 11 ($self->{DAY}) = $lines[++$i]
3865 =~ /Day:\s+(\d+)/;
3866 11 ($self->{HOUR}) = $lines[++$i]
3867 =~ /Hour:\s+(\d+)/;
3868 11 ($self->{MINUTE}) = $lines[++$i]
3869 =~ /Minute:\s+(\d+)/;
3870 _croak "reencode_message: Something seriously wrong in decoded section 1"
3871 11 ▶ unless defined $self->{MINUTE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"MINUTE"} 0 11 11
3872 } elsif ($self->{BUFR_EDITION} == 4) {
3873 7 ($self->{MASTER_TABLE}) = $lines[++$i]
3874 =~ /BUFR master table:\s+(\d+)/;
3875 7 ($self->{CENTRE}) = $lines[++$i]
3876 =~ /Originating centre:\s+(\d+)/;
3877 7 ($self->{SUBCENTRE}) = $lines[++$i]
3878 =~ /Originating subcentre:\s+(\d+)/;
3879 7 ($self->{UPDATE_NUMBER}) = $lines[++$i]
3880 =~ /Update sequence number:\s+(\d+)/;
3881 7 ($self->{OPTIONAL_SECTION}) = $lines[++$i]
3882 =~ /Optional section present:\s+(\d+)/;
3883 7 ($self->{DATA_CATEGORY}) = $lines[++$i]
3884 =~ /Data category \(table A\):\s+(\d+)/;
3885 7 ($self->{INT_DATA_SUBCATEGORY}) = $lines[++$i]
3886 =~ /International data subcategory:\s+(\d+)/;
3887 7 ($self->{LOC_DATA_SUBCATEGORY}) = $lines[++$i]
3888 =~ /Local data subcategory:\s+(\d+)/;
3889 7 ($self->{MASTER_TABLE_VERSION}) = $lines[++$i]
3890 =~ /Master table version number:\s+(\d+)/;
3891 7 ($self->{LOCAL_TABLE_VERSION}) = $lines[++$i]
3892 =~ /Local table version number:\s+(\d+)/;
3893 7 ($self->{YEAR}) = $lines[++$i]
3894 =~ /Year:\s+(\d+)/;
3895 7 ($self->{MONTH}) = $lines[++$i]
3896 =~ /Month:\s+(\d+)/;
3897 7 ($self->{DAY}) = $lines[++$i]
3898 =~ /Day:\s+(\d+)/;
3899 7 ($self->{HOUR}) = $lines[++$i]
3900 =~ /Hour:\s+(\d+)/;
3901 7 ($self->{MINUTE}) = $lines[++$i]
3902 =~ /Minute:\s+(\d+)/;
3903 7 ($self->{SECOND}) = $lines[++$i]
3904 =~ /Second:\s+(\d+)/;
3905 _croak "reencode_message: Something seriously wrong in decoded section 1"
3906 7 ▶ unless defined $self->{SECOND};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"SECOND"} 0 7 7
3907 }
3908  
3909 # Extract section 3 info
3910 18 ▶ $i++ while $lines[$i] !~ /^Section 3/;
Branch: 1 branch
BranchTrueFalseTotal
$lines[$i] =~ /^Section 3/ or do { ++$i } 36 18 54
3911 18 ▶ _croak "reencode_message: Don't find decoded section 3" if $i >= @lines;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @lines 0 18 18
3912 18 $i++; # Skip length of section 3
3913  
3914 18 ($self->{NUM_SUBSETS}) = $lines[++$i]
3915 =~ /Number of data subsets:\s+(\d+)/;
3916 _croak "Don't support reencoding of 0 subset message"
3917 18 ▶ if $self->{NUM_SUBSETS} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NUM_SUBSETS"} == 0 0 18 18
3918 18 ($self->{OBSERVED_DATA}) = $lines[++$i]
3919 =~ /Observed data:\s+(\d+)/;
3920 18 ($self->{COMPRESSED_DATA}) = $lines[++$i]
3921 =~ /Compressed data:\s+(\d+)/;
3922 18 ($self->{DESCRIPTORS_UNEXPANDED}) = $lines[++$i]
3923 =~ /Data descriptors unexpanded:\s+(\d+.*)/;
3924 _croak "reencode_message: Something seriously wrong in decoded section 3"
3925 18 ▶ unless defined $self->{DESCRIPTORS_UNEXPANDED};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"DESCRIPTORS_UNEXPANDED"} 0 18 18
3926  
3927 # Extract data values to use in section 4
3928 18 my ($data_refs, $desc_refs);
3929 18 my $subset = 0;
3930 18 ▶ SUBSET: while ($i < @lines-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @lines - 1) 3999 18 4017
3931 3999 $_ = $lines[++$i];
3932 3999 ▶ next SUBSET if /^$/ or /^Subset/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ or /^Subset/ 93 3906 3999
Condition100%3/3
/^$/ or /^Subset/
l!l&&r!l&&!r
62313906
MC/DC100%2/2
/^$/ or /^Subset/
/^$/ /^Subset/
Truth table100%3/3
A or B
A= /^$/B= /^Subset/
ABresult
1X1
011
000
3933 3906 ▶ last SUBSET if /^Message/;
Branch: 1 branch
BranchTrueFalseTotal
if /^Message/ 0 3906 3906
3934 3906 $_ = substr $_, 0, $width + 16;
3935 3906 s/^\s+//;
3936 3906 ▶ next SUBSET if not /^\d/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^\d/ 0 3906 3906
3937 3906 my ($n, $desc, $value) = split /\s+/, $_, 3;
3938 3906 ▶ $subset++ if $n == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 1 31 3875 3906
3939 3906 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 3861 45 3906
3940 3861 $value =~ s/\s+$//;
3941 3861 ▶ $value = undef if $value eq '' or $value eq 'missing';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "" or $value eq "missing" 624 3237 3861
Condition66%2/3
$value eq "" or $value eq "missing"
l!l&&r!l&&!r
06243237
MC/DC50%1/2
$value eq "" or $value eq "missing"
$value eq "" $value eq "missing"
Truth table66%2/3
A or B
A= $value eq ""B= $value eq "missing"
ABresult
1X1
011
000
3942 } else {
3943 # Some descriptors are not numbered (like 222000)
3944 45 $desc = $n;
3945 45 $value = '';
3946 }
3947 3906 push @{$data_refs->[$subset]}, $value;
3948 3906 push @{$desc_refs->[$subset]}, $desc;
3949 }
3950  
3951 # If optional section is present, pretend it is not, because we
3952 # are not able to encode this section
3953 18 ▶ if ($self->{OPTIONAL_SECTION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTIONAL_SECTION"}) 0 18 18
3954 0 $self->{OPTIONAL_SECTION} = 0;
3955 0 carp "Warning: 'Optional section present' changed from 1 to 0'\n";
3956 }
3957  
3958 18 $bufr_messages .= $self->encode_message($data_refs, $desc_refs);
3959 }
3960  
3961 18 return $bufr_messages;
3962 }
3963  
3964  
3965 ## Encode a new BUFR message. All relevant metadata
3966 ## ($self->{BUFR_EDITION} etc) must have been initialized already or
3967 ## else the _encode_sec routines will croak.
3968 sub encode_message {
3969 26 ▶ my $self = shift;
Subroutine encode_message: called CC=5 SCAR=16.1
Pod undocumented
3970 26 my ($data_refs, $desc_refs) = @_;
3971  
3972 26 ▶ _croak "encode_message: No data/descriptors provided" unless $desc_refs;
Branch: 1 branch
BranchTrueFalseTotal
unless $desc_refs 0 26 26
3973  
3974 26 $self->{MESSAGE_NUMBER}++;
3975 26 ▶ $self->_spew(2, "Encoding message number %d", $self->{MESSAGE_NUMBER}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 1 25 26
3976  
3977 26 $self->load_BDtables();
3978  
3979 26 ▶ $self->_spew(2, "Encoding section 1-3") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 1 25 26
3980 26 my $sec1_stream = $self->_encode_sec1();
3981 26 my $sec2_stream = $self->_encode_sec2();
3982 26 my $sec3_stream = $self->_encode_sec3();
3983 26 ▶ $self->_spew(2, "Encoding section 4") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 1 25 26
3984 26 my $sec4_stream = $self->_encode_sec4($data_refs, $desc_refs);
3985  
3986 # Compute length of whole message and encode section 0
3987 26 my $msg_len = 8 + length($sec1_stream) + length($sec2_stream)
3988 + length($sec3_stream) + length($sec4_stream) + 4;
3989 26 my $msg_len_binary = pack("N", $msg_len);
3990 26 my $bufr_edition_binary = pack('n', $self->{BUFR_EDITION});
3991 26 my $sec0_stream = 'BUFR' . substr($msg_len_binary,1,3)
3992 . substr($bufr_edition_binary,1,1);
3993  
3994 26 my $new_message = $sec0_stream . $sec1_stream . $sec2_stream
3995 . $sec3_stream . $sec4_stream . '7777';
3996 26 return $new_message;
3997 }
3998  
3999 ## Encode and return section 1
4000 sub _encode_sec1 {
4001 27 ▶ my $self = shift;
Subroutine _encode_sec1: called CC=15 SCAR=28.4
4002  
4003 my $bufr_edition = $self->{BUFR_EDITION} or
4004 27 ▶ _croak "_encode_sec1: BUFR edition not defined";
Branch: 1 branch
BranchTrueFalseTotal
my $bufr_edition = $self->{"BUFR_EDITION"} or _croak("_encode_sec1: BUFR edition not defined") 0 27 27
4005  
4006 27 my @keys = qw( MASTER_TABLE CENTRE SUBCENTRE UPDATE_NUMBER
4007 OPTIONAL_SECTION DATA_CATEGORY MASTER_TABLE_VERSION
4008 LOCAL_TABLE_VERSION MONTH DAY HOUR MINUTE );
4009 27 ▶ if ($bufr_edition < 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bufr_edition < 4) { } 15 12 27
elsif ($bufr_edition == 4) { } 12 0 12
4010 15 push @keys, qw( DATA_SUBCATEGORY YEAR_OF_CENTURY );
4011 } elsif ($bufr_edition == 4) {
4012 12 push @keys, qw( INT_DATA_SUBCATEGORY LOC_DATA_SUBCATEGORY YEAR SECOND );
4013 }
4014  
4015 # Check that the required variables for section 1 are provided
4016 27 foreach my $key (@keys) {
4017 _croak "_encode_sec1: $key not given"
4018 402 ▶ unless defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 0 402 402
4019 }
4020  
4021 27 ▶ $self->_validate_datetime() if ($Strict_checking);
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking 22 5 27
4022  
4023 27 my $sec1_stream;
4024 # Byte 4-
4025 27 ▶ if ($bufr_edition < 4) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bufr_edition < 4) { } 15 12 27
elsif ($bufr_edition == 4) { } 12 0 12
4026 15 ▶ $self->{LOCAL_USE} = "\0" if !defined $self->{LOCAL_USE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"LOCAL_USE"} 15 0 15
4027 $sec1_stream = pack 'C14a*',
4028 $self->{MASTER_TABLE},
4029 $self->{SUBCENTRE},
4030 $self->{CENTRE},
4031 $self->{UPDATE_NUMBER},
4032 $self->{OPTIONAL_SECTION} ? 128 : 0,
4033 $self->{DATA_CATEGORY},
4034 $self->{DATA_SUBCATEGORY},
4035 $self->{MASTER_TABLE_VERSION},
4036 $self->{LOCAL_TABLE_VERSION},
4037 $self->{YEAR_OF_CENTURY},
4038 $self->{MONTH},
4039 $self->{DAY},
4040 $self->{HOUR},
4041 $self->{MINUTE},
4042 15 ▶ $self->{LOCAL_USE};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'OPTIONAL_SECTION'} ? : 0 15 15
4043 } elsif ($bufr_edition == 4) {
4044 $sec1_stream = pack 'CnnC7nC5',
4045 $self->{MASTER_TABLE},
4046 $self->{CENTRE},
4047 $self->{SUBCENTRE},
4048 $self->{UPDATE_NUMBER},
4049 $self->{OPTIONAL_SECTION} ? 128 : 0,
4050 $self->{DATA_CATEGORY},
4051 $self->{INT_DATA_SUBCATEGORY},
4052 $self->{LOC_DATA_SUBCATEGORY},
4053 $self->{MASTER_TABLE_VERSION},
4054 $self->{LOCAL_TABLE_VERSION},
4055 $self->{YEAR},
4056 $self->{MONTH},
4057 $self->{DAY},
4058 $self->{HOUR},
4059 $self->{MINUTE},
4060 12 ▶ $self->{SECOND};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'OPTIONAL_SECTION'} ? : 0 12 12
4061 $sec1_stream .= pack 'a*', $self->{LOCAL_USE}
4062 12 ▶ if defined $self->{LOCAL_USE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"LOCAL_USE"} 1 11 12
4063 }
4064  
4065 27 my $sec1_len = 3 + length $sec1_stream;
4066 27 ▶ if ($bufr_edition < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bufr_edition < 4) 15 12 27
4067 # Each section should be an even number of octets
4068 15 ▶ if ($sec1_len % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec1_len % 2) 0 15 15
4069 0 $sec1_stream .= "\0";
4070 0 $sec1_len++;
4071 }
4072 }
4073  
4074 # Byte 1-3
4075 27 my $sec1_len_binary = substr pack("N", $sec1_len), 1, 3;
4076  
4077 27 return $sec1_len_binary . $sec1_stream;
4078 }
4079  
4080 ## Encode and return section 2 (empty string if no optional section)
4081 sub _encode_sec2 {
4082 26 ▶ my $self = shift;
Subroutine _encode_sec2: called CC=3 SCAR=15.1
4083 26 ▶ if ($self->{OPTIONAL_SECTION}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'OPTIONAL_SECTION'}) { } 0 26 26
4084 _croak "_encode_sec2: No optional section provided"
4085 0 ▶ unless defined $self->{SEC2_STREAM};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"SEC2_STREAM"} 0 0 0
4086 0 return $self->{SEC2_STREAM};
4087 } else {
4088 26 return '';
4089 }
4090 }
4091  
4092 ## Encode and return section 3
4093 sub _encode_sec3 {
4094 27 ▶ my $self = shift;
Subroutine _encode_sec3: called CC=6 SCAR=17.9
4095  
4096 # Check that the required variables for section 3 are provided
4097 27 foreach my $key (qw(NUM_SUBSETS OBSERVED_DATA COMPRESSED_DATA
4098 DESCRIPTORS_UNEXPANDED)) {
4099 _croak "_encode_sec3: $key not given"
4100 108 ▶ unless defined $self->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$key} 0 108 108
4101 }
4102  
4103 27 my @desc = split / /, $self->{DESCRIPTORS_UNEXPANDED};
4104  
4105 # Byte 5-6
4106 27 my $nsubsets_binary = pack "n", $self->{NUM_SUBSETS};
4107  
4108 # Byte 7
4109 my $flag = pack 'C', $self->{OBSERVED_DATA}*128 +
4110 27 $self->{COMPRESSED_DATA}*64;
4111  
4112 # Byte 8-
4113 27 my $desc_binary = "\0\0" x @desc;
4114 27 my $pos = 0;
4115 27 foreach my $desc (@desc) {
4116 229 my $f = substr($desc,0,1);
4117 229 my $x = substr($desc,1,2)+0;
4118 229 my $y = substr($desc,3,3)+0;
4119 229 dec2bitstream($f, $desc_binary, $pos, 2);
4120 229 $pos += 2;
4121 229 dec2bitstream($x, $desc_binary, $pos, 6);
4122 229 $pos += 6;
4123 229 dec2bitstream($y, $desc_binary, $pos, 8);
4124 229 $pos += 8;
4125 }
4126  
4127 27 my $sec3_len = 7 + length $desc_binary;
4128 27 ▶ if ($self->{BUFR_EDITION} < 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BUFR_EDITION"} < 4) 15 12 27
4129 # Each section should be an even number of octets
4130 15 ▶ if ($sec3_len % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sec3_len % 2) 15 0 15
4131 15 $desc_binary .= "\0";
4132 15 $sec3_len++;
4133 }
4134 }
4135  
4136 # Byte 1-4
4137 27 my $sec3_len_binary = pack("N", $sec3_len);
4138 27 my $sec3_start = substr($sec3_len_binary, 1, 3) . "\0";
4139  
4140 27 return $sec3_start . $nsubsets_binary . $flag . $desc_binary;
4141 }
4142  
4143 ## Encode and return section 4
4144 sub _encode_sec4 {
4145 26 ▶ my $self = shift;
Subroutine _encode_sec4: called CC=3 SCAR=11.0
4146 26 my ($data_refs, $desc_refs) = @_;
4147  
4148 # Check that dimension of argument arrays agrees with number of
4149 # subsets in section 3
4150 26 my $nsubsets = $self->{NUM_SUBSETS};
4151 26 ▶ _croak "Wrong number of subsets ($nsubsets) in section 3?\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @$desc_refs == $nsubsets + 1 0 26 26
4152 . "Disagrees with dimension of descriptor array used as argument "
4153 . "to encode_message()"
4154 unless @$desc_refs == $nsubsets + 1;
4155  
4156 my ($bitstream, $byte_len) = $self->{COMPRESSED_DATA}
4157 26 ▶ ? $self->_encode_compressed_bitstream($data_refs, $desc_refs)
Branch: 1 branch
BranchTrueFalseTotal
$self->{'COMPRESSED_DATA'} ? : 6 20 26
4158 : $self->_encode_bitstream($data_refs, $desc_refs);
4159  
4160 26 my $sec4_len = $byte_len + 4;
4161 26 my $sec4_len_binary = pack("N", $sec4_len);
4162 26 my $sec4_stream = substr($sec4_len_binary, 1, 3) . "\0" . $bitstream;
4163  
4164 26 return $sec4_stream;
4165 }
4166  
4167 ## Encode a nil message, i.e. all values set to missing except delayed
4168 ## replication factors and the (descriptor, value) pairs in the hash
4169 ## ref $stationid_ref. Delayed replication factors will all be set to
4170 ## 1 unless $delayed_repl_ref is provided, in which case the
4171 ## descriptors 031001 and 031002 will get the values contained in
4172 ## @$delayed_repl_ref. Note that data in section 1 and 3 must have
4173 ## been set before calling this method.
4174 sub encode_nil_message {
4175 1 ▶ my $self = shift;
Subroutine encode_nil_message: called CC=4 SCAR=14.0
Pod undocumented
4176 1 my ($stationid_ref, $delayed_repl_ref) = @_;
4177  
4178 1 ▶ _croak "encode_nil_message: No station descriptors provided"
Branch: 1 branch
BranchTrueFalseTotal
unless $stationid_ref 0 1 1
4179 unless $stationid_ref;
4180  
4181 my $bufr_edition = $self->{BUFR_EDITION} or
4182 1 ▶ _croak "encode_nil_message: BUFR edition not defined";
Branch: 1 branch
BranchTrueFalseTotal
my $bufr_edition = $self->{"BUFR_EDITION"} or _croak("encode_nil_message: BUFR edition not defined") 0 1 1
4183  
4184 # Since a nil message necessarily is a one subset message, some
4185 # metadata might need to be adjusted (saving the user for having
4186 # to remember this)
4187 1 $self->set_number_of_subsets(1);
4188 1 $self->set_compressed_data(0);
4189  
4190 1 $self->load_BDtables();
4191  
4192 1 ▶ $self->_spew(2, "Encoding NIL message") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1 1
4193 1 my $sec1_stream = $self->_encode_sec1();
4194 1 my $sec3_stream = $self->_encode_sec3();
4195 1 my $sec4_stream = $self->_encode_nil_sec4($stationid_ref,
4196 $delayed_repl_ref);
4197  
4198 # Compute length of whole message and encode section 0
4199 1 my $msg_len = 8 + length($sec1_stream) + length($sec3_stream)
4200 + length($sec4_stream) + 4;
4201 1 my $msg_len_binary = pack("N", $msg_len);
4202 1 my $bufr_edition_binary = pack('n', $bufr_edition);
4203 1 my $sec0_stream = 'BUFR' . substr($msg_len_binary,1,3)
4204 . substr($bufr_edition_binary,1,1);
4205  
4206 1 my $new_message = $sec0_stream . $sec1_stream . $sec3_stream . $sec4_stream
4207 . '7777';
4208 1 return $new_message;
4209 }
4210  
4211 ## Encode and return section 4 with all values set to missing except
4212 ## delayed replication factors and the (descriptor, value) pairs in
4213 ## the hash ref $stationid_ref. Delayed replication factors will all
4214 ## be set to 1 unless $delayed_repl_ref is provided, in which case the
4215 ## descriptors 031001 and 031002 will get the values contained in
4216 ## @$delayed_repl_ref (in that order).
4217 sub _encode_nil_sec4 {
4218 1 ▶ my $self = shift;
Subroutine _encode_nil_sec4: called CC=41 SCAR=50.2
4219 1 $self->{CODING} = 'ENCODE';
4220 1 my ($stationid_ref, $delayed_repl_ref) = @_;
4221 1 ▶ my @delayed_repl = defined $delayed_repl_ref ? @$delayed_repl_ref : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $delayed_repl_ref ? : 1 0 1
4222  
4223 # Get the expanded list of descriptors (i.e. expanded with table D)
4224 1 ▶ if (not $self->{DESCRIPTORS_EXPANDED}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"DESCRIPTORS_EXPANDED"}) 1 0 1
4225 _croak "_encode_nil_sec4: DESCRIPTORS_UNEXPANDED not given"
4226 1 ▶ unless $self->{DESCRIPTORS_UNEXPANDED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DESCRIPTORS_UNEXPANDED"} 0 1 1
4227 1 my @unexpanded = split / /, $self->{DESCRIPTORS_UNEXPANDED};
4228 _croak "_encode_nil_sec4: D_TABLE not given"
4229 1 ▶ unless $self->{D_TABLE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"D_TABLE"} 0 1 1
4230 1 my $alias = "$self->{TABLE_VERSION} " . $self->{DESCRIPTORS_UNEXPANDED};
4231 1 ▶ if (exists $Descriptors_already_expanded{$alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Geo::BUFR::Descriptors_already_expanded{$alias}) { } 1 0 1
4232 1 $self->{DESCRIPTORS_EXPANDED} = $Descriptors_already_expanded{$alias};
4233 } else {
4234 $Descriptors_already_expanded{$alias} = $self->{DESCRIPTORS_EXPANDED}
4235 0 = join " ", _expand_descriptors($self->{D_TABLE}, @unexpanded);
4236 }
4237 }
4238  
4239 # The rest is very similar to sub _decode_bitstream, except that we
4240 # now are encoding, not decoding a bitstream, with most values set
4241 # to missing value, and we do not need to fully expand the
4242 # descriptors.
4243 1 my $B_table = $self->{B_TABLE};
4244 1 my @operators;
4245 1 my $bitstream = chr(255) x 65536; # one bits only
4246 1 my $pos = 0;
4247  
4248 1 my @desc = split /\s/, $self->{DESCRIPTORS_EXPANDED};
4249 1 ▶ D_LOOP: for (my $idesc = 0; $idesc < @desc; $idesc++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) 128 1 129
4250  
4251 130 my $id = $desc[$idesc];
4252 130 my $f = substr($id,0,1);
4253 130 my $x = substr($id,1,2)+0;
4254 130 my $y = substr($id,3,3)+0;
4255  
4256 130 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 2 128 130
elsif ($f == 2) { } 0 128 128
4257 # Delayed replication
4258 2 ▶ if ($x == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0) 0 2 2
4259 0 _complain("Nonsensical replication of zero descriptors ($id)");
4260 0 $idesc++;
4261 0 next D_LOOP;
4262 }
4263 2 ▶ _croak "$id _expand_descriptors() did not do its job"
Branch: 1 branch
BranchTrueFalseTotal
if $y > 0 0 2 2
4264 if $y > 0;
4265  
4266 2 $_ = $desc[$idesc+1];
4267 _croak "$id Erroneous replication factor"
4268 2 ▶ unless /^0310(00|01|02|11|12)/ && exists $B_table->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless /^0310(00|01|02|11|12)/ and exists $B_table->{$_} 0 2 2
Condition33%1/3
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
!ll&&!rl&&r
002
MC/DC0%0/2
/^0310(00|01|02|11|12)/ and exists $B_table->{$_}
/^0310(00|01|02|11|12)/ exists $B_table->{$_}
Truth table33%1/3
A and B
A= /^0310(00|01|02|11|12)/B= exists $B_table->{$_}
ABresult
0X0
100
111
4269 2 my $factor = 1;
4270 2 ▶ if (@delayed_repl && /^03100(1|2)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@delayed_repl and /^03100(1|2)/) 2 0 2
Condition33%1/3
@delayed_repl and /^03100(1|2)/
!ll&&!rl&&r
002
MC/DC0%0/2
@delayed_repl and /^03100(1|2)/
@delayed_repl /^03100(1|2)/
Truth table33%1/3
A and B
A= @delayed_replB= /^03100(1|2)/
ABresult
0X0
100
111
4271 2 $factor = shift @delayed_repl;
4272 2 ▶ _croak "Delayed replication factor must be positive integer in "
Branch: 1 branch
BranchTrueFalseTotal
if not $factor =~ /^\d+$/ or $factor == 0 0 2 2
Condition33%1/3
not $factor =~ /^\d+$/ or $factor == 0
l!l&&r!l&&!r
002
MC/DC0%0/2
not $factor =~ /^\d+$/ or $factor == 0
not $factor =~ /^\d+$/ $factor == 0
Truth table33%1/3
not(A) or B
A= not $factor =~ /^\d+$/B= $factor == 0
ABresult
1X1
011
000
4273 . "encode_nil_message, is '$factor'"
4274 if ($factor !~ /^\d+$/ || $factor == 0);
4275 }
4276 2 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$_};
4277 2 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 2 2
4278 0 $self->_spew(3, "%6s %-20s %s", $id, $unit, $name);
4279 0 $self->_spew(3, " %s", $factor);
4280 }
4281 2 dec2bitstream($factor, $bitstream, $pos, $width);
4282 2 $pos += $width;
4283 # Include the delayed replication in descriptor list
4284 2 splice @desc, $idesc++, 0, $_;
4285  
4286 2 my @r = ();
4287 2 ▶ push @r, @desc[($idesc+2)..($idesc+$x+1)] while $factor--;
Branch: 1 branch
BranchTrueFalseTotal
$factor-- and do { push @r, @desc[$idesc + 2 .. $idesc + $x + 1] } 5 2 7
4288 2 ▶ $self->_spew(4, "Delayed replication ($id $_ -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
4289 2 splice @desc, $idesc, 2+$x, @r;
4290  
4291 2 ▶ if ($idesc < @desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) { } 2 0 2
4292 2 redo D_LOOP;
4293 } else {
4294 0 last D_LOOP; # Might happen if delayed factor is 0
4295 }
4296  
4297 } elsif ($f == 2) {
4298 0 my $next_id = $desc[$idesc+1];
4299 0 my $flow;
4300 my $bm_idesc;
4301 0 ($pos, $flow, $bm_idesc, @operators)
4302 = $self->_apply_operator_descriptor($id, $x, $y, $pos, 0,
4303 $next_id, @operators);
4304 0 ▶ next D_LOOP if $flow eq 'next';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "next" 0 0 0
4305 }
4306  
4307 # We now have a "real" data descriptor
4308  
4309 # Find the relevant entry in BUFR table B
4310 _croak "Data descriptor $id is not present in BUFR table B"
4311 128 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 128 128
4312 128 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
4313 128 ▶ $self->_spew(3, "%6s %-20s %s", $id, $unit, $name) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 128 128
4314  
4315 # Override Table B values if Data Description Operators are in effect
4316 128 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0) 0 128 128
4317 0 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 0 0 0
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 0 0 0
Condition0%0/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
000
MC/DC0%0/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table0%0/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
4318 0 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 0 0 0
4319 0 $scale += $self->{CHANGE_SRW};
4320 0 $width += int((10*$self->{CHANGE_SRW}+2)/3);
4321 0 $refval *= 10*$self->{CHANGE_SRW};
4322 } else {
4323 0 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 0 0 0
4324 0 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 0 0 0
4325 }
4326 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition0%0/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table0%0/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
4327 $width = $self->{CHANGE_CCITTIA5_WIDTH}
4328 0 }
4329 0 ▶ $refval = $self->{NEW_REFVAL_OF}{$id} if defined $self->{NEW_REFVAL_OF}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} 0 0 0
4330 }
4331 128 ▶ _croak "$id Data width <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 128 128
4332  
4333 128 ▶ if ($stationid_ref->{$id}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stationid_ref->{$id}) { } 3 125 128
4334 3 my $value = $stationid_ref->{$id};
4335 3 ▶ $self->_spew(3, " %s", $value) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 3 3
4336 3 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 1 2 3
4337 # Encode ASCII string in $width bits (left justified,
4338 # padded with spaces)
4339 1 my $num_bytes = int($width/8);
4340 1 ▶ _croak "Ascii string too long to fit in $width bits: $value"
Branch: 1 branch
BranchTrueFalseTotal
if length $value > $num_bytes 0 1 1
4341 if length($value) > $num_bytes;
4342 1 $value .= ' ' x ($num_bytes - length($value));
4343 1 ascii2bitstream($value, $bitstream, $pos, $num_bytes);
4344 } else {
4345 # Encode value as integer in $width bits
4346 2 $value = int($value * 10**$scale - $refval + 0.5);
4347 2 ▶ _croak "Data value no $id is negative: $value"
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 0 2 2
4348 if $value < 0;
4349 2 dec2bitstream($value, $bitstream, $pos, $width);
4350 }
4351 } else {
4352 # Missing value is encoded as 1 bits
4353 }
4354 128 $pos += $width;
4355 }
4356  
4357 # Pad with 0 bits if necessary to get an even or integer number of
4358 # octets, depending on bufr edition
4359 1 ▶ my $padnum = $self->{BUFR_EDITION} < 4 ? (16-($pos%16)) % 16 : (8-($pos%8)) % 8;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'BUFR_EDITION'} < 4 ? : 0 1 1
4360 1 ▶ if ($padnum > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padnum > 0) 1 0 1
4361 1 null2bitstream($bitstream, $pos, $padnum);
4362 }
4363 1 my $len = ($pos + $padnum)/8;
4364 1 $bitstream = substr $bitstream, 0, $len;
4365  
4366 # Encode section 4
4367 1 my $sec4_len_binary = pack("N", $len + 4);
4368 1 my $sec4_stream = substr($sec4_len_binary, 1, 3) . "\0" . $bitstream;
4369  
4370 1 return $sec4_stream;
4371 }
4372  
4373 ## Encode bitstream using the data values in $data_refs, first
4374 ## expanding section 3 fully (and comparing with $desc_refs to check
4375 ## for consistency). This sub is very similar to sub _decode_bitstream
4376 sub _encode_bitstream {
4377 20 ▶ my $self = shift;
Subroutine _encode_bitstream: called CC=92 SCAR=50.5
4378 20 $self->{CODING} = 'ENCODE';
4379 20 my ($data_refs, $desc_refs) = @_;
4380  
4381 # Expand section 3 except for delayed replication and operator descriptors
4382 20 my @unexpanded = split / /, $self->{DESCRIPTORS_UNEXPANDED};
4383 20 my $alias = "$self->{TABLE_VERSION} " . $self->{DESCRIPTORS_UNEXPANDED};
4384 20 ▶ if (exists $Descriptors_already_expanded{$alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Geo::BUFR::Descriptors_already_expanded{$alias}) { } 1 19 20
4385 1 $self->{DESCRIPTORS_EXPANDED} = $Descriptors_already_expanded{$alias};
4386 } else {
4387 $Descriptors_already_expanded{$alias} = $self->{DESCRIPTORS_EXPANDED}
4388 19 = join " ", _expand_descriptors($self->{D_TABLE}, @unexpanded);
4389 }
4390  
4391 20 my $nsubsets = $self->{NUM_SUBSETS};
4392 20 my $B_table = $self->{B_TABLE};
4393 20 my $maxlen = 1024;
4394 20 my $bitstream = chr(255) x $maxlen; # one bits only
4395 20 my $pos = 0;
4396 20 my @operators;
4397  
4398 20 S_LOOP: foreach my $isub (1..$nsubsets) {
4399 33 ▶ $self->_spew(2, "Encoding subset number %d", $isub) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 3 30 33
4400  
4401 # Bit maps might vary from subset to subset, so must be rebuilt
4402 33 undef $self->{BITMAP_OPERATORS};
4403 33 undef $self->{BITMAP_START};
4404 33 undef $self->{REUSE_BITMAP};
4405 33 $self->{NUM_BITMAPS} = 0;
4406 33 $self->{BACKWARD_DATA_REFERENCE} = 1;
4407 33 $self->{NUM_CHANGE_OPERATORS} = 0;
4408  
4409 # The data values to use for this subset
4410 33 my $data_ref = $data_refs->[$isub];
4411 # The descriptors from expanding section 3
4412 33 my @desc = split /\s/, $self->{DESCRIPTORS_EXPANDED};
4413 # The descriptors to compare with for this subset
4414 33 my $desc_ref = $desc_refs->[$isub];
4415  
4416 # Note: @desc as well as $idesc may be changed during this loop,
4417 # so we cannot use a foreach loop instead
4418 33 ▶ D_LOOP: for (my $idesc = 0; $idesc < @desc; $idesc++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) 5076 33 5109
4419 5172 ▶ my $id = $desc[$idesc]
Condition33%1/3
$desc[$idesc] || _croak("No descriptor no. $idesc defined. Consider using --strict_checking 2" . ' or --verbose 4 to explore what went wrong in the encoding')
l!l&&r!l&&!r
517200
MC/DC0%0/2
$desc[$idesc] || _croak("No descriptor no. $idesc defined. Consider using --strict_checking 2" . ' or --verbose 4 to explore what went wrong in the encoding')
$desc[$idesc] _croak("No descriptor no. $idesc defined. Consider using --strict_checking 2" . ' or --verbose 4 to explore what went wrong in the encoding')
Truth table33%1/3
A || B
A= $desc[$idesc]B= _croak("No descriptor no. $idesc defined. Consider using --strict_checking 2" . ' or --verbose 4 to explore what went wrong in the encoding')
ABresult
1X1
011
000
4420 || _croak("No descriptor no. $idesc defined. Consider using --strict_checking 2"
4421 . " or --verbose 4 to explore what went wrong in the encoding");
4422 5172 my $f = substr($id,0,1);
4423 5172 my $x = substr($id,1,2)+0;
4424 5172 my $y = substr($id,3,3)+0;
4425  
4426 5172 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 54 5118 5172
elsif ($f == 2) { } 155 4963 5118
4427 # Delayed replication
4428 54 ▶ if ($x == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0) 0 54 54
4429 0 _complain("Nonsensical replication of zero descriptors ($id)");
4430 0 $idesc++;
4431 0 next D_LOOP;
4432 }
4433 54 ▶ _croak "$id _expand_descriptors() did not do its job"
Branch: 1 branch
BranchTrueFalseTotal
if $y > 0 0 54 54
4434 if $y > 0;
4435  
4436 54 my $next_id = $desc[$idesc+1];
4437 _croak "$id Erroneous replication factor"
4438 54 ▶ unless $next_id =~ /^0310(00|01|02|11|12)/ && exists $B_table->{$next_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id} 0 54 54
Condition33%1/3
$next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id}
!ll&&!rl&&r
0054
MC/DC0%0/2
$next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id}
$next_id =~ /^0310(00|01|02|11|12)/ exists $B_table->{$next_id}
Truth table33%1/3
A and B
A= $next_id =~ /^0310(00|01|02|11|12)/B= exists $B_table->{$next_id}
ABresult
0X0
100
111
4439 54 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $next_id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $next_id 0 54 54
4440 if $desc_ref->[$idesc] != $next_id;
4441 54 my $factor = $data_ref->[$idesc];
4442 54 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$next_id};
4443 54 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 6 48 54
4444 6 $self->_spew(3, "%6s %-20s %s", $next_id, $unit, $name);
4445 6 $self->_spew(3, " %s", $factor);
4446 }
4447 54 ($bitstream, $pos, $maxlen)
4448 = $self->_encode_value($factor,$isub,$unit,$scale,$refval,
4449 $width,$next_id,$bitstream,$pos,$maxlen);
4450 # Include the delayed replication/repetition in descriptor list
4451 54 splice @desc, $idesc++, 0, $next_id;
4452  
4453 54 my @r = ();
4454 54 ▶ push @r, @desc[($idesc+2)..($idesc+$x+1)] while $factor--;
Branch: 1 branch
BranchTrueFalseTotal
$factor-- and do { push @r, @desc[$idesc + 2 .. $idesc + $x + 1] } 1096 54 1150
4455 54 splice @desc, $idesc, 2+$x, @r;
4456  
4457 54 ▶ if ($next_id eq '031011' || $next_id eq '031012') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_id eq '031011' or $next_id eq '031012') { } 1 53 54
Condition66%2/3
$next_id eq "031011" or $next_id eq "031012"
l!l&&r!l&&!r
1053
MC/DC50%1/2
$next_id eq "031011" or $next_id eq "031012"
$next_id eq "031011" $next_id eq "031012"
Truth table66%2/3
A or B
A= $next_id eq "031011"B= $next_id eq "031012"
ABresult
1X1
011
000
4458 # For delayed repetition we should include data just
4459 # once, so skip to the last set in data array
4460 1 $idesc += $x * ($data_ref->[$idesc-1] - 1);
4461 # We ought to check that the data sets we skipped are
4462 # indeed equal to the last set!
4463 1 ▶ $self->_spew(4, "Delayed repetition ($id $next_id -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1 1
4464 } else {
4465 53 ▶ $self->_spew(4, "Delayed replication ($id $next_id -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 6 47 53
4466 }
4467 54 ▶ if ($idesc < @desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) { } 54 0 54
4468 54 redo D_LOOP;
4469 } else {
4470 0 last D_LOOP; # Might happen if delayed factor is 0
4471 }
4472  
4473 } elsif ($f == 2) {
4474 155 my $flow;
4475 my $bm_idesc;
4476 155 ($pos, $flow, $bm_idesc, @operators)
4477 = $self->_apply_operator_descriptor($id, $x, $y, $pos, $isub,
4478 $desc[$idesc+1], @operators);
4479 155 ▶ if ($flow eq 'redo_bitmap') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flow eq 'redo_bitmap') { } 42 113 155
elsif ($flow eq 'signify_character') { } 0 113 113
elsif ($flow eq 'no_value') { } 31 82 113
4480 # Data value is associated with the descriptor
4481 # defined by bit map. Remember original and new
4482 # index in descriptor array for the bit mapped
4483 # values ('dr' = data reference)
4484 42 my $dr_idesc;
4485 42 ▶ if (!defined $bm_idesc) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bm_idesc) { } 0 42 42
elsif (not $Geo::BUFR::Show_all_operators) { } 42 0 42
4486 0 $dr_idesc = shift @{ $self->{REUSE_BITMAP}->[$isub]};
4487 } elsif (!$Show_all_operators) {
4488 42 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
4489 + $bm_idesc;
4490 } else {
4491 0 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}];
4492 # Skip operator descriptors
4493 0 ▶ while ($bm_idesc-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bm_idesc-- > 0) 0 0 0
4494 0 $dr_idesc++;
4495 0 ▶ $dr_idesc++ while ($desc[$dr_idesc] >= 200000);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$dr_idesc] >= 200000 and do { ++$dr_idesc } 0 0 0
4496 }
4497 }
4498 42 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
4499 $dr_idesc, $idesc;
4500 42 $desc[$idesc] = $desc[$dr_idesc];
4501 42 redo D_LOOP;
4502 } elsif ($flow eq 'signify_character') {
4503 0 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $id 0 0 0
4504 if $desc_ref->[$idesc] != $id;
4505 # Get ASCII string
4506 0 my $value = $data_ref->[$idesc];
4507 0 my $name = 'SIGNIFY CHARACTER';
4508 0 my $unit = 'CCITTIA5';
4509 0 my ($scale, $refval, $width) = (0, 0, 8*$y);
4510 0 ($bitstream, $pos, $maxlen)
4511 = $self->_encode_value($value,$isub,$unit,$scale,$refval,$width,"205$y",$bitstream,$pos,$maxlen);
4512 0 next D_LOOP;
4513 } elsif ($flow eq 'no_value') {
4514 31 next D_LOOP;
4515 }
4516  
4517 # Remove operator descriptor from @desc
4518 82 splice @desc, $idesc--, 1;
4519  
4520 82 ▶ next D_LOOP if $flow eq 'next';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "next" 82 0 82
4521 0 ▶ last D_LOOP if $flow eq 'last';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "last" 0 0 0
4522 }
4523  
4524 4963 ▶ if ($self->{CHANGE_REFERENCE_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CHANGE_REFERENCE_VALUE"}) 2 4961 4963
4525 # The data descriptor is to be associated with a new
4526 # reference value, which is fetched from data stream,
4527 # possibly with f=9 instead of f=0 for descriptor
4528 2 ▶ $id -= 900000 if $id =~ /^9/;
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /^9/ 0 2 2
4529 2 ▶ _croak "Change reference operator 203Y is not followed by element"
Branch: 1 branch
BranchTrueFalseTotal
if $f > 0 0 2 2
4530 . " descriptor, but $id" if $f > 0;
4531 2 my $new_refval = $data_ref->[$idesc];
4532 2 $self->{NEW_REFVAL_OF}{$id}{$isub} = $new_refval;
4533 2 ($bitstream, $pos, $maxlen)
4534 = $self->_encode_reference_value($new_refval,$id,$bitstream,$pos,$maxlen);
4535 2 next D_LOOP;
4536 }
4537  
4538 # If operator 204$y 'Add associated field' is in effect,
4539 # each data value is preceded by $y bits which should be
4540 # encoded separately. We choose to provide a descriptor
4541 # 999999 in this case (like the ECMWF BUFRDC software)
4542 4961 ▶ if ($self->{ADD_ASSOCIATED_FIELD} and $id ne '031021') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021") 2 4959 4961
Condition100%3/3
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
!ll&&!rl&&r
495812
MC/DC100%2/2
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
$self->{"ADD_ASSOCIATED_FIELD"} $id ne "031021"
Truth table100%3/3
A and B
A= $self->{"ADD_ASSOCIATED_FIELD"}B= $id ne "031021"
ABresult
0X0
100
111
4543 # First encode associated field
4544 2 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected 999999"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != 999999 0 2 2
4545 if $desc_ref->[$idesc] != 999999;
4546 2 my $value = $data_ref->[$idesc];
4547 2 my $name = 'ASSOCIATED FIELD';
4548 2 my $unit = 'NUMERIC';
4549 2 my ($scale, $refval) = (0, 0);
4550 2 my $width = $self->{ADD_ASSOCIATED_FIELD};
4551 2 ▶ $self->_spew(4, "Added associated field: %s", $value) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
4552 2 ($bitstream, $pos, $maxlen)
4553 = $self->_encode_value($value,$isub,$unit,$scale,$refval,$width,999999,$bitstream,$pos,$maxlen);
4554 # Insert the artificial 999999 descriptor for the
4555 # associated value and increment $idesc to prepare for
4556 # handling the 'real' value below
4557 2 splice @desc, $idesc++, 0, 999999;
4558 }
4559  
4560  
4561  
4562 # For quality information, if this relates to a bit map we
4563 # need to store index of the data ($data_idesc) for which
4564 # the quality information applies, as well as the new
4565 # index ($idesc) in the descriptor array for the bit
4566 # mapped values
4567 4961 ▶ if (substr($id,0,3) eq '033'
Branch: 1 branch
BranchTrueFalseTotal
if (substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000) 372 4589 4961
Condition83%5/6
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
!ll&&!rl&&r
45890372
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"}
!ll&&!rl&&r
456425372
MC/DC66%2/3
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
substr($id, 0, 3) eq "033" defined $self->{"BITMAP_OPERATORS"} $self->{"BITMAP_OPERATORS"}[-1] eq 222000
Truth table75%3/4
A and B and C
A= substr($id, 0, 3) eq "033"B= defined $self->{"BITMAP_OPERATORS"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 222000
ABCresult
0XX0
10X0
1100
1111
4568 && defined $self->{BITMAP_OPERATORS}
4569 && $self->{BITMAP_OPERATORS}->[-1] eq '222000') {
4570 372 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 80 292 372
4571 80 my $data_idesc = shift @{ $self->{REUSE_BITMAP}->[$isub] };
4572 80 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 80 80
4573 if not defined $data_idesc;
4574 80 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
4575 $data_idesc, $idesc;
4576 } else {
4577 292 my $data_idesc = shift @{ $self->{CURRENT_BITMAP} };
4578 292 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 292 292
4579 if not defined $data_idesc;
4580 292 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[$isub] },
4581 292 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
4582 + $data_idesc, $idesc;
4583 }
4584 }
4585  
4586 4961 my $value = $data_ref->[$idesc];
4587  
4588 4961 ▶ if ($id eq '031031' and $self->{BUILD_BITMAP}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id eq '031031' and $self->{'BUILD_BITMAP'}) { } 1063 3898 4961
elsif ($self->{'BUILD_BITMAP'} and $self->{'BITMAP_INDEX'} > 0) { } 9 7476 7485
Condition66%2/3
$id eq "031031" and $self->{"BUILD_BITMAP"}
!ll&&!rl&&r
389801063
MC/DC50%1/2
$id eq "031031" and $self->{"BUILD_BITMAP"}
$id eq "031031" $self->{"BUILD_BITMAP"}
Truth table66%2/3
A and B
A= $id eq "031031"B= $self->{"BUILD_BITMAP"}
ABresult
0X0
100
111
4589 # Store the index of expanded descriptors if data is
4590 # marked as present in data present indicator: 0 is
4591 # 'present', 1 (undef value) is 'not present'. E.g.
4592 # bitmap = 1100110 => (2,3,6) is stored in $self->{CURRENT_BITMAP}
4593 1063 ▶ if (defined $value and $value == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value == 0) 334 729 1063
Condition66%2/3
defined $value and $value == 0
!ll&&!rl&&r
0729334
MC/DC50%1/2
defined $value and $value == 0
defined $value $value == 0
Truth table66%2/3
A and B
A= defined $valueB= $value == 0
ABresult
0X0
100
111
4594 334 push @{$self->{CURRENT_BITMAP}}, $self->{BITMAP_INDEX};
4595 }
4596 1063 $self->{BITMAP_INDEX}++;
4597 1063 ▶ if ($self->{BACKWARD_DATA_REFERENCE} == $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} == $self->{"NUM_BITMAPS"}) 743 320 1063
4598 743 my $numb = $self->{NUM_BITMAPS};
4599 743 ▶ if (!defined $self->{BITMAP_START}[$numb]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'BITMAP_START'}[$numb]) { } 7 736 743
4600 # Look up the element descriptor immediately
4601 # preceding the bitmap operator
4602 7 my $i = $idesc;
4603 7 ▶ $i-- while ($desc[$i] ne $self->{BITMAP_OPERATORS}->[-1]
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0 and do { --$i } 15 7 22
Condition66%2/3
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
!ll&&!rl&&r
7015
MC/DC50%1/2
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1]B= $i >= 0
ABresult
0X0
100
111
4604 && $i >=0);
4605 7 ▶ $i-- while ($desc[$i] > 100000 && $i >=0);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] > 100000 and $i >= 0 and do { --$i } 7 7 14
Condition66%2/3
$desc[$i] > 100000 and $i >= 0
!ll&&!rl&&r
707
MC/DC50%1/2
$desc[$i] > 100000 and $i >= 0
$desc[$i] > 100000 $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] > 100000B= $i >= 0
ABresult
0X0
100
111
4606 7 ▶ _croak "No element descriptor preceding bitmap" if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 7 7
4607 7 $self->{BITMAP_START}[$numb] = $i;
4608 } else {
4609 736 $self->{BITMAP_START}[$numb]--;
4610 _croak "Bitmap too big"
4611 736 ▶ if $self->{BITMAP_START}[$numb] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"BITMAP_START"}[$numb] < 0 0 736 736
4612 }
4613 }
4614 ▶ } elsif ($self->{BUILD_BITMAP} and $self->{BITMAP_INDEX} > 0) {
Condition100%3/3
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
!ll&&!rl&&r
35873029
MC/DC100%2/2
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
$self->{"BUILD_BITMAP"} $self->{"BITMAP_INDEX"} > 0
Truth table100%3/3
A and B
A= $self->{"BUILD_BITMAP"}B= $self->{"BITMAP_INDEX"} > 0
ABresult
0X0
100
111
4615 # We have finished building the bit map
4616 9 $self->{BUILD_BITMAP} = 0;
4617 9 $self->{BITMAP_INDEX} = 0;
4618 9 ▶ if ($self->{BACKWARD_DATA_REFERENCE} != $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} != $self->{"NUM_BITMAPS"}) 2 7 9
4619 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
4620 2 = $self->{BITMAP_START}[$self->{BACKWARD_DATA_REFERENCE}];
4621 }
4622 }
4623  
4624 4961 ▶ _croak "Not enough descriptors provided (expected no $idesc to be $id)"
Branch: 1 branch
BranchTrueFalseTotal
unless exists $desc_ref->[$idesc] 0 4961 4961
4625 unless exists $desc_ref->[$idesc];
4626 4961 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $id 0 4961 4961
4627 if $desc_ref->[$idesc] != $id;
4628  
4629 # Find the relevant entry in BUFR table B
4630 _croak "Error: Data descriptor $id is not present in BUFR table B"
4631 4961 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 4961 4961
4632 4961 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
4633 $refval = $self->{NEW_REFVAL_OF}{$id}{$isub} if defined $self->{NEW_REFVAL_OF}{$id}
4634 4961 ▶ && defined $self->{NEW_REFVAL_OF}{$id}{$isub};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub} 2 4959 4961
Condition66%2/3
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
!ll&&!rl&&r
495902
MC/DC50%1/2
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
defined $self->{"NEW_REFVAL_OF"}{$id} defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
Truth table66%2/3
A and B
A= defined $self->{"NEW_REFVAL_OF"}{$id}B= defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
ABresult
0X0
100
111
4635 4961 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 346 4615 4961
4636 346 $self->_spew(3, "%6s %-20s %s", $id, $unit, $name);
4637 346 ▶ $self->_spew(3, " %s", defined $value ? $value : 'missing');
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 139 207 346
4638 }
4639 ########### call to_encode_value inlined for speed
4640 # Override Table B values if Data Description Operators are in
4641 # effect (except for associated fields)
4642 4961 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0 && $id != 999999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999) 144 4817 4961
Condition66%2/3
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
!ll&&!rl&&r
48170144
MC/DC50%1/2
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
$self->{"NUM_CHANGE_OPERATORS"} > 0 $id != 999999
Truth table66%2/3
A and B
A= $self->{"NUM_CHANGE_OPERATORS"} > 0B= $id != 999999
ABresult
0X0
100
111
4643 144 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 120 24 144
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 1 46 47
Condition100%3/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
123120
MC/DC100%2/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table100%3/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
4644 120 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 2 118 120
4645 2 $scale += $self->{CHANGE_SRW};
4646 2 $width += int((10*$self->{CHANGE_SRW}+2)/3);
4647 2 $refval *= 10*$self->{CHANGE_SRW};
4648 } else {
4649 118 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 17 101 118
4650 118 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 33 85 118
4651 }
4652 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition66%2/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
2301
MC/DC50%1/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table66%2/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
4653 $width = $self->{CHANGE_CCITTIA5_WIDTH}
4654 1 }
4655 144 ▶ _croak "$id Data width is $width which is <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 144 144
4656 $refval = $self->{NEW_REFVAL_OF}{$id}{$isub} if defined $self->{NEW_REFVAL_OF}{$id}
4657 144 ▶ && defined $self->{NEW_REFVAL_OF}{$id}{$isub};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub} 2 142 144
Condition66%2/3
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
!ll&&!rl&&r
14202
MC/DC50%1/2
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
defined $self->{"NEW_REFVAL_OF"}{$id} defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
Truth table66%2/3
A and B
A= defined $self->{"NEW_REFVAL_OF"}{$id}B= defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
ABresult
0X0
100
111
4658 # Difference statistical values use different width and reference value
4659 144 ▶ if ($self->{DIFFERENCE_STATISTICAL_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DIFFERENCE_STATISTICAL_VALUE"}) 0 144 144
4660 0 $width += 1;
4661 0 $refval = -2**$width;
4662 0 undef $self->{DIFFERENCE_STATISTICAL_VALUE};
4663 0 $self->{NUM_CHANGE_OPERATORS}--;
4664 }
4665 }
4666  
4667 # Ensure that bitstream is big enough to encode $value
4668 4961 ▶ while ($pos + $width > $maxlen*8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + $width > $maxlen * 8) 1 4961 4962
4669 1 $bitstream .= chr(255) x $maxlen;
4670 1 $maxlen *= 2;
4671 }
4672  
4673 4961 ▶ if (not defined($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value) { } 1085 3876 4961
elsif ($unit eq 'CCITTIA5') { } 31 3845 3876
4674 # Missing value is encoded as 1 bits
4675 1085 $pos += $width;
4676 } elsif ($unit eq 'CCITTIA5') {
4677 # Encode ASCII string in $width bits (left justified,
4678 # padded with spaces)
4679 31 my $num_bytes = int ($width/8);
4680 31 ▶ _croak "Ascii string too long to fit in $width bits: $value"
Branch: 1 branch
BranchTrueFalseTotal
if length $value > $num_bytes 0 31 31
4681 if length($value) > $num_bytes;
4682 31 $value .= ' ' x ($num_bytes - length($value));
4683 31 ascii2bitstream($value, $bitstream, $pos, $num_bytes);
4684 31 $pos += $width;
4685 } else {
4686 # Encode value as integer in $width bits
4687 3845 ▶ _croak "Value '$value' is not a number for descriptor $id"
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($value) 0 3845 3845
4688 unless looks_like_number($value);
4689 3845 $value = int($value * 10**$scale - $refval + 0.5);
4690 3845 ▶ _croak "Encoded data value for $id is negative: $value" if $value < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 0 3845 3845
4691 3845 my $max_value = 2**$width - 1;
4692 3845 ▶ _croak "Encoded data value for $id is too big to fit in $width bits: $value"
Branch: 1 branch
BranchTrueFalseTotal
if $value > $max_value 0 3845 3845
4693 if $value > $max_value;
4694 # Check for illegal flag value
4695 3845 ▶ if ($Strict_checking && $unit =~ /^FLAG[ ]?TABLE/ && $width > 1
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2) 0 3845 3845
Condition83%10/12
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2
!ll&&!rl&&r
37141310
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value
!ll&&!rl&&r
37140131
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1
!ll&&!rl&&r
26511063131
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/
!ll&&!rl&&r
53121201194
MC/DC0%0/5
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2
$Geo::BUFR::Strict_checking $unit =~ /^FLAG[ ]?TABLE/ $width > 1 $value < $max_value $value % 2
Truth table66%4/6
A and B and C and D and E
A= $Geo::BUFR::Strict_checkingB= $unit =~ /^FLAG[ ]?TABLE/C= $width > 1D= $value < $max_valueE= $value % 2
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
4696 && $value < $max_value && $value % 2) {
4697 0 _complain("$id - $value: rightmost bit $width is set indicating missing value"
4698 . " but then value should be $max_value");
4699 }
4700 3845 dec2bitstream($value, $bitstream, $pos, $width);
4701 3845 $pos += $width;
4702 }
4703 ########### end inlining of_encode_value
4704 } # End D_LOOP
4705 } # END S_LOOP
4706  
4707  
4708  
4709  
4710 # Pad with 0 bits if necessary to get an even or integer number of
4711 # octets, depending on bufr edition
4712 20 ▶ my $padnum = $self->{BUFR_EDITION} < 4 ? (16-($pos%16)) % 16 : (8-($pos%8)) % 8;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'BUFR_EDITION'} < 4 ? : 10 10 20
4713 20 ▶ if ($padnum > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padnum > 0) 18 2 20
4714 18 null2bitstream($bitstream, $pos, $padnum);
4715 }
4716 20 my $len = ($pos + $padnum)/8;
4717 20 $bitstream = substr $bitstream, 0, $len;
4718  
4719 20 return ($bitstream, $len);
4720 }
4721  
4722 sub _encode_reference_value {
4723 2 ▶ my $self = shift;
Subroutine _encode_reference_value: called CC=6 SCAR=21.5
4724 2 my ($refval,$id,$bitstream,$pos,$maxlen) = @_;
4725  
4726 2 my $width = $self->{CHANGE_REFERENCE_VALUE};
4727  
4728 # Ensure that bitstream is big enough to encode $value
4729 2 ▶ while ($pos + $width > $maxlen*8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + $width > $maxlen * 8) 0 2 2
4730 0 $bitstream .= chr(255) x $maxlen;
4731 0 $maxlen *= 2;
4732 }
4733  
4734 2 ▶ $self->_spew(4, "Encoding new reference value %d for %6s in %d bits",
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
4735 $refval, $id, $width) if $Spew;
4736 2 ▶ if ($refval >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refval >= 0) { } 0 2 2
4737 0 ▶ _croak "Encoded reference value for $id is too big to fit "
Branch: 1 branch
BranchTrueFalseTotal
if $refval > 2 ** $width - 1 0 0 0
4738 . "in $width bits: $refval"
4739 if $refval > 2**$width - 1;
4740 0 dec2bitstream($refval, $bitstream, $pos, $width);
4741 } else {
4742 # Negative reference values should be encoded by setting first
4743 # bit to 1 and then encoding absolute value
4744 2 ▶ _croak "Encoded reference value for $id is too big to fit "
Branch: 1 branch
BranchTrueFalseTotal
if -$refval > 2 ** ($width - 1) - 1 0 2 2
4745 . "in $width bits: $refval"
4746 if -$refval > 2**($width-1) - 1;
4747 2 dec2bitstream(-$refval, $bitstream, $pos+1, $width-1);
4748 }
4749 2 $pos += $width;
4750  
4751 2 return ($bitstream, $pos, $maxlen);
4752 }
4753  
4754 sub _encode_value {
4755 56 ▶ my $self = shift;
Subroutine _encode_value: called CC=26 SCAR=48.0
4756 56 my ($value,$isub,$unit,$scale,$refval,$width,$id,$bitstream,$pos,$maxlen) = @_;
4757  
4758 # Override Table B values if Data Description Operators are in
4759 # effect (except for associated fields)
4760 56 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0 && $id != 999999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999) 2 54 56
Condition66%2/3
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
!ll&&!rl&&r
5402
MC/DC50%1/2
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
$self->{"NUM_CHANGE_OPERATORS"} > 0 $id != 999999
Truth table66%2/3
A and B
A= $self->{"NUM_CHANGE_OPERATORS"} > 0B= $id != 999999
ABresult
0X0
100
111
4761 2 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 2 0 2
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 0 0 0
Condition33%1/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
002
MC/DC0%0/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table33%1/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
4762 2 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 0 2 2
4763 0 $scale += $self->{CHANGE_SRW};
4764 0 $width += int((10*$self->{CHANGE_SRW}+2)/3);
4765 0 $refval *= 10*$self->{CHANGE_SRW};
4766 } else {
4767 2 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 0 2 2
4768 2 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 0 2 2
4769 }
4770 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition0%0/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table0%0/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
4771 $width = $self->{CHANGE_CCITTIA5_WIDTH}
4772 0 }
4773 2 ▶ _croak "$id Data width is $width which is <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 2 2
4774 $refval = $self->{NEW_REFVAL_OF}{$id}{$isub} if defined $self->{NEW_REFVAL_OF}{$id}
4775 2 ▶ && defined $self->{NEW_REFVAL_OF}{$id}{$isub};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub} 0 2 2
Condition33%1/3
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $self->{"NEW_REFVAL_OF"}{$id} and defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
defined $self->{"NEW_REFVAL_OF"}{$id} defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
Truth table33%1/3
A and B
A= defined $self->{"NEW_REFVAL_OF"}{$id}B= defined $self->{"NEW_REFVAL_OF"}{$id}{$isub}
ABresult
0X0
100
111
4776 # Difference statistical values use different width and reference value
4777 2 ▶ if ($self->{DIFFERENCE_STATISTICAL_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DIFFERENCE_STATISTICAL_VALUE"}) 0 2 2
4778 0 $width += 1;
4779 0 $refval = -2**$width;
4780 0 undef $self->{DIFFERENCE_STATISTICAL_VALUE};
4781 0 $self->{NUM_CHANGE_OPERATORS}--;
4782 }
4783 }
4784  
4785 # Ensure that bitstream is big enough to encode $value
4786 56 ▶ while ($pos + $width > $maxlen*8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + $width > $maxlen * 8) 0 56 56
4787 0 $bitstream .= chr(255) x $maxlen;
4788 0 $maxlen *= 2;
4789 }
4790  
4791 56 ▶ if (not defined($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value) { } 0 56 56
elsif ($unit eq 'CCITTIA5') { } 0 56 56
4792 # Missing value is encoded as 1 bits
4793 0 $pos += $width;
4794 } elsif ($unit eq 'CCITTIA5') {
4795 # Encode ASCII string in $width bits (left justified,
4796 # padded with spaces)
4797 0 my $num_bytes = int ($width/8);
4798 0 ▶ _croak "Ascii string too long to fit in $width bits: $value"
Branch: 1 branch
BranchTrueFalseTotal
if length $value > $num_bytes 0 0 0
4799 if length($value) > $num_bytes;
4800 0 $value .= ' ' x ($num_bytes - length($value));
4801 0 ascii2bitstream($value, $bitstream, $pos, $num_bytes);
4802 0 $pos += $width;
4803 } else {
4804 # Encode value as integer in $width bits
4805 56 ▶ _croak "Value '$value' is not a number for descriptor $id"
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($value) 0 56 56
4806 unless looks_like_number($value);
4807 56 $value = int($value * 10**$scale - $refval + 0.5);
4808 56 ▶ _croak "Encoded data value for $id is negative: $value" if $value < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 0 56 56
4809 56 my $max_value = 2**$width - 1;
4810 56 ▶ _croak "Encoded data value for $id is too big to fit in $width bits: $value"
Branch: 1 branch
BranchTrueFalseTotal
if $value > $max_value 0 56 56
4811 if $value > $max_value;
4812 # Check for illegal flag value
4813 56 ▶ if ($Strict_checking && $unit =~ /^FLAG[ ]?TABLE/ && $width > 1
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2) 0 56 56
Condition41%5/12
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2
!ll&&!rl&&r
5600
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value
!ll&&!rl&&r
5600
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1
!ll&&!rl&&r
5600
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/
!ll&&!rl&&r
16400
MC/DC0%0/5
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1 and $value < $max_value and $value % 2
$Geo::BUFR::Strict_checking $unit =~ /^FLAG[ ]?TABLE/ $width > 1 $value < $max_value $value % 2
Truth table33%2/6
A and B and C and D and E
A= $Geo::BUFR::Strict_checkingB= $unit =~ /^FLAG[ ]?TABLE/C= $width > 1D= $value < $max_valueE= $value % 2
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
4814 && $value < $max_value && $value % 2) {
4815 0 _complain("$id - $value: rightmost bit $width is set indicating missing value"
4816 . " but then value should be $max_value");
4817 }
4818 56 dec2bitstream($value, $bitstream, $pos, $width);
4819 56 $pos += $width;
4820 }
4821  
4822 56 return ($bitstream, $pos, $maxlen);
4823 }
4824  
4825 # Encode reference value using BUFR compression, assuming all subsets
4826 # have same reference value
4827 sub _encode_compressed_reference_value {
4828 1 ▶ my $self = shift;
Subroutine _encode_compressed_reference_value: called CC=6 SCAR=20.9
4829 1 my ($refval,$id,$nsubsets,$bitstream,$pos,$maxlen) = @_;
4830  
4831 1 my $width = $self->{CHANGE_REFERENCE_VALUE};
4832  
4833 # Ensure that bitstream is big enough to encode $value
4834 1 ▶ while ($pos + ($nsubsets+1)*$width + 6 > $maxlen*8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + ($nsubsets + 1) * $width + 6 > $maxlen * 8) 0 1 1
4835 0 $bitstream .= chr(255) x $maxlen;
4836 0 $maxlen *= 2;
4837 }
4838  
4839 1 ▶ $self->_spew(4, "Encoding new reference value %d for %6s in %d bits",
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1 1
4840 $refval, $id, $width) if $Spew;
4841 # Encode value as integer in $width bits
4842 1 ▶ if ($refval >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refval >= 0) { } 0 1 1
4843 0 ▶ _croak "Encoded reference value for $id is too big to fit "
Branch: 1 branch
BranchTrueFalseTotal
if $refval > 2 ** $width - 1 0 0 0
4844 . "in $width bits: $refval" if $refval > 2**$width - 1;
4845 0 dec2bitstream($refval, $bitstream, $pos, $width);
4846 } else {
4847 # Negative reference values should be encoded by setting first
4848 # bit to 1 and then encoding absolute value
4849 1 ▶ _croak "Encoded reference value for $id is too big to fit "
Branch: 1 branch
BranchTrueFalseTotal
if -$refval > 2 ** ($width - 1) - 1 0 1 1
4850 . "in $width bits: $refval" if -$refval > 2**($width-1) - 1;
4851 1 dec2bitstream(-$refval, $bitstream, $pos+1, $width-1);
4852 }
4853 1 $pos += $width;
4854  
4855 # Increment width set to 0
4856 1 dec2bitstream(0, $bitstream, $pos, 6);
4857 1 $pos += 6;
4858  
4859 1 return ($bitstream, $pos, $maxlen);
4860 }
4861  
4862 sub _encode_compressed_value {
4863 479 ▶ my $self = shift;
Subroutine _encode_compressed_value: called CC=58 SCAR=47.9
4864 479 my ($bitstream,$pos,$maxlen,$unit,$scale,$refval,$width,$id,$data_refs,$idesc,$nsubsets) = @_;
4865  
4866 # Override Table B values if Data Description Operators are in
4867 # effect (except for associated fields)
4868 479 ▶ if ($self->{NUM_CHANGE_OPERATORS} > 0 && $id != 999999) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999) 12 467 479
Condition66%2/3
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
!ll&&!rl&&r
467012
MC/DC50%1/2
$self->{"NUM_CHANGE_OPERATORS"} > 0 and $id != 999999
$self->{"NUM_CHANGE_OPERATORS"} > 0 $id != 999999
Truth table66%2/3
A and B
A= $self->{"NUM_CHANGE_OPERATORS"} > 0B= $id != 999999
ABresult
0X0
100
111
4869 12 ▶ if ($unit ne 'CCITTIA5' && $unit !~ /^(CODE|FLAG)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($unit ne 'CCITTIA5' and not $unit =~ /^(CODE|FLAG)/) { } 12 0 12
elsif ($unit eq 'CCITTIA5' and defined $self->{'CHANGE_CCITTIA5_WIDTH'}) { } 0 0 0
Condition33%1/3
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
!ll&&!rl&&r
0012
MC/DC0%0/2
$unit ne "CCITTIA5" and not $unit =~ /^(CODE|FLAG)/
$unit ne "CCITTIA5" not $unit =~ /^(CODE|FLAG)/
Truth table33%1/3
A and not(B)
A= $unit ne "CCITTIA5"B= not $unit =~ /^(CODE|FLAG)/
ABresult
0X0
100
111
4870 12 ▶ if (defined $self->{CHANGE_SRW}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'CHANGE_SRW'}) { } 1 11 12
4871 1 $scale += $self->{CHANGE_SRW};
4872 1 $width += int((10*$self->{CHANGE_SRW}+2)/3);
4873 1 $refval *= 10*$self->{CHANGE_SRW};
4874 } else {
4875 11 ▶ $scale += $self->{CHANGE_SCALE} if defined $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_SCALE"} 3 8 11
4876 11 ▶ $width += $self->{CHANGE_WIDTH} if defined $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"CHANGE_WIDTH"} 11 0 11
4877 }
4878 ▶ } elsif ($unit eq 'CCITTIA5' && defined $self->{CHANGE_CCITTIA5_WIDTH}) {
Condition0%0/3
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
!ll&&!rl&&r
000
MC/DC0%0/2
$unit eq "CCITTIA5" and defined $self->{"CHANGE_CCITTIA5_WIDTH"}
$unit eq "CCITTIA5" defined $self->{"CHANGE_CCITTIA5_WIDTH"}
Truth table0%0/3
A and B
A= $unit eq "CCITTIA5"B= defined $self->{"CHANGE_CCITTIA5_WIDTH"}
ABresult
0X0
100
111
4879 $width = $self->{CHANGE_CCITTIA5_WIDTH}
4880 0 }
4881 12 ▶ _croak "$id Data width <= 0" if $width <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width <= 0 0 12 12
4882 12 ▶ $refval = $self->{NEW_REFVAL_OF}{$id} if defined $self->{NEW_REFVAL_OF}{$id};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_REFVAL_OF"}{$id} 1 11 12
4883 # Difference statistical values use different width and reference value
4884 12 ▶ if ($self->{DIFFERENCE_STATISTICAL_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DIFFERENCE_STATISTICAL_VALUE"}) 0 12 12
4885 0 $width += 1;
4886 0 $refval = -2**$width;
4887 0 undef $self->{DIFFERENCE_STATISTICAL_VALUE};
4888 0 $self->{NUM_CHANGE_OPERATORS}--;
4889 }
4890 }
4891  
4892 # Ensure that bitstream is big enough to encode $value
4893 479 ▶ while ($pos + ($nsubsets+1)*$width + 6 > $maxlen*8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos + ($nsubsets + 1) * $width + 6 > $maxlen * 8) 0 479 479
4894 0 $bitstream .= chr(255) x $maxlen;
4895 0 $maxlen *= 2;
4896 }
4897  
4898 # Get all values for this descriptor
4899 479 my @values;
4900 479 my $first_value = $data_refs->[1][$idesc];
4901 479 my $all_equal = 1; # Set to 0 if at least 2 elements differ
4902 479 foreach my $value (map { $data_refs->[$_][$idesc] } 2..$nsubsets) {
4903 603 ▶ if (defined $value && $unit ne 'CCITTIA5' && !looks_like_number($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $unit ne "CCITTIA5" and not &looks_like_number($value)) 0 603 603
Condition83%5/6
defined $value and $unit ne "CCITTIA5" and not &looks_like_number($value)
!ll&&!rl&&r
1424610
defined $value and $unit ne "CCITTIA5"
!ll&&!rl&&r
1402461
MC/DC0%0/3
defined $value and $unit ne "CCITTIA5" and not &looks_like_number($value)
defined $value $unit ne "CCITTIA5" not &looks_like_number($value)
Truth table75%3/4
A and B and not(C)
A= defined $valueB= $unit ne "CCITTIA5"C= not &looks_like_number($value)
ABCresult
0XX0
10X0
1100
1111
4904 0 _croak "Value '$value' is not a number for descriptor $id"
4905 }
4906 # This used to be a sub (_check_equality), but inlined for speed
4907 603 ▶ if ($all_equal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_equal) 544 59 603
4908 544 ▶ if (defined $value && defined $first_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $value and defined $first_value) { } 390 154 544
elsif (defined $value or defined $first_value) { } 23 131 154
Condition100%3/3
defined $value and defined $first_value
!ll&&!rl&&r
13519390
MC/DC100%2/2
defined $value and defined $first_value
defined $value defined $first_value
Truth table100%3/3
A and B
A= defined $valueB= defined $first_value
ABresult
0X0
100
111
4909 390 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 1 389 390
4910 1 ▶ $all_equal = 0 if $value ne $first_value;
Branch: 1 branch
BranchTrueFalseTotal
if $value ne $first_value 1 0 1
4911 } else {
4912 389 ▶ $all_equal = 0 if $value != $first_value;
Branch: 1 branch
BranchTrueFalseTotal
if $value != $first_value 89 300 389
4913 }
4914 ▶ } elsif (defined $value || defined $first_value) {
Condition100%3/3
defined $value or defined $first_value
l!l&&r!l&&!r
194131
MC/DC100%2/2
defined $value or defined $first_value
defined $value defined $first_value
Truth table100%3/3
A or B
A= defined $valueB= defined $first_value
ABresult
1X1
011
000
4915 23 $all_equal = 0;
4916 }
4917 }
4918 603 ▶ if (not defined $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value) { } 140 463 603
elsif ($unit eq 'CCITTIA5') { } 2 461 463
4919 140 push @values, undef;
4920 } elsif ($unit eq 'CCITTIA5') {
4921 2 push @values, $value;
4922 } else {
4923 461 push @values, int($value * 10**$scale - $refval + 0.5);
4924 }
4925 # Check for illegal flag value
4926 603 ▶ if ($Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1) 11 592 603
Condition83%5/6
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1
!ll&&!rl&&r
48510711
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/
!ll&&!rl&&r
0485118
MC/DC66%2/3
$Geo::BUFR::Strict_checking and $unit =~ /^FLAG[ ]?TABLE/ and $width > 1
$Geo::BUFR::Strict_checking $unit =~ /^FLAG[ ]?TABLE/ $width > 1
Truth table75%3/4
A and B and C
A= $Geo::BUFR::Strict_checkingB= $unit =~ /^FLAG[ ]?TABLE/C= $width > 1
ABCresult
0XX0
10X0
1100
1111
4927 11 ▶ if (defined $value and $value ne 'missing' and $value % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and $value ne "missing" and $value % 2) 0 11 11
Condition33%2/6
defined $value and $value ne "missing" and $value % 2
!ll&&!rl&&r
0110
defined $value and $value ne "missing"
!ll&&!rl&&r
0011
MC/DC0%0/3
defined $value and $value ne "missing" and $value % 2
defined $value $value ne "missing" $value % 2
Truth table25%1/4
A and B and C
A= defined $valueB= $value ne "missing"C= $value % 2
ABCresult
0XX0
10X0
1100
1111
4928 0 my $max_value = 2**$width - 1;
4929 0 _complain("$id - value $value in subset $_:\n"
4930 . "rightmost bit $width is set indicating missing value"
4931 . " but then value should be $max_value");
4932 }
4933 }
4934 }
4935  
4936 479 ▶ if ($all_equal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all_equal) { } 366 113 479
4937 # Same value in all subsets. No need to calculate or store increments
4938 366 ▶ if (defined $first_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $first_value) { } 270 96 366
4939 270 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 0 270 270
4940 # Encode ASCII string in $width bits (left justified,
4941 # padded with spaces)
4942 0 my $num_bytes = int ($width/8);
4943 0 ▶ _croak "Ascii string too long to fit in $width bits: $first_value"
Branch: 1 branch
BranchTrueFalseTotal
if length $first_value > $num_bytes 0 0 0
4944 if length($first_value) > $num_bytes;
4945 0 $first_value .= ' ' x ($num_bytes - length($first_value));
4946 0 ascii2bitstream($first_value, $bitstream, $pos, $num_bytes);
4947 } else {
4948 # Encode value as integer in $width bits
4949 270 ▶ _croak "First value '$first_value' is not a number for descriptor $id"
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($first_value) 0 270 270
4950 unless looks_like_number($first_value);
4951 270 $first_value = int($first_value * 10**$scale - $refval + 0.5);
4952 270 ▶ _croak "Encoded data value for $id is negative: $first_value"
Branch: 1 branch
BranchTrueFalseTotal
if $first_value < 0 0 270 270
4953 if $first_value < 0;
4954 270 ▶ _croak "Encoded data value for $id is too big to fit "
Branch: 1 branch
BranchTrueFalseTotal
if $first_value > 2 ** $width - 1 0 270 270
4955 . "in $width bits: $first_value"
4956 if $first_value > 2**$width - 1;
4957 270 dec2bitstream($first_value, $bitstream, $pos, $width);
4958 }
4959 } else {
4960 # Missing value is encoded as 1 bits, but bitstream is
4961 # padded with 1 bits already
4962 }
4963 366 $pos += $width;
4964 # Increment width set to 0
4965 366 dec2bitstream(0, $bitstream, $pos, 6);
4966 366 $pos += 6;
4967 } else {
4968 113 ▶ if ($unit eq 'CCITTIA5') {
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq 'CCITTIA5') { } 1 112 113
4969 1 unshift @values, $first_value;
4970 # Local reference value set to 0 bits
4971 1 null2bitstream($bitstream, $pos, $width);
4972 1 $pos += $width;
4973 # Do not store more characters than needed: remove leading
4974 # and trailing spaces, then right pad with spaces so that
4975 # all strings has same length as largest string
4976 1 my $largest_length = _trimpad(\@values);
4977 1 dec2bitstream($largest_length, $bitstream, $pos, 6);
4978 1 $pos += 6;
4979 # Store the character values
4980 1 foreach my $value (@values) {
4981 3 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 3 0 3
4982 # Encode ASCII string in $largest_length bytes
4983 3 ascii2bitstream($value, $bitstream, $pos, $largest_length);
4984 } else {
4985 # Missing value is encoded as 1 bits, but
4986 # bitstream is padded with 1 bits already
4987 }
4988 3 $pos += $largest_length * 8;
4989 }
4990 } else {
4991 112 ▶ _croak "First value '$first_value' is not a number for descriptor $id"
Branch: 1 branch
BranchTrueFalseTotal
if defined $first_value and not &looks_like_number($first_value) 0 112 112
Condition66%2/3
defined $first_value and not &looks_like_number($first_value)
!ll&&!rl&&r
19930
MC/DC0%0/2
defined $first_value and not &looks_like_number($first_value)
defined $first_value not &looks_like_number($first_value)
Truth table66%2/3
A and not(B)
A= defined $first_valueB= not &looks_like_number($first_value)
ABresult
0X0
100
111
4992 if defined($first_value) && !looks_like_number($first_value);
4993 112 ▶ unshift @values, defined $first_value
Branch: 1 branch
BranchTrueFalseTotal
defined $first_value ? : 93 19 112
4994 ? int($first_value * 10**$scale - $refval + 0.5)
4995 : undef;
4996 # Numeric data. First find minimum value
4997 112 my ($min_value, $isub) = _minimum(\@values);
4998 112 ▶ _croak "Encoded data value for $id and subset $isub is negative: $min_value"
Branch: 1 branch
BranchTrueFalseTotal
if $min_value < 0 0 112 112
4999 if $min_value < 0;
5000 my @inc_values =
5001 112 ▶ map { defined $_ ? $_ - $min_value : undef } @values;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 256 30 286
5002 # Find how many bits are required to hold the increment
5003 # values (or rather: the highest increment value pluss one
5004 # (except for associated values), to be able to store
5005 # missing values also)
5006 112 my $max_inc = _maximum(\@inc_values);
5007 112 ▶ my $deltabits = ($id eq '999999')
Branch: 1 branch
BranchTrueFalseTotal
$id eq '999999' ? : 0 112 112
5008 ?_get_number_of_bits_to_store($max_inc)
5009 : _get_number_of_bits_to_store($max_inc + 1);
5010 # Store local reference value
5011 112 ▶ $self->_spew(5, " Local reference value: %d", $min_value) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 112 112
5012 112 dec2bitstream($min_value, $bitstream, $pos, $width);
5013 112 $pos += $width;
5014 # Store increment width
5015 112 ▶ $self->_spew(5, " Increment width (bits): %d", $deltabits) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 112 112
5016 112 dec2bitstream($deltabits, $bitstream, $pos, 6);
5017 112 $pos += 6;
5018 # Store values
5019 $self->_spew(5, " Increment values: %s",
5020 112 ▶ join(',', map { defined $inc_values[$_]
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 112 112
defined $inc_values[$_] ? : 0 0 0
5021 ? $inc_values[$_] : ''} 0..$#inc_values))
5022 if $Spew;
5023 112 foreach my $value (@inc_values) {
5024 286 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 256 30 286
5025 256 ▶ _complain("value " . ($value + $min_value) . " for $id too big"
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and $value + $min_value > 2 ** $width - 1 0 256 256
Condition33%1/3
$Geo::BUFR::Strict_checking and $value + $min_value > 2 ** $width - 1
!ll&&!rl&&r
02560
MC/DC0%0/2
$Geo::BUFR::Strict_checking and $value + $min_value > 2 ** $width - 1
$Geo::BUFR::Strict_checking $value + $min_value > 2 ** $width - 1
Truth table33%1/3
A and B
A= $Geo::BUFR::Strict_checkingB= $value + $min_value > 2 ** $width - 1
ABresult
0X0
100
111
5026 . " to be encoded without compression")
5027 if ($Strict_checking && ($value + $min_value) > 2**$width -1);
5028 256 dec2bitstream($value, $bitstream, $pos, $deltabits);
5029 } else {
5030 # Missing value is encoded as 1 bits, but
5031 # bitstream is padded with 1 bits already
5032 }
5033 286 $pos += $deltabits;
5034 }
5035 }
5036 }
5037  
5038 479 return ($bitstream, $pos, $maxlen);
5039 }
5040  
5041 ## Encode bitstream using the data values in $data_refs, first
5042 ## expanding section 3 fully (and comparing with $desc_refs to check
5043 ## for consistency). This sub is very similar to sub
5044 ## _decompress_bitstream
5045 sub _encode_compressed_bitstream {
5046 6 ▶ my $self = shift;
Subroutine _encode_compressed_bitstream: called CC=64 SCAR=52.5
5047 6 $self->{CODING} = 'ENCODE';
5048 6 my ($data_refs, $desc_refs) = @_;
5049  
5050 # Expand section 3 except for delayed replication and operator
5051 # descriptors. This expansion is the same for all subsets, since
5052 # delayed replication has to be the same (this needs to be
5053 # checked) for compression to be possible
5054 6 my @unexpanded = split / /, $self->{DESCRIPTORS_UNEXPANDED};
5055 6 my $alias = "$self->{TABLE_VERSION} " . $self->{DESCRIPTORS_UNEXPANDED};
5056 6 ▶ if (exists $Descriptors_already_expanded{$alias}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Geo::BUFR::Descriptors_already_expanded{$alias}) { } 0 6 6
5057 0 $self->{DESCRIPTORS_EXPANDED} = $Descriptors_already_expanded{$alias};
5058 } else {
5059 $Descriptors_already_expanded{$alias} = $self->{DESCRIPTORS_EXPANDED}
5060 6 = join " ", _expand_descriptors($self->{D_TABLE}, @unexpanded);
5061 }
5062 6 my @desc = split /\s/, $self->{DESCRIPTORS_EXPANDED};
5063  
5064 6 my $nsubsets = $self->{NUM_SUBSETS};
5065 6 my $B_table = $self->{B_TABLE};
5066 6 my $maxlen = 1024;
5067 6 my $bitstream = chr(255) x $maxlen; # one bits only
5068 6 my $pos = 0;
5069 6 my @operators;
5070  
5071 6 my $desc_ref = $desc_refs->[1];
5072  
5073 # All subsets should have same set of expanded descriptors. This
5074 # is checked later, but we also need to check that the number of
5075 # descriptors in each subset is the same for all subsets
5076 6 my $num_desc = @{$desc_ref};
5077 6 foreach my $isub (2..$nsubsets) {
5078 7 my $num_d = @{$desc_refs->[$isub]};
5079 7 ▶ _croak "Compression impossible: Subset 1 contains $num_desc descriptors,"
Branch: 1 branch
BranchTrueFalseTotal
if $num_d != $num_desc 0 7 7
5080 . " while subset $isub contains $num_d descriptors"
5081 if $num_d != $num_desc;
5082 }
5083  
5084  
5085 6 ▶ D_LOOP: for (my $idesc = 0; $idesc < @desc; $idesc++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) 510 6 516
5086 518 my $id = $desc[$idesc];
5087 518 my $f = substr($id,0,1);
5088 518 my $x = substr($id,1,2)+0;
5089 518 my $y = substr($id,3,3)+0;
5090  
5091 518 ▶ if ($f == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($f == 1) { } 7 511 518
elsif ($f == 2) { } 38 473 511
5092 # Delayed replication
5093 7 ▶ if ($x == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x == 0) 0 7 7
5094 0 _complain("Nonsensical replication of zero descriptors ($id)");
5095 0 $idesc++;
5096 0 next D_LOOP;
5097 }
5098 7 ▶ _croak "$id _expand_descriptors() did not do its job"
Branch: 1 branch
BranchTrueFalseTotal
if $y > 0 0 7 7
5099 if $y > 0;
5100  
5101 7 my $next_id = $desc[$idesc+1];
5102 _croak "$id Erroneous replication factor"
5103 7 ▶ unless $next_id =~ /^0310(00|01|02|11|12)/ && exists $B_table->{$next_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id} 0 7 7
Condition33%1/3
$next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id}
!ll&&!rl&&r
007
MC/DC0%0/2
$next_id =~ /^0310(00|01|02|11|12)/ and exists $B_table->{$next_id}
$next_id =~ /^0310(00|01|02|11|12)/ exists $B_table->{$next_id}
Truth table33%1/3
A and B
A= $next_id =~ /^0310(00|01|02|11|12)/B= exists $B_table->{$next_id}
ABresult
0X0
100
111
5104 7 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $next_id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $next_id 0 7 7
5105 if $desc_ref->[$idesc] != $next_id;
5106 7 my $factor = $data_refs->[1][$idesc];
5107 7 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$next_id};
5108 7 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 7 7
5109 0 $self->_spew(3, "%6s %-20s %s", $next_id, $unit, $name);
5110 0 $self->_spew(3, " %s", $factor);
5111 }
5112 7 ($bitstream, $pos, $maxlen)
5113 = $self->_encode_compressed_value($bitstream,$pos,$maxlen,
5114 $unit,$scale,$refval,$width,
5115 $next_id,$data_refs,$idesc,$nsubsets);
5116 # Include the delayed replication/repetition in descriptor list
5117 7 splice @desc, $idesc++, 0, $next_id;
5118  
5119 7 my @r = ();
5120 7 ▶ push @r, @desc[($idesc+2)..($idesc+$x+1)] while $factor--;
Branch: 1 branch
BranchTrueFalseTotal
$factor-- and do { push @r, @desc[$idesc + 2 .. $idesc + $x + 1] } 18 7 25
5121 7 splice @desc, $idesc, 2+$x, @r;
5122  
5123 7 ▶ if ($next_id eq '031011' || $next_id eq '031012') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_id eq '031011' or $next_id eq '031012') { } 1 6 7
Condition66%2/3
$next_id eq "031011" or $next_id eq "031012"
l!l&&r!l&&!r
106
MC/DC50%1/2
$next_id eq "031011" or $next_id eq "031012"
$next_id eq "031011" $next_id eq "031012"
Truth table66%2/3
A or B
A= $next_id eq "031011"B= $next_id eq "031012"
ABresult
1X1
011
000
5124 # For delayed repetition we should include data just
5125 # once, so skip to the last set in data array
5126 1 $idesc += $x * ($data_refs->[1][$idesc-1] - 1);
5127 # We ought to check that the data sets we skipped are
5128 # indeed equal to the last set!
5129 1 ▶ $self->_spew(4, "Delayed repetition ($id $next_id -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 1 1
5130 } else {
5131 6 ▶ $self->_spew(4, "Delayed replication ($id $next_id -> @r)") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 6 6
5132 }
5133 7 ▶ if ($idesc < @desc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idesc < @desc) { } 7 0 7
5134 7 redo D_LOOP;
5135 } else {
5136 0 last D_LOOP; # Might happen if delayed factor is 0
5137 }
5138  
5139 } elsif ($f == 2) {
5140 38 my $flow;
5141 my $bm_idesc;
5142 38 ($pos, $flow, $bm_idesc, @operators)
5143 = $self->_apply_operator_descriptor($id, $x, $y, $pos, 0,
5144 $desc[$idesc+1], @operators);
5145 38 ▶ if ($flow eq 'redo_bitmap') {
Branch: 3 branches
BranchTrueFalseTotal
if ($flow eq 'redo_bitmap') { } 1 37 38
elsif ($flow eq 'signify_character') { } 0 37 37
elsif ($flow eq 'no_value') { } 8 29 37
5146 # Data value is associated with the descriptor
5147 # defined by bit map. Remember original and new
5148 # index in descriptor array for the bit mapped
5149 # values ('dr' = data reference)
5150 1 my $dr_idesc;
5151 1 ▶ if (!defined $bm_idesc) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $bm_idesc) { } 0 1 1
elsif (not $Geo::BUFR::Show_all_operators) { } 1 0 1
5152 0 $dr_idesc = shift @{ $self->{REUSE_BITMAP}->[0] };
5153 } elsif (!$Show_all_operators) {
5154 1 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
5155 + $bm_idesc;
5156 } else {
5157 0 $dr_idesc = $self->{BITMAP_START}[$self->{NUM_BITMAPS}];
5158 # Skip operator descriptors
5159 0 ▶ while ($bm_idesc-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bm_idesc-- > 0) 0 0 0
5160 0 $dr_idesc++;
5161 0 ▶ $dr_idesc++ while ($desc[$dr_idesc] >= 200000);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$dr_idesc] >= 200000 and do { ++$dr_idesc } 0 0 0
5162 }
5163 }
5164 1 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
5165 $dr_idesc, $idesc;
5166 1 $desc[$idesc] = $desc[$dr_idesc];
5167 1 redo D_LOOP;
5168 } elsif ($flow eq 'signify_character') {
5169 0 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $id 0 0 0
5170 if $desc_ref->[$idesc] != $id;
5171 # Get ASCII string
5172 0 my @values = map { $data_refs->[$_][$idesc] } 1..$nsubsets;
5173 0 my $name = 'SIGNIFY CHARACTER';
5174 0 my $unit = 'CCITTIA5';
5175 0 my ($scale, $refval, $width) = (0, 0, 8*$y);
5176 0 ($bitstream, $pos, $maxlen)
5177 = $self->_encode_compressed_value($bitstream,$pos,$maxlen,
5178 $unit,$scale,$refval,$width,
5179 "205$y",$data_refs,$idesc,$nsubsets);
5180 0 next D_LOOP;
5181 } elsif ($flow eq 'no_value') {
5182 8 next D_LOOP;
5183 }
5184  
5185 # Remove operator descriptor from @desc
5186 29 splice @desc, $idesc--, 1;
5187  
5188 29 ▶ next D_LOOP if $flow eq 'next';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "next" 29 0 29
5189 0 ▶ last D_LOOP if $flow eq 'last';
Branch: 1 branch
BranchTrueFalseTotal
if $flow eq "last" 0 0 0
5190 }
5191  
5192 473 ▶ if ($self->{CHANGE_REFERENCE_VALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CHANGE_REFERENCE_VALUE"}) 1 472 473
5193 # The data descriptor is to be associated with a new
5194 # reference value, which is fetched from data stream,
5195 # possibly with f=9 instead of f=0 for descriptor
5196 1 ▶ $id -= 900000 if $id =~ /^9/;
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /^9/ 0 1 1
5197 1 ▶ _croak "Change reference operator 203Y is not followed by element"
Branch: 1 branch
BranchTrueFalseTotal
if $f > 0 0 1 1
5198 . " descriptor, but $id" if $f > 0;
5199 1 my @new_ref_values = map { $data_refs->[$_][$idesc] } 1..$nsubsets;
5200 1 my $new_refval = $new_ref_values[0];
5201 # Check that they are all the same
5202 1 foreach my $val (@new_ref_values[1..$#new_ref_values]) {
5203 1 ▶ _croak "Change reference value differ between subsets"
Branch: 1 branch
BranchTrueFalseTotal
if $val != $new_refval 0 1 1
5204 . " which cannot be combined with BUFR compression"
5205 if $val != $new_refval;
5206 }
5207 1 $self->{NEW_REFVAL_OF}{$id} = $new_refval;
5208 1 ($bitstream, $pos, $maxlen)
5209 = $self->_encode_compressed_reference_value($new_refval,$id,$nsubsets,$bitstream,$pos,$maxlen);
5210 1 next D_LOOP;
5211 }
5212  
5213 # If operator 204$y 'Add associated field' is in effect,
5214 # each data value is preceded by $y bits which should be
5215 # encoded separately. We choose to provide a descriptor
5216 # 999999 in this case (like the ECMWF BUFRDC software)
5217 472 ▶ if ($self->{ADD_ASSOCIATED_FIELD} and $id ne '031021') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021") 0 472 472
Condition33%1/3
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
!ll&&!rl&&r
47200
MC/DC0%0/2
$self->{"ADD_ASSOCIATED_FIELD"} and $id ne "031021"
$self->{"ADD_ASSOCIATED_FIELD"} $id ne "031021"
Truth table33%1/3
A and B
A= $self->{"ADD_ASSOCIATED_FIELD"}B= $id ne "031021"
ABresult
0X0
100
111
5218 # First encode associated field
5219 0 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected 999999"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != 999999 0 0 0
5220 if $desc_ref->[$idesc] != 999999;
5221 0 my @values = map { $data_refs->[$_][$idesc] } 1..$nsubsets;
5222 0 my $name = 'ASSOCIATED FIELD';
5223 0 my $unit = 'NUMERIC';
5224 0 my ($scale, $refval) = (0, 0);
5225 0 my $width = $self->{ADD_ASSOCIATED_FIELD};
5226 0 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 0 0
5227 0 $self->_spew(3, "%6s %-20s %s", $id, $unit, $name);
5228 0 $self->_spew(3, " %s", 999999);
5229 }
5230 0 ($bitstream, $pos, $maxlen)
5231 = $self->_encode_compressed_value($bitstream,$pos,$maxlen,
5232 $unit,$scale,$refval,$width,
5233 999999,$data_refs,$idesc,$nsubsets);
5234 # Insert the artificial 999999 descriptor for the
5235 # associated value and increment $idesc to prepare for
5236 # handling the 'real' value below
5237 0 splice @desc, $idesc++, 0, 999999;
5238 }
5239  
5240  
5241  
5242 # For quality information, if this relates to a bit map we
5243 # need to store index of the data ($data_idesc) for which
5244 # the quality information applies, as well as the new
5245 # index ($idesc) in the descriptor array for the bit
5246 # mapped values
5247 472 ▶ if (substr($id,0,3) eq '033'
Branch: 1 branch
BranchTrueFalseTotal
if (substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000) 30 442 472
Condition83%5/6
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
!ll&&!rl&&r
442030
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"}
!ll&&!rl&&r
4321030
MC/DC66%2/3
substr($id, 0, 3) eq "033" and defined $self->{"BITMAP_OPERATORS"} and $self->{"BITMAP_OPERATORS"}[-1] eq 222000
substr($id, 0, 3) eq "033" defined $self->{"BITMAP_OPERATORS"} $self->{"BITMAP_OPERATORS"}[-1] eq 222000
Truth table75%3/4
A and B and C
A= substr($id, 0, 3) eq "033"B= defined $self->{"BITMAP_OPERATORS"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 222000
ABCresult
0XX0
10X0
1100
1111
5248 && defined $self->{BITMAP_OPERATORS}
5249 && $self->{BITMAP_OPERATORS}->[-1] eq '222000') {
5250 30 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 20 10 30
5251 20 my $data_idesc = shift @{ $self->{REUSE_BITMAP}->[0] };
5252 20 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 20 20
5253 if not defined $data_idesc;
5254 20 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
5255 $data_idesc, $idesc;
5256 } else {
5257 10 my $data_idesc = shift @{ $self->{CURRENT_BITMAP} };
5258 10 ▶ _croak "$id: Not enough quality values provided"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data_idesc 0 10 10
5259 if not defined $data_idesc;
5260 10 push @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}]->[0] },
5261 10 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
5262 + $data_idesc, $idesc;
5263 }
5264 }
5265  
5266 472 ▶ if ($id eq '031031' and $self->{BUILD_BITMAP}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($id eq '031031' and $self->{'BUILD_BITMAP'}) { } 107 365 472
elsif ($self->{'BUILD_BITMAP'} and $self->{'BITMAP_INDEX'} > 0) { } 2 702 704
Condition66%2/3
$id eq "031031" and $self->{"BUILD_BITMAP"}
!ll&&!rl&&r
3650107
MC/DC50%1/2
$id eq "031031" and $self->{"BUILD_BITMAP"}
$id eq "031031" $self->{"BUILD_BITMAP"}
Truth table66%2/3
A and B
A= $id eq "031031"B= $self->{"BUILD_BITMAP"}
ABresult
0X0
100
111
5267 # Store the index of expanded descriptors if data is
5268 # marked as present in data present indicator: 0 is
5269 # 'present', 1 (undef value) is 'not present'. E.g.
5270 # bitmap = 1100110 => (2,3,6) is stored in $self->{CURRENT_BITMAP}
5271  
5272 # NB: bit map might vary betwen subsets!!!!????
5273 107 ▶ if ($data_refs->[1][$idesc] == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_refs->[1][$idesc] == 0) 11 96 107
5274 11 push @{$self->{CURRENT_BITMAP}}, $self->{BITMAP_INDEX};
5275 }
5276 107 $self->{BITMAP_INDEX}++;
5277 107 ▶ if ($self->{BACKWARD_DATA_REFERENCE} == $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} == $self->{"NUM_BITMAPS"}) 107 0 107
5278 107 my $numb = $self->{NUM_BITMAPS};
5279 107 ▶ if (!defined $self->{BITMAP_START}[$numb]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'BITMAP_START'}[$numb]) { } 2 105 107
5280 # Look up the element descriptor immediately
5281 # preceding the bitmap operator
5282 2 my $i = $idesc;
5283 2 ▶ $i-- while ($desc[$i] ne $self->{BITMAP_OPERATORS}->[-1]
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0 and do { --$i } 5 2 7
Condition66%2/3
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
!ll&&!rl&&r
205
MC/DC50%1/2
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] and $i >= 0
$desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1] $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] ne $self->{"BITMAP_OPERATORS"}[-1]B= $i >= 0
ABresult
0X0
100
111
5284 && $i >=0);
5285 2 ▶ $i-- while ($desc[$i] > 100000 && $i >=0);
Branch: 1 branch
BranchTrueFalseTotal
$desc[$i] > 100000 and $i >= 0 and do { --$i } 2 2 4
Condition66%2/3
$desc[$i] > 100000 and $i >= 0
!ll&&!rl&&r
202
MC/DC50%1/2
$desc[$i] > 100000 and $i >= 0
$desc[$i] > 100000 $i >= 0
Truth table66%2/3
A and B
A= $desc[$i] > 100000B= $i >= 0
ABresult
0X0
100
111
5286 2 ▶ _croak "No element descriptor preceding bitmap" if $i < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 2 2
5287 2 $self->{BITMAP_START}[$numb] = $i;
5288 } else {
5289 105 $self->{BITMAP_START}[$numb]--;
5290 _croak "Bitmap too big"
5291 105 ▶ if $self->{BITMAP_START}[$numb] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"BITMAP_START"}[$numb] < 0 0 105 105
5292 }
5293 }
5294 ▶ } elsif ($self->{BUILD_BITMAP} and $self->{BITMAP_INDEX} > 0) {
Condition100%3/3
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
!ll&&!rl&&r
339242
MC/DC100%2/2
$self->{"BUILD_BITMAP"} and $self->{"BITMAP_INDEX"} > 0
$self->{"BUILD_BITMAP"} $self->{"BITMAP_INDEX"} > 0
Truth table100%3/3
A and B
A= $self->{"BUILD_BITMAP"}B= $self->{"BITMAP_INDEX"} > 0
ABresult
0X0
100
111
5295 # We have finished building the bit map
5296 2 $self->{BUILD_BITMAP} = 0;
5297 2 $self->{BITMAP_INDEX} = 0;
5298 2 ▶ if ($self->{BACKWARD_DATA_REFERENCE} != $self->{NUM_BITMAPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"BACKWARD_DATA_REFERENCE"} != $self->{"NUM_BITMAPS"}) 0 2 2
5299 $self->{BITMAP_START}[$self->{NUM_BITMAPS}]
5300 0 = $self->{BITMAP_START}[$self->{BACKWARD_DATA_REFERENCE}];
5301 }
5302 }
5303  
5304 # We now have a "real" data descriptor
5305 472 ▶ _croak "Descriptor no $idesc is $desc_ref->[$idesc], expected $id"
Branch: 1 branch
BranchTrueFalseTotal
if $desc_ref->[$idesc] != $id 0 472 472
5306 if $desc_ref->[$idesc] != $id;
5307  
5308 # Find the relevant entry in BUFR table B
5309 _croak "Data descriptor $id is not present in BUFR table B"
5310 472 ▶ unless exists $B_table->{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $B_table->{$id} 0 472 472
5311 472 my ($name,$unit,$scale,$refval,$width) = split /\0/, $B_table->{$id};
5312 472 ▶ if ($Spew) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Spew) 0 472 472
5313 0 $self->_spew(3, "%6s %-20s %s", $id, $unit, $name);
5314 $self->_spew(3, " %s", join ' ',
5315 0 ▶ map { defined($data_refs->[$_][$idesc]) ?
Branch: 1 branch
BranchTrueFalseTotal
defined $data_refs->[$_][$idesc] ? : 0 0 0
5316 $data_refs->[$_][$idesc] : 'missing'} 1..$nsubsets );
5317 }
5318 472 ($bitstream, $pos, $maxlen)
5319 = $self->_encode_compressed_value($bitstream,$pos,$maxlen,
5320 $unit,$scale,$refval,$width,
5321 $id,$data_refs,$idesc,$nsubsets);
5322 } # End D_LOOP
5323  
5324 # Pad with 0 bits if necessary to get an even or integer number of
5325 # octets, depending on bufr edition
5326 6 ▶ my $padnum = $self->{BUFR_EDITION} < 4 ? (16-($pos%16)) % 16 : (8-($pos%8)) % 8;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'BUFR_EDITION'} < 4 ? : 5 1 6
5327 6 ▶ if ($padnum > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($padnum > 0) 4 2 6
5328 4 null2bitstream($bitstream, $pos, $padnum);
5329 }
5330 6 my $len = ($pos + $padnum)/8;
5331 6 $bitstream = substr $bitstream, 0, $len;
5332  
5333 6 return ($bitstream, $len);
5334 }
5335  
5336 ## Check that the length of data section computed from expansion of
5337 ## section 3 ($comp_len) equals actual length of data part of section
5338 ## 4, allowing for padding zero bits according to BUFR Regulation 94.1.3
5339 ## Strict checking should also check that padding actually consists of
5340 ## zero bits only.
5341 sub _check_section4_length {
5342 56 ▶ my $self = shift;
Subroutine _check_section4_length: called CC=10 SCAR=25.0
5343 56 my ($comp_len, $actual_len) = @_;
5344  
5345 56 ▶ if ($comp_len > $actual_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp_len > $actual_len) { } 0 56 56
5346 0 _croak "More descriptors in expansion of section 3"
5347 . " than what can fit in the given length of section 4"
5348 . " ($comp_len versus $actual_len bits)";
5349 } else {
5350 56 ▶ return if not $Strict_checking; # Excessive bytes in section 4
Branch: 1 branch
BranchTrueFalseTotal
unless $Geo::BUFR::Strict_checking 42 14 56
5351 # does not prevent further decoding
5352 14 ▶ return if $Noqc; # No more sensible checks to do in this case
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Noqc 0 14 14
5353  
5354 14 my $bufr_edition = $self->{BUFR_EDITION};
5355 14 my $actual_bytes = $actual_len/8; # This is sure to be an integer
5356 14 ▶ if ($bufr_edition < 4 and $actual_bytes % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bufr_edition < 4 and $actual_bytes % 2) 0 14 14
Condition33%1/3
$bufr_edition < 4 and $actual_bytes % 2
!ll&&!rl&&r
0140
MC/DC0%0/2
$bufr_edition < 4 and $actual_bytes % 2
$bufr_edition < 4 $actual_bytes % 2
Truth table33%1/3
A and B
A= $bufr_edition < 4B= $actual_bytes % 2
ABresult
0X0
100
111
5357 0 _complain("Section 4 is odd number ($actual_bytes) of bytes,"
5358 . " which is an error in BUFR edition $bufr_edition");
5359 }
5360 14 my $comp_bytes = int($comp_len/8);
5361 14 ▶ $comp_bytes++ if $comp_len % 8; # Need to pad with zero bits
Branch: 1 branch
BranchTrueFalseTotal
if $comp_len % 8 13 1 14
5362 14 ▶ $comp_bytes++ if $bufr_edition < 4 and $comp_bytes % 2; # Need to pad with an extra byte of zero bits
Branch: 1 branch
BranchTrueFalseTotal
if $bufr_edition < 4 and $comp_bytes % 2 10 4 14
Condition66%2/3
$bufr_edition < 4 and $comp_bytes % 2
!ll&&!rl&&r
0410
MC/DC50%1/2
$bufr_edition < 4 and $comp_bytes % 2
$bufr_edition < 4 $comp_bytes % 2
Truth table66%2/3
A and B
A= $bufr_edition < 4B= $comp_bytes % 2
ABresult
0X0
100
111
5363 14 ▶ if ($actual_bytes > $comp_bytes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($actual_bytes > $comp_bytes) 0 14 14
5364 0 _complain("Binary data part of section 4 longer ($actual_bytes bytes)"
5365 . " than expected from section 3 ($comp_bytes bytes)");
5366 }
5367 }
5368 14 return;
5369 }
5370  
5371 # Trim string, also removing nulls (and _complain if nulls found).
5372 # If strict_checking, checks also for bit 1 set in each character
5373 sub _trim {
5374 83 ▶ my ($str, $id) = @_;
Subroutine _trim: called CC=9 SCAR=26.2
5375 83 ▶ return unless defined $str;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $str 0 83 83
5376 83 ▶ if ($str =~ /\0/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /\0/) { } 0 83 83
elsif ($Geo::BUFR::Strict_checking and $str =~ /^ +$/) { } 0 139 139
5377 0 (my $str2 = $str) =~ s|\0|\\0|g;
5378 0 _complain("Nulls (" . '\0'
5379 . ") found in string '$str2' for descriptor $id");
5380 0 $str =~ s/\0//g;
5381 ▶ } elsif ($Strict_checking && $str =~/^ +$/) {
Condition66%2/3
$Geo::BUFR::Strict_checking and $str =~ /^ +$/
!ll&&!rl&&r
56270
MC/DC0%0/2
$Geo::BUFR::Strict_checking and $str =~ /^ +$/
$Geo::BUFR::Strict_checking $str =~ /^ +$/
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= $str =~ /^ +$/
ABresult
0X0
100
111
5382 0 _complain("Only spaces ('$str') found for descriptor $id, "
5383 . "ought to have been encoded as missing value ");
5384 }
5385  
5386 83 $str =~ s/\s+$//;
5387 83 $str =~ s/^\s+//;
5388  
5389 83 ▶ if ($Strict_checking && $str ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking and $str ne "") 27 56 83
Condition66%2/3
$Geo::BUFR::Strict_checking and $str ne ""
!ll&&!rl&&r
56027
MC/DC50%1/2
$Geo::BUFR::Strict_checking and $str ne ""
$Geo::BUFR::Strict_checking $str ne ""
Truth table66%2/3
A and B
A= $Geo::BUFR::Strict_checkingB= $str ne ""
ABresult
0X0
100
111
5390 27 foreach my $char (split //, $str) {
5391 135 ▶ if (ord($char) > 127) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $char > 127) 0 135 135
5392 0 _complain("Character $char (ascii value " . ord($char) .
5393 ") in string '$str' is not allowed in CCITTIA5");
5394 0 last; # Don't want to warn for every bad character
5395 }
5396 }
5397 }
5398 83 return $str;
5399 }
5400  
5401 ## Remove leading and trailing spaces in the strings provided, then add
5402 ## spaces if necessary so that all strings have same length as largest
5403 ## trimmed string. This length (in bytes) is returned
5404 sub _trimpad {
5405 1 ▶ my $string_ref = shift;
Subroutine _trimpad: called CC=6 SCAR=18.0
5406 1 my $largest_length = 0;
5407 1 foreach my $string (@{$string_ref}) {
5408 3 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 3 0 3
5409 3 $string =~ s/^\s+//;
5410 3 $string =~ s/\s+$//;
5411 3 ▶ if (length $string > $largest_length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string > $largest_length) 2 1 3
5412 2 $largest_length = length $string;
5413 }
5414 }
5415 }
5416 1 foreach my $string (@{$string_ref}) {
5417 3 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 3 0 3
5418 3 $string .= ' ' x ($largest_length - length $string);
5419 }
5420 }
5421 1 return $largest_length;
5422 }
5423  
5424 ## Use timegm in Time::Local to validate date and time in section 1
5425 sub _validate_datetime {
5426 43 ▶ my $self = shift;
Subroutine _validate_datetime: called CC=11 SCAR=27.6
5427 43 my $bufr_edition = $self->{BUFR_EDITION};
5428 my $year = $bufr_edition < 4 ? $self->{YEAR_OF_CENTURY} + 2000
5429 43 ▶ : $self->{YEAR};
Branch: 1 branch
BranchTrueFalseTotal
$bufr_edition < 4 ? : 34 9 43
5430 43 my $month = $self->{MONTH} - 1;
5431 43 ▶ my $second = $bufr_edition == 4 ? $self->{SECOND} : 0;
Branch: 1 branch
BranchTrueFalseTotal
$bufr_edition == 4 ? : 9 34 43
5432  
5433 # All datetime variables set to 0 should be considered ok
5434 return if ($self->{MINUTE} == 0 && $self->{HOUR} == 0
5435 43 ▶ && $self->{DAY} == 0 && $self->{MONTH} == 0
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0 and $self->{"MONTH"} == 0 and $second == 0 and $year == 0 || $year == 2000 0 43 43
Condition44%8/18
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0 and $self->{"MONTH"} == 0 and $second == 0 and $year == 0 || $year == 2000
!ll&&!rl&&r
4300
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0 and $self->{"MONTH"} == 0 and $second == 0
!ll&&!rl&&r
4300
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0 and $self->{"MONTH"} == 0
!ll&&!rl&&r
4300
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0
!ll&&!rl&&r
3850
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0
!ll&&!rl&&r
25135
$year == 0 or $year == 2000
l!l&&r!l&&!r
000
MC/DC0%0/7
$self->{"MINUTE"} == 0 and $self->{"HOUR"} == 0 and $self->{"DAY"} == 0 and $self->{"MONTH"} == 0 and $second == 0 and $year == 0 || $year == 2000
$self->{"MINUTE"} == 0 $self->{"HOUR"} == 0 $self->{"DAY"} == 0 $self->{"MONTH"} == 0 $second == 0 $year == 0 $year == 2000
Truth table37%3/8
A and B and C and D and E and F or G
A= $self->{"MINUTE"} == 0B= $self->{"HOUR"} == 0C= $self->{"DAY"} == 0D= $self->{"MONTH"} == 0E= $second == 0F= $year == 0G= $year == 2000
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
11111000
111111X1
11111011
5436 && $second == 0 && ($year == 0 || $year == 2000));
5437  
5438 43 eval {
5439 my $dummy = timegm($second,$self->{MINUTE},$self->{HOUR},
5440 43 $self->{DAY},$month,$year);
5441 };
5442  
5443 43 ▶ _complain("Invalid date in section 1: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 43 43
5444 }
5445  
5446 ## Return number of bits necessary to store the nonnegative number $n
5447 ## (1 for 0,1, 2 for 2,3, 3 for 4,5,6,7 etc)
5448 sub _get_number_of_bits_to_store {
5449 112 ▶ my $n = shift;
Subroutine _get_number_of_bits_to_store: called CC=4 SCAR=13.9
5450 112 ▶ return 1 if $n == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 0 112 112
5451 112 my $x = 1;
5452 112 my $i = 0;
5453 112 ▶ while ($x < $n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $n) 654 112 766
5454 654 $i++;
5455 654 $x *= 2;
5456 }
5457 112 ▶ return $x==$n ? $i+1 : $i;
Branch: 1 branch
BranchTrueFalseTotal
$x == $n ? : 26 86 112
5458 }
5459  
5460 ## Find minimum value among set of numbers (undefined values
5461 ## permitted, but at least one value must be defined). Also returns
5462 ## for which number the minimum occurs (counting from 1).
5463 sub _minimum {
5464 112 ▶ my $v_ref = shift;
Subroutine _minimum: called CC=4 SCAR=13.9
5465 112 my $min = 2**63;
5466 112 my $idx = 0;
5467 112 my $i=0;
5468 112 foreach my $v (@{$v_ref}) {
5469 286 $i++;
5470 286 ▶ next if not defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 30 256 286
5471 256 ▶ if ($v < $min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v < $min) 165 91 256
5472 165 $min = $v;
5473 165 $idx = $i;
5474 }
5475 }
5476 112 return ($min, $idx);
5477 }
5478  
5479 ## Find maximum value among set of nonnegative numbers or undefined values
5480 sub _maximum {
5481 112 ▶ my $v_ref = shift;
Subroutine _maximum: called CC=5 SCAR=16.1
5482 112 my $max = 0;
5483 112 foreach my $v (@{$v_ref}) {
5484 286 ▶ next if not defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 30 256 286
5485 256 ▶ if ($v > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > $max) 115 141 256
5486 115 $max = $v;
5487 }
5488 }
5489 112 ▶ _croak "Internal error: Found no maximum value" if $max < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $max < 0 0 112 112
5490 112 return $max;
5491 }
5492  
5493 ## Return index of first occurrence av $value in $list, undef if no match
5494 sub _get_index_in_list {
5495 3 ▶ my ($list, $value) = @_;
Subroutine _get_index_in_list: called CC=3 SCAR=11.0
5496 3 ▶ for (my $i=0; $i <= $#{$list}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$list;}) 5 1 6
5497 5 ▶ if ($list->[$i] eq $value) { # Match
Branch: 1 branch
BranchTrueFalseTotal
if ($list->[$i] eq $value) 2 3 5
5498 2 return $i;
5499 }
5500 }
5501 # No match
5502 1 return undef;
5503 }
5504  
5505 ## Apply the operator descriptor $id, adjusting $pos and
5506 ## @operators. Also returning $bm_idesc (explained in start of module)
5507 ## and a hint of what to do next in $flow
5508 sub _apply_operator_descriptor {
5509 387 ▶ my $self = shift;
Subroutine _apply_operator_descriptor: called CC=125 SCAR=70.0
5510 387 my ($id, $x, $y, $pos, $isub, $next_id, @operators) = @_;
5511 # $isub should be 0 for compressed messages, else subset number
5512  
5513 387 my $flow = '';
5514 387 my $bm_idesc = '';
5515  
5516 387 ▶ if ($y == 0 && $x =~ /^[12378]$/) {
Branch: 31 branches
BranchTrueFalseTotal
if ($y == 0 and $x =~ /^[12378]$/) { } 87 300 387
elsif ($x == 1) { } 52 248 300
elsif ($x == 2) { } 24 224 248
elsif ($x == 3 and $y == 255) { } 6 218 224
elsif ($x == 3) { } 6 212 218
elsif ($x == 4) { } 22 190 212
elsif ($x == 5) { } 0 190 190
elsif ($x == 6) { } 24 166 190
elsif ($x == 7) { } 3 163 166
elsif ($x == 8) { } 2 161 163
elsif ($x == 9) { } 0 161 161
elsif ($x == 21) { } 0 161 161
elsif ($x == 22 and $y == 0) { } 40 121 161
elsif ($x == 23 and $y == 0) { } 3 118 121
elsif ($x == 23 and $y == 255) { } 60 58 118
elsif ($x == 24 and $y == 0) { } 4 54 58
elsif ($x == 24 and $y == 255) { } 4 50 54
elsif ($x == 25 and $y == 0) { } 0 50 50
elsif ($x == 25 and $y == 255) { } 0 50 50
elsif ($x == 32 and $y == 0) { } 2 48 50
elsif ($x == 32 and $y == 255) { } 4 44 48
elsif ($x == 35 and $y == 0) { } 2 42 44
elsif ($x == 36 and $y == 0) { } 18 24 42
elsif ($x == 37 and $y == 0) { } 24 0 24
elsif ($x == 37 and $y == 255) { } 0 0 0
elsif ($x == 41 and $y == 0) { } 0 0 0
elsif ($x == 41 and $y == 255) { } 0 0 0
elsif ($x == 42 and $y == 0) { } 0 0 0
elsif ($x == 42 and $y == 255) { } 0 0 0
elsif ($x == 43 and $y == 0) { } 0 0 0
elsif ($x == 43 and $y == 255) { } 0 0 0
Condition100%3/3
$y == 0 and $x =~ /^[12378]$/
!ll&&!rl&&r
19610487
MC/DC100%2/2
$y == 0 and $x =~ /^[12378]$/
$y == 0 $x =~ /^[12378]$/
Truth table100%3/3
A and B
A= $y == 0B= $x =~ /^[12378]$/
ABresult
0X0
100
111
5517 # 20[12378]000 Cancellation of a data descriptor operator
5518 _complain("$id Cancelling unused operator")
5519 87 ▶ if $Strict_checking and !grep {$_ == $x} @operators;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Strict_checking and not grep({$_ == $x;} @operators) 0 87 87
Condition66%2/3
$Geo::BUFR::Strict_checking and not grep({$_ == $x;} @operators)
!ll&&!rl&&r
38490
MC/DC0%0/2
$Geo::BUFR::Strict_checking and not grep({$_ == $x;} @operators)
$Geo::BUFR::Strict_checking not grep({$_ == $x;} @operators)
Truth table66%2/3
A and not(B)
A= $Geo::BUFR::Strict_checkingB= not grep({$_ == $x;} @operators)
ABresult
0X0
100
111
5520 87 @operators = grep {$_ != $x} @operators;
5521 87 ▶ if ($x == 1) {
Branch: 5 branches
BranchTrueFalseTotal
if ($x == 1) { } 52 35 87
elsif ($x == 2) { } 24 11 35
elsif ($x == 3) { } 6 5 11
elsif ($x == 7) { } 3 2 5
elsif ($x == 8) { } 2 0 2
5522 52 ▶ $self->{NUM_CHANGE_OPERATORS}-- if $self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CHANGE_WIDTH"} 52 0 52
5523 52 undef $self->{CHANGE_WIDTH};
5524 } elsif ($x == 2) {
5525 24 ▶ $self->{NUM_CHANGE_OPERATORS}-- if $self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CHANGE_SCALE"} 24 0 24
5526 24 undef $self->{CHANGE_SCALE};
5527 } elsif ($x == 3) {
5528 6 ▶ $self->{NUM_CHANGE_OPERATORS}-- if $self->{NEW_REFVAL_OF};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"NEW_REFVAL_OF"} 6 0 6
5529 6 undef $self->{NEW_REFVAL_OF};
5530 } elsif ($x == 7) {
5531 3 ▶ $self->{NUM_CHANGE_OPERATORS}-- if $self->{CHANGE_SRW};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CHANGE_SRW"} 3 0 3
5532 3 undef $self->{CHANGE_SRW};
5533 } elsif ($x == 8) {
5534 2 ▶ $self->{NUM_CHANGE_OPERATORS}-- if $self->{CHANGE_CCITTIA5_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CHANGE_CCITTIA5_WIDTH"} 2 0 2
5535 2 undef $self->{CHANGE_CCITTIA5_WIDTH};
5536 }
5537 87 ▶ $self->_spew(4, "$id * Reset %s",
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 87 87
5538 ("width of CCITTIA5 field","data width","scale","reference values",0,0,0,
5539 "increase of scale, reference value and data width")[$x % 8]) if $Spew;
5540 87 $flow = 'next';
5541 } elsif ($x == 1) {
5542 # ^201 Change data width
5543 _croak "201 operator cannot be nested within 207 operator"
5544 52 ▶ if grep {$_ == 7} @operators;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == 7;} @operators 0 52 52
5545 52 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{CHANGE_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGE_WIDTH"} 52 0 52
5546 52 $self->{CHANGE_WIDTH} = $y-128;
5547 52 ▶ $self->_spew(4, "$id * Change data width: %d", $self->{CHANGE_WIDTH}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 52 52
5548 52 push @operators, $x;
5549 52 $flow = 'next';
5550 } elsif ($x == 2) {
5551 # ^202 Change scale
5552 _croak "202 operator cannot be nested within 207 operator"
5553 24 ▶ if grep {$_ == 7} @operators;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == 7;} @operators 0 24 24
5554 24 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{CHANGE_SCALE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGE_SCALE"} 24 0 24
5555 24 $self->{CHANGE_SCALE} = $y-128;
5556 24 ▶ $self->_spew(4, "$id * Change scale: %d", $self->{CHANGE_SCALE}) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 24 24
5557 24 push @operators, $x;
5558 24 $flow = 'next';
5559 ▶ } elsif ($x == 3 && $y == 255) {
Condition100%3/3
$x == 3 and $y == 255
!ll&&!rl&&r
21266
MC/DC100%2/2
$x == 3 and $y == 255
$x == 3 $y == 255
Truth table100%3/3
A and B
A= $x == 3B= $y == 255
ABresult
0X0
100
111
5560 # 203255 Terminate change reference value definition
5561 $self->_spew(4, "$id * Terminate reference value definition %s",
5562 '203' . (defined $self->{CHANGE_REFERENCE_VALUE}
5563 6 ▶ ? sprintf("%03d", $self->{CHANGE_REFERENCE_VALUE}) : '???')) if $Spew;
Branch: 2 branches
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 6 6
defined $self->{'CHANGE_REFERENCE_VALUE'} ? : 0 0 0
5564 _complain("$id no current change reference value to terminate")
5565 6 ▶ unless defined $self->{CHANGE_REFERENCE_VALUE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CHANGE_REFERENCE_VALUE"} 0 6 6
5566 6 undef $self->{CHANGE_REFERENCE_VALUE};
5567 6 $flow = 'next';
5568 } elsif ($x == 3) {
5569 # ^203 Change reference value
5570 _croak "203 operator cannot be nested within 207 operator"
5571 6 ▶ if grep {$_ == 7} @operators;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ == 7;} @operators 0 6 6
5572 6 ▶ $self->_spew(4, "$id * Change reference value") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 6 6
5573 # Get reference value from data stream ($y == number of bits)
5574 6 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{CHANGE_REFERENCE_VALUE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGE_REFERENCE_VALUE"} 6 0 6
5575 6 $self->{CHANGE_REFERENCE_VALUE} = $y;
5576 6 push @operators, $x;
5577 6 $flow = 'next';
5578 } elsif ($x == 4) {
5579 # ^204 Add associated field
5580 22 ▶ if ($y > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y > 0) { } 11 11 22
5581 _croak "$id Nesting of Add associated field is not implemented"
5582 11 ▶ if $self->{ADD_ASSOCIATED_FIELD};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ADD_ASSOCIATED_FIELD"} 0 11 11
5583 11 $self->{ADD_ASSOCIATED_FIELD} = $y;
5584 11 $flow = 'next';
5585 } else {
5586 _complain "$id No previous Add associated field"
5587 11 ▶ unless defined $self->{ADD_ASSOCIATED_FIELD};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ADD_ASSOCIATED_FIELD"} 0 11 11
5588 11 undef $self->{ADD_ASSOCIATED_FIELD};
5589 11 $flow = 'next';
5590 }
5591 } elsif ($x == 5) {
5592 # ^205 Signify character (i.e. the following $y bytes is
5593 # character information)
5594 0 $flow = 'signify_character';
5595 } elsif ($x == 6) {
5596 # ^206 Signify data width for the immediately following local
5597 # descriptor. If we find this local descriptor in BUFR table B
5598 # with data width $y bits, we assume we can use this table
5599 # entry to decode/encode the value properly, and can just
5600 # ignore the operator descriptor. Else we skip the local
5601 # descriptor and the corresponding value if decoding, or have
5602 # to give up if encoding
5603 24 my $ff = substr($next_id,0,1);
5604 24 ▶ _croak("Descriptor $next_id following Signify data width"
Branch: 1 branch
BranchTrueFalseTotal
if $ff != 0 0 24 24
5605 . " operator $_ is not an element descriptor")
5606 if $ff != 0;
5607 24 ▶ if ($Strict_checking) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Geo::BUFR::Strict_checking) 8 16 24
5608 8 my $xx = substr($next_id,1,2);
5609 8 my $yy = substr($next_id,3,3);
5610 8 ▶ _complain("Descriptor $next_id following Signify data width"
Branch: 1 branch
BranchTrueFalseTotal
if $xx < 48 and $yy < 192 0 8 8
Condition33%1/3
$xx < 48 and $yy < 192
!ll&&!rl&&r
080
MC/DC0%0/2
$xx < 48 and $yy < 192
$xx < 48 $yy < 192
Truth table33%1/3
A and B
A= $xx < 48B= $yy < 192
ABresult
0X0
100
111
5611 . " operator $id is not a local descriptor")
5612 if ($xx < 48 && $yy < 192);
5613 }
5614 24 ▶ if (exists $self->{B_TABLE}->{$next_id}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'B_TABLE'}{$next_id} and (split(/\0/, $self->{'B_TABLE'}{$next_id}, 0))[-1] == $y) { } 16 8 24
Condition66%2/3
exists $self->{"B_TABLE"}{$next_id} and (split(/\0/, $self->{"B_TABLE"}{$next_id}, 0))[-1] == $y
!ll&&!rl&&r
8016
MC/DC50%1/2
exists $self->{"B_TABLE"}{$next_id} and (split(/\0/, $self->{"B_TABLE"}{$next_id}, 0))[-1] == $y
exists $self->{"B_TABLE"}{$next_id} (split(/\0/, $self->{"B_TABLE"}{$next_id}, 0))[-1] == $y
Truth table66%2/3
A and B
A= exists $self->{"B_TABLE"}{$next_id}B= (split(/\0/, $self->{"B_TABLE"}{$next_id}, 0))[-1] == $y
ABresult
0X0
100
111
5615 and (split /\0/, $self->{B_TABLE}->{$next_id})[-1] == $y) {
5616 16 ▶ $self->_spew(4, "Found $next_id with data width $y, ignoring $id") if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 16 16
5617 16 $flow = 'next';
5618 } else {
5619 _croak "Cannot encode descriptor $next_id (following $id), not found in table B"
5620 8 ▶ if $self->{CODING} eq 'ENCODE';
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CODING"} eq "ENCODE" 0 8 8
5621 8 ▶ $self->_spew(4, "$_: Did not find $next_id in table B."
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 8 8
5622 . " Skipping $id and $next_id.") if $Spew;
5623 8 $pos += $y; # Skip next $y bits in bitstream if decoding
5624 8 $flow = 'skip';
5625 }
5626  
5627 } elsif ($x == 7) {
5628 # ^207 Increase scale, reference value and data width
5629 _croak "207 operator cannot be nested within 201/202/203 operators"
5630 3 ▶ if grep {$_ == 1 || $_ == 2 || $_ == 3} @operators;
Branch: 2 branches
BranchTrueFalseTotal
if grep {$_ == 1 or $_ == 2 or $_ == 3;} @operators 0 3 3
$_ == 1 or $_ == 2 or $_ == 3 0 0 0
Condition0%0/3
$_ == 1 or $_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ == 1 or $_ == 2
$_ == 1 $_ == 2
Truth table0%0/3
A or B
A= $_ == 1B= $_ == 2
ABresult
1X1
011
000
5631 3 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{CHANGE_SRW};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGE_SRW"} 3 0 3
5632 3 $self->{CHANGE_SRW} = $y;
5633 3 ▶ $self->_spew(4, "$id * Increase scale, reference value and data width: %d", $y) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 3 3
5634 3 push @operators, $x;
5635 3 $flow = 'next';
5636 } elsif ($x == 8) {
5637 # ^208 Change data width for ascii data
5638 2 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{CHANGE_CCITTIA5_WIDTH};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"CHANGE_CCITTIA5_WIDTH"} 2 0 2
5639 2 $self->{CHANGE_CCITTIA5_WIDTH} = $y*8;
5640 2 ▶ $self->_spew(4, "$id * Change width for CCITTIA5 field: %d bytes", $y) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 0 2 2
5641 2 push @operators, $x;
5642 2 $flow = 'next';
5643 } elsif ($x == 9) {
5644 # ^209 IEEE floating point representation
5645 0 _croak "$id IEEE floating point representation (not implemented)";
5646 } elsif ($x == 21) {
5647 # ^221 Data not present
5648 0 _croak "$id Data not present (not implemented)";
5649 ▶ } elsif ($x == 22 && $y == 0) {
Condition66%2/3
$x == 22 and $y == 0
!ll&&!rl&&r
121040
MC/DC50%1/2
$x == 22 and $y == 0
$x == 22 $y == 0
Truth table66%2/3
A and B
A= $x == 22B= $y == 0
ABresult
0X0
100
111
5650 # 222000 Quality information follows
5651 40 push @{ $self->{BITMAP_OPERATORS} }, '222000';
5652 40 $self->{NUM_BITMAPS}++;
5653 # Mark that a bit map probably needs to be built
5654 40 $self->{BUILD_BITMAP} = 1;
5655 40 $self->{BITMAP_INDEX} = 0;
5656 40 ▶ $flow = $Noqc ? 'last' : 'no_value';
Branch: 1 branch
BranchTrueFalseTotal
$Geo::BUFR::Noqc ? : 1 39 40
5657 ▶ } elsif ($x == 23 && $y == 0) {
Condition100%3/3
$x == 23 and $y == 0
!ll&&!rl&&r
58603
MC/DC100%2/2
$x == 23 and $y == 0
$x == 23 $y == 0
Truth table100%3/3
A and B
A= $x == 23B= $y == 0
ABresult
0X0
100
111
5658 # 223000 Substituted values follow, each one following a
5659 # descriptor 223255. Which value they are a substitute for is
5660 # defined by a bit map, which already may have been defined
5661 # (if descriptor 23700 is encountered), or will shortly be
5662 # defined by data present indicators (031031)
5663 3 push @{ $self->{BITMAP_OPERATORS} }, '223000';
5664 3 $self->{NUM_BITMAPS}++;
5665 # Mark that a bit map probably needs to be built
5666 3 $self->{BUILD_BITMAP} = 1;
5667 3 $self->{BITMAP_INDEX} = 0;
5668 3 $flow = 'no_value';
5669 ▶ } elsif ($x == 23 && $y == 255) {
Condition66%2/3
$x == 23 and $y == 255
!ll&&!rl&&r
58060
MC/DC50%1/2
$x == 23 and $y == 255
$x == 23 $y == 255
Truth table66%2/3
A and B
A= $x == 23B= $y == 255
ABresult
0X0
100
111
5670 # 223255 Substituted values marker operator
5671 _croak "$id No bit map defined"
5672 unless (defined $self->{CURRENT_BITMAP} || defined $self->{REUSE_BITMAP})
5673 60 ▶ && $self->{BITMAP_OPERATORS}[-1] eq '223000';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 223000 0 60 60
Condition33%2/6
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 223000
!ll&&!rl&&r
0060
defined $self->{"CURRENT_BITMAP"} or defined $self->{"REUSE_BITMAP"}
l!l&&r!l&&!r
6000
MC/DC0%0/3
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 223000
defined $self->{"CURRENT_BITMAP"} defined $self->{"REUSE_BITMAP"} $self->{"BITMAP_OPERATORS"}[-1] eq 223000
Truth table20%1/5
A or B and C
A= defined $self->{"CURRENT_BITMAP"}B= defined $self->{"REUSE_BITMAP"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 223000
ABCresult
00X0
1X00
0100
1X11
0111
5674 60 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 0 60 60
5675 _croak "More 223255 encountered than current bit map allows"
5676 0 ▶ unless @{ $self->{REUSE_BITMAP}->[$isub] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"REUSE_BITMAP"}[$isub];} 0 0 0
5677 0 $bm_idesc = undef;
5678 } else {
5679 _croak "More 223255 encountered than current bit map allows"
5680 60 ▶ unless @{$self->{CURRENT_BITMAP}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"CURRENT_BITMAP"};} 0 60 60
5681 60 $bm_idesc = shift @{$self->{CURRENT_BITMAP}};
5682 }
5683 60 $flow = 'redo_bitmap';
5684 ▶ } elsif ($x == 24 && $y == 0) {
Condition100%3/3
$x == 24 and $y == 0
!ll&&!rl&&r
5044
MC/DC100%2/2
$x == 24 and $y == 0
$x == 24 $y == 0
Truth table100%3/3
A and B
A= $x == 24B= $y == 0
ABresult
0X0
100
111
5685 # 224000 First order statistical values follow
5686 4 push @{ $self->{BITMAP_OPERATORS} }, '224000';
5687 4 $self->{NUM_BITMAPS}++;
5688 # Mark that a bit map probably needs to be built
5689 4 $self->{BUILD_BITMAP} = 1;
5690 4 $self->{BITMAP_INDEX} = 0;
5691 4 $flow = 'no_value';
5692 ▶ } elsif ($x == 24 && $y == 255) {
Condition66%2/3
$x == 24 and $y == 255
!ll&&!rl&&r
5004
MC/DC50%1/2
$x == 24 and $y == 255
$x == 24 $y == 255
Truth table66%2/3
A and B
A= $x == 24B= $y == 255
ABresult
0X0
100
111
5693 # 224255 First order statistical values marker operator
5694 _croak "$id No bit map defined"
5695 unless (defined $self->{CURRENT_BITMAP} || defined $self->{REUSE_BITMAP})
5696 4 ▶ && $self->{BITMAP_OPERATORS}[-1] eq '224000';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 224000 0 4 4
Condition33%2/6
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 224000
!ll&&!rl&&r
004
defined $self->{"CURRENT_BITMAP"} or defined $self->{"REUSE_BITMAP"}
l!l&&r!l&&!r
400
MC/DC0%0/3
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 224000
defined $self->{"CURRENT_BITMAP"} defined $self->{"REUSE_BITMAP"} $self->{"BITMAP_OPERATORS"}[-1] eq 224000
Truth table20%1/5
A or B and C
A= defined $self->{"CURRENT_BITMAP"}B= defined $self->{"REUSE_BITMAP"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 224000
ABCresult
00X0
1X00
0100
1X11
0111
5697 4 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 0 4 4
5698 _croak "More 224255 encountered than current bit map allows"
5699 0 ▶ unless @{ $self->{REUSE_BITMAP}->[$isub] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"REUSE_BITMAP"}[$isub];} 0 0 0
5700 0 $bm_idesc = undef;
5701 } else {
5702 _croak "More 224255 encountered than current bit map allows"
5703 4 ▶ unless @{$self->{CURRENT_BITMAP}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"CURRENT_BITMAP"};} 0 4 4
5704 4 $bm_idesc = shift @{$self->{CURRENT_BITMAP}};
5705 }
5706 4 $flow = 'redo_bitmap';
5707 ▶ } elsif ($x == 25 && $y == 0) {
Condition33%1/3
$x == 25 and $y == 0
!ll&&!rl&&r
5000
MC/DC0%0/2
$x == 25 and $y == 0
$x == 25 $y == 0
Truth table33%1/3
A and B
A= $x == 25B= $y == 0
ABresult
0X0
100
111
5708 # 225000 Difference statistical values follow
5709 0 push @{ $self->{BITMAP_OPERATORS} }, '225000';
5710 0 $self->{NUM_BITMAPS}++;
5711 # Mark that a bit map probably needs to be built
5712 0 $self->{BUILD_BITMAP} = 1;
5713 0 $self->{BITMAP_INDEX} = 0;
5714 0 $flow = 'no_value';
5715 ▶ } elsif ($x == 25 && $y == 255) {
Condition33%1/3
$x == 25 and $y == 255
!ll&&!rl&&r
5000
MC/DC0%0/2
$x == 25 and $y == 255
$x == 25 $y == 255
Truth table33%1/3
A and B
A= $x == 25B= $y == 255
ABresult
0X0
100
111
5716 # 225255 Difference statistical values marker operator
5717 _croak "$id No bit map defined\n"
5718 unless (defined $self->{CURRENT_BITMAP} || defined $self->{REUSE_BITMAP})
5719 0 ▶ && $self->{BITMAP_OPERATORS}[-1] eq '225000';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 225000 0 0 0
Condition0%0/6
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 225000
!ll&&!rl&&r
000
defined $self->{"CURRENT_BITMAP"} or defined $self->{"REUSE_BITMAP"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 225000
defined $self->{"CURRENT_BITMAP"} defined $self->{"REUSE_BITMAP"} $self->{"BITMAP_OPERATORS"}[-1] eq 225000
Truth table0%0/5
A or B and C
A= defined $self->{"CURRENT_BITMAP"}B= defined $self->{"REUSE_BITMAP"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 225000
ABCresult
00X0
1X00
0100
1X11
0111
5720 0 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 0 0 0
5721 _croak "More 225255 encountered than current bit map allows"
5722 0 ▶ unless @{ $self->{REUSE_BITMAP}->[$isub] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"REUSE_BITMAP"}[$isub];} 0 0 0
5723 0 $bm_idesc = undef;
5724 } else {
5725 _croak "More 225255 encountered than current bit map allows"
5726 0 ▶ unless @{$self->{CURRENT_BITMAP}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"CURRENT_BITMAP"};} 0 0 0
5727 0 $bm_idesc = shift @{$self->{CURRENT_BITMAP}};
5728 }
5729 # Must remember to change data width and reference value
5730 0 ▶ $self->{NUM_CHANGE_OPERATORS}++ if !$self->{DIFFERENCE_STATISTICAL_VALUE};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"DIFFERENCE_STATISTICAL_VALUE"} 0 0 0
5731 0 $self->{DIFFERENCE_STATISTICAL_VALUE} = 1;
5732 0 $flow = 'redo_bitmap';
5733 ▶ } elsif ($x == 32 && $y == 0) {
Condition100%3/3
$x == 32 and $y == 0
!ll&&!rl&&r
4442
MC/DC100%2/2
$x == 32 and $y == 0
$x == 32 $y == 0
Truth table100%3/3
A and B
A= $x == 32B= $y == 0
ABresult
0X0
100
111
5734 # 232000 Replaced/retained values follow, each one following a
5735 # descriptor 232255. Which value they are a replacement for is
5736 # defined by a bit map, which already may have been defined
5737 # (if descriptor 23700 is encountered), or will shortly be
5738 # defined by data present indicators (031031)
5739 2 push @{ $self->{BITMAP_OPERATORS} }, '232000';
5740 2 $self->{NUM_BITMAPS}++;
5741 # Mark that a bit map probably needs to be built
5742 2 $self->{BUILD_BITMAP} = 1;
5743 2 $self->{BITMAP_INDEX} = 0;
5744 2 $flow = 'no_value';
5745 ▶ } elsif ($x == 32 && $y == 255) {
Condition66%2/3
$x == 32 and $y == 255
!ll&&!rl&&r
4404
MC/DC50%1/2
$x == 32 and $y == 255
$x == 32 $y == 255
Truth table66%2/3
A and B
A= $x == 32B= $y == 255
ABresult
0X0
100
111
5746 # 232255 Replaced/retained values marker operator
5747 _croak "$id No bit map defined"
5748 unless (defined $self->{CURRENT_BITMAP} || defined $self->{REUSE_BITMAP})
5749 4 ▶ && $self->{BITMAP_OPERATORS}[-1] eq '232000';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 232000 0 4 4
Condition33%2/6
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 232000
!ll&&!rl&&r
004
defined $self->{"CURRENT_BITMAP"} or defined $self->{"REUSE_BITMAP"}
l!l&&r!l&&!r
400
MC/DC0%0/3
defined $self->{"CURRENT_BITMAP"} || defined $self->{"REUSE_BITMAP"} and $self->{"BITMAP_OPERATORS"}[-1] eq 232000
defined $self->{"CURRENT_BITMAP"} defined $self->{"REUSE_BITMAP"} $self->{"BITMAP_OPERATORS"}[-1] eq 232000
Truth table20%1/5
A or B and C
A= defined $self->{"CURRENT_BITMAP"}B= defined $self->{"REUSE_BITMAP"}C= $self->{"BITMAP_OPERATORS"}[-1] eq 232000
ABCresult
00X0
1X00
0100
1X11
0111
5750 4 ▶ if (defined $self->{REUSE_BITMAP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'REUSE_BITMAP'}) { } 0 4 4
5751 _croak "More 232255 encountered than current bit map allows"
5752 0 ▶ unless @{ $self->{REUSE_BITMAP}->[$isub] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"REUSE_BITMAP"}[$isub];} 0 0 0
5753 0 $bm_idesc = undef;
5754 } else {
5755 _croak "More 232255 encountered than current bit map allows"
5756 4 ▶ unless @{$self->{CURRENT_BITMAP}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"CURRENT_BITMAP"};} 0 4 4
5757 4 $bm_idesc = shift @{$self->{CURRENT_BITMAP}};
5758 }
5759 4 $flow = 'redo_bitmap';
5760 ▶ } elsif ($x == 35 && $y == 0) {
Condition66%2/3
$x == 35 and $y == 0
!ll&&!rl&&r
4202
MC/DC50%1/2
$x == 35 and $y == 0
$x == 35 $y == 0
Truth table66%2/3
A and B
A= $x == 35B= $y == 0
ABresult
0X0
100
111
5761 # 235000 Cancel backward data reference
5762 2 undef $self->{REUSE_BITMAP};
5763 2 $self->{BACKWARD_DATA_REFERENCE} = $self->{NUM_BITMAPS} + 1;
5764 2 $flow = 'no_value';
5765 ▶ } elsif ($x == 36 && $y == 0) {
Condition66%2/3
$x == 36 and $y == 0
!ll&&!rl&&r
24018
MC/DC50%1/2
$x == 36 and $y == 0
$x == 36 $y == 0
Truth table66%2/3
A and B
A= $x == 36B= $y == 0
ABresult
0X0
100
111
5766 # 236000 Define data present bit map
5767 18 undef $self->{CURRENT_BITMAP};
5768 18 $self->{BUILD_BITMAP} = 1;
5769 18 $self->{BITMAP_INDEX} = 0;
5770 18 $flow = 'no_value';
5771 ▶ } elsif ($x == 37 && $y == 0) {
Condition33%1/3
$x == 37 and $y == 0
!ll&&!rl&&r
0024
MC/DC0%0/2
$x == 37 and $y == 0
$x == 37 $y == 0
Truth table33%1/3
A and B
A= $x == 37B= $y == 0
ABresult
0X0
100
111
5772 # 237000 Use defined data present bit map
5773 _croak "$id No previous bit map defined"
5774 24 ▶ unless defined $self->{BITMAPS};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"BITMAPS"} 0 24 24
5775 24 my %hash = @{ $self->{BITMAPS}->[$self->{NUM_BITMAPS}-1]->[$isub] };
5776 24 $self->{REUSE_BITMAP}->[$isub] = [sort {$a <=> $b} keys %hash];
5777 24 $flow = 'no_value';
5778 ▶ } elsif ($x == 37 && $y == 255) {
Condition0%0/3
$x == 37 and $y == 255
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 37 and $y == 255
$x == 37 $y == 255
Truth table0%0/3
A and B
A= $x == 37B= $y == 255
ABresult
0X0
100
111
5779 # 237255 Cancel 'use defined data present bit map'
5780 _complain("$id No data present bit map to cancel")
5781 0 ▶ unless defined $self->{REUSE_BITMAP};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"REUSE_BITMAP"} 0 0 0
5782 0 undef $self->{REUSE_BITMAP};
5783 0 $flow = 'next';
5784 ▶ } elsif ($x == 41 && $y == 0) {
Condition0%0/3
$x == 41 and $y == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 41 and $y == 0
$x == 41 $y == 0
Truth table0%0/3
A and B
A= $x == 41B= $y == 0
ABresult
0X0
100
111
5785 # 241000 Define event
5786 0 _croak "$id Define event (not implemented)";
5787 ▶ } elsif ($x == 41 && $y == 255) {
Condition0%0/3
$x == 41 and $y == 255
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 41 and $y == 255
$x == 41 $y == 255
Truth table0%0/3
A and B
A= $x == 41B= $y == 255
ABresult
0X0
100
111
5788 # 241255 Cancel define event
5789 0 _croak "$id Cancel define event (not implemented)";
5790 ▶ } elsif ($x == 42 && $y == 0) {
Condition0%0/3
$x == 42 and $y == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 42 and $y == 0
$x == 42 $y == 0
Truth table0%0/3
A and B
A= $x == 42B= $y == 0
ABresult
0X0
100
111
5791 # 242000 Define conditioning event
5792 0 _croak "$id Define conditioning event (not implemented)";
5793 ▶ } elsif ($x == 42 && $y == 255) {
Condition0%0/3
$x == 42 and $y == 255
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 42 and $y == 255
$x == 42 $y == 255
Truth table0%0/3
A and B
A= $x == 42B= $y == 255
ABresult
0X0
100
111
5794 # 242255 Cancel define conditioning event
5795 0 _croak "$id Cancel define conditioning event (not implemented)";
5796 ▶ } elsif ($x == 43 && $y == 0) {
Condition0%0/3
$x == 43 and $y == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 43 and $y == 0
$x == 43 $y == 0
Truth table0%0/3
A and B
A= $x == 43B= $y == 0
ABresult
0X0
100
111
5797 # 243000 Categorial forecast values follow
5798 0 _croak "$id Categorial forecast values follow (not implemented)";
5799 ▶ } elsif ($x == 43 && $y == 255) {
Condition0%0/3
$x == 43 and $y == 255
!ll&&!rl&&r
000
MC/DC0%0/2
$x == 43 and $y == 255
$x == 43 $y == 255
Truth table0%0/3
A and B
A= $x == 43B= $y == 255
ABresult
0X0
100
111
5800 # 243255 Cancel categorial forecast values follow
5801 0 _croak "$id Cancel categorial forecast values follow (not implemented)";
5802 } else {
5803 0 _croak "$id Unknown data description operator";
5804 }
5805  
5806 387 return ($pos, $flow, $bm_idesc, @operators);
5807 }
5808  
5809 ## Extract data from selected subsets in selected bufr objects, joined
5810 ## into a single ($data_refs, $desc_refs), to later be able to make a
5811 ## single BUFR message by calling encode_message. Also returns number
5812 ## of subsets extracted.
5813 sub join_subsets {
5814 1 ▶ my $self = shift;
Subroutine join_subsets: called CC=15 SCAR=27.4
Pod undocumented
5815 1 my (@bufr, @subset_list);
5816 1 my $last_arg_was_bufr;
5817 1 my $num_objects = 0;
5818 1 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 1 4
5819 3 my $arg = shift;
5820 3 ▶ if (ref($arg) eq 'Geo::BUFR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg eq 'Geo::BUFR') { } 2 1 3
elsif (ref $arg eq 'ARRAY') { } 1 0 1
5821 2 $bufr[$num_objects++] = $arg;
5822 2 $last_arg_was_bufr = 1;
5823 } elsif (ref($arg) eq 'ARRAY') {
5824 1 ▶ _croak "Wrong input (multiple array refs) to join_subsets"
Branch: 1 branch
BranchTrueFalseTotal
unless $last_arg_was_bufr 0 1 1
5825 unless $last_arg_was_bufr;
5826 1 $subset_list[$num_objects-1] = $arg;
5827 1 $last_arg_was_bufr = 0;
5828 } else {
5829 0 _croak "Input is not Geo::BUFR object or array ref in join_subsets";
5830 }
5831 }
5832  
5833 1 my ($data_refs, $desc_refs);
5834 1 my $n = 1; # Number of subsets included
5835 # Ought to check for common section 3 also?
5836 1 ▶ for (my $i=0; $i < $num_objects; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_objects) 2 1 3
5837 2 $bufr[$i]->rewind();
5838 2 my $isub = 1;
5839 2 ▶ if (!exists $subset_list[$i]) { # grab all subsets from this object
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $subset_list[$i]) { } 1 1 2
5840 1 ▶ while (not $bufr[$i]->eof()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bufr[$i]->eof) 2 0 2
5841 2 my ($data, $descriptors) = $bufr[$i]->next_observation();
5842 2 ▶ last if !$data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 1 1 2
5843 1 ▶ $self->_spew(2, "Joining subset %d from bufr object %d", $isub, $i) if $Spew;
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 1 0 1
5844 1 $data_refs->[$n] = $data;
5845 1 $desc_refs->[$n++] = $descriptors;
5846 1 $isub++;
5847 }
5848 } else { # grab the subsets specified, also inserting them in the specified order
5849 1 my $num_found = 0;
5850 1 ▶ while (not $bufr[$i]->eof()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bufr[$i]->eof) 4 0 4
5851 4 my ($data, $descriptors) = $bufr[$i]->next_observation();
5852 4 ▶ last if !$data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 1 3 4
5853 3 my $index = _get_index_in_list($subset_list[$i], $isub);
5854 3 ▶ if (defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) 2 1 3
5855 2 ▶ $self->_spew(2, "Joining subset %d from subset %d"
Branch: 1 branch
BranchTrueFalseTotal
if $Geo::BUFR::Spew 2 0 2
5856 . " in bufr object %d", $isub, $index, $i) if $Spew;
5857 2 $data_refs->[$n + $index] = $data;
5858 2 $desc_refs->[$n + $index] = $descriptors;
5859 2 $num_found++;
5860 }
5861 3 $isub++;
5862 }
5863 _croak "Mismatch between number of subsets found ($num_found) and "
5864 0 . "expected from argument [@{$subset_list[$i]}] to join_subsets"
5865 1 ▶ if $num_found != @{$subset_list[$i]};
Branch: 1 branch
BranchTrueFalseTotal
if $num_found != @{$subset_list[$i];} 0 1 1
5866 1 $n += $num_found;
5867 }
5868 2 $bufr[$i]->rewind();
5869 }
5870 1 $n--;
5871 1 return ($data_refs, $desc_refs, $n)
5872 }
5873  
5874 79 1; # Make sure require or use succeeds.
5875  
5876  
5877 __END__
« blib/script/bufralter.pl ↑ Summary blib/lib/Geo/bufrextract.pl »