INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

a beginner's question, input/output of fortran

a beginner's question, input/output of fortran

(OP)
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

RE: a beginner's question, input/output of fortran

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

RE: a beginner's question, input/output of fortran

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close