Bsoft  2.1.0
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 
75 {
76  return fft_setup_plan(size[0], size[1], size[2], dir, opt);
77 }
78 
88 {
89  fftwf_destroy_plan(plan);
90 
91  return 0;
92 }
93 
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 
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
fftw
int fftw(fft_plan plan, Complex< float > *a)
Fast Fourier transforms a data array.
Definition: fft.cpp:106
Complex
Definition: Complex.h:23
Vector3< long >
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
fft_direction
int fft_direction
Definition: fft.h:19
utilities.h
Header file for general utilities.
verbose
int verbose
fft_complex
fftwf_complex fft_complex
Definition: fft.h:18
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
fft.h
General FFT for n-dimensional data.
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