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

Andrew Walker arwalker at sumusltd.com
Sat Mar 24 00:24:13 CET 2007


SVN commit 645958 by arwalker:

add matrix handling for binary format

 M  +38 -35    scuba.cpp  
 M  +1 -0      scuba.h  


--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.cpp #645957:645958
@@ -100,7 +100,6 @@
     "",                       // 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*);
@@ -166,9 +165,16 @@
   _format = FormatText2;
   _numEntriesInFormatText2Line = 8;
   _numEntriesInFormatBinaryLine = 8;
+  _numHousekeepingFieldsInUse = 0;
   _first = true;
   _numFramesLastReadMatrix = 0;
 
+  for (int i=0; i<numHousekeepingFields; i++) {
+    if (strlen(housekeepingFields[i]) > 0) {
+      _numHousekeepingFieldsInUse++;
+    }
+  }
+
   if (type.isEmpty() || type == "SCUBA") {
     _config = new ScubaSource::Config;
     _config->read(cfg, filename);
@@ -561,23 +567,20 @@
               //
             } else if (_format == FormatBinary) {
               //
-              // always need to skip the first line as it is the header...
+              // always need to skip the housekeeping fields...
               //
-/*
-              for (i=0; i<yStart+1; ++i) {
-                read = readFullLine(file, str);
-              }
+              int length = numHousekeepingFields + ( _numRows * _numEntriesInFormatBinaryLine );
+              long rawValues[length];
+              long read;
 
-              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 {
+              read = file.readBlock((char*)rawValues, length * sizeof( long ));
+              if( read == length * (long)sizeof( long )) {
+                for (i=0; i<yNumSteps; ++i) {
+                  if (i < _numRows) {
+                    for (j=0; j<xNumSteps; j++) {
+                      if (j < _numEntriesInFormatBinaryLine) {
+                        lvalue = rawValues[numHousekeepingFields + ( i * _numEntriesInFormatBinaryLine ) + j];
+
                         switch (_datamode) {
                           case DataError:
                           case DataPreScaleFeedback:
@@ -622,7 +625,6 @@
                   }
                 }
               }
-*/
             } else if (_format == FormatText2) {
               QStringList entries;
               QString str;
@@ -768,42 +770,43 @@
             //
           } else if (_format == FormatBinary) {
             long read = 0;
+            long length;
 
             for (i = 0; i < n; ++i) {
               v[i] = KST::NOPOINT;
 
               file.at(_frameIndex[(s + i)/iSamplesPerFrame]);
 
-              if (fieldIndex < numHousekeepingFields) {
-                long values[numHousekeepingFields];
+              if (fieldIndex < _numHousekeepingFieldsInUse) {
+                long values[_numHousekeepingFieldsInUse];
 
-                read = file.readBlock((char*)values, ( fieldIndex + 1 ) * sizeof( long ) );
-                if( read == ( fieldIndex + 1 ) * (long)sizeof( long ) ) {
+                length = fieldIndex + 1;
+                read = file.readBlock((char*)values, length * sizeof( long ) );
+                if( read == length * (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 = fieldIndex - _numHousekeepingFieldsInUse;
                     valueIndex += s + i - (((s + i)/iSamplesPerFrame) * iSamplesPerFrame ); 
                     break;
                   case Data18_14:
                   case Data24_8:
-                    valueIndex = (fieldIndex - numHousekeepingFields) / 2;
+                    valueIndex = (fieldIndex - _numHousekeepingFieldsInUse) / 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[numHousekeepingFields + valueIndex];
 
-                if (read == length * (long)sizeof( long ) ) {
-                  lvalue = values[length];
                   switch (_datamode) {
                     case DataError:
                     case DataPreScaleFeedback:
@@ -811,7 +814,7 @@
                     case DataRaw:
                       break;
                     case Data18_14:
-                      if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                      if ( ( fieldIndex - _numHousekeepingFieldsInUse ) % 2 == 0) {
                         lvalue /= 0x4000;
                       } else {
                         lvalue &= 0x3FFF;
@@ -821,7 +824,7 @@
                       }
                       break;
                     case Data24_8:
-                      if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                      if ( ( fieldIndex - _numHousekeepingFieldsInUse ) % 2 == 0) {
                         lvalue /= 0x100;
                       } else {
                         lvalue &= 0xFF;
@@ -850,7 +853,7 @@
 
               file.at(_frameIndex[(s + i)/iSamplesPerFrame]);
 
-              if (fieldIndex < numHousekeepingFields) {
+              if (fieldIndex < _numHousekeepingFieldsInUse) {
                 if( readFullLine(file, str) != -1) {
                   values = QStringList::split(QChar(' '), str);
                   if (fieldIndex < int(values.size())) {
@@ -866,12 +869,12 @@
                   case DataPreScaleFeedback:
                   case DataFiltered:
                   case DataRaw:
-                    valueIndex = fieldIndex - numHousekeepingFields;
+                    valueIndex = fieldIndex - _numHousekeepingFieldsInUse;
                     valueIndex += s + i - (((s + i)/iSamplesPerFrame) * iSamplesPerFrame ); 
                     break;
                   case Data18_14:
                   case Data24_8:
-                    valueIndex = (fieldIndex - numHousekeepingFields) / 2;
+                    valueIndex = (fieldIndex - _numHousekeepingFieldsInUse) / 2;
                     break;
                 }
 
@@ -897,7 +900,7 @@
                         case DataRaw:
                           break;
                         case Data18_14:
-                          if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                          if ( ( fieldIndex - _numHousekeepingFieldsInUse ) % 2 == 0) {
                             lvalue /= 0x4000;
                           } else {
                             lvalue &= 0x3FFF;
@@ -907,7 +910,7 @@
                           }
                           break;
                         case Data24_8:
-                          if ( ( fieldIndex - numHousekeepingFields ) % 2 == 0) {
+                          if ( ( fieldIndex - _numHousekeepingFieldsInUse ) % 2 == 0) {
                             lvalue /= 0x100;
                           } else {
                             lvalue &= 0xFF;
@@ -1123,7 +1126,7 @@
     if (_config->_readMatrices) {
       if (_datamode != DataRaw) {
         QFile file(_filename);
-    
+
         if (file.open(IO_ReadOnly)) {
           QStringList entries;
           QStringList rc;
@@ -1138,7 +1141,7 @@
           int read;
           int row;
           int i;
-    
+
           while (!done) {
             read = file.readLine(s, 1000);
             if (read < 0) {
--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.h #645957:645958
@@ -65,6 +65,7 @@
     int _colStart;
     int _numEntriesInFormatText2Line;
     int _numEntriesInFormatBinaryLine;
+    int _numHousekeepingFieldsInUse;
     QIODevice::Offset *_frameIndex;
     QValueList<int> _rows;
     DataFormat _format;


More information about the Kst mailing list