program test_direct_access
  implicit none

! Length in 4 byte units of one 8 byte real in an unformatted direct access file record.
  integer, parameter :: LEN_R64 = 2

  character(len=80) :: fn
  integer :: ios, rl, n, lu, i
  real(8), allocatable :: row(:)

  fn = 'test_da.dat'
  n  = 111
  rl = n*LEN_R64
  allocate(row(n))
  row = 99.0

  lu = 12
  open(unit=lu,             &
       file=fn,             &
       access='direct',     &
       form='unformatted',  &
       status='unknown',    &
       action='write',      &
       iostat=ios,          &
       recl=rl)

  if (ios/=0) then
    write(*,'(a)') " Unable to open output file "//trim(adjustl(fn))//"."
  end if

! Write the row of 8 byte reals to the unformatted direct access file.
  do i=1,100
    write(unit=lu , rec=i) row
  end do

  write(*,'(a)') " Success!"
  close(lu)

end program