# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "<stdin>"
program reduce_it
  use reshape_mod
  use sep
  implicit none
  integer :: n(3),ns(3)
  integer :: i,ndo
  real :: o(3),os(3),d(3),ds(3)
  type(sep3d) :: input,output
  real, pointer :: semb(:,:,:),wt(:,:,:)
  call init_sep3d("in",input,"INPUT")
  ns=1
  call from_param("ns",ns)
  call from_param("os",os)
  call from_param("ds",ds)
  call init_sep3d(output,"OUTPUT","FLOAT","REGULAR",ns,os,ds)
  call sep3d_write_description("out",output)
  i=sep3d_ndims(input)
  if (ns(3).eq.1 .and. i >2) then
    call sep_put_data_axis_par("out",i,input%n(i),input%o(i),input%d(i&
      &),input%label(i))
  end if
  n(1:2)=input%n(1:2)
  o(1:2)=input%o(1:2)
  d(1:2)=input%d(1:2)
  if (sep3d_ndims(input)<4) then
    n(3)=1
    o(3)=0
    d(3)=1
  else
    n(3)=input%n(3)
    o(3)=input%o(3)
    d(3)=input%d(3)
  end if
  ndo=input%n(sep3d_ndims(input))
  if (sep3d_ndims(input).eq.2) then
    ndo=1
  end if
  allocate(semb(ns(1),ns(2),ns(3)))
  do i=1,ndo
    semb=0.
    if (.not. shrink_image_tag("in",n,o,d,ns,os,ds,semb)) then
      write(0,*) "trouble shrinking image",i
      call seperr("")
    end if
    write(0,*) "CHECK SUM",sum(semb),i,ndo,ns
    call srite("out",semb,size(semb)*4)
  end do
end program
