Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
bufr.pm:bufrencode_source [2010-04-05 08:21:28] pals |
bufr.pm:bufrencode_source [2023-02-05 10:18:55] (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 22: | Line 22: | ||
use strict; | use strict; | ||
+ | use warnings; | ||
use Getopt:: | use Getopt:: | ||
use Pod::Usage qw(pod2usage); | use Pod::Usage qw(pod2usage); | ||
- | use File::Slurp qw(write_file); | ||
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 |
+ | use constant DEFAULT_TABLE_PATH_ECCODES => '/ | ||
# Parse command line options | # Parse command line options | ||
Line 40: | Line 45: | ||
' | ' | ||
' | ' | ||
+ | ' | ||
' | ' | ||
' | ' | ||
Line 58: | Line 64: | ||
Geo:: | Geo:: | ||
- | # Set verbosity level for the BUFR module. Must be set also for each | + | # Set verbosity level |
- | # BUFR object generated | + | Geo::BUFR-> |
- | my $verbose | + | |
- | Geo:: | + | # Set BUFR table format |
+ | my $tableformat | ||
+ | Geo:: | ||
# Set BUFR table path | # Set BUFR table path | ||
Line 71: | Line 79: | ||
Geo:: | Geo:: | ||
} else { | } else { | ||
- | # If all else fails, use the default | + | # If all else fails, use the default |
- | Geo:: | + | |
+ | | ||
+ | } elsif ($tableformat eq ' | ||
+ | Geo:: | ||
+ | } | ||
} | } | ||
my $bufr = Geo:: | my $bufr = Geo:: | ||
- | |||
- | # This sets object verbose level equal to class verbose level | ||
- | $bufr-> | ||
# Read metadata into $bufr | # Read metadata into $bufr | ||
Line 92: | Line 101: | ||
# Print the encoded BUFR message | # Print the encoded BUFR message | ||
+ | my $buffer = $bufr-> | ||
if ($option{outfile}) { | if ($option{outfile}) { | ||
- | my $buffer | + | my $outfile |
- | write_file($option{outfile}, | + | open my $fh, '>', $outfile or die " |
+ | binmode($fh); | ||
+ | print $fh $buffer; | ||
} else { | } else { | ||
- | print $bufr-> | + | |
+ | | ||
} | } | ||
- | |||
# See OPTIONS section in pod for format of metadata file | # See OPTIONS section in pod for format of metadata file | ||
Line 110: | Line 122: | ||
chomp; | chomp; | ||
next if /^\s*$/; | next if /^\s*$/; | ||
+ | s/^\s+//; | ||
my ($key, $value) = split /\s+/, $_, 2; | my ($key, $value) = split /\s+/, $_, 2; | ||
$metadata{$key} = $value; | $metadata{$key} = $value; | ||
Line 185: | Line 198: | ||
=pod | =pod | ||
+ | |||
+ | =encoding utf8 | ||
=head1 SYNOPSIS | =head1 SYNOPSIS | ||
Line 191: | Line 206: | ||
[--outfile <file to print encoded BUFR message to>] | [--outfile <file to print encoded BUFR message to>] | ||
[--strict_checking n] | [--strict_checking n] | ||
+ | [--tableformat < | ||
[--tablepath <path to BUFR tables>] | [--tablepath <path to BUFR tables>] | ||
[--verbose n] | [--verbose n] | ||
Line 202: | Line 218: | ||
Execute without arguments for Usage, with option --help for some | Execute without arguments for Usage, with option --help for some | ||
- | additional info. See also L</https:// | + | additional info. See also L< |
examples of use. | examples of use. | ||
=head1 OPTIONS | =head1 OPTIONS | ||
- | | + | --help |
- | | + | the same as consulting perldoc bufrencode.pl |
- | + | --outfile < | |
- | | + | instead of STDOUT |
- | | + | |
- | | + | n=1 Issue warning if (recoverable) error in |
- | | + | BUFR format |
- | | + | n=2 (default) Croak if (recoverable) error in BUFR format. |
- | + | Nothing more in this message will be encoded. | |
- | --verbose n Set verbose level to n, 0< | + | --tableformat |
- | | + | |
- | be combined with option --outfile | + | |
| | ||
- | If used, will set path to BUFR tables. If not set, | + | |
- | will fetch tables from the environment variable | + | |
- | BUFR_TABLES, | + | |
- | DEFAULT_TABLE_PATH | + | |
- | + | hard coded in source code. | |
- | --help Display Usage and explain the options. Almost | + | --verbose n Set verbose level to n, 0< |
- | the same as consulting perldoc bufrencode.pl | + | |
+ | be combined with option --outfile | ||
=head2 Required options | =head2 Required options | ||
Line 238: | Line 252: | ||
BUFR_EDITION | BUFR_EDITION | ||
MASTER_TABLE | MASTER_TABLE | ||
- | CENTRE | + | CENTRE |
SUBCENTRE | SUBCENTRE | ||
UPDATE_SEQUENCE_NUMBER | UPDATE_SEQUENCE_NUMBER | ||
OPTIONAL_SECTION | OPTIONAL_SECTION | ||
DATA_CATEGORY | DATA_CATEGORY | ||
- | INT_DATA_SUBCATEGORY | + | INT_DATA_SUBCATEGORY |
LOC_DATA_SUBCATEGORY | LOC_DATA_SUBCATEGORY | ||
- | MASTER_TABLE_VERSION | + | MASTER_TABLE_VERSION |
- | LOCAL_TABLE_VERSION | + | LOCAL_TABLE_VERSION |
YEAR 2008 | YEAR 2008 | ||
MONTH 9 | MONTH 9 | ||
Line 294: | Line 308: | ||
... | ... | ||
- | To encode a NIL subset, all delayed replication factors should be set | + | To encode a NIL subset, all delayed replication factors should be |
- | to 1, and all other values set to missing except for the descriptors | + | nonzero, and all other values set to missing except for the |
- | defining the station. | + | descriptors defining the station. |
Options may be abbreviated, | Options may be abbreviated, | ||
Line 306: | Line 320: | ||
=head1 COPYRIGHT | =head1 COPYRIGHT | ||
- | Copyright (C) 2010 met.no | + | Copyright (C) 2010-2023 MET Norway |
=cut | =cut | ||
</ | </ |