Getting fortran runtime error: end of file

前端 未结 6 1980
借酒劲吻你
借酒劲吻你 2020-12-19 03:54

I have recently learned how to work with basic files in Fortran and I assumed it was as simple as:

open(unit=10,file=\"data.dat\")
read(10,*) some_variable,         


        
6条回答
  •  长情又很酷
    2020-12-19 04:29

    Using Fortran 2003 standard, one can do the following to check if the end of file is reached:

        use :: iso_fortran_env
    
        character(len=1024) :: line
        integer :: u1,stat
    
        open (newunit=u1,action='read',file='input.dat',status='old')
    
    ef: do
          read(u1,'A',iostat=stat) line
          if (stat == iostat_end) exit ef ! end of file
          ...
        end do ef
        close(u1)
    

提交回复
热议问题