(j3.2006) Partial write in record with nonadvancing I/O

Tobias Burnus burnus
Wed Feb 29 09:15:44 EST 2012


Dear all,

On Mon, Feb 27, 2012 at 10:19:09AM +0100, Tobias Burnus wrote:
> 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.
> http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/694050b1806da367

I have just realized that the compilers already produce quite different results
for the following program. The program comes in four variants:

* With and without a nonadvancing READ, which places the position in
  the current record.

* With advancing and with nonadvancing WRITE.

!--------------------------------------------------------
  OPEN (10, FILE='XXX', status='replace')
  WRITE(10, '(a)') 'ABCDEFGHIJKL'
  WRITE(10, '(a)') '1234567890ab'
  close (10)

  OPEN (10, FILE='XXX', position='REWIND', status='old', &
        action='readwrite')
!      READ(10, '(tl1)', advance='no') ! << add optionally
  WRITE (10, '(A)', ADVANCE='NO') 'mnop' ! << optionally: advance='yes'
  FLUSH (10)
  call execute_command_line ('cat XXX; echo "<"')
  close(10)
  call execute_command_line ('cat XXX; echo "<"')
end
!--------------------------------------------------------

(Replace "flush(10)" by "call flush(10)" and "execute_command_line"
 by "system" if your compiler supports those instead of the new
 F2003 statement/F2008 intrinsic. On Windows, the "cat" could be
 replaced by "type". I had to do some of those for the results below.)


Upon special request, I refrain from quoting the standard. However, I am
interested, which output you expect and whether the program is valid or not.


Results for several compilers:


a) Nonadvancing READ, nonadvancing WRITE
----------------------------------------

(i) Pathscale 3.2.99, Cray 7.1, Open64 4.2

mnopEFGHIJKL
1234567890ab
<
mnopEFGHIJKL
<


(ii) gfortran 4.7, PGI 11.5,

mnop<
mnop
<


(iii) g95 0.93

ABCDEFGHIJKL
mnop<
ABCDEFGHIJKL
mnop<


(iv) ifort 12.1 [also with "-assume nobuffered_io"]

ABCDEFGHIJKL
1234567890ab
<
ABCDEFGHIJKL
mnop
<


b) Nonadvancing READ, advancing WRITE
-------------------------------------

(i) Pathscale 3.2.99, Cray 7.1, Open64 4.2

mnopEFGHIJKL
1234567890ab
<
mnopEFGHIJKL
<


(ii) gfortran 4.7, PGI 11.5,

mnop
<
mnop
<


(iii) g95 0.93, ifort 12.1

ABCDEFGHIJKL
mnop
<
ABCDEFGHIJKL
mnop
<


c) No READ, nonadvancing WRITE
------------------------------

(i) Pathscale 3.2.99, Cray 7.1, Open64 4.2

mnopEFGHIJKL
1234567890ab
<
mnop
<


(ii) gfortran 4.7, PGI 11.5,

mnop<
mnop
<


(iii) g95 0.93

mnop<
mnop<


(iv) ifort 12.1 [-assume nobuffered_io]

ABCDEFGHIJKL
1234567890ab
<
mnop
<


d) No READ, advancing WRITE
------------------------------

(i) Pathscale 3.2.99, Cray 7.1, Open64 4.2

mnop
FGHIJKL
1234567890ab
<
mnop
<


(ii) gfortran 4.7, PGI 11.5, g95, ifort 12.1

mnop
<
mnop
<


Tobias



More information about the J3 mailing list