Getting fortran runtime error: end of file

前端 未结 6 1967
借酒劲吻你
借酒劲吻你 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:47

    Thanks for all your help i did fix the code:

    Function Load_Names(Staff_Name(65))!Loads Staff Names
    
        character(len=30) :: Staff_Name(65)
        integer :: i = 1
    
        open(unit=10, file="Staff_Names.txt", status='old', action='read')!opens file for reading
    
        do while(i < 66)!Sets Set_Name() equal to the file one string at a time
    
            read(10,*,end=100) Staff_Name(i)
            i = i + 1
    
        end do 
        100 close(10)!closes file
        return!returns Value
    end Function Load_Names
    

    I needed to change read(10,*) to read(10,*,END=100) so it knew what to do when it came to the end the file as it was in a loop I assume.

提交回复
热议问题