I am running the following code via an online Fortran compiler .
PROGRAM ONE
IMPLICIT NONE
REAL:: v
READ (*,*) v
IF ( sqrt(v) > 1. ) THEN
WRITE(*,*) 'At first: sqrt(v) > 1.'
ELSE IF ( sqrt(v) < 1. ) THEN
WRITE(*,*) 'At first: sqrt(v) < 1. '
ELSE
WRITE(*,*) 'At first: sqrt(v) == 1.'
END IF
END PROGRAM ONE
I get the following message.
$gfortran -std=gnu *.f95 -o main
$main
At line 7 of file main.f95 (unit = 5, file = 'stdin')
Fortran runtime error: End of file
Error termination. Backtrace:
#0 0x7fb0b576beda
#1 0x7fb0b576ca85
#2 0x7fb0b576d24d
#3 0x7fb0b58e3513
#4 0x7fb0b58dc459
#5 0x7fb0b58ddbb9
#6 0x400824
#7 0x4009bd
#8 0x7fb0b4c334d9
#9 0x400719
#10 0xffffffffffffffff
When you have a read statement like
READ (*,*) v
you may typically expect the program to pause, waiting for data from standard input . However, it's possible that a normal file has been redirected to standard input, in which case the program tries to read from that file. If that file is empty, then an end-of-file condition (see your runtime error message) will occur, rather than the program waiting.
In your case, with your online compiler, there is a tab next to the source code where you can enter the data which will be used as standard input. Unless you put the input here, you will see this failure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.