[Kst] branches/work/kst/pluginify/kst/src/plugins
Adam Treat
treat at kde.org
Tue Sep 19 20:04:09 CEST 2006
SVN commit 586478 by treat:
* Port the effective_bandwidth plugin to the new system
as discussed here:
http://bugs.kde.org/show_bug.cgi?id=126642
* I've enabled it in the build for now, but I make no claims
whether it is mathematically correct.
M +1 -1 Makefile.am
M +7 -8 effective_bandwidth/Makefile.am
M +87 -27 effective_bandwidth/effective_bandwidth.cpp
A effective_bandwidth/effective_bandwidth.h [License: GPL (v2+)]
A effective_bandwidth/kstobject_effbandwidth.desktop
M +0 -1 testplugin/testplugin.cpp
--- branches/work/kst/pluginify/kst/src/plugins/Makefile.am #586477:586478
@@ -20,5 +20,5 @@
CORRELATION_SUBDIR=correlation
endif
-SUBDIRS=bin linefit periodogram phase statistics chop crossspectrum syncbin testplugin $(NOISE_SUBDIR) $(FITS_SUBDIR) $(FITSNONLINEAR_SUBDIR) $(INTERPOLATIONS_SUBDIR) $(PASS_FILTERS_SUBDIR) $(CORRELATION_SUBDIR) $(CONVOLUTION_SUBDIR) cumulative_sum differentiation shift
+SUBDIRS=bin linefit periodogram phase statistics chop crossspectrum syncbin testplugin effective_bandwidth $(NOISE_SUBDIR) $(FITS_SUBDIR) $(FITSNONLINEAR_SUBDIR) $(INTERPOLATIONS_SUBDIR) $(PASS_FILTERS_SUBDIR) $(CORRELATION_SUBDIR) $(CONVOLUTION_SUBDIR) cumulative_sum differentiation shift
--- branches/work/kst/pluginify/kst/src/plugins/effective_bandwidth/Makefile.am #586477:586478
@@ -1,12 +1,11 @@
-installdir=$(kde_moduledir)/kstplugins
-INCLUDES=-I$(srcdir)/../../kst $(all_includes)
+INCLUDES=-I$(top_srcdir)/kst -I$(top_srcdir)/kst/src/libkst -I$(top_srcdir)/kst/src/libkstmath $(all_includes)
-install_LTLIBRARIES = effective_bandwidth.la
+kde_module_LTLIBRARIES=kstobject_effbandwidth.la
-effective_bandwidth_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
-effective_bandwidth_la_LIBADD = $(GSL_LIBS)
-effective_bandwidth_la_SOURCES = effective_bandwidth.cpp
+kstobject_effbandwidth_la_LDFLAGS=$(all_libraries) -module -avoid-version
+kstobject_effbandwidth_la_SOURCES=effective_bandwidth.cpp
-METASOURCES=AUTO
+services_DATA=kstobject_effbandwidth.desktop
+servicesdir=$(kde_servicesdir)/kst
-install_DATA=effective_bandwidth.xml
+METASOURCES=AUTO
--- branches/work/kst/pluginify/kst/src/plugins/effective_bandwidth/effective_bandwidth.cpp #586477:586478
@@ -14,39 +14,67 @@
* (at your option) any later version. *
* *
***************************************************************************/
+#include "effective_bandwidth.h"
#include <math.h>
+#include <kgenericfactory.h>
-extern "C" int effective_bandwidth(const double *const inArrays[], const int inArrayLens[],
- const double inScalars[],
- double *outArrays[], int outArrayLens[],
- double outScalars[]);
+//in
+static const QString& X_ARRAY = KGlobal::staticQString("X Array");
+static const QString& Y_ARRAY = KGlobal::staticQString("Y Array");
+static const QString& MIN_WN_FREQ = KGlobal::staticQString("Min. White Noise Freq.");
+static const QString& SAMPLING_FREQ = KGlobal::staticQString("SamplingFrequency (Hz)");
+static const QString& K = KGlobal::staticQString("K");
-int effective_bandwidth(const double *const inArrays[], const int inArrayLens[],
- const double inScalars[],
- double *outArrays[], int outArrayLens[],
- double outScalars[])
-{
- if ((inArrayLens[1] != inArrayLens[0] ) || (inArrayLens[0] < 1)) {
- return -2;
+//out
+static const QString& LIMIT = KGlobal::staticQString("White Noise Limit");
+static const QString& SIGMA = KGlobal::staticQString("White Noise Sigma");
+static const QString& EFF_BANDWIDTH = KGlobal::staticQString("Effective Bandwidth");
+
+K_EXPORT_COMPONENT_FACTORY( kstobject_effbandwidth,
+ KGenericFactory<EffBandwidth>( "kstobject_effbandwidth" ) )
+
+EffBandwidth::EffBandwidth( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
+ : KstBasicPlugin() {
+}
+
+
+EffBandwidth::~EffBandwidth() {
+}
+
+
+bool EffBandwidth::algorithm() {
+ KstVectorPtr xArray = inputVector(X_ARRAY);
+ KstVectorPtr yArray = inputVector(Y_ARRAY);
+
+ KstScalarPtr min = inputScalar(MIN_WN_FREQ);
+ KstScalarPtr sampling = inputScalar(SAMPLING_FREQ);
+ KstScalarPtr k = inputScalar(K);
+
+ KstScalarPtr limit = outputScalar(LIMIT);
+ KstScalarPtr sigma = outputScalar(SIGMA);
+ KstScalarPtr eff = outputScalar(EFF_BANDWIDTH);
+
+ if ((yArray->length() != xArray->length() ) || (xArray->length() < 1)) {
+ return false;
}
double minWhiteNoiseFreq, samplingFrequency, radiometerConstantK;
- minWhiteNoiseFreq = inScalars[0];
- samplingFrequency = inScalars[1];
- radiometerConstantK = inScalars[2];
+ minWhiteNoiseFreq = min->value();
+ samplingFrequency = sampling->value();
+ radiometerConstantK = k->value();
int minWhiteNoiseIndex;
//fast calculation of index for minWhiteNoiseFreq
int i_bot, i_top;
i_bot = 0;
- i_top = inArrayLens[0] - 1;
+ i_top = xArray->length() - 1;
while (i_bot + 1 < i_top) {
int i0 = (i_top + i_bot)/2;
- if (minWhiteNoiseFreq < inArrays[0][i0]) {
+ if (minWhiteNoiseFreq < xArray->value()[i0]) {
i_top = i0;
} else {
i_bot = i0;
@@ -55,8 +83,8 @@
minWhiteNoiseIndex = i_top;
//verify calculated indices.
- if ( !(minWhiteNoiseIndex>0) || !(minWhiteNoiseIndex<(inArrayLens[0]-1)) ) {
- return -2;
+ if ( !(minWhiteNoiseIndex>0) || !(minWhiteNoiseIndex<(xArray->length()-1)) ) {
+ return false;
}
// calculate white noise limit
@@ -66,23 +94,55 @@
int i;
double yi;
- for (i = minWhiteNoiseIndex; i < inArrayLens[0]; i++) {
- yi = inArrays[1][i];
+ for (i = minWhiteNoiseIndex; i < xArray->length(); i++) {
+ yi = yArray->value()[i];
sumY += yi;
sumY2 += pow(yi,2);
}
double ybar, ysigma;
- ybar = sumY/(inArrayLens[0] - minWhiteNoiseIndex);
- ysigma = sqrt((sumY2 - 2*ybar*sumY + pow(ybar,2)*(inArrayLens[0] - minWhiteNoiseIndex))/(inArrayLens[0] - minWhiteNoiseIndex));
+ ybar = sumY/(xArray->length() - minWhiteNoiseIndex);
+ ysigma = sqrt((sumY2 - 2*ybar*sumY + pow(ybar,2)*(xArray->length() - minWhiteNoiseIndex))/(xArray->length() - minWhiteNoiseIndex));
// end calculate white noise limit
- double effectiveBandwidth = 2*samplingFrequency*pow(radiometerConstantK*inArrays[1][0]/ysigma,2);
+ double effectiveBandwidth = 2*samplingFrequency*pow(radiometerConstantK*yArray->value()[0]/ysigma,2);
// output fit data
- outScalars[0] = ybar;
- outScalars[1] = ysigma;
- outScalars[2] = effectiveBandwidth;
+ limit->setValue(ybar);
+ sigma->setValue(ysigma);
+ eff->setValue(effectiveBandwidth);
- return 0;
+ return true;
}
+
+
+QStringList EffBandwidth::inputVectorList() const {
+ return QStringList( X_ARRAY ) << Y_ARRAY;
+}
+
+
+QStringList EffBandwidth::inputScalarList() const {
+ return QStringList( MIN_WN_FREQ ) << SAMPLING_FREQ << K;
+}
+
+
+QStringList EffBandwidth::inputStringList() const {
+ return QStringList();
+}
+
+
+QStringList EffBandwidth::outputVectorList() const {
+ return QStringList();
+}
+
+
+QStringList EffBandwidth::outputScalarList() const {
+ return QStringList( LIMIT ) << SIGMA << EFF_BANDWIDTH;
+}
+
+
+QStringList EffBandwidth::outputStringList() const {
+ return QStringList();
+}
+
+#include "effective_bandwidth.moc"
--- branches/work/kst/pluginify/kst/src/plugins/testplugin/testplugin.cpp #586477:586478
@@ -16,7 +16,6 @@
***************************************************************************/
#include "testplugin.h"
-#include <kdebug.h>
#include <kgenericfactory.h>
static const QString& VECTOR_IN = KGlobal::staticQString("Vector In");
More information about the Kst
mailing list