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