program main
  use sep
  implicit none
  integer, dimension(5) :: n_cube, j_wind, n_wind, f_wind
  integer               :: n_dim_cube, err
  integer               :: n1, n2, n3, n4, n5, i5
  integer, external     :: srite_window, sreed_window
  real, allocatable     :: dat(:,:,:,:)

  call initpar()
  
  call auxinout("image")

  call from_aux("image", "n1", n1)
  call from_aux("image", "n2", n2)
  call from_aux("image", "n3", n3)
  call from_aux("image", "n4", n4)
  call from_aux("image", "n5", n5)


  !call auxputch("n1", "i", n1, "image")
  !call auxputch("n2", "i", n2, "image")
  !call auxputch("n3", "i", n3, "image")
  !call auxputch("n4", "i", n4, "image")
  !call auxputch("n5", "i", n5, "image")

  !call to_history("n1", n1, "image")
  !call to_history("n2", n2, "image")
  !call to_history("n3", n3, "image")
  !call to_history("n4", n4, "image")
  !call to_history("n5", n5, "image")


  allocate(dat(n1, n2, n3, n4))

  dat = 5.

  n_dim_cube = 5
  n_cube = (/n1, n2, n3, n4, n5 /)
  j_wind = (/1, 1, 1, 1, 1/)
  n_wind = (/n1/2, n2/2, n3, n4, 1/)

  do i5=1, n5

     f_wind = (/0,0,0,0,i5-1/)

     err = srite_window("image",n_dim_cube,n_cube,n_wind,f_wind,j_wind,4,dat) 

     err = sreed_window("image",n_dim_cube,n_cube,n_wind,f_wind,j_wind,4,dat)
     !write(0,*)dat
     if (err .lt. 0) then
         write(0,*)"sreed_window: trouble in reading file", err
         stop
     end if
  end do
  
end program
