Hi all, there's apparently a bug in the runtime when handling unformatted I/O on scratch files. It reads back garbage after writing. Sample program: program gfbug4 implicit none integer strlen parameter (strlen = 4) integer iunit, i, k character string *4 do 10 i = 1, strlen string(i:i) = achar (i) 10 continue iunit = 99 open (UNIT=iunit,FORM='unformatted',ACCESS='direct',RECL=strlen) write (iunit, rec=1) string read (iunit, rec=1) i close (iunit) print *, i open (UNIT=iunit,FORM='unformatted',ACCESS='direct', $ STATUS='scratch',RECL=strlen) write (iunit, rec=1) string read (iunit, rec=1) k close (iunit) print *, k if (i .eq. k) then print *, 'O.K.' else print *, '*** Bug! ***' endif end Result: % ./a.out 67305985 538976288 *** Bug! *** The first write to fort.99 and reading back works fine - it indicates that I/O has little-endian form, but the second is just 0x20202020.
it is a run-time library bug. --bud davis
proposed patch: http://gcc.gnu.org/ml/fortran/2004-08/msg00225.html
Subject: Bug 16597 CVSROOT: /cvs/gcc Module name: gcc Changes by: bdavis@gcc.gnu.org 2004-08-27 07:59:30 Modified files: gcc/testsuite : ChangeLog libgfortran : ChangeLog libgfortran/io : transfer.c io.h rewind.c Added files: gcc/testsuite/gfortran.dg: pr16597.f90 Log message: 2004-08-27 Bud Davis <bdavis9659@comcast.net> PR fortran/16597 * io/io.h: created typedef for unit_mode. * io/io.h (gfc_unit): added mode to unit structure. * io/transfer.c (data_transfer_init): flush if a write then read is done on a unit (direct access files). * io/rewind.c (st_rewind): Used unit mode instead of global. * gfortran.dg/pr16597.f90: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4201&r2=1.4202 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/pr16597.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.67&r2=1.68 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/transfer.c.diff?cvsroot=gcc&r1=1.12&r2=1.13 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/io.h.diff?cvsroot=gcc&r1=1.8&r2=1.9 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/rewind.c.diff?cvsroot=gcc&r1=1.3&r2=1.4
Fixed.