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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing a matrix 5x5 in an output file (.txt)

Status
Not open for further replies.

carlasilva

Programmer
Jan 6, 2003
12
PT
How do I programme writing a matrix 5x5 in an output file (.txt)?
I would like to see the original matrix format, but I had tried and in the output file appears all the numbers in a single column.

Thank you for your help!
 
DIMENSION M(5,5)
OPEN(10,FILE='M.TXT')
C DEFINE THE MATRIX ......
C ........
DO 20 I = 1 , 5
20 WRITE(10,22) (M(I,J),J=1,5)
22 FORMAT(1H ,5I5)
CLOSE (10)
END
 

Hey~!

I'm trying to do the samne thing but I want the user to be able to define how large the matrix is going to be. That is, I want to be able to format the output and still have it print in a matrix form once the user tells the program how large - # of rows and columns - the nput and output matrices have

Is there a way to do this without using the default (*) format specifier?
 
Set the dimension to (at least) the maximum to be used.
Instead of upper limit (5) of I and J , enter the maximum : READ(*,*) IMAX,JMAX and use
DO 20I=1,IMAX
20 WRITE(20,22)(M(I,J),J=1,JMAX)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top