|-----Original Message-----
|From: Fortran 90 List [mailto:[log in to unmask]]On Behalf
|Of Richard Maine
|Sent: Tuesday, January 08, 2002 10:23 AM
|To: [log in to unmask]
|Subject: Re: /dev/null and scope of UNITs
|
<snipped description of unit number handling code>
|
|This code isn't very sophisticated. I've seen other versions that
|do some additional checks of the unit number. (I think it was to
|make sure that the unit existed). Strictly speaking those might be
|needed, and someday I might add them...but this code was written
|before that was pointed out to me....and I've never actually run into
|a problem from that, so I left the code as is.
This is pretty much what I wrote as well. I use a subroutine GetUnitNo(u)
which roughly corresponds to Richard Maine's assign_lun(), and an array of
flags. I also use hard coded limits to the max and min units. I encapsulate
everything, and "roll over" to the beginning of the unit number list if I
hit the upper limit, so that you only fail if you want more than (max - min
+ 1) files open simultaneously.
One comment: at first I tried to be clever and set the max and min using
inquire() and the exist={t,f} flag. The problem was that in some compilers,
exist doesn't work dependably, and the loop that scanned for the maximum
unit no (by detecting whether it existed or not) would go on forever. That's
when I went to the hard coded limits.
The unit number is pretty archaic, but if you use something like what you've
seen here, you can save yourself a lot of grief and use the unit number more
or less like a handle. You can even consider unit number behavior as a
"feature" (remember that old adage: "It's not a bug, it's a feature!" :-) ).
Files shouldn't be scoped, so their handles (unit numbers) shouldn't be
either. Consider your open files a globally available resource.
Alvaro Fernandez
Vice President
Athena Technology Consultants, Inc.
WWW: www.athena-eng.com
Email: [log in to unmask]
Voice: 281-648-3994
Fax: 281-648-4015
|