  real*8, allocatable :: array(:,:,:)
!
  integer*4 wl, length, i,j,k, iostat, rec
  integer*4 ni,nj,nk
  real*4    elapse_sec, dtime, t
  external  elapse_sec, dtime
!
  t = elapse_sec ()
  write (*,*) 'Start of test    ', dtime()
!
  ni = 22
  nj = 7826
  nk = 8086
!
! *** Compiler dependent ***
  wl     = 2           ! number of 4-byte units in a single real(8) array
!
  length = ni*wl       ! the length of each record
!
  open (unit=11, file='write_test_22.bin', access='direct', recl=length, iostat=iostat)
  write (*,*) 'Opened file      ', dtime()

  allocate ( array(ni,nj,nk) )
  write (*,*) 'Allocated array  ', dtime()
!
  array = 1
  write (*,*) 'Initialised array', dtime()
!  
  rec = 0
  do K = 1, nk
    do J = 1,nj
      rec = rec+1
      write (11, rec=rec) (array(i,j,k),i=1,ni)
    end do
  end do
  write (*,*) 'write array      ', dtime()
!  
  do K = 1, nk
    do J = 1,nj
      rec = j + (k-1)*nj
      read (11, rec=rec) (array(i,j,k),i=1,ni)
    end do
  end do
  write (*,*) 'read array       ', dtime()
!
  write (*,*) 'total test time =', elapse_sec() - t
  end

real*4 function dtime ()
  real*4 :: last = -1
  real*4 :: elapse_sec, t
!
  t = elapse_sec ()
  if ( last < 0 ) last = t
  dtime = t - last
  last  = t 
end function dtime

real*4 function elapse_sec ()
  integer*8 :: clock, tick
!
  call system_clock ( clock, tick )
  elapse_sec = real (clock) / real (tick)
end function elapse_sec