-
Notifications
You must be signed in to change notification settings - Fork 0
/
yfftw.c
233 lines (214 loc) · 6.44 KB
/
yfftw.c
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <stdlib.h>
#include <fftw3.h>
#include <stdlib.h>
#include <string.h>
/* REVISIONS
12.06.201 D. Munro - close file handles.
*/
/* GENERAL ------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
long _fftwT (double tlim) /* set time limit on planning */
{
fftw_set_timelimit(tlim);
return (1);
}
/* DOUBLE ------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
long _fftwI (char *wisdom_file) /* import */
{
FILE *fp;
int stat;
fp = fopen(wisdom_file, "r");
if((fp = fopen(wisdom_file, "r"))==NULL) {
printf("Error reading wisdom file\"%s\"\n",wisdom_file);
fflush(stdout);
exit(0);
}
stat= fftw_import_wisdom_from_file(fp);
fclose(fp);
return stat;
}
/*--------------------------------------------------------------------------*/
long _fftwO (char *wisdom_file) /* export */
{
FILE *fp;
if((fp = fopen(wisdom_file, "w"))==NULL) {
printf("Error creating wisdom file\"%s\"\n",wisdom_file);
fflush(stdout);
exit(0);
}
fftw_export_wisdom_to_file(fp);
fflush(fp);
fclose(fp);
return (1);
}
/*--------------------------------------------------------------------------*/
long _fftwA (char* w, long ni) /* export wisdom to string */
{
char *ws;
ws = fftw_export_wisdom_to_string();
long n = strlen(ws);
if (n>ni) return -n;
strcpy(w,ws);
return n;
}
/*--------------------------------------------------------------------------*/
fftw_plan _fftwP (fftw_complex *in, /* plan */
fftw_complex *out,
long ft_rank, long *ft_dims, long *ft_strides,
long ft_loop, long *loop_dims, long *loop_strides,
long dir) /* forward (1) or reverse (-1) */
{
/* Declarations */
int i;
int sign= -1*dir;
fftw_plan p;
long plan_mode;
fftw_iodim *id_fft;
fftw_iodim *id_loop;
plan_mode = FFTW_MEASURE; /* FFTW_ESTIMATE FFTW_MEASURE FFTW_PATIENT FFTW_EXHAUSTIVE;*/
id_fft = (fftw_iodim *)fftw_malloc(sizeof(fftw_iodim) * ft_rank);
id_loop = (fftw_iodim *)fftw_malloc(sizeof(fftw_iodim) * ft_loop);
for (i = 0 ; i < ft_rank ; i++) {
id_fft[i].n = ft_dims[i];
id_fft[i].is = ft_strides[i];
id_fft[i].os = ft_strides[i];
}
for (i = 0 ; i < ft_loop ; i++) {
id_loop[i].n = loop_dims[i];
id_loop[i].is = loop_strides[i];
id_loop[i].os = loop_strides[i];
}
if (in == out){ /*in place*/
p = fftw_plan_guru_dft((int)ft_rank, id_fft, (int)ft_loop, id_loop, in, in, sign, plan_mode);
}else{
p = fftw_plan_guru_dft((int)ft_rank, id_fft, (int)ft_loop, id_loop, in, out, sign, plan_mode);
}
fftw_free(id_fft);
fftw_free(id_loop);
return p;
}
/*--------------------------------------------------------------------------*/
void _fftwE (fftw_plan p, fftw_complex *in, fftw_complex *out) /*execute*/
{
fftw_execute_dft(p, in, out);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwD (fftw_plan p) /*destroy*/
{
fftw_destroy_plan(p);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwS (fftw_plan p) /*print S==screen ;)*/
{
fftw_print_plan(p);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwC (void) /*cleanup*/
{
fftw_cleanup();
return;
}
/* FLOAT ------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
long _fftwfI (char *wisdom_file) /* import */
{
FILE *fp;
int stat;
fp = fopen(wisdom_file, "r");
if((fp = fopen(wisdom_file, "r"))==NULL) {
printf("Error reading wisdom file\"%s\"\n",wisdom_file);
fflush(stdout);
exit(0);
}
stat = fftwf_import_wisdom_from_file(fp);
fclose(fp);
return stat;
}
/*--------------------------------------------------------------------------*/
long _fftwfO (char *wisdom_file) /* export */
{
FILE *fp;
if((fp = fopen(wisdom_file, "w"))==NULL) {
printf("Error creating wisdom file\"%s\"\n",wisdom_file);
fflush(stdout);
exit(0);
}
fftwf_export_wisdom_to_file(fp);
fflush(fp);
fclose(fp);
return (1);
}
/*--------------------------------------------------------------------------*/
long _fftwfA (char* w, long ni) /* export wisdom to string */
{
char *ws;
ws = fftwf_export_wisdom_to_string();
long n = strlen(ws);
if (n>ni) return -n;
strcpy(w,ws);
return n;
}
/*--------------------------------------------------------------------------*/
fftwf_plan _fftwfP (fftwf_complex *in, /* plan */
fftwf_complex *out,
long ft_rank, long *ft_dims, long *ft_strides,
long ft_loop, long *loop_dims, long *loop_strides,
long dir) /* forward (1) or reverse (-1) */
{
/* Declarations */
int i;
int sign= -1*dir;
fftwf_plan p;
long plan_mode;
fftwf_iodim *id_fft;
fftwf_iodim *id_loop;
plan_mode = FFTW_PATIENT; /* FFTW_ESTIMATE FFTW_MEASURE FFTW_PATIENT FFTW_EXHAUSTIVE;*/
id_fft = (fftwf_iodim *)fftwf_malloc(sizeof(fftwf_iodim) * ft_rank);
id_loop = (fftwf_iodim *)fftwf_malloc(sizeof(fftwf_iodim) * ft_loop);
for (i = 0 ; i < ft_rank ; i++) {
id_fft[i].n = ft_dims[i];
id_fft[i].is = ft_strides[i];
id_fft[i].os = ft_strides[i];
}
for (i = 0 ; i < ft_loop ; i++) {
id_loop[i].n = loop_dims[i];
id_loop[i].is = loop_strides[i];
id_loop[i].os = loop_strides[i];
}
if (in == out){ /*in place*/
p = fftwf_plan_guru_dft((int)ft_rank, id_fft, (int)ft_loop, id_loop, in, in, sign, plan_mode);
}else{
p = fftwf_plan_guru_dft((int)ft_rank, id_fft, (int)ft_loop, id_loop, in, out, sign, plan_mode);
}
fftwf_free(id_fft);
fftwf_free(id_loop);
return p;
}
/*--------------------------------------------------------------------------*/
void _fftwfE (fftwf_plan p, fftwf_complex *in, fftwf_complex *out) /*execute*/
{
fftwf_execute_dft(p, in, out);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwfD (fftwf_plan p) /*destroy*/
{
fftwf_destroy_plan(p);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwfS (fftwf_plan p) /*print S==screen ;)*/
{
fftwf_print_plan(p);
return;
}
/*--------------------------------------------------------------------------*/
void _fftwfC (void) /*cleanup*/
{
fftwf_cleanup();
return;
}