d@0
|
1 <html lang="en">
|
d@0
|
2 <head>
|
d@0
|
3 <title>Fortran Examples - FFTW 3.2.1</title>
|
d@0
|
4 <meta http-equiv="Content-Type" content="text/html">
|
d@0
|
5 <meta name="description" content="FFTW 3.2.1">
|
d@0
|
6 <meta name="generator" content="makeinfo 4.8">
|
d@0
|
7 <link title="Top" rel="start" href="index.html#Top">
|
d@0
|
8 <link rel="up" href="Calling-FFTW-from-Fortran.html#Calling-FFTW-from-Fortran" title="Calling FFTW from Fortran">
|
d@0
|
9 <link rel="prev" href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran" title="FFTW Execution in Fortran">
|
d@0
|
10 <link rel="next" href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f" title="Wisdom of Fortran?">
|
d@0
|
11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
d@0
|
12 <!--
|
d@0
|
13 This manual is for FFTW
|
d@0
|
14 (version 3.2.1, 5 February 2009).
|
d@0
|
15
|
d@0
|
16 Copyright (C) 2003 Matteo Frigo.
|
d@0
|
17
|
d@0
|
18 Copyright (C) 2003 Massachusetts Institute of Technology.
|
d@0
|
19
|
d@0
|
20 Permission is granted to make and distribute verbatim copies of
|
d@0
|
21 this manual provided the copyright notice and this permission
|
d@0
|
22 notice are preserved on all copies.
|
d@0
|
23
|
d@0
|
24 Permission is granted to copy and distribute modified versions of
|
d@0
|
25 this manual under the conditions for verbatim copying, provided
|
d@0
|
26 that the entire resulting derived work is distributed under the
|
d@0
|
27 terms of a permission notice identical to this one.
|
d@0
|
28
|
d@0
|
29 Permission is granted to copy and distribute translations of this
|
d@0
|
30 manual into another language, under the above conditions for
|
d@0
|
31 modified versions, except that this permission notice may be
|
d@0
|
32 stated in a translation approved by the Free Software Foundation.
|
d@0
|
33 -->
|
d@0
|
34 <meta http-equiv="Content-Style-Type" content="text/css">
|
d@0
|
35 <style type="text/css"><!--
|
d@0
|
36 pre.display { font-family:inherit }
|
d@0
|
37 pre.format { font-family:inherit }
|
d@0
|
38 pre.smalldisplay { font-family:inherit; font-size:smaller }
|
d@0
|
39 pre.smallformat { font-family:inherit; font-size:smaller }
|
d@0
|
40 pre.smallexample { font-size:smaller }
|
d@0
|
41 pre.smalllisp { font-size:smaller }
|
d@0
|
42 span.sc { font-variant:small-caps }
|
d@0
|
43 span.roman { font-family:serif; font-weight:normal; }
|
d@0
|
44 span.sansserif { font-family:sans-serif; font-weight:normal; }
|
d@0
|
45 --></style>
|
d@0
|
46 </head>
|
d@0
|
47 <body>
|
d@0
|
48 <div class="node">
|
d@0
|
49 <p>
|
d@0
|
50 <a name="Fortran-Examples"></a>
|
d@0
|
51 Next: <a rel="next" accesskey="n" href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f">Wisdom of Fortran?</a>,
|
d@0
|
52 Previous: <a rel="previous" accesskey="p" href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran">FFTW Execution in Fortran</a>,
|
d@0
|
53 Up: <a rel="up" accesskey="u" href="Calling-FFTW-from-Fortran.html#Calling-FFTW-from-Fortran">Calling FFTW from Fortran</a>
|
d@0
|
54 <hr>
|
d@0
|
55 </div>
|
d@0
|
56
|
d@0
|
57 <h3 class="section">7.4 Fortran Examples</h3>
|
d@0
|
58
|
d@0
|
59 <p>In C, you might have something like the following to transform a
|
d@0
|
60 one-dimensional complex array:
|
d@0
|
61
|
d@0
|
62 <pre class="example"> fftw_complex in[N], out[N];
|
d@0
|
63 fftw_plan plan;
|
d@0
|
64
|
d@0
|
65 plan = fftw_plan_dft_1d(N,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
|
d@0
|
66 fftw_execute(plan);
|
d@0
|
67 fftw_destroy_plan(plan);
|
d@0
|
68 </pre>
|
d@0
|
69 <p>In Fortran, you would use the following to accomplish the same thing:
|
d@0
|
70
|
d@0
|
71 <pre class="example"> double complex in, out
|
d@0
|
72 dimension in(N), out(N)
|
d@0
|
73 integer*8 plan
|
d@0
|
74
|
d@0
|
75 call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
|
d@0
|
76 call dfftw_execute_dft(plan, in, out)
|
d@0
|
77 call dfftw_destroy_plan(plan)
|
d@0
|
78 </pre>
|
d@0
|
79 <p><a name="index-dfftw_005fplan_005fdft_005f1d-341"></a><a name="index-dfftw_005fexecute_005fdft-342"></a><a name="index-dfftw_005fdestroy_005fplan-343"></a>
|
d@0
|
80 Notice how all routines are called as Fortran subroutines, and the
|
d@0
|
81 plan is returned via the first argument to <code>dfftw_plan_dft_1d</code>.
|
d@0
|
82 Notice also that we changed <code>fftw_execute</code> to
|
d@0
|
83 <code>dfftw_execute_dft</code> (see <a href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran">FFTW Execution in Fortran</a>). To do
|
d@0
|
84 the same thing, but using 8 threads in parallel (see <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>), you would simply prefix these calls with:
|
d@0
|
85
|
d@0
|
86 <pre class="example"> call dfftw_init_threads
|
d@0
|
87 call dfftw_plan_with_nthreads(8)
|
d@0
|
88 </pre>
|
d@0
|
89 <p><a name="index-dfftw_005finit_005fthreads-344"></a><a name="index-dfftw_005fplan_005fwith_005fnthreads-345"></a>
|
d@0
|
90 To transform a three-dimensional array in-place with C, you might do:
|
d@0
|
91
|
d@0
|
92 <pre class="example"> fftw_complex arr[L][M][N];
|
d@0
|
93 fftw_plan plan;
|
d@0
|
94
|
d@0
|
95 plan = fftw_plan_dft_3d(L,M,N, arr,arr,
|
d@0
|
96 FFTW_FORWARD, FFTW_ESTIMATE);
|
d@0
|
97 fftw_execute(plan);
|
d@0
|
98 fftw_destroy_plan(plan);
|
d@0
|
99 </pre>
|
d@0
|
100 <p>In Fortran, you would use this instead:
|
d@0
|
101
|
d@0
|
102 <pre class="example"> double complex arr
|
d@0
|
103 dimension arr(L,M,N)
|
d@0
|
104 integer*8 plan
|
d@0
|
105
|
d@0
|
106 call dfftw_plan_dft_3d(plan, L,M,N, arr,arr,
|
d@0
|
107 & FFTW_FORWARD, FFTW_ESTIMATE)
|
d@0
|
108 call dfftw_execute_dft(plan, arr, arr)
|
d@0
|
109 call dfftw_destroy_plan(plan)
|
d@0
|
110 </pre>
|
d@0
|
111 <p><a name="index-dfftw_005fplan_005fdft_005f3d-346"></a>
|
d@0
|
112 Note that we pass the array dimensions in the “natural” order in both C
|
d@0
|
113 and Fortran.
|
d@0
|
114
|
d@0
|
115 <p>To transform a one-dimensional real array in Fortran, you might do:
|
d@0
|
116
|
d@0
|
117 <pre class="example"> double precision in
|
d@0
|
118 dimension in(N)
|
d@0
|
119 double complex out
|
d@0
|
120 dimension out(N/2 + 1)
|
d@0
|
121 integer*8 plan
|
d@0
|
122
|
d@0
|
123 call dfftw_plan_dft_r2c_1d(plan,N,in,out,FFTW_ESTIMATE)
|
d@0
|
124 call dfftw_execute_dft_r2c(plan, in, out)
|
d@0
|
125 call dfftw_destroy_plan(plan)
|
d@0
|
126 </pre>
|
d@0
|
127 <p><a name="index-dfftw_005fplan_005fdft_005fr2c_005f1d-347"></a><a name="index-dfftw_005fexecute_005fdft_005fr2c-348"></a>
|
d@0
|
128 To transform a two-dimensional real array, out of place, you might use
|
d@0
|
129 the following:
|
d@0
|
130
|
d@0
|
131 <pre class="example"> double precision in
|
d@0
|
132 dimension in(M,N)
|
d@0
|
133 double complex out
|
d@0
|
134 dimension out(M/2 + 1, N)
|
d@0
|
135 integer*8 plan
|
d@0
|
136
|
d@0
|
137 call dfftw_plan_dft_r2c_2d(plan,M,N,in,out,FFTW_ESTIMATE)
|
d@0
|
138 call dfftw_execute_dft_r2c(plan, in, out)
|
d@0
|
139 call dfftw_destroy_plan(plan)
|
d@0
|
140 </pre>
|
d@0
|
141 <p><a name="index-dfftw_005fplan_005fdft_005fr2c_005f2d-349"></a>
|
d@0
|
142 <strong>Important:</strong> Notice that it is the <em>first</em> dimension of the
|
d@0
|
143 complex output array that is cut in half in Fortran, rather than the
|
d@0
|
144 last dimension as in C. This is a consequence of the interface routines
|
d@0
|
145 reversing the order of the array dimensions passed to FFTW so that the
|
d@0
|
146 Fortran program can use its ordinary column-major order.
|
d@0
|
147 <a name="index-column_002dmajor-350"></a><a name="index-r2c_002fc2r-multi_002ddimensional-array-format-351"></a>
|
d@0
|
148 <!-- -->
|
d@0
|
149
|
d@0
|
150 </body></html>
|
d@0
|
151
|