Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a beginner's question, input/output of fortran

Status
Not open for further replies.

clover17

Technical User
Nov 1, 2015
1
US
Below is my code, ef.txt is the file with my data. I do not know why the code below can only generate the files before the ef part. So if I run the code below, there is no error message but only mu.txt and mu2.txt appear in the folder. mu1 cannot be found in the folder...why..I really cannot figure out.
----------------------------------
PROGRAM Source1

implicit none
integer :: i
real*8, dimension(3) :: eta


open(21,file='mu.txt',form='formatted')
do i = 1,3
write(21,187) i, i+1
187 format(i5,i5)
end do
close(21)




open(24,file='mu2.txt',form='formatted')
do i = 1,3
write(24,13) i, i+1
13 format(i5,i5)
end do
close(24)

open(2,file='ef.txt',form='formatted')
do i = 1,3
read(2,8) eta(i)
8 format(f18.10)
end do
close(2)

open(23,file='mu1.txt',form='formatted')
do i = 1,3
write(23,12) i, i-1
12 format(i5,i2)
end do
close(23)


end program Source1
 
IMO, you have problem reading the file ef.
Try to read without the format 8, simply
read(2,*) eta(i)

 
Typically when you open a file FORTRAN positions it so that you can write new rows at the end. Do the following to get it to the beginning

open(2,file='ef.txt',form='formatted')
rewind 2
do i = 1,3
read(2,8) eta(i)
8 format(f18.10)
end do
close(2)

You can also tell it you only want to read the file. You do this by the following code

open(2,file='ef.txt',form='formatted',STATUS='OLD', ACTION='READ') )
do i = 1,3
read(2,8) eta(i)
8 format(f18.10)
end do
close(2)



Bill
Lead Application Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top