program OW_3dslant
! 3D-linear Radon transform

  use sep
  use OW_type
  use OW_sltpar
  use OW_3dslt
  use OW_3drot
!  use solver_tiny_mod1
!  use solver_prc_mod 
!  use igrad1
!  use cgstep_mod1

  implicit none

  real, allocatable, dimension (:)		:: in,out
  integer					:: stat,ix,ih,iz,ind,ozchunk

  call sep_init()
  call sep_begin_prog()
  call owsltpar()
  allocate(in(sog%z%n*sog%sh%n*sog%xm%n))
  call sreed("in",in,4*sog%z%n*sog%sh%n*sog%xm%n)
  if (teste) then
     if (upshft) then
        allocate(out(nz*sog%sh%n*nah*nax*sog%xm%n))
     else
        allocate(out(nz*nah*nax*sog%xm%n))
     end if
     stat = ow3dslant(.true.,.false.,out,in)
     stat = ow3dslant(.false.,.false.,out,in)
     call srite("out",in,4*sog%z%n*sog%sh%n*sog%xm%n)
  else if (rot) then
     if (upshft) then
        allocate(out(nz*sog%sh%n*nah*nax*sog%xm%n))
     else
        allocate(out(nz*nah*nax*sog%xm%n))
     end if
     stat = ow3dslant(.true.,.false.,out,in)
!     deallocate(in)
!     allocate(in(nz*sog%sh%n*sog%xm%n))
     stat = ow3drot(.true.,.false.,in,out)
!     call srite("out",in,4*nz*sog%sh%n*sog%xm%n)
     call srite("out",in,4*sog%z%n*sog%sh%n*sog%xm%n)
  else
     if (upshft) then
        do iz=1,nzchunk+1
           ozchunk=(iz-1)*zchunk+1
           if (zremain.ne.0.and.iz.eq.nzchunk+1) then
              if (allocated(out)) deallocate(out)
              allocate(out(zremain*sog%sh%n*nah*nax*sog%xm%n))
              out=0
              stat = ow3dslant_init(ozchunk,zremain)
              stat = ow3dslant(.true.,.false.,out,in)
              call srite_window("out",5,(/sog%xm%n,sog%sh%n,nah,nax,nz/),&
                                    (/sog%xm%n,sog%sh%n,nah,nax,zremain/),&
                                    (/0,0,0,0,ozchunk-1/),(/1,1,1,1,1/),4,out)
           else
              if (allocated(out)) deallocate(out)
              allocate(out(zchunk*sog%sh%n*nah*nax*sog%xm%n))
              out=0
              stat = ow3dslant_init(ozchunk,zchunk)
              stat = ow3dslant(.true.,.false.,out,in)
              call srite_window("out",5,(/sog%xm%n,sog%sh%n,nah,nax,nz/),&
                                    (/sog%xm%n,sog%sh%n,nah,nax,zchunk/),&
                                    (/0,0,0,0,ozchunk-1/),(/1,1,1,1,1/),4,out)
           end if
        end do
     else
        do iz=1,nzchunk+1
           ozchunk=(iz-1)*zchunk+1
           if (zremain.ne.0.and.iz.eq.nzchunk+1) then
write(0,*) iz,ozchunk,zremain
              if (allocated(out)) deallocate(out)
              allocate(out(zremain*nah*nax*sog%xm%n))
              out=0
              stat = ow3dslant_init(ozchunk,zremain)
              stat = ow3dslant(.true.,.false.,out,in)
              call srite_window("out",4,(/sog%xm%n,nah,nax,nz/),&
                                    (/sog%xm%n,nah,nax,zremain/),&
                                    (/0,0,0,ozchunk-1/),(/1,1,1,1/),4,out)
           else
write(0,*) iz,ozchunk,zchunk
              if (allocated(out)) deallocate(out)
              allocate(out(zchunk*nah*nax*sog%xm%n))
              out=0
              stat = ow3dslant_init(ozchunk,zchunk)
              stat = ow3dslant(.true.,.false.,out,in)
              call srite_window("out",4,(/sog%xm%n,nah,nax,nz/),&
                                    (/sog%xm%n,nah,nax,zchunk/),&
                                    (/0,0,0,ozchunk-1/),(/1,1,1,1/),4,out)
           end if
        end do
     end if
  end if
  deallocate(in,out)
  call sep_end_prog()
end program 
