Fortran77 end-of-file error reading formatted input

In summary, the conversation discusses a problem with reading a formatted file with six columns of data in Fortran. The speaker wants to use a do loop to read each row of data until the end of the file is reached, without receiving an "end of file" error. They mention that they do not fully understand the concepts of "sequential", "list directed", etc. and are seeking help. Another speaker suggests using a statement label and a do loop to read the data, but the first speaker encounters a syntax error and the do loop does not execute. The conversation concludes with the suggestion to post the program for further assistance.
  • #1
gcc2012
3
0
Hi,

I am new to the forum, apologies if I break any rule posting a new thread. I could not find the answer in similar threads came up after searching the forum.

I want to read a formatted file of six column data. Reading works OK, but I want to put it into a do loop with the repeat as many as number of lines(rows) in the file and stops when reaching the end without complaining about the 'end of file'. I find in various sites that there is END parameter that can be used in READ, WRITE statements, e.g.,

READ (UNIT=15, FMT=2000, END=999)
and '999' at the end of file, but this does not work..

I am not so much into Fortran, so I do not understand the explanations of 'sequential', 'list directed', etc. exceptions to using END. And I do not know any other way of handling this.
Any help would be great!

gcc2012
 
Technology news on Phys.org
  • #2
The 999 is a statement label in your program, not the data on the last line of the input file.

Do something like
Code:
do i = 1,n
  READ (UNIT=15, FMT=2000, END=999) a(i),b(i),c(i),d(i),e(i),f(i)
enddo
999 npoints = i - 1
where "npoints" will be the number of lines that you read from the file (or it will be equal to n, if the file contained more than n lines of data)
 
  • #3
Thanks AlephZero, I tried that way and it gives syntax error.
How would you read the data file organized as follows:

- sequential formatted
- six columns of real numbers
- number of rows are not always known

My immediate goal is to get the data read and each column would form an individual array. It is easy if one knows the number of lines. But, I did not see any elegant way of getting the number of rows and using it for do loops later, or getting the data read until end-of-file and code continues to run without 'end of file' error.

any suggestion?
 
  • #4
gcc2012 said:
I tried that way and it gives syntax error.
If you post the message, we might be able to help. If you don't, we can't.

How would you read the data file organized as follows:

- sequential formatted
- six columns of real numbers
- number of rows are not always known
I would do it the way I already posted.
 
  • #5
Thanks AlephZero.

I sorted out the syntax error, it was due to the variable type declaration.

But, now I have another problem. It does not execute the do loop at all. I print out 'npoints' and the value is 0.

What would be wrong?

No error message in this case.

gcc2012
 
  • #6
You need to post the program.
 

What is a Fortran77 end-of-file error reading formatted input?

A Fortran77 end-of-file error reading formatted input occurs when the program attempts to read data from a file and reaches the end of the file before all the data has been read. This can happen if the input file is shorter than expected or if the program has reached the end of the file prematurely due to an error.

What causes a Fortran77 end-of-file error reading formatted input?

There are several possible causes for this error, including incorrectly formatted data in the input file, an incorrect file name or path, or an error in the program's logic that causes it to stop reading the file prematurely. It can also occur if the program attempts to read data beyond the end of the file.

How can I fix a Fortran77 end-of-file error reading formatted input?

The first step in fixing this error is to check the input file for any formatting errors or missing data. If the file appears to be correct, then you may need to review the program's logic to ensure that it is correctly reading and processing the data from the file. You may also need to check the file name and path to ensure that the program is reading from the correct file.

How can I prevent Fortran77 end-of-file error reading formatted input?

To prevent this error, it is important to thoroughly test your program and input file before running it on a larger dataset. You should also ensure that your program has appropriate error handling to catch and handle any unexpected end-of-file errors. It is also important to regularly check and maintain your input files to ensure they are correctly formatted and contain all the necessary data.

Are there any resources available for troubleshooting Fortran77 end-of-file error reading formatted input?

Yes, there are many online resources available for troubleshooting Fortran77 end-of-file error reading formatted input, including forums, tutorials, and documentation. You can also consult with other Fortran programmers or reach out to the Fortran community for assistance. Additionally, your institution or workplace may have resources or experts available to help with troubleshooting Fortran errors.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
22
Views
3K
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
8
Views
808
  • Programming and Computer Science
Replies
6
Views
909
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top