Reputation: 13
So I'm writing some code in Fortran that multiplies a square matrix by itself. But the matrix I have to multiply is in a file and I'm having some issues reading it into the program. I think its because the sample data is in the following format:
3
101
010
101
The first row is the dimension of the matrix, and each row is a now in the matrix, but there aren't spaces in between the entries. So I guess my question is how do I split up those rows as I read them into a 2d array?
Upvotes: 1
Views: 360
Reputation: 1
Read using format
read (1,*) n
allocate(A(n,n))
do i=1,n
read (1,'(1000i1)'),A(i,:)
enddo
it does not matter whether you declare extra "i1" than actually needed
Upvotes: 0
Reputation: 29401
Read in the first number as N
and use it to allocate an array of dimension N by N. Then read a row at a time of this array: array (i, 1:N))
for i=1 to N. See Fortran: reading a row of numbers into an array for the format to use.
Upvotes: 1