 program sodcig_rot_fft

 use sep
! use sogrot_mod1
! use sogrot_mod2
! use sogrot_mod3_fft
! use sogrot_mod3
 use sogrot_mod3a
! use sogrot_mod4
! use sep3d_struct_mod

 implicit none

 integer					:: test_fft
 complex, allocatable				:: transf_cig(:,:,:)
 real, allocatable				:: sodcig(:,:,:), Rot_s_cig(:,:,:), Rot_g_cig(:,:,:)
!
!
 real, allocatable				:: cig_out(:,:,:)
 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 from_param("npadz",npadz,int(z%n/4))
 call from_param("npadx",npadx,int(x%n/4))
 call from_param("npadh",npadh,int(h%n/4))
 call from_param("test_fft",test_fft)

 if (mod(x%n+npadx,2) == 1) then
    npadx=npadx+1
 end if
 if (mod(h%n+npadh,2) == 1) then
    npadh=npadh+1
 end if
 if (mod(z%n+npadz,2) == 1) then
    npadz=npadz+1
 end if

 call sogrot_init(npadz,npadx,npadh)
 stat = fftvar_init(x, z, h)

 allocate(sodcig(z%n,h%n,x%n),transf_cig(z%n+npadz,h%n+npadh,x%n+npadx))
 sodcig=0.;transf_cig=0.

 call sreed("in", sodcig, 4*z%n*h%n*x%n)

 if(test_fft==1) then
   allocate(Rot_s_cig(z%n,h%n,x%n))
   call to_history("n1",z%n,"Rot_s_cig"); call to_history("d1",z%d,"Rot_s_cig"); call to_history("o1",z%o,"Rot_s_cig")
   call to_history("n2",h%n,"Rot_s_cig"); call to_history("d2",h%d,"Rot_s_cig"); call to_history("o2",h%o,"Rot_s_cig")
   call to_history("n3",x%n,"Rot_s_cig"); call to_history("d3",x%d,"Rot_s_cig"); call to_history("o3",x%o,"Rot_s_cig")
   transf_cig = sog_fft(sodcig)
   Rot_s_cig = sog_ifft(transf_cig)
   call srite("Rot_s_cig",Rot_s_cig, 4*z%n*h%n*x%n)
 else if(test_fft==2) then  
   allocate(Rot_s_cig(kz%n,kh%n,kx%n))
   call to_history("n1",kz%n,"Rot_s_cig"); call to_history("d1",kz%d,"Rot_s_cig"); call to_history("o1",kz%o,"Rot_s_cig")
   call to_history("n2",kh%n,"Rot_s_cig"); call to_history("d2",kh%d,"Rot_s_cig"); call to_history("o2",kh%o,"Rot_s_cig")
   call to_history("n3",kx%n,"Rot_s_cig"); call to_history("d3",kx%d,"Rot_s_cig"); call to_history("o3",kx%o,"Rot_s_cig")
   transf_cig = sog_fft(sodcig)
   Rot_s_cig = cabs(transf_cig)
   call srite("Rot_s_cig",Rot_s_cig, 4*kz%n*kh%n*kx%n)
 else if(test_fft==3) then  
   allocate(Rot_s_cig(kz%n,kh%n,kx%n))
   call to_history("n1",kz%n,"Rot_s_cig"); call to_history("d1",kz%d,"Rot_s_cig"); call to_history("o1",kz%o,"Rot_s_cig")
   call to_history("n2",kh%n,"Rot_s_cig"); call to_history("d2",kh%d,"Rot_s_cig"); call to_history("o2",kh%o,"Rot_s_cig")
   call to_history("n3",kx%n,"Rot_s_cig"); call to_history("d3",kx%d,"Rot_s_cig"); call to_history("o3",kx%o,"Rot_s_cig")
   transf_cig = sog_fft(sodcig)
   Rot_s_cig = cabs(rotsou_geodip(transf_cig))
   call srite("Rot_s_cig",Rot_s_cig, 4*kz%n*kh%n*kx%n)
 end if

 call sep_end_prog()
 end program sodcig_rot_fft
