How to read data from files and process it?

Click For Summary
SUMMARY

The discussion focuses on reading and processing data from a file using Fortran. The user encounters an issue where the output consistently returns 0.00000. Key points include the necessity of specifying the correct file format in the OPEN statements, with options like FORM=FORMATTED for text files and FORM=UNFORMATTED for binary files. The user is advised to ensure the data files are in the expected format to resolve the output issue.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with file I/O operations in Fortran
  • Knowledge of data file formats (text vs binary)
  • Basic debugging skills in programming
NEXT STEPS
  • Learn about Fortran file I/O operations, specifically the OPEN statement
  • Research data file formats and their implications on reading data in Fortran
  • Explore debugging techniques for Fortran programs to identify I/O issues
  • Investigate the use of IOSTAT in Fortran for error handling during file operations
USEFUL FOR

Fortran developers, data analysts, and anyone involved in scientific computing who needs to read and process data from files efficiently.

ade_tokunbo
Messages
2
Reaction score
0
Dear all,

I want to read data from a file which has four column and process the data for further calculation. After running the code it keeps given me 0.00000 as output. What do i do? Here is the structure of the code

program new

Implicit none
integer,parameter ::Nmax=1000
Integer :: i,io,max,t
Real*8,Dimension(Nmax) :: Ev,X,Y,Z
Real*8, Dimension(Nmax)::Evr,Xr,Yr,Zr


open(1, File='si.dat',status='old')

open(16,file='cal.dat',status='unknown')

max=0
do i=1,Nmax
read(1,*,IOSTAT = io)Ev(i),X(i),Y(i),Z(i)
if (io.eq.0) then
max = max+1
else
goto 677
endif
enddo


677 close(1)

do t=1,Nmax
open(1, file='si.dat',status='old')
do i=1,max

read(1,*,iostat=io)Ev(i),X(i),Y(i),Z(i)
enddo
write(6,*)Ev(t),X(t),Y(t),Z(t)
enddo
close(16)

end program
 
Technology news on Phys.org
On the OPEN statements, if the data is in human readable form (i.e. text), add the additional option FORM=FORMATTED. If the data is binary, then FORM=UNFORMATTED and RECL=xxx should be added, but in any event, you'll need to know what form the data files are in.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
26K
  • · Replies 5 ·
Replies
5
Views
5K