!!.. input : z-x-y
!!.. output: kz-kx-ky
program main
  use base_struct_mod
  implicit none

  integer                                :: sign1, sign2, sign3
  integer                                :: n1, n2, n3
  complex, dimension(:)    , allocatable :: vec1, vec2, vec3
  complex, dimension(:,:,:), allocatable :: cdat
  logical                                :: do1, do2, do3
  call sep_init()

  call from_history("n1", a1%n); call from_history("d1", a1%d); call from_history("o1", a1%o)
  call from_history("n2", a2%n); call from_history("d2", a2%d); call from_history("o2", a2%o)
  call from_history("n3", a3%n); call from_history("d3", a3%d); call from_history("o3", a3%o)

  call from_param("sign1", sign1, 0); do1 = (sign1/=0 .and. n1>1)
  call from_param("sign2", sign2, 0); do2 = (sign2/=0 .and. n2>1)
  call from_param("sign3", sign3, 0); do3 = (sign3/=0 .and. n3>1)

  call from_param("n1pad_beg", n1pad_beg, 0); call from_param("n1pad_end", n1pad_end, 0)
  call from_param("n2pad_beg", n2pad_end, 0); call from_param("n2pad_end", n2pad_end, 0)
  call from_param("n3pad_beg", n3pad_beg, 0); call from_param("n3pad_end", n3pad_end, 0)

  nk1 = a1%n + n1pad_beg + n1pad_end
  nk2 = a2%n + n2pad_beg + n2pad_end
  nk3 = a3%n + n3pad_beg + n3pad_end

  


  call to_history("n1", )


  allocate(cdat( nk1, nk2, nk3))
  allocate(vec1(nk1), vec2(nk2), vec3(nk3))

  call sep_read(cdat)

  write(0,*)"generating plans..."
  !!.. 1st dimension
  if (sign1 == +1) then
     call sfftw_plan_dft_1d(plan_1dx_vec1, n1, vec1, vec1, FFTW_FORWARD , FFTW_MEASURE)
  else
     call sfftw_plan_dft_1d(plan_1dx_vec1, n1, vec1, vec1, FFTW_BACKWARD, FFTW_MEASURE)
  end if
  !!.. 2nd dimension
  if (sign2 == +1) then
     call sfftw_plan_dft_1d(plan_1dx_vec2, n2, vec2, vec2, FFTW_FORWARD , FFTW_MEASURE)
  else
     call sfftw_plan_dft_1d(plan_1dx_vec2, n2, vec2, vec2, FFTW_BACKWARD, FFTW_MEASURE)
  end if
  !!.. 3rd dimension
  if (sign3 == +1) then
     call sfftw_plan_dft_1d(plan_1dx_vec1, n3, vec3, vec3, FFTW_FORWARD , FFTW_MEASURE)
  else
     call sfftw_plan_dft_1d(plan_1dx_vec1, n3, vec3, vec3, FFTW_BACKWARD, FFTW_MEASURE)
  end if

  if (do1) then
     do i3=1, n3
     do i2=1, n2
        vec1 = cdat(:,i2,i3)
        call sfftw_execute(plan_1dx_vec1)
        cdat(:,i2,i3) = vec1
     end do
     end do
  end if

  if (do2) then
     do i3=1, n3
     do i1=1, n1
        vec2 = cdat(i1,:,i3)
        call sfftw_execute(plan_1dx_vec2)
        cdat(i1,:,i3) = vec2
     end do
     end do
  end if

  if (do3) then
     do i2=1, n2
     do i1=1, n1
        vec3 = cdat(i1,i2,:)
        call sfftw_execute(plan_1dx_vec3)
        cdat(i1,i2,:) = vec3
     end do
     end do
  end if

  call sep_write(cdat)


end program













