(j3.2006) Partial write in record with nonadvancing I/O
Mon Feb 27 08:27:37 EST 2012
Some additional tests
On 2/27/12 3:19 AM, Tobias Burnus wrote:
> Dear all,
> at comp.lang.fortran, Bob Corbett queried what the different compilers output
> for the following program - and the replies showed that the results vary a lot. Cf.
> (I assume that he intended to post it here or write an IR.)
> Which output(s) do you believe are standard conforming?
> The program is the following and I think looking at the created file is even more
> informative than looking at the OUTPUT_UNIT output of the program:
> PROGRAM MAIN
> CHARACTER*12 STR
> OPEN (10, FILE='XXX', POSITION='REWIND')
> WRITE (10, '(A)') 'ABCDEFGHIJKL'
> REWIND 10
> READ (10, '(TR4)', ADVANCE='NO')
> WRITE (10, '(TL2, A)', ADVANCE='NO') 'MNOP'
> REWIND 10
> READ (10, '(A)') STR
> PRINT '(A)', STR
> (Variant: Replace the last ADVANCE='NO' by 'YES'.)
In all the cases I tried, I got the same result with the original and
> (a) Pathscale 4.0, Openf95 5.0, OpenUH/Open64
(a) Also Cray.
> (b) gfortran (4.1 to 4.7), NAG 5.1, Lahey:
(b) Also PGI.
> (c) g95, Silverfrost ftn95, ifort 11.1/12.1
> [Where "MNOP" is in the next record, either at position 1 or
> at position 3.]
(c) Intel: MNOP starts at pos 1 of record 2
> (d) sunf95/Oracle f95, IBM xlf, Microsoft V 3.31 (1985)*
> (* This compiler needs some message to get this result)
> Some relevant parts of the Fortran 2008 standard:
> Paragraph 2 of Clause 126.96.36.199 has the following:
> "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."
> C.6.2, paragraph 4 (nonnormative):
> "If the next I/O operation on a file after a nonadvancing write is a
> rewind, backspace, end file or close operation, the file is positioned
> implicitly after the current record before an ENDFILE record is written
> to the file, that is, a REWIND, BACKSPACE, or ENDFILE statement
> following a nonadvancing WRITE statement causes the file to be
> positioned at the end of the current output record before the endfile
> record is written to the file."
> Interpretation request Fortran 95/000024:
> Other Fortran 2008 quotes:
> "188.8.131.52 File position prior to data transfer" (para. 2 and 4):
> "For sequential access on input, if there is a current record, the file
> position is not changed. [...]"
> "For sequential access on output, if there is a current record, the file
> position is not changed and the current record becomes the last record
> of the file. [...]"
> "184.108.40.206 File position after data transfer" (para. 4 and 5):
> "For nonadvancing input, if no error condition or end-of-file condition
> occurred, but an end-of-record condition (9.11) occurred, the file is
> positioned after the record just read. If no error condition,
> end-of-file condition, or end-of-record condition occurred in a nonadvancing
> input statement, the file position is not changed. If no error condition
> occurred in a nonadvancing output statement, the file position is not changed.
> "In all other cases, the file is positioned after the record just read or
> written and that record becomes the preceding record."
> PS: Bob's expected output is (a): "ABCDMNOPIJKL", I'm more inclined to (b),
> but Bob could have the better arguments.
> ----- End forwarded message -----
> J3 mailing list
> J3 at j3-fortran.org
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
More information about the J3