Fortran · File status code
What does IOSTAT -1 — End-of-File Condition mean in Fortran?
Returned by the IOSTAT= specifier on a READ when the statement tries to pull data past the last record of the file, i.e. end-of-file is reached before the input list is satisfied. The standard only requires this value be negative and distinct from the end-of-record value; -1 is simply what both Intel Fortran and gfortran use in practice. It never appears on WRITE or on a READ that has an END= specifier, since that branches control away before IOSTAT is even checked.
Returned by the IOSTAT= specifier on a READ when the statement tries to pull data past the last record of the file, i.e. end-of-file is reached before the input list is satisfied. The standard only requires this value be negative and distinct from the end-of-record value; -1 is simply what both Intel Fortran and gfortran use in practice. It never appears on WRITE or on a READ that has an END= specifier, since that branches control away before IOSTAT is even checked.
Test IOSTAT for a negative value (or better, compare against ISO_FORTRAN_ENV's IOSTAT_END constant or call IS_IOSTAT_END()) and exit the read loop cleanly instead of treating it as a fatal error.