(j3.2006) Nonadvancing I/O with t edit descriptor
Tue Feb 14 15:29:15 EST 2012
the following question came up at comp.lang.fortran : Should the
following program print "Hello" in the first column or in the 25th column:
Write( *, '( t25 )', Advance = 'No' )
Write( *, '( "Hello" )' )
With two compilers "Hello" starts in column 1, with seven compilers it
starts in column 25.
Glancing at the standard, I am inclined that the majority is right.
However, as one rather careful and experienced Fortran standard reader
is unsure , I think it makes sense to ask at J3 (and maybe even to
fill an interpretation request).
One problem seems to be the relation between "file position" and
Lengthy quote from the Fortran 2008 standard, which hopefully contains
all relevant quotes:
"220.127.116.11 Advancing and nonadvancing input/output"
"A nonadvancing input/output statement may position a record file at a
character position within the current record, or a subsequent record (10.8.2).
Using nonadvancing input/output, it is possible to read or write a record
of the file by a sequence of input/output statements, each accessing a portion
of the record. It is also possible to read variable-length records and be
notified of their lengths. If a nonadvancing output statement leaves a file
positioned within a current record and no further output statement is executed
for the file before it is closed or a BACKSPACE, ENDFILE, or REWIND statement
is executed for it, the effect is as if the output statement were the
corresponding advancing output statement."
"10.5 Positioning by format control
After each data edit descriptor or character string edit descriptor is
processed, the file is positioned after the last character read or written in
the current record.
After each T, TL, TR, or X edit descriptor is processed, the file is positioned
as described in 10.8.1. [...]"
"10.8.1 Position editing
The T, TL, TR, and X edit descriptors specify the position at which the next
character will be transmitted to or from the record. If any character skipped
by a T, TL, TR, or X edit descriptor is of type nondefault character, and the
unit is a default character internal file or an external non-Unicode file, the
result of that position editing is processor dependent.
The position specified by a T edit descriptor may be in either direction from
the current position. [...]
On output, a T, TL, TR, or X edit descriptor does not by itself cause
characters to be transmitted and therefore does not by itself affect the length
of the record. If characters are transmitted to positions at or after the
position specified by a T, TL, TR, or X edit descriptor, positions skipped and
not previously filled are filled with blanks. The result is as if the entire
record were initially filled with blanks.
On output, a character in the record may be replaced. However, a T, TL, TR, or
X edit descriptor never directly causes a character already placed in the
record to be replaced. Such edit descriptors may result in positioning such
that subsequent editing causes a replacement.
10.8.1.1 T, TL, and TR editing
The left tab limit affects file positioning by the T and TL edit descriptors.
Immediately prior to nonchild data transfer (18.104.22.168.2), the left tab limit
becomes defined as the character position of the current record or the current
position of the stream file. If, during data transfer, the file is positioned
to another record, the left tab limit becomes defined as character position one
of that record.
The Tn edit descriptor indicates that the transmission of the next character to
or from a record is to occur at the nth character position of the record,
relative to the left tab limit."
"C.6.2 Nonadvancing input/output (22.214.171.124)
Data transfer statements affect the positioning of an external file. In Fortran
77, if no error or end-of-file condition exists, the file is positioned after
the record just read or written and that record becomes the preceding record.
This part of ISO/IEC 1539 contains the record positioning ADVANCE= specifier in
a data transfer statement that provides the capability of maintaining a
position within the current record from one formatted data transfer statement
to the next data transfer statement. The value NO provides this capability. The
value YES positions the
le after the record just read or written. The default
The tab edit descriptor and the slash are still appropriate for use with this
type of record access but the tab cannot reposition before the left tab limit.
In an implementation of nonadvancing input/output in which a nonadvancing write
to a terminal device causes immediate display of the output, such a write can
be used as a mechanism to output a prompt.
This part of ISO/IEC 1539 does not require that an implementation of
nonadvancing input/output operate in this manner. For example, an
implementation of nonadvancing output in which the display of the output is
deferred until the current record is complete is also standard-conforming. Such
an implementation will not, however, allow a prompting mechanism of this kind
More information about the J3