comparison src/fftw-3.3.3/doc/html/Fortran-Examples.html @ 10:37bf6b4a2645

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