Statement read*

why do someone uses
(just that, after for example after an error occured in reading a file or finishing a program)
is that to read a new file as replacement or continuation?

1 Like

The answer is dependent on how the program is compiled and run, but usually the following is the reason for placing a read * statement prior to program termination. When a Fortran program is run from a window environment, the added statement causes the program to pause and wait for input from the user before terminating the program. The user gets a chance to inspect the program output and take other action as needed before pressing the return key. Without the read * statement, the output window would get closed when the program terminated, and the user might not know what happened.

If the program is being run from a command shell, such a read * statement is not required.

1 Like

Hi @fallenengineer, welcome to the Fortran community.

The read * is used to read the input from command line.

For example, try to run this program:

implicit none
integer :: i
real :: r

! read the inputs
print*, "enter the integer: i"
read *, i
print*, "enter the real: r"
read *, r

! now print the inputs
print *, i
print *, r

Now: compile and execute:

gfortran test.f90 && ./a.out
 enter the integer: i
 enter the real: r
1 Like

I was actualy thinking what you think, but I am not so sure. Thank you