opening direct access file for binary data

I’m trying to dump a binary file to disk (consisting of real*4 data values)
and the open statement below gives me an error. Can somebody please
tell me what I’m doing wrong and what the correct statement should be?
Is it anything to do with the record length (recl) specifier, as everything else seems to be standard.

Thanks,

Catherine

PROGRAM DUMP_BIN

IMPLICIT NONE

INTEGER, PARAMETER :: NDATA=132
REAL*4, DIMENSION(NDATA) :: VALUES
INTEGER :: I

open(10,file=‘test.bin’,form=‘unformatted’,access=‘direct’, &
recl=ndata*4,action=‘write’,status=‘replace’,err=100)

do i = 1,ndata
values(i) = i
end do

write(10,rec=1,err=101) (values(i),i=1,ndata)

close(10)

100 STOP ‘PROBLEM OPENING FILE’
101 STOP ‘PROBLEM WRITING FILE’

STOP
END PROGRAM DUMP_BIN

Hi Catherine,

The last STOP needs to move to right after close(10) statement before your 100 and 101 labels.

Hongyon

Ah, that’s a stupid mistake. However, the code still doesn’t work.
I get a binary file filled with zeroes. Is there something peculiar
to how the Portland Group compilers handle writing direct-access
unformatted binary files? This code works fine with the SGI compilers.

Thanks for any hints,

Catherine

Hi Catherine,

You code works for me. How do you read a binary file? I wrote a another program to read from that file and it gets correct input. Try write a program to read and print output on screen.

Hongyon