annotate fft/fftw/fftw-3.3.4/doc/html/Wisdom-Generic-Export_002fImport-from-Fortran.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>Wisdom Generic Export/Import from Fortran - 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="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran" title="Accessing the wisdom API from Fortran">
Chris@19 9 <link rel="prev" href="Wisdom-String-Export_002fImport-from-Fortran.html#Wisdom-String-Export_002fImport-from-Fortran" title="Wisdom String Export/Import from Fortran">
Chris@19 10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
Chris@19 11 <!--
Chris@19 12 This manual is for FFTW
Chris@19 13 (version 3.3.4, 20 September 2013).
Chris@19 14
Chris@19 15 Copyright (C) 2003 Matteo Frigo.
Chris@19 16
Chris@19 17 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@19 18
Chris@19 19 Permission is granted to make and distribute verbatim copies of
Chris@19 20 this manual provided the copyright notice and this permission
Chris@19 21 notice are preserved on all copies.
Chris@19 22
Chris@19 23 Permission is granted to copy and distribute modified versions of
Chris@19 24 this manual under the conditions for verbatim copying, provided
Chris@19 25 that the entire resulting derived work is distributed under the
Chris@19 26 terms of a permission notice identical to this one.
Chris@19 27
Chris@19 28 Permission is granted to copy and distribute translations of this
Chris@19 29 manual into another language, under the above conditions for
Chris@19 30 modified versions, except that this permission notice may be
Chris@19 31 stated in a translation approved by the Free Software Foundation.
Chris@19 32 -->
Chris@19 33 <meta http-equiv="Content-Style-Type" content="text/css">
Chris@19 34 <style type="text/css"><!--
Chris@19 35 pre.display { font-family:inherit }
Chris@19 36 pre.format { font-family:inherit }
Chris@19 37 pre.smalldisplay { font-family:inherit; font-size:smaller }
Chris@19 38 pre.smallformat { font-family:inherit; font-size:smaller }
Chris@19 39 pre.smallexample { font-size:smaller }
Chris@19 40 pre.smalllisp { font-size:smaller }
Chris@19 41 span.sc { font-variant:small-caps }
Chris@19 42 span.roman { font-family:serif; font-weight:normal; }
Chris@19 43 span.sansserif { font-family:sans-serif; font-weight:normal; }
Chris@19 44 --></style>
Chris@19 45 </head>
Chris@19 46 <body>
Chris@19 47 <div class="node">
Chris@19 48 <a name="Wisdom-Generic-Export%2fImport-from-Fortran"></a>
Chris@19 49 <a name="Wisdom-Generic-Export_002fImport-from-Fortran"></a>
Chris@19 50 <p>
Chris@19 51 Previous:&nbsp;<a rel="previous" accesskey="p" href="Wisdom-String-Export_002fImport-from-Fortran.html#Wisdom-String-Export_002fImport-from-Fortran">Wisdom String Export/Import from Fortran</a>,
Chris@19 52 Up:&nbsp;<a rel="up" accesskey="u" href="Accessing-the-wisdom-API-from-Fortran.html#Accessing-the-wisdom-API-from-Fortran">Accessing the wisdom API from Fortran</a>
Chris@19 53 <hr>
Chris@19 54 </div>
Chris@19 55
Chris@19 56 <h4 class="subsection">7.6.3 Wisdom Generic Export/Import from Fortran</h4>
Chris@19 57
Chris@19 58 <p>The most generic wisdom export/import functions allow you to provide
Chris@19 59 an arbitrary callback function to read/write one character at a time
Chris@19 60 in any way you want. However, your callback function must be written
Chris@19 61 in a special way, using the <code>bind(C)</code> attribute to be passed to a
Chris@19 62 C interface.
Chris@19 63
Chris@19 64 <p><a name="index-fftw_005fexport_005fwisdom-575"></a>In particular, to call the generic wisdom export function
Chris@19 65 <code>fftw_export_wisdom</code>, you would write a callback subroutine of the form:
Chris@19 66
Chris@19 67 <pre class="example"> subroutine my_write_char(c, p) bind(C)
Chris@19 68 use, intrinsic :: iso_c_binding
Chris@19 69 character(C_CHAR), value :: c
Chris@19 70 type(C_PTR), value :: p
Chris@19 71 <em>...write c...</em>
Chris@19 72 end subroutine my_write_char
Chris@19 73 </pre>
Chris@19 74 <p>Given such a subroutine (along with the corresponding interface definition), you could then export wisdom using:
Chris@19 75
Chris@19 76 <p><a name="index-c_005ffunloc-576"></a>
Chris@19 77 <pre class="example"> call fftw_export_wisdom(c_funloc(my_write_char), p)
Chris@19 78 </pre>
Chris@19 79 <p><a name="index-c_005floc-577"></a><a name="index-c_005ff_005fpointer-578"></a>The standard <code>c_funloc</code> intrinsic converts a Fortran
Chris@19 80 <code>bind(C)</code> subroutine into a C function pointer. The parameter
Chris@19 81 <code>p</code> is a <code>type(C_PTR)</code> to any arbitrary data that you want
Chris@19 82 to pass to <code>my_write_char</code> (or <code>C_NULL_PTR</code> if none). (Note
Chris@19 83 that you can get a C pointer to Fortran data using the intrinsic
Chris@19 84 <code>c_loc</code>, and convert it back to a Fortran pointer in
Chris@19 85 <code>my_write_char</code> using <code>c_f_pointer</code>.)
Chris@19 86
Chris@19 87 <p>Similarly, to use the generic <code>fftw_import_wisdom</code>, you would
Chris@19 88 define a callback function of the form:
Chris@19 89
Chris@19 90 <p><a name="index-fftw_005fimport_005fwisdom-579"></a>
Chris@19 91 <pre class="example"> integer(C_INT) function my_read_char(p) bind(C)
Chris@19 92 use, intrinsic :: iso_c_binding
Chris@19 93 type(C_PTR), value :: p
Chris@19 94 character :: c
Chris@19 95 <em>...read a character c...</em>
Chris@19 96 my_read_char = ichar(c, C_INT)
Chris@19 97 end function my_read_char
Chris@19 98
Chris@19 99 ....
Chris@19 100
Chris@19 101 integer(C_INT) :: ret
Chris@19 102 ret = fftw_import_wisdom(c_funloc(my_read_char), p)
Chris@19 103 if (ret .eq. 0) stop 'error importing wisdom'
Chris@19 104 </pre>
Chris@19 105 <p>Your function can return <code>-1</code> if the end of the input is reached.
Chris@19 106 Again, <code>p</code> is an arbitrary <code>type(C_PTR</code> that is passed
Chris@19 107 through to your function. <code>fftw_import_wisdom</code> returns <code>0</code>
Chris@19 108 if an error occurred and nonzero otherwise.
Chris@19 109
Chris@19 110 <!-- -->
Chris@19 111 </body></html>
Chris@19 112