Re: Automatic allocation of an available file unit



Joe Krahn wrote:
I noticed that J3 is (finally) implementing automatic file unit allocation:
http://j3-fortran.org/doc/year/06/06-138r2.txt

I see that the plan is to use negative unit numbers for automatically assigned units. It seems to me that there would be fewer conflicts by using positive numbers starting at some number higher than the old compiler limits, an therefore unlikely to conflict with old code using constant unit numbers.

That's just my 2 cents.

I have been strictly avoiding constant unit numbers for a long time, using a function that returns a free UNIT, found by a simple INQUIRE loop, which also returns the unit number in an optional argument, so you can do an open statement like this:

open(unit=file_unit(data_unit), ...)
read(data_unit,...)

Doesn't everyone do something like this? :o) Although I tend towards the:
fileid=get_lun()
open(fileid, ....)
read(fileid, ....)
method.

But, if you do the above doesn't it mean that you don't really care what the actual unit value is? All you care is that it's valid to use for file I/O, right? So what does it matter if it's negative? From the link you gave, if the NEWUNIT= specifier is used, you'd do something like:
open(file='myfile.name',newunit=fileid, ....)
read(fileid, ....)

Same dog, different leg AFAICT.

cheers,

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
.



Relevant Pages

  • Re: Automatic allocation of an available file unit
    ... It seems to me that there would be fewer conflicts by ... negative unit numbers have previously been invalid. ... The only bad part of allowing negative unit numbers is for people who use variables to hold file unit numbers, where an invalid value means the file is not opened. ... The file unit finding routine should determine if the unit is /valid/, not some magic number that changes from compiler to compiler. ...
    (comp.lang.fortran)
  • Re: Automatic allocation of an available file unit
    ... It seems to me that there would be fewer conflicts by ... What number is this that is higher than "the old compiler limits"? ... negative unit numbers have previously been invalid. ... The only bad part of allowing negative unit numbers is for people who use variables to hold file unit numbers, where an invalid value means the file is not opened. ...
    (comp.lang.fortran)