[gradsusr] problems with non-floating point binary data

David Lorenz dlorenz at wisc.edu
Tue Jan 18 16:12:03 EST 2011


Hi,

This post concerns how GrADS handles non-floating point binary data (for example, a data file with 2 byte integers). One tells GrADS that the data is non-standard with the units field of the control file. For example:

VARS 1
variable   0 -1,40,2,-1 
ENDVARS

tells GrADS that "variable" is store as a signed 2-byte integer (see http://www.iges.org/grads/gadoc/descriptorfile.html#VARS).


I'm using GrADS v2.0.a8 on an intel mac, and there appear to be some errors in how GrADS implements the above features: 

First, GrADS assumes the wrong endianness of the signed and unsigned 2-byte integers. For example, when I create a file of LITTLE endian 2-byte integers on my machine, GrADS will not read the data correctly unless I specify "OPTIONS  big_endian" in the control file.
 
Second, GrADS assumes all previous variables are stored with the same number of bytes as the current variable when finding position in file to get data. For example, suppose I create a small ".dat" file with a single 2 byte integer and then a single 4 byte integer. When I try to read the 4 byte integer in GrADS I get a "Low Level I/O Error:  Read error on data file", because GrADS looks in bytes number 5 through 8 in the file instead of looking at bytes number 3 through 6.

The above errors can be reproduced with the fortran code and the 2 control files at the bottom of this message. 

When I open the file case1.ctl in GrADS:
GrADS reads the variable "i4" correctly, but "i2" is read in as 256 instead of 10 because: 1) the variable "i2" is assumed to be in bytes 3 to 4 of the file instead of bytes 5 to 6. This error in isolation would mean GrADS reads in the number 1 instead of 10. 2) 2 byte integers are read in with the wrong endianess, which changes the 1 to a 256.

When I open the file case2.ctl in GrADS:
GrADS reads the variable "i2" as 2560 instead of 10 (2560 is 10 in the opposite endianess). GrADS gives "Low Level I/O Error:  Read error on data file", when I try to read the variable i4 because it doesn't take into account that the previous variable, "i2", is a smaller variable type.

-Dave

-----------------
Fortran program:
-----------------

program case

  integer*2 :: i2
  integer :: i4

  i2 = 10
  i4 = 2 + 1*256*256 ! = 65538

  open(1,file='case1.dat',access='stream',form='unformatted')
  write(1) i4
  write(1) i2
  close(1)

  open(1,file='case2.dat',access='stream',form='unformatted')
  write(1) i2
  write(1) i4
  close(1)

end program case

------------------
Two control Files:
------------------

DSET  ^case1.dat
UNDEF -99.
XDEF 1 LINEAR 0 1
YDEF 1 LINEAR 0 1
ZDEF 1 LINEAR 0 1
TDEF 1 LINEAR 1jan1950 1dy
VARS 2
i4   0 -1,40,4       4_byte_integer
i2   0 -1,40,2,-1    signed_2_byte_integer
ENDVARS

DSET  ^case2.dat
UNDEF -99.
XDEF 1 LINEAR 0 1
YDEF 1 LINEAR 0 1
ZDEF 1 LINEAR 0 1
TDEF 1 LINEAR 1jan1950 1dy
VARS 2
i2   0 -1,40,2,-1    signed_2_byte_integer
i4   0 -1,40,4       4_byte_integer
ENDVARS




More information about the gradsusr mailing list