| Bsoft 2.0.5 Bernard's software package

fft.cpp
Go to the documentation of this file.
1
11 #include "fft.h"
12 #include "utilities.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
31 fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
32 {
33 int rank = 0;
34 int n[3] = {1, 1, 1};
35 if ( z > 1 ) {
36 rank = 3;
37 n[0] = z;
38 n[1] = y;
39 n[2] = x;
40 } else if ( y > 1 ) {
41 rank = 2;
42 n[0] = y;
43 n[1] = x;
44 } else {
45 rank = 1;
46 n[0] = x;
47 }
48
49 if ( verbose & VERB_DEBUG )
50 cout << "DEBUG fft_setup_plan: n=" << n[0] << "x" << n[1] << "x" << n[2] << " opt=" << opt << endl;
51
52 int flags = FFTW_ESTIMATE;
53
54 switch ( opt ) {
55 case 1: flags = FFTW_MEASURE; break;
56 case 2: flags = FFTW_PATIENT; break;
57 case 3: flags = FFTW_EXHAUSTIVE; break;
58 default: flags = FFTW_ESTIMATE;
59 }
60
61 fft_complex* in = NULL;
62 fft_complex* out = in;
63 if ( opt )
64 in = out = new fft_complex[x*y*z];
65
66 fft_plan plan = fftwf_plan_dft(rank, n, in, out, dir, flags);
67
68 if ( opt )
69 delete[] in;
70
71 return plan;
72 }
73
74 fft_plan fft_setup_plan(Vector3<long> size, fft_direction dir, int opt)
75 {
76 return fft_setup_plan(size[0], size[1], size[2], dir, opt);
77 }
78
87 int fft_destroy_plan(fft_plan plan)
88 {
89 fftwf_destroy_plan(plan);
90
91 return 0;
92 }
93
106 int fftw(fft_plan plan, Complex<float>* a)
107 {
108 fft_complex* in = (fft_complex *) a;
109 fft_complex* out = in;
110
111 fftwf_execute_dft(plan, in, out);
112
113 return 0;
114 }
115
116
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
fft_setup_plan
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
Definition: fft.cpp:31
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
fft_plan
fftwf_plan fft_plan
Definition: fft.h:16
verbose
int verbose
fft_complex
fftwf_complex fft_complex
Definition: fft.h:14
fft_direction
int fft_direction
Definition: fft.h:15
Complex
Definition: Complex.h:23
fftw
int fftw(fft_plan plan, Complex< float > *a)
Fast Fourier transforms a data array.
Definition: fft.cpp:106
Vector3< long >
fft.h
General FFT for n-dimensional data.