 program sodcig_rot

 use sep
! use sogrot_mod3c
! use sogrot_mod3d
 use sogrot_mod3a
! use sogrot_mod3z

 implicit none

 complex, allocatable				:: Ccig(:,:,:),temp(:,:,:)
 real, allocatable				:: sodcig(:,:,:), Rot_s_cig(:,:,:), Rot_g_cig(:,:,:)
 integer					:: stat, ikx, ikh, ikz
 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 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")

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

 open(unit=2,file='lixo')

 stat = fftvar_init(x, z, h)

 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,h%n,x%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)

 write(0,*) kz%n,kh%n,kx%n

 Ccig = sog_fft(sodcig) 
 deallocate(sodcig)

 !do ikx=1,kx%n
 !   do ikh=1,kh%n
 !      do ikz=1,kz%n
 !	  if (cabs(Ccig(ikz,ikh,ikx)) .ne. 0.) then
 !         write(2,*) kx%all(ikx), kh%all(ikh), kz%all(ikz), real(Ccig(ikz,ikh,ikx)), imag(Ccig(ikz,ikh,ikx))
 !	  end if
 !      end do
 !   end do
 !end do

 Rot_s_cig = sogrot_exe(Ccig,.true.)
 call srite("Rot_s_cig",Rot_s_cig, 4*z%n*h%n*x%n)
! call srite("Rot_s_cig",real(Ccig), 4*z%n*h%n*x%n)

 Rot_g_cig = sogrot_exe(Ccig,.false.)
 call srite("Rot_g_cig",Rot_g_cig, 4*z%n*h%n*x%n)
! call srite("Rot_g_cig",imag(Ccig), 4*z%n*h%n*x%n)

 close(2)

 call sep_end_prog()
 end program sodcig_rot
