annotate Lib/fftw-3.2.1/api/.svn/text-base/f77api.c.svn-base @ 9:262e084a15a9

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