You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

bufr_copy examples

  1. To copy only the SYNOP messages from a file

    >  bufr_copy -w dataCategory=0 in.bufr out.bufr
    


  2. To copy only the non-SYNOP messages from a file

    >  bufr_copy -w dataCategory!=0 in.bufr out.bufr
    


  3. Use the square brackets to insert the value of a key in the name of the output file.

    > bufr_copy in.bufr out_[dataCategory].bufr 
    


bufr_dump examples

  1. To dump BUFR messages into a flat JSON format.

    > bufr_dump -jf ../data/bufr/aaen_55.bufr
    


  2. To dump BUFR messages into a structured JSON format.

    > bufr_dump -js ../data/bufr/aaen_55.bufr
    


  3. To dump in a WMO documentation style with hexadecimal octet values (-H).

    > bufr_dump -OH ../data/bufr/syno_1.bufr
    


  4. To add key type information (-t).

    > bufr_dump -OtH ../data/bufr/syno_1.bufr
    


bufr_filter examples

  1. The bufr_filter sequentially processes all bufr messages contained in the input files and applies the rules to each of them. Input messages can be written to the output by using the "write" statement. The write statement can be parameterised so that output is sent to multiple files depending on key values used in the output file name. First we write a rules_file containing the following statement:

    write "../data/split/[bufrHeaderCentre:i]_[dataCategory].bufr[editionNumber]";
    
    Then we create the BUFR file multitype.bufr from three others:
    mkdir ../data/split 
    cat ../data/bufr/syno_1.bufr ../data/bufr/goes_87.bufr ../data/bufr/gosat.bufr > ../data/split/multitype.bufr 
    
    Applying this rules_file to the "../data/split/multitype.bufr" bufr file we obtain several files in the ../data/split directory containing messages split according to their key values
    > bufr_filter rules_file ../data/split/multitype.bufr
    > ls ../data/split
    98_0.bufr3
    98_3.bufr4
    98_5.bufr3
    multitype.bufr
    


  2. The bufr header information can be accessed without unpacking the data. This rules_file:

    print "[bufrHeaderCentre] [bufrHeaderSubCentre] [masterTablesVersionNumber] [localTablesVersionNumber] [numberOfSubsets]";
    
    will result in the following output:
    > bufr_filter rules_file ../data/bufr/syno_multi.bufr
    98 0 13 1 1
    98 0 13 1 1
    98 0 13 1 1
    


  3. To print values from the data section the messages have to be unpacked. To do that we need to set key unapack to 1. This rules_file:

    set unpack=1;
    print "block=[blockNumber] station=[stationNumber] lat=[latitude] lon=[longitude] t2=[airTemperatureAt2M]";
    
    will print out some data values from the specified SYNOP bufr messages.
    > bufr_filter rules_file ../data/bufr/syno_multi.bufr
    block=1 station=1 lat=70.93 lon=-8.67 t2=274.5
    block=1 station=3 lat=77 lon=15.5 t2=268.4
    block=1 station=7 lat=78.92 lon=11.93 t2=268.5
    


  4. bufr_filter allows defining new keys with the transient keyword. We will further develop the previous example by creating a new key to combine the block number and the station number into the full WMO station id:

    set unpack=1;
    transient statid=1000*blockNumber+stationNumber;
    print "statid=[statid] lat=[latitude] lon=[longitude] t2=[airTemperatureAt2M]";
    
    The result is:
    > bufr_filter rules_file ../data/bufr/syno_multi.bufr
    statid=1001 lat=70.93 lon=-8.67 t2=274.5
    statid=1003 lat=77 lon=15.5 t2=268.4
    statid=1007 lat=78.92 lon=11.93 t2=268.5
    


  5. We can use conditional statements in bufr_filter. The syntax is:

    if ( condition ) { block of rules } else { block of rules }
    
    The condition can be made using ==,!= and joining single block conditions with || and &&. The statement can be any valid statement also another nested condition The rules_file below shows how to filter only SYNOP messages with a specific station id:
    set unpack=1;
    transient statid=1000*blockNumber+stationNumber;
    
    if (dataCategory ==0 && statid == 1003) {
      write out.bufr;
    }
    


  6. The switch statement is an enhanced version of the if statement. Its syntax is the following:

    switch (key1,key2,...,keyn) {
        case val11,val12,...,val1n:
            # block of rules;
        case val21,val22,...,val2n:
            # block of rules;
        default:
            # [ block of rules ]
    }
    
    Each value of each key given as argument to the switch statement is matched against the values specified in the case statements. If there is a match, then the block or rules corresponding to the matching case statement is executed. Otherwise, the default case is executed. The default case is mandatory if the case statements do not cover all the possibilities. The "~" operator can be used to match "anything".


  7. To access the keys' attributes use the -> operator. The example below prints the attributes of key pressure from a SYNOP bufr message.

    print "pressure=[pressure] [pressure->units]";
    print "pressure->code=[pressure->code!06d]";
    print "pressure->scale=[pressure->scale]";
    print "pressure->reference=[pressure->reference]";
    print "pressure->width=[pressure->width]";
    print "pressure->percentConfidence=[pressure->percentConfidence] [pressure->percentConfidence->units]";
    print "pressure->percentConfidence->code=[pressure->percentConfidence->code!06d]";
    print "pressure->percentConfidence->scale=[pressure->percentConfidence->scale]";
    print "pressure->percentConfidence->reference=[pressure->percentConfidence->reference]";
    print "pressure->percentConfidence->width=[pressure->percentConfidence->width]";
    
    The result is:
    > bufr_filter rules_file ../data/bufr/syno_1.bufr
    pressure=undef undef
    ERROR: Key/value not found
    </p></li><br /></ol><h2>bufr_get examples</h2><ol><li><p> bufr_get fails if a key is not found. 
    <ac:structured-macro ac:name="code"><ac:plain-text-body><![CDATA[ 
    > bufr_get -p centreName ../data/bufr/syno_1.bufr
    no messages found in ../data/bufr/syno_1.bufr
    


bufr_ls examples

  1. Without options a default list of keys is printed. The default list can be different depending on the type of BUFR message.

     
    >  bufr_ls ../data/bufr/syno_multi.bufr 
    
    The result is:
     
    ../data/bufr/syno_multi.bufr
    centre                     masterTablesVersionNumber  localTablesVersionNumber   rdbType                    rdbSubtype                 rdbtimeYear                rdbtimeMonth               typicalDate                typicalTime                numberOfSubsets            localLatitude              localLongitude             
    98                         13                         1                          1                          1                          2009                       1                          20090124                   120000                     1                          70.93                      -8.67                     
    98                         13                         1                          1                          1                          2009                       1                          20090124                   120000                     1                          77                         15.5                      
    98                         13                         1                          1                          1                          2009                       1                          20090124                   120000                     1                          78.92                      11.93                     
    3 of 3 messages in ../data/bufr/syno_multi.bufr
    
    3 of 3 total messages in 1 files
    


  2. It is allowed to use wildcards in filenames.

     
    >  bufr_ls ../data/bufr/syno_*.bufr 
    


  3. To list only a specific set of keys use the -p option.

     
    >  bufr_ls -p totalLength,bufrHeaderCentre,bufrHeaderSubCentre ../data/bufr/syno_multi.bufr 
    


  4. To list only a subset of messages use the -w (where option). Only the 12 UTC messages are listed with the following line.

     
    >  bufr_ls -w typicalTime="120000" ../data/bufr/syno_*.bufr
    


  5. All the non-12 UTC messages are listed as follows:

     
    >   bufr_ls -w typicalTime!="120000" ../data/bufr/syno_*.bufr
    


  6. To list only the scond message from a BUFR file:

     
    >  bufr_ls -w count=2 ../data/bufr/syno_multi.bufr
    


bufr_set examples

  1. Set key bufrHeaderCentre in the header and print its value after the change:

     
    >  bufr_set -v -p bufrHeaderCentre -s bufrHeaderCentre=222  ../data/bufr/syno_1.bufr out.bufr 
    


  • No labels