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 [2014-05-28 14:31:14] pals |
bufr.pm:bufr_reencode_source [2025-11-05 09:25:44] (current) pals |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| <code perl> | <code 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 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 46: | Line 52: | ||
| # User asked for help | # User asked for help | ||
| pod2usage(-verbose => 1) if $option{help}; | pod2usage(-verbose => 1) if $option{help}; | ||
| + | |||
| + | # Make sure there is an input file | ||
| + | pod2usage(-verbose => 0) unless @ARGV == 1; | ||
| + | my $infile = shift; | ||
| my $width = $option{width} ? $option{width} : 15; | my $width = $option{width} ? $option{width} : 15; | ||
| - | |||
| - | my $infile = shift; | ||
| - | if (!$infile || !-f $infile) { | ||
| - | print STDERR "File ' | ||
| - | pod2usage(-verbose => 0); | ||
| - | } | ||
| # Default is croak if (recoverable) error found in encoded BUFR format | # Default is croak if (recoverable) error found in encoded BUFR format | ||
| Line 62: | Line 66: | ||
| # Set verbosity level | # Set verbosity level | ||
| 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 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 $dumped_message = read_file($infile); | + | my $dumped_message = do { |
| + | local $/; # Enable slurp mode | ||
| + | open my $fh, '<', | ||
| + | < | ||
| + | }; | ||
| my $bufr = Geo:: | my $bufr = Geo:: | ||
| + | |||
| + | 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-> | + | |
| + | | ||
| } | } | ||
| =pod | =pod | ||
| + | |||
| + | =encoding utf8 | ||
| =head1 SYNOPSIS | =head1 SYNOPSIS | ||
| Line 93: | Line 117: | ||
| | | ||
| | | ||
| + | | ||
| | | ||
| | | ||
| Line 135: | Line 160: | ||
| | | ||
| 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 bufr_reencode.pl | the same as consulting perldoc bufr_reencode.pl | ||
| Line 156: | Line 182: | ||
| =head1 COPYRIGHT | =head1 COPYRIGHT | ||
| - | Copyright (C) 2010 met.no | + | Copyright (C) 2010-2025 MET Norway |
| =cut | =cut | ||
| </ | </ | ||