program OWfft5d

use sep 
use OW_type
use OW_exec_time
use OW_parms_areal
use OW_fftw_areal
implicit none

real, allocatable					:: B_image(:,:,:,:,:)
real                                                        :: start,finish
complex, allocatable				:: tfld3(:,:,:,:,:),D_image(:,:,:,:,:)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 call sep_init()
 call sep_begin_prog()
 call owparam()

    call owexec_time(start)
    allocate(tfld3(img%z%n,nsecdim,1,img%xm%n,img%ym%n));tfld3=0.
    call owfftw3(tfld3)
    call owexec_time(finish)
    write(0,*) "Finished initialization in", (finish-start)/60," min"
    call owexec_time(start)
    if (esize==4) then
       allocate(B_image(img%z%n,nsecdim,1,img%xm%n,img%ym%n));B_image=0.
       call sreed("in",B_image,4*img%xm%n*nsecdim*img%z%n*img%ym%n)
       tfld3=cmplx(B_image,0.)
       call owfft3Fexe(tfld3)
       tfld3=tfld3/sqrt(1.*img%xm%n*nsecdim*img%z%n*img%ym%n)
       call srite("out",tfld3,8*img%xm%n*nsecdim*img%z%n*img%ym%n)
       call owfftdestroy3()
       deallocate(tfld3,B_image)
    else
       allocate(D_image(img%z%n,nsecdim,1,img%xm%n,img%ym%n));D_image=0.
       call sreed("in",D_image,4*img%xm%n*nsecdim*img%z%n*img%ym%n)
       tfld3=D_image
       call owfft3Iexe(tfld3)
       tfld3=tfld3/sqrt(1.*img%xm%n*nsecdim*img%z%n*img%ym%n)
       call srite("out",real(tfld3),4*img%xm%n*nsecdim*img%z%n*img%ym%n)
       call owfftdestroy3()
       deallocate(tfld3,D_image)
    end if
    call owexec_time(finish)
    write(0,*) "Finished processing in", (finish-start)/60," min"
 call sep_end_prog()
end program
