If the iostat
keyword is present, a program does not stop if an I/O error occurs. Then, if I try to read an improper value into a scalar variable, i
say, will this variable remain unchanged? The following seems to work:
program test
integer :: i, stat
i = 1
do
write (*, "('i = ')", advance='no')
read (*, *, iostat=stat) i
if (stat .eq. 0) then
write (*, "('Valid integer. i has been set to ', I0)") i
else
write (*, "('Bad integer. i is still ', I0)") i
end if
end do
end program test
Can I rely on this behavior in Fortran 2003?