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

AI Thread Summary
To read three columns of data from a text file in Fortran, allocate arrays for each variable and use a loop to read the data row-by-row. The provided code attempts to read the data but may encounter issues with file handling. A suggested method involves using an implied do loop to simplify the reading process into a single statement. The example shows how to declare a 2D array and read data efficiently. Proper file management and array allocation are crucial for successful data processing in Fortran.
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
 
Back
Top