------- Comment #6 from sgk at troutmask dot apl dot washington dot edu 2007-03-06 15:53 ------- Subject: Re: Bad IOSTAT values when readings NAMELISTs past EOF
On Tue, Mar 06, 2007 at 08:20:23AM -0000, anlauf at gmx dot de wrote: > > > ------- Comment #3 from anlauf at gmx dot de 2007-03-06 08:20 ------- > (In reply to comment #2) > > The value 5008 is listed in libgfortran.h as ERROR_ENDFILE. The > > -1 corresponds to ERROR_END. So, the return value of 5008 is > > telling you that you are trying to (initiate a?) read beyond > > the end of the file, which you admit to doing. > > I actually do not want to read beyond the end of file, > I want gfortran to stay at the end of the file when trying to > read the next record or namelist. > > All other compilers I have checked (xlf, ifort 7.x-9.x, g95) > stay at the end of file. I find their behavior consistent > with the F2003 standard, section 9.10.4: > > Execution of an input/output statement containing the IOSTAT= > specifier causes the scalar-int-variable in the IOSTAT= specifier > to become defined with > > (3) The processor-dependent negative integer value of the constant > IOSTAT_END (13.8.2.5) if an end-of-file condition occurs and no > error condition occurs, or (...) > > > AFAIK, the IOSTAT values aren't documented in gfortran.texi. > > Someday, someone will get around to documenting them. > > The standard separates end-of-file, end-of-record, and > error conditions. I don't think that EOF is necessarily > an error condition. It would be nice if gfortran would > conform with these other compilers. For whatever reason, you are hitting (2). (2) A processor-dependent positive integer value if an error condition occurs. At a guess, you get a -1 if you start a read from within the the file, and you hit the EOF. Once the EOF is hit, the file is probably positioned at a point beyond the EOF, the next attempt of a read is considered an error condition, so the 5008 is return. I saw your other email about BACKSPACE. I don't know what the expected behavior is with BACKSPACE and a file position that is at or exceeds the EOF marker. At a guess and knowing the vagueness of the Standard, this is probably processor-dependent. I think you're getting hit by 9.10.2(4) for F2003: (4) If the file specified in the input statement is an external record file, it is positioned after the endfile record. and BACKSPACE isn't doing its job with respect to Note 9.54. This is an area that Jerry knows. Perhaps, he has an opinion. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31052