~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/plugins/discretizing_filters/kstfilter_generic.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
6
 */
 
7
 
 
8
#include <math.h>
 
9
#include "filter.h"
 
10
#include "polynom.h"
 
11
#include <qregexp.h>
 
12
#include <qstring.h>
 
13
#include <qstringlist.h>
 
14
 
 
15
extern "C" int kstfilter_generic(const double *const inArrays[], const int inArrayLens[],
 
16
                const double inScalars[],
 
17
                double *outArrays[], int outArrayLens[],
 
18
                double outScalars[],
 
19
                const char* inStrings[], char *outStrings[]);
 
20
 
 
21
int kstfilter_generic(const double *const inArrays[], const int inArrayLens[],
 
22
                const double inScalars[],
 
23
                double *outArrays[], int outArrayLens[],
 
24
                double outScalars[],
 
25
                const char* inStrings[], char *outStrings[])
 
26
{
 
27
 
 
28
int i = 0, length = inArrayLens[0];
 
29
 
 
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;
 
36
bool ok = false;
 
37
for (i=0; i<=numDegree; i++) {
 
38
  tmpDouble = numCoeffs[i].toDouble(&ok);
 
39
  if (ok) Num[i]= tmpDouble;
 
40
  else Num[i] = 0.0;
 
41
}
 
42
for (i=0; i<=denDegree; i++) {
 
43
  tmpDouble = denCoeffs[i].toDouble(&ok);
 
44
  if (ok) Den[i] = tmpDouble;
 
45
  else Den[i] = 0.0;
 
46
}
 
47
 
 
48
// Time step
 
49
double DeltaT = inScalars[0];
 
50
 
 
51
// Allocate storage for output vectors
 
52
outArrays[0] = (double *) realloc(outArrays[0], length * sizeof(double));
 
53
outArrayLens[0] = length;
 
54
 
 
55
// Create filter
 
56
filter<double> theFilter(Num,Den,DeltaT);
 
57
double in = 0.0;
 
58
theFilter.ConnectTo(in);
 
59
theFilter.Reset();
 
60
for (int i=0; i<length; i++) {
 
61
  in = inArrays[0][i];
 
62
  theFilter.NextTimeStep();
 
63
  outArrays[0][i] = theFilter.out;
 
64
}
 
65
 
 
66
return 0;
 
67
}