[Kst] branches/work/kst/1.6/kst/src/libkst

Andrew Walker arwalker at sumusltd.com
Sat Nov 17 00:10:57 CET 2007


SVN commit 737669 by arwalker:

set scalar values for KstSMatrix

 M  +2 -6      kstamatrix.cpp  
 M  +1 -3      kstamatrix.h  
 M  +14 -14    kstmatrix.cpp  
 M  +9 -9      kstmatrix.h  
 M  +48 -18    kstsmatrix.cpp  
 M  +8 -3      kstsmatrix.h  


--- branches/work/kst/1.6/kst/src/libkst/kstamatrix.cpp #737668:737669
@@ -31,7 +31,7 @@
   double in_xMin = 0, in_yMin = 0, in_xStep = 1, in_yStep = 1;
   int in_nX = 2, in_nY = 2;
   QString in_tag = QString::null; 
-  
+
   // must get the grid dimensions before the data
   QDomNode n = e.firstChild();
   while (!n.isNull()) {
@@ -51,7 +51,7 @@
         in_xStep = e.text().toDouble();
       } else if (e.tagName() == "ystep") {
         in_yStep = e.text().toDouble();
-      } 
+      }
     }
     n = n.nextSibling();
   }
@@ -96,9 +96,7 @@
 
 
 void KstAMatrix::save(QTextStream &ts, const QString& indent) {
-
   QString indent2 = "  ";
-  
   QByteArray qba(_zSize*sizeof(double));
   QDataStream qds(qba, IO_WriteOnly);
 
@@ -118,5 +116,3 @@
   ts << indent << "</amatrix>" << endl;
 }
 
-
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/libkst/kstamatrix.h #737668:737669
@@ -31,7 +31,5 @@
 typedef KstSharedPtr<KstAMatrix> KstAMatrixPtr;
 typedef KstObjectList<KstAMatrixPtr> KstAMatrixList;
 
-
-
 #endif
-// vim: ts=2 sw=2 et
+
--- branches/work/kst/1.6/kst/src/libkst/kstmatrix.cpp #737668:737669
@@ -180,25 +180,25 @@
 
 
 void KstMatrix::calcNoSpikeRange(double per) {
-  double *min_list, *max_list, min_of_max, max_of_min;
+  double *min_list, *max_list;
+  double min_of_max, max_of_min;
+  double n_skip;
+  double x = 0.0;
   int n_list;
   int max_n = 50000; // the most samples we will look at...
-  double n_skip;
-  double x=0;
-  int n_notnan;
+  int n_notnan = 0;
+  int i, j, k;
 
-  int i,j, k;
-
   // count number of points which aren't nans.
-  for (i=n_notnan=0; i<_NS; i++) {
+  for (i=0; i<_NS; i++) {
     if (!KST_ISNAN(_z[i])) {
       n_notnan++;
     }
   }
 
-  if (n_notnan==0) {
-    _minNoSpike = 0;
-    _maxNoSpike = 0;
+  if (n_notnan == 0) {
+    _minNoSpike = 0.0;
+    _maxNoSpike = 0.0;
 
     return;
   }
@@ -207,14 +207,14 @@
   max_n *= int((double)_NS/(double)n_notnan);
 
   n_skip = (double)_NS/max_n;
-  if (n_skip<1.0) n_skip = 1.0;
+  if (n_skip < 1.0) {
+    n_skip = 1.0;
+  }
 
   n_list = int(double(_NS)*per/n_skip);
-
   min_list = (double *)malloc(n_list * sizeof(double));
   max_list = (double *)malloc(n_list * sizeof(double));
 
-
   // prefill the list
   for (i=0; i<n_list; i++) {
     j = int(i*n_skip);
@@ -242,8 +242,8 @@
         }
       }
     }
+
     if (_z[j] > min_of_max) { // member for the max list
-      //printf("******** z: %g  min_of_max: %g\n", _z[j], min_of_max);
       // replace min of max with the new value
       for (k=0; k<n_list; k++) {
         if (max_list[k]==min_of_max) {
--- branches/work/kst/1.6/kst/src/libkst/kstmatrix.h #737668:737669
@@ -37,7 +37,7 @@
 
   protected:
     ~KstMatrix();
-    
+
   public:
     void change(const KstObjectTag& tag, uint nX, uint nY, double minX, double minY,
         double stepX, double stepY);
@@ -45,10 +45,15 @@
     // Return the sample count (x times y) of the matrix
     virtual int sampleCount() const;
 
+    // spike insensitive values 
+    virtual void calcNoSpikeRange(double per = 0.005);
+    virtual double maxValueNoSpike() const;
+    virtual double minValueNoSpike() const;
+
     // return the z value of the rectangle in which the specified point lies
     // ok is false if the point is out of bounds
     double value(double x, double y, bool *ok = 0L);
-    
+
     // set the z value of the rectangle in which the specified point lies
     // return false if the point is out of bounds
     bool setValue(double x, double y, double z);
@@ -56,7 +61,7 @@
     // return the value of the specified rectangle 
     // ok is false if the rectangle does not exist
     double valueRaw(int x, int y, bool *ok = 0L);
-    
+
     // set the value of the specified rectangle
     // return false if the rectangle does not exist
     bool setValueRaw(int x, int y, double z);
@@ -65,11 +70,6 @@
     double minValue() const;
     double maxValue() const;
 
-    // spike insensitive values 
-    void calcNoSpikeRange(double per = 0.005);
-    double maxValueNoSpike() const;
-    double minValueNoSpike() const;
-
     // return mean of the z values
     double meanValue() const;
 
@@ -156,7 +156,7 @@
     // the flat-packed array in row-major order
     double *_z;
     int _zSize; // internally keep track of real _z size
-    
+
     // for resizing the internal array _z only
     virtual bool resizeZ(int sz, bool reinit = true);
 
--- branches/work/kst/1.6/kst/src/libkst/kstsmatrix.cpp #737668:737669
@@ -19,8 +19,8 @@
 #include <qstylesheet.h>
 
 KstSMatrix::KstSMatrix(const QDomElement &e) : KstMatrix() {
-  double in_xMin = 0, in_yMin = 0, in_xStep = 1, in_yStep = 1;
-  double in_gradZMin = 0, in_gradZMax = 1;
+  double in_xMin = 0.0, in_yMin = 0.0, in_xStep = 1.0, in_yStep = 1.0;
+  double in_gradZMin = 0.0, in_gradZMax = 1.0;
   bool in_xDirection = true;
   int in_nX = 2, in_nY = 2;
   QString in_tag = QString::null;
@@ -73,9 +73,8 @@
 }
 
 void KstSMatrix::save(QTextStream &ts, const QString& indent) {
-      
   QString indent2 = "  ";
-  
+
   ts << indent << "<smatrix>" << endl;
   ts << indent << indent2 << "<tag>" << QStyleSheet::escape(tag().tagString()) << "</tag>" << endl;
   ts << indent << indent2 << "<xmin>" << minX() << "</xmin>" << endl;
@@ -94,22 +93,22 @@
                         uint nY, double minX, double minY, double stepX,
                         double stepY, double gradZMin, double gradZMax,
                         bool xDirection) {
-  setTagName(tag);  
-  
+  setTagName(tag);
+
   // some checks on parameters
   if (nX < 1) {
-    nX = 1;  
+    nX = 1;
   }
   if (nY < 1) {
-    nY = 1;  
+    nY = 1;
   }
-  if (stepX <= 0) {
+  if (stepX <= 0.0) {
     stepX = 0.1;
   }
-  if (stepY <= 0) {
+  if (stepY <= 0.0) {
     stepY = 0.1;
   }
-  
+
   _nX = nX;
   _nY = nY;
   _minX = minX;
@@ -119,7 +118,7 @@
   _gradZMin = gradZMin;
   _gradZMax = gradZMax;
   _xDirection = xDirection;
-  
+
   if (_nX*_nY != _zSize) {
     resizeZ(_nX*_nY, false);
   }
@@ -130,16 +129,19 @@
     if (_nX > 1) {
       zIncrement = (_gradZMax - _gradZMin) / (_nX - 1);
     } else {
-      zIncrement = 0; 
+      zIncrement = 0.0;
     }
   } else {
     if (_nY > 1) {
       zIncrement = (_gradZMax - _gradZMin) / (_nY - 1);  
     } else {
-      zIncrement = 0;
-    }  
+      zIncrement = 0.0;
+    }
   }
-  
+
+  double sum = 0.0;
+  double sumsquared = 0.0;
+
   // fill in the matrix with the gradient
   for (int i = 0; i < _nX; i++) {
     for (int j = 0; j < _nY; j++) {
@@ -148,10 +150,38 @@
       } else {
         _z[i*nY + j] = _gradZMin + j*zIncrement;
       }
-    }  
+      sum += _z[i];
+      sumsquared += _z[i] * _z[i];
+    }
   }
+
+  _statScalars["sum"]->setValue(sum);
+  _statScalars["sumsquared"]->setValue(sumsquared);
+  _statScalars["max"]->setValue(gradZMin);
+  _statScalars["min"]->setValue(gradZMax);
+  _statScalars["minpos"]->setValue(0.0);
+  _statScalars["mean"]->setValue((gradZMax-gradZMin)/2.0);
+  _statScalars["ns"]->setValue(_nX*_nY);
+  _statScalars["rms"]->setValue(0.0);
+  _statScalars["sigma"]->setValue(0.0);
+
   setDirty(true);
 }
 
 
-// vim: ts=2 sw=2 et
+double KstSMatrix::minValueNoSpike() const {
+  return _minNoSpike;
+}
+
+
+double KstSMatrix::maxValueNoSpike() const {
+  return _maxNoSpike;
+}
+
+
+void KstSMatrix::calcNoSpikeRange(double per) {
+  Q_UNUSED(per)
+
+  _minNoSpike = _gradZMin;
+  _maxNoSpike = _gradZMax;
+}
--- branches/work/kst/1.6/kst/src/libkst/kstsmatrix.h #737668:737669
@@ -30,15 +30,20 @@
 
     virtual void save(QTextStream &ts, const QString& indent = QString::null);
 
+    // spike insensitive values
+    virtual void calcNoSpikeRange(double per = 0.005);
+    virtual double maxValueNoSpike() const;
+    virtual double minValueNoSpike() const;
+
     void change(KstObjectTag tag, uint nX, uint nY,
                 double minX, double minY, double stepX, double stepY,
                 double gradZMin, double gradZMax, bool xDirection);
-    
+
     // return gradient min and maxes in order
     double gradZMin() { return _gradZMin; }
     double gradZMax() { return _gradZMax; }
     bool xDirection() { return _xDirection; }
-    
+
   private:
     double _gradZMin;
     double _gradZMax;
@@ -49,4 +54,4 @@
 typedef KstObjectList<KstSMatrixPtr> KstSMatrixList;
 
 #endif
-// vim: ts=2 sw=2 et
+


More information about the Kst mailing list