Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
bufr.pm:bufrextract.pl_source [2016-11-29 08:41:07] pals created |
bufr.pm:bufrextract.pl_source [2023-02-05 09:07:45] (current) pals |
||
---|---|---|---|
Line 1: | Line 1: | ||
<code perl> | <code perl> | ||
- | # | + | # |
- | # (C) Copyright 2010-2016 MET Norway | + | # (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); | ||
Line 31: | Line 32: | ||
| | ||
' | ' | ||
+ | ' | ||
+ | ' | ||
' | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
' | ' | ||
' | ' | ||
+ | ' | ||
) or pod2usage(-verbose => 0); | ) or pod2usage(-verbose => 0); | ||
Line 43: | Line 44: | ||
# only_ahl and without_ahl are mutually exclusive | # only_ahl and without_ahl are mutually exclusive | ||
- | pod2usage( -message => " | + | pod2usage( -message => " |
| | ||
| | ||
- | if $option{only_ahl} && $option{without_ahl}; | + | if ( ($option{only_ahl} && |
+ | || ($option{without_ahl} && ($option{only_ahl} || $option{gts})) | ||
+ | || ($option{gts} && ($option{only_ahl} || $option{without_ahl})) ); | ||
# Make sure there is at least one input file | # Make sure there is at least one input file | ||
Line 53: | Line 56: | ||
# Set verbosity level | # Set verbosity level | ||
Geo:: | Geo:: | ||
- | |||
- | # Set whether last ahl should be reused if current BUFR message has no AHL | ||
- | Geo:: | ||
my $ahl_regexp; | my $ahl_regexp; | ||
Line 71: | Line 71: | ||
$OUT = *STDOUT; | $OUT = *STDOUT; | ||
} | } | ||
+ | binmode($OUT); | ||
# No need to decode section 4 here | # No need to decode section 4 here | ||
Line 133: | Line 134: | ||
last READLOOP if $current_subset_number == 0; | last READLOOP if $current_subset_number == 0; | ||
- | $current_message_number = $bufr-> | + | |
- | $current_ahl = $bufr-> | + | $current_ahl = $bufr-> |
+ | my $gts_eom = ''; | ||
- | # Must use \r\r\n after AHL, or else BUFR.pm will not | + | |
- | # recognize AHL. Should I change this in BUFR.pm? | + | if ($option{only_ahl}) { |
- | if ($current_ahl | + | print $OUT $current_ahl, |
- | | + | } elsif (!$option{without_ahl}) { |
- | print $OUT $current_ahl, | + | if ($option{gts}) { |
- | | + | my $current_gts_starting_line = $bufr-> |
- | print $OUT $current_ahl . " | + | print $OUT $current_gts_starting_line; |
- | | + | $gts_eom = $bufr-> |
- | } | + | } |
- | next READLOOP if $option{only_ahl}; | + | # Use \r\r\n after AHL, since this is the standard |
+ | # sequence used in GTS bulletins | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | next READLOOP if $option{only_ahl}; | ||
- | my $msg = $bufr-> | + | |
- | print $OUT $msg; | + | print $OUT $msg, $gts_eom; |
} | } | ||
} | } | ||
Line 170: | Line 177: | ||
bufrextract.pl <bufr file(s)> | bufrextract.pl <bufr file(s)> | ||
[--ahl < | [--ahl < | ||
- | [--only_ahl] | [--without_ahl] | + | [--only_ahl] | [--without_ahl] |
- | | + | |
- | [--help] | + | |
[--outfile < | [--outfile < | ||
+ | [--help] | ||
[--verbose n] | [--verbose n] | ||
Line 181: | Line 187: | ||
possibly filtering on AHL. | possibly filtering on AHL. | ||
- | The AHL (Abbreviated Header Line) is recognized as the TTAAii CCCC DTG | + | The AHL (Abbreviated Header Line) is recognized as the TTAAii CCCC |
- | [BBB] immediately preceding the BUFR message. | + | YYGGgg |
Execute without arguments for Usage, with option C< | Execute without arguments for Usage, with option C< | ||
Line 193: | Line 199: | ||
--ahl < | --ahl < | ||
matching < | matching < | ||
+ | | ||
| | ||
| | ||
- | | ||
- | only if immediately preceding | ||
- | n=1 When filtering using --ahl: Reuse last AHL found if current | ||
- | BUFR message has no immediately preceding AHL | ||
- | | ||
- | more info you might prefer to consult perldoc bufrextract.pl | ||
| | ||
Will print to < | Will print to < | ||
+ | | ||
+ | more info you might prefer to consult perldoc bufrextract.pl | ||
| | ||
Line 211: | Line 214: | ||
(ISS) from CCCC=ENMI. | (ISS) from CCCC=ENMI. | ||
- | If the BUFR file(s) are known to consist solely of GTS bulletins, you | + | Use option |
- | probably should use C<--reuse 1> when applying C< | + | present) to be included in output. There are 2 main variations on this |
- | extract all (and not only the first) BUFR messages in multi message | + | envelope |
- | bulletins (such bulletins are very rare, though). Note that the | + | the GTS: Attachment II-4. Format of Meteorological Messages. |
- | corresponding AHL is still extracted | + | |
No bufrtables are needed for running bufrextract.pl, | No bufrtables are needed for running bufrextract.pl, | ||
Line 231: | Line 233: | ||
next if $bufr-> | next if $bufr-> | ||
+ | |||
+ | Or to extract BUFR messages with TM315009 only: | ||
+ | |||
+ | next if bufr-> | ||
=head1 CAVEAT | =head1 CAVEAT | ||
- | bufrextract.pl expects the character sequence CRCRLF (\r\r\n in perl) | + | Sometimes GTS bulletins are erroneously issued with extra characters |
- | between the AHL and the start of the BUFR message. If the file of BUFR | + | between the GTS AHL and the start of BUFR message |
- | messages has been prepared from a collection of GTS bulletins where | + | standard |
- | this control | + | miss the AHL. |
- | every ' | + | |
- | in order to get the AHLs or filter on AHL. | + | |
=head1 AUTHOR | =head1 AUTHOR | ||
Line 247: | Line 251: | ||
=head1 COPYRIGHT | =head1 COPYRIGHT | ||
- | Copyright (C) 2010-2016 MET Norway | + | Copyright (C) 2010-2023 MET Norway |
=cut | =cut | ||
</ | </ |