Fortran runtime error: End of file

0

I want to generate an algorithm that identifies me the minimum value of an array of dimension n read from an a.dat file

program ejercicio11
implicit none
real, dimension(:), allocatable :: a
integer :: n
real :: min
    open(unit=20, file='a.dat')
    read(20,*) n
    allocate(a(n))
    read (20,*) a
    print*, a
    !print*, min
    call mini(n)
    deallocate(a)
end program
!######################subroutine##################################
subroutine mini(n)
implicit none
real :: min
integer :: i, n
real,dimension(:),allocatable :: a
    read(20,*) n
    allocate(a(n))
    read(20,*) a    
    min = a(1)
    do i=2,n
        if (a(i)<min) then
        min=a(i)
        end if
    enddo
    print*, min
end subroutine mini

Compile perfect, but when running it I get the following error:

   4.00000000       5.00000000       7.00000000       8.00000000       9.00000000       4.00000000    
At line 22 of file alternativa.f90 (unit = 20, file = 'a.dat')
Fortran runtime error: End of file
Error termination. Backtrace:
#0  0x7ff37a29ef3a
#1  0x7ff37a29fa45
#2  0x7ff37a2a01bc
#3  0x7ff37a363393
#4  0x7ff37a35e0f9
#5  0x400bbc
#6  0x401181
#7  0x40120a
#8  0x7ff379edbf44
#9  0x400a88
#10  0xffffffffffffffff

the next one would be the a.dat:

6
4 5 7 8 9 4/
    
asked by Santiagot Gimenez 02.02.2018 в 18:04
source

0 answers