annotate src/fftw-3.3.3/doc/html/Fortran-Examples.html @ 95:89f5e221ed7b

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