 program sodcig_rot

 use sep
 use sogrot_mod1
! use sep3d_struct_mod

 implicit none

 complex, allocatable				:: transf_cig(:,:,:),temp(:,:,:)
 real, allocatable				:: sodcig(:,:,:)
 integer					:: ih,iz
 integer					:: npadx, npadz, npadh, stat
 type(axis)					:: x,z,h,kz,kx


 call sep_init()
 call sep_begin_prog()

 call from_history("n1",z%n); call from_history("d1",z%d); call from_history("o1",z%o)
 call from_history("n2",h%n); call from_history("d2",h%d); call from_history("o2",h%o)
 call from_history("n3",x%n); call from_history("d3",x%d); call from_history("o3",x%o)

! call to_history("n1",z%n); call to_history("d1",z%d); call to_history("o1",z%o)
! call to_history("n2",h%n); call to_history("d2",h%d); call to_history("o2",h%o)
! call to_history("n3",x%n); call to_history("d3",x%d); call to_history("o3",x%o)

 call from_param("npadz",npadz,int(z%n/4))
 call from_param("npadx",npadx,int(x%n/4))
 call from_param("npadz",npadh,int(h%n/4))

 allocate(sodcig(z%n,h%n,x%n),transf_cig(z%n+npadz,h%n+npadh,x%n+npadx))
 allocate(temp(z%n+npadz,h%n+npadh,x%n+npadx))
 call sogrot_init(npadz,npadx,npadh)

 stat = fftvar_init(x, z, h)

 call sreed("in", sodcig, 4*z%n*h%n*x%n)
! call sogrot_exe(sodcig)
! call srite("out",sodcig, 4*z%n*h%n*x%n)

 call to_history("n1",z%n+npadz); call to_history("d1",z%d); call to_history("o1",z%o)
 call to_history("n2",h%n+npadh); call to_history("d2",h%d); call to_history("o2",h%o)
 call to_history("n3",x%n+npadx); call to_history("d3",x%d); call to_history("o3",x%o)
 transf_cig = sog_fft(sodcig);
 temp=cmplx(0,0)
 do iz=1,z%n+npadz
    do ih=1,h%n+npadh
       if ((iz.lt.int((z%n+npadz)/2)+1).and.(ih.lt.int((h%n+npadh)/2)+1)) then
          temp(iz+int((z%n+npadz)/2),ih+int((h%n+npadh)/2),:)=transf_cig(iz,ih,:)
       else if ((iz.lt.int((z%n+npadz)/2)+1).and.(ih.gt.int((h%n+npadh)/2)+1)) then
          temp(iz+int((z%n+npadz)/2),ih-int((h%n+npadh)/2),:)=transf_cig(iz,ih,:)
       else if ((iz.gt.int((z%n+npadz)/2)+1).and.(ih.gt.int((h%n+npadh)/2)+1)) then
          temp(iz-int((z%n+npadz)/2),ih-int((h%n+npadh)/2),:)=transf_cig(iz,ih,:)
       else if ((iz.gt.int((z%n+npadz)/2)+1).and.(ih.lt.int((h%n+npadh)/2)+1)) then
          temp(iz-int((z%n+npadz)/2),ih+int((h%n+npadh)/2),:)=transf_cig(iz,ih,:)
       end if
    end do
 end do
 call sep_write(temp,"out",(z%n+npadz),(h%n+npadh),(x%n+npadx),8)

 call sep_end_prog()
 end program sodcig_rot
