cannam@127: c Copyright (c) 2003, 2007-14 Matteo Frigo cannam@127: c Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology cannam@127: c cannam@127: c This program is free software; you can redistribute it and/or modify cannam@127: c it under the terms of the GNU General Public License as published by cannam@127: c the Free Software Foundation; either version 2 of the License, or cannam@127: c (at your option) any later version. cannam@127: c cannam@127: c This program is distributed in the hope that it will be useful, cannam@127: c but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@127: c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@127: c GNU General Public License for more details. cannam@127: c cannam@127: c You should have received a copy of the GNU General Public License cannam@127: c along with this program; if not, write to the Free Software cannam@127: c Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA cannam@127: c cannam@127: cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cannam@127: c cannam@127: c This is an example implementation of Fortran wisdom export/import cannam@127: c to/from a Fortran unit (file), exploiting the generic cannam@127: c dfftw_export_wisdom/dfftw_import_wisdom functions. cannam@127: c cannam@127: c We cannot compile this file into the FFTW library itself, lest all cannam@127: c FFTW-calling programs be required to link to the Fortran I/O cannam@127: c libraries. cannam@127: c cannam@127: cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cannam@127: cannam@127: c Strictly speaking, the '$' format specifier, which allows us to cannam@127: c write a character without a trailing newline, is not standard F77. cannam@127: c However, it seems to be a nearly universal extension. cannam@127: subroutine write_char(c, iunit) cannam@127: character c cannam@127: integer iunit cannam@127: write(iunit,321) c cannam@127: 321 format(a,$) cannam@127: end cannam@127: cannam@127: subroutine export_wisdom_to_file(iunit) cannam@127: integer iunit cannam@127: external write_char cannam@127: call dfftw_export_wisdom(write_char, iunit) cannam@127: end cannam@127: cannam@127: c Fortran 77 does not have any portable way to read an arbitrary cannam@127: c file one character at a time. The best alternative seems to be to cannam@127: c read a whole line into a buffer, since for fftw-exported wisdom we cannam@127: c can bound the line length. (If the file contains longer lines, cannam@127: c then the lines will be truncated and the wisdom import should cannam@127: c simply fail.) Ugh. cannam@127: subroutine read_char(ic, iunit) cannam@127: integer ic cannam@127: integer iunit cannam@127: character*256 buf cannam@127: save buf cannam@127: integer ibuf cannam@127: data ibuf/257/ cannam@127: save ibuf cannam@127: if (ibuf .lt. 257) then cannam@127: ic = ichar(buf(ibuf:ibuf)) cannam@127: ibuf = ibuf + 1 cannam@127: return cannam@127: endif cannam@127: read(iunit,123,end=666) buf cannam@127: ic = ichar(buf(1:1)) cannam@127: ibuf = 2 cannam@127: return cannam@127: 666 ic = -1 cannam@127: ibuf = 257 cannam@127: 123 format(a256) cannam@127: end cannam@127: cannam@127: subroutine import_wisdom_from_file(isuccess, iunit) cannam@127: integer isuccess cannam@127: integer iunit cannam@127: external read_char cannam@127: call dfftw_import_wisdom(isuccess, read_char, iunit) cannam@127: end