-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfftw_3d_release.f90
115 lines (90 loc) · 2.96 KB
/
fftw_3d_release.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
!************************************************************
! This program calculated 3d Fourier transform for arbitray *
! dimensions using FFTW library BASIC interface- *
! Fortran interface & C interface. *
! While using C interface dimension are reversed accounting *
! to difference of C & Fortran arrays. *
!************************************************************
module fftw_basic_interface
contains
subroutine fftw_3d(input)
#ifdef __CINTERFACE__
use, intrinsic :: iso_c_binding
#endif
implicit none
integer nx,ny,nz
parameter(nx=4,ny=4,nz=4)
#ifdef __FINTERFACE__
integer*8 plan_3d_forward, plan_3d_backward
double complex input(nx,ny,nz)
#endif
#ifdef __CINTERFACE__
type(C_PTR) plan_3d_forward, plan_3d_backward
complex(C_DOUBLE_COMPLEX) input(nx,ny,nz)
#endif
#ifdef __CINTERFACE__
include 'fftw3.f03'
#endif
#ifdef __FINTERFACE__
include 'fftw3.f'
#endif
! Forward 3 D FFT
#ifdef __FINTERFACE__
call dfftw_plan_dft_3d(plan_3d_forward,nx,ny,nz,input,input,&
FFTW_FORWARD,FFTW_ESTIMATE)
call dfftw_execute_dft(plan_3d_forward,input,input)
call dfftw_destroy_plan(plan_3d_forward)
#endif
#ifdef __CINTERFACE__
plan_3D_forward = fftw_plan_dft_3d(nz,ny,nx,input,input, &
FFTW_FORWARD,FFTW_ESTIMATE)
call fftw_execute_dft(plan_3d_forward,input,input)
call fftw_destroy_plan(plan_3d_forward)
#endif
! Backward 3D FFT
#ifdef __FINTERFACE__
call dfftw_plan_dft_3d(plan_3d_backward,nx,ny,nz,input,input,&
FFTW_BACKWARD,FFTW_ESTIMATE)
call dfftw_execute_dft(plan_3d_backward,input,input)
call dfftw_destroy_plan(plan_3d_backward)
#endif
#ifdef __CINTERFACE__
plan_3d_backward = fftw_plan_dft_3d(nz,ny,nx,input,input,&
FFTW_BACKWARD,FFTW_ESTIMATE)
call fftw_execute_dft(plan_3d_backward,input,input)
call fftw_destroy_plan(plan_3d_backward)
#endif
end
end
program ft
use fftw_basic_interface
implicit none
include 'fftw3.f'
integer n,i
parameter(N=64)
double complex input(N)
! Data filling
do i=1,n
input(i) = i
end do
#ifdef __FINTERFACE__
print*, 'Data before forward fft using fftw fortran interface',&
input
#endif
#ifdef __CINTERFACE__
print*, 'Data before forward fft using fftw C interface',input
#endif
call fftw_3d(input)
! Normalization -Note -FFTW produces un-normalized output
do i=1,n
input(i) = input(i)/DBLE(N)
end do
#ifdef __FINTERFACE__
print*, 'Data after backward fft using fftw BASIC fortran &
interface', input
#endif
#ifdef __CINTERFACE__
print*, 'Data after backward fft using fftw BASIC C interface',&
input
#endif
end