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
Fortran运行时错误:gfortran中的文件结束_Fortran_Gfortran - Fatal编程技术网

Fortran运行时错误:gfortran中的文件结束

Fortran运行时错误:gfortran中的文件结束,fortran,gfortran,Fortran,Gfortran,当我使用gfortran test.f95运行此程序时,它显示一个错误 At line 10 of file test.f95 (unit = 15, file = 'open.dat') Fortran runtime error: End of file 有人能告诉我这里怎么了吗 implicit none integer:: a,b,c,ios open(unit=15,file="open.dat",status='unknown', action='readwrite',iost

当我使用gfortran test.f95运行此程序时,它显示一个错误

At line 10 of file test.f95 (unit = 15, file = 'open.dat')

Fortran runtime error: End of file
有人能告诉我这里怎么了吗

implicit none
integer:: a,b,c,ios

open(unit=15,file="open.dat",status='unknown', action='readwrite',iostat=ios)
open(unit=16,file="open.out",status="unknown",action='write')

do a=1,100
  write(15,*)a
end do

do c=1,45,1
  read(15,*)
  read(15,*)b
  write(16,*)b
end do

stop
end

确保使用“倒带”/fseek


你也可以通过倒带(15)来实现这一点。我根本不推荐fseek。标准Fortran已经足够强大了。仍然坚持非标准和不可移植的
fseek
:-)C传统;)但是,毕竟,倒带是最终代码中的“选择之一”。)谢谢大家。我用倒带解决了我的问题。请对所有Fortran问题使用tag。如果您将错误消息复制并粘贴到标题中,系统将告诉您此类问题已经存在。可能它已经告诉过你了,所以你不得不稍微改变一下。请,你真的应该先阅读现有的问题。另外,向我们显示您正在读取的数据非常重要。顺便说一句,在
结束之前传递
状态='unknown'
和使用
停止
,是没有意义的。您可以直接删除它。您也不应该指定
iostat
,然后不处理结果。
implicit none
integer :: a, b, c, ios, ierr

open( unit=15, file="open.dat", action='readwrite', iostat=ios)
open( unit=16, file="open.out", action='write')
do a=1,100
  write(15,*)a
end do

! Here we need to get back to beginning of file
! otherwise, you try to read where you finished writing
! at the end of file
! CALL FSEEK(UNIT, OFFSET, WHENCE[, STATUS])
! https://gcc.gnu.org/onlinedocs/gfortran/FSEEK.html
! call fseek(15, 0, 0, ierr)

! you can also use rewind file
! https://www.fortran.com/F77_std/rjcnf0001-sh-12.html
rewind(15)

do c=1,45,1
  read(15,*)
  read(15,*)b
  write(16,*)b
end do

end