For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2006 > Re: Automatic allocation of an available file unit









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Automatic allocation of an available file unit
Paul Van Delst

2006-03-31, 7:01 pm

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com