annotate src/fftw-3.3.3/api/f77api.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21 #include "api.h"
Chris@10 22 #include "dft.h"
Chris@10 23 #include "rdft.h"
Chris@10 24
Chris@10 25 #include "x77.h"
Chris@10 26
Chris@10 27 /* if F77_FUNC is not defined, then we don't know how to mangle identifiers
Chris@10 28 for the Fortran linker, and we must omit the f77 API. */
Chris@10 29 #if defined(F77_FUNC) || defined(WINDOWS_F77_MANGLING)
Chris@10 30
Chris@10 31 /*-----------------------------------------------------------------------*/
Chris@10 32 /* some internal functions used by the f77 api */
Chris@10 33
Chris@10 34 /* in fortran, the natural array ordering is column-major, which
Chris@10 35 corresponds to reversing the dimensions relative to C's row-major */
Chris@10 36 static int *reverse_n(int rnk, const int *n)
Chris@10 37 {
Chris@10 38 int *nrev;
Chris@10 39 int i;
Chris@10 40 A(FINITE_RNK(rnk));
Chris@10 41 nrev = (int *) MALLOC(sizeof(int) * rnk, PROBLEMS);
Chris@10 42 for (i = 0; i < rnk; ++i)
Chris@10 43 nrev[rnk - i - 1] = n[i];
Chris@10 44 return nrev;
Chris@10 45 }
Chris@10 46
Chris@10 47 /* f77 doesn't have data structures, so we have to pass iodims as
Chris@10 48 parallel arrays */
Chris@10 49 static X(iodim) *make_dims(int rnk, const int *n,
Chris@10 50 const int *is, const int *os)
Chris@10 51 {
Chris@10 52 X(iodim) *dims;
Chris@10 53 int i;
Chris@10 54 A(FINITE_RNK(rnk));
Chris@10 55 dims = (X(iodim) *) MALLOC(sizeof(X(iodim)) * rnk, PROBLEMS);
Chris@10 56 for (i = 0; i < rnk; ++i) {
Chris@10 57 dims[i].n = n[i];
Chris@10 58 dims[i].is = is[i];
Chris@10 59 dims[i].os = os[i];
Chris@10 60 }
Chris@10 61 return dims;
Chris@10 62 }
Chris@10 63
Chris@10 64 typedef struct {
Chris@10 65 void (*f77_write_char)(char *, void *);
Chris@10 66 void *data;
Chris@10 67 } write_char_data;
Chris@10 68
Chris@10 69 static void write_char(char c, void *d)
Chris@10 70 {
Chris@10 71 write_char_data *ad = (write_char_data *) d;
Chris@10 72 ad->f77_write_char(&c, ad->data);
Chris@10 73 }
Chris@10 74
Chris@10 75 typedef struct {
Chris@10 76 void (*f77_read_char)(int *, void *);
Chris@10 77 void *data;
Chris@10 78 } read_char_data;
Chris@10 79
Chris@10 80 static int read_char(void *d)
Chris@10 81 {
Chris@10 82 read_char_data *ed = (read_char_data *) d;
Chris@10 83 int c;
Chris@10 84 ed->f77_read_char(&c, ed->data);
Chris@10 85 return (c < 0 ? EOF : c);
Chris@10 86 }
Chris@10 87
Chris@10 88 static X(r2r_kind) *ints2kinds(int rnk, const int *ik)
Chris@10 89 {
Chris@10 90 if (!FINITE_RNK(rnk) || rnk == 0)
Chris@10 91 return 0;
Chris@10 92 else {
Chris@10 93 int i;
Chris@10 94 X(r2r_kind) *k;
Chris@10 95
Chris@10 96 k = (X(r2r_kind) *) MALLOC(sizeof(X(r2r_kind)) * rnk, PROBLEMS);
Chris@10 97 /* reverse order for Fortran -> C */
Chris@10 98 for (i = 0; i < rnk; ++i)
Chris@10 99 k[i] = (X(r2r_kind)) ik[rnk - 1 - i];
Chris@10 100 return k;
Chris@10 101 }
Chris@10 102 }
Chris@10 103
Chris@10 104 /*-----------------------------------------------------------------------*/
Chris@10 105
Chris@10 106 #define F77(a, A) F77x(x77(a), X77(A))
Chris@10 107
Chris@10 108 #ifndef WINDOWS_F77_MANGLING
Chris@10 109
Chris@10 110 #if defined(F77_FUNC)
Chris@10 111 # define F77x(a, A) F77_FUNC(a, A)
Chris@10 112 # include "f77funcs.h"
Chris@10 113 #endif
Chris@10 114
Chris@10 115 /* If identifiers with underscores are mangled differently than those
Chris@10 116 without underscores, then we include *both* mangling versions. The
Chris@10 117 reason is that the only Fortran compiler that does such differing
Chris@10 118 mangling is currently g77 (which adds an extra underscore to names
Chris@10 119 with underscores), whereas other compilers running on the same
Chris@10 120 machine are likely to use non-underscored mangling. (I'm sick
Chris@10 121 of users complaining that FFTW works with g77 but not with e.g.
Chris@10 122 pgf77 or ifc on the same machine.) Note that all FFTW identifiers
Chris@10 123 contain underscores, and configure picks g77 by default. */
Chris@10 124 #if defined(F77_FUNC_) && !defined(F77_FUNC_EQUIV)
Chris@10 125 # undef F77x
Chris@10 126 # define F77x(a, A) F77_FUNC_(a, A)
Chris@10 127 # include "f77funcs.h"
Chris@10 128 #endif
Chris@10 129
Chris@10 130 #else /* WINDOWS_F77_MANGLING */
Chris@10 131
Chris@10 132 /* Various mangling conventions common (?) under Windows. */
Chris@10 133
Chris@10 134 /* g77 */
Chris@10 135 # define WINDOWS_F77_FUNC(a, A) a ## __
Chris@10 136 # define F77x(a, A) WINDOWS_F77_FUNC(a, A)
Chris@10 137 # include "f77funcs.h"
Chris@10 138
Chris@10 139 /* Intel, etc. */
Chris@10 140 # undef WINDOWS_F77_FUNC
Chris@10 141 # define WINDOWS_F77_FUNC(a, A) a ## _
Chris@10 142 # include "f77funcs.h"
Chris@10 143
Chris@10 144 /* Digital/Compaq/HP Visual Fortran, Intel Fortran. stdcall attribute
Chris@10 145 is apparently required to adjust for calling conventions (callee
Chris@10 146 pops stack in stdcall). See also:
Chris@10 147 http://msdn.microsoft.com/library/en-us/vccore98/html/_core_mixed.2d.language_programming.3a_.overview.asp
Chris@10 148 */
Chris@10 149 # undef WINDOWS_F77_FUNC
Chris@10 150 # if defined(__GNUC__)
Chris@10 151 # define WINDOWS_F77_FUNC(a, A) __attribute__((stdcall)) A
Chris@10 152 # elif defined(_MSC_VER) || defined(_ICC) || defined(_STDCALL_SUPPORTED)
Chris@10 153 # define WINDOWS_F77_FUNC(a, A) __stdcall A
Chris@10 154 # else
Chris@10 155 # define WINDOWS_F77_FUNC(a, A) A /* oh well */
Chris@10 156 # endif
Chris@10 157 # include "f77funcs.h"
Chris@10 158
Chris@10 159 #endif /* WINDOWS_F77_MANGLING */
Chris@10 160
Chris@10 161 #endif /* F77_FUNC */