fftwaffar.cc 5.78 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
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
/*! \file fftwaffar.cc
 * \brief engine to transfrom several signals at once (implementation)
 * 
 * ----------------------------------------------------------------------------
 * 
 * $Id$
 * \author Thomas Forbriger
 * \date 13/05/2011
 * 
 * engine to transfrom several signals at once (implementation)
 * 
 * Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach) 
 *
 * ----
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version. 
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 * ----
 *
 * 
 * REVISIONS and CHANGES 
 *  - 13/05/2011   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define TF_FFTWAFFAR_CC_VERSION \
  "TF_FFTWAFFAR_CC   V1.0   "
#define TF_FFTWAFFAR_CC_CVSID \
  "$Id$"

#include <fourier::fftwaffar.h>

namespace fourier {

  namespace fft {

    DRFFTWAFFArrayEngine::DRFFTWAFFArrayEngine(const int& nseis,
                                               const int& nsamp)
      : Mseries(TAseries(nseis,nsamp)),
      Mspectrum(TAspectrum(nseis,DRFFTWAFFArrayEngine::ncoeff(nsamp))),
      Mplanr2c(0), Mplanc2r(0) 
    {
      this->checkconsistency;
    }

    /*----------------------------------------------------------------------*/

    DRFFTWAFFArrayEngine::DRFFTWAFFArrayEngine(const TAseries& series,
                                               const TAspectrum& spec)
      : Mseriesarray(series), Mspectrumarrays(spec),
      Mplanr2c(0), Mplanc2r(0) 
    { this->checkconsistency(); }

    /*----------------------------------------------------------------------*/

    //! delete plan.
    DRFFTWAFFArrayEngine::~DRFFTWAFFArrayEngine()
    {
      this->delete_plans();
    } // DRFFTWAFFArrayEngine::~DRFFTWAFFArrayEngine()

    /*----------------------------------------------------------------------*/

    //! delete plans.
    void DRFFTWAFFArrayEngine::delete_plans() const
    {
      if (Mplanr2c != 0) { fftw_destroy_plan(Mplanr2c); }
      if (Mplanc2r != 0) { fftw_destroy_plan(Mplanc2r); }
      Mplanr2c=0;
      Mplanc2r=0;
    } // DRFFTWAFFArrayEngine::delete_plans()

    /*----------------------------------------------------------------------*/

    //! execute r2c plan
    void DRFFTWAFFArrayEngine::r2c() 
    {
      if (Mplanr2c == 0)
      {

      }

    } // DRFFTWAFFArrayEngine::r2c()

    /*----------------------------------------------------------------------*/

    void DRFFTWAFFArrayEnginge::checkconsistency()
    {
      FOURIER_assert(Mseries.size(0)==
                     DRFFTWAFFArrayEnginge::ncoeff(Mspectrum.size(0)),
                     "ERROR: sample size inconsistent");
      FOURIER_assert(Mseries.size(1)==Mspectrum.size(1),
                     "ERROR: inconsistent number of signals");
      FOURIER_assert(((Mseries.size(2)==1) && (Mspectrum.size(2)==1)),
                     "ERROR: two-dimensional arrays only");
      FOURIER_assert(((Mseries.size(3)==1) && (Mspectrum.size(3)==1)),
                     "ERROR: two-dimensional arrays only");
    } // void DRFFTWAFFArrayEnginge::checkconsistency()

    /*----------------------------------------------------------------------*/

    void DRFFTWAFFArrayEnginge::createplanr2c()
    {
      if (Mplanr2c==0)
      {
        // tranformation only along one dimension
        const int rank=1;
        const int n[]={1};
        // number of signals to be transformed
        const int howmany=Mseries.size(1);
        // quick design
        const unsigned flags=FFTW_ESTIMATE;
        Mplanr2c=fftw_plan_many_dft_r2c(int rank,
                                        const int *n,
                                        int howmany,
                                        double *in,
                                        const int *inembed,
                                        int istride,
                                        int idist,
                                        fftw_complex *out,
                                        const int *onembed,
                                        int ostride,
                                        int odist,
                                        unsigned flags);
        FOURIER_assert(Mplanr2c!=0, "ERROR: creating r2c plan");
      }
    } // void DRFFTWAFFArrayEnginge::createplanr2c()

    /*----------------------------------------------------------------------*/

    void DRFFTWAFFArrayEnginge::createplanc2r()
    {
      if (Mplanc2r==0)
      {
        Mplanc2r=fftw_plan_many_dft_c2r(int rank,
                                        const int *n,
                                        int howmany,
                                        fftw_complex *in,
                                        const int *inembed,
                                        int istride,
                                        int idist,
                                        double *out,
                                        const int *onembed,
                                        int ostride,
                                        int odist,
                                        unsigned flags);
        FOURIER_assert(Mplanr2c!=0, "ERROR: creating c2r plan");
      }
    } // void DRFFTWAFFArrayEnginge::createplanc2r()

  } // namespace fft

} // namespace fourier

/* ----- END OF fftwaffar.cc ----- */