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

Click For Summary
SUMMARY

The discussion focuses on reading columns of data from a text file using Fortran. The user seeks assistance in setting up a matrix to store three variables across 400 rows. A working example provided includes using an implied do loop with a dimensioned array to read data efficiently. The key takeaway is the importance of correctly allocating memory and using the appropriate read statements to avoid reading past the file's end.

PREREQUISITES
  • Fortran programming language basics
  • Understanding of arrays and memory allocation in Fortran
  • File I/O operations in Fortran
  • Knowledge of implied do loops in Fortran
NEXT STEPS
  • Study Fortran array allocation techniques
  • Learn about Fortran file handling and error checking
  • Explore advanced Fortran I/O formatting options
  • Investigate performance optimization for large data sets in Fortran
USEFUL FOR

This discussion is beneficial for Fortran programmers, data analysts, and researchers working with numerical data who need to efficiently read and process data from text files.

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
 

Similar threads

Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
8
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 23 ·
Replies
23
Views
9K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K