Re: closing unit=5 and unit=6 and print *
- From: nospam@xxxxxxxxxxxxx (Richard E Maine)
- Date: Tue, 29 Aug 2006 08:55:56 -0700
First, a short answer to the OP.
This is compiler-dependent. It is common for units 5 and 6 to refer to
input and output on the console. The standard does not require this, but
it is allowed and is quite common. It varies from compiler to compiler
what the effect of closong units 5 and 6 are. The standard allowws
either behavior. You are strongly advised to not use those unit numbers
for other files. More generally, I advise avoiding unit numbers less
than 10, as various compilers have reserved various of those numbers for
special purposes.
And a longer reply to Tim.
Tim Prince <timothyprince@xxxxxxxxxxxxx> wrote:
According to my understanding, in f77 and subsequent standards, unit=*
is required to be independent of positive numbered units in the
available contiguous range.
I'm afraid I disagree with almost everything in that statement. :-(
First, the easy part. Nowhere does the standard mention that the set of
available unit numbers must be contiguous. It typically is so, but that
requirement isn't in the standard.
The other part is more subtle, but I disagree with it also. I do not
interpret the standard as requiring * to be independent of the numbered
units. Prior to f2003, it is my interpretation that this is a
compiler-dependent matter. Indeed, there exist multiple compilers on
both sides of that fence. I believe there was even a formal interp on
the matter. Ah yes. F95 interp 68, appended below. I recalled that some
people were trying to argue for your interpretation based on the fact
that it was the way their compiler acted. I didn't think that a very
good basis for interpreting the standard, insomuch as:
1. The standard didn't actually say anything like that. There is a bit
that could possibly be misinterpreted that way, but I believe that would
be a misinterpretation... and the formal interp agrees with me. You are
probably reading the part that says that a file may not be connected to
more than one unit at the same time. The subtle part is in the
distinction between a unit and a unit identifier; the standard is a bit
sloppy about that distinction, but I maintain that * and 6 (for example)
can be two different identifiers for the same unit, just like two
different integer variables with the same value could identify the same
unit. I agree it is a subtle distinction.
Hmm. In reading f77, I see a further subtlety in that f77 says that *
identifies a (singular) unit, while f95 says that it identifies units
(plural - different for input and output). The formal interp is about
f95. I suppose that this difference does allow some possible wiggle room
to argue that f77 might have been different. Oh well; you aren't going
to get a formal interp on f77 any more.
2. There existed other compilers that didn't act like that.
3. That reading would have been incompaatible with a new feature already
in f2003. Odd as I thought it was to try to retroactively legislate a
requirement that the standard had formerly been quiet on, I thought it
even more so to make such retroactive legislation incompatible with
subsequent versions of the standard.
4. I happen to personally find your interpretation to be inconvenient. I
was surprised when I found that there were compilers that worked that
way. It took me a while to conclude that those compilers were ok and
that the standard didn't actually require the behavior that I liked. My
preference isn't directly a valid argument for why the standard should
be interpreted the way I like, but it does mean that I was paying
attention and objected vociferously when some people tried to pass a
contrary interpretation without solid support in the standard.
Elaboration on point 4 above - namely why my preference lies the other
way. I like the flexibility of being able to use variables for unit
numbers. I have multiple places in my codes where the same write
statement might want to write to a disk file in some cases, and the
terminal in other cases. Both cases happen at different times in the
same execution of the program, so external file redirection doesn't do
the trick. (Actually, it is very much like file redirection, but
internal to my programs; I have options to redirect output from some
user commands in my programs). This all works fine to the extent that I
can use a unit number for "standard output". It is a mess if I am forced
to use a *. This is basically the same issue as Beliavsky mentioned.
Oh. And the new feature of f2003 are the module parameter is input_unit
and output_unit, which are explicitly required to be unit numbers that
identify the same units as identified by *. Those unit numbers may be
negative if the compiler wants to keep them "out of the way" of other
unit numbers. I suspect that those compilers that currently treat 5 and
6 as differet from * are likely to continue to do so and add new,
possibly negative unit numbers for the new facility. But those compilers
that treat 5 and 6 as being the same as * are likely to just define the
parameters as 5 and 6.
The formal f95 interp follows:
NUMBER: 000068
TITLE: Asterisks as I/O units
KEYWORDS: Asterisk, I/O, unit
DEFECT TYPE: Interpretation
STATUS: Passed by WG5 ballot
Question:
1. Does the Fortran 95 standard require the external unit
corresponding to the I/O unit identified by an asterisk for
input or output to be the same as the external unit identified
by some fixed nonnegative integer value?
2. Can the I/O unit identified by an asterisk for input or output
correspond to more than one external unit?
3. If the external unit identified by an integer value that
corresponds to the I/O unit identified by an asterisk for input
or output is closed, does that cause the I/O unit identified by
an asterisk to become disconnected?
ANSWER:
1. No.
2. No.
3. Not addressed by Fortran 95.
DISCUSSION:
The submitter states: At least one Fortran 95 implementation uses -1
as the value of the I/O unit identified by an asterisk. A carefully
constructed INQUIRE statement can expose this value to the user. Many
users expect I/O to the units identified by asterisks to continue to
work even after the corresponding units identified by integer values
have been closed.
1. There is no requirement in the standard that the asterisk
correspond to an external-file-unit; it is, however, permissible.
2. For the units identified by the asterisk, the text of
section 9.3.2 does not allow two or more units to be connected
simultaneously to the same file [139:8-9].
3. Fortran 95 does not specify the behavior in this instance.
REFERENCES: ISO/IEC 1539-1:1997(E), Sections 9.3 and 9.4.4.2
EDITS: None
SUBMITTED BY: Robert Corbett
HISTORY: 99-192 m150 Submitted
99-215r1 m150 approved uc
00-208 m153 passed by J3 letter ballot
00-268 m154 Failed WG5 letter ballot (N1395 & N1403)
WG5/N1452 Suggested revision (expanded discussion)
01-296r1 m158 Passed by J3 meeting
01-380 m159 Failed J3 letter ballot
04-306r1 m168 Passed by J3 meeting vote
04-417r1 m170 Passed by J3 letter ballot #8
05-180 m172 Passed by WG5 ballot N1617
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.
- Follow-Ups:
- Re: closing unit=5 and unit=6 and print *
- From: robert . corbett
- Re: closing unit=5 and unit=6 and print *
- From: glen herrmannsfeldt
- Re: closing unit=5 and unit=6 and print *
- References:
- closing unit=5 and unit=6 and print *
- From: Dylan Sung
- Re: closing unit=5 and unit=6 and print *
- From: Tim Prince
- closing unit=5 and unit=6 and print *
- Prev by Date: Re: How to USE modules in a different directory?
- Next by Date: Re: How to USE modules in a different directory?
- Previous by thread: Re: closing unit=5 and unit=6 and print *
- Next by thread: Re: closing unit=5 and unit=6 and print *
- Index(es):
Relevant Pages
|