[Kst] CARRAY patch for dirfile datasource

D. V. Wiebe getdata at ketiltrout.net
Fri Dec 3 00:16:29 CET 2010


Hiya guys,

The newest GetData updates the Dirfile Standards to add (in addition to
other things) a scalar field type called CARRAY.  This behaves exactly
like a CONST scalar field, except it can hold multiple values:

  digits CARRAY UINT8 0 1 2 3 4 5 6 7 8 9

We use it when converting MAS flatfiles into dirfiles to store such
things as bias points, &c., which are arrays of data, but constant across
the dirfile.

I've attached a tentative patch to kst2 which conditionally adds support for
this to kst, when the GetData library support it.  You may want to
handle them in some other manner.

The patch doesn't add the CARRAY as a vector (since it's not indexed by
samples, nor frames, nor INDEX), but adds each element of the CARRAY to
the list of scalars using the notation "field_name<n>" where
"field_name" is the field name, "n" is the index of the element,
starting from zero, and '<' and '>' are actual angle brackets.  This
is the notation used internally by GetData.  So, the above would produce
something like "digit<0>", "digit<1>", &c.  Feel free to change it if
there's a more kst-ish notation; GetData won't care.

It seems to work for me here.  (Acutally, it appears to only work with
metafield scalar fields.  kst appears to ignore top-level scalar
(including string) fields found in the dirfile.  Or am I missing
something?)

Here's the format file for a trivial test case (no other data files are
needed):

--CUT--CUT--CUT--
format RAW UINT8 1
format/foo CARRAY UINT16 1 2 3 4 5 6 7 8 9
format/bar CARRAY FLOAT64 1.2 2.3 3.4 4.5 5.6 6.7 7.8
format/baz CONST INT8 1
--CUT--CUT--CUT--

Cheers,
-dvw
-- 
D. V. Wiebe
getdata at ketiltrout.net
http://getdata.sourceforge.net/
-------------- next part --------------
Index: kst/src/datasources/dirfilesource/dirfilesource.cpp
===================================================================
--- kst/src/datasources/dirfilesource/dirfilesource.cpp	(revision 1202971)
+++ kst/src/datasources/dirfilesource/dirfilesource.cpp	(working copy)
@@ -195,6 +195,15 @@ bool DirFileSource::init() {
     for (int i = 0; xl[i]!=NULL; i++) {
       _scalarList.append(QString::fromUtf8(xl[i]));
     }
+#if HAVE_CARRAY
+    xl = _dirfile->FieldListByType(CarrayEntryType);
+    for (int i = 0; xl[i]!=NULL; i++) {
+      size_t len = _dirfile->CarrayLen(xl[i]);
+      for (size_t j = 0; j < len; ++j) {
+        _scalarList.append(QString::fromUtf8(xl[i]) + "<" + j + ">");
+      }
+    }
+#endif
 
     _stringList.append("FILE");
     const char **tl = _dirfile->FieldListByType(StringEntryType);
@@ -283,7 +292,16 @@ int DirFileSource::readScalar(double &S, const QSt
     S = _frameCount;
     return 1;
   } else {
+#if HAVE_CARRAY
+    QStringList list = scalar.split('<');
+    if (list.size() == 2) {
+      _dirfile->GetCarray(list[0].toUtf8().constData(), Float64, (void *)&S,
+          list[1].toUInt(), 1);
+    } else
+#endif
+    {
     _dirfile->GetConstant(scalar.toUtf8().constData(), Float64, (void *)&S);
+    }
     if (_dirfile->Error() == GD_E_OK) {
       return 1;
     }
@@ -313,13 +331,23 @@ int DirFileSource::readString(QString &S, const QS
 
 QStringList DirFileSource::fieldScalars(const QString& field) {
   const char **mflist = _dirfile->MFieldListByType(field.toAscii(), ConstEntryType);
-  if (!mflist) {
-    return QStringList();
-  }
   QStringList scalars;
+  if (mflist) {
   for (int i=0; mflist[i]; i++) {
     scalars.append(mflist[i]);
   }
+  }
+#if HAVE_CARRAY
+  mflist = _dirfile->MFieldListByType(field.toAscii(), CarrayEntryType);
+  if (mflist) {
+    for (int i=0; mflist[i]; i++) {
+      size_t len = _dirfile->CarrayLen(field.toAscii() + '/' + mflist[i]);
+      for (size_t j = 0; j < len; ++j) {
+        scalars.append(QString(mflist[i]) + '<' + QString::number(j) + '>');
+      }
+    }
+  }
+#endif
   return scalars;
 }
 
@@ -332,7 +360,21 @@ int DirFileSource::readFieldScalars(QList<double>
     for (int i=0; i<nc; i++) {
       v.append(vin[i]);
     }
+#if HAVE_CARRAY
+    struct dcarray_t {
+      size_t n;
+      double *v;
+    } *carrays;
+
+    carrays = (struct dcarray_t*)_dirfile->MCarrays(field.toAscii(), Float64);
+    for (int i = 0; carrays[i].n; ++i) {
+      nc += carrays[i].n;
+      for (size_t j = 0; j < carrays[i].n; ++j) {
+        v.append(carrays[i].v[j]);
   }
+    }
+#endif
+  }
   return (nc);
 }
 
@@ -421,7 +463,16 @@ QStringList DirFilePlugin::scalarList(QSettings *c
     for (int i = 0; xl[i]!=NULL; i++) {
       scalarList.append(QString::fromUtf8(xl[i]));
     }
+#if HAVE_CARRAY
+    xl = dirfile.FieldListByType(CarrayEntryType);
+    for (int i = 0; xl[i]!=NULL; i++) {
+      size_t len = dirfile.CarrayLen(xl[i]);
+      for (size_t j = 0; j < len; ++j) {
+        scalarList.append(QString::fromUtf8(xl[i]) + "<" + QString::number(j) + ">");
   }
+    }
+#endif
+  }
 
   if (complete) {
     *complete = true;
Index: kst/src/datasources/dirfilesource/dirfilesource.h
===================================================================
--- kst/src/datasources/dirfilesource/dirfilesource.h	(revision 1202971)
+++ kst/src/datasources/dirfilesource/dirfilesource.h	(working copy)
@@ -22,6 +22,12 @@
 #include <dataplugin.h>
 #include <getdata/dirfile.h>
 
+#if defined GD_DIRFILE_STANDARDS_VERSION && GD_DIRFILE_STANDARDS_VERSION >= 8
+#define HAVE_CARRAY 1
+#else
+#define HAVE_CARRAY 0
+#endif
+
 using namespace GetData;
 
 class QFileSystemWatcher;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/kst/attachments/20101202/7c043450/attachment.sig 


More information about the Kst mailing list