FORTRAN Problem Runtime Error: End of File

In summary, the programmer was trying to read data from two files and count the number of values in each interval. If the value in x_min was greater than the value in x_next, then the program would increase the value of a by 1. If the value in y_min was greater than the value in y_next, then the program would increase the value of b by 1. Lastly, the program would write the data to a third file. If it encountered any errors, it would stop.
  • #1
karenmarie3
10
0
FORTRAN Problem! "Runtime Error: End of File"

Hey everyone, back again with another Fortran question.

I am getting the runtime error in Fortran "End of Line". I have tried to simply understand what this means, but I am not getting much help from Google.

I have pasted my code below, and highlighted the line that I understand the error exists. (in my terminal window, it's line 32) I am currently working on the latest distro of Ubuntu, and I am compiling with gfortran.

Could someone please assist me in correcting my error, as well as explain to me what this error means, so that I unserstand what to look for in the future? Also, if anyone knows of a good debugging tutorial or website that would be greatly appreciated as well.

This code is designed to read from an input file (x for now, eventually y as well) and count the number of values on an interval then write this data in another file so that I can create a histogram of the data.

If you need further clarification, please let me know.

Thanks in advance!


program histogram

implicit none

integer x_min, x_next, a, N, M
integer y_min, y_next , b, i, j
real x, y, z

real, dimension(4500, 4500, 4500, 4500) :: histo1
integer, dimension(4500, 4500, 4500, 4500) :: histo2

open(unit=2, file="xz.dat", action="read", status="old")
! open(unit=3, file="yz.dat", action="read"' status="old")
open(unit=7, file="xa.dat", action="write"' status="unknown")
! open(unit=8, file="yb.dat", action="write"' status="unknown")


x_min = -13

! y_min = -13

M = 13

N = 4209

do i = -13, M

do j = 1, N

read(2,*) x, z

! read(3,*) y, z

if (x .lt. (x_min + 1)) then

a = a + 1

! if (y .lt. (x_min + 1)) then

! b = b + 1

end if

end do


if (x .lt. (x_min + 1)) then

x_min = x_next

! if (y .lt. (y_min + 1)) then

! y_min = y_next

end if

end do


write(7,*) x, a

! write(8,*) y, b


close(2)
! close(3)
close(7)
! close(8)
stop
end program
 
Technology news on Phys.org
  • #2
Ok so I solved my runtime error by removing the 'z' in the read line. Now I just need to get the program to write all the data I require to my new file. I'll come back if I have issues with this.
 
  • #3
When you do, please use the
Code:
 tags to load your source files.  It helps in trying to track down errors.
 

What is a runtime error in FORTRAN?

A runtime error in FORTRAN refers to an error that occurs during the execution of a program. It can be caused by a variety of factors such as invalid input, logical errors, or memory issues.

What is a FORTRAN "End of File" error?

A FORTRAN "End of File" error occurs when the program reaches the end of a file that it is trying to read or write to. This can happen if the file is not properly formatted or if there is missing data.

How can I fix a FORTRAN runtime error?

The first step in fixing a FORTRAN runtime error is to identify the specific error message and the line of code where the error occurred. Then, you can debug the code by checking for any logical errors or incorrect data. It may also be helpful to use a debugger tool to track down the source of the error.

Why does my FORTRAN program keep encountering an "End of File" error?

If your FORTRAN program is repeatedly encountering an "End of File" error, it could be due to a logical error in your code. Make sure that you are properly managing input and output files, and that all necessary data is being read or written to the files.

How can I prevent "End of File" errors in FORTRAN?

To prevent "End of File" errors in FORTRAN, you can perform error checking and validation on input data to ensure that it is in the correct format. You can also use control statements to handle unexpected end-of-file situations and prompt the user for more input if needed.

Similar threads

  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
4
Views
614
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
19
Views
5K
  • Programming and Computer Science
Replies
2
Views
7K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
2
Views
24K
  • Programming and Computer Science
Replies
12
Views
7K
Back
Top