[patch, libfortran] PR34795 inquire statement , direct= specifier incorrectly returns YES

Jerry DeLisle jvdelisle@verizon.net
Mon Jan 21 08:09:00 GMT 2008


Tobias Burnus wrote:
> Jerry DeLisle wrote:
>> This patch modifies gfortran behavior for inquire. The specifiers
>> DIRECT=, FORMATTED=, UNFORMATTED=, and SEQUENTIAL answer the question
>> whether a given file "may" be opened with the given specifier.
>>
>> This implies that the given file or unit is not already opened.
> I have to admit that I do not see this implication - especially not if
> one queries by unit and not by name.

"may" as in "can be opened without a failure in that mode" not to imply being 
able to read or write it usefully, which would depend on content. "may be 
opened" also implies a future tense of the action "open"
> 
>> The patch addresses the case where the files are already opened in
>> which case we can query the unit for the actual mode and return
>> "YES","NO", "FORMATTED", or "UNFORMATTED" accordingly.
>>
>> SEQUENTIAL= was already handled this way.
> 
> As written in #gfortran I regard it as useful change to return the same
> result as the majority of the compilers in this case, i.e. "YES" if the
> file has been opened in this mode and "NO" if it has been opened in a
> different mode. (NAG f95 has "YES" and "UNKNOWN".)
> 
> There are programs relying on the new behavior: The file is opened
> somewhere and then the unit number or the filename is passed around and
> before the write/read statement the current mode is checked.
> 
> 
> The only correct answer would be, by the way, "UNKNOWN" and not "NO" as
> one does not rule out the other. (Though using formatted on unformatted,
> non-stream files might yield interesting results.)

Not sure what you mean here.  If it has been opened already as "FORMATTED" you 
can't read it unformatted (etc)

> 
> (Actually, for closed files is the same problem: The library does not
> know whether a file is formatted or unformatted - and the operating
> system does not know it either. [I think VAX made a distinction.])

Yes, but it does know whether it is seekable which is needed for DIRECT whereas 
SEQUENTIAL does not need seekable.
> 
>> Regression tested on X86-64-Linux.  We have no existing test case that
>> is affected by this change.  A new test case is provided.
> 
> Can you enhance the test case to check also inquire(file='testfile')
> instead of testing only inquite(unit=19) ?
> 

Yes, will do

> 
> Additionally, your test case fails if the file "testdirect.f" does not
> exist. As you call this file "inquire_13.f90" and not "testdirect.f" (as
> the original bug report did, the test case will fail for:
> 
> open(unit=19,file='testdirect.f',status='OLD',err=170)
> 
> which is probably not intended.

oops, not intended.  :)

> 
> Touching the file and calling inquire after that open statement
> 
> inquire(file='testfile', direct=drct, opened=opn, access=acc)
> 
> gives different results for drct:  "YES" with gfortran and "UNKNOWN"
> with ifort, sunf95, openf95, pathscale, PGI and NAG f95. Otherwise
> gfortran's output is identical to ifort and sunf95 (using
> "inquire(file=...)") while there are some differences to the other
> compilers for the other tests. Only g95 and g77 have also "YES".
> 
> I think that therefore gfortran should also print "UNKNOWN" for this
> test case.

I will check this. Thanks for review.
> 
> Otherwise the patch is ok.
> 
> Tobias
> 
>> PS Is the patch tracker working any more?
> No. The last time I pinged on #gcc the answer was something like "as
> time permits" and about in 2-3 weeks. Someone suggested at gcc@ to put
> it on the gcc.gnu.org server, though there might be problems as it uses
> Ruby.
> 



More information about the Fortran mailing list