Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

big endian unsigned 16 bit integers


dear all,

i'm using fortran to read a grid of 16 bit integers written to a big endian file.  i can't figure out what i'm doing incorrectly.

the output values are -9999

        program readdat

c       program to try to read the binary SNODAS data

c       The grid for the masked data files is 6,935 columns by 3,351 rows

        parameter(jdim=3531, idim=6935)

        integer*2 iswe(idim,jdim)




     +    ,CONVERT='BIG_ENDIAN',recl=2)

c       read in the data

        do i=1,idim

          do j=1,1

            read(11,rec=2) iswe(i,j)


          end do

        end do


can someone please advice me what is wrong with this code?  i've tried all sorts of variations and i haven't hit on the correct one yet.

thank you in advance.


0 Kudos
1 Reply
Black Belt

There are two likely sources of error, depending on what your intentions were w.r.t. what to read.

1. You open the file with RECL=2. If you specified the compiler option /assume:byterecl, you would have specified the record length as 2 bytes, which is probably what you want. By default, without that option, the unit for record length is 4 bytes, so RECL=2 would imply a record length of 8 bytes, which is probably not what you want.

2. The statement

read(11,rec=2) iswe(i,j)

will read a single record, namely, the 2nd record, into all the array elements  referenced in the double DO loop. This is probably not what you wanted, so you need to specify a record number that is matched to the (i,j) indices. You would need to know the structure of the SNODAS data files to decide what that correspondence should be.