2
* General filter plugin for KST.
3
* Copyright 2005, the kst development team
4
* Released under the terms of the GNU GPL v2+.
5
* Author: Nicolas Brisset
13
#include <qstringlist.h>
15
extern "C" int kstfilter_generic(const double *const inArrays[], const int inArrayLens[],
16
const double inScalars[],
17
double *outArrays[], int outArrayLens[],
19
const char* inStrings[], char *outStrings[]);
21
int kstfilter_generic(const double *const inArrays[], const int inArrayLens[],
22
const double inScalars[],
23
double *outArrays[], int outArrayLens[],
25
const char* inStrings[], char *outStrings[])
28
int i = 0, length = inArrayLens[0];
30
// Extract polynom coefficients and instantiate polynoms
31
QStringList numCoeffs = QStringList::split(QRegExp("\\s*(,|;|:)\\s*"), inStrings[0]);
32
QStringList denCoeffs = QStringList::split(QRegExp("\\s*(,|;|:)\\s*"), inStrings[1]);
33
int numDegree = numCoeffs.count() - 1, denDegree = denCoeffs.count() - 1;
34
polynom<double> Num(numDegree), Den(denDegree);
35
double tmpDouble = 0.0;
37
for (i=0; i<=numDegree; i++) {
38
tmpDouble = numCoeffs[i].toDouble(&ok);
39
if (ok) Num[i]= tmpDouble;
42
for (i=0; i<=denDegree; i++) {
43
tmpDouble = denCoeffs[i].toDouble(&ok);
44
if (ok) Den[i] = tmpDouble;
49
double DeltaT = inScalars[0];
51
// Allocate storage for output vectors
52
outArrays[0] = (double *) realloc(outArrays[0], length * sizeof(double));
53
outArrayLens[0] = length;
56
filter<double> theFilter(Num,Den,DeltaT);
58
theFilter.ConnectTo(in);
60
for (int i=0; i<length; i++) {
62
theFilter.NextTimeStep();
63
outArrays[0][i] = theFilter.out;