The first program I sent out wasn't what I intended, since there were a
couple of typos, but what I said still applies. I meant to sent out...
PROGRAM test_rewind_prog
IMPLICIT NONE
INTEGER, PARAMETER :: unit=20
INTEGER :: record_1, record_2
INTEGER :: n_records
INTEGER :: dummy
! Initialise
record_1=1
record_2=2
n_records=2
dummy=0
! Write to file
OPEN(&
& UNIT=unit,&
& FILE="test_rewind_prog.dat", &
& FORM='UNFORMATTED',&
& ACCESS='SEQUENTIAL',&
& ACTION='WRITE',&
& STATUS='REPLACE'&
& )
WRITE(UNIT=unit) dummy
WRITE(UNIT=unit) record_1
WRITE(UNIT=unit) record_2
REWIND(UNIT=unit)
WRITE(UNIT=unit) n_records
CLOSE(UNIT=unit)
! Zero
record_1=0
record_2=0
n_records=0
! Read from file
OPEN(&
& UNIT=unit,&
& FILE="test_rewind_prog.dat", &
& FORM='UNFORMATTED',&
& ACCESS='SEQUENTIAL',&
& ACTION='READ',&
& STATUS='OLD'&
& )
READ(UNIT=unit) n_records
! Get an end of file error on this line
READ(UNIT=unit) record_1
READ(UNIT=unit) record_2
CLOSE(UNIT=unit)
! Print to screen
PRINT *,n_records,record_1,record_2
END PROGRAM test_rewind_prog
Paul
|