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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Data from Text Files

Status
Not open for further replies.

carbontrek

Programmer
Aug 15, 2014
1
US
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.
 
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.

 
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?).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top