! 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 5.5. (File input.) Program with module subroutine Swap.
  program F05
    use F05M
    implicit none
    integer :: Loop, EoF, I, J
! start program F05
    open (unit = 1, file = "array.txt", status = "old", action = "read", position = "rewind")
    do Loop = 1, ARRAY_SIZE
      read (unit = 1, fmt = *, iostat = EoF) Data_Array(Loop)
      if (EoF < 0) then
        write (unit = *, fmt = *) " Insufficient data in file. "
        stop
      end if
    end do
    write (unit = *, fmt =*) " Please enter subscripts of elements to be swapped. "
    read (unit = *, fmt =*) I, J
    call Swap( I, J )
    write (unit = *, fmt = *) Data_Array
    stop
  end program F05
