File: f77_wisdom.f

package info (click to toggle)
fftw3 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 16,824 kB
  • ctags: 8,846
  • sloc: ansic: 246,029; sh: 10,285; ml: 5,470; perl: 1,423; makefile: 935; fortran: 110; asm: 26
file content (79 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
c     Copyright (c) 2003, 2007-8 Matteo Frigo
c     Copyright (c) 2003, 2007-8 Massachusetts Institute of Technology
c     
c     This program is free software; you can redistribute it and/or modify
c     it under the terms of the GNU General Public License as published by
c     the Free Software Foundation; either version 2 of the License, or
c     (at your option) any later version.
c     
c     This program is distributed in the hope that it will be useful,
c     but WITHOUT ANY WARRANTY; without even the implied warranty of
c     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c     GNU General Public License for more details.
c     
c     You should have received a copy of the GNU General Public License
c     along with this program; if not, write to the Free Software
c     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c     
c     This is an example implementation of Fortran wisdom export/import
c     to/from a Fortran unit (file), exploiting the generic
c     dfftw_export_wisdom/dfftw_import_wisdom functions.
c     
c     We cannot compile this file into the FFTW library itself, lest all
c     FFTW-calling programs be required to link to the Fortran I/O
c     libraries.
c     
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

c     Strictly speaking, the '$' format specifier, which allows us to
c     write a character without a trailing newline, is not standard F77.
c     However, it seems to be a nearly universal extension.
      subroutine write_char(c, iunit)
      character c
      integer iunit
      write(iunit,321) c
 321  format(a,$)
      end      

      subroutine export_wisdom_to_file(iunit)
      integer iunit
      external write_char
      call dfftw_export_wisdom(write_char, iunit)
      end

c     Fortran 77 does not have any portable way to read an arbitrary
c     file one character at a time.  The best alternative seems to be to
c     read a whole line into a buffer, since for fftw-exported wisdom we
c     can bound the line length.  (If the file contains longer lines,
c     then the lines will be truncated and the wisdom import should
c     simply fail.)  Ugh.
      subroutine read_char(ic, iunit)
      integer ic
      integer iunit
      character*256 buf
      save buf
      integer ibuf
      data ibuf/257/
      save ibuf
      if (ibuf .lt. 257) then
         ic = ichar(buf(ibuf:ibuf))
         ibuf = ibuf + 1
         return
      endif
      read(iunit,123,end=666) buf
      ic = ichar(buf(1:1))
      ibuf = 2
      return
 666  ic = -1
      ibuf = 257
 123  format(a256)
      end
      
      subroutine import_wisdom_from_file(isuccess, iunit)
      integer isuccess
      integer iunit
      external read_char
      call dfftw_import_wisdom(isuccess, read_char, iunit)
      end