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

Binary Files in Compaq Visual Fortran

g_krishnan1
Beginner
591 Views
Hi
I am trying to write & read integers into a binary file. The field size varies for the variables. The write statement syntax belowseems to work fine
OPEN (4, FILE = "Bin", ACTION = "WRITE", FORM = "BINARY", &
ACCESS = "SEQUENTIAL", STATUS = "UNKNOWN" )
WRITE(4) AREA(I),STRESS(I)
But I am unable to read the file I write. I have tried closing & reopening & also rewinding. Any help is appretiated
Thanks
GK
0 Kudos
2 Replies
davidgraham
Beginner
591 Views

I used the following statements to write :-

open (55,file=cgbf,access='DIRECT',form='BINARY',recl=1)

write (55,rec=1) itype,ifc,ibyte,biatch,goe,gon
write (55,rec=55) e0,n0,e9,n9

close (55)

Note the variables itype, ifc, ibyte etc are all different sizes - int2, int4, real4 & real 8, you just need to keep track of the current location.

Then to read I use the opposite :-

open (55,file=cgbf,access='DIRECT',form='BINARY',recl=1)

read (55,rec=1) itype,ifc,ibyte,biatch,goe,gon
read (55,rec=55) e0,n0,e9,n9

close (55)

Therefore I would think

OPEN (4, FILE = "Bin",FORM = "BINARY",ACCESS = "DIRECT", RECL=1 )
WRITE(4,rec=1) AREA(I),STRESS(I)
should work
0 Kudos
g_krishnan1
Beginner
591 Views

Thaks for the tip. It worked

Cheers

GK

0 Kudos
Reply