bufr.pm:bufrread.pl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bufr.pm:bufrread.pl [2019-02-16 07:09:56]
pals
bufr.pm:bufrread.pl [2025-11-05 09:22:06] (current)
pals
Line 1: Line 1:
-<code>+<code perl>
 #!/usr/bin/perl #!/usr/bin/perl
  
-# (C) Copyright 2010-2019 MET Norway+# (C) Copyright 2010-2025 MET Norway
 # #
 # This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
Line 34: Line 34:
 use constant DEFAULT_TABLE_PATH_BUFRDC => '/usr/local/lib/bufrtables'; use constant DEFAULT_TABLE_PATH_BUFRDC => '/usr/local/lib/bufrtables';
 use constant DEFAULT_TABLE_PATH_ECCODES => '/usr/local/share/eccodes/definitions/bufr/tables'; use constant DEFAULT_TABLE_PATH_ECCODES => '/usr/local/share/eccodes/definitions/bufr/tables';
-# Ought to be your most up-to-date code table(s) 
-use constant DEFAULT_CTABLE_BUFRDC => 'C0000000000000029000'; 
-use constant DEFAULT_CTABLE_ECCODES => '0/wmo/29'; 
  
 # Parse command line options # Parse command line options
Line 43: Line 40:
            \%option,            \%option,
            'ahl=s',        # Decode BUFR messages with AHL matching <ahl_regexp> only            'ahl=s',        # Decode BUFR messages with AHL matching <ahl_regexp> only
-           'all_operators',# Show all operator descriptors when printing section 4+           'all_operators',# Show replication descriptors and all operator descriptors 
 +                           # when printing section 4
            'bitmap',       # Display bit-mapped values on same line            'bitmap',       # Display bit-mapped values on same line
            'codetables',   # Use code and flag tables to resolve values            'codetables',   # Use code and flag tables to resolve values
Line 105: Line 103:
     eval { $ahl_regexp = qr/$option{ahl}/ };     eval { $ahl_regexp = qr/$option{ahl}/ };
     die "Argument to --ahl is not a valid Perl regular expression: $@" if $@;     die "Argument to --ahl is not a valid Perl regular expression: $@" if $@;
-    # When filtering on ahl we assume file is composed of GTS bulletins only 
-    Geo::BUFR->reuse_current_ahl(); 
 } }
  
Line 124: Line 120:
  
 # Arrays over filter criteria, used if option --filter is set # Arrays over filter criteria, used if option --filter is set
-my @fid;      # Filter descriptors, .e.g. $fid[1] = [ 001001, 001002 ]+my @fid;      # Filter descriptors, e.g. $fid[1] = [ 001001, 001002 ]
 my @fiv;      # Filter values, e.g. $fiv[1] = [ [ 3, 895 ], [ 6 252 ] ] my @fiv;      # Filter values, e.g. $fiv[1] = [ [ 3, 895 ], [ 6 252 ] ]
 my @num_desc; # Number of filter descriptors for each criterion, e.g. $num_desc[1] = 2 my @num_desc; # Number of filter descriptors for each criterion, e.g. $num_desc[1] = 2
Line 199: Line 195:
             # Load C table, trying first to use same table version as             # Load C table, trying first to use same table version as
             # the B and D tables loaded in next_observation, or if             # the B and D tables loaded in next_observation, or if
-            # this C table file does not exist, loads DEFAULT_CTABLE +            # this C table file does not exist, loads C table for latest 
-            # instead.+            # master table in table path found instead.
             my $table_version = $bufr->get_table_version();             my $table_version = $bufr->get_table_version();
             my $tableformat = Geo::BUFR->get_tableformat();             my $tableformat = Geo::BUFR->get_tableformat();
             if ($tableformat eq 'BUFRDC') {             if ($tableformat eq 'BUFRDC') {
-                $bufr->load_Ctable("C$table_version", DEFAULT_CTABLE_BUFRDC);+                $bufr->load_Ctable("C$table_version");
             } elsif ($tableformat eq 'ECCODES' {             } elsif ($tableformat eq 'ECCODES' {
-                $bufr->load_Ctable("$table_version", DEFAULT_CTABLE_ECCODES);+                $bufr->load_Ctable("$table_version");
             }             }
         }         }
Line 332: Line 328:
 # Read in contents of $filter_file into variables @fid, @fiv, # Read in contents of $filter_file into variables @fid, @fiv,
 # @num_desc, @num_val and $num_criteria, which are defined above. # @num_desc, @num_val and $num_criteria, which are defined above.
 +# Note that index 0 of the arrays is not used.
 sub read_filter_file { sub read_filter_file {
     my $filter_file = shift;     my $filter_file = shift;
Line 357: Line 354:
         } else {         } else {
             my @values = split;             my @values = split;
 +            # Check that value line contains correct number of values
 +            die "Number of values doesn't match number of descriptors"
 +                . " for line $. in filter file '$filter_file'"
 +                if scalar @values != scalar @{$fid[$num_criteria]};
             # Remove leading 0's in numerical values (to prepare for string comparison)             # Remove leading 0's in numerical values (to prepare for string comparison)
             for $_ (@values) { s/^0+(\d+)$/$1/ };             for $_ (@values) { s/^0+(\d+)$/$1/ };
Line 375: Line 376:
     my ($data, $descriptors) = @_;     my ($data, $descriptors) = @_;
  
-    my $num_ordinary_criteria = @fid - $num_required_criteria;+    my $num_ordinary_criteria = $#fid - $num_required_criteria;
     my $num_success_req_criteria = 0; # Number of required criteria successfully fulfilled     my $num_success_req_criteria = 0; # Number of required criteria successfully fulfilled
     my $num_success_ord_criteria = 0; # Number of ordinary criteria successfully fulfilled     my $num_success_ord_criteria = 0; # Number of ordinary criteria successfully fulfilled
Line 433: Line 434:
                                                  or $num_success_ord_criteria > 0)) {                                                  or $num_success_ord_criteria > 0)) {
                                             return 0; # Don't filter this observation                                             return 0; # Don't filter this observation
 +                                        } else {
 +                                            next DESC;
                                         }                                         }
                                     } else {                                     } else {
Line 500: Line 503:
    --ahl <ahl_regexp>    --ahl <ahl_regexp>
                    Decode BUFR messages with AHL matching <ahl_regexp> only                    Decode BUFR messages with AHL matching <ahl_regexp> only
-   --all_operators Show all operator descriptors when printing section 4+   --all_operators Show replication descriptors and all operator descriptors 
 +                   when printing section 4
    --bitmap        Display bit-mapped values on same line    --bitmap        Display bit-mapped values on same line
    --codetables    Use code and flag tables to resolve values when unit    --codetables    Use code and flag tables to resolve values when unit
Line 552: Line 556:
  
 Using C<--filter> will decode only those observations that meet one of Using C<--filter> will decode only those observations that meet one of
-the criteria in <filter file> (and all of those criteria marked +the criteria in <filter file> marked D: and all of those criteria 
-D!). Comments (starting with #) are ignored. An example of a filter +marked D!:. Comments (starting with #) are ignored. An example of a 
-file is+filter file is
  
   D: 001001   D: 001001
Line 598: Line 602:
 =head1 COPYRIGHT =head1 COPYRIGHT
  
-Copyright (C) 2010-2019 MET Norway+Copyright (C) 2010-2025 MET Norway
  
 =cut =cut
 </code> </code>
  • bufr.pm/bufrread.pl.1550300996.txt.gz
  • Last modified: 2022-05-31 09:23:11
  • (external edit)