Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
bufr.pm:bufr_reencode_source [2010-07-22 07:34:30] pals |
bufr.pm:bufr_reencode_source [2023-02-05 10:20:14] (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 Carp; | use Carp; | ||
use Getopt:: | use Getopt:: | ||
use Pod::Usage qw(pod2usage); | use Pod::Usage qw(pod2usage); | ||
- | use File::Slurp qw(read_file 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 39: | Line 44: | ||
' | ' | ||
' | ' | ||
+ | ' | ||
' | ' | ||
' | ' | ||
Line 47: | Line 53: | ||
pod2usage(-verbose => 1) if $option{help}; | pod2usage(-verbose => 1) if $option{help}; | ||
- | my $width | + | # Make sure there is an input file |
+ | pod2usage(-verbose | ||
my $infile = shift; | my $infile = shift; | ||
- | pod2usage(-verbose | + | |
+ | my $width | ||
# Default is croak if (recoverable) error found in encoded BUFR format | # Default is croak if (recoverable) error found in encoded BUFR format | ||
Line 57: | 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 70: | 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 $dumped_message = read_file($infile); | + | my $dumped_message = do { |
+ | local $/; # Enable slurp mode | ||
+ | open my $fh, '<', | ||
+ | < | ||
+ | }; | ||
my $bufr = Geo:: | my $bufr = Geo:: | ||
- | # This sets object verbose level equal to class verbose level | + | my $buffer = $bufr->reencode_message($dumped_message, |
- | $bufr->set_verbose($verbose); | + | |
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-> | + | |
+ | | ||
} | } | ||
=pod | =pod | ||
+ | |||
+ | =encoding utf8 | ||
=head1 SYNOPSIS | =head1 SYNOPSIS | ||
Line 95: | Line 117: | ||
| | ||
| | ||
+ | | ||
| | ||
| | ||
Line 107: | Line 130: | ||
Execute without arguments for Usage, with option --help for some | Execute without arguments for Usage, with option --help for some | ||
additional info. | additional info. | ||
- | |||
- | See L</ | ||
=head1 OPTIONS | =head1 OPTIONS | ||
Bufr_reencode.pl will create BUFR message(s) printed to STDOUT from | Bufr_reencode.pl will create BUFR message(s) printed to STDOUT from | ||
- | content | + | contents |
by running bufrread.pl on the final BUFR message(s). | by running bufrread.pl on the final BUFR message(s). | ||
Line 136: | Line 157: | ||
n=2 (default) Croak if (recoverable) error in BUFR format. | n=2 (default) Croak if (recoverable) error in BUFR format. | ||
| | ||
- | | + | |
| | ||
be combined with option --outfile | be combined with option --outfile | ||
+ | | ||
| | ||
If used, will set path to BUFR tables. If not set, | If used, will set path to BUFR tables. If not set, | ||
will fetch tables from the environment variable | will fetch tables from the environment variable | ||
| | ||
- | DEFAULT_TABLE_PATH | + | DEFAULT_TABLE_PATH_< |
| | ||
- | the same as consulting perldoc | + | the same as consulting perldoc |
=head1 CAVEAT | =head1 CAVEAT | ||
' | ' | ||
- | set to 0, as reencode_message in Geo:: | + | set to 0, as reencode_message in Geo::BUFR does not provide encoding |
- | encoding of section 2. A warning will be printed to STDERR if | + | of section 2. A warning will be printed to STDERR if ' |
- | ' | + | present' |
=head1 AUTHOR | =head1 AUTHOR | ||
Line 160: | Line 182: | ||
=head1 COPYRIGHT | =head1 COPYRIGHT | ||
- | Copyright (C) 2010 met.no | + | Copyright (C) 2010-2023 MET Norway |
=cut | =cut | ||
</ | </ |