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