annotate src/fftw-3.3.3/doc/html/Wisdom-Generic-Export_002fImport-from-Fortran.html @ 83:ae30d91d2ffe

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