Contact US

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.

Students Click Here

Terminating reading of .txt file

Terminating reading of .txt file

Terminating reading of .txt file

Hey everyone!

I'm new to fortran and would like to get some help from you pros out there! It would really help a bunch.

Basically, my problem is that I have a .txt file, of unknown number of rows, which contains data in the following format:

equipment(a), value1, value2, value3, value4
equipment(b), value1, value2, value3, value4
equipment(c), value1, value2, value3, value4

I have no problems reading the data I need using the following code in a DO loop:
READ (1,*) equipment, a, b, c, d

However, I get an error when I want to terminate reading the .txt file. I'm currently using this syntax to exit:
IF (equipment=="END") EXIT

Are there any ways to terminate upon reading the "END" line? Your help is much appreciated! Thank you :)

RE: Terminating reading of .txt file

for example something like this:


  integer :: stat
  ! open input file

    read(10,*,end=99, iostat=stat) my_val01, my_val02, ...
    if (stat .ne. 0) then
      write(*,*) 'Error reading data !'
      go to 99
    end if
    call process_my_data
  end do

  ! close file
  99 continue
  close (10)

RE: Terminating reading of .txt file

Thank you so much !

It works wonders :)

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! Already a Member? Login

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