2014-09-14 TOYODA Eizi
Environment Canada's BUFR decoder, called libECBufr, is neat and really stable software which I would recommend. By the word "stable" honestly I mean it can decode some JMA BUFR's which cannot be done by other decoder. This note is to show a quick-hack (I don't claim best) way to utilize it in Fortran-based computing application, in order to demonstrate that is possible.
Source and binary packages of libECBufr is available at https://launchpad.net/libecbufr. If you are using Debian or Ubuntu, you can simply download
*.deb binary package and install it. Otherwise source code is officially serviced via
$ bzr branch lp:libecbufr
for those who are not familliar with Debian tools, I have prepared tarball that can be used instead. Env Canada's guides to install:
Env Canada gives quick usage guide. Recommended option to generate computer-readable output is "
-dump". Assuming input is input-bufr.bin, the commandline would be naively:
$ BUFR_TABLES=/usr/share/libecbufr bufr_decoder -inbufr input-bufr.bin -dump -output dump.txt
But sometimes that fails. Error can be detected by presence of file "
DEBUG.decoder". The file looks like following:
Descriptor 1210 ??
Error: unknown descriptor 1210
Descriptor 13209 ??
Error: unknown descriptor 13209
Error: Template definition contains error(s)
Error: Unable to create Template
Error: can't decode messages
Note that there are messsages "unknown descriptor". That indicates there are some missing entries in the BUFR Table B, stored in the file
/usr/share/libecbufr/table_b_bufr by default.
Each BUFR message contains a sequence of six-digit "descriptors", followed by actual data bits. Each descriptor is could be explained as variable number: the element can be numeric value with units, ASCII string (called its obsolete name CCITT IA5), or code/flag reference. Decoder reads the Table B to find name, units, number of bits, and reference value, to proceed decoding actual data. Thus the decoder has to stop at an unknown descriptor because the number of bits of accompanied data cannot be known a priori.
In this case the sequence of descriptors is as follows:
008021 TIME SIGNIFICANCE CODE TABLE 004001 YEAR YEAR 004002 MONTH MONTH 004003 DAY DAY 004004 HOUR HOUR 004005 MINUTE MINUTES 001210 RIVER IDENTIFIER NUMERIC 005001 LATITUDE(HIGH ACCURACY) DEGREE 006001 LONGITUDE (HIGH ACCURACY) DEGREE 013209 RUNOFF INDEX NUMERIC
The missing table entry may be recent addition to the WMO Standard Table B, which is usually updated twice a year and posted at WMO website. But in case the lowest three digits of the descriptor is 192 or more, that is local descriptors which can be defined independently by the originating center (in this case JMA). There should be some documentation or please consult the data provider.
Note: If decoder says a descriptor whose top digit is '3' (i.e. 3xxxxx), that is sequence descriptor to be stored in Table D (file table_d_bufr for libECBufr). A sequence descriptor is a shorthand for several (or even dozens of) other descriptors, and is used to save the size of message.
Anyhow you will have revised Tables B and D. Then the commandline would be:$ bufr_decoder -ltableb ./table_b_bufr -ltabled ./table_d_bufr -inbufr input-bufr.bin -dump -output dump.txt
The dump file looks like following:
BUFR_EDITION=4 ---+ BUFR_MASTER_TABLE=0 | ORIG_CENTER=34 | ORIG_SUB_CENTER=0 +--- one per each BUFR message ... | COMPRESSED=1 ---+ DATASUBSET 1 : 13 codes ---+ 008021 16 | 301011 | 004001 2014 | 004002 7 | 004003 10 | 301012 +--- repeated subsets 004004 1 | 004005 0 | 001210 81001013 | 301021 | 005001 45.00000 | 006001 141.68750 | 013209 3 ---+ DATASUBSET 2 : 13 codes 008021 16 ...
The sample code
is an example Fortran program to read this format. It reads filename from the standard input, opens the dump file and read, and then prints the decode in CSV:
$ echo dump.txt | ./readdump | more
It can be modified as appropriate to be incorporated into the computing application.
The sample code
may be used for dump of other BUFR.
Although it is intended to be generic to some extent, following limitations remains:
|GPLv3.txt||14-Sep-2014 09:53||34K||Lesser GNU License|
|Makefile||13-Sep-2014 18:49||1.0K||build instruction|
|Z__C_RJTD_20140710010000_MET_SEQ_RAwstd_Proi_ANAL_bufr.bin||12-Sep-2014 13:16||25K||Analysis data sample|
|Z__C_RJTD_20140710010000_MET_SEQ_RAwstd_Proi_FH01-06_bufr4.bin||12-Sep-2014 13:16||36K||Forecast data sample|
|anldump.csv||17-Sep-2014 05:29||466K||result in CSV|
|anldump.txt||14-Sep-2014 07:37||473K||dump by libECBufr|
|fcsdump.csv||17-Sep-2014 05:29||780K||result in CSV|
|fcsdump.txt||14-Sep-2014 07:37||775K||dump by libECBufr|
|table_b_bufr||13-Sep-2014 18:46||143K||modified table B|
|table_d_bufr||12-Sep-2014 13:54||75K||(un)modified Table D|