Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Reading different byte size data

min_c_shim
Beginner
381 Views
Hi,

I just started using Fortran and I couldn't find information I needed online.
I am trying to read binary data. The file contains mixed 4 and 8 bytes of data.
What's the most efficient way to read different sizes of data?

Thanks,
Min
0 Kudos
1 Reply
Steven_L_Intel1
Employee
382 Views
If you open the file with FORM='BINARY', you can use unformatted reads with the appropriate sized variables and it will just transfer the data directly as a byte stream. This is a non-standard extension in Intel Fortran.

For example:

integer(4) i4(10)
integer(8) i8(10)
open (unit=1,file='foo.dat',form='binary')
read (1) i4,i8

This reads 10 4-byte values and then 10 8-byte values.

Message Edited by Steve_Lionel on 06-20-2006 09:06 PM

0 Kudos
Reply