Reading matrix elements from a file in Fortran77

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 4K views
Telemachus
Messages
820
Reaction score
30
SOLVED

Hi there. I have the elements of a matrix written in a txt file (in row major order). I need to read this matrix to use it in my fortran77 program. The text file contains the elements written in this way:

A(1,1)
A(1,2)
...
A(1,N)
...
A(N,N-1)
A(N,N).

I was thinking in doing a do loop, but I haven't used the read statement before for this kind of tasks. So I wasn't sure on how to do this.
Fortran:
        open (unit=10,file='matrix.dat',status='old')

       do i=1,cols
         do j=1,rows
           A(i,j)=?
         enddo
      enddo

I don't know what the statement at ? should be, in order to get the elements of the file matrix.dat written in the array A(rows,cols).

Thanks in advance.

Edit: just had to use read(file,*)A(i,j)!
 
Last edited:
on Phys.org