 program sodcig4_rot
 use sep
 use sogrot_mod5

 implicit none

 complex, allocatable				:: Ccig(:,:,:),temp(:,:,:)
 real, allocatable				:: sodcig(:,:,:), Rot_s_cig(:,:,:), Rot_g_cig(:,:,:)
 integer					:: npadx, npadz, npadh, stat
 real						:: b
 type(axis)					:: x,z,h


 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))

! open(unit=2,file="lixo")

 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)

 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",kh%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",kx%n,"Rot_s_cig"); call to_history("d3",x%d,"Rot_s_cig"); call to_history("o3",x%o,"Rot_s_cig")

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

 allocate(sodcig(z%n,h%n,x%n),Ccig(kz%n,kh%n,kx%n),temp(kz%n,kh%n,kx%n))
 allocate(Rot_s_cig(z%n,kh%n,kx%n),Rot_g_cig(z%n,h%n,x%n))

 Rot_s_cig=0.;Rot_g_cig=0.
 sodcig=0.;Ccig=0.

 call sreed("in", sodcig, 4*z%n*h%n*x%n)
 Ccig = sog_fft(sodcig) 
! Rot_s_cig =  sog_ifft(Ccig) 
! temp = Ccig
! Ccig = rotsou_chk(temp)

! 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")
! call to_history("n1",kz%n,"Rot_g_cig"); call to_history("d1",kz%d,"Rot_g_cig"); call to_history("o1",kz%o,"Rot_g_cig")
! call to_history("n2",kh%n,"Rot_g_cig"); call to_history("d2",kh%d,"Rot_g_cig"); call to_history("o2",kh%o,"Rot_g_cig")
! call to_history("n3",kx%n,"Rot_g_cig"); call to_history("d3",kx%d,"Rot_g_cig"); call to_history("o3",kx%o,"Rot_g_cig")

! call srite("Rot_s_cig",real(Ccig), 4*kz%n*kh%n*kx%n)
! call srite("Rot_g_cig",imag(Ccig), 4*kz%n*kh%n*kx%n)

 deallocate(sodcig)

 Rot_s_cig = sogrot_exe(Ccig,.true.)
 call srite("Rot_s_cig",Rot_s_cig, 4*z%n*kh%n*kx%n)

 Rot_g_cig = sogrot_exe(Ccig,.false.)
 call srite("Rot_g_cig",Rot_g_cig, 4*z%n*kh%n*kx%n)

 call sep_end_prog()
 end program sodcig4_rot
