[Kst] extragear/graphics/kst/src/datasources/scuba2
Andrew Walker
arwalker at sumusltd.com
Thu Feb 8 00:21:05 CET 2007
SVN commit 631416 by arwalker:
allow scuba datasource to create matrices
M +297 -55 scuba.cpp
M +1 -0 scuba.h
--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.cpp #631415:631416
@@ -53,7 +53,7 @@
static char* housekeepingFields[] = {
"Status", // value 0 of housekeeping block
- "Frame Sequence Number", // value 1 of housekeeping block
+ "Sequence Number", // value 1 of housekeeping block
"Sync Number", // value 2 of housekeeping block
"DV Pulse Number", // value 3 of housekeeping block
@@ -166,6 +166,7 @@
_format = FormatText2;
_numEntriesInFormatText2Line = 8;
_first = true;
+ _numFramesLastReadMatrix = 0;
if (type.isEmpty() || type == "SCUBA") {
_config = new ScubaSource::Config;
@@ -462,7 +463,150 @@
if (isValidMatrix(matrix)) {
if (xNumSteps > 0 && yNumSteps > 0) {
+ if (_datamode != DataRaw) {
+ QFile file(_filename);
+ if (file.open(IO_ReadOnly)) {
+ double *values = data->z;
+ QStringList entries;
+ int lineIndex;
+ int lines;
+ QString str;
+ long lvalue = 0;
+ bool ok;
+ bool error = false;
+ bool max = false;
+ bool avg = false;
+ int valueIndex = 0;
+ int read = 0;
+ int frameStart = _numFrames;
+ int frameEnd = _numFrames;
+ int frame;
+ int i;
+ int j;
+
+ if (matrix.contains("Error") > 0) {
+ error = true;
+ }
+ if (matrix.contains("Max") > 0) {
+ frameStart = _numFramesLastReadMatrix;
+ max = true;
+ }
+ if (matrix.contains("Avg") > 0) {
+ frameStart = _numFramesLastReadMatrix;
+ avg = true;
+ }
+
+ for (frame=frameStart-1; frame<frameEnd; frame++) {
+ file.at(_frameIndex[frame]);
+
+ if (_format == FormatText) {
+ //
+ // currently not operational...
+ //
+ } else if (_format == FormatBinary) {
+ //
+ // currently no test data available...
+ //
+ } else if (_format == FormatText2) {
+ //
+ // 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 >>= 14;
+ lvalue &= 0x3FFFF;
+ if (lvalue & 0x40000) {
+ lvalue *= -1;
+ lvalue &= 0x1FFFF;
+ }
+ } else {
+ lvalue &= 0x3FFF;
+ if (lvalue & 0x4000) {
+ lvalue *= -1;
+ lvalue &= 0x1FFF;
+ }
+ }
+ break;
+ case Data24_8:
+ if (!error) {
+ lvalue >>= 8;
+ lvalue &= 0xFFFFFF;
+ if (lvalue & 0x800000) {
+ lvalue *= -1;
+ lvalue &= 0x7FFFFF;
+ }
+ } else {
+ lvalue &= 0xFF;
+ if (lvalue & 0x80) {
+ lvalue *= -1;
+ lvalue &= 0x7F;
+ }
+ }
+ break;
+ }
+
+ if (max) {
+ if (frame > frameStart && double(lvalue) > *values) {
+ *values = double(lvalue);
+ }
+ } else if (avg) {
+ *values += double(lvalue);
+ } else {
+ *values = double(lvalue);
+ }
+ }
+
+ ++values;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (avg && frameEnd > frameStart) {
+ values = data->z;
+
+ for (i=0; i<yNumSteps; ++i) {
+ for (j=0; j<xNumSteps; j++) {
+ *values /= double(frameEnd - frameStart);
+ }
+ }
+ }
+
+ data->xMin = xStart;
+ data->yMin = yStart;
+ data->xStepSize = 1;
+ data->yStepSize = 1;
+
+ totalSamples = xNumSteps * yNumSteps;
+
+ _numFramesLastReadMatrix = _numFrames;
+
+ file.close( );
+ }
+ }
}
}
@@ -691,23 +835,24 @@
}
QStringList ScubaSource::fieldListFor(const QString& filename, ScubaSource::Config *cfg) {
- QStringList entries;
QStringList rc;
- QValueList<int> rows;
- QString s;
QFile file(filename);
- bool done = false;
- bool ok;
- int datamode = -1;
- int num_rows = -1;
- int num_cols = -1;
- int row_len = -1;
- int read;
- int row;
- int i;
- int j;
if (file.open(IO_ReadOnly)) {
+ QStringList entries;
+ QValueList<int> rows;
+ QString s;
+ bool done = false;
+ bool ok;
+ int datamode = -1;
+ int num_rows = -1;
+ int num_cols = -1;
+ int row_len = -1;
+ int read;
+ int row;
+ int i;
+ int j;
+
while (!done) {
read = file.readLine(s, 1000);
if (read < 0) {
@@ -759,21 +904,21 @@
for (j=0; j<num_cols; j++) {
switch (datamode) {
case DataError:
- rc += QString("Error[%1,%2]").arg(i).arg(j);
+ rc += QString("Error_%1_%2").arg(i).arg(j);
break;
case DataPreScaleFeedback:
- rc += QString("Pixel[%1,%2]").arg(i).arg(j);
+ rc += QString("Pixel_%1_%2").arg(i).arg(j);
break;
case DataFiltered:
- rc += QString("Pixel(filtered)[%1,%2]").arg(i).arg(j);
+ rc += QString("Pixel_%1_%2").arg(i).arg(j);
break;
case Data18_14:
- rc += QString("Pixel[%1,%2]").arg(i).arg(j);
- rc += QString("Error[%1,%2]").arg(i).arg(j);
+ rc += QString("Pixel_%1_%2").arg(i).arg(j);
+ rc += QString("Error_%1_%2").arg(i).arg(j);
break;
case Data24_8:
- rc += QString("Pixel[%1,%2]").arg(i).arg(j);
- rc += QString("Error[%1,%2]").arg(i).arg(j);
+ rc += QString("Pixel_%1_%2").arg(i).arg(j);
+ rc += QString("Error_%1_%2").arg(i).arg(j);
break;
default:
break;
@@ -784,36 +929,6 @@
//
// include some simple calculations, such as row average, column average, etc...
//
-/*
- //
- // include matrices if requested...
- //
- if (datamode != DataRaw) {
- if (cfg->_readMatrices) {
- for (i=0; i<numFrames; ++i) {
- switch (datamode) {
- case DataError:
- rc += QString("FrameError[%1]").arg(i);
- break;
- case DataPreScaleFeedback:
- rc += QString("FramePixel[%1]").arg(i);
- break;
- case DataFiltered:
- rc += QString("FramePixel(filtered)[%1]").arg(i);
- break;
- case Data18_14:
- rc += QString("FramePixel[%1]").arg(i);
- rc += QString("FrameError[%1]").arg(i);
- break;
- case Data24_8:
- rc += QString("FramePixel[%1]").arg(i);
- rc += QString("FrameError[%1]").arg(i);
- break;
- default:
- break;
- }
- }
-*/
}
file.close();
@@ -835,10 +950,137 @@
QStringList ScubaSource::matrixList() const {
if (_matrixList.isEmpty()) {
- //
- // for scuba data sources, matrix fields start with Frame
- //
- _matrixList = fieldList().grep(QRegExp("Frame*"));
+ if (_config->_readMatrices) {
+ if (_datamode != DataRaw) {
+ QFile file(_filename);
+
+ if (file.open(IO_ReadOnly)) {
+ QStringList entries;
+ QStringList rc;
+ QValueList<int> rows;
+ QString s;
+ bool done = false;
+ bool ok;
+ int datamode = -1;
+ int num_rows = -1;
+ int num_cols = -1;
+ int row_len = -1;
+ int read;
+ int row;
+ int i;
+
+ while (!done) {
+ read = file.readLine(s, 1000);
+ if (read < 0) {
+ done = true;
+ } else if (s.compare(END_HEADER_1) == 0) {
+ done = true;
+ } else if (s.contains("data_mode") == 1) {
+ datamode = s.right(8).toInt(&ok, 16);
+ if (!ok) {
+ datamode = -1;
+ }
+ } else if (s.contains("row_len") == 1) {
+ row_len = s.right(8).toInt(&ok, 16);
+ if (!ok) {
+ row_len = -1;
+ }
+ } else if (s.contains("num_rows") == 1) {
+ num_rows = s.right(8).toInt(&ok, 16);
+ if (!ok) {
+ num_rows = -1;
+ }
+ } else if (s.contains("row_order") == 1) {
+ entries = QStringList::split( QChar('\t'), s);
+ if (!entries.empty()) {
+ s = entries.last();
+ entries = QStringList::split( QChar(' '), s);
+ for (QStringList::ConstIterator it = entries.begin(); it != entries.end(); ++it) {
+ row = (*it).toInt(&ok, 16);
+ if (ok) {
+ rows.append(row);
+ }
+ }
+ }
+ }
+ }
+
+ num_cols = 8;
+
+ for (i=0; i<_numFrames; i++) {
+ switch (datamode) {
+ case DataError:
+ _matrixList += QString("FrameError_%d").arg(i);
+ break;
+ case DataPreScaleFeedback:
+ _matrixList += QString("FramePixel_%d").arg(i);
+ break;
+ case DataFiltered:
+ _matrixList += QString("FramePixel_%d").arg(i);
+ break;
+ case Data18_14:
+ _matrixList += QString("FramePixel_%d").arg(i);
+ _matrixList += QString("FrameError_%d").arg(i);
+ break;
+ case Data24_8:
+ _matrixList += QString("FramePixel_%d").arg(i);
+ _matrixList += QString("FrameError_%d").arg(i);
+ break;
+ default:
+ break;
+ }
+ }
+
+ switch (datamode) {
+ case DataError:
+ _matrixList += QString("FrameErrorLast");
+ _matrixList += QString("FrameErrorRecentAvg");
+ _matrixList += QString("FrameErrorRecentMax");
+ break;
+ case DataPreScaleFeedback:
+ _matrixList += QString("FramePixelLast");
+ _matrixList += QString("FramePixelRecentAvg");
+ _matrixList += QString("FramePixelRecentMax");
+ _matrixList += QString("FramePixelRecentMin");
+
+ _matrixList += QString("FrameErrorLast");
+ _matrixList += QString("FrameErrorRecentAvg");
+ _matrixList += QString("FrameErrorRecentMax");
+ break;
+ case DataFiltered:
+ _matrixList += QString("FramePixelLast");
+ _matrixList += QString("FramePixelRecentAvg");
+ _matrixList += QString("FramePixelRecentMax");
+ _matrixList += QString("FramePixelRecentMin");
+ break;
+ case Data18_14:
+ _matrixList += QString("FramePixelLast");
+ _matrixList += QString("FramePixelRecentAvg");
+ _matrixList += QString("FramePixelRecentMax");
+ _matrixList += QString("FramePixelRecentMin");
+
+ _matrixList += QString("FrameErrorLast");
+ _matrixList += QString("FrameErrorRecentAvg");
+ _matrixList += QString("FrameErrorRecentMax");
+ break;
+ case Data24_8:
+ _matrixList += QString("FramePixelLast");
+ _matrixList += QString("FramePixelRecentAvg");
+ _matrixList += QString("FramePixelRecentMax");
+ _matrixList += QString("FramePixelRecentMin");
+
+ _matrixList += QString("FrameErrorLast");
+ _matrixList += QString("FrameErrorRecentAvg");
+ _matrixList += QString("FrameErrorRecentMax");
+ break;
+ default:
+ break;
+ }
+
+ file.close();
+ }
+ }
+ }
}
return _matrixList;
--- trunk/extragear/graphics/kst/src/datasources/scuba2/scuba.h #631415:631416
@@ -76,6 +76,7 @@
uint _tmpBufSize;
bool _haveHeader;
bool _first;
+ int _numFramesLastReadMatrix;
mutable bool _fieldListComplete;
};
More information about the Kst
mailing list