I have found the following useful in ameliorating the undesirable
features of global IO units:
You can use the OPENED attribute with the INQUIRE function to determine
if a unit is already connected. It is then trivial to write a function
GetFreeUnit which returns the next free logical unit. The attached code
illustrates the idea. Note that care is required to exclude the system
dependent standard input, output, and error units.
A problem arises when an end-user develops code using a library that you
have provided. Although your library carefully assigns unit numbers
there is no way of ensuring that the end-user does not try to open a
unit that your library code has already opened. To minimize the risk of
clashes in this situation I reserve unit numbers with high values (e.g.
1,000,000 to 1,000,999). This is on the basis that end users who are
careless about unit numbers will be unlikely to use such high values. Of
course the library documentation also alerts the end-user that
GetFreeUnit is available to assign valid unit numbers. It also states
which unit numbers should be avoided if the end-user chooses to assign
unit numbers by another means.
David.
Aleksandar Donev wrote:
>
> Hello,
>
> Thanks for the comments and advice on /dev/null. At least avoiding disk
> writes seems possible on Linux...
>
> > This is one area where I think the C way is better. But there is
> > an awful lot of inertia behind the old Fortran method. I'd like it
> > to be different, but its not at all clear that a real change is
> > likely to happen.
>
> Well, backward compatibility is a thing in my opinion separate from what
> happens to any new standards. And the whole system of global unit numbers
> left over from days of hard-wiring to tape drivers is just very bad as it
> makes design of IO libraries too hard. And it seems to me it shouldn't be
> hard to add something to at least ameliorate things, such as a standard way
> of getting a valid (free) UNIT number. I haven't really though of this since
> I rarely have many files open, but I don't see how this would be a big
> change. It might be a simple matter of adding a new field, alike UNIT, which
> does not take integers like UNIT (so as to avoid 6's and 5's and arithmetic
> on units), but rather a new intrinsic TYPE(FILE) or something...I also
> haven't yet looked into F2k's additions in terms of stream io and such, but
> will soon.
>
> Always complaining,
> Aleksandar
>
> --
> __________________________________
> Aleksandar Donev
> Complex Materials Theory Group (http://cherrypit.princeton.edu/)
> Princeton Materials Institute & Program in Applied and Computational
> Mathematics
> @ Princeton University
> Address:
> 419 Bowen Hall, 70 Prospect Avenue
> Princeton University
> Princeton, NJ 08540-5211
> E-mail: [log in to unmask]
> WWW: http://atom.princeton.edu/donev
> Phone: (609) 258-2775
> Fax: (609) 258-6878
> __________________________________
|