[Kst] [Bug 120827] Command line option -f fails for some asciifiles

Ted Kisner tskisner.public at gmail.com
Sat Jan 28 00:07:44 CET 2006


It seems that this is a very difficult problem.  In main.cpp, we correctly 
find an ascii datasource for a text file and then create a KstRVector.  Then, 
we call the vector's isValid() function, which calls the ascii datasource's 
isValidField() function.  But the field is not valid yet, since we haven't 
specified the starting line.

So we can't just change the starting line within readField, since we never try 
to read the data before calling isValidField...

So, is there a way of setting the AsciiSource::_config->_dataLine variable 
*before* calling the KstRVector->isValid() function?  And we have to do this 
using the existing interfaces in KstDataSource.

Here's a (somewhat ugly) idea:  what if the ascii datasource always returns 
true for isValidField(), and then readField just returns zero samples if the 
field really isn't valid?  This is what currently happens with a call to 
readField when you specify an invalid field.  I guess we could also return 
one sample of NaN...

Here is a small patch that does this- it now works as expected.  Of course if 
you try to access data that doesn't exist, it will create an empty vector.  
Not sure if this failure mechanism is any worse than displaying an empty plot 
without creating the vector...  Any suggestions of a cleaner way to do this?

-Ted


--- kst/datasources/ascii/ascii.cpp     (revision 502450)
+++ kst/datasources/ascii/ascii.cpp     (working copy)
@@ -452,7 +452,7 @@
     }
     return n;
   }
-
+
   QStringList fieldList = this->fieldList();
   uint col = 0;
   for (QStringList::ConstIterator i = fieldList.begin(); i != 
fieldList.end(); ++i) {
@@ -463,13 +463,24 @@
   }

   if (col + 1 > fieldList.count()) {
-    if (_fieldListComplete) {
-      return 0;
+    _config->_dataLine = s;
+    fieldList = this->fieldList();
+    uint col = 0;
+    for (QStringList::ConstIterator i = fieldList.begin(); i != 
fieldList.end(); ++i) {
+      if (*i == field) {
+        break;
+      }
+      ++col;
     }
-    bool ok = false;
-    col = field.toInt(&ok);
-    if (!ok) {
-      return 0;
+    if (col + 1 > fieldList.count()) {
+      if (_fieldListComplete) {
+        return 0;
+      }
+      bool ok = false;
+      col = field.toInt(&ok);
+      if (!ok) {
+        return 0;
+      }
     }
   }

@@ -575,7 +586,8 @@


 bool AsciiSource::isValidField(const QString& field) const {
-  return fieldList().contains(field);
+  Q_UNUSED(field)
+  return true;
 }


@@ -687,11 +699,8 @@


 QStringList AsciiSource::fieldList() const {
-  if (_fields.isEmpty()) {
-    _fields = fieldListFor(_filename, _config);
-    _fieldListComplete = _fields.count() > 1;
-  }
-
+  _fields = fieldListFor(_filename, _config);
+  _fieldListComplete = _fields.count() > 1;
   return _fields;
 }






More information about the Kst mailing list