! 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.11. Formatted internal data transfer.
  program J11
    use J11M
    implicit none
    character (len = 79) :: Buffer
    real, dimension(13) :: Z
    real :: Answer
    integer :: N, EoF
! start program J11
    open (unit = 1, file = "j11.txt", status = "old", action = "read", position = "rewind")
    N = 0
    do
      N = N + 1
      read (unit = 1, fmt = "( a79)", iostat = EoF) Buffer  ! External input (formatted)
      if (EoF /= 0) then
         exit
      else if (Buffer(1 : 1) == "C") then
        write (unit = *, fmt = *) Buffer(2 : )  ! External output
      else if (Buffer(1: 1) == " ") then
        read (unit = Buffer, fmt = "(tr1, 13 f6.3)" ) Z  ! Internal data transfer
        write (unit = *, fmt = *) Z
        call Calc( Z, Answer )
        write (unit = *, fmt = *) Answer
      else
        write (unit = *, fmt = *) " Column 1 is not blank or C at record number ", N
      end if
    end do
    stop
  end program J11
