 program sod2adcig
 use sep
 use sod2adcig_mod

 implicit none

 complex, allocatable				:: Ccig(:,:,:)
 real, allocatable				:: sodcig(:,:,:), adcig(:,:,:)
 integer					:: npadx, npadz, npadh, stat
 type(axis)					:: x,z,h, gama1


 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("amin",gama1%o,-60.)
 call from_param("nang",gama1%n,121)
 call from_param("dang",gama1%d,1.)

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

 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 so2adcig_init(npadz,npadx,npadh)
 stat = fftvar_init(gama1,x, z, h)

 allocate(sodcig(z%n,h%n,x%n),Ccig(kz%n,kh%n,x%n))
 allocate(adcig(z%n,gama%n,x%n))
 adcig=0.
 sodcig=0.;Ccig=0.

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

 write(0,*) "passei 01"
 Ccig = adcig_fft(sodcig) 
 write(0,*) "passei 02"

 deallocate(sodcig)

 adcig = so2adcig_exe(Ccig)
!!!!
!
! testando ...
!
!deallocate(adcig)
! allocate(adcig(kz%n,gama%n,x%n))
!  adcig = imag(do_adcig(Ccig))
!!!!
 write(0,*) "passei 03"

 call srite("adcig",adcig, 4*z%n*gama%n*x%n)
 write(0,*) "passei 04"

 call sep_end_prog()
 end program sod2adcig
