bufr.pm:bufrextract.pl_source

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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]
pals
Line 1: Line 1:
 <code perl> <code perl>
-#!/usr/bin/perl -w+#!/usr/bin/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::Long; use Getopt::Long;
 use Pod::Usage qw(pod2usage); use Pod::Usage qw(pod2usage);
Line 31: 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
            'only_ahl',     # Extract AHLs only            'only_ahl',     # Extract AHLs only
-           'reuse_ahl=i',  # Reuse last AHL if current BUFR message has no AHL 
-           'without_ahl',  # Print the BUFR messages only, skipping AHLs 
-           'help',         # Print help information and exit 
            'outfile=s',    # Print to file instead of STDOUT            'outfile=s',    # Print to file instead of STDOUT
            '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
        ) 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 => "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 53: 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 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->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 = '';
  
- # Must use \r\r\n after AHL, or else BUFR.pm will not +        if ($current_ahl) { 
- # recognize AHL. Should I change this in BUFR.pm? +            if ($option{only_ahl}) { 
- if ($current_ahl && !$bufr->ahl_is_reused()) { +                print $OUT $current_ahl, "\n"; 
-     if ($option{only_ahl}) { +            } elsif (!$option{without_ahl}) { 
- print $OUT $current_ahl, "\n"; +                if ($option{gts}) { 
-     } elsif (!$option{without_ahl}) { +                    my $current_gts_starting_line = $bufr->get_current_gts_starting_line() || ''; 
- print $OUT $current_ahl . "\r\r\n"; +                    print $OUT $current_gts_starting_line; 
-     +                    $gts_eom = $bufr->get_current_gts_eom() || ''; 
-+                } 
- next READLOOP if $option{only_ahl};+                # Use \r\r\n after AHL, since this is the standard 
 +                # sequence used in GTS bulletins 
 +                print $OUT $current_ahl . "\r\r\n"; 
 +            
 +        
 +        next READLOOP if $option{only_ahl};
  
- my $msg = $bufr->get_bufr_message(); +        my $msg = $bufr->get_bufr_message(); 
- print $OUT $msg;+        print $OUT $msg, $gts_eom;
     }     }
 } }
Line 170: 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]
-      [--reuse_ahl n] +
-      [--help]+
       [--outfile <filename>]       [--outfile <filename>]
 +      [--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 [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 193: 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
-   --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 
-                      more info you might prefer to consult perldoc bufrextract.pl 
    --outfile <filename>    --outfile <filename>
                       Will print to <filename> instead of STDOUT                       Will print to <filename> instead of STDOUT
 +   --help             Display Usage and explain the options used. For even
 +                      more info you might prefer to consult perldoc bufrextract.pl
    --verbose n        Set verbose level to n, 0<=n<=6 (default 0)    --verbose n        Set verbose level to n, 0<=n<=6 (default 0)
  
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 C<--gtsif you want the full GTS message envelope (if 
-probably should use C<--reuse 1when applying C<--ahl>, in order to +presentto be included in outputThere are 2 main variations on this 
-extract all (and not only the first) BUFR messages in multi message +envelope (SOH/ETX and ZCZC notation), for details see the Manual on 
-bulletins (such bulletins are very rare, though). Note that the +the GTS: Attachment II-4. Format of Meteorological Messages.
-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 231: Line 233:
  
   next if $bufr->get_data_category() != 1;   next if $bufr->get_data_category() != 1;
 +
 +Or to extract BUFR messages with TM315009 only:
 +
 +  next if bufr->get_descriptors_unexpanded() ne '315009';
  
 =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 (besides the 
-messages has been prepared from a collection of GTS bulletins where +standard character sequence CRCRLF)likely leading bufrextract.pl to 
-this control character sequence has been removedyou should replace +miss the AHL.
-every 'BUFR' in file with '\r\r\nBUFR' before applying bufrextract.pl +
-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
 </code> </code>
  • bufr.pm/bufrextract.pl_source.txt
  • Last modified: 2023-02-05 09:07:45
  • by pals