Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Io `gfortran中的backspace`n(旧的和新的)_Io_Fortran_Gfortran - Fatal编程技术网

Io `gfortran中的backspace`n(旧的和新的)

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

假设我想在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
但是,在
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