Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * Copyright (c) 1997-1999 Massachusetts Institute of Technology
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 2 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 */
19
 
20
#include <ports/fftw.h>
21
#include <ports/f77_func.h>
22
 
23
#ifdef F77_FUNC_ /* only compile wrappers if fortran mangling is known */
24
 
25
/* fftwf77.c:
26
 
27
   FORTRAN-callable "wrappers" for some of the FFTW routines.  To
28
   make these routines callable from FORTRAN, three things had to
29
   be done:
30
 
31
   * The routine names have to be in the style that is expected by
32
     the FORTRAN linker.  This is accomplished with the F77_FUNC_
33
     macro.  (See the file "f77_func.h".)
34
 
35
   * All parameters must be passed by reference.
36
 
37
   * Return values had to be converted into parameters (some
38
     Fortran implementations seem to have trouble calling C functions
39
     that return a value).
40
 
41
   Note that the "fftw_plan" and "fftwnd_plan" types are pointers.
42
   The calling FORTRAN code should use a type of the same size
43
   (probably "integer").
44
 
45
   The wrapper routines have the same name as the wrapped routine,
46
   except that "fftw" and "fftwnd" are replaced by "fftw_f77" and
47
   "fftwnd_f77".
48
 
49
*/
50
 
51
#ifdef __cplusplus
52
extern "C" {
53
#endif                          /* __cplusplus */
54
 
55
/************************************************************************/
56
 
57
void F77_FUNC_(fftw_f77_create_plan,FFTW_F77_CREATE_PLAN)
58
(fftw_plan *p, int *n, int *idir, int *flags)
59
{
60
     fftw_direction dir = *idir < 0 ? FFTW_FORWARD : FFTW_BACKWARD;
61
 
62
     *p = fftw_create_plan(*n,dir,*flags);
63
}
64
 
65
void F77_FUNC_(fftw_f77_destroy_plan,FFTW_F77_DESTROY_PLAN)
66
(fftw_plan *p)
67
{
68
     fftw_destroy_plan(*p);
69
}
70
 
71
void F77_FUNC_(fftw_f77,FFTW_F77)
72
(fftw_plan *p, int *howmany, fftw_complex *in, int *istride, int *idist,
73
 fftw_complex *out, int *ostride, int *odist)
74
{
75
     fftw(*p,*howmany,in,*istride,*idist,out,*ostride,*odist);
76
}
77
 
78
void F77_FUNC_(fftw_f77_one,FFTW_F77_ONE)
79
(fftw_plan *p, fftw_complex *in, fftw_complex *out)
80
{
81
     fftw_one(*p,in,out);
82
}
83
 
84
void fftw_reverse_int_array(int *a, int n)
85
{
86
     int i;
87
 
88
     for (i = 0; i < n/2; ++i) {
89
          int swap_dummy = a[i];
90
          a[i] = a[n - 1 - i];
91
          a[n - 1 - i] = swap_dummy;
92
     }
93
}
94
 
95
void F77_FUNC_(fftwnd_f77_create_plan,FFTWND_F77_CREATE_PLAN)
96
(fftwnd_plan *p, int *rank, int *n, int *idir, int *flags)
97
{
98
     fftw_direction dir = *idir < 0 ? FFTW_FORWARD : FFTW_BACKWARD;
99
 
100
     fftw_reverse_int_array(n,*rank);  /* column-major -> row-major */
101
     *p = fftwnd_create_plan(*rank,n,dir,*flags);
102
     fftw_reverse_int_array(n,*rank);  /* reverse back */
103
}
104
 
105
void F77_FUNC_(fftw2d_f77_create_plan,FFTW2D_F77_CREATE_PLAN)
106
(fftwnd_plan *p, int *nx, int *ny, int *idir, int *flags)
107
{
108
     fftw_direction dir = *idir < 0 ? FFTW_FORWARD : FFTW_BACKWARD;
109
 
110
     *p = fftw2d_create_plan(*ny,*nx,dir,*flags);
111
}
112
 
113
void F77_FUNC_(fftw3d_f77_create_plan,FFTW3D_F77_CREATE_PLAN)
114
(fftwnd_plan *p, int *nx, int *ny, int *nz, int *idir, int *flags)
115
{
116
     fftw_direction dir = *idir < 0 ? FFTW_FORWARD : FFTW_BACKWARD;
117
 
118
     *p = fftw3d_create_plan(*nz,*ny,*nx,dir,*flags);
119
}
120
 
121
void F77_FUNC_(fftwnd_f77_destroy_plan,FFTWND_F77_DESTROY_PLAN)
122
(fftwnd_plan *p)
123
{
124
     fftwnd_destroy_plan(*p);
125
}
126
 
127
void F77_FUNC_(fftwnd_f77,FFTWND_F77)
128
(fftwnd_plan *p, int *howmany, fftw_complex *in, int *istride, int *idist,
129
 fftw_complex *out, int *ostride, int *odist)
130
{
131
     fftwnd(*p,*howmany,in,*istride,*idist,out,*ostride,*odist);
132
}
133
 
134
void F77_FUNC_(fftwnd_f77_one,FFTWND_F77_ONE)
135
(fftwnd_plan *p, fftw_complex *in, fftw_complex *out)
136
{
137
     fftwnd_one(*p,in,out);
138
}
139
 
140
/****************************************************************************/
141
 
142
#ifdef __cplusplus
143
}                               /* extern "C" */
144
#endif                          /* __cplusplus */
145
 
146
#endif /* defined(F77_FUNC_) */