[Kst] kdeextragear-2/kst/kst

Barth Netterfield netterfield at astro.utoronto.ca
Fri Jul 11 02:20:40 CEST 2003


CVS commit by netterfield: 

psd's use output vectors instead of locally allocated arrays
output vectors now work from psd's
fixed 1 off bug in kstvector::interpolate()


  M +20 -10    kstpsdcurve.cpp   1.16
  M +0 -1      kstpsdcurve.h   1.13
  M +13 -2     kstvector.cpp   1.30


--- kdeextragear-2/kst/kst/kstpsdcurve.cpp  #1.15:1.16
@@ -25,4 +25,6 @@
 #include <stdlib.h>
 
+#include <iostream>
+
 #include <klocale.h>
 #include "kstpsddialog_i.h"
@@ -113,5 +115,4 @@ void KstPSDCurve::commonConstructor(cons
 
   PSDLen = int(pow(2, Len-1));
-  psd = new double[PSDLen];
 
   ALen = PSDLen*2;
@@ -126,5 +127,8 @@ void KstPSDCurve::commonConstructor(cons
   setAppodize(true);
 
-  KstVectorPtr iv = new KstVector(_tag+"-sv", PSDLen);
+  KstVectorPtr iv = new KstVector(_tag+"-freq", 2);
+  _outputVectors.prepend(iv);
+
+  iv = new KstVector(_tag+"-sv", PSDLen);
   _outputVectors.prepend(iv);
 
@@ -133,9 +137,6 @@ void KstPSDCurve::commonConstructor(cons
 
 KstPSDCurve::~KstPSDCurve() {
-  if (psd != 0L) {
-    delete[] psd;
-  }
   KST::vectorList.remove(_outputVectors[0]);
-  psd = 0L;
+  KST::vectorList.remove(_outputVectors[1]);
 
   delete[] w;
@@ -173,4 +174,6 @@ KstObject::UpdateType KstPSDCurve::updat
   bool force = false;
 
+  double *psd;
+
   if (update_counter == _lastUpdateCounter) {
     return NO_CHANGE;
@@ -197,4 +200,6 @@ KstObject::UpdateType KstPSDCurve::updat
   }
 
+  psd = _outputVectors[0]->value();
+
   for (i_samp = 0; i_samp < PSDLen; i_samp++) {
     psd[i_samp] = 0;
@@ -282,5 +287,10 @@ KstObject::UpdateType KstPSDCurve::updat
   MeanX = MaxX/2.0;
 
+  double *f = _outputVectors[1]->value();
+  f[0] = 0;
+  f[1] = Freq/2.0;
+
   _outputVectors[0]->update(update_counter);
+  _outputVectors[1]->update(update_counter);
 
   return UPDATE;
@@ -288,6 +298,7 @@ KstObject::UpdateType KstPSDCurve::updat
 
 void KstPSDCurve::getPoint(int i, double &x, double &y) {
-  x = double(i)/double(NS) * MaxX;
-  y = psd[i];
+  x = _outputVectors[1]->interpolate(i, NS);
+//xxxdouble(i)/double(NS) * MaxX;
+  y = _outputVectors[0]->interpolate(i, NS);
 }
 
@@ -333,6 +344,5 @@ void KstPSDCurve::setLen(int in_len) {
 
   PSDLen = int(pow(2,Len-1));
-  delete[] psd;
-  psd = new double[PSDLen];
+  _outputVectors[0]->resize(PSDLen);
 
   ALen = PSDLen*2;

--- kdeextragear-2/kst/kst/kstpsdcurve.h  #1.12:1.13
@@ -79,5 +79,4 @@ private:
   int last_n_new;
 
-  double *psd;
   double *w;
   int PSDLen;

--- kdeextragear-2/kst/kst/kstvector.cpp  #1.29:1.30
@@ -23,5 +23,5 @@
 #include <stdio.h>
 #include <math.h>
-
+#include <iostream>
 #include "kstvector.h"
 #include "kstdatacollection.h"
@@ -92,5 +92,5 @@ double KstVector::interpolate(int in_i, 
   }
 
-  fj = in_i * double(_size) / double(ns_i); //scaled index
+  fj = in_i * double(_size-1) / double(ns_i); //scaled index
 
   j = int(floor(fj));          // index of sample one lower
@@ -111,4 +111,15 @@ double KstVector::interpolate(int in_i, 
 
   return _v[j+1]*fdj + _v[j]*(1.0 - fdj);
+}
+
+double KstVector::value(int i) {
+  if (i < 0) {//can't look before begining
+    return 0.0;
+  }
+
+  if (i >= _size) {// can't look past end
+    return 0.0;
+  }
+  return _v[i];
 }
 




More information about the Kst mailing list