annotate src/fftw-3.3.8/doc/html/Fortran-Examples.html @ 167:bd3cc4d1df30

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