bufr.pm:bufrextract.pl_source

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:bufrextract.pl_source [2019-02-16 08:09:08]
pals
bufr.pm:bufrextract.pl_source [2023-02-05 09:07:45] (current)
pals
Line 2: Line 2:
 #!/usr/bin/perl #!/usr/bin/perl
  
-# (C) Copyright 2010-2019 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 32: Line 32:
            \%option,            \%option,
            'ahl=s',        # Extract BUFR messages with AHL matching <ahl_regexp> only            'ahl=s',        # Extract BUFR messages with AHL matching <ahl_regexp> only
 +           'gts',          # Include full gts message envelope if present
            'help',         # Print help information and exit            'help',         # Print help information and exit
            'only_ahl',     # Extract AHLs only            'only_ahl',     # Extract AHLs only
            'outfile=s',    # Print to file instead of STDOUT            'outfile=s',    # Print to file instead of STDOUT
-           'reuse_ahl=i',  # Reuse last AHL if current BUFR message has no AHL 
            'verbose=i',    # Set verbose level to n, 0<=n<=6 (default 0)            'verbose=i',    # Set verbose level to n, 0<=n<=6 (default 0)
            'without_ahl',  # Print the BUFR messages only, skipping AHLs            'without_ahl',  # Print the BUFR messages only, skipping AHLs
Line 44: Line 44:
  
 # only_ahl and without_ahl are mutually exclusive # only_ahl and without_ahl are mutually exclusive
-pod2usage( -message => "Options only_ahl and without_ahl are mutually exclusive",+pod2usage( -message => "Options only_ahlwithout_ahl and gts are mutually exclusive",
            -exitval => 2,            -exitval => 2,
            -verbose => 0)            -verbose => 0)
-    if $option{only_ahl} && $option{without_ahl};+    if ( ($option{only_ahl} && ($option{without_ahl} || $option{gts})) 
 +         || ($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 54: Line 56:
 # Set verbosity level # Set verbosity level
 Geo::BUFR->set_verbose($option{verbose}) if $option{verbose}; Geo::BUFR->set_verbose($option{verbose}) if $option{verbose};
- 
-# Set whether last ahl should be reused if current BUFR message has no AHL 
-Geo::BUFR->reuse_current_ahl($option{reuse_ahl}) if defined $option{reuse_ahl}; 
  
 my $ahl_regexp; my $ahl_regexp;
Line 137: Line 136:
         $current_message_number = $bufr->get_current_message_number();         $current_message_number = $bufr->get_current_message_number();
         $current_ahl = $bufr->get_current_ahl() || '';         $current_ahl = $bufr->get_current_ahl() || '';
 +        my $gts_eom = '';
  
-        if ($current_ahl && !$bufr->ahl_is_reused()) {+        if ($current_ahl) {
             if ($option{only_ahl}) {             if ($option{only_ahl}) {
                 print $OUT $current_ahl, "\n";                 print $OUT $current_ahl, "\n";
             } elsif (!$option{without_ahl}) {             } elsif (!$option{without_ahl}) {
 +                if ($option{gts}) {
 +                    my $current_gts_starting_line = $bufr->get_current_gts_starting_line() || '';
 +                    print $OUT $current_gts_starting_line;
 +                    $gts_eom = $bufr->get_current_gts_eom() || '';
 +                }
                 # Use \r\r\n after AHL, since this is the standard                 # Use \r\r\n after AHL, since this is the standard
                 # sequence used in GTS bulletins                 # sequence used in GTS bulletins
Line 150: Line 155:
  
         my $msg = $bufr->get_bufr_message();         my $msg = $bufr->get_bufr_message();
-        print $OUT $msg;+        print $OUT $msg, $gts_eom;
     }     }
 } }
Line 172: Line 177:
   bufrextract.pl <bufr file(s)>   bufrextract.pl <bufr file(s)>
       [--ahl <ahl_regexp>]       [--ahl <ahl_regexp>]
-      [--only_ahl] | [--without_ahl]+      [--only_ahl] | [--without_ahl] | [--gts]
       [--outfile <filename>]       [--outfile <filename>]
-      [--reuse_ahl n] 
       [--help]       [--help]
       [--verbose n]       [--verbose n]
Line 183: 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 [BBB] immediately preceding the BUFR message.
  
 Execute without arguments for Usage, with option C<--help> for some Execute without arguments for Usage, with option C<--help> for some
Line 195: Line 199:
    --ahl <ahl_regexp> Extract BUFR messages and/or AHLs with AHL    --ahl <ahl_regexp> Extract BUFR messages and/or AHLs with AHL
                       matching <ahl_regexp> only                       matching <ahl_regexp> only
 +   --gts              Include full gts message envelope if present
    --only_ahl         Extract AHLs only    --only_ahl         Extract AHLs only
    --without_ahl      Extract BUFR messages only    --without_ahl      Extract BUFR messages only
    --outfile <filename>    --outfile <filename>
                       Will print to <filename> instead of STDOUT                       Will print to <filename> instead of STDOUT
-   --reuse_ahl n  n=0 (default) AHL is considered belonging to a BUFR message 
-                      only if immediately preceding 
-                  n=1 When filtering using --ahl: Reuse last AHL found if current 
-                      BUFR message has no immediately preceding AHL 
    --help             Display Usage and explain the options used. For even    --help             Display Usage and explain the options used. For even
                       more info you might prefer to consult perldoc bufrextract.pl                       more info you might prefer to consult perldoc bufrextract.pl
Line 213: 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 C<--gtsif you want the full GTS message envelope (if 
-might consider setting C<--reuse 1when applying C<--ahl>, in order +present) to be included in outputThere are 2 main variations on this 
-to extract all (and not only the first) BUFR messages in multi message +envelope (SOH/ETX and ZCZC notation), for details see the Manual on 
-bulletinsSuch bulletins are very rare nowadays, however, and see +the GTS: Attachment II-4. Format of Meteorological Messages.
-also the L</"CAVEAT"> for more on this option. Note that the +
-corresponding AHL is still extracted (and printedonly once.+
  
 No bufrtables are needed for running bufrextract.pl, since section 4 No bufrtables are needed for running bufrextract.pl, since section 4
Line 244: Line 243:
 between the GTS AHL and the start of BUFR message (besides the between the GTS AHL and the start of BUFR message (besides the
 standard character sequence CRCRLF), likely leading bufrextract.pl to standard character sequence CRCRLF), likely leading bufrextract.pl to
-miss the AHL. Also, if applying C<--reuse 1>, the BUFR message of such +miss the AHL.
-a GTS bulletin will then be wrongly associated with the AHL of the +
-previous GTS bulletin when filtering on AHL. If bulletins with this +
-kind of error is more of a concern than multi message bulletins, you +
-should probably refrain from making use of the C<--reuse 1> option.+
  
 =head1 AUTHOR =head1 AUTHOR
Line 256: Line 251:
 =head1 COPYRIGHT =head1 COPYRIGHT
  
-Copyright (C) 2010-2019 MET Norway+Copyright (C) 2010-2023 MET Norway
  
 =cut =cut
- 
 </code> </code>
  • bufr.pm/bufrextract.pl_source.1550304548.txt.gz
  • Last modified: 2022-05-31 09:23:11
  • (external edit)