Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
bufr.pm:bufrresolve_source [2010-03-10 09:17:55] pals |
bufr.pm:bufrresolve_source [2023-02-05 10:15:44] (current) pals |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | + | < |
- | # | + | # |
- | # (C) Copyright 2010, met.no | + | # (C) Copyright 2010-2023 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 19: | Line 19: | ||
# 02110-1301, USA. | # 02110-1301, USA. | ||
- | # Usage 1: $0 < | + | # pod included at end of file |
- | + | ||
- | # Resolve the given descriptor(s) fully into table B descriptors, | + | |
- | # name, unit, scale, reference value and width written on each line. | + | |
- | # With option --noexpand no expansion | + | |
- | # is done. With option --partial table D descriptors are expanded only | + | |
- | # once and replication ignored. Option --simple is like --partial, but | + | |
- | # all descriptors are listed on one line without any info. | + | |
- | + | ||
- | # The tables used can be chosen by the user with options --bufrtable | + | |
- | # and --tablepath. Default is DEFAULT_TABLE in directory | + | |
- | # DEFAULT_TABLE_PATH or in directory $ENV{BUFR_TABLES} if this is set. | + | |
- | + | ||
- | # Usage 2: $0 --code < | + | |
- | + | ||
- | # Print the content of code or flag table < | + | |
- | + | ||
- | # Usage 3: $0 --flag < | + | |
- | + | ||
- | # Display the bits set for flag value < | + | |
- | + | ||
- | # It is supposed the code and flag tables are contained in a file with | + | |
- | # same name as corresponding B and D tables except for having prefix C | + | |
- | # instead of B or D. | + | |
- | + | ||
- | # Author: P.Sannes met.no 2010 | + | |
use strict; | use strict; | ||
+ | use warnings; | ||
use Getopt:: | use Getopt:: | ||
- | use BUFR; | + | use Pod::Usage qw(pod2usage); |
+ | 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 |
+ | use constant DEFAULT_TABLE_PATH_ECCODES => '/ | ||
# Ought to be your most up-to-date B table | # Ought to be your most up-to-date B table | ||
- | use constant | + | use constant |
+ | use constant DEFAULT_TABLE_ECCODES => ' | ||
# Parse command line options | # Parse command line options | ||
Line 60: | Line 43: | ||
GetOptions( | GetOptions( | ||
| | ||
- | ' | + | ' |
- | ' | + | ' |
' | ' | ||
' | ' | ||
Line 69: | Line 52: | ||
' | ' | ||
# descriptors on one line | # descriptors on one line | ||
- | ' | + | ' |
- | ' | + | ' |
- | ) or die "Wrong option(s), execute $0 without arguments for Usage\n" | + | ' |
+ | ) or pod2usage(-verbose => 0); | ||
# User asked for help | # User asked for help | ||
- | usage() if $option{help}; | + | pod2usage(-verbose => 1) if $option{help}; |
# No arguments if --code or --flag, else there should be at least one argument | # No arguments if --code or --flag, else there should be at least one argument | ||
if (defined $option{code} or defined $option{flag}) { | if (defined $option{code} or defined $option{flag}) { | ||
- | | + | |
} else { | } else { | ||
- | | + | |
} | } | ||
# If --flag is set, user must also provide code table | # If --flag is set, user must also provide code table | ||
- | usage() if defined $option{flag} and !defined $option{code}; | + | pod2usage(-verbose => 0) if defined $option{flag} and !defined $option{code}; |
+ | |||
+ | # All arguments must be integers | ||
+ | foreach (@ARGV) { | ||
+ | pod2usage(" | ||
+ | } | ||
+ | if (defined $option{code} && $option{code} !~ /^\d+$/) { | ||
+ | pod2usage(" | ||
+ | } | ||
+ | if (defined $option{flag} && $option{flag} !~ /^\d+$/) { | ||
+ | pod2usage(" | ||
+ | } | ||
# Set verbosity level for the BUFR module | # Set verbosity level for the BUFR module | ||
my $verbose = $option{verbose} ? 1 : 0; | my $verbose = $option{verbose} ? 1 : 0; | ||
- | BUFR-> | + | Geo::BUFR-> |
+ | |||
+ | # From version 1.32 a descriptor sequence ending in e.g. 106000 031001 | ||
+ | # will be allowed unless strict checking is set, and we really want | ||
+ | # bufrresolve.pl to complain in this case | ||
+ | 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 | ||
if ($option{tablepath}) { | if ($option{tablepath}) { | ||
# Command line option --tablepath overrides all | # Command line option --tablepath overrides all | ||
- | BUFR-> | + | |
} elsif ($ENV{BUFR_TABLES}) { | } elsif ($ENV{BUFR_TABLES}) { | ||
# If no --tablepath option, use the BUFR_TABLES environment variable | # If no --tablepath option, use the BUFR_TABLES environment variable | ||
- | BUFR-> | + | |
} else { | } else { | ||
- | # If all else fails, use the libemos bufrtables | + | # If all else fails, use the default tablepath in BUFRDC/ |
- | BUFR-> | + | |
+ | Geo::BUFR-> | ||
+ | } elsif ($tableformat eq ' | ||
+ | Geo:: | ||
+ | } | ||
} | } | ||
- | print 'BUFR tablepath: ', BUFR-> | ||
# BUFR table file to use | # BUFR table file to use | ||
- | my $table = $option{bufrtable} || DEFAULT_TABLE; | + | my $table = $option{bufrtable} || |
+ | ($tableformat eq ' | ||
- | my $bufr = BUFR-> | + | my $bufr = Geo::BUFR-> |
if (defined $option{code}) { | if (defined $option{code}) { | ||
Line 112: | Line 122: | ||
my $code_table = $option{code}; | my $code_table = $option{code}; | ||
if (defined $option{flag}) { | if (defined $option{flag}) { | ||
- | print $bufr-> | + | |
+ | print "No bits are set\n"; | ||
+ | } else { | ||
+ | | ||
+ | } | ||
} else { | } else { | ||
print $bufr-> | print $bufr-> | ||
Line 130: | Line 144: | ||
} | } | ||
+ | =pod | ||
- | sub usage { | + | =encoding utf8 |
- | print <<" | + | |
- | Usage 1: $0 < | + | =head1 SYNOPSIS |
- | | + | |
+ | [--partial] | ||
+ | [--simple] | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | [--help] | ||
- | [--partial] | + | 2) bufrresolve.pl |
- | | + | |
- | [--simple] | + | [--tableformat < |
- | | + | [--tablepath <path to BUFR tables> |
- | [--noexpand] | + | |
- | [--bufrtable <name of BUFR B or D table] | + | |
- | [--tablepath <path to BUFR tables> | + | |
- | [--verbose] | + | |
- | [--help] | + | |
- | --simple, | + | |
- | | + | [--bufrtable <name of BUFR table] |
- | | + | [--tableformat < |
+ | [--tablepath <path to BUFR tables> | ||
+ | | ||
- | Usage 2: $0 --code < | + | =head1 DESCRIPTION |
- | Print the content of code or flag table < | + | Utility program for fetching info from BUFR tables. |
- | Usage 3: $0 --flag <value> --code | + | Execute without arguments for Usage, with option C<--help> for some |
+ | additional info. See also L<https:// | ||
+ | examples of use. | ||
- | Display | + | The tables used can be selected by the user with options |
+ | C<--bufrtable>, C<--tablepath> and C< | ||
+ | tableformat in Geo::BUFR is BUFRDC, while default tablepath in | ||
+ | bufrresolve.pl will be overridden if the environment variable | ||
+ | BUFR_TABLES is set. You should consider edit the source code of | ||
+ | bufrresolve.pl if you are not satisfied with the defaults chosen for | ||
+ | tablepath and bufrtable (search for ' | ||
- | For Usage 2 and 3 the only useful options are --bufrtable, | + | For tableformat ECCODES, see |
+ | L< | ||
+ | for more info on how to set C<--tablepath>. | ||
- | EOF | + | For the table name in C< |
- | | + | table, e.g. B0000000000098013001.TXT. Replacing B with D or C, or |
- | } | + | omitting this prefix altogether, or even omitting the trailing ' |
+ | (i.e. 0000000000098013001) will also work. | ||
+ | |||
+ | For the table name in C< | ||
+ | of table location, e.g. ' | ||
+ | ' | ||
+ | up local sequence descriptors, | ||
+ | and the local table to get the full expansion, e.g. | ||
+ | ' | ||
+ | |||
+ | See also L</" | ||
+ | |||
+ | =head1 OPTIONS | ||
+ | |||
+ | | ||
+ | | ||
+ | descriptors on one line | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | --help | ||
+ | the same as consulting perldoc bufrresolve.pl | ||
+ | |||
+ | Usage 1): Resolves the given descriptor(s) fully into table B | ||
+ | descriptors, | ||
+ | bits) written on each line (except for --simple). --partial, --simple | ||
+ | and --noexpand are mutually exclusive (full expansion is default). | ||
+ | |||
+ | Usage 2): Prints the contents of the requested code or flag table | ||
+ | (named by the table B descriptor). | ||
+ | |||
+ | Usage 3): Displays the bits set when the data value for the requested | ||
+ | flag table is < | ||
+ | |||
+ | Options may be abbreviated, | ||
+ | |||
+ | =head1 CAVEAT | ||
+ | |||
+ | The C< | ||
+ | is no guarantee that the same BUFR descriptor resolves the same way | ||
+ | for different BUFR tables. However, as soon as a new BUFR descriptor | ||
+ | is introduced in a BUFR table, it is extremely rare that the | ||
+ | descriptor is redefined in later versions. So for convenience, | ||
+ | bufrresolve.pl uses a default table (adding option C< | ||
+ | show you the tables used). If this is the wrong table for your purpose | ||
+ | (most common case will be if the descriptor was added in a higher | ||
+ | version than that of the default table), you should definitely use | ||
+ | C< | ||
+ | |||
+ | =head1 AUTHOR | ||
+ | |||
+ | Pål Sannes E< | ||
+ | |||
+ | =head1 COPYRIGHT | ||
+ | |||
+ | Copyright (C) 2010-2023 MET Norway | ||
+ | |||
+ | =cut | ||
</ | </ |