Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with matrix

Status
Not open for further replies.

fcod

Programmer
Dec 2, 2008
2
BR
i started programming short time ago, and i cant understand what´s going wrong with the program i made, i expect someone can help me.
the matrix.txt i refer in the program is:
21 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
14 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
75 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
85 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
96 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
03 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
54 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
55 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
34 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
56 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
77 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
22 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
33 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
44 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
10 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
12 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
13 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
17 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
34 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56
56 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56


and the program is:
PROGRAM MATRIX
INTEGER J,A,L
DIMENSION A(20,20)
L=0
OPEN(20,FILE='matriz.txt',STATUS='OLD')

DO WHILE (L.LT.20)
L=L+1
read(20,'(20(I2))')
ENDDO
L=0
DO WHILE (L.LT.20)
L=L+1
WRITE(*,'(20(1X,I2))') (A(L,J),J=1,20)
ENDDO

END
But the result of it is a totally different matrix, and a can´t get why..=/
someone pleasee.
 
1) You aren't reading the data into anything
read(20,'(20(I2))')

will just read 20 numbers but not put them anywhere. You need something like

read(20,'(20I2))') (A(L,J), J=1, 20)

2) You did not account for the space between the numbers. 20I2 would be something like

5613344455337890321121324355669723217856

The problem here is that there is no leading space so you have to do something like

read(20,'(I2,19(1X,I2))') (A(L,J), J=1, 20)

or

read(20,'(I2,20I3)') (A(L,J), J=1, 20)

If you had a leading space i.e.

56 13 34 44 55 33 78 90 32 11 21 32 43 55 66 97 23 21 78 56

then you could have

read(20, '(20I3)') (A(L,J), J=1, 20)
 
thanks xwb, it helped a lot,
i used read(20,'(20(I2,1X))')(A(L,J),J=1,20) and it worked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top