! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 9.1. Exception handling.
  program J01
    implicit none
    integer :: Code, Input_Data
! start program J01
    open (unit = 1, file = "except.txt", status = "old", action = "read", position = "rewind")
    do
      read (unit = 1, fmt = *, iostat = Code) Input_Data
      if (Code < 0) then
         write (unit = *, fmt = *) " End of file: ", Code
      else if (Code > 0) then
         write (unit = *, fmt = *) " Input error: ", Code
      else
        write (unit = *, fmt = *) Input_Data
        cycle ! Skip the stop statement; begin the next iteration
      end if
      stop
    end do
    stop ! Never reached.
  end program J01
