annotate src/fftw-3.3.3/doc/html/Wisdom-String-Export_002fImport-from-Fortran.html @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
Chris@10 1 <html lang="en">
Chris@10 2 <head>
Chris@10 3 <title>Wisdom String 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-File-Export_002fImport-from-Fortran.html#Wisdom-File-Export_002fImport-from-Fortran" title="Wisdom File Export/Import from Fortran">
Chris@10 10 <link rel="next" href="Wisdom-Generic-Export_002fImport-from-Fortran.html#Wisdom-Generic-Export_002fImport-from-Fortran" title="Wisdom Generic Export/Import from Fortran">
Chris@10 11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
Chris@10 12 <!--
Chris@10 13 This manual is for FFTW
Chris@10 14 (version 3.3.3, 25 November 2012).
Chris@10 15
Chris@10 16 Copyright (C) 2003 Matteo Frigo.
Chris@10 17
Chris@10 18 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@10 19
Chris@10 20 Permission is granted to make and distribute verbatim copies of
Chris@10 21 this manual provided the copyright notice and this permission
Chris@10 22 notice are preserved on all copies.
Chris@10 23
Chris@10 24 Permission is granted to copy and distribute modified versions of
Chris@10 25 this manual under the conditions for verbatim copying, provided
Chris@10 26 that the entire resulting derived work is distributed under the
Chris@10 27 terms of a permission notice identical to this one.
Chris@10 28
Chris@10 29 Permission is granted to copy and distribute translations of this
Chris@10 30 manual into another language, under the above conditions for
Chris@10 31 modified versions, except that this permission notice may be
Chris@10 32 stated in a translation approved by the Free Software Foundation.
Chris@10 33 -->
Chris@10 34 <meta http-equiv="Content-Style-Type" content="text/css">
Chris@10 35 <style type="text/css"><!--
Chris@10 36 pre.display { font-family:inherit }
Chris@10 37 pre.format { font-family:inherit }
Chris@10 38 pre.smalldisplay { font-family:inherit; font-size:smaller }
Chris@10 39 pre.smallformat { font-family:inherit; font-size:smaller }
Chris@10 40 pre.smallexample { font-size:smaller }
Chris@10 41 pre.smalllisp { font-size:smaller }
Chris@10 42 span.sc { font-variant:small-caps }
Chris@10 43 span.roman { font-family:serif; font-weight:normal; }
Chris@10 44 span.sansserif { font-family:sans-serif; font-weight:normal; }
Chris@10 45 --></style>
Chris@10 46 </head>
Chris@10 47 <body>
Chris@10 48 <div class="node">
Chris@10 49 <a name="Wisdom-String-Export%2fImport-from-Fortran"></a>
Chris@10 50 <a name="Wisdom-String-Export_002fImport-from-Fortran"></a>
Chris@10 51 <p>
Chris@10 52 Next:&nbsp;<a rel="next" accesskey="n" href="Wisdom-Generic-Export_002fImport-from-Fortran.html#Wisdom-Generic-Export_002fImport-from-Fortran">Wisdom Generic Export/Import from Fortran</a>,
Chris@10 53 Previous:&nbsp;<a rel="previous" accesskey="p" href="Wisdom-File-Export_002fImport-from-Fortran.html#Wisdom-File-Export_002fImport-from-Fortran">Wisdom File Export/Import from Fortran</a>,
Chris@10 54 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 55 <hr>
Chris@10 56 </div>
Chris@10 57
Chris@10 58 <h4 class="subsection">7.6.2 Wisdom String Export/Import from Fortran</h4>
Chris@10 59
Chris@10 60 <p><a name="index-fftw_005fexport_005fwisdom_005fto_005fstring-568"></a>Dealing with FFTW's C string export/import is a bit more painful. In
Chris@10 61 particular, the <code>fftw_export_wisdom_to_string</code> function requires
Chris@10 62 you to deal with a dynamically allocated C string. To get its length,
Chris@10 63 you must define an interface to the C <code>strlen</code> function, and to
Chris@10 64 deallocate it you must define an interface to C <code>free</code>:
Chris@10 65
Chris@10 66 <pre class="example"> use, intrinsic :: iso_c_binding
Chris@10 67 interface
Chris@10 68 integer(C_INT) function strlen(s) bind(C, name='strlen')
Chris@10 69 import
Chris@10 70 type(C_PTR), value :: s
Chris@10 71 end function strlen
Chris@10 72 subroutine free(p) bind(C, name='free')
Chris@10 73 import
Chris@10 74 type(C_PTR), value :: p
Chris@10 75 end subroutine free
Chris@10 76 end interface
Chris@10 77 </pre>
Chris@10 78 <p>Given these definitions, you can then export wisdom to a Fortran
Chris@10 79 character array:
Chris@10 80
Chris@10 81 <pre class="example"> character(C_CHAR), pointer :: s(:)
Chris@10 82 integer(C_SIZE_T) :: slen
Chris@10 83 type(C_PTR) :: p
Chris@10 84 p = fftw_export_wisdom_to_string()
Chris@10 85 if (.not. c_associated(p)) stop 'error exporting wisdom'
Chris@10 86 slen = strlen(p)
Chris@10 87 call c_f_pointer(p, s, [slen+1])
Chris@10 88 ...
Chris@10 89 call free(p)
Chris@10 90 </pre>
Chris@10 91 <p><a name="index-c_005fassociated-569"></a><a name="index-c_005ff_005fpointer-570"></a>
Chris@10 92 Note that <code>slen</code> is the length of the C string, but the length of
Chris@10 93 the array is <code>slen+1</code> because it includes the terminating null
Chris@10 94 character. (You can omit the &lsquo;<samp><span class="samp">+1</span></samp>&rsquo; if you don't want Fortran to
Chris@10 95 know about the null character.) The standard <code>c_associated</code> function
Chris@10 96 checks whether <code>p</code> is a null pointer, which is returned by
Chris@10 97 <code>fftw_export_wisdom_to_string</code> if there was an error.
Chris@10 98
Chris@10 99 <p><a name="index-fftw_005fimport_005fwisdom_005ffrom_005fstring-571"></a>To import wisdom from a string, use
Chris@10 100 <code>fftw_import_wisdom_from_string</code> as usual; note that the argument
Chris@10 101 of this function must be a <code>character(C_CHAR)</code> that is terminated
Chris@10 102 by the <code>C_NULL_CHAR</code> character, like the <code>s</code> array above.
Chris@10 103
Chris@10 104 <!-- =========> -->
Chris@10 105 </body></html>
Chris@10 106