annotate fft/fftw/fftw-3.3.4/mpi/genf03-wrap.pl @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 #!/usr/bin/perl -w
Chris@19 2 # Generate Fortran 2003 wrappers (which translate MPI_Comm from f2c) from
Chris@19 3 # function declarations of the form (one per line):
Chris@19 4 # extern <type> fftw_mpi_<name>(...args...)
Chris@19 5 # extern <type> fftw_mpi_<name>(...args...)
Chris@19 6 # ...
Chris@19 7 # with no line breaks within a given function. (It's too much work to
Chris@19 8 # write a general parser, since we just have to handle FFTW's header files.)
Chris@19 9 # Each declaration has at least one MPI_Comm argument.
Chris@19 10
Chris@19 11 sub canonicalize_type {
Chris@19 12 my($type);
Chris@19 13 ($type) = @_;
Chris@19 14 $type =~ s/ +/ /g;
Chris@19 15 $type =~ s/^ //;
Chris@19 16 $type =~ s/ $//;
Chris@19 17 $type =~ s/([^\* ])\*/$1 \*/g;
Chris@19 18 $type =~ s/double/R/;
Chris@19 19 $type =~ s/fftw_([A-Za-z0-9_]+)/X(\1)/;
Chris@19 20 return $type;
Chris@19 21 }
Chris@19 22
Chris@19 23 while (<>) {
Chris@19 24 next if /^ *$/;
Chris@19 25 if (/^ *extern +([a-zA-Z_0-9 ]+[ \*]) *fftw_mpi_([a-zA-Z_0-9]+) *\((.*)\) *$/) {
Chris@19 26 $ret = &canonicalize_type($1);
Chris@19 27 $name = $2;
Chris@19 28
Chris@19 29 $args = $3;
Chris@19 30
Chris@19 31
Chris@19 32 print "\n$ret XM(${name}_f03)(";
Chris@19 33
Chris@19 34 $comma = "";
Chris@19 35 foreach $arg (split(/ *, */, $args)) {
Chris@19 36 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@19 37 $argtype = &canonicalize_type($1);
Chris@19 38 $argname = $2;
Chris@19 39 print $comma;
Chris@19 40 if ($argtype eq "MPI_Comm") {
Chris@19 41 print "MPI_Fint f_$argname";
Chris@19 42 }
Chris@19 43 else {
Chris@19 44 print "$argtype $argname";
Chris@19 45 }
Chris@19 46 $comma = ", ";
Chris@19 47 }
Chris@19 48 print ")\n{\n";
Chris@19 49
Chris@19 50 print " MPI_Comm ";
Chris@19 51 $comma = "";
Chris@19 52 foreach $arg (split(/ *, */, $args)) {
Chris@19 53 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@19 54 $argtype = &canonicalize_type($1);
Chris@19 55 $argname = $2;
Chris@19 56 if ($argtype eq "MPI_Comm") {
Chris@19 57 print "$comma$argname";
Chris@19 58 $comma = ", ";
Chris@19 59 }
Chris@19 60 }
Chris@19 61 print ";\n\n";
Chris@19 62
Chris@19 63 foreach $arg (split(/ *, */, $args)) {
Chris@19 64 $arg =~ /^([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) *$/;
Chris@19 65 $argtype = &canonicalize_type($1);
Chris@19 66 $argname = $2;
Chris@19 67 if ($argtype eq "MPI_Comm") {
Chris@19 68 print " $argname = MPI_Comm_f2c(f_$argname);\n";
Chris@19 69 }
Chris@19 70 }
Chris@19 71
Chris@19 72 $argnames = $args;
Chris@19 73 $argnames =~ s/([a-zA-Z_0-9 ]+[ \*]) *([a-zA-Z_0-9]+) */$2/g;
Chris@19 74 print " ";
Chris@19 75 print "return " if ($ret ne "void");
Chris@19 76 print "XM($name)($argnames);\n}\n";
Chris@19 77 }
Chris@19 78 }