I'm writing a program which has to read the augmented matrix (A|B) of a linear equation system Ax=B from a text file, and store it into a matrix to solve it later.
My routine for solving the equation system seems to work, but I'm having trouble reading the file itself, which shouldn't be too hard but I'm obfuscated at this point. The text file contains a real number matrix which is N+1 entries wide (the coefficient matrix plus the corresponding independent term entry in the end) and N entries high. My attempt (with a N=5 system) has been this one:
OPEN(10,FILE="sistema.txt")
DO I=1,N
DO J=1,(N+1)
IF(J==(N+1)) THEN
READ(10,*) B(I)
ELSE
READ(10,*) A(I,J)
END IF
END DO
END DO
CLOSE(10)
With A(1:N,1:n) being a real array and B(1:N) a real array too (and N an integer entered by the user in order to decide between two strategies). The program returns and End of file error, and I've tried changing the indexes of the loop to I=1,2 and J=1,3 just to see what happens, but it keeps returning the same EoF error. Only with I=1,2 and J=1,2 will it read the file and leave all but four entries untouched. I don't understand what's going on.
The contents of the txt file, if it helps:
10.0 1.0 2.0 3.0 4.0 12.0
1.0 9.0 -1.0 2.0 -3.0 -27.0
2.0 -1.0 7.0 3.0 -5.0 14.0
3.0 2.0 3.0 12.0 -1.0 -17.0
4.0 -3.0 -5.0 -1.0 15.0 12.0
readproceeds to the next line. You need to read each line with a single read statement. something likeread(..)a(i,:n),b(i)