! 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.9. Direct access input and output.
  program J09
    implicit none
    integer :: I, IOS, Code
    complex :: Bugle, Prism
    character (len = 15) :: String_1
! start program J09
    I = 77
    Code = 999
    Bugle = (123.4, 567.8)
    Prism = (-1.0, 0.0)
    String_1 = " Say it in eF. "
    open (unit = 3, file = "DA", access = "direct", form = "formatted", &
      recl = 112, status = "replace", action = "readwrite", iostat = IOS)
    if (IOS /= 0) then
      write (unit = *, fmt = *) " Can't open the file."
      stop
    end if
    write (unit = 3, fmt = "(2 i10, a16, 4 f16.8)", rec = 76) I, Code, String_1, Bugle, Prism
    write (unit = *, fmt = "(2 i10, a16, 4 f16.8)" ) I, Code, String_1, Bugle, Prism
    String_1 = "XXXXXXXXXXXXXXXXXXXX"
    read (unit = 3, fmt = "(2 i10, a16, 4 f16.8)", rec = 76) Code, I, String_1(3: 12), Prism, Bugle
    write (unit = *, fmt = "(2 i10, a16, 4 f16.8)" ) I, Code, String_1, Bugle, Prism
    stop
  end program J09
