Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
bufr.pm:bufrread.pl [2016-04-18 07:50:40] pals |
bufr.pm:bufrread.pl [2025-11-05 09:22:06] (current) pals |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| <code perl> | <code perl> | ||
| - | # | + | # |
| - | # (C) Copyright 2010-2016 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 22: | Line 22: | ||
| use strict; | use strict; | ||
| + | use warnings; | ||
| use Getopt:: | use Getopt:: | ||
| use Pod::Usage qw(pod2usage); | use Pod::Usage qw(pod2usage); | ||
| use Geo::BUFR; | use Geo::BUFR; | ||
| + | |||
| + | # This is actually default in BUFR.pm, but provided here to make it | ||
| + | # easier for users to change to ' | ||
| + | use constant DEFAULT_TABLE_FORMAT => ' | ||
| # Will be used if neither --tablepath nor $ENV{BUFR_TABLES} is set | # Will be used if neither --tablepath nor $ENV{BUFR_TABLES} is set | ||
| - | use constant | + | use constant |
| - | # Ought to be your most up-to-date C table | + | use constant |
| - | use constant | + | |
| # Parse command line options | # Parse command line options | ||
| Line 36: | Line 40: | ||
| | | ||
| ' | ' | ||
| - | ' | + | ' |
| + | # | ||
| ' | ' | ||
| ' | ' | ||
| Line 49: | Line 54: | ||
| ' | ' | ||
| ' | ' | ||
| + | ' | ||
| ' | ' | ||
| ' | ' | ||
| Line 72: | Line 78: | ||
| Geo:: | Geo:: | ||
| + | |||
| + | # Set BUFR table format | ||
| + | my $tableformat = (defined $option{tableformat}) ? uc $option{tableformat} : DEFAULT_TABLE_FORMAT; | ||
| + | Geo:: | ||
| # Set BUFR table path | # Set BUFR table path | ||
| Line 81: | Line 91: | ||
| Geo:: | Geo:: | ||
| } else { | } else { | ||
| - | # If all else fails, use the libbufr bufrtables | + | # If all else fails, use the default tablepath in BUFRDC/ |
| - | Geo:: | + | |
| + | | ||
| + | } elsif ($tableformat eq ' | ||
| + | Geo:: | ||
| + | } | ||
| } | } | ||
| Line 89: | Line 103: | ||
| eval { $ahl_regexp = qr/ | eval { $ahl_regexp = qr/ | ||
| die " | die " | ||
| - | # When filtering on ahl we assume file is composed of GTS bulletins only | ||
| - | Geo:: | ||
| } | } | ||
| Line 108: | 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, | + | my @fid; # Filter descriptors, |
| 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 162: | Line 174: | ||
| if ($@) { | if ($@) { | ||
| $current_ahl = $bufr-> | $current_ahl = $bufr-> | ||
| - | next READLOOP if $option{ahl} && $current_ahl !~ $ahl_regexp; | + | next READLOOP if $option{ahl} && $current_ahl !~ $ahl_regexp; |
| warn $@; | warn $@; | ||
| Line 183: | 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, | # the B and D tables loaded in next_observation, | ||
| - | # 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-> | my $table_version = $bufr-> | ||
| - | $bufr-> | + | |
| + | if ($tableformat eq ' | ||
| + | | ||
| + | } elsif ($tableformat eq ' | ||
| + | $bufr-> | ||
| + | } | ||
| } | } | ||
| Line 311: | 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, | # @num_desc, @num_val and $num_criteria, | ||
| + | # 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 336: | Line 354: | ||
| } else { | } else { | ||
| my @values = split; | my @values = split; | ||
| + | # Check that value line contains correct number of values | ||
| + | die " | ||
| + | . " for line $. in 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/ | for $_ (@values) { s/ | ||
| Line 354: | 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 412: | 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 460: | Line 484: | ||
| [--param < | [--param < | ||
| [--strict_checking n] | [--strict_checking n] | ||
| + | [--tableformat < | ||
| [--tablepath <path to BUFR tables>] | [--tablepath <path to BUFR tables>] | ||
| [--verbose n] | [--verbose n] | ||
| Line 478: | Line 503: | ||
| --ahl < | --ahl < | ||
| | | ||
| - | | + | |
| + | when printing section 4 | ||
| | | ||
| | | ||
| Line 502: | Line 528: | ||
| n=2 Croak if (recoverable) error in BUFR format. | n=2 Croak if (recoverable) error in BUFR format. | ||
| | | ||
| + | | ||
| | | ||
| Set path to BUFR tables (overrides ENV{BUFR_TABLES}) | Set path to BUFR tables (overrides ENV{BUFR_TABLES}) | ||
| Line 514: | Line 541: | ||
| set the environment variable BUFR_TABLES to the directory where your | set the environment variable BUFR_TABLES to the directory where your | ||
| BUFR tables are located (unless the default path provided by | BUFR tables are located (unless the default path provided by | ||
| - | bufrread.pl works for you). | + | bufrread.pl works for you). For tableformat ECCODES, se |
| + | L< | ||
| + | for more info on how to set C< | ||
| For option C< | For option C< | ||
| - | expression. E.g. C< | + | expression. E.g. C< |
| (ISS) from CCCC=ENMI. This is the only case where a little knowledge | (ISS) from CCCC=ENMI. This is the only case where a little knowledge | ||
| - | of Perl might be required | + | of Perl might possibly |
| - | Geo::BUFR. | + | included in Geo::BUFR. |
| For option C< | For option C< | ||
| Line 527: | Line 556: | ||
| Using C< | Using C< | ||
| - | the criteria in <filter file> | + | the criteria in <filter file> |
| - | D!). Comments (starting with #) are ignored. An example of a filter | + | marked |
| - | file is | + | filter |
| D: 001001 | D: 001001 | ||
| Line 573: | Line 602: | ||
| =head1 COPYRIGHT | =head1 COPYRIGHT | ||
| - | Copyright (C) 2010-2016 MET Norway | + | Copyright (C) 2010-2025 MET Norway |
| =cut | =cut | ||
| </ | </ | ||