annotate src/fftw-3.3.5/doc/html/Fortran-Examples.html @ 42:2cd0e3b3e1fd

Current fftw source
author Chris Cannam
date Tue, 18 Oct 2016 13:40:26 +0100
parents
children
rev   line source
Chris@42 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Chris@42 2 <html>
Chris@42 3 <!-- This manual is for FFTW
Chris@42 4 (version 3.3.5, 30 July 2016).
Chris@42 5
Chris@42 6 Copyright (C) 2003 Matteo Frigo.
Chris@42 7
Chris@42 8 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@42 9
Chris@42 10 Permission is granted to make and distribute verbatim copies of this
Chris@42 11 manual provided the copyright notice and this permission notice are
Chris@42 12 preserved on all copies.
Chris@42 13
Chris@42 14 Permission is granted to copy and distribute modified versions of this
Chris@42 15 manual under the conditions for verbatim copying, provided that the
Chris@42 16 entire resulting derived work is distributed under the terms of a
Chris@42 17 permission notice identical to this one.
Chris@42 18
Chris@42 19 Permission is granted to copy and distribute translations of this manual
Chris@42 20 into another language, under the above conditions for modified versions,
Chris@42 21 except that this permission notice may be stated in a translation
Chris@42 22 approved by the Free Software Foundation. -->
Chris@42 23 <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
Chris@42 24 <head>
Chris@42 25 <title>FFTW 3.3.5: Fortran Examples</title>
Chris@42 26
Chris@42 27 <meta name="description" content="FFTW 3.3.5: Fortran Examples">
Chris@42 28 <meta name="keywords" content="FFTW 3.3.5: Fortran Examples">
Chris@42 29 <meta name="resource-type" content="document">
Chris@42 30 <meta name="distribution" content="global">
Chris@42 31 <meta name="Generator" content="makeinfo">
Chris@42 32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Chris@42 33 <link href="index.html#Top" rel="start" title="Top">
Chris@42 34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
Chris@42 35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
Chris@42 36 <link href="Calling-FFTW-from-Legacy-Fortran.html#Calling-FFTW-from-Legacy-Fortran" rel="up" title="Calling FFTW from Legacy Fortran">
Chris@42 37 <link href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f" rel="next" title="Wisdom of Fortran?">
Chris@42 38 <link href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran" rel="prev" title="FFTW Execution in Fortran">
Chris@42 39 <style type="text/css">
Chris@42 40 <!--
Chris@42 41 a.summary-letter {text-decoration: none}
Chris@42 42 blockquote.smallquotation {font-size: smaller}
Chris@42 43 div.display {margin-left: 3.2em}
Chris@42 44 div.example {margin-left: 3.2em}
Chris@42 45 div.indentedblock {margin-left: 3.2em}
Chris@42 46 div.lisp {margin-left: 3.2em}
Chris@42 47 div.smalldisplay {margin-left: 3.2em}
Chris@42 48 div.smallexample {margin-left: 3.2em}
Chris@42 49 div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
Chris@42 50 div.smalllisp {margin-left: 3.2em}
Chris@42 51 kbd {font-style:oblique}
Chris@42 52 pre.display {font-family: inherit}
Chris@42 53 pre.format {font-family: inherit}
Chris@42 54 pre.menu-comment {font-family: serif}
Chris@42 55 pre.menu-preformatted {font-family: serif}
Chris@42 56 pre.smalldisplay {font-family: inherit; font-size: smaller}
Chris@42 57 pre.smallexample {font-size: smaller}
Chris@42 58 pre.smallformat {font-family: inherit; font-size: smaller}
Chris@42 59 pre.smalllisp {font-size: smaller}
Chris@42 60 span.nocodebreak {white-space:nowrap}
Chris@42 61 span.nolinebreak {white-space:nowrap}
Chris@42 62 span.roman {font-family:serif; font-weight:normal}
Chris@42 63 span.sansserif {font-family:sans-serif; font-weight:normal}
Chris@42 64 ul.no-bullet {list-style: none}
Chris@42 65 -->
Chris@42 66 </style>
Chris@42 67
Chris@42 68
Chris@42 69 </head>
Chris@42 70
Chris@42 71 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
Chris@42 72 <a name="Fortran-Examples"></a>
Chris@42 73 <div class="header">
Chris@42 74 <p>
Chris@42 75 Next: <a href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f" accesskey="n" rel="next">Wisdom of Fortran?</a>, Previous: <a href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran" accesskey="p" rel="prev">FFTW Execution in Fortran</a>, Up: <a href="Calling-FFTW-from-Legacy-Fortran.html#Calling-FFTW-from-Legacy-Fortran" accesskey="u" rel="up">Calling FFTW from Legacy Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
Chris@42 76 </div>
Chris@42 77 <hr>
Chris@42 78 <a name="Fortran-Examples-1"></a>
Chris@42 79 <h3 class="section">8.4 Fortran Examples</h3>
Chris@42 80
Chris@42 81 <p>In C, you might have something like the following to transform a
Chris@42 82 one-dimensional complex array:
Chris@42 83 </p>
Chris@42 84 <div class="example">
Chris@42 85 <pre class="example"> fftw_complex in[N], out[N];
Chris@42 86 fftw_plan plan;
Chris@42 87
Chris@42 88 plan = fftw_plan_dft_1d(N,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
Chris@42 89 fftw_execute(plan);
Chris@42 90 fftw_destroy_plan(plan);
Chris@42 91 </pre></div>
Chris@42 92
Chris@42 93 <p>In Fortran, you would use the following to accomplish the same thing:
Chris@42 94 </p>
Chris@42 95 <div class="example">
Chris@42 96 <pre class="example"> double complex in, out
Chris@42 97 dimension in(N), out(N)
Chris@42 98 integer*8 plan
Chris@42 99
Chris@42 100 call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
Chris@42 101 call dfftw_execute_dft(plan, in, out)
Chris@42 102 call dfftw_destroy_plan(plan)
Chris@42 103 </pre></div>
Chris@42 104 <a name="index-dfftw_005fplan_005fdft_005f1d"></a>
Chris@42 105 <a name="index-dfftw_005fexecute_005fdft-1"></a>
Chris@42 106 <a name="index-dfftw_005fdestroy_005fplan"></a>
Chris@42 107
Chris@42 108 <p>Notice how all routines are called as Fortran subroutines, and the
Chris@42 109 plan is returned via the first argument to <code>dfftw_plan_dft_1d</code>.
Chris@42 110 Notice also that we changed <code>fftw_execute</code> to
Chris@42 111 <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@42 112 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@42 113 </p>
Chris@42 114 <div class="example">
Chris@42 115 <pre class="example"> integer iret
Chris@42 116 call dfftw_init_threads(iret)
Chris@42 117 call dfftw_plan_with_nthreads(8)
Chris@42 118 </pre></div>
Chris@42 119 <a name="index-dfftw_005finit_005fthreads"></a>
Chris@42 120 <a name="index-dfftw_005fplan_005fwith_005fnthreads"></a>
Chris@42 121
Chris@42 122 <p>(You might want to check the value of <code>iret</code>: if it is zero, it
Chris@42 123 indicates an unlikely error during thread initialization.)
Chris@42 124 </p>
Chris@42 125 <p>To transform a three-dimensional array in-place with C, you might do:
Chris@42 126 </p>
Chris@42 127 <div class="example">
Chris@42 128 <pre class="example"> fftw_complex arr[L][M][N];
Chris@42 129 fftw_plan plan;
Chris@42 130
Chris@42 131 plan = fftw_plan_dft_3d(L,M,N, arr,arr,
Chris@42 132 FFTW_FORWARD, FFTW_ESTIMATE);
Chris@42 133 fftw_execute(plan);
Chris@42 134 fftw_destroy_plan(plan);
Chris@42 135 </pre></div>
Chris@42 136
Chris@42 137 <p>In Fortran, you would use this instead:
Chris@42 138 </p>
Chris@42 139 <div class="example">
Chris@42 140 <pre class="example"> double complex arr
Chris@42 141 dimension arr(L,M,N)
Chris@42 142 integer*8 plan
Chris@42 143
Chris@42 144 call dfftw_plan_dft_3d(plan, L,M,N, arr,arr,
Chris@42 145 &amp; FFTW_FORWARD, FFTW_ESTIMATE)
Chris@42 146 call dfftw_execute_dft(plan, arr, arr)
Chris@42 147 call dfftw_destroy_plan(plan)
Chris@42 148 </pre></div>
Chris@42 149 <a name="index-dfftw_005fplan_005fdft_005f3d"></a>
Chris@42 150
Chris@42 151 <p>Note that we pass the array dimensions in the &ldquo;natural&rdquo; order in both C
Chris@42 152 and Fortran.
Chris@42 153 </p>
Chris@42 154 <p>To transform a one-dimensional real array in Fortran, you might do:
Chris@42 155 </p>
Chris@42 156 <div class="example">
Chris@42 157 <pre class="example"> double precision in
Chris@42 158 dimension in(N)
Chris@42 159 double complex out
Chris@42 160 dimension out(N/2 + 1)
Chris@42 161 integer*8 plan
Chris@42 162
Chris@42 163 call dfftw_plan_dft_r2c_1d(plan,N,in,out,FFTW_ESTIMATE)
Chris@42 164 call dfftw_execute_dft_r2c(plan, in, out)
Chris@42 165 call dfftw_destroy_plan(plan)
Chris@42 166 </pre></div>
Chris@42 167 <a name="index-dfftw_005fplan_005fdft_005fr2c_005f1d"></a>
Chris@42 168 <a name="index-dfftw_005fexecute_005fdft_005fr2c"></a>
Chris@42 169
Chris@42 170 <p>To transform a two-dimensional real array, out of place, you might use
Chris@42 171 the following:
Chris@42 172 </p>
Chris@42 173 <div class="example">
Chris@42 174 <pre class="example"> double precision in
Chris@42 175 dimension in(M,N)
Chris@42 176 double complex out
Chris@42 177 dimension out(M/2 + 1, N)
Chris@42 178 integer*8 plan
Chris@42 179
Chris@42 180 call dfftw_plan_dft_r2c_2d(plan,M,N,in,out,FFTW_ESTIMATE)
Chris@42 181 call dfftw_execute_dft_r2c(plan, in, out)
Chris@42 182 call dfftw_destroy_plan(plan)
Chris@42 183 </pre></div>
Chris@42 184 <a name="index-dfftw_005fplan_005fdft_005fr2c_005f2d"></a>
Chris@42 185
Chris@42 186 <p><strong>Important:</strong> Notice that it is the <em>first</em> dimension of the
Chris@42 187 complex output array that is cut in half in Fortran, rather than the
Chris@42 188 last dimension as in C. This is a consequence of the interface routines
Chris@42 189 reversing the order of the array dimensions passed to FFTW so that the
Chris@42 190 Fortran program can use its ordinary column-major order.
Chris@42 191 <a name="index-column_002dmajor-3"></a>
Chris@42 192 <a name="index-r2c_002fc2r-multi_002ddimensional-array-format-3"></a>
Chris@42 193 </p>
Chris@42 194 <hr>
Chris@42 195 <div class="header">
Chris@42 196 <p>
Chris@42 197 Next: <a href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f" accesskey="n" rel="next">Wisdom of Fortran?</a>, Previous: <a href="FFTW-Execution-in-Fortran.html#FFTW-Execution-in-Fortran" accesskey="p" rel="prev">FFTW Execution in Fortran</a>, Up: <a href="Calling-FFTW-from-Legacy-Fortran.html#Calling-FFTW-from-Legacy-Fortran" accesskey="u" rel="up">Calling FFTW from Legacy Fortran</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
Chris@42 198 </div>
Chris@42 199
Chris@42 200
Chris@42 201
Chris@42 202 </body>
Chris@42 203 </html>