If one uses advance = NO, after the write a FLUSH should be called.
-----------------
program test
implicit none
character(20) :: fname
WRITE(*,ADVANCE='NO',FMT='(A)') " Input name of file?"
READ(*,'(a)') fname
print *, 'Read: ',trim(fname)
end program test
-----------------
If you run this program with gfortran (trunk) or with gfortran-4.2 the result
is:
x
Input name of file? Read: x
However, using gfortran-4.1 (20061024), NAG f95, ifort, g95 sunf95 the result
is:
Input name of file?x
Read: x
Expected: For advance='NO' the output should probably flushed. Or
alternatively, for read(*) the output to that unit should be flushed first.
I don't know what is the best way, to work (a) reliably and (b) does not have a
too big performance penalty.
A test using "call sleep(3)" instead of read() shows that ifort, NAG f95 and
sunf95 flush on the read, g95 and gfortran-4.1 on the write.
I think the ifort/NAGf95/sunf95 is better since one only needs to have
everything flushed if one wants to read. In addition, the same problem could
happen if one does a buffered write() with advance="YES".
(I don't know what gfortran currently does. ifort supports, e.g., -assume
nobuffered_io (default) and -assume buffered_io. It it seems to buffer for
advance='yes' using no options.)
--
Summary: [4.2/4.3 Regression] write(*,*,advance='NO'), READ():
Data not flushed
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29752