1
votes

When i try to read a txt file with the following code example:

double precision inp(100)
open(1,file='whatever.txt')
do i=1,100
read(1,*) inp(i)
enddo
close(1)

The program just ends when it arrives at the read sentence. I tried alternative ways to write the loop, like

do
read(1,*) inp
enddo

but it's the same. The funny part is that if i write a txt with fortran or by hand and then i try to read it, it works!!

i'm desperate, please, help me.

1
Have you tried using a unit larger than 10? You're using 1, which might be already taken by something like standard in or something like that. - chw21
this should be closed as the issue was resolved and apparently unrelated to the code. - agentp

1 Answers

0
votes

Here are a few ideas:

  1. Take a unit number of 10 or larger, 1 might be taken by something like default i/o
  2. Use iostat and iomsg to find out why the read fails:

    integer :: iostat
    character(len=100) :: iomsg
    
    read(unit=u, fmt=*, iostat=iostat, iomsg=iomsg) inp(i)
    if (iostat /= 0) then
        print *, "Error reading inp"
        print *, "i was ", i
        print *, "Error was: ", trim(iomsg)
    end if