Consider the following: Wot now ? cat da.f90 Program da
Implicit None Real :: a, b a = 1.111111111 b = 2.222222222 Open( 10, File = 't.dat', Form = 'Formatted', Access = 'Direct', Recl = 12 ) Write( 10, rec = 1, fmt = '( f6.4, /, f6.4 )' ) a, b Close( 10 ) a = -1.0 b = -1.0 Open( 10, File = 't.dat', Form = 'Formatted', Access = 'Direct', Recl = 12 ) Read( 10, rec = 1, fmt = '( f6.4, /, f6.4 )' ) a, b Write( *, '( "Partial record 1", t25, 2( f6.4, 1x ) )' ) a, b Read( 10, rec = 1, fmt = '( f6.4 )' ) a, b Write( *, '( "Partial record 2", t25, 2( f6.4, 1x ) )' ) a, b Read( 10, rec = 1, fmt = '( f12.4, /, f12.4 )' ) a, b Write( *, '( "Full record 1", t25, 2( f6.4, 1x ) )' ) a, b Read( 10, rec = 1, fmt = '( f12.4 )' ) a, b Write( *, '( "Full record 2", t25, 2( f6.4, 1x ) )' ) a, b Read( 10, rec = 1, fmt = '( f6.4, 6x, /, f6.4, 6x )' ) a, b Write( *, '( "Full record with 6x", t25, 2( f6.4, 1x ) )' ) a, b Read( 10, rec = 1, fmt = '( f6.4 )' ) a Read( 10, rec = 2, fmt = '( f6.4 )' ) b Write( *, '( "Record at a time", t25, 2( f6.4, 1x ) )' ) a, b End Program da Wot now ? ~/Download/usr/local/gfortran/bin/gfortran --version GNU Fortran (GCC) 4.5.0 20091116 (experimental) [trunk revision 154218] Copyright (C) 2009 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING Wot now ? ~/Download/usr/local/gfortran/bin/gfortran -W -Wall -pedantic -fbounds-check -g -O2 da.f90 Wot now ? ./a.out Partial record 1 1.1111 0.0000 Partial record 2 1.1111 0.0000 Full record 1 1.1111 2.2222 Full record 2 1.1111 2.2222 Full record with 6x 1.1111 2.2222 Record at a time 1.1111 2.2222 Wot now ? Note that when reading partial records gfortran gets the value of b wrong. Compare g95 and the sun fortran compiler: Wot now ? g95 --version G95 (GCC 4.0.3 (g95 0.92!) Mar 27 2009) Copyright (C) 2002-2008 Free Software Foundation, Inc. G95 comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of G95 under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING Wot now ? g95 -W -Wall -pedantic -fbounds-check -g -O2 da.f90 Wot now ? ./a.out Partial record 1 1.1111 2.2222 Partial record 2 1.1111 2.2222 Full record 1 1.1111 2.2222 Full record 2 1.1111 2.2222 Full record with 6x 1.1111 2.2222 Record at a time 1.1111 2.2222 Wot now ? f90 -V f90: Sun Fortran 95 8.4 Linux_i386 2009/06/03 Usage: f90 [ options ] files. Use 'f90 -flags' for details Wot now ? f90 da.f90 Wot now ? ./a.out Partial record 1 1.1111 2.2222 Partial record 2 1.1111 2.2222 Full record 1 1.1111 2.2222 Full record 2 1.1111 2.2222 Full record with 6x 1.1111 2.2222 Record at a time 1.1111 2.2222 I've also checked against the intel, portland group, pathscale and cray compilers and they all give what I think is the correct result, i.e. the same as g95 and the sun compiler Also sorry about screwing up the first attempt at submission ! -- Summary: Problems when reading partial records in formatted direct access files Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ian dot bush at nag dot co dot uk http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42090