From: Thomas Koenig on
I have read the J3/04-007 draft on the properties of formatted
stream I/O, and I have confess I am still baffeled about some
points.

Question 1:

What should the program

program main
open(99,form="formatted",access="stream")
write (99,'(A)') 'a'
write (99,'(A)') 'b'
close (99)
end program main

write to file 99? One incomplete line containing

ab

or two lines

a
b

gfortran and ifort agree here, they both write
two lines.

Question 2:

What should the program

program main
open(99,form="formatted",access="stream")
write (99,'(A)',advance="no") 'a'
write (99,'(A)',advance="no") 'b'
close (99)
end program main

write to file 99? gfortran writes two lines containing

a
b

ifort writes a single "b". I would expect a single
line containing

ab
From: Gary Scott on
Thomas Koenig wrote:
> I have read the J3/04-007 draft on the properties of formatted
> stream I/O, and I have confess I am still baffeled about some
> points.
>
> Question 1:
>
> What should the program
>
> program main
> open(99,form="formatted",access="stream")
> write (99,'(A)') 'a'
> write (99,'(A)') 'b'
> close (99)
> end program main
>
> write to file 99? One incomplete line containing
>
> ab
>
> or two lines
>
> a
> b
>
> gfortran and ifort agree here, they both write
> two lines.
>
> Question 2:
>
> What should the program
>
> program main
> open(99,form="formatted",access="stream")
> write (99,'(A)',advance="no") 'a'
> write (99,'(A)',advance="no") 'b'
> close (99)
> end program main
>
> write to file 99? gfortran writes two lines containing
>
> a
> b
>
> ifort writes a single "b". I would expect a single
> line containing
>
> ab

:) My guess too is a single line containing ab

I would not think that advance='no' means not to advance the position
pointer, but rather not to write a line termination character. It looks
like ifort failed to advance the position pointer and overwrite the "a"
with the "b"




--

Gary Scott
mailto:garylscott(a)sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
From: Terence on
I agree with Gary and the expectation of
ab

From: Craig Dedo on
"Gary Scott" <garylscott(a)sbcglobal.net> wrote in message
news:8rH4j.28532$lD6.27163(a)newssvr27.news.prodigy.net...
> Thomas Koenig wrote:
>> I have read the J3/04-007 draft on the properties of formatted
>> stream I/O, and I have confess I am still baffeled about some
>> points.
>>
>> Question 1:
>>
>> What should the program
>>
>> program main
>> open(99,form="formatted",access="stream")
>> write (99,'(A)') 'a'
>> write (99,'(A)') 'b'
>> close (99)
>> end program main
>>
>> write to file 99? One incomplete line containing
>>
>> ab
>>
>> or two lines
>>
>> a
>> b
>>
>> gfortran and ifort agree here, they both write
>> two lines.

You are correct. ADVANCE="NO" is not specified in the WRITE statements, so
by default, they are advancing write statements (Fortran 2003, 9.5.1.3).
Therefore, two complete records should be written.

To clarify, advance mode, i.e., advancing/non-advancing read/write, is
completely separate and independent of whether the access mode is sequential or
stream. It is possible to have all four combinations.

>> Question 2:
>>
>> What should the program
>>
>> program main
>> open(99,form="formatted",access="stream")
>> write (99,'(A)',advance="no") 'a'
>> write (99,'(A)',advance="no") 'b'
>> close (99)
>> end program main
>>
>> write to file 99? gfortran writes two lines containing
>>
>> a
>> b
>>
>> ifort writes a single "b". I would expect a single
>> line containing
>>
>> ab
>
> :) My guess too is a single line containing ab
>
> I would not think that advance='no' means not to advance the position pointer,
> but rather not to write a line termination character. It looks like ifort
> failed to advance the position pointer and overwrite the "a" with the "b"
> --
> Gary Scott
> mailto:garylscott(a)sbcglobal dot net

Both ifort and gfortran are wrong in their behavior with this statement.
Thsi should not need a guess; the Fortran 2003 standard is quite explicit in
this case.

ADVANCE="NO" in this case specifies non-advancing output and applies to the
record, **NOT** the position within the record (Fortran 2003, 9.2.3.1). This
record should be complete, with the contents "ab". The last sentence of 9.2.3.1
states, "If a nonadvancing output statement leaves a file positioned within a
current record and no further output statement is executed for the file befoer
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 output
statement."

--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cdedo(a)wi.rr.com> or <craig(a)ctdedo.com>

From: Thomas Koenig on
Thanks for the explanations!

I've opened a bug report for gfortran, maybe
somebody could do the same with ifort.