fftwaffar.cc 8.41 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
/*! \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$"

41
42
#include <fourier/fftwaffar.h>
#include <fourier/error.h>
thomas.forbriger's avatar
thomas.forbriger committed
43
44
45
46
47
48
49

namespace fourier {

  namespace fft {

    DRFFTWAFFArrayEngine::DRFFTWAFFArrayEngine(const int& nseis,
                                               const int& nsamp)
50
51
      : Mseriesarray(TAseries(nseis,nsamp)),
      Mspectrumarray(TAspectrum(nseis,DRFFTWAFFArrayEngine::ncoeff(nsamp))),
thomas.forbriger's avatar
thomas.forbriger committed
52
53
      Mplanr2c(0), Mplanc2r(0) 
    {
54
      this->checkconsistency();
thomas.forbriger's avatar
thomas.forbriger committed
55
56
57
58
59
60
    }

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

    DRFFTWAFFArrayEngine::DRFFTWAFFArrayEngine(const TAseries& series,
                                               const TAspectrum& spec)
61
      : Mseriesarray(series), Mspectrumarray(spec),
thomas.forbriger's avatar
thomas.forbriger committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
      Mplanr2c(0), Mplanc2r(0) 
    { this->checkconsistency(); }

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

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

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

    //! delete plans.
76
    void DRFFTWAFFArrayEngine::delete_plans() 
thomas.forbriger's avatar
thomas.forbriger committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    {
      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()

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

98
    void DRFFTWAFFArrayEngine::checkconsistency()
thomas.forbriger's avatar
thomas.forbriger committed
99
    {
100
101
      FOURIER_assert(Mseriesarray.size(0)==
                     DRFFTWAFFArrayEngine::ncoeff(Mspectrumarray.size(0)),
thomas.forbriger's avatar
thomas.forbriger committed
102
                     "ERROR: sample size inconsistent");
103
      FOURIER_assert(Mseriesarray.size(1)==Mspectrumarray.size(1),
thomas.forbriger's avatar
thomas.forbriger committed
104
                     "ERROR: inconsistent number of signals");
105
      FOURIER_assert(((Mseriesarray.size(2)==1) && (Mspectrumarray.size(2)==1)),
thomas.forbriger's avatar
thomas.forbriger committed
106
                     "ERROR: two-dimensional arrays only");
107
      FOURIER_assert(((Mseriesarray.size(3)==1) && (Mspectrumarray.size(3)==1)),
thomas.forbriger's avatar
thomas.forbriger committed
108
                     "ERROR: two-dimensional arrays only");
109
    } // void DRFFTWAFFArrayEngine::checkconsistency()
thomas.forbriger's avatar
thomas.forbriger committed
110
111
112

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

113
    void DRFFTWAFFArrayEngine::createplanr2c()
thomas.forbriger's avatar
thomas.forbriger committed
114
115
116
    {
      if (Mplanr2c==0)
      {
117
118
        // overall parameters
        // ------------------
thomas.forbriger's avatar
thomas.forbriger committed
119
120
        // tranformation only along one dimension
        const int rank=1;
121
122
        // size of each series
        int n=Mseriesarray.size(0);
thomas.forbriger's avatar
thomas.forbriger committed
123
        // number of signals to be transformed
124
        const int howmany=Mseriesarray.size(1);
thomas.forbriger's avatar
thomas.forbriger committed
125
126
        // quick design
        const unsigned flags=FFTW_ESTIMATE;
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

        // input array
        // -----------
        // one-dimensional transform: use default
        int* inembed=0;
        // distance to next sample
        const int istride=Mseriesarray.stride(0);
        // distance to next signal
        const int idist=Mseriesarray.stride(1);
        // reference to memory
        TAseries::Trepresentation irep=Mseriesarray.representation();
        // offset in array representation
        aff::Tsubscript ioffset=Mseriesarray.first_offset();
        // pointer to first array element in memory
        TAseries::Trepresentation::Tpointer ipointer=&irep[ioffset];
        // casted pointer
        double* in=aff::SizeCheckedCast<TAseries::Tvalue,double>::cast(ipointer);

        // output array
        // ------------
        // one-dimensional transform: use default
        int* onembed=0;
        // distance to next sample
        const int ostride=Mspectrumarray.stride(0);
        // distance to next signal
        const int odist=Mspectrumarray.stride(1);
        // reference to memory
        TAspectrum::Trepresentation orep=Mspectrumarray.representation();
        // offset in array representation
        aff::Tsubscript ooffset=Mspectrumarray.first_offset();
        // pointer to first array element in memory
        TAspectrum::Trepresentation::Tpointer opointer=&orep[ooffset];
        // casted pointer
        fftw_complex* out=aff::SizeCheckedCast<TAspectrum::Tvalue,fftw_complex>::cast(opointer);

        // create plan
        Mplanr2c=fftw_plan_many_dft_r2c(rank, &n, howmany,
                                        in, inembed, istride, idist,
                                        out, onembed, ostride, odist,
                                        flags);
thomas.forbriger's avatar
thomas.forbriger committed
167
168
        FOURIER_assert(Mplanr2c!=0, "ERROR: creating r2c plan");
      }
169
    } // void DRFFTWAFFArrayEngine::createplanr2c()
thomas.forbriger's avatar
thomas.forbriger committed
170
171
172

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

173
    void DRFFTWAFFArrayEngine::createplanc2r()
thomas.forbriger's avatar
thomas.forbriger committed
174
175
176
    {
      if (Mplanc2r==0)
      {
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
        // overall parameters
        // ------------------
        // tranformation only along one dimension
        const int rank=1;
        // size of each series
        int n=Mseriesarray.size(0);
        // number of signals to be transformed
        const int howmany=Mseriesarray.size(1);
        // quick design
        const unsigned flags=FFTW_ESTIMATE;

        // input array
        // -----------
        // one-dimensional transform: use default
        int* inembed=0;
        // distance to next sample
        const int istride=Mspectrumarray.stride(0);
        // distance to next signal
        const int idist=Mspectrumarray.stride(1);
        // reference to memory
        TAspectrum::Trepresentation irep=Mspectrumarray.representation();
        // offset in array representation
        aff::Tsubscript ioffset=Mspectrumarray.first_offset();
        // pointer to first array element in memory
        TAspectrum::Trepresentation::Tpointer ipointer=&irep[ioffset];
        // casted pointer
        fftw_complex* in=aff::SizeCheckedCast<TAspectrum::Tvalue,fftw_complex>::cast(ipointer);

        // output array
        // ------------
        // one-dimensional transform: use default
        int* onembed=0;
        // distance to next sample
        const int ostride=Mseries.stride(0);
        // distance to next signal
        const int odist=Mseries.stride(1);
        // reference to memory
        TAseries::Trepresentation orep=Mseries.representation();
        // offset in array representation
        aff::Tsubscript ooffset=Mseries.first_offset();
        // pointer to first array element in memory
        TAseries::Trepresentation::Tpointer opointer=&orep[ooffset];
        // casted pointer
        double* out=aff::SizeCheckedCast<TAseries::Tvalue,double>::cast(opointer);

        // create plan
        Mplanr2c=fftw_plan_many_dft_c2r(rank, &n, howmany,
                                        in, inembed, istride, idist,
                                        out, onembed, ostride, odist,
                                        flags);
thomas.forbriger's avatar
thomas.forbriger committed
227
228
        FOURIER_assert(Mplanr2c!=0, "ERROR: creating c2r plan");
      }
229
    } // void DRFFTWAFFArrayEngine::createplanc2r()
thomas.forbriger's avatar
thomas.forbriger committed
230
231
232
233
234
235

  } // namespace fft

} // namespace fourier

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