This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Problem reading unformated file and using ERR=
- From: Chris Talley <cst at cfdrc dot com>
- To: fortran at gcc dot gnu dot org
- Date: Tue, 28 Nov 2006 14:06:20 -0600
- Subject: Problem reading unformated file and using ERR=
I've been helping a co-worker attempt to compile and run a legacy CFD
code using gfortran from the 4.2-20061031 (prerelease) build. When
reading an unformatted sequential file, the CFD code uses a statement
as follows:
READ(1,ERR=10,END=100) I,J,K
The original intent of the ERR specifier was to jump to label 10 if
an end-of-record occurred before all the requested data was read.
This works as intended using the NAG F95 compiler; however, using
gfortran the code jumps to label 100. If the END=100 specifier is
remove, gfortran gives a runtime end-of-file error. Is this a bug or
am I doing something wrong? Below is a test program and its resulting
output.
program test3
IMPLICIT NONE
INTEGER :: I,J,K
I=1
J=2
K=3
OPEN(1,FILE='test3.dat',STATUS='NEW',FORM='UNFORMATTED',
& ACTION='WRITE')
WRITE(1) I
WRITE(1) I, J, K
WRITE(1) I, J, K
CLOSE(1)
OPEN(1,FILE='test3.dat',STATUS='OLD',FORM='UNFORMATTED',
& ACTION='READ')
print*, "before read err=10"
READ(1,ERR=10) I,J,K
print*, "after read err=10"
10 CONTINUE
print*, "after 10 continue "
print*," I = ", I
print*," J = ", J
print*," K = ", K
END PROGRAM
>gfortran -g test6.f
>rm test3.dat
>./a.out
before read err=10
At line 18 of file test6.f
Fortran runtime error: End of file
I appreciate any help you can give me in resolving this issue.
Thanks,
Chris Talley