This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Problem reading unformated file and using ERR=
- From: Brooks Moses <brooks dot moses at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: Chris Talley <cst at cfdrc dot com>
- Date: Tue, 28 Nov 2006 13:44:38 -0800
- Subject: Re: Problem reading unformated file and using ERR=
- Organization: Stanford University
- References: <AC07C03C-05FA-4ECD-99A6-35F3BD7CFA05@cfdrc.com>
Chris Talley wrote:
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.
This is a bug; I've filed it as PR 30010.
However, I think it's worth noting that "end-of-record condition" is
only a concept that applies to formatted files. What you have here is
an unformatted record with an insufficient number of elements in it,
which is an "error condition".
(Incidentally, note that on a formatted file, an end-of-record condition
is not an error condition, and if you specify ERR= but not EOR=, the
program should terminate; see the last paragraph of section 9.4.3 of the
F95 standard.)
- Brooks