Io `gfortran中的backspace`n(旧的和新的)
假设我想在Fortran中的文件中附加一行。使用最新版本(4.7)的Io `gfortran中的backspace`n(旧的和新的),io,fortran,gfortran,Io,Fortran,Gfortran,假设我想在Fortran中的文件中附加一行。使用最新版本(4.7)的gfortran,我发现这是可行的: program test integer :: lun=10, i=0 open(FILE='test.dat', UNIT=lun) do read(lun, *, END=20) i print *, i end do 20 backspace(lun) write(lun, *), i+1 end program test 但是,在gfo
gfortran
,我发现这是可行的:
program test
integer :: lun=10, i=0
open(FILE='test.dat', UNIT=lun)
do
read(lun, *, END=20) i
print *, i
end do
20 backspace(lun)
write(lun, *), i+1
end program test
但是,在gfortran 4.4
中,它会覆盖最后一行。为了附加,我发现我需要使用
20 continue
而不是退格
怎么回事?在一个真正的程序中如何处理这个问题?在4.4中似乎根本不正确。根据标准“如果前面的记录是endfile记录,则该文件将位于endfile记录之前。”.fwiw,一个旧的g77(3.4.6)按预期运行(不覆盖),而gfortran 4.1.2覆盖。两者都可以使用openappend正常工作(尽管77国集团需要access=而不是position=)
program test
integer :: lun=10, i=0,io
open(FILE='test.dat', UNIT=lun, POSITION="append")
backspace(lun,iostat=io)
if (io==0) then
read(lun,*) i
else
i = 0
end if
write(lun, *) i+1
end program test