[Kst] extragear/graphics/kst/src/datasources/scuba2

Andrew Walker arwalker at sumusltd.com
Fri Mar 23 21:51:31 CET 2007


SVN commit 645883 by arwalker:

first draft of binary format data

 M  +218 -30   scuba.cpp  
 M  +2 -0      scuba.h  


--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.cpp #645882:645883
@@ -91,16 +91,16 @@
     "Comm Error Box Temp",    // value 32 of housekeeping block
     "Box Temp",               // value 33 of housekeeping block
 
-                              // value 34 of housekeeping block is currently reserved
-                              // value 35 of housekeeping block is currently reserved
-                              // value 36 of housekeeping block is currently reserved
-                              // value 37 of housekeeping block is currently reserved
-                              // value 38 of housekeeping block is currently reserved
-                              // value 39 of housekeeping block is currently reserved
-                              // value 40 of housekeeping block is currently reserved
-                              // value 41 of housekeeping block is currently reserved
-                              // value 42 of housekeeping block is currently reserved
-                              // value 43 of housekeeping block is currently reserved
+    "",                       // value 34 of housekeeping block is currently reserved
+    "",                       // value 35 of housekeeping block is currently reserved
+    "",                       // value 36 of housekeeping block is currently reserved
+    "",                       // value 37 of housekeeping block is currently reserved
+    "",                       // value 38 of housekeeping block is currently reserved
+    "",                       // value 39 of housekeeping block is currently reserved
+    "",                       // value 40 of housekeeping block is currently reserved
+    "",                       // value 41 of housekeeping block is currently reserved
+    ""                        // value 42 of housekeeping block is currently reserved
+    ""                        // value 43 of housekeeping block is currently reserved
 };
 
 static int numHousekeepingFields = sizeof(housekeepingFields)/sizeof(char*);
@@ -165,6 +165,7 @@
   _rowLen = 0;
   _format = FormatText2;
   _numEntriesInFormatText2Line = 8;
+  _numEntriesInFormatBinaryLine = 8;
   _first = true;
   _numFramesLastReadMatrix = 0;
 
@@ -242,7 +243,27 @@
   return read;
 }
 
+void ScubaSource::setDataType(QFile& file) {
+  int length = 200;
+  int read;
+  char text[length];
 
+  read = file.readBlock((char*)text, length);
+  if (read == length) {
+    int i;
+
+    _format = FormatText2;
+
+    for (i=0; i<read; i++) {
+      if ( !isdigit(text[i]) && !isspace(text[i]) && text[i] != '\n') {
+        _format = FormatBinary;
+
+        break;
+      }
+    }
+  }
+}
+
 bool ScubaSource::initFrameIndex() {
   bool rc = false;
 
@@ -313,9 +334,13 @@
       ++line;
     }
 
-    _numCols = 8;
+    if (s.compare(END_HEADER_1) == 0) {
+      setDataType(file);
+    }
 
     _first = false;
+
+    file.close();
   }
 
   return rc;
@@ -363,9 +388,45 @@
             // currently not operational...
             //
           } else if (_format == FormatBinary) {
-            //
-            // currently no test data available...
-            //
+            long length = numHousekeepingFields + ( _numRows * _numEntriesInFormatBinaryLine );
+            long values[length];
+            long value;
+            long checksum;
+            long read = 0;
+            int i;
+
+            while (read != -1) {
+              checksum = 0;
+
+              read = file.readBlock((char*)values, length * sizeof( long ) );
+              if (read == length * (long)sizeof( long ) ) {
+                for (i=0; i<length; i++) {
+                  checksum ^= values[i];
+                }
+              } else {
+                read = -1;
+              }
+
+              if (read != -1) {
+                //
+                // read the checksum value...
+                //
+                read = file.readBlock((char*)(&value), sizeof( long ) );
+                if (read == sizeof( long ) ) {
+                  if (value == checksum) {
+                    if (_numFrames >= _numFrameIndexAlloc) {
+                      _numFrameIndexAlloc += FRAMEINDEXBUFFERINCREMENT;
+                      _frameIndex = (QIODevice::Offset*)realloc(_frameIndex, _numFrameIndexAlloc*sizeof(QIODevice::Offset));
+                    }
+                    new_data = true;
+                    ++_numFrames;
+                    _frameIndex[_numFrames] = file.at();
+                  }
+                } else {
+                  read = -1;
+                }
+              }
+            }
           } else if (_format == FormatText2) {
             QStringList entries;
             QString s;
@@ -395,7 +456,6 @@
 
               if (read != -1) {
                 read = readFullLine(file, s);
-
                 if (read != -1) {
                   value = s.toInt(&ok, 10);
 
@@ -468,8 +528,6 @@
 
         if (file.open(IO_ReadOnly)) {
           double *values = data->z;
-          QStringList entries;
-          QString str;
           long lvalue = 0;
           bool ok;
           bool error = false;
@@ -503,9 +561,72 @@
               //
             } else if (_format == FormatBinary) {
               //
-              // currently no test data available...
+              // always need to skip the first line as it is the header...
               //
+/*
+              for (i=0; i<yStart+1; ++i) {
+                read = readFullLine(file, str);
+              }
+
+              for (i=0; i<yNumSteps; ++i) {
+                read = readFullLine(file, str);
+                if (read != -1) {
+                  entries = QStringList::split(QChar(' '), str);
+                  for (j=0; j<xNumSteps; j++) {
+                    if (j < int(entries.size())) {
+                      lvalue = entries[j].toInt(&ok, 10);
+                      if (!ok) {
+                        *values = KST::NOPOINT;
+                      } else {
+                        switch (_datamode) {
+                          case DataError:
+                          case DataPreScaleFeedback:
+                          case DataFiltered:
+                          case DataRaw:
+                            break;
+                          case Data18_14:
+                            if (!error) {
+                              lvalue /= 0x4000;
+                            } else {
+                              lvalue &= 0x3FFF;
+                              if (lvalue & 0x2000) {
+                                lvalue -= 0x4000;
+                              }
+                            }
+                            break;
+                          case Data24_8:
+                            if (!error) {
+                              lvalue /= 0x100;
+                            } else {
+                              lvalue &= 0xFF;
+                              if (lvalue & 0x80) {
+                                lvalue -= 0x100;
+                              }
+                            }
+                            break;
+                        }
+
+                        if (max) {
+                          if (frame > frameStart && double(lvalue) > *values) {
+                            *values = double(lvalue);
+                          }
+                        } else if (avg) {
+                          *values += double(lvalue);
+                        } else {
+                          *values = double(lvalue);
+                        }
+                      }
+
+                      ++values;
+                    }
+                  }
+                }
+              }
+*/
             } else if (_format == FormatText2) {
+              QStringList entries;
+              QString str;
+
               //
               // always need to skip the first line as it is the header...
               //
@@ -636,13 +757,9 @@
       QIODevice::Offset bufread = _frameIndex[(s + n)/iSamplesPerFrame] - _frameIndex[s/iSamplesPerFrame];
 
       if (bufread > 0) {
-        QStringList values;
         QFile file(_filename);
-        QString str;
         long lvalue = 0;
-        bool ok;
         int valueIndex = 0;
-        int read = 0;
 
         if (file.open(IO_ReadOnly)) {
           if (_format == FormatText) {
@@ -650,14 +767,83 @@
             // currently not operational...
             //
           } else if (_format == FormatBinary) {
-            //
-            // currently no test data available...
-            //
+            long read = 0;
+
+            for (i = 0; i < n; ++i) {
+              v[i] = KST::NOPOINT;
+
+              file.at(_frameIndex[(s + i)/iSamplesPerFrame]);
+
+              if (fieldIndex < numHousekeepingFields) {
+                long values[numHousekeepingFields];
+
+                read = file.readBlock((char*)values, ( fieldIndex + 1 ) * sizeof( long ) );
+                if( read == ( fieldIndex + 1 ) * (long)sizeof( long ) ) {
+                  v[i] = double(values[fieldIndex]);
+                }
+              } else {
+                long length;
+
+                switch (_datamode) {
+                  case DataError:
+                  case DataPreScaleFeedback:
+                  case DataFiltered:
+                  case DataRaw:
+                    valueIndex = fieldIndex - numHousekeepingFields;
+                    valueIndex += s + i - (((s + i)/iSamplesPerFrame) * iSamplesPerFrame ); 
+                    break;
+                  case Data18_14:
+                  case Data24_8:
+                    valueIndex = (fieldIndex - numHousekeepingFields) / 2;
+                    break;
+                }
+
+                length = numHousekeepingFields + valueIndex + 1;
+                long values[length];
+                read = file.readBlock((char*)values, length * sizeof( long ) );
+
+                if (read == length * (long)sizeof( long ) ) {
+                  lvalue = values[length];
+                  switch (_datamode) {
+                    case DataError:
+                    case DataPreScaleFeedback:
+                    case DataFiltered:
+                    case DataRaw:
+                      break;
+                    case Data18_14:
+                      if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                        lvalue /= 0x4000;
+                      } else {
+                        lvalue &= 0x3FFF;
+                        if (lvalue & 0x2000) {
+                          lvalue -= 0x4000;
+                        }
+                      }
+                      break;
+                    case Data24_8:
+                      if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                        lvalue /= 0x100;
+                      } else {
+                        lvalue &= 0xFF;
+                        if (lvalue & 0x80) {
+                          lvalue -= 0x100;
+                        }
+                      }
+                      break;
+                  }
+                  v[i] = double(lvalue);
+                }
+              }
+            }
+
+            rc = n;
           } else if (_format == FormatText2) {
-            QStringList entries;
+            QStringList values;
             QString str;
+            bool ok;
             int lineIndex;
             int lines;
+            int read = 0;
 
             for (i = 0; i < n; ++i) {
               v[i] = KST::NOPOINT;
@@ -666,9 +852,9 @@
 
               if (fieldIndex < numHousekeepingFields) {
                 if( readFullLine(file, str) != -1) {
-                  entries = QStringList::split(QChar(' '), str);
-                  if (fieldIndex < int(entries.size())) {
-                    v[i] = double(entries[fieldIndex].toInt(&ok, 10));
+                  values = QStringList::split(QChar(' '), str);
+                  if (fieldIndex < int(values.size())) {
+                    v[i] = double(values[fieldIndex].toInt(&ok, 10));
                     if (!ok) {
                       v[i] = KST::NOPOINT;
                     }
@@ -876,7 +1062,9 @@
     rc += "INDEX";
 
     for (i=0; i<numHousekeepingFields; i++) {
-      rc += housekeepingFields[i];
+      if (strlen(housekeepingFields[i]) > 0) {
+        rc += housekeepingFields[i];
+      }
     }
 
     if (datamode == DataRaw) {
--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.h #645882:645883
@@ -55,6 +55,7 @@
     static QStringList fieldListFor(const QString& filename, Config *cfg);
   private:
     bool initFrameIndex();
+    void setDataType(QFile& file);
 
     int _datamode;
     int _rowLen;
@@ -63,6 +64,7 @@
     int _rowStart;
     int _colStart;
     int _numEntriesInFormatText2Line;
+    int _numEntriesInFormatBinaryLine;
     QIODevice::Offset *_frameIndex;
     QValueList<int> _rows;
     DataFormat _format;


More information about the Kst mailing list