How to read data from files and process it?

AI Thread Summary
The discussion centers around a Fortran program designed to read data from a file with four columns and process it for calculations. The user encounters an issue where the output consistently returns 0.00000. Key points include the structure of the code, which involves opening a file, reading data into arrays, and attempting to write output. A critical suggestion is to specify the file format in the OPEN statements. If the data is in a human-readable format, the option FORM=FORMATTED should be added. Conversely, for binary data, FORM=UNFORMATTED and RECL=xxx are necessary. Understanding the data file's format is essential for resolving the output issue.
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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
2
Views
2K
Replies
12
Views
3K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
8
Views
4K
Replies
10
Views
25K
Replies
5
Views
5K
Back
Top