Bufr User Guide
Bufr User Guide
Milan Dragosavac
Operations Department
AUGUST 2008
c Copyright 2008
Literary and scientific copyrights belong to ECMWF and are reserved in all countries.
The information within this publication is given in good faith and considered to be true, but ECMWF accepts
no liability for error, omission and for loss or damage arising from its use.
CONTENTS
Contents
1 Introduction 3
2 BUFR format 4
2.1 Indicator section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Identification section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Optional section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Data description section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Data section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.6 End section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 BUFR software 8
3.1 Bufr tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Defaults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Decoding and encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.1 Subroutine BUFREX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.2 Subroutine BUFREN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4 Error codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5 Partial expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.1 Subroutine BUSRQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.6 Printing routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6.1 To print Section 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6.2 To print Section 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6.3 To print Section 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.6.4 To print Section 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.6.5 To print data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.7 Bufr software tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7.1 Subroutine BUS012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7.2 Subroutine BUS0123 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.7.3 Subroutine BUSEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.7.4 Subroutine BUSEL2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5 Examples 66
5.1 To unpack and print data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
5.2 To expand data descriptors only . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.3 To create bufr message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
5.4 An example of decoding Opera radar composite images . . . . . . . . . . . . . . . . . . . . 89
5.5 An example of C program calling fortran bufr subroutines . . . . . . . . . . . . . . . . . . . 92
FM-94 BUFR (Binary Universal Form for data Representation) has been designed to achieve efficient exchange
and storage of meteorological and oceanographic data. It is self defining, table driven and very flexible data
representation system, especially for huge volumes of data.
The User’s Guide is described in six sections.
Section 2 describes Bufr format in general, and it is useful for those who are not familiar with the Bufr concept.
Section 3 explains Bufr software usage. It contains FORTRAN subroutines for expanding and packing Bufr
data. A number of routines described shall be used as a tools.
A quality control representation in the Bufr is given in section 4.
Section 5 contains few example programs to decode/repack bufr data, create a new bufr message and expand
data descriptors only.
Useful WMO example templates are given in the section 6.
2 BUFR format
A full definition of the BUFR form is given in WMO Manual on Codes, Volume I, International Codes,
Part B-Binary Codes, WMO-No.306, FM 94-IX Ext. BUFR. This section offers a brief description of the
basic structure and representation of the BUFR code.
The BUFR form is a binary representation of meteorological data. It is a continuous bit stream made up of a
sequence of octets (one octet is eight bits). The only part of BUFR where information does not end on byte
boundaries is the data section, where a length of BUFR table B elements can have any number of bits (although
it must not exceed the number of bits in a computer word for non-character data).
A BUFR message consists of six sections, some of which may be completely optional (section 2) or partially
optional (section 1).
The representation of data in the form of a series of bits is independent of any particular machine representation.
It is important to stress that the BUFR representation is not suitable for data visualisation without computer
interpretation.
The data section consists of one or more data subsets of related meteorological data which are defined, de-
scribed and represented by a single Bufr table D entry. For observational data, one subset corresponds to one
observation. The data section can be in compressed or uncompressed form.
Each section included in the message always contain an even number of octets. If necessary, sections must be
appended with bits set to zero to fulfil this requirement.
A BUFR message is comprised of the following sections:
• Indicator section
• Identification section
• Optional section
• Data section
• End section
Indicator section or Section 0 of a Bufr message has a fixed length of eight octets. Information about the total
size of the BUFR message in octets 5-7 is very useful for reading BUFR data from pure binary files. The
content of Section 0 is given in the Table 1.
This section contains information relevant to data recognition without performing complete expansion of data.
Data type and observation date and time are the most important parts of it. In the case of multi-subset data
the time of the earliest observation should be packed into section 1. This section also contains all information
necessary do define the Bufr tables used.
The presence of Section 2 of the Bufr message is indicated by a flag in the 8th byte of Section 1. This section
can be used locally by Automated Data Processing centres. This Section is used to keep the Report Data Base
key.
The layout of Section 2 is given in table 3.
This section describes the data in the data section. The information which can be found in the first seven octets
is the number of subsets in the message, their form and the type of data (observation/non-observation). The
data descriptors start in the 8th octet of the section 3. Each descriptor is spread over two bytes and contains
three parts. If F = 0, the descriptor is an element descriptor and values of X and Y define entries in Bufr Table
F X Y
2 bits 6 bits 8 bits
B. For F = 1, the descriptor is a replication descriptor. If F = 2, the descriptor is one of the operators from bufr
Table C. F = 3 means that the descriptor represents the sequence descriptor from Bufr Table D. The table D
entries contain a list of element descriptors, operators, and/or other sequence descriptors.
In an ideal situation, data in Section 4 should be described by one Bufr Table D entry only.
X stands for class of elements in the range from 0-63 and Y is an entry within class 0-255. Classes 48-63 are
reserved for local use and entries from 192-255 within all classes are also reserved for local usage.
Layout of Data description section is given in the Table 5.
The Data section, like all sections, starts with the length of Section 4 followed by a continuous stream of bits
from byte 5 onward.
The End section is comprised of four ”7” characters in CCITT International Alphabet No.5 and this marks the
end of the Bufr message. The layout of the End section is given in the Table 7.
3 BUFR software
The first version of ECMWF Bufr software was designed and implemented in 1987. A great deal of experience
has been gathered in handling binary coded observations since. Bufr software is written in FORTRAN 77.
Versions for C90, VAX, IBM, SGi , SUN, HP and for all UNIX and LINUX based platforms are available. It
has been installed on Mac OSX as well.
Bufr Tables B and D are used to collect all necessary information to pack/unpack Bufr data. Which table is to
be loaded is decided at runtime using information from Section 1 of the Bufr message. The naming convention
for Bufr binary tables is as follows:
Current version of the software will keep in memory up to JTMAX=10 versions of tables in the round robin
fashion.
3.2 Defaults
NVIND = 2147483647
RVIND = 1.7D38
Default path for Bufr Tables is hard coded in the software. To change the path set environmental variable
BUFR TABLES :
During decoding code/flag tables could be read if code figure meaning is needed. If user want to use code and
flag tables set: VARIABLE USE TABLE C=true
Purpose
Decodes Bufr message into fully expanded form, returning information relevant to all Bufr Sections, expanded
values, Bufr Table B element names and units.
Interface
CALL BUFREX(KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KSEC3,KSEC4,
KELEM,CNAMES,CUNITS,KVALS,VALUES,CVALS,KERR)
where:
Input arguments
Output arguments
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly.
• KSEC2 - An INTEGER array of 4096 words containing Bufr Section 2 information. ECMWF uses this
section to store Report Data Base key.
Method
A Bufr message passed as an argument to this routine is decoded section by section. Before Section 3 ex-
pansion Bufr tables are loaded using KSEC1 information to create table names. The loaded Bufr tables are
kept in memory and swapped only if the next message is requesting different tables.
Section 3 Data descriptors are unpacked and expanded applying all necessary operators in force and creating a
list of Bufr Table B elements which correspond one to one to the data in the Data section of the Bufr message.
Word and bit pointers are calculated for each element in the message.
Having all this information, unpacking of the data is performed applying reference value and scaling to get the
final value for one element in the Bufr message. Unpacked data are stored in VALUES array. The correspond-
ing element names and units are stored in the CNAMES and CUNITS arrays respectively.
To achieve efficiency, original Data descriptors are saved for the following comparison. If the Data descriptors
for the next observation are not different from the previous, the former word and bit pointers to the elements
are used saving time for data descriptors expansion.
If a Bufr Table B element is type character, the corresponding VALUES element contains a real number which,
when truncated to an integer represents
where:
In the case of multi subset data, the one dimensional array VALUES contains all subsets of data. The formula
to find the index to the VALUES array of the i-th element of observation is:
index=i + (nsub-1)*KELEM
Current version of the Bufr software can handle KELEM up to 160000 and KVALS up to 4096000.
Externals
Reference
WMO -No. 306 Manual on Codes Volume I, Part B - Binary Codes: J.K. Gibson and M. Dragosavac 1988:
Decoding Data Represented in FM 94-IX Ext. BUFR
Purpose
Creates a packed Bufr message from the information contained in the arguments of the subroutine.
Interface
CALL BUFREN(KSEC0,KSEC1,KSEC2,KSEC3,KSEC4,
KTDLEN,KTDLST,KDLEN,KDATA,KELEM,KVALS,
VALUES,CVALS,KBUFL,KBUFF,KERR)
where
Input arguments
Output arguments
• KBUFL - An INTEGER variable containing the length of the Bufr message in words.
Method
A basic approach when this software was designed to have a one to one correspondence between expanded
data descriptors and the data itself.
The input arguments have to be filled in before packing,. The lengths of the Sections and the total Bufr
message length are set by the software. The lengths of the Section 1 and 2 must be supplied by the user. The
other Section lengths ought to be set to zero. The default size of the Section 1 is 18 octets and 22 octets for
Bufr Edition 4, if there are no local entries. The Section 2 is optional section, and ECMWF uses it to store
Report Data Base key. In this case the length of the Section 2 is 52 octets.
Before setting values in the VALUES array, it is recommended to initialise it with the MISSING value indicator.
The Optional Section 2 and a local part of Section 1 must be in the packed form because encoder packs these
information in byte by byte manner.
The Data descriptors stored in the KTDLST array are expanded taking delayed replication factor values from
KDATA array if needed. The order of replication factor values must be as they appear in the data. If 203YYY
change reference value operator is used a reference value shall be in KDATA array.
The VALUES array must be filled in correspondence with previously described data elements. In the case of
multi subsets, the pointer of the ith element in VALUES array is:
index=i +(nsub-1)*KELEM
which implies that the first element of the second subset begins at KELEM+1 position even if the number of
elements in the observation is less then KELEM.
For character information or elements having CCITT IA No.5 as units, VALUES array element contains a real
number which, when truncated to an integer represents
value=isub*1000+length
where isub is a subscript of the element in CVALS array, where the character string is stored and the length
represents number of bytes/character occupied by this element.
To find out what one observation should look like, the BUXDES routine can be used. This routine expands
data descriptors for the user. The procedure to print an expanded list of the data descriptors is the same as to
print Section 3 of Bufr message.
Externals
Reference
WMO -No. 306 Manual on Codes Volume I, Part B - Binary Codes: J.K. Gibson and M. Dragosavac 1988:De-
coding Data Represented in FM 94-IX
The errors returned by the Bufr decoding/encoding routines can be zero, negative and positive. The zero
returned error code means no errors detected, negative error is a warning error which can occur during packing.
If the value to be packed is too big, BUFREN will pack the truncated value and return a negative error code.
The hard errors are positive.
The Error codes are given in Table 8.
It is possible to expand only the requested subset of elements without unpacking the whole Bufr message. This
method is called partial expansion.
To do partial expansion, the request has to be set by calling the BUSRQ routine before calling BUFREX.
Purpose
Sets flags and Bufr table B reference numbers of the requested elements for partial expansion.
Interface
CALL BUSRQ(KREQ,KRQL,KRQ,RQV,KERR)
where:
Input arguments
1 0 not used
2 0 - No partial expansion
1 - Partial expansion
3 0 - No quality control
1 - quality control
4 0 - No statistics
1 - Statistics
5 0 - No difference statistics
1 - Difference statistics
6 0 - No substituted values
1 - Substituted values
• KRQ - An INTEGER array containing the list of requested elements (Bufr table B reference numbers)
• RQV - A REAL*8 array of KRQL containing a list of values signifying requested elements
Output arguments
Method
The lists of flags and Bufr Table B reference numbers are used to designate requested Bufr elements. The
elements from class 7 and 8 are possible qualifiers for the other elements if supplied with corresponding
values.
The partial expansion is not supported for the whole analysis feedback Bufr messages ( includes original
observation and analysis variables followed by the statistics e.t.c.)
The list of the requested elements and corresponding word and bit pointers are created before expansion. These
pointers are used to extract data from the Data section of the Bufr message.
The KRQ and RQV arrays have to be initialised by missing value indicators NVIND and RVIND respectively.
The KREQ(1) is useful to split the feedback Bufr message into original, quality control and analysis feed back
data.
Externals
Reference
None
3.5.2 Example
Running BUFR program and answering prompts as below, 500 mb level information is unpacked by the
BUFREX routine.
ECMWF
LENGTH OF SECTION 2 52
1 309007
2 104000
3 031001
4 007004
5 008001
6 011061
7 011062
8 222000
9 101000
10 031002
11 031031
12 001031
13 001032
14 101000
15 031002
16 033007
1 007004 PRESSURE
2 008001 VERTICAL SOUNDING SIGNIFICANCE
3 010003 GEOPOTENTIAL
4 012001 TEMPERATURE/DRY BULB TEMPERATURE
5 012003 DEW POINT TEMPERATURE
6 011001 WIND DIRECTION
7 011002 WIND SPEED
1 PRESSURE 0.5000000000E+05 PA
2 VERTICAL SOUNDI 0.3600000000E+02 FLAG TABLE 008001
3 GEOPOTENTIAL 0.5374000000E+05 M**2/S**2
4 TEMPERATURE/DRY 0.2475000000E+03 K
5 DEW POINT TEMPE 0.2245000000E+03 K
6 WIND DIRECTION 0.3050000000E+03 DEGREE TRUE
7 WIND SPEED 0.2600000000E+02 M/S
KREQ(1)=1
KREQ(2)=2
KRQL=7
KRQ(1)=007004 RQV(1)=50000.
KRQ(2)=008001 RQV(2)=RMISS
KRQ(3)=010003 RQV(3)=RMISS
KRQ(4)=012001 RQV(4)=RMISS
KRQ(5)=012003 RQV(5)=RMISS
KRQ(6)=011001 RQV(6)=RMISS
KRQ(7)=011002 RQV(7)=RMISS
CALL BURQS(KREQ,KRQL,KRQ,RQV,KERR)
Bufr form is a binary representation of meteorological data and as such is not suitable for visualization. After
expanding Bufr data using the BUFREX routine a number of printing routines can be used to print different
parts of the Bufr message.
CALL BUPRS0(KSEC0)
CALL BUPRS1(KSEC1)
Section 2 of the Bufr message is an optional section and every ADP centre can pack any information in this
section. The Bufr software decodes this local information and stores it into KSEC2 array. ECMWF is storing
RDB key in the Section 2 of the Bufr messages. To print content of the Section 2, subroutine BUUKEY must
be called before the BUPRS2 routine.
For other cases, special routines have to be written to unpack this information.
CALL BUUKEY(KSEC1,KSEC2,KEY,KSUP,KERR)
CALL BUPRS2(KSUP,KEY)
where
Prior to calling the BUPRS3 routine, the BUSEL or BUSEL2 routine has to be called to get lists of unexpanded
and fully expanded Data descriptors. In the case of multi-subset uncompressed bufr data the expanded list of
descriptors might be different for different subsets.
CALL BUSEL(KTDLEN,KTDLST,KTDEXL,KTDEXP,KERR)
or
CALL BUSEL2(KSUBSET,KELEM,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,CUNITS,KERR)
CALL BUPRS3(KSEC3,KTDLEN,KTDLST,KTDEXL,KTDEXP,KELEM,CNAMES)
CALL BUPRT(K,KSUB1,KSUB2,KELEM,CNAMES,CUNITS,CVALS,
KVALS,VALUES,KSUP,KSEC1,KERR)
where:
Purpose
Interface
CALL BUS012(KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KERR)
where
Input arguments
Output argument
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly.
• KSEC2 - An INTEGER array of 4096 words containing Bufr Section 2 information. ECMWF uses this
section to store Report Data Base key.
Method
None.
Externals
Reference
None.
Purpose
Interface
CALL BUS0123(KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KSEC3,KERR)
where
Input arguments
Output argument
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly.
• KSEC2 - An INTEGER array of 4096 words containing Bufr Section 2 information. ECMWF uses this
section to store Report Data Base key.
Method
None.
Externals
Reference
None.
Purpose
Returns lists of unexpanded and expanded data descriptors from the Bufr message. The lists contains Bufr
Table D sequence numbers, and the Bufr Table B reference numbers.
Interface
CALL BUSEL(KTDLEN,KTDLST,KTDEXL,KTDEXP,KERR)
where
Input arguments
None.
Output arguments
Method
None
Externals
None
Reference
None
Purpose
Returns lists of unexpanded and expanded data descriptors from the Bufr message for particular sebset.
Interface
CALL BUSEL2(KSUBSET,KELEM,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,CUNITS,KERR)
where
Input arguments
Output arguments
Method
None
Externals
None
Reference
None
Purpose
Interface
CALL BUUKEY(KSEC1,KSEC2,KEY,KSUP,KERR)
where: zz
Input arguments
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly.
• KSEC2 - An INTEGER array of 4096 words containing Bufr Section 2 information. ECMWF uses this
section to store Report Data Base Key.
• KSUP - An INTEGER array (size 9) containing supplementary information.
Output arguments
Method
The latitudes and longitudes are unpacked and stored as integers. To get real values apply the following
calculation:
Externals
Reference
None.
Purpose
Interface
CALL BUPKEY(KEY,KSEC1,KSEC2,KERR)
where:
Input arguments
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly.
KSEC1 The content od the KSEC1 array is given in the following Table:
Array index Word content
1 Length of section 1 in bytes
2 Bufr Edition number (currently 4)
3 Originating centre
4 Update sequence number
5 Flag (presence of Section 2 in the message)
6 Bufr message type ( Bufr Table A)
7 Bufr message subtype (local use)
8 Version number of local table used
9 Year
10 Month
11 Day
12 Hour
13 Minute
14 Bufr Master Table used
15 Version number of Master table used
16 Originating sub-centre
17 International sub-category
18 Second
19- Local ADP centre information (byte by byte)
KSEC2 The content od the KSEC2 array is given in the following Table:
Array index Word content
1 Length of Section 2 in bytes
2- Report Data Base key in packed form
Output arguments
Method
The integer values in the KEY array for latitude and longitude must be calculated as:
Externals
Purpose
A basic principle in encoding Bufr data is to have a one to one correspondence between data descriptors and
the values to be packed.
This routine is a tool to achieve this requirement. It expands Data descriptors and prints unexpanded and
expanded lists. The Unexpanded list should be part of Section 3 of the Bufr message and the VALUES array
ought to be filled with element values corresponding to the expanded data descriptors.
Interface
CALL BUXDES(K,KSEC1,KTDLEN,KTDLST,KDLEN,KDATA,KELEM,
KTDEXL,KTDEXP,CNAMES, CUNITS,KERR)
where:
Input arguments
• KSEC1 - An INTEGER array of at least 40 words containing Bufr Section 1 information. When Section
1 contains data for local use, KSEC1 should be sized accordingly. The following words of KSEC1 must
be filled:
KSEC1(2) - Bufr Edition number (currently 4) KSEC1(3) - Originating centre KSEC1(8) - Version
number of local tables used KSEC1(15)- Version number of Master table used
• KDATA - An INTEGER array containing delayed replication factors in the order they appear in the
expanded list
Output arguments
Method
None.
Externals
Reference
None.
Purpose
The expanded Bufr message can be very lengthy containing many bit maps referring backwards to the data.
This routine resolves bit maps for the user, returning two dimensional arrays containing the expanded obser-
vation and the corresponding applications (quality controls, statistics, differences e.t.c).
Every application appears as a new column. A new data are following each other in the first column, starting
with the generating centre/application information.
Interface
CALL BUBOX(KSUB,KSUP,KELEM,KWTR,CNAMES,CUNITS,KVALS,
VALUES,KBOX,KAPP,KLEN,KBOXR,VALS,CBOXN,CBOXU, KERR)
where:
Input arguments
• KELEM - An INTEGER variable containing expected number of expanded. elements. It must be the
same as used in BUFREX routine previously called.
• KWTR - An INTEGER array containing list of expanded Bufr table B reference numbers (KTDEXP
output from BUSEL routine).
Output arguments
• KLEN - An INTEGER containing max index for number of rows. The next column starts at KLEN +1
element or index=i + (KAPP - 1)*KLEN to address any value in the box.
Method
The expanded Bufr message is passed in the subroutine to resolve backward reference bit maps associating
all applications to the particular element. The output arrays containing boxed data are one dimensional arrays
containing information as two dimensional table.
The first column contains in first 6 rows reserved information and the original observation starts at the index
7. Columns 2- KAPP are different generating applications corresponding through bit maps to the data in the
column 1. Column 1 contains KLEN elements. Index to the i-th element can be calculated as:
index = i + (KAPP-1) * KLEN
The first raw, columns 2 to KAPP contain quality control operators (222000, 225000 e.t.c) Rows 2 to 6,
columns 2 to KAPP contain generating centre, generating application, statistics, incremental update number
and minimisation simulation number respectively.
Externals
Reference
None.
Purpose
Interface
CALL BUPRTBOX(KBOX,KAPP,KLEN,KBOXR,VALS,CBOXN,CBOXU)
Input arguments
• KLEN - An INTEGER containing max index for number of rows. The next column starts at KLEN +1
element or index=i + (KAPP –1)*KLEN to address any value in the box.
Output arguments
None.
Method
None.
Externals
None.
Reference
None.
Purpose
Applies delayed repetition to create full image. The routine can be called after call to bufrex and busel2
routines. It will return image array and imahe meta-data information.
Interface
BUGET_OPERA_IMAGE(KSEC1,KTDEXL,KTDEXP,CNAMES,CUNITS,
KELEM,,KVALS,VALUES,CVALS,
KTDEXL_IMG,KTDEXP_IMG,CNAMES_IMG,CUNITS_IMG,
KVALS_IMG,VALUES_IMG,CVALS_IMG,IMAGE,KERR)
Input arguments
Output arguments
• KTDEXP IMG - An INTEGER array containing the list of KTDEXL IMG data descriptors
Method
None.
Externals
None.
3.8 Performance
The speed to decode Bufr messages is proportional to the number of messages. Since the same number of the
same kind of observations can be packed into Bufr form in many ways, it is recommended to use multi subsets
in compressed form when- ever possible. To get the best performance from the software it is recommended
that:
• The input file for expansion should contain Bufr messages sorted according to their types.
Here are some figures of real times used on IBM RS6000, single processor computer to expand:
• All conventional data for one analysis cycle (56945 Bufr messages, 197696 subsets) 18 seconds.
• All AIRS data for one analysis cycle (70 Mbytes, 7775 bufr messages with 80563 subsets) 122 seconds.
A quality control information in the Bufr shall be represented using Quality control operators from the Bufr
Table C. Table 9 contains definition of possible operators and their usage.
Table 9: Bufr Tables C quality control operators
Bufr message containing analysis feedback data was expanded. List of descriptors in the section 3 shows
how to use quality control operators to represent various quality controls and statistics. The output contains
following information:
ECMWF
LENGTH OF SECTION 2 52
1 311001
2 222000
3 101018
4 031031
5 001031
6 001032
7 101018
8 033007
9 001031
10 001032
11 033220
12 033232
13 033222
14 033233
15 235000
16 001031
17 001032
18 007004
19 011003
20 011004
21 010195
22 012001
23 222000
24 236000
25 101005
26 031031
27 001031
28 001032
29 101005
30 033209
31 222000
32 237000
33 001031
34 001032
35 101005
36 033208
37 222000
38 237000
39 001031
40 001032
41 101005
42 033207
43 222000
44 237000
45 001031
46 001032
47 101005
48 033206
49 222000
50 237000
51 001031
52 001032
53 101005
54 033205
55 222000
56 237000
57 001031
58 001032
59 101005
60 033236
61 222000
62 237000
63 001031
64 001032
65 101005
66 033249
67 222000
68 237000
69 001031
70 001032
71 101005
72 033238
73 222000
74 237000
75 001031
76 001032
77 101005
78 033234
79 222000
80 237000
81 001031
82 001032
83 101005
84 033250
85 222000
86 237000
87 001031
88 001032
89 101005
90 033251
91 224000
92 237000
93 001031
94 001032
95 008023
96 101005
97 224255
98 224000
99 237000
100 001031
101 001032
102 008023
103 101005
104 224255
105 224000
106 237000
107 001031
108 001032
109 008023
110 101005
111 224255
112 224000
113 237000
114 001031
115 001032
116 008023
117 101005
118 224255
119 224000
120 237000
121 001031
122 001032
123 008023
124 101005
125 224255
126 225000
127 237000
128 001031
129 001032
130 008024
131 101005
132 225255
133 225000
134 237000
135 001031
136 001032
137 008024
138 033210
139 033211
140 101005
141 225255
142 225000
143 237000
144 001031
145 001032
146 008024
147 033210
148 033211
149 101005
150 225255
151 225000
152 237000
153 001031
154 001032
155 008024
156 033210
157 033211
158 101005
159 225255
160 225000
161 237000
162 001031
163 001032
164 008024
165 033210
166 033211
167 101005
168 225255
169 225000
170 237000
171 001031
172 001032
173 008024
174 033210
175 033211
176 101005
177 225255
178 225000
179 237000
180 001031
181 001032
182 008024
183 033210
184 033211
185 101005
186 225255
187 225000
188 237000
189 001031
190 001032
191 008024
192 033210
193 033211
194 101005
195 225255
196 225000
197 237000
198 001031
199 001032
200 008024
201 033210
202 033211
203 101005
204 225255
205 225000
206 237000
207 001031
208 001032
209 008024
210 033210
211 033211
212 101005
213 225255
5 Examples
This program is an interactive version to expand Bufr data. It can decode and encode unpacked data as a single
or multi-subset Bufr messages. It calls BUBOX and BUPRTBOX routines to resolve the bit map.
The outputs of the expanded AIREP data using Bufr print routines and BUPRTBOX are attached.
PROGRAM BUFR
C
C**** *BUFR*
C
C
C PURPOSE.
C --------
C EXAMPLE OF USING BUFR UNPACKING/PACKING SOFTWARE.
C
C
C** INTERFACE.
C ----------
C
C NONE.
C
C METHOD.
C -------
C
C NONE.
C
C
C EXTERNALS.
C ----------
C
C CALL BUSEL2
C CALL BUFREX
C CALL BUFREN
C CALL BUPRS0
C CALL BUPRS1
C CALL BUPRS2
C CALL BUPRS3
C CALL BUPRT
C CALL BUUKEY
C
C REFERENCE.
C ----------
C
C NONE.
C
C AUTHOR.
C -------
C
C M. DRAGOSAVAC *ECMWF* 15/09/87.
C
C
C MODIFICATIONS.
C --------------
C
C NONE.
C
C
IMPLICIT LOGICAL(L,O,G), CHARACTER*8(C,H,Y)
C
PARAMETER(JSUP = 9,JSEC0= 3,JSEC1= 40,JSEC2=4096,JSEC3= 4,
1 JSEC4=2,JELEM=320000,JSUBS=400,JCVAL=150 ,JBUFL=512000,
2 JBPW = 32,JTAB =3000,JCTAB=3000,JCTST=3000,JCTEXT=6000,
3 JWORK=4096000,JKEY=46, JTMAX=10,JTCLAS=64,JTEL=255)
C
PARAMETER (KELEM=80000)
PARAMETER (KVALS=4096000)
C
DIMENSION KBUFF(JBUFL)
DIMENSION KBUFR(JBUFL)
DIMENSION KSUP(JSUP) ,KSEC0(JSEC0),KSEC1(JSEC1)
DIMENSION KSEC2(JSEC2),KSEC3(JSEC3),KSEC4(JSEC4)
DIMENSION KEY (JKEY),KREQ(2)
DIMENSION NREQUEST(2)
C
REAL*8 VALUES(KVALS),VALUE(KVALS)
DIMENSION KTDLST(JELEM),KTDEXP(JELEM),KRQ(KELEM)
REAL*8 RQV(KELEM)
DIMENSION KDATA(200),KBOXR(JELEM*4)
REAL*8 VALS(KVALS)
C
CHARACTER*256 CF,COUT,CARG(4)
CHARACTER*64 CNAMES(KELEM),CBOXN(JELEM*4)
CHARACTER*24 CUNITS(KELEM),CBOXU(JELEM*4)
CHARACTER*80 CVALS(kelem)
CHARACTER*80 CVAL(kelem)
CHARACTER*80 YENC
REAL*8 RVIND
REAL*8 EPS
C
EXTERNAL GETARG
C
C ------------------------------------------------------------------
C* 1. INITIALIZE CONSTANTS AND VARIABLES.
C -----------------------------------
100 CONTINUE
C
C MISSING VALUE INDICATOR
C
NBYTPW=JBPW/8
RVIND=1.7D38
NVIND=21474834096647
IOBS=0
EPS=10.D-8
NPACK=0
IYEAR=NVIND
N=0
NCOM=0
OO=.FALSE.
C
C
C
C GET INPUT AND OUTPUT FILE NAME.
C
NARG=IARGC()
C
C
DO 104 J=1,NARG
CALL GETARG(J,CARG(J))
104 CONTINUE
II=0
IO=0
DO 105 J=1,NARG
IF(CARG(J).EQ.’-i’) THEN
IN=J
ELSEIF(CARG(J).EQ.’-o’) THEN
IO=J
END IF
105 CONTINUE
IF(IN.EQ.0) THEN
PRINT*,’USAGE -- decode_bufr -i infile’
STOP
END IF
IF(IO.EQ.0.and.IN.EQ.0) THEN
PRINT*,’USAGE -- decode_bufr -i infile -o outfile’
STOP
END IF
C
IF(IO.NE.0) COUT=CARG(IO+1)
C
IF(IO.LT.IN) THEN
IST=IN+1
IEND=NARG
ELSE
IST=IN+1
IEND=IO-1
END IF
C
C
IF(IO.NE.0) THEN
JJ=INDEX(COUT,’ ’)
JJ=JJ-1
CALL PBOPEN(IUNIT1,COUT(1:JJ),’W’,IRET)
IF(IRET.EQ.-1) STOP ’OPEN FAILED ON BUFR.DAT’
IF(IRET.EQ.-2) STOP ’INVALID FILE NAME’
IF(IRET.EQ.-3) STOP ’INVALID OPEN MODE SPECIFIED’
END IF
C
DO 101 II=IST,IEND
CF=CARG(II)
ILN=INDEX(CF,’ ’)
ILN=ILN-1
KRQL=0
NR=0
KREQ(1)=0
KREQ(2)=0
DO 103 I=1,KELEM
RQV(I)=RVIND
KRQ(I)=NVIND
103 CONTINUE
C
C
C
C -----------------------------------------------------------------
C* 2. SET REQUEST FOR EXPANSION.
C --------------------------
200 CONTINUE
C
OPRT=.FALSE.
OENC=.FALSE.
WRITE(*,’(A,$)’) ’ DO YOU WANT TO PRINT( Y/N ) : ’
READ (*,’(A)’) YENC
IF(YENC(1:1).EQ.’Y’.OR.YENC(1:1).EQ.’y’) THEN
OPRT=.TRUE.
END IF
ICODE=0
WRITE(*,’(A,$)’) ’ CODE TABLES TO BE PRINTED ( Y/N ) : ’
READ (*,’(A)’) YCODC
IF(YCODC(1:1).EQ.’Y’.OR.YCODC(1:1).EQ.’y’) THEN
ICODE=1
END IF
WRITE(*,’(A,$)’) ’ DO YOU WANT ENCODING( Y/N ) : ’
READ (*,’(A)’) YENC
IF(YENC(1:1).EQ.’Y’.OR.YENC(1:1).EQ.’y’) THEN
OENC=.TRUE.
WRITE(*,’(A,$)’) ’ NUMBER OF SUBSETS TO PACK : ’
READ(*,’(BN,I4)’) NCOM
OCOMP=.FALSE.
WRITE(*,’(A,$)’) ’ DO YOU WANT COMPRESSION( Y/N ) : ’
READ (*,’(A)’) YCOMP
IF(YCOMP(1:1).EQ.’Y’.OR.YCOMP(1:1).EQ.’y’) OCOMP=.TRUE.
END IF
WRITE(*,’(A,$)’) ’ RECORD NUMBER TO START FROM : ’
READ(*,’(BN,I6)’) NR
C
201 CONTINUE
C
WRITE(*,’(A,$)’) ’ REQUESTED ELEMENT : ’
READ(*,’(BN,I6)’) IEL
WRITE(*,’(A,$)’) ’ REQUESTED VALUE : ’
READ(*,’(BN,F12.2)’) VAL
IF(IEL.EQ.0) THEN
KRQL=J
ELSE
J=J+1
KRQ(J)=IEL
RQV(J)=VAL
IF(VAL.EQ.0.) RQV(J)=RVIND
GO TO 201
END IF
C
WRITE(*,’(A,$)’) ’ REQUESTED FLAG 1 : ’
READ(*,’(BN,I6)’) KREQ(1)
C
WRITE(*,’(A,$)’) ’ REQUESTED FLAG 2 : ’
READ(*,’(BN,I6)’) KREQ(2)
C
WRITE(*,’(A,$)’) ’ DO YOU WANT TO PRINT SECTION 0-3( Y/N ) : ’
READ (*,’(A,$)’) YENC
OSEC3=.FALSE.
IF(YENC(1:1).EQ.’Y’.OR.YENC(1:1).EQ.’y’) OSEC3=.TRUE.
C
C* 2.1 SET REQUEST FOR PARTIAL EXPANSION.
C ----------------------------------
210 CONTINUE
C
c IERR=0
CALL BUSRQ(KREQ,KRQL,KRQ,RQV,IERR)
C
C SET VARIABLE TO PACK BIG VALUES AS MISSING VALUE INDICATOR
C
KPMISS=1
KPRUS=0
KOKEY=0
CALL BUPRQ(KPMISS,KPRUS,KOKEY)
C
C -----------------------------------------------------------------
IF(NCOM.NE.0) THEN
KEL1=KVALS/NCOM
IF(KEL1.GT.KELEM) KEL1=KELEM
END IF
C
C* 3. READ BUFR MESSAGE.
C ------------------
300 CONTINUE
C
IERR=0
KBUFL=0
C
CALL PBBUFR(IUNIT,KBUFF,JBYTE*4,KBUFL,IERR)
IF(IERR.EQ.-1) THEN
IF(NPACK.NE.0) GO TO 600
PRINT*,’NUMBER OF SUBSETS ’,IOBS
PRINT*,’NUMBER OF MESSAGES ’,N
STOP ’EOF’
END IF
IF(IERR.EQ.-2) STOP ’FILE HANDLING PROBLEM’
IF(IERR.EQ.-3) STOP ’ARRAY TOO SMALL FOR PRODUCT’
C
N=N+1
PRINT*,’----------------------------------’,N,’ ’,KBUFL
KBUFL=KBUFL/NBYTPW+1
IF(N.LT.NR) GO TO 300
C
C -----------------------------------------------------------------
C* 4. EXPAND BUFR MESSAGE.
C --------------------
400 CONTINUE
C
CALL BUS0123( KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KSEC3,IERR)
IF(IERR.NE.0) THEN
PRINT*,’ERROR IN BUS012: ’,IERR
PRINT*,’ BUFR MESSAGE NUMBER ’,N,’ CORRUPTED.’
IERR=0
GO TO 300
END IF
C
KEL=KVALS/KSEC3(3)
IF(KEL.GT.KELEM) KEL=KELEM
C
CALL BUFREX(KBUFL,KBUFF,KSUP,KSEC0 ,KSEC1,KSEC2 ,KSEC3 ,KSEC4,
1 KEL,CNAMES,CUNITS,KVALS,VALUES,CVALS,IERR)
C
IF(IERR.NE.0) THEN
CALL EXIT(2)
END IF
C
C
IOBS=IOBS+KSEC3(3)
C
C
ISUBSET=1
CALL BUSEL2(ISUBSET,KEL,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
1 CUNITS,IERR)
C IF(IERR.NE.0) CALL EXIT(2)
C
C
c DO 401 IK=1,KSEC3(3)
c
c CALL BUSEL2(IK,KEL,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
c 1 CUNITS,IERR)
c KSEP(5)=KTDEXL
c CALL BUBOX(IK,KSUP,KEL,KTDEXP,CNAMES,CUNITS,KVALS,VALUES,
c 1 KBOX,KAPP,KLEN,KBOXR,VALS,CBOXN,CBOXU,IERR)
C
c 401 CONTINUE
C
C
C* 4.1 PRINT CONTENT OF EXPANDED DATA.
C -------------------------------
410 CONTINUE
C
IF(.NOT.OPRT) GO TO 500
IF(.NOT.OSEC3) GO TO 450
C
C* 4.2 PRINT SECTION ZERO OF BUFR MESSAGE.
C -----------------------------------
420 CONTINUE
C
CALL BUPRS0(KSEC0)
C
C* 4.3 PRINT SECTION ONE OF BUFR MESSAGE.
C -----------------------------------
430 CONTINUE
C
CALL BUPRS1(KSEC1)
C
C
C IF(KSEC1(6).EQ.11) THEN
C
C IST=1
C IEND=KSEC3(3)
C
CALL BUPRT(ICODE,IST,IEND,KEL,CNAMES,CUNITS,CVALS,
1 KVALS,VALUES,KSUP,KSEC1,IERR)
C ELSE
C
C RESOLVE BIT MAPS FOR EACH SUBSET
C
C ist=1
C iend=ksec3(3)
C
C IF(IEND.GT.KSEC3(3)) IEND=KSEC3(3)
C
C DO 461 IK=IST,IEND
C
C CALL BUSEL2(IK,KEL,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
C 1 CUNITS,IERR)
C
C KSUP(5)=KTDEXL
C CALL BUBOX(IK,KSUP,KEL,KTDEXP,CNAMES,CUNITS,KVALS,VALUES,
C 1 KBOX,KAPP,KLEN,KBOXR,VALS,CBOXN,CBOXU,IERR)
C IF(IERR.NE.0) CALL EXIT(2)
C
C CALL BUPRTBOX(KBOX,KAPP,KLEN,KBOXR,VALS,CBOXN,CBOXU)
C
C461 CONTINUE
C END IF
C
C -----------------------------------------------------------------
C* 5. COLLECT DATA FOR REPACKING.
C ---------------------------
500 CONTINUE
C
C
IF(.NOT.OENC) GO TO 300
C
ISUBS=KSEC3(3)
DO J=1,ISUBS
C
NPACK=NPACK+1
C
C FIRST GET DATA DESCRIPTORS
C
CALL BUSEL2(J,KEL,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
1 CUNITS,IERR)
IF(IERR.NE.0) CALL EXIT(2)
C
DO I=1,KTDEXL
IO=I+(NPACK-1)*KEL1
IN=I+(J-1)*KEL
C
IF(CUNITS(I).EQ.’CCITTIA5’) THEN
IPOS =VALUES(IN)/1000.
ICH=NINT(VALUES(IN)-IPOS*1000)
KKK=KKK+1
VALUE(IO)=KKK*1000+ICH
CVAL(KKK)=CVALS(IPOS)
ELSE
VALUE(IO)=VALUES(IN)
END IF
IF(KTDEXP(I).EQ.31001.OR.KTDEXP(I).EQ.31002) THEN
KK=KK+1
KDATA(KK)=NINT(VALUE(IO))
END IF
IF(KTDEXP(I).EQ.004001) THEN
IF(IYEAR.EQ.NVIND) THEN
IYEAR=NINT(VALUE(IO))
END IF
END IF
END DO
C
KDLEN=KK
IF(NPACK.EQ.NCOM) THEN
KSEC3(3)=NPACK
KSEC1(5)=0
KSEC1(8)=1
KSEC1(15)=12
IF(KSEC0(3).LT.4) THEN
KSEC1(17)=255
KSEC1(18)=0
END IF
KSEC0(3)=4 ! EDITION 4 OF BUFR MESSAGE
IF(KSEC0(3).GE.4) KSEC1(1)=22
KSEC3(4)=0 ! NO COMPRESSION
IF(KSEC1(9).LT.101) THEN
KSEC1(9)=IYEAR
END IF
IF(OCOMP) KSEC3(4)=64 ! COMPRESSION
KBUFL=JBUFL
CALL BUFREN( KSEC0,KSEC1,KSEC2,KSEC3,KSEC4,
1 KTDLEN,KTDLST,KDLEN,KDATA,KEL1,
2 KVALS,VALUE,CVAL,KBUFL,KBUFR,IERR)
IF(IERR.NE.0) THEN
PRINT*,’ERROR IS ’,IERR
PRINT*,’ERROR DURING ENCODING.’
CALL EXIT(2)
END IF
C
ILEN=KBUFL*NBYTPW
C
IERR=0
C
CALL PBWRITE(IUNIT1,KBUFR,ILEN,IERR)
IF(IERR.LT.0) THEN
PRINT*,’ERROR WRITING INTO TARGET FILE.’
CALL EXIT(2)
END IF
PRINT*,’RECORD WRITTEN INTO FILE ’
C
NPACK=0
KKK=0
KK=0
END IF
C
END DO
C
GO TO 300
C -----------------------------------------------------------------
C* 6. PACK BUFR MESSAGE BACK INTO BUFR.
C ---------------------------------
600 CONTINUE
C
KSEC3(3)=NPACK
KSEC1(8)=1
KSEC1(15)=12
KSEC0(3)=4 ! EDITION 4 OF BUFR MESSAGE
IF(KSEC0(3).GE.4) KSEC1(1)=22
IF(KSEC0(3).LT.4) THEN
KSEC1(17)=255
KSEC1(18)=0
END IF
KSEC3(4)=0 ! NO COMPRESSION
IF(KSEC1(9).LT.101) THEN
KSEC1(9)=IYEAR
END IF
C
IF(OCOMP) KSEC3(4)=64 ! COMPRESSION
KBUFL=JBUFL
C
C
C* 6.2 ENCODE DATA INTO BUFR MESSAGE.
C ------------------------------
620 CONTINUE
C
CALL BUFREN( KSEC0,KSEC1,KSEC2,KSEC3,KSEC4,
1 KTDLEN,KTDLST,KDLEN,KDATA,KEL1,
2 KVALS,VALUE,CVAL,KBUFL,KBUFR,IERR)
IF(IERR.NE.0) THEN
PRINT*,’ERROR IS ’,IERR
PRINT*,’ERROR DURING ENCODING.’
CALL EXIT(2)
END IF
C
C 6.3 WRITE PACKED BUFR MESSAGE INTO FILE.
C ------------------------------------
630 CONTINUE
C
ILEN=KBUFL*NBYTPW
C
CALL PBWRITE(IUNIT1,KBUFR,ILEN,IERR)
IF(IERR.LT.0) THEN
PRINT*,’ERROR WRITING INTO TARGET FILE.’
CALL EXIT(2)
END IF
PRINT*,’RECORD WRITTEN INTO FILE ’
C
NPACK=0
KKK=0
C
GO TO 300
C -----------------------------------------------------------------
C
810 CONTINUE
C
WRITE(*,’(1H ,A)’) ’OPEN ERROR ON INPUT FILE’
GO TO 900
C
800 CONTINUE
C
IF(IRET.EQ.-1) THEN
PRINT*,’NUMBER OF RECORDS PROCESSED ’,N
PRINT*,’NUMBER OF OBSERVATIONS ’,IOBS
ELSE
PRINT*,’ BUFR : ERROR= ’,IERR
END IF
C
900 CONTINUE
C
CALL PBCLOSE(IUNIT,IRET)
101 CONTINUE
CALL PBCLOSE(IUNIT1,IRET)
C
END
This is an example of the expanded AIREP data containing quality control information.
ECMWF
LENGTH OF SECTION 2 52
1 311001
2 222000
3 101018
4 031031
5 001031
6 001032
7 101018
8 033007
Output of the AIREP data after calling BUBOX and BUPRTBOX routines.
ECMWF
1 301001
2 001011
3 001003
4 002001
5 301011
6 301012
7 301021
8 007030
9 007031
10 302001
11 007004
12 010009
13 007032
14 012101
15 012103
16 013003
17 007032
18 020001
19 007032
20 013023
21 007032
22 302004
23 101004
24 302005
25 105003
26 008002
27 020011
28 020012
29 020014
30 020017
31 020062
32 013013
33 012113
34 020003
35 004024
36 020004
37 020005
38 004024
39 002004
40 013033
41 004024
42 014031
43 004025
44 014002
45 014004
46 014016
47 014028
48 014029
49 014030
50 007032
51 102002
52 004024
53 013011
54 007032
55 101002
56 004024
57 012111
58 004024
59 012112
60 007032
61 002002
62 008021
63 004025
64 011001
65 011002
66 008021
67 103002
68 004025
69 011043
70 011041
PROGRAM TDEXP
C
C**** *TDEXP*
C
C
C PURPOSE.
C --------
C Expands list of Bufr data descriptors.
C
C
C** INTERFACE.
C ----------
C
C NONE.
C
C METHOD.
C -------
C
C NONE.
C
C
C EXTERNALS.
C ----------
C
C CALL BUSEL
C CALL BUFREX
C CALL BUFREN
C CALL BUPRS0
C CALL BUPRS1
C CALL BUPRS2
C CALL BUPRS3
C CALL BUPRT
C CALL BUUKEY
C
C REFERENCE.
C ----------
C
C NONE.
C
C AUTHOR.
C -------
C
C M. DRAGOSAVAC *ECMWF* June 2005.
C
C
C MODIFICATIONS.
C --------------
C
C NONE.
C
C
IMPLICIT LOGICAL(L,O,G), CHARACTER*8(C,H,Y)
C
PARAMETER(JSEC1=40,JSEC3=4)
PARAMETER (KDLEN=200,KELEM=40000,KVALS=360000)
C
DIMENSION KSEC1(JSEC1) ! ,KSEC3(JSEC3)
C
DIMENSION KTDLST(KELEM),KTDEXP(KELEM)
DIMENSION KDATA(KDLEN)
C
CHARACTER*64 CNAMES(KELEM)
CHARACTER*24 CUNITS(KELEM)
C
C
C ------------------------------------------------------------------
C* 1. INITIALIZE CONSTANTS AND VARIABLES.
C -----------------------------------
100 CONTINUE
C
C
RVIND=1.7D38
C
C INITIALIZE DELAYED REPLICATION FACTORS OR REFERENCE VALUES ETD.
C
C
KDATA(1)=2
KDATA(2)=14
KDATA(3)=2
KDATA(4)=2
C
C SET DATA DECSRIPTORS
C
KTDLST( 1)=301001
KTDLST( 2)=301011
KTDLST( 3)=301012
KTDLST( 4)=301021
KTDLST( 5)=107000
KTDLST( 6)=031001
KTDLST( 7)=007004
KTDLST( 8)=008001
KTDLST( 9)=010003
KTDLST( 10)=012001
KTDLST( 11)=012003
KTDLST( 12)=011003
KTDLST( 13)=011004
KTDLST( 14)=224000
KTDLST( 15)=236000
KTDLST( 16)=101000
KTDLST( 17)=031001
KTDLST( 18)=031031
KTDLST( 19)=001031
KTDLST( 20)=001032
KTDLST( 21)=008023
KTDLST( 22)=105000
KTDLST( 23)=031001
KTDLST( 24)=204002
KTDLST( 25)=031021
KTDLST( 26)=204002
KTDLST( 27)=031021
KTDLST( 28)=224255
KTDLST( 29)=204000
KTDLST( 30)=225000
KTDLST( 31)=237000
KTDLST( 32)=001031
KTDLST( 33)=001032
KTDLST( 34)=008024
KTDLST( 35)=101000
KTDLST( 36)=031001
KTDLST( 37)=225255
C
KTDLEN=37
C
C SET DATA DECSRIPTORS
C
C SECTION 1 CONTENT
C
KSEC1(2)=4 ! BUFR EDITION NUMBER
KSEC1(14)=0 ! BUFR MASTER TABLE USED
ksec1(16)=0 ! ORIGINATING SUB-CENTRE
KSEC1(3)=98 ! ORIGINATING CENTRE
KSEC1(8)=1 ! VERSION NUMBER OF LOCAL TABLE USED
KSEC1(15)=12 ! VERSION NUMBER OF MASTER TABLE USED
C
C SECTION 3 CONTENT
C
C
K=1
CALL BUXDES(K,KSEC1,KTDLEN,KTDLST,KDLEN,KDATA,KELEM,
1 KTDEXL,KTDEXP,CNAMES,CUNITS,KERR)
C
END
The output of the expanded data using BUXDES routine is given below.
ECMWF
1 301001
2 301011
3 301012
4 301021
5 107000
6 031001
7 007004
8 008001
9 010003
10 012001
11 012003
12 011003
13 011004
14 224000
15 236000
16 101000
17 031001
18 031031
19 001031
20 001032
21 008023
22 105000
23 031001
24 204002
25 031021
26 204002
27 031021
28 224255
29 204000
30 225000
31 237000
32 001031
33 001032
34 008024
35 101000
36 031001
37 225255
PROGRAM BUFR
C
C**** *BUFR*
C
C
C PURPOSE.
C --------
C An example of using Bufr packing/unpacking software.
C It will create synop data in bufr edition 4
C
C
C** INTERFACE.
C ----------
C
C NONE.
C
C METHOD.
C -------
C
C NONE.
C
C
C EXTERNALS.
C ----------
C
C
C REFERENCE.
C ----------
C
C NONE.
C
C AUTHOR.
C -------
C
C M. DRAGOSAVAC *ECMWF* 05/04/2005.
C
C
C MODIFICATIONS.
C --------------
C
C NONE.
C
C
IMPLICIT LOGICAL(O,G), CHARACTER*8(C,H,Y)
C
C
PARAMETER(JSUP = 9,JSEC0= 3,JSEC1= 40,JSEC2=4096,JSEC3= 4,
1 JSEC4=2,JELEM=320000,JSUBS=400,JCVAL=150 ,JBUFL=512000,
#ifdef JBPW_64
2 JBPW = 64,JTAB =3000,JCTAB=3000,JCTST=3000,JCTEXT=6000,
#else
2 JBPW = 32,JTAB =3000,JCTAB=3000,JCTST=3000,JCTEXT=6000,
#endif
3 JWORK=4096000,JKEY=46, JTMAX=10,JTCLAS=64,JTEL=255)
C
PARAMETER (KDLEN=200,KELEM=4000)
parameter (KVALS=4000,KVALS1=4000)
C
DIMENSION KBUFR(JBUFL)
DIMENSION KSUP(JSUP) ,KSEC0(JSEC0),KSEC1(JSEC1)
DIMENSION KSEC2(JSEC2),KSEC3(JSEC3),KSEC4(JSEC4)
DIMENSION KEY (JKEY)
DIMENSION ISUP(JSUP) ,ISEC0(JSEC0),ISEC1(JSEC1)
DIMENSION ISEC2(JSEC2),ISEC3(JSEC3),ISEC4(JSEC4)
C
#ifndef R_4
REAL*8 VALUES(KVALS),VALUE(KVALS1)
REAL*8 RQV(KELEM)
REAL*8 RVIND
#else
REAL VALUES(KVALS),VALUE(KVALS1)
REAL RQV(KELEM)
REAL RVIND
#endif
DIMENSION KTDLST(KELEM),KTDEXP(KELEM),KRQ(KELEM)
DIMENSION ITDLST(KELEM),ITDEXP(KELEM)
DIMENSION KDATA(KDLEN),IDATA(KDLEN)
C
CHARACTER*8 CF
CHARACTER*64 CNAMES(KELEM),CNAME(KELEM)
CHARACTER*24 CUNITS(KELEM),CUNIT(KELEM)
CHARACTER*80 CVALS(KVALS)
CHARACTER*80 CVAL (KVALS1)
CHARACTER*80 YENC
C
C
C ------------------------------------------------------------------
C* 1. INITIALIZE CONSTANTS AND VARIABLES.
C -----------------------------------
100 CONTINUE
C
C
RVIND=1.7D38
C
CALL PBOPEN(IUNIT1,’synop.bufr’,’W’,IRET)
IF(IRET.EQ.-1) STOP ’OPEN FAILED ON synop.dat’
IF(IRET.EQ.-2) STOP ’INVALID FILE NAME’
IF(IRET.EQ.-3) STOP ’INVALID OPEN MODE SPECIFIED’
C
C
C INITIALIZE DELAYED REPLICATION FACTORS OR REFERENCE VALUES ETD.
C
DO 101 I=1,KDLEN
KDATA(I)=0
VALUES(I)=RVIND
101 CONTINUE
C
KDATA(1)=10
c
KDLENG=3
C
C
C SET DATA DECSRIPTORS
C
ktdlen=70
! Pressure
values( 14)=99 ! 007031 HEIGHT OF BAROMETER ABOVE MEAN SEA LEVEL M
values( 15)=1014. ! 010004 PRESSURE PA
values( 16)=1026.1 ! 010051 PRESSURE REDUCED TO MEAN SEA LEVEL PA
values( 17)=-190. ! 010061 3 HOUR PRESSURE CHANGE PA
values( 18)=7. ! 010063 CHARACTERISTIC OF PRESSURE TENDENCY CODE TABLE 010063
values( 19)=rvind ! 007004 PRESSURE PA
values( 20)=rvind ! 010009 GEOPOTENTIAL HEIGHT GPM
! Temperature data
values( 21)=2. ! 007032 HEIGHT OF SENSOR ABOVE LOCAL GROUND ( OR M
values( 22)=292.6 ! 012101 TEMPERATURE/DRY BULB TEMPERATURE K
values( 23)=288. ! 012103 DEW-POINT TEMPERATURE K
values( 24)=rvind ! 013003 RELATIVE HUMIDITY %
! Visibility data
values( 25)=1. ! 007032 HEIGHT OF SENSOR ABOVE LOCAL GROUND ( OR M
values( 26)=20000 ! 020001 HORIZONTAL VISIBILITY M
! Cloud data
values( 30)=40. ! 020010 CLOUD COVER (TOTAL) %
values( 31)=1. ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 32)=0. ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 33)=8000. ! 020013 HEIGHT OF BASE OF CLOUD M
values( 34)=30. ! 020012 CLOUD TYPE CODE TABLE 020012
values( 35)=20. ! 020012 CLOUD TYPE CODE TABLE 020012
values( 36)=11. ! 020012 CLOUD TYPE CODE TABLE 020012
values( 37)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 38)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 39)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 40)=rvind ! 020013 HEIGHT OF BASE OF CLOUD M
values( 41)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 42)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 43)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 44)=rvind ! 020013 HEIGHT OF BASE OF CLOUD M
values( 45)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 46)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 47)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 48)=rvind ! 020013 HEIGHT OF BASE OF CLOUD M
values( 49)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 50)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 51)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 52)=rvind ! 020013 HEIGHT OF BASE OF CLOUD M
values( 58)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 59)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 60)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 61)=rvind ! 020014 HEIGHT OF TOP OF CLOUD M
values( 62)=rvind ! 020017 CLOUD TOP DESCRIPTION CODE TABLE 020017
values( 63)=rvind ! 008002 VERTICAL SIGNIFICANCE (SURFACE OBSERVATI CODE TABLE 008002
values( 64)=rvind ! 020011 CLOUD AMOUNT CODE TABLE 020011
values( 65)=rvind ! 020012 CLOUD TYPE CODE TABLE 020012
values( 66)=rvind ! 020014 HEIGHT OF TOP OF CLOUD M
values( 67)=rvind ! 020017 CLOUD TOP DESCRIPTION CODE TABLE 020017
! Present weather
values( 71)=2. ! 020003 PRESENT WEATHER CODE TABLE 020003
values( 72)=24. ! 004024 TIME PERIOD OR DISPLACEMENT HOUR
values( 73)=1. ! 020004 PAST WEATHER (1) CODE TABLE 020004
values( 74)=1. ! 020005 PAST WEATHER (2) CODE TABLE 020005
! Evaporation measurements
values( 75)=rvind ! 004024 TIME PERIOD OR DISPLACEMENT HOUR
values( 76)=rvind ! 002004 TYPE OF INSTRUMENTATION FOR EVAPORATION CODE TABLE 002004
values( 77)=rvind ! 013033 EVAPORATION/EVAPOTRANSPIRATION KG/M**2
! Sunshine data
values( 78)=rvind ! 004024 TIME PERIOD OR DISPLACEMENT HOUR
values( 79)=rvind ! 014031 TOTAL SUNSHINE MINUTE
! Radiation data
values( 80)=rvind ! 004025 TIME PERIOD OR DISPLACEMENT MINUTE
values( 81)=rvind ! 014002 LONG-WAVE RADIATION,INTEGRATED OVER PERI J/M**2
values( 82)=rvind ! 014004 SHORT-WAVE RADIATION,INTEGRATED OVER PER J/M**2
values( 83)=rvind ! 014016 NET RADIATION,INTEGRATED OVER PERIOD SPE J/M**2
values( 84)=rvind ! 014028 GLOBAL SOLAR RADIATION INTEGRATED OVERPE J/M**2
values( 85)=rvind ! 014029 DIFFUSE SOLAR RADIATION INTEGRATED OVERP J/M**2
values( 86)=rvind ! 014030 DIRECT SOLAR RADIATION INTEGRATED OVERPE J/M**2
! Precipitation measurements
values( 87)=0. ! 007032 HEIGHT OF SENSOR ABOVE LOCAL GROUND ( OR M
values( 88)=-6 ! 004024 TIME PERIOD OR DISPLACEMENT HOUR
values( 89)=2. ! 013011 TOTAL PRECIPITATION/TOTAL WATER EQUIVALE KG/M**2
! Wind data
values( 98)=10. ! 007032 HEIGHT OF SENSOR ABOVE LOCAL GROUND ( OR M
values( 99)=1. ! 002002 TYPE OF INSTRUMENTATION FOR WIND MEASURE FLAG TABLE 002002
values( 100)=2. ! 008021 TIME SIGNIFICANCE CODE TABLE 008021
values( 101)=-10. ! 004025 TIME PERIOD OR DISPLACEMENT MINUTE
values( 102)=100. ! 011001 WIND DIRECTION DEGREE TRUE
values( 103)=1. ! 011002 WIND SPEED M/S
values( 104)=rvind ! 008021 TIME SIGNIFICANCE CODE TABLE 008021
values( 105)=rvind ! 004025 TIME PERIOD OR DISPLACEMENT MINUTE
values( 106)=rvind ! 011043 MAXIMUM WIND GUST DIRECTION DEGREE TRUE
values( 107)=rvind ! 011041 MAXIMUM WIND SPEED (GUSTS) M/S
values( 108)=rvind ! 004025 TIME PERIOD OR DISPLACEMENT MINUTE
values( 109)=rvind ! 011043 MAXIMUM WIND GUST DIRECTION DEGREE TRUE
values( 110)=rvind ! 011041 MAXIMUM WIND SPEED (GUSTS) M/S
C
C SET CCITTIA5 STATION OR SITE NAME
cvals(1)=’SURCIN’
C
C
C SECTION 0 CONTENT
C
KSEC0(1)=0 ! TOTAL LENGTH OF SECTION 0
KSEC0(2)=0 ! TOTAL LENGTH OF BUFR MESSAGE
KSEC0(3)=4 ! BUFR EDITION NUMBER
C
C SECTION 1 CONTENT
C
KSEC1(1)=22 ! TOTTAL LENGTH OF SECTION 1 ( set to 18 for edition <= 3)
KSEC1(2)=4 ! BUFR EDITION NUMBER
KSEC1(3)=98 ! ORIGINATING CENTRE
KSEC1(4)=1 ! UPDATE SEQUENCE NUMBER
KSEC1(5)=0 !128 ! FLAG (PRESENCE OF SECTION 2)
KSEC1(6)=0 ! BUFR MESSAGE TYPE
KSEC1(7)=1 ! BUFR_MESSAGE SUBTYPE
KSEC1(8)=1 ! VERSION NUMBER OF LOCAL TABLE USED
KSEC1(9)=nint(values(6))
if(KSEC1(2).le.3) then
if(ksec1(9).gt.2000) then
ksec1(9)=ksec1(9)-2000
else
ksec1(9)=ksec1(9)-1900
end if
end if
KSEC1(10)=nint(values(7))
KSEC1(11)=nint(values(8)) ! DAY
KSEC1(12)=nint(values(9)) ! HOUR
KSEC1(13)=nint(values(10)) ! MINUTE
KSEC1(14)=0 ! BUFR MASTER TABLE( ZERO) FOR METEOROLOGICAL DATA)
KSEC1(15)=12 ! VERSION NUMBER OF MASTER TABLE USED
KSEC1(16)=0 ! ORIGINATING SUB-CENTRE
KSEC1(17)=0 ! International sub-category
KSEC1(18)=0 ! Second
C
C SECTION 2 CONTENT
C
KSEC2(1)=52
C
DO 110 I=2,JSEC2
KSEC2(I)=0
110 CONTINUE
C
C SECTION 3 CONTENT
C
KSEC3(1)=0 ! TOTAL LENGTH OF SECTION 3
KSEC3(2)=0 ! RESERVED
KSEC3(3)=1
KSEC3(4)=0 ! 64 FOR COMPRESSION/ 0 MANY SUBSETS
C
IREP=0
C
C
C* 6. PACK BUFR MESSAGE
C -----------------
600 CONTINUE
C
C---------------------------------------------------------------
C This call is not needed for packing. It just
C prints expanded list corresponding to ktdlst sequence
C and delayed replications in kdata array. This four
C lines can be deleted or commented out.
K=1
CALL BUXDES(K,KSEC1,KTDLEN,KTDLST,KDLENG,KDATA,KELEM,
1 KTDEXL,KTDEXP,CNAMES,CUNITS,KERR)
C
IF(KERR.NE.0) CALL EXIT(2)
C---------------------------------------------------------------
C
C
C* 6.2 ENCODE DATA INTO BUFR MESSAGE.
C ------------------------------
620 CONTINUE
C
KBUFL=3000
KPMISS=1
KPRUS=1
NOKEY=0
CALL BUPRQ(KPMISS,KPRUS,NOKEY)
C
KERR=0
CALL BUFREN( KSEC0,KSEC1,KSEC2,KSEC3,KSEC4,
1 KTDLEN,KTDLST,KDLENG,KDATA,KELEM,
2 KVALS,VALUES,CVALS,KBUFL,KBUFR,KERR)
C
IF(KERR.GT.0) THEN
CALL EXIT(2)
ELSEIF(KERR.lt.0) then
print*,’Encoding return_code=’,kerr
END IF
c
ILEN=KBUFL*JBPW/8
C
IERR=0
CALL PBWRITE(IUNIT1,KBUFR,ILEN,IERR)
IF(IERR.LT.0) THEN
PRINT*,’ERROR WRITING INTO TARGET FILE.’
CALL EXIT(2)
END IF
C
C -----------------------------------------------------------------
C* 7. UNPACK MESSAGE.
C -------------
700 CONTINUE
C
DO 702 I=1,KVALS1
VALUE(I)=RVIND
702 CONTINUE
c
701 CONTINUE
C
CALL BUFREX(KBUFL,KBUFR,ISUP,ISEC0 ,ISEC1,ISEC2 ,ISEC3 ,ISEC4,
1 KELEM,CNAME,CUNIT,KVALS1,VALUE,CVAL,IERR)
c
IF(IERR.NE.0) CALL EXIT(2)
C
CALL BUPRS0(ISEC0)
CALL BUPRS1(ISEC1)
CALL BUUKEY(ISEC1,ISEC2,KEY,ISUP,KERR)
CALL BUPRS2(ISUP ,KEY)
ISUBSET=1
CALL BUSEL2(ISUBSET,KELEM,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
1 CUNITS,IERR)
CALL BUPRS3(ISEC3,KTDLEN,KTDLST,KTDEXL,KTDEXP,KELEM,CNAME)
C
WRITE(*,’(a,$)’) ’ STARTING SUBSET TO BE PRINTED : ’
READ(*,’(I5)’) IST
WRITE(*,’(a,$)’) ’ ENDING SUBSET TO BE PRINTED : ’
READ(*,’(I6)’) IEND
C
ICODE=0
CALL BUPRT(ICODE,IST,IEND,KELEM,CNAME,CUNIT,CVAL,
1 KVALS1,VALUE,ISUP,ISEC1,IERR)
C
C
IREP=IREP+1
C
IF(IREP.GT.3) GO TO 900
GO TO 900
C
810 CONTINUE
C
WRITE(*,’(1H ,A)’) ’OPEN ERROR ON INPUT FILE’
GO TO 900
C
800 CONTINUE
C
IF(IERR.EQ.-1) THEN
print*,’Number of records processed ’,IREP
ELSE
print*,’ BUFR : error= ’,ierr
END IF
C
900 CONTINUE
C
STOP
END
PROGRAM DECODE_BUFR_IMAGE
C
C**** *DECODE_BUFR_IMAGE*
C
C
C PURPOSE.
C --------
C Expnds Opera run-length encoded composite images
C and creates image header and image file.
C
C
C** INTERFACE.
C ----------
C
C NONE.
C
C METHOD.
C -------
C
C NONE.
C
C
C EXTERNALS.
C ----------
C
C REFERENCE.
C ----------
C
C NONE.
C
C AUTHOR.
C -------
C
C M. DRAGOSAVAC *ECMWF* 15/07/2008.
C
C
C MODIFICATIONS.
C --------------
C
C NONE.
C
C
IMPLICIT LOGICAL(L,O,G), CHARACTER*8(C,H,Y)
C
PARAMETER(JSUP = 9,JSEC0= 3,JSEC1= 40,JSEC2=4096 ,JSEC3= 4,
1 JSEC4= 2,JELEM=320000,JSUBS=400,JCVAL=150 ,JBUFL=300000,
2 JBPW = 32,JTAB =3000,JCTAB=120,JCTST=1800,JCTEXT=1200,
3 JWORK=4096000,JKEY=46,JBYTE=440000)
C
PARAMETER (KELEM=320000)
PARAMETER (KVALS=4096000)
C
DIMENSION KBUFF(JBUFL)
DIMENSION KBUFR(JBUFL)
DIMENSION KSUP(JSUP) ,KSEC0(JSEC0),KSEC1(JSEC1)
DIMENSION KSEC2(JSEC2),KSEC3(JSEC3),KSEC4(JSEC4)
C
REAL*8 VALUES(KVALS),VALUES_IMG(500)
DIMENSION IMAGE8(522500)
DIMENSION KTDLST(KELEM),KTDEXP(KELEM)
DIMENSION KTDEXP_IMG(KELEM)
C
CHARACTER*256 CF,COUT,CARG(4),COUT1,COUT2,COUT3
CHARACTER*64 CNAMES(KELEM),CNAMES_IMG(KELEM)
CHARACTER*24 CUNITS(KELEM),CUNITS_IMG(KELEM)
CHARACTER*80 CVALS(KELEM),CVALS_IMG(KELEM)
REAL*8 RVIND
C
EQUIVALENCE(IMAGE1,IMAGE2,IMAGE4)
C ------------------------------------------------------------------
C* 1. INITIALIZE CONSTANTS AND VARIABLES.
C -----------------------------------
100 CONTINUE
C
C MISSING VALUE INDICATOR
C
NBYTPW=JBPW/8
RVIND=1.7D38
NVIND=2147483647
IOBS=0
N=0
C
C
C
C GET INPUT AND OUTPUT FILE NAME.
C
NARG=IARGC()
C
C
DO 104 J=1,NARG
CALL GETARG(J,CARG(J))
104 CONTINUE
IF(NARG.EQ.0) THEN
PRINT*,’USAGE -- decode_bufr_image infile’
STOP
END IF
C
DO 101 II=1,NARG
CF=CARG(II)
ILN=INDEX(CF,’ ’)-1
C
C* 1.2 OPEN FILE CONTAINING BUFR DATA.
C -------------------------------
120 CONTINUE
C
IRET=0
CALL PBOPEN(IUNIT,CF(1:ILN),’R’,IRET)
IF(IRET.EQ.-1) STOP ’OPEN FAILED’
IF(IRET.EQ.-2) STOP ’INVALID FILE NAME’
IF(IRET.EQ.-3) STOP ’INVALID OPEN MODE SPECIFIED’
C
COUT1=CF(1:ILN-5)//’.img’
ILN1=INDEX(COUT1,’ ’)-1
CALL PBOPEN(IUNIT1,COUT1(1:ILN1),’W’,IRET)
IF(IRET.EQ.-1) STOP ’OPEN FAILED ON *.img file’
IF(IRET.EQ.-2) STOP ’INVALID FILE NAME’
IF(IRET.EQ.-3) STOP ’INVALID OPEN MODE SPECIFIED’
C
COUT2=CF(1:ILN-5)//’.img_header’
ILN2=INDEX(COUT2,’ ’)-1
IUNIT2=40
OPEN(UNIT=IUNIT2,FILE=COUT2(1:ILN2),STATUS=’UNKNOWN’,IOSTAT=ios)
IF(IOS.NE.0) THEN
PRINT*,’Open error on ’,COUT2(1:ILN2)
STOP
END IF
C
COUT3=CF(1:ILN-5)//’.section_1’
ILN3=INDEX(COUT3,’ ’)-1
IUNIT3=41
OPEN(UNIT=IUNIT3,FILE=COUT3(1:ILN3),STATUS=’UNKNOWN’,IOSTAT=ios)
IF(IOS.NE.0) THEN
PRINT*,’Open error on ’,COUT3(1:ILN3)
STOP
END IF
C
C -----------------------------------------------------------------
C
C* 3. READ BUFR MESSAGE.
C ------------------
300 CONTINUE
C
IERR=0
KBUFL=0
C
CALL PBBUFR(IUNIT,KBUFF,JBYTE*4,KBUFL,IERR)
IF(IERR.EQ.-1) THEN
PRINT*,’NUMBER OF SUBSETS ’,IOBS
PRINT*,’NUMBER OF MESSAGES ’,N
STOP ’EOF’
END IF
IF(IERR.EQ.-2) STOP ’FILE HANDLING PROBLEM’
IF(IERR.EQ.-3) STOP ’ARRAY TOO SMALL FOR PRODUCT’
C
N=N+1
PRINT*,’----------------------------------’,N,’ ’,KBUFL
KBUFL=KBUFL/NBYTPW+1
C
C -----------------------------------------------------------------
C* 4. EXPAND BUFR MESSAGE.
C --------------------
400 CONTINUE
C
CALL BUS0123( KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KSEC3,IERR)
IF(IERR.NE.0) THEN
PRINT*,’ERROR IN BUS012: ’,IERR
PRINT*,’ BUFR MESSAGE NUMBER ’,N,’ CORRUPTED.’
IERR=0
GO TO 300
END IF
C
KEL=KVALS/KSEC3(3)
IF(KEL.GT.KELEM) KEL=KELEM
C
CALL BUFREX(KBUFL,KBUFF,KSUP,KSEC0 ,KSEC1,KSEC2 ,KSEC3 ,KSEC4,
1 KEL,CNAMES,CUNITS,KVALS,VALUES,CVALS,IERR)
C
IF(IERR.NE.0) THEN
CALL EXIT(2)
END IF
C
IOBS=IOBS+KSEC3(3)
C
C
ISUBSET=1
CALL BUSEL2(ISUBSET,KEL,KTDLEN,KTDLST,KTDEXL,KTDEXP,CNAMES,
1 CUNITS,IERR)
C IF(IERR.NE.0) CALL EXIT(2)
C
C Get full image as array of pixel values
CALL BUGET_OPERA_IMAGE(KSEC1,KTDEXL,KTDEXP,CNAMES,CUNITS,
1 KELEM,KVALS,VALUES,CVALS,KTDEXL_IMG,KTDEXP_IMG,
2 CNAMES_IMG,CUNITS_IMG,KVALS_IMG,VALUES_IMG,
3 CVALS_IMG,KSIZE_IMG_BYTES,IMAGE8,KPIXEL_SIZE,KERR)
c
c
C
C Write image meta data into file
C -------------------------------
DO I=1,KTDEXL_IMG
WRITE(IUNIT2,’(I6,1X,A64,1x,F20.8,1x,a24)’) I,CNAMES_IMG(I),
c VALUES_IMG(I),CUNITS_IMG(I)
END DO
C
C Write bufr section 1 into file
C ------------------------------
CALL BBUPRS1(IUNIT3,KSEC1)
imx=KSIZE_IMG_BYTES
c print*,’printing bytes=’,imx
C
C Write image ( pixel values ) into file
C -----------------------------------------------------------------
CALL PBWRITE(IUNIT1,IMAGE8,imx,IERR)
C
C
GO TO 900
C -----------------------------------------------------------------
C
810 CONTINUE
C
WRITE(*,’(1H ,A)’) ’OPEN ERROR ON INPUT FILE’
GO TO 900
C
800 CONTINUE
C
IF(IRET.EQ.-1) THEN
PRINT*,’NUMBER OF RECORDS PROCESSED ’,N
PRINT*,’NUMBER OF OBSERVATIONS ’,IOBS
ELSE
PRINT*,’ BUFR : ERROR= ’,IERR
END IF
C
900 CONTINUE
C
CALL PBCLOSE(IUNIT,IRET)
CALL PBCLOSE(IUNIT1,IRET)
CLOSE(IUNIT2)
CLOSE(IUNIT3)
101 CONTINUE
C
END
#include "stdio.h"
#include "stdlib.h"
FILE *fp;
char bufr_message[15000];
char filename[256];
long int length=15000;
long int status;
int Nbpw;
int i;
long kelem = KELEM,kvals = KVALS;
char cvals[KVALS][80];
float values[KVALS],vals[KVALS];
long icode = 0;
long ktdlst[KELEM],ktdexp[KELEM],ktdlen,ktdexl;
if(sizeof(long) == 4) Nbpw=32;
else if(sizeof(long) == 8) Nbpw=64;
else{
printf("Abort.....\n");
}
printf("%d\n",Nbpw);
if(argc != 3) {
printf("%c",argc);
if(!strcmp(argv[1],"-i")) strcpy(filename,argv[2]);
else {
printf("Usage: bufr_decode -i infile \n");
exit(1);
}
if (ksup[5] > 1)
kelem = kvals/ksup[5];
else
kelem = KELEM;
buukey_(ksec1,ksec2,key,ksup,&kerr);
busel_(&ktdlen,ktdlst,&ktdexl,ktdexp,&kerr);
buprs3_(ksec3,&ktdlen,ktdlst,&ktdexl,ktdexp,&kelem,(char **)cnames);
icode = 0;
long current_ss;
current_ss = 1;
buprt_(&icode,¤t_ss,¤t_ss,&kelem,(char **)cnames,
(char **)cunits,(char **)cvals,
&kvals,values,ksup,ksec1,&kerr);
return kerr;
ECMWF
1 301090
2 008010
3 301091
4 302001
5 007004
6 010009
7 302072
8 101005
9 307063
10 302069
11 007032
12 007033
13 020031
14 020032
15 002038
16 022043
17 302021
18 302078
19 302073
20 302074
21 302075
22 004025
23 302076
24 302071
25 302077
26 007033
27 302079
28 007032
29 302080
30 302081
31 302082
32 004025
33 013059
BUFR SECTION 0
BUFR SECTION 1
BUFR SECTION 3
1 307080
ECMWF
BUFR SECTION 0
BUFR SECTION 1
BUFR SECTION 3
1 001003
2 001020
3 001005
4 002001
5 002036
6 002149
7 301011
8 301012
9 008021
10 301011
11 301012
12 008021
13 301021
14 027004
15 028004
16 007030
17 001051
18 002148
19 001012
20 001014
21 002040
22 033022
23 033023
24 033027
25 022063
26 302021
27 302022
28 302023
29 008081
30 025026
31 008081
32 025026
33 008081
34 025026
35 008081
36 002034
37 022060
38 007070
39 002190
40 025086
41 002035
42 002168
43 020031
44 002038
45 306004
46 002030
47 306005
48 007031
49 008081
50 012064
51 302001
52 008081
53 007032
54 007033
55 012101
56 012103
57 013003
58 007032
59 007033
60 008082
61 007033
62 002169
63 002002
64 008021
65 004025
66 011001
67 011002
68 008021
69 004025
70 011043
71 011041
72 008082
73 007033
74 007032
75 004024
76 013011
77 007032
78 008021
79 004024
80 014021
81 008021
82 025028
83 025028
84 025028
ECMWF
1 301090
2 004023
3 008023
4 010004
5 010051
6 007004
7 010009
8 007032
9 012101
10 002051
11 004051
12 012118
13 004052
14 012119
15 013004
16 008023
17 012151
18 007032
19 102005
20 008050
21 008020
22 014032
23 014033
24 008050
25 008020
26 102018
27 008052
28 008022
29 007032
30 008053
31 004003
32 012152
33 008053
34 004003
35 012153
36 008053
37 004003
38 008023
39 012101
40 008053
41 004003
42 008023
43 012101
44 008023
45 007032
46 002002
47 008053
48 004003
49 011046
50 008053
51 004003
52 004004
53 004023
54 007032
55 013060
56 013051
57 004053
58 008050
59 008020
60 102006
61 008052
62 008022
63 008053
64 004003
65 013052
66 007032
67 004001
68 004001
69 004002
70 004003
71 004004
72 004022
73 008023
74 010004
75 010051
76 007004
77 010009
78 007032
79 012101
80 002051
81 004051
82 012118
83 004052
84 012119
85 013004
86 012151
87 007032
88 014032
89 008023
90 004001
91 004001
92 004002
93 004003
94 004004
95 004022
96 007032
97 008023
98 013060
99 004053
100 008023
101 102006
102 008050
103 008020
ECMWF
1 301001
2 301011
3 301012
4 001007
5 001033
6 025150
7 122000
8 031001
9 001027
10 019150
11 019106
12 008005
13 005002
14 006002
15 008005
16 019107
17 019005
18 019006
19 019108
20 019109
21 019110
22 019111
23 019112
24 019113
25 019114
26 019115
27 019116
28 019117
29 019118
30 019119
4 004002 MONTH
5 004003 DAY
6 004004 HOUR
7 004005 MINUTE
8 001007 SATELLITE IDENTIFIER
9 001033 IDENTIFICATION OF ORIGINATING/GENERATING CENTRE
10 025150 SATELLITE INTENSITY ANALYSIS METHOD OF TROPICAL CYCLONE
11 031001 DELAYED DESCRIPTOR REPLICATION FACTOR
12 001027 WMO LONG STORM NAME
13 019150 TYPHOON INTERNATIONAL COMMON NUMBER (TYPHOON COMMITTEE)
14 019106 IDENTIFICATION NUMBER OF TROPICAL CYCLONE
15 008005 METEOROLOGICAL ATTRIBUTE SIGNIFICANCE
16 005002 LATITUDE (COARSE ACCURACY)
17 006002 LONGITUDE (COARSE ACCURACY)
18 008005 METEOROLOGICAL ATTRIBUTE SIGNIFICANCE
19 019107 TIME INTERVAL OF THE TROPICAL CYCLONE ANALYSIS
20 019005 DIRECTION OF MOTION OF FEATURE
21 019006 SPEED OF MOTION OF FEATURE
22 019108 ACCURACY OF GEOGRAPHICAL POSITION OF THE TROPICAL CYCLONE
23 019109 MEAN DIAMETER OF THE OVERCAST CLOUD OF THE TROPICAL CYCLONE
24 019110 APPARENT 24-HOUR CHANGE IN INTENSITY OF TROPICAL CYCLONE
25 019111 CURRENT INTENSITY (CI) NUMBER OF THE TROPICAL CYCLONE
26 019112 DATA TROPICAL (DT) NUMBER OF TROPICAL CYCLONES
27 019113 CLOUD PATTERN TYPE OF DT-NUMBER
28 019114 MODEL EXPECTED TROPICAL CYCLONE (MET) number of THE TROPICAL CYC
29 019115 TREND OF PAST 24-HOUR CHANGE (+: DEVELOPED,-:WEAKENED)
30 019116 PATTERN PROPICAL (PT) NUMBER OF THE TROPICAL CYCLONE
31 019117 CLOUDE PICTURE TYPE OF THE PT-NUMBER
32 019118 FINAL TROPICAL (T) NUMBER OF THE TROPICAL CYCLONE
33 019119 TYPE OF THE FINAL T-NUMBER
1 309052
42 007004 PRESSURE
43 010009 GEOPOTENTIAL HEIGHT
44 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
45 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
46 012101 TEMPERATURE/DRY-BULB TEMPERATURE
47 012103 DEW-POINT TEMPERATURE
48 011001 WIND DIRECTION
49 011002 WIND SPEED
50 004086 LONG TIME PERIOD OR DISPLACEMENT
51 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
52 007004 PRESSURE
53 010009 GEOPOTENTIAL HEIGHT
54 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
55 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
56 012101 TEMPERATURE/DRY-BULB TEMPERATURE
57 012103 DEW-POINT TEMPERATURE
58 011001 WIND DIRECTION
59 011002 WIND SPEED
60 004086 LONG TIME PERIOD OR DISPLACEMENT
61 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
62 007004 PRESSURE
63 010009 GEOPOTENTIAL HEIGHT
64 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
65 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
66 012101 TEMPERATURE/DRY-BULB TEMPERATURE
67 012103 DEW-POINT TEMPERATURE
68 011001 WIND DIRECTION
69 011002 WIND SPEED
70 004086 LONG TIME PERIOD OR DISPLACEMENT
71 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
72 007004 PRESSURE
73 010009 GEOPOTENTIAL HEIGHT
74 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
75 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
76 012101 TEMPERATURE/DRY-BULB TEMPERATURE
77 012103 DEW-POINT TEMPERATURE
78 011001 WIND DIRECTION
79 011002 WIND SPEED
80 004086 LONG TIME PERIOD OR DISPLACEMENT
81 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
82 007004 PRESSURE
83 010009 GEOPOTENTIAL HEIGHT
84 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
85 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
86 012101 TEMPERATURE/DRY-BULB TEMPERATURE
87 012103 DEW-POINT TEMPERATURE
88 011001 WIND DIRECTION
89 011002 WIND SPEED
90 004086 LONG TIME PERIOD OR DISPLACEMENT
91 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
92 007004 PRESSURE
93 010009 GEOPOTENTIAL HEIGHT
94 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
95 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
96 012101 TEMPERATURE/DRY-BULB TEMPERATURE
97 012103 DEW-POINT TEMPERATURE
98 011001 WIND DIRECTION
99 011002 WIND SPEED
100 004086 LONG TIME PERIOD OR DISPLACEMENT
101 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
102 007004 PRESSURE
103 010009 GEOPOTENTIAL HEIGHT
104 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
105 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
106 012101 TEMPERATURE/DRY-BULB TEMPERATURE
107 012103 DEW-POINT TEMPERATURE
108 011001 WIND DIRECTION
109 011002 WIND SPEED
110 004086 LONG TIME PERIOD OR DISPLACEMENT
111 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
112 007004 PRESSURE
113 010009 GEOPOTENTIAL HEIGHT
114 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
115 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
116 012101 TEMPERATURE/DRY-BULB TEMPERATURE
117 012103 DEW-POINT TEMPERATURE
118 011001 WIND DIRECTION
119 011002 WIND SPEED
120 004086 LONG TIME PERIOD OR DISPLACEMENT
121 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
122 007004 PRESSURE
123 010009 GEOPOTENTIAL HEIGHT
124 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)
125 006015 LONGITUDE DISPLACEMENT (HIGH ACCURACY)
126 012101 TEMPERATURE/DRY-BULB TEMPERATURE
127 012103 DEW-POINT TEMPERATURE
128 011001 WIND DIRECTION
129 011002 WIND SPEED
130 004086 LONG TIME PERIOD OR DISPLACEMENT
131 008042 EXTENDED VERTICAL SOUNDING SIGNIFICANCE
132 007004 PRESSURE
133 010009 GEOPOTENTIAL HEIGHT
134 005015 LATITUDE DISPLACEMENT (HIGH ACCURACY)