Issues with reading PREPBUFR and BUFR radiance data with gfortran and intel compilers

Symptoms

WRFDA compiled with gfotran or ifort will get the following error message when trying to read the file unblocked and re-blocked by the "cwordsh" program

**************BUFR ARCHIVE LIBRARY ABORT*****************
BUFRLIB: OPENBF - ERROR READING INPUT FILE CONNECTED TO UNIT 26 WHEN
CHECKING FOR 'BUFR' IN FIRST 4 BYTES OF RECORD
**************BUFR ARCHIVE LIBRARY ABORT*****************

For WRFDA v3.2.1 or eariler: Adding convert='little_endian' to the open statement

1. da/da_obs_io/da_read_obs_bufr.inc

At the section "bufrfile:", add convert='little_endian' to the open statement

open(unit = iunit, FILE = trim(filename), &
iostat = iost, form = 'unformatted', STATUS = 'OLD' &
convert='little_endian')

2. da/da_radiance/da_read_obs_bufrairs.inc

At the section "Open BUFR file" , add convert='little_endian' to the open statement

open(unit = lnbufr, FILE = trim(infile), &
form = 'unformatted', iostat = iost, &
convert='little_endian')

3. da/da_radiance/da_read_obs_bufrtovs.inc

At the section "! 0.0 Open unit to satellite bufr file and read file header", add convert='little_endian' to the open statement

open(unit = lnbufr, FILE = trim(infile), &
form = 'unformatted', iostat = iost, status = 'old', &
convert='little_endian')

4. da/da_radiance/da_read_obs_bufrssmis.inc

At the section "! 0.0 Open unit to satellite bufr file and read file header", add convert='little_endian' to the open statement

open(unit = lnbufr, FILE = trim(infile), &
form = 'unformatted', iostat = iost, status = 'old', &
convert='little_endian')

5. da/da_obs_io/da_read_obs_bufrgpsro.inc

At the section "! open file " add convert='little_endian' to the open statement

open(unit = iunit, FILE = trim(filename), &
iostat = iost, form = 'unformatted', STATUS ='OLD' , &
convert='little_endian')

Side effect: After the modification, the code will work just for gfortran and ifort compilers

For WRFDA 3.3 or later : Set environment variable

GFORTRAN_CONVERT_UNIT (Gfortran) and F_UFMTENDIAN (ifort) environment variables will override the CONVERT specifier in the open statement. It just needs to reserve and fix the units used to open bufr file by the following files. It is not necessary to amend the open statement for different compilers.

For Csh

gfortran: setenv GFORTRAN_CONVERT_UNIT "little_endian:94-99"
ifort: setenv F_UFMTENDIAN "little:94-99"

For Bash

gfortran: export GFORTRAN_CONVERT_UNIT="little_endian:94-99"
ifort: export F_UFMTENDIAN="little:94-99"

Side effect: In order not to interfere with other applications, it's better to unset the environment
variable after da_wrfvar.exe is completed.

For the reblocking utility, reblock.c writen by Baoyu YIN is recommended.
(http://www.math.ucdavis.edu/~cheung/PROJECTS/DAO_Projects/halem/iret/reblock.c)
It reads a blocked BUFR file, byteswap the f77 control words and
writes out the file directly, no bufrlib is needed.