NCEP Home > NCO Home > Systems Integration Branch > Decoders > BUFRLIB > BUFRLIB Table of Contents > CWORDSH|
Printer Friendly Version
The NCEP cwordsh utility
At its most basic level, a BUFR file is just a stream of bits encoded
according to a set of rules as spelled out within
WMO Manual #306
More to the point, this type of file structure is not very conducive to
interaction with standard FORTRAN, which is the language in which the the BUFRLIB software
is written, because standard
FORTRAN, unlike certain other programming languages such as C and C++,
does not have the capability to read or write data to or from a system file as a pure
binary stream of bits. And, while it's true that some vendors of FORTRAN
compilers do provide their own non-standard extensions to allow such a
capability, this is by no means universal across all of the many available
UNIX platforms in existence today. This dilemna is the primary reason why the
BUFRLIB software leaves the actual FORTRAN "OPEN" of BUFR files up to each
individual application program, because the "OPEN" statement is where a file's
organization and access mode (via the "FORM=" attribute) are specified; thus,
users who are fortunate enough to be operating on a platform which provides
the capability to access a file as a binary stream can easily do so for their
BUFR files when using the BUFRLIB software. The question, then, is what can
the rest of us, for whom the best available option in standard FORTRAN is
often the FORM='UNFORMATTED' access mode, do to get around this problem?
We could, of course, use the available BUFRLIB subroutines
in order to read/write BUFR messages directly from/to an array in FORTRAN
memory, which could then be redirected to a C function in order to actually
interact with the local filesystem, but this approach leads to a loss of
overall flexibility in how application programs can interface with the
BUFRLIB software. Instead, the better (and more portable!) solution is to
use a separate utility that can translate back-and-forth between a pure BUFR file
and one that contains FORTRAN-blocking information, and which can thus be
interfaced to the BUFRLIB software via the universally-supported FORM='UNFORMATTED' access mode!
By making use of such a utility, an application program that writes BUFR
messages directly to a file (via, e.g., subroutine WRITSB) can use the
FORM='UNFORMATTED' attribute in the FORTRAN "OPEN" statement for that file
and then, subsequently, remove the FORTRAN-blocking information
generated by that attribute and thereby obtain a pure, unblocked BUFR bit stream.
Likewise, an application program that wished to directly read a pure,
unblocked BUFR file (via, e.g., subroutine
READMG) could first FORTRAN-block
the file using this special utility, and then the subsequent use of
FORM='UNFORMATTED' would allow that file to be read by the BUFRLIB software.
Thankfully, such a utility does exist, and its name is
To use the cwordsh utility, it must first be compiled on the platform on
which it is to be run, and this obviously should be the same platform upon
which the application program is run which uses the BUFRLIB software in
order to read or write the related BUFR file.
In addition, note that, while cwordsh is not itself directly a part of
BUFRLIB, it does make use of several BUFRLIB subroutines, and
therefore the BUFRLIB software must have already been compiled at the time
that cwordsh is compiled so that it can be object-linked during the
compilation. However, once this is done, we now have a utility that can
alternately FORTRAN-block and unblock BUFR files that are created using
the BUFRLIB software!
The NCEP cwordsh utility is freely available, subject to the terms of the
usual NWS disclaimer,
and is downloadable as a tarfile cwordsh.tar.
After downloading and unpacking (via "tar xvf") this tarfile,
read and follow the instructions in the extracted file
"README_cwordsh" in order to compile and run the utility.