To copy only the SYNOP messages from a file
To copy only the non-SYNOP messages from a file
Use the square brackets to insert the value of a key in the name of the output file.
To dump BUFR messages into a flat JSON format.
To dump BUFR messages into a structured JSON format. Note: This is the default if you omit the -j option
To dump a Fortran program with instructions to create (encode) the input message.Now compile and run 'encode.aaen_55.f90'. This will create a new BUFR file called 'outfile.bufr'. Check this is the the same as the input.
To dump a Python program with instructions to decode the input message.Examine the generated Python script 'decode.aaen_55.py'. You will see how to access each of the BUFR keys
To dump in a WMO documentation style with hexadecimal octet values (-H).
To add key type information (-t).
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:Then we create the BUFR file multitype.bufr from three others: 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
The bufr header information can be accessed without unpacking the data. This rules_file:will result in the following output:
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:will print out some data values from the specified SYNOP bufr messages.
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:The result is:
We can use conditional statements in bufr_filter. The syntax is: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:
The switch statement is an enhanced version of the if statement. Its syntax is the following: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".
To access the keys' attributes use the -> operator. The example below prints the attributes of key nonCoordinatePressure from a SYNOP bufr message.The result is:
To access keys by rank (i.e. by their occurrence in the message) use the # operator. The example below prints the value from the 4th occurrence of key pressure from a TEMP bufr message. As a reference, we also print all the pressure values found in the message.The result is:
It is possible to access elements by conditions imposed on coordinate descriptors. The example below prints the temperature values on temperature significant levels from a TEMP bufr message. For temperature significant levels the key verticalSoundingSignificance=4 and this is what we use in the condition:The result is:
Another example for accessing keys by condition is to read scatterometer data. File asca_139.bufr contains a single message with 2016 subsets in a compressed form. In this case each subset has exactly the same structure: they store one location with several beams and one backscatter value in each beam. To print the backScatter values for beamIdentifier=2 from all the subsets we can simply define the condition like this:The result is:
Accessing keys by condition provides the means to read individual subsets from uncompressed data. File synop_multi_subset.bufr contains a single message with several subsets in an uncompressed form. To access a given subset we can simply use key subsetNumber in the filter condition. The example below shows how to read the blockNumber, stationNumber and airTemperaturefor the first 3 subsets in the message:The result is:
bufr_get fails if a key is not found.
Without options a default list of keys is printed. The default list can be different depending on the type of BUFR message.The result is:
It is allowed to use wildcards in filenames.
To list only a specific set of keys use the -p option.
To list only a subset of messages use the -w (where option). Only the 12 UTC messages are listed with the following line.
All the non-12 UTC messages are listed as follows:
To list only the second message from a BUFR file:
Set key bufrHeaderCentre in the header and print its value after the change: