0

writing a very simple read file in Fortran 95. The file has only three numbers in it, every time I run the code, the .exe file says "error: attempt to read end-of-file at address", any clues why this keeps happening?

The code is :

program readdata

implicit none

!Delcaration of variables

real :: x,y,z

!Main part

open (10, file='C:\Users\matth\OneDrive\Documents\Tutorialcode\array.txt',ACCESS='SEQUENTIAL', STATUS='OLD', FORM='FORMATTED')

read (10, *) x, y, z

print *,x,y,z

close (10)

end program readdata
  • 2
    You'd also have to post the _file_. – Armali Jan 31 '20 at 14:29
  • 2
    Test the following: in a terminal, go to the director "C:\Users\matth\OneDrive\Documents\Tutorialcode". Change the "open" statement to only use "array.txt". Test again. There might be an issue with the path to the file (backslashes instead of slashes, etc). – Pierre de Buyl Jan 31 '20 at 14:33
  • 1
    Also, please provide the compiler, the command invoked to compile the code and the command used to execute the code. – Pierre de Buyl Jan 31 '20 at 14:34
  • 1
    Welcome, please take the [tour]. When debugging, please compile your code with debugging flags enabled (for example `gfortran -g -Wall -fcheck=all`) and post the *complete* error output here. Do not just select a sentence, but tell us all the details. We certainly need to see your input file here. I also suggest to use forward slashes for your paths, they do work on Windows. – Vladimir F Героям слава Jan 31 '20 at 14:52
  • 1
    Hello everybody. The input file was a simple .txt file with the numbers: 1.00, 2.00, 3.00 in the file in a list. The compiler I am working with is checkmate as it’s part of the Silverfrost free download so that’s what I’m using. The code seems to compile good, builds and links the only problem arises when executing. I don’t have access to the whole warning code right now but will tomorrow, Hope this makes sense? Everything from compiling to executing done with silverfrost free download – Matthew19 Feb 01 '20 at 15:28
  • The input file is a simple text file with the numbers: 1.00, 2.00, 3.00 in it. – Matthew19 Feb 03 '20 at 10:11
  • Attempt to read past end-of-file at address 1c0086e1 Within file readdata2.exe in READDATA2 in line 6, at address e8 RAX = 0000000000000039 RBX = 0000000000000039 RCX = 0000000000000039 RDX = 0000000000000000 RBP = 000000001c000000 RSI = 0000000000000039 RDI = 00000000001fa0b0 RSP = 000000000240f9d0 R8 = 00000000000000a1 R9 = 00000000000000a1 R10 = 000000000000009e R11 = 000000000240f6e0 R12 = 0000000000000000 R13 = 0000000000000003 R14 = 00000000004050a0 R15 = 0000000000405098 1c0086e1) int9 – Matthew19 Feb 03 '20 at 10:11
  • The compiler is CHECKMATE and SLINK is the linker – Matthew19 Feb 03 '20 at 10:14
  • Error message:***57 Attempt to read past end-of-file at location main - in file readdata2.f95 at line 6 [+00b0] line 6: read(10,*) a,b,c – Matthew19 Feb 03 '20 at 10:20

1 Answers1

0

I have loaded your code into my Eclipse IDE, using GNU Fortran.

I confirm that the code compiles, without error or warning, and runs as advertised.

With an array.txt file of:

1.00, 2.00, 3.00

I get output:

1.00, 2.00, 3.00

With an empty file I get:

At line 13 of file ../readdata.f90 (unit = 10, file = 'C:\Users\franc\array.txt')
Fortran runtime error: End of file

Error termination. Backtrace:

Could not print backtrace: libbacktrace could not find executable to open
#0  0xffffffff
#1  0xffffffff
#2  0xffffffff
#3  0xffffffff
#4  0xffffffff
#5  0xffffffff
#6  0xffffffff
#7  0xffffffff
#8  0xffffffff
#9  0xffffffff
#10  0xffffffff
#11  0xffffffff
#12  0xffffffff
#13  0xffffffff
#14  0xffffffff

So, my suspicion is over whether your file is missing some values.

Please also see:

Fortran 90 - Attempt to read past end of file

Francis King
  • 1,652
  • 1
  • 7
  • 14