[Kst] kdeextragear-2/kst/kst/datasources/planck

George Staikos staikos at kde.org
Fri Jan 14 09:15:10 CET 2005


CVS commit by staikos: 

add skip support, though seems to not be quite right yet.  Also could be much
more efficient with changes in piolib.


  M +68 -0     planck.cpp   1.27
  M +2 -0      planck.h   1.11


--- kdeextragear-2/kst/kst/datasources/planck/planck.cpp  #1.26:1.27
@@ -104,4 +104,72 @@ int PlanckSource::readField(double *v, c
 
 
+int PlanckSource::readField(double *v, const QString &field, int s, int n, int skip, int *lastFrameRead) {
+  if (*lastFrameRead) {
+    *lastFrameRead = -1;
+  }
+
+  if (field.lower() == "index") {
+    if (n < 0) {
+      v[0] = double(s);
+      if (*lastFrameRead) {
+        *lastFrameRead = -1; // FIXME
+      }
+      return 1;
+    }
+    for (int i = 1; i <= n; ++i) {
+      v[i - 1] = double(s + i*skip);
+    }
+    if (*lastFrameRead) {
+      *lastFrameRead = -1; // FIXME
+    }
+    return n > 0 ? n : 0;
+  }
+
+  if (!_valid || !_planckObject || !_planckObject->isValid()) {
+    return -1;
+  }
+
+  QSize sz = _planckObject->range(field);
+  long start = sz.width(), end = sz.height();
+  long count = end - start + 1;
+
+  if (s >= count) { // start past the end
+    return 0;
+  }
+
+  if (n < 0) { // reading less than 0 -> read only one sample!
+    n = 1;
+  }
+
+  if (s + (n + 1)*skip > count) { // trying to read past the end
+    n = -1 + (count - s) / skip;
+  }
+
+  if (s + start > end) {
+    kdDebug() << "Nothing to read: (" << start << "," << end << ") " << s << endl;
+    return 0;
+  }
+
+  // PIOLib doesn't have a mechanism to read with skip.  This needs to be added
+  // later.  For now, we read into a temp buffer, then extract what we need.
+  double *tmp = new double[(n + 1) * skip];
+  int rc = _planckObject->readObject(field, tmp, start + s, start + s + (n + 1)*skip - 1);
+  int i = 0;
+  int rctmp = rc;
+  while (rctmp > skip) {
+    rctmp -= skip;
+    v[i] = tmp[(i + 1) * skip];
+    ++i;
+  }
+  delete[] tmp;
+
+  if (*lastFrameRead) {
+    *lastFrameRead = -1; // FIXME
+  }
+
+  return rc;
+}
+
+
 bool PlanckSource::isValidField(const QString& field) const {
   return field.lower() == "index" || _fieldList.contains(field);

--- kdeextragear-2/kst/kst/datasources/planck/planck.h  #1.10:1.11
@@ -34,4 +34,6 @@ class PlanckSource : public KstDataSourc
     virtual int readField(double *v, const QString &field, int s, int n);
 
+    virtual int readField(double *v, const QString &field, int s, int n, int skip, int *lastFrameRead = 0L);
+
     virtual bool isValidField(const QString &field) const;
 




More information about the Kst mailing list