Commit 1cac2e6f authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

started new project

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/branches/libfourier
SVN Revision: 3936
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent a41c7fa5
......@@ -17,7 +17,7 @@
* Note:
* The library code is migrated to FFTW3. This program however was just meant
* to be a testing sandbox to develop the first library code. It is not used
* in production or is it used to test the library. This code will no
* in production nor is it used to test the library. This code will not be
* migrated and becomes obsolete.
*
* ============================================================================
......
......@@ -16,11 +16,13 @@
* - 12/09/2007 V1.1 first running version
* - 07/10/2010 V1.2
* - migrate to FFTW3
* - 13/05/2011 V1.3
* - properly delete plans in delete_arrays() function
*
* ============================================================================
*/
#define TF_FFTWAFF_CC_VERSION \
"TF_FFTWAFF_CC V1.2"
"TF_FFTWAFF_CC V1.3"
#define TF_FFTWAFF_CC_CVSID \
"$Id$"
......@@ -148,12 +150,13 @@ namespace fourier {
//! delete arrays.
void DRFFTWAFF::delete_arrays() const
{
this->delete_plans();
if (Mseriesarray != 0) { fftw_free(Mseriesarray); }
if (Mspectrumarray != 0) { fftw_free(Mspectrumarray); }
Mplan_forward=0;
Mplan_backward=0;
Mseries=Tseries(0);
Mspectrum=Tspectrum(0);
// Mplan_forward=0;
// Mplan_backward=0;
} // DRFFTWAFF::delete_arrays()
#endif
......
/*! \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 ----- */
/*! \file fftwaffar.h
* \brief engine to transfrom several signals at once (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id$
* \author Thomas Forbriger
* \date 13/05/2011
*
* engine to transfrom several signals at once (prototypes)
*
* 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
*
* ============================================================================
*/
// include guard
#ifndef TF_FFTWAFFAR_H_VERSION
#define TF_FFTWAFFAR_H_VERSION \
"TF_FFTWAFFAR_H V1.0 "
#define TF_FFTWAFFAR_H_CVSID \
"$Id$"
#include<complex>
#include<fftw3.h>
#include<aff/array.h>
namespace fourier {
namespace fft {
/*! \brief Engine to transform several signals at once.
* References to workspace are passed to the contstructor.
*
* The difference between DRFFTWAFF and DRFFTWAFFArrayEngine is that the
* latter transforms more than on signal at the same time. It uses a
* persistent workspace and makes full use of the reference semantics
* implemented in aff::Array.
*
* When initializing DRFFTWAFFArrayEngine either the dimensions of the
* time series array must be passed or a readily prepared workspace is
* passed to the engine. In both cases the engine assumes that the user
* program holds references to the seismogram and the coefficient array
* through instances of aff::Array. The engine is just called to do the
* actual transform. New values to be transformed are received through the
* common reference with the user program. A reference to the arrays is
* provided through member functions.
*/
class DRFFTWAFFArrayEngine {
public:
typedef double Tsample;
typedef std::complex<Tsample> Tcoeff;
typedef aff::Array<Tsample> TAseries;
typedef aff::Array<Tcoeff> TAspectrum;
DRFFTWAFFArrayEngine(const int& nseis,
const int& nsamp);
DRFFTWAFFArrayEngine(const TAseries& series,
const TAspectrum& spec);
~DRFFTWAFFArrayEngine();
void r2c();
void c2r();
Tsample scale_series(const Tsample& dt) const;
Tsample scale_spectrum(const Tsample& dt) const;
TAseries series() const { return Mseriesarray; }
TAspectrum spectrum() const { return Mspectrumarray; }
private:
void checkconsistency();
void createplanr2c();
void createplanc2r();
void delete_plans() const;
static int ncoeff(const int& nsamples) const { return(nsamples/2+1); }
TAseries Mseriesarray;
TAspectrum Mspectrumarray;
fftw_plan Mplanr2c;
fftw_plan Mplanc2r;
}; // class DRFFTWAFFArrayEngine
} // namespace fft
} // namespace fourier
#endif // TF_FFTWAFFAR_H_VERSION (includeguard)
/* ----- END OF fftwaffar.h ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment