bufr.pm:bufrresolve_source

LDAP: couldn't connect to LDAP server

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:bufrresolve_source [2014-05-28 14:17:57]
pals
bufr.pm:bufrresolve_source [2025-11-05 09:24:36] (current)
pals
Line 1: Line 1:
 <code perl> <code perl>
-#!/usr/bin/perl -w+#!/usr/bin/perl
  
-# (C) Copyright 2010, met.no+# (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::Long; use Getopt::Long;
 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 'ECCODES' if preferred
 +use constant DEFAULT_TABLE_FORMAT => 'BUFRDC';
  
 # 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 DEFAULT_TABLE_PATH => '/usr/local/lib/bufrtables'; +use constant DEFAULT_TABLE_PATH_BUFRDC => '/usr/local/lib/bufrtables'; 
-# Ought to be your most up-to-date B table +use constant DEFAULT_TABLE_PATH_ECCODES => '/usr/local/share/eccodes/definitions/bufr/tables';
-use constant DEFAULT_TABLE => 'B0000000000000019000';+
  
 # Parse command line options # Parse command line options
Line 36: Line 40:
 GetOptions( GetOptions(
            \%option,            \%option,
-           'tablepath=s',# Set BUFR table path +           'bufrtable=s',# Set BUFR tables 
-           'code=s',     # Print the content of code table+           'code=s',     # Print the contents of code table
            'flag=i',     # Resolve the flag value given            'flag=i',     # Resolve the flag value given
            'help',       # Print help information and exit            'help',       # Print help information and exit
Line 45: Line 49:
            'simple',     # Like 'partial', but displaying the resulting            'simple',     # Like 'partial', but displaying the resulting
                          # descriptors on one line                          # descriptors on one line
-           'bufrtable=s',# Set BUFR tables+           'tableformat=s',  # Set BUFR table format 
 +           'tablepath=s',# Set BUFR table path
            'verbose=i',  # Display path and tables used            'verbose=i',  # Display path and tables used
        ) or pod2usage(-verbose => 0);        ) or pod2usage(-verbose => 0);
Line 78: Line 83:
 my $verbose = $option{verbose} ? 1 : 0; my $verbose = $option{verbose} ? 1 : 0;
 Geo::BUFR->set_verbose($verbose); Geo::BUFR->set_verbose($verbose);
 +
 +# 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::BUFR->set_strict_checking(2);
 +
 +# Set BUFR table format
 +my $tableformat = (defined $option{tableformat}) ? uc $option{tableformat} : DEFAULT_TABLE_FORMAT;
 +Geo::BUFR->set_tableformat($tableformat);
  
 # Set BUFR table path # Set BUFR table path
Line 87: Line 101:
     Geo::BUFR->set_tablepath($ENV{BUFR_TABLES});     Geo::BUFR->set_tablepath($ENV{BUFR_TABLES});
 } else { } else {
-    # If all else fails, use the libbufr bufrtables +    # If all else fails, use the default tablepath in BUFRDC/ECCODES 
-    Geo::BUFR->set_tablepath(DEFAULT_TABLE_PATH);+    if ($tableformat eq 'BUFRDC') { 
 +        Geo::BUFR->set_tablepath(DEFAULT_TABLE_PATH_BUFRDC); 
 +    } elsif ($tableformat eq 'ECCODES'
 +        Geo::BUFR->set_tablepath(DEFAULT_TABLE_PATH_ECCODES); 
 +    }
 } }
  
 # BUFR table file to use # BUFR table file to use
-my $table = $option{bufrtable} || DEFAULT_TABLE;+my $table = $option{bufrtable} || Geo::BUFR->get_max_table_version();
  
 my $bufr = Geo::BUFR->new(); my $bufr = Geo::BUFR->new();
Line 123: Line 141:
  
 =pod =pod
 +
 +=encoding utf8
  
 =head1 SYNOPSIS =head1 SYNOPSIS
Line 130: Line 150:
      [--simple]      [--simple]
      [--noexpand]      [--noexpand]
-     [--bufrtable <name of BUFR table]+     [--bufrtable <name of BUFR table
 +     [--tableformat <BUFRDC|ECCODES>]
      [--tablepath <path to BUFR tables>]      [--tablepath <path to BUFR tables>]
      [--verbose n]      [--verbose n]
Line 136: Line 157:
  
   2) bufrresolve.pl --code <code or flag table>   2) bufrresolve.pl --code <code or flag table>
-     [--bufrtable <name of BUFR table>]+     [--bufrtable <name of BUFR table>] 
 +     [--tableformat <BUFRDC|ECCODES>]
      [--tablepath <path to BUFR tables>]      [--tablepath <path to BUFR tables>]
      [--verbose n]      [--verbose n]
  
   3) bufrresolve.pl --flag <value> --code <flag table>   3) bufrresolve.pl --flag <value> --code <flag table>
-     [--bufrtable <name of BUFR table]+     [--bufrtable <name of BUFR table
 +     [--tableformat <BUFRDC|ECCODES>]
      [--tablepath <path to BUFR tables>]      [--tablepath <path to BUFR tables>]
      [--verbose n]      [--verbose n]
Line 150: Line 173:
  
 Execute without arguments for Usage, with option C<--help> for some Execute without arguments for Usage, with option C<--help> for some
-additional info. See also L</https://wiki.met.no/bufr.pm/start> for+additional info. See also L<https://wiki.met.no/bufr.pm/start> for
 examples of use. examples of use.
  
-It is supposed that the code and flag tables are contained in a file +The tables used can be selected by the user with options 
-with same name as corresponding B table except for having prefix C +C<--bufrtable>C<--tablepath> and C<--tableformat>. Default 
-instead of B. The tables used can be chosen by the user with options +tableformat in Geo::BUFR is BUFRDCwhile default tablepath in 
-C<--bufrtable> and C<--tablepath>. Default is the hard coded +bufrresolve.pl will be overridden if the environment variable 
-DEFAULT_TABLE in directory DEFAULT_TABLE_PATHbut this last one will +BUFR_TABLES is set. You should consider edit the source code of 
-be overriden if the environment variable BUFR_TABLES is set. You +bufrresolve.pl if you are not satisfied with the defaults chosen for 
-should consider edit the source code if you are not satisfied with the +tablepath and bufrtable (search for 'DEFAULT'). 
-defaults chosen.+ 
 +For tableformat ECCODES, see 
 +L<http://search.cpan.org/dist/Geo-BUFR/lib/Geo/BUFR.pm#BUFR-TABLE-FILES> 
 +for more info on how to set C<--tablepath>
 + 
 +For the table name in C<--bufrtable> in BUFRDC, use basename of B 
 +table, e.g.  B0000000000098013001.TXT. Replacing B with D or C, or 
 +omitting this prefix altogether, or even omitting the trailing '.TXT' 
 +(i.e. 0000000000098013001) will also work. 
 + 
 +For the table name in C<--bufrtable> in ECCODES, use last significant part 
 +of table location, e.g. '0/wmo/29' for WMO master tables or 
 +'0/local/8/78/236' for local tables on Unix-like systems. For looking 
 +up local sequence descriptors, you might need to provide both a master 
 +and the local table to get the full expansion, e.g. 
 +'0/wmo/29,0/local/8/78/236'
 + 
 +See also L</"CAVEAT"> below for more about the C<--bufrtable> option.
  
 =head1 OPTIONS =head1 OPTIONS
Line 168: Line 208:
                 descriptors on one line                 descriptors on one line
    --noexpand   Don't expand D descriptors at all    --noexpand   Don't expand D descriptors at all
- 
    --bufrtable <name of BUFR B or D table>  Set BUFR tables    --bufrtable <name of BUFR B or D table>  Set BUFR tables
 +   --tableformat Currently supported are BUFRDC and ECCODES (default is BUFRDC)
    --tablepath <path to BUFR tables>  Set BUFR table path    --tablepath <path to BUFR tables>  Set BUFR table path
    --verbose n  Display path and tables used if n > 0    --verbose n  Display path and tables used if n > 0
- 
    --help       Display Usage and explain the options used. Almost    --help       Display Usage and explain the options used. Almost
                 the same as consulting perldoc bufrresolve.pl                 the same as consulting perldoc bufrresolve.pl
Line 189: Line 228:
 Options may be abbreviated, e.g. C<--h> or C<-h> for C<--help> Options may be abbreviated, e.g. C<--h> or C<-h> for C<--help>
  
-=head1 NOTE ON --VERBOSE+=head1 CAVEAT
  
-n > 1 in C<--verbose ndoes not provide any more output than n=1so +The C<--bufrtableoption could be considered mandatorysince there 
-demanding an argument to C<--verbose> looks funnyBut if notsooner +is no guarantee that the same BUFR descriptor resolves the same way 
-or later someone would type C<bufrresolve.pl 307080 --verbose 1> which +for different BUFR tablesHoweveras soon as a new BUFR descriptor 
-by Perl would be interpreted as if the arguments were C<307080 000001 +is introduced in a BUFR table, it is extremely rare that the 
---verbose>, which probably is not what the user intended.+descriptor is redefined in later versions. So for convenience, 
 +bufrresolve.pl uses a default table (adding option C<--verbose 1> will 
 +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<--bufrtablewith the appropriate table.
  
 =head1 AUTHOR =head1 AUTHOR
Line 203: Line 247:
 =head1 COPYRIGHT =head1 COPYRIGHT
  
-Copyright (C) 2010 met.no+Copyright (C) 2010-2025 MET Norway
  
 =cut =cut
- 
 </code> </code>
  • bufr.pm/bufrresolve_source.1401286677.txt.gz
  • Last modified: 2022-05-31 09:23:11
  • (external edit)