10 #define round(x) floor( (x) + 0.5 )
20 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
23 if ( dir.isEmpty() )
return;
26 QDir d( dir,
"*", QDir::Name, QDir::Files | QDir::Readable );
28 if ( dir.right( 1 ) !=
"/" ) dir +=
"/";
30 QStringList files = d.entryList( QDir::Files );
33 if ( files.size() < 1 )
return;
35 runType = files[ 0 ].right( 3 ).left( 2 ).toUpper();
45 QRegExp rx(
"^[A-J]?\\d{4,6}\\.(?:RA|RI|IP|FI|WA|WI)\\d$" );
47 if ( rx.indexIn( f.toUpper() ) >= 0 )
52 QChar c = f.at( 0 ).toUpper();
53 if ( c.isLetter() && ! channels.contains( c ) )
58 if ( runType ==
"FI" )
60 QStringList oldfList = fileList;
63 fexts <<
"FI1" <<
"FI2" <<
"FI3" <<
"FI4"
64 <<
"FI5" <<
"FI6" <<
"FI7" <<
"FI8"
65 <<
"fi1" <<
"fi2" <<
"fi3" <<
"fi4"
66 <<
"fi5" <<
"fi6" <<
"fi7" <<
"fi8";
67 int ntotf = oldfList.size();
72 foreach ( fext, fexts )
74 foreach( fname, oldfList )
76 if ( fname.endsWith( fext ) )
83 if ( ktotf >= ntotf )
break;
87 if ( channels.isEmpty() ) channels <<
"A";
90 for (
int i = 0; i < fileList.size(); i++ )
96 QChar c = fileList[ i ].at( 0 );
98 data.
channel = ( c.isDigit() ) ?
'A' : c.toAscii();
100 if ( runType ==
"RI" )
103 for (
int j = 0; j < data.
rvalues.size(); j++ )
112 rawLegacyData << data;
113 rawLegacyData << data2;
118 rawLegacyData << data;
124 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
125 QVector< US_DataIO::RawData >& rawConvertedData,
126 QList< TripleInfo >& triples,
131 setTriples( rawLegacyData, triples, runType, tolerance );
135 rawConvertedData.clear();
137 if ( triples.size() == 1 )
139 convert( rawLegacyData, newRawData, triples[ 0 ].tripleDesc,
140 runType, tolerance );
142 rawConvertedData << newRawData;
148 for (
int i = 0; i < triples.size(); i++ )
151 convert( rawLegacyData, newRawData, triples[ i ].tripleDesc,
152 runType, tolerance );
153 qDebug() <<
"Cvt:cvLD: i, trip" << i << triples[i].tripleDesc;
156 rawConvertedData << newRawData;
162 QVector< US_DataIO::RawData* >& rawConvertedData,
163 QList< TripleInfo >& triples,
164 QVector< Excludes >& allExcludes,
171 if ( rawConvertedData[ 0 ]->scanData.empty() )
179 QStringList rmvfilt(
"*.auc" );
180 QStringList rmvfiles = d.entryList( rmvfilt, QDir::Files, QDir::Name );
181 for (
int ii = 0; ii < rmvfiles.size(); ii++ )
182 if ( ! d.remove( rmvfiles[ ii ] ) )
183 qDebug() <<
"Unable to remove file" << rmvfiles[ ii ];
185 QString wavelnp =
"";
187 for (
int i = 0; i < triples.size(); i++ )
189 if ( triples[ i ].excluded )
continue;
191 QString triple = triples[ i ].tripleDesc;
192 QStringList parts = triple.split(
" / ");
194 QString cell = parts[ 0 ];
195 QString channel = parts[ 1 ];
198 if ( runType ==
"WA" )
200 double r = parts[ 2 ].toDouble() * 1000.0;
201 QString radius = QString::number( (
int)
round( r ) );
202 filename = runID +
"."
211 QString wavelength = parts[ 2 ];
212 if ( wavelength.contains(
"." ) )
214 double dwlen = wavelength.toDouble();
215 wavelength = QString::number( qRound( dwlen ) );
216 if ( wavelength == wavelnp )
217 wavelength = wavelength +
"b";
219 wavelnp = wavelength;
220 filename = runID +
"."
224 + wavelength +
".auc";
230 (
unsigned char*) rawConvertedData[ i ]->rawGUID );
232 if ( saveGUIDs && uuidc !=
"00000000-0000-0000-0000-000000000000" )
235 memcpy( triples [ i ].tripleGUID,
236 (
char*) rawConvertedData[ i ]->rawGUID, 16 );
245 memcpy( rawConvertedData[ i ]->rawGUID, (
char*) uuid, 16 );
246 memcpy( triples [ i ].tripleGUID, (
char*) uuid, 16 );
250 QRegExp rx(
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" );
252 ( ! rx.exactMatch( triples[ i ].solution.solutionGUID ) ) )
255 triples[ i ].solution.solutionDesc =
"New Solution";
259 triples[ i ].solution.saveToDisk();
262 triples[ i ].tripleFilename = filename;
266 Excludes currentExcludes = allExcludes [ i ];
270 QVector< US_DataIO::Scan > sourceScans = rawConvertedData[ i ]->scanData;
271 for (
int j = 0; j < sourceScans.size(); j++ )
273 if ( ! currentExcludes.
contains( j ) )
274 currentData.
scanData << sourceScans[ j ];
295 QVector< US_DataIO::RawData >& rawConvertedData,
296 QList< TripleInfo >& triples,
300 rawConvertedData.clear();
302 QStringList nameFilters = QStringList(
"*.auc" );
306 QStringList files = d.entryList( nameFilters,
307 QDir::Files | QDir::Readable, QDir::Name );
309 if ( files.size() == 0 )
313 QStringList part = files[ 0 ].split(
"." );
318 for (
int i = 0; i < files.size(); i++ )
321 part = files[ i ].split(
"." );
323 if ( runType ==
"WA" )
324 wl = QString::number( part[ 4 ].toDouble() / 1000.0 );
330 t.
tripleDesc = part[ 2 ] +
" / " + part[ 3 ] +
" / " + wl;
337 foreach ( file, files )
339 QString filename = dir + file;
346 rawConvertedData << data;
354 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
361 qDebug() <<
"Cvt:cnvt: IN";
362 QStringList parts = triple.split(
" / ");
364 int cell = parts[ 0 ].toInt();
365 char channel = parts[ 1 ].toAscii()[ 0 ];
366 double wavelength = parts[ 2 ].toDouble();
368 QList< US_DataIO::BeckmanRawScan > ccwLegacyData;
371 ccwLegacyData.clear();
374 for (
int i = 0; i < rawLegacyData.size(); i++ )
378 if ( data.
cell == cell &&
380 fabs ( data.
rpoint - wavelength ) < tolerance )
381 ccwLegacyData << data;
385 for (
int i = 0; i < ccwLegacyData.size(); i++ )
387 for (
int j = i + 1; j < ccwLegacyData.size(); j++ )
389 if ( ccwLegacyData[ j ].seconds < ccwLegacyData[ i ].seconds )
390 ccwLegacyData.swap( i, j );
394 if ( ccwLegacyData.isEmpty() )
return ;
396 strncpy( newRawData.
type, runType.toAscii().constData(), 2 );
397 memset( newRawData.
rawGUID, 0, 16 );
398 newRawData.
cell = cell;
400 newRawData.
description = ccwLegacyData[ 0 ].description;
403 double min_radius = 1.0e99;
404 double max_radius = 0.0;
408 for (
int i = 0; i < rawLegacyData.size(); i++ )
410 double first = rawLegacyData[ i ].xvalues[ 0 ];
411 int size = rawLegacyData[ i ].xvalues.size();
412 double last = rawLegacyData[ i ].xvalues[ size - 1 ];
414 min_radius = qMin( min_radius, first );
415 max_radius = qMax( max_radius, last );
416 max_size = qMax( max_size, size );
421 qDebug() <<
"Cvt: runType" << runType;
422 if ( runType ==
"IP" )
425 QStringList descriptionParts = rawLegacyData[ 0 ]
426 .description.split(
" ", QString::SkipEmptyParts );
427 QString proto = descriptionParts[ 1 ].toAscii();
431 if ( proto.toDouble() == 0.0 )
432 delta_r = ( max_radius - min_radius ) / ( max_size - 1 );
435 delta_r = proto.toDouble();
436 qDebug() <<
"Cvt: proto" << proto <<
"delta_r" << delta_r;
446 int radius_count = (int)
round( ( max_radius - min_radius ) / delta_r ) + 1;
447 qDebug() <<
"Cvt: rad_cnt delta_r" << radius_count << delta_r;
448 double radius = min_radius;
449 for (
int j = 0; j < radius_count; j++ )
456 for (
int i = 0; i < ccwLegacyData.size(); i++ )
461 s.
rpm = ccwLegacyData[ i ].rpm;
462 s.
seconds = ccwLegacyData[ i ].seconds;
463 s.
omega2t = ccwLegacyData[ i ].omega2t;
468 int bitmap_size = ( radius_count + 7 ) / 8;
469 uchar* interpolated =
new uchar[ bitmap_size ];
471 memset( interpolated, 0, bitmap_size );
472 qDebug() <<
"Cvt: sc i" << i <<
"interp set";
510 int rCount = ccwLegacyData[ i ].xvalues.size();
511 double r0 = ccwLegacyData[ i ].xvalues[ 0 ];
512 double rLast = ccwLegacyData[ i ].xvalues[ rCount - 1 ];
516 qDebug() <<
"Cvt: rad" << radius <<
"rCount" << rCount << radius_count;
518 for (
int j = 0; j < radius_count; j++ )
525 dr = radius - ccwLegacyData[ i ].xvalues[ k ];
527 if ( runType ==
"IP" )
529 if ( dr > -3.0e-4 && k < rCount )
531 rvalue = ccwLegacyData[ i ].rvalues[ k ];
535 else if ( radius < r0 )
537 rvalue = ccwLegacyData[ i ].rvalues[ 0 ];
541 else if ( radius > rLast || k >= rCount )
543 rvalue = ccwLegacyData[ i ].rvalues[ rCount - 1 ];
550 else if ( dr > -3.0e-4 && k < rCount )
552 rvalue = ccwLegacyData[ i ].rvalues[ k ];
553 rstdev = ccwLegacyData[ i ].nz_stddev ?
554 ccwLegacyData[ i ].stddevs[ k ] : 0.0;
562 else if ( radius < r0 )
564 rvalue = ccwLegacyData[ i ].rvalues[ 0 ];
568 else if ( radius > rLast || k >= rCount )
570 rvalue = ccwLegacyData[ i ].rvalues[ rCount - 1 ];
576 double dv = ccwLegacyData[ i ].rvalues[ k ] -
577 ccwLegacyData[ i ].rvalues[ k - 1 ];
579 double dR = ccwLegacyData[ i ].xvalues[ k ] -
580 ccwLegacyData[ i ].xvalues[ k - 1 ];
582 dr = radius - ccwLegacyData[ i ].xvalues[ k - 1 ];
584 rvalue = ccwLegacyData[ i ].rvalues[ k - 1 ] + dr * dv / dR;
598 qDebug() <<
"Cvt: rCount loop complete";
599 s.
interpolated = QByteArray( (
char*)interpolated, bitmap_size );
600 delete [] interpolated;
608 qDebug() <<
"Cvt:cnvt: RTN";
613 QVector< US_DataIO::RawData >& rawConvertedData,
614 QList< TripleInfo >& triples,
616 QList< double >& subsets )
619 QVector< US_DataIO::RawData >* oldData =
new QVector< US_DataIO::RawData >;
620 *oldData = rawConvertedData;
621 rawConvertedData.clear();
626 QList< TripleInfo > oldTriples = triples;
629 for (
int i = 0; i < oldData->size(); i++ )
631 qDebug() <<
"Cvt:splRA: i cTrip" << i << currentTriple;
632 if ( i != currentTriple )
635 rawConvertedData << oldRawData[ i ];
636 triples << oldTriples[ i ];
642 for (
int j = 1; j < subsets.size(); j++ )
647 strncpy( newRawData.
type, oldRawData[ i ].
type, 2 );
648 memset( newRawData.
rawGUID, 0, 16 );
649 newRawData.
cell = oldRawData[ i ].
cell;
654 for (
int k = 0; k < oldRawData[ i ].
xvalues.size(); k++ )
655 if ( ( oldRawData[ i ].radius( k ) >= subsets[ j - 1 ] ) &&
656 ( oldRawData[ i ].
radius( k ) <= subsets[ j ] ) )
661 for (
int k = 0; k < oldRawData[ i ].
scanData.size(); k++ )
663 oldRawData[ i ].xvalues,
668 rawConvertedData << newRawData;
672 QStringList parts = t.
tripleDesc.split(
" / ");
673 QString wavelength = parts[ 2 ];
675 t.
tripleDesc = QString::number( newRawData.cell ) +
" / " +
676 QString ( newRawData.channel ) +
" / " +
678 qDebug() <<
"Cvt:splRA: tDesc" << t.
tripleDesc;
682 if ( uuidc !=
"00000000-0000-0000-0000-000000000000" )
703 for (
int i = 0; i < triples.size(); i++ )
704 triples[ i ].tripleID = i;
710 QVector< double >& xvalues,
726 int first_reading = 0;
727 for (
int i = 0; i < oldScan.
rvalues.size(); i++ )
729 if ( ( xvalues[ i ] >= r_start ) &&
730 ( xvalues[ i ] <= r_end ) )
733 if ( first_reading == 0 ) first_reading = i;
739 int bitmap_size = ( s.
rvalues.size() + 7 ) / 8;
740 uchar* interpolated =
new uchar[ bitmap_size ];
741 memset( interpolated, 0, bitmap_size );
743 for (
int i = first_reading; i < first_reading + s.
rvalues.size(); i++ )
747 int mask = 1 << ( 7 - bit );
753 s.
interpolated = QByteArray( (
char*)interpolated, bitmap_size );
754 delete [] interpolated;
760 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
761 QList< TripleInfo >& triples,
766 if ( runType ==
"WA" )
774 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
775 QList< TripleInfo >& triples,
782 QStringList wavelengths;
784 for (
int i = 0; i < rawLegacyData.size(); i++ )
786 QString wl = QString::number( rawLegacyData[ i ].rpoint,
'f', 1 );
793 QList< QList< double > > modes;
794 QList< double > mode;
796 for (
int i = 0; i < wavelengths.size(); i++ )
798 double wl = wavelengths[ i ].toDouble();
800 if ( ! mode.empty() && fabs( mode.last() - wl ) > tolerance )
809 if ( mode.size() > 0 ) modes << mode;
813 QList< double > wl_average;
815 for (
int i = 0; i < modes.size(); i++ )
819 for (
int j = 0; j < modes[ i ].size(); j++ ) sum += modes[ i ][ j ];
821 wl_average << (double)
round( 10.0 * sum / modes[ i ].size() ) / 10.0;
826 for (
int i = 0; i < rawLegacyData.size(); i++ )
828 QString cell = QString::number( rawLegacyData[ i ].cell );
829 QString channel = QString( rawLegacyData[ i ].channel );
830 double wl = rawLegacyData[ i ].rpoint;
831 QString wavelength =
"0";
834 for (
int j = 0; j < wl_average.size(); j++ )
836 if ( fabs( wl_average[ j ] - wl ) < tolerance )
838 wavelength = QString::number( (
int)
round( wl_average[ j ] ) );
843 QString t = cell +
" / " + channel +
" / " + wavelength;
845 for (
int j = 0; j < triples.size(); j++ )
847 if ( triples[ j ].tripleDesc == t )
861 QList< US_DataIO::BeckmanRawScan >& rawLegacyData,
862 QList< TripleInfo >& triples,
871 for (
int i = 0; i < rawLegacyData.size(); i++ )
873 QString r = QString::number( rawLegacyData[ i ].rpoint,
'f', 1 );
875 qDebug() <<
"CCR: i, r" << i << r;
882 QList< QList< double > > modes;
883 QList< double > mode;
885 for (
int i = 0; i < radii.size(); i++ )
887 double r = radii[ i ].toDouble();
889 if ( ! mode.empty() && fabs( mode.last() - r ) > tolerance )
898 if ( mode.size() > 0 ) modes << mode;
899 qDebug() <<
"CCR: mode" << mode;
903 QList< double > r_average;
905 for (
int i = 0; i < modes.size(); i++ )
909 for (
int j = 0; j < modes[ i ].size(); j++ ) sum += modes[ i ][ j ];
911 r_average << (double)
round( 10.0 * sum / modes[ i ].size() ) / 10.0;
913 qDebug() <<
"CCR: r_average" << r_average;
917 for (
int i = 0; i < rawLegacyData.size(); i++ )
919 QString cell = QString::number( rawLegacyData[ i ].cell );
920 QString channel = QString( rawLegacyData[ i ].channel );
921 double r = rawLegacyData[ i ].rpoint;
922 QString radius =
"0";
925 for (
int j = 0; j < r_average.size(); j++ )
927 if ( fabs( r_average[ j ] - r ) < tolerance )
929 radius = QString::number( r_average[ j ] );
933 qDebug() <<
"CCR: radius" << radius;
935 QString t = cell +
" / " + channel +
" / " + radius;
938 for (
int j = 0; j < triples.size(); j++ )
940 if ( triples[ j ].tripleDesc == t )
944 qDebug() <<
"CCR: t" << t <<
"found" << found;
957 int byte = location / 8;
958 int bit = location % 8;
960 bitmap[ byte ] |= 1 << ( 7 - bit );
972 tripleDesc = QString(
"" );
973 description = QString(
"" );
976 memset( tripleGUID, 0, 16 );
977 tripleFilename = QString(
"" );
986 qDebug() <<
"tripleID = " << tripleID <<
'\n'
987 <<
"tripleDesc = " << tripleDesc <<
'\n'
988 <<
"description = " << description <<
'\n'
989 <<
"centerpiece = " << centerpiece <<
'\n'
990 <<
"tripleGUID = " << QString( uuidc ) <<
'\n'
991 <<
"tripleFilename = " << tripleFilename <<
'\n'
992 <<
"channelID = " << QString::number( channelID ) <<
'\n'
993 <<
"solutionID = " << QString::number( solution.solutionID ) <<
'\n'
994 <<
"solutionGUID = " << solution.solutionGUID <<
'\n'
995 <<
"solutionDesc = " << solution.solutionDesc;
997 if ( excluded ) qDebug() <<
"excluded";