annotate fft/fftw/fftw-3.3.4/doc/html/Fortran-Examples.html @ 40:223f770b5341 kissfft-double tip

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