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

Reading Data from Text Files

Reading Data from Text Files

(OP)
Hi All,

I'm doing some self study from a book written by Brian Hahn (Fortran 90 for Scientists and Engineers).

There is a section that is particularly talking about reading data from text files.
I'm on a mac and compiling using gfortran filename.f90[/b] then running ./a.out on the following:

PROGRAM Practice

OPEN (1, FILE = 'DATA')
READ(1, *) A, B, C
PRINT*, A, B, C

END PROGRAM Practice

So using text edit I saved a file (DATA) with the line 3 4 5.

When I try to run this, I get a runtime error: end of file

I would like to figure out how I'm actually supposed to do this since the rest of the book problems are reading in files like this.

RE: Reading Data from Text Files

First thing to try is to make sure that there is "room" after the last number (the 5). So, either add a few extra spaces after the 5 or, better yet, get into the habit of ending your files with the end-of-file character in its own line and not right after the last entry.

RE: Reading Data from Text Files

Also, Fortran is not case sensitive and it does not require ALL UPPERCASE; so, I would suggest lower case for all fortran commands/statements and reserve upper case for certain variables that warrant it, possibly followed with lower case to indicate some kind of subscript; maybe even camelCase here and there, if you like it.

Using all uppercase makes the screen look so crowded and difficult to read...this is one of those arguments people who like trashing Fortran use...let's stop giving them ammunition and show them that Fortran can look rather pretty, easy to read, without unnecessary ornaments (semicolon anyone?).


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