Basic fortran help: reading columns of data from a text file

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 12K views
tomg10000
Messages
3
Reaction score
0
Hi everybody,
I have 3 columns of data (3 different variables) and 400 rows. How would I set up a matrix/array sort of thing to read each row individually and store it in my fortran program to calculate equations at each step?

What I have basically tried and can't get to work, I think it tries to read past the file all the time...
-------------------------------------
read(99,*)N
allocate(x(N),y(N),z(N))
do i=1,N ! Read matrix row-by-row
read(99,*)x(i),y(i),z(i)
'Equations calculating from each line'
enddo
close(99)
---------------------------------------
Any help? or does someone have part of a working program i can use and modify?
Thanks.
 
Physics news on Phys.org
Whenever I've read in matricies I'd use a read statement with an implied do loop. For instance:
dimension a(400,3)
do 1 i=1,400

read(1,*)(a(i,j),j=1,3)

1 continue