bufr.pm:sortbufrtemp.pl

Differences

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

Link to this comparison view

Next revision
Previous revision
bufr.pm:sortbufrtemp.pl [2015-02-16 14:27:50]
pals created
bufr.pm:sortbufrtemp.pl [2022-05-31 09:29:31] (current)
Line 126: Line 126:
     }     }
  
-    if ($bufr->get_descriptors_unexpanded() !~ /^309052/) { +    my $descriptors_unexpanded = $bufr->get_descriptors_unexpanded()
- if ($verbose > && $isub == 1) {+    if ($descriptors_unexpanded !~ /^30905(2|3)/) { 
 + if ($verbose > && $isub == 1) {
      print "Removing message $imsg";      print "Removing message $imsg";
      print " contained in bulletin with ahl $ahl" if $ahl;      print " contained in bulletin with ahl $ahl" if $ahl;
-     print " since unexpanded descriptors did not start with 309052\n";+     print " since unexpanded descriptors did not start with 309052 or 309053\n";
  }  }
  next;  next;
     } else {     } else {
- if ($verbose > 2) {+ if ($verbose > 3) {
      print "Processing subset $isub in message $imsg";      print "Processing subset $isub in message $imsg";
      print " contained in bulletin with ahl $ahl" if $ahl;      print " contained in bulletin with ahl $ahl" if $ahl;
Line 141: Line 142:
         my @plevels; # array of references to the 10 data values of         my @plevels; # array of references to the 10 data values of
                      # one pressure level                      # one pressure level
-        my $i1 = 29;+        my $i_eddrf ($descriptors_unexpanded =~ /^309052/) ? 29 : 19; 
 + my $i1 = $i_eddrf;
         while ($desc->[$i1] ne '031001') {         while ($desc->[$i1] ne '031001') {
             my @record = @$data[$i1 .. $i1+9];             my @record = @$data[$i1 .. $i1+9];
             if (defined $record[2]) {             if (defined $record[2]) {
                 push @plevels, \@record;                 push @plevels, \@record;
-            } elsif ($verbose > 1) { +            } elsif ($verbose > 2) { 
-                print "Missing pressure in level ", ($i1 - 29)/10 + 1+                print "Missing pressure in level ", ($i1 - $i_eddrf)/10 + 1
                     . " in subset $isub in Message number $imsg";                     . " in subset $isub in Message number $imsg";
                 print " in $ahl" if $ahl;                 print " in $ahl" if $ahl;
Line 166: Line 168:
             }             }
             my ($new_data, $new_desc)             my ($new_data, $new_desc)
-                = get_sorted_data($data,$desc,\@plevels,$i1);+                = get_sorted_data($data,$desc,\@plevels,$i1,$i_eddrf);
             $subset_data[$isub] = $new_data;             $subset_data[$isub] = $new_data;
             $subset_desc[$isub] = $new_desc;             $subset_desc[$isub] = $new_desc;
Line 184: Line 186:
 ## missing) ## missing)
 sub get_sorted_data { sub get_sorted_data {
-    my ($data,$desc,$plevels,$i1) = @_;+    my ($data,$desc,$plevels,$i1,$i_eddrf) = @_;
     my ($new_data,$new_desc);     my ($new_data,$new_desc);
  
     # Section 4 up to where pressure level data starts is unaltered     # Section 4 up to where pressure level data starts is unaltered
-    for my $ii (0 .. 27) {+    for my $ii (0 .. $i_eddrf-2) {
         $new_desc->[$ii] = $desc->[$ii];         $new_desc->[$ii] = $desc->[$ii];
         $new_data->[$ii] = $data->[$ii];         $new_data->[$ii] = $data->[$ii];
Line 194: Line 196:
  
     # Then handle pressure levels (and eddrf)     # Then handle pressure levels (and eddrf)
-    $new_desc->[28] = '031002'; +    $new_desc->[$i_eddrf-1] = '031002'; 
-    $new_data->[28] = undef; # Will be filled with $eddrf later+    $new_data->[$i_eddrf-1] = undef; # Will be filled with $eddrf later
     my $eddrf = 0; # extended delayed descriptor replication factor     my $eddrf = 0; # extended delayed descriptor replication factor
  
Line 212: Line 214:
             && same_pos_time(\@prev_plevel,$sorted_plevels[$ii])) {             && same_pos_time(\@prev_plevel,$sorted_plevels[$ii])) {
             # Combine the two levels into 1             # Combine the two levels into 1
-            if ($verbose > 1) {+            if ($verbose > 2) {
                 print "Merging pressure level for pressure = $PP\n";                 print "Merging pressure level for pressure = $PP\n";
             }             }
Line 240: Line 242:
     $eddrf++;     $eddrf++;
  
-    $new_data->[28] = $eddrf;+    $new_data->[$i_eddrf-1] = $eddrf;
  
     # Section 4 after pressure level data is unaltered     # Section 4 after pressure level data is unaltered
Line 275: Line 277:
     my $ii = 0;     my $ii = 0;
     foreach my $PP (@PP) {     foreach my $PP (@PP) {
-        return 0 if $PP > $prev_PP;+ if ($PP > $prev_PP) { 
 +     if ($verbose > 1) { 
 + print "Not sorted after pressure level $prev_PP"; 
 + print " (next level is $PP)\n"; 
 +     } 
 +     return 0; 
 + }
         if ($PP == $prev_PP) {         if ($PP == $prev_PP) {
-            return 0 if same_pos_time($plevels->[$ii],$plevels->[$ii-1]); +            if (same_pos_time($plevels->[$ii],$plevels->[$ii-1])) { 
-        }+ if ($verbose > 1) { 
 +     print "Duplicate levels at pressure $PP\n"
 +
 + return 0; 
 +     } 
 + }
         $prev_PP = $PP;         $prev_PP = $PP;
         $ii++;         $ii++;
Line 314: Line 327:
  
 Will extract from <bufr file> all BUFR TEMPs (recognized by unexpanded Will extract from <bufr file> all BUFR TEMPs (recognized by unexpanded
-descriptors in section 3 starting with 309052), sorting the pressure +descriptors in section 3 starting with 309052 or 309053), sorting the 
-levels and merging duplicate pressure levels (having same pressure, +pressure levels and merging duplicate pressure levels (having same 
-time and location coordinates) into one single level, printing to +pressure, time and location coordinates) into one single level, 
-STDOUT unless C<--outfile> is set. Pressure levels with missing +printing to STDOUT unless C<--outfile> is set. Pressure levels with 
-pressure will be removed.+missing pressure will be removed.
  
 Execute without arguments for Usage, with option C<--help> for some Execute without arguments for Usage, with option C<--help> for some
Line 333: Line 346:
                     n>=1: prints which BUFR messages were actually altered,                     n>=1: prints which BUFR messages were actually altered,
                           and which messages were removed because unexpanded                           and which messages were removed because unexpanded
-                          descriptors did not start with 309052 +                          descriptors did not start with 309052 or 309053 
-                    n>=2: prints which pressure levels were merged, and +                    n>=2: prints at which pressure level sorting 
-                          which levels were removed due to missing pressure +                          breaks, or first duplicate level encountered 
-                    n=3: prints which subset, message number and ahl+                          (whichever of these conditions happened 
 +                          first) 
 +                    n>=3: prints which pressure levels were merged, 
 +                          and which levels were removed due to missing 
 +                          pressure 
 +                    n=4: prints which subset, message number and ahl
                          (if exists) is currently processed                          (if exists) is currently processed
                     Verbose output is sent to STDOUT, so ought to be                     Verbose output is sent to STDOUT, so ought to be
                     combined with option --outfile                     combined with option --outfile
    --help           Display Usage and explain the options used. Almost    --help           Display Usage and explain the options used. Almost
-                    the same as consulting perldoc mergebufrtemp.pl+                    the same as consulting perldoc sortbufrtemp.pl
  
 Options may be abbreviated, e.g. C<--h> or C<-h> for C<--help>. Options may be abbreviated, e.g. C<--h> or C<-h> for C<--help>.
  • bufr.pm/sortbufrtemp.pl.1424096870.txt.gz
  • Last modified: 2022-05-31 09:23:11
  • (external edit)