3 #include <QApplication>
23 int main(
int argc,
char* argv[] )
25 QApplication application( argc, argv );
33 return application.exec();
39 setObjectName(
"US_ExportLegacy" );
46 setWindowTitle( tr(
"Export Data in Legacy (Beckman) Format" ) );
73 connect(
pb_load, SIGNAL( clicked() ),
74 this, SLOT(
load() ) );
77 connect(
pb_save, SIGNAL( clicked() ),
79 connect(
pb_view, SIGNAL( clicked() ),
95 QLabel* lb_info =
us_banner( tr(
"Information for this Run" ) );
96 QLabel* lb_triples =
us_banner( tr(
"Cell / Channel / Wavelength" ) );
97 QLabel* lb_id =
us_label ( tr(
"Run ID:" ) );
98 QLabel* lb_temp =
us_label ( tr(
"Avg. Temp.:" ) );
99 QLabel* lb_stat =
us_banner( tr(
"Export Status" ) );
105 QFontMetrics fm( font );
106 int fontHeight = fm.lineSpacing();
109 te_desc->setMaximumHeight( fontHeight * 3 + 12 );
113 te_stat->setMaximumHeight( fontHeight * 3 + 12 );
114 te_stat->setTextColor( Qt::blue );
118 lw_triples->setMaximumHeight( fontHeight * 8 + 12 );
134 tr(
"Velocity Data" ),
136 tr(
"Absorbance" ) );
150 connect(
pb_reset, SIGNAL( clicked() ),
151 this, SLOT(
reset() ) );
152 connect(
pb_close, SIGNAL( clicked() ),
153 this, SLOT( close() ) );
154 connect(
pb_help, SIGNAL( clicked() ),
155 this, SLOT(
help() ) );
168 setMaximumSize( qApp->desktop()->size() - QSize( 40, 40 ) );
188 connect( dialog, SIGNAL( changed (
bool ) ),
191 if ( dialog->exec() != QDialog::Accepted )
return;
193 qApp->processEvents();
195 QFontMetrics fm( font );
196 int fontHeight = fm.lineSpacing();
198 lw_triples->setMaximumHeight( fontHeight *
min( ntriples, 8 ) + 12 );
200 for (
int ii = 0; ii < ntriples; ii++ )
213 le_temp->setText( QString::number( avgTemp,
'f', 1 ) +
" " +
DEGC );
215 te_stat->setText( tr(
"%1 input %2 triples" )
221 connect(
lw_triples, SIGNAL( currentRowChanged(
int ) ),
226 QVector< double > RIProfile;
227 QMessageBox msgBox(
this );
228 msgBox.setTextFormat ( Qt::RichText );
235 msgBox.setWindowTitle ( tr(
"RA Export Type" ) );
236 QString mtxt = tr(
"The input is <b>RI</b> data,<br> "
237 "but <b>no RI Profile</b> exists!<br><br>"
238 "So, <b>Pseudo Absorbance (RA)</b><br> "
239 "data will be exported." );
240 msgBox.setText ( mtxt );
241 msgBox.addButton ( QMessageBox::Ok );
248 QString ybtn = tr(
"Absorbance" );
249 QString nbtn = tr(
"Intensity" );
250 QString mtxt = tr(
"For <b>RI</b> data, you may export values as<br>"
251 "<b>Intensity</b> or "
252 "<b>Pseudo Absorbance</b>.<br><br>"
253 "Which export type do you want?" );
254 msgBox.setWindowTitle ( tr(
"RI Export Type" ) );
255 msgBox.setText ( mtxt );
256 QPushButton* pb_abs = msgBox.addButton( ybtn, QMessageBox::YesRole );
257 msgBox.addButton ( nbtn, QMessageBox::NoRole );
258 msgBox.setDefaultButton( pb_abs );
261 if ( msgBox.clickedButton() == pb_abs )
263 DbgLv(1) <<
"RI Export: YES : Absorbance";
269 DbgLv(1) <<
"RI Export: NO : Intensity";
276 for (
int kk = 0; kk <
rawList.size(); kk++ )
301 dialog->move( this->pos() + QPoint( 100, 100 ) );
303 qApp->processEvents();
316 le_temp->setText( QString::number( avgTemp,
'f', 1 ) +
" " +
DEGC );
337 QString dataType = tr(
"Absorbance" );
338 if (
rawDtype ==
"RI" ) dataType = tr(
"Intensity" );
339 if (
rawDtype ==
"WI" ) dataType = tr(
"Intensity" );
340 if (
rawDtype ==
"IP" ) dataType = tr(
"Interference" );
341 if (
rawDtype ==
"FI" ) dataType = tr(
"Fluourescence" );
343 tr(
"Velocity Data for " ) +
runID );
345 dataType + tr(
" at " ) +
rawWaveln + tr(
" nm" ) );
347 tr(
"Radius (cm)" ) );
356 double* rr = vecr.data();
357 double* vv = vecv.data();
373 title = tr(
"Curve " ) + QString::number( ii );
376 curve->setPen( pen_plot );
378 curve->setData( rr, vv, valueCount );
394 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
409 QApplication::restoreOverrideCursor();
412 int nfiles = files.count();
414 QString umsg = tr(
"In directory \"" ) + legadir +
"\",\n"
415 + tr(
" in subdirectory \"" ) +
runID +
"\",\n"
416 + tr(
" %1 files were written:\n" ).arg( nfiles );
417 umsg += files[ 0 ] +
"\n...\n" + files[ nfiles - 1 ] +
"\n";
419 QMessageBox::information(
this, tr(
"Successfully Written" ), umsg );
425 umsg = tr(
"From %1 input %2 triples, legacy output\n" )
428 umsg = tr(
"From 1 input %1 triple, legacy output\n" ).arg(
rawDtype );
430 umsg += tr(
"was written to %1 files." ).arg( nfiles );
442 QString odirname = legadir +
"/" +
runID +
"/";
450 QString htype = QString(
"U" );
451 htype = (
rawDtype ==
"RA" ) ?
"R" : htype;
452 htype = (
rawDtype ==
"RI" ) ?
"I" : htype;
453 htype = (
rawDtype ==
"IP" ) ?
"P" : htype;
454 htype = (
rawDtype ==
"FI" ) ?
"F" : htype;
455 htype = (
rawDtype ==
"WA" ) ?
"W" : htype;
456 htype = (
rawDtype ==
"WI" ) ?
"V" : htype;
459 bool wldata = ( QString(
rawDtype ).left( 1 ) ==
"W" );
462 int hrpm = qRound( dscan->
rpm );
463 int hsecs = qRound( dscan->
seconds );
471 QString fext =
"." +
rawDtype + QString::number( hcell );
472 bool channdir =
false;
476 for (
int drow = 0; drow < ntriples; drow++ )
478 QString chann =
triples[ drow ].section(
"/", 1, 1 ).simplified();
479 DbgLv(1) <<
" drow chann" << drow << chann;
488 for (
int drow = 0; drow < ntriples; drow++ )
493 fext =
"." +
rawDtype + QString::number( hcell );
494 QString chann =
triples[ drow ].section(
"/", 1, 1 ).simplified();
498 QString odirchan = runID +
"_channel" + chann;
499 odirname = legadir +
"/" + odirchan +
"/";
500 mkdir( legadir, odirchan );
503 for (
int ii = 0; ii < nscan; ii++ )
505 ofname = chann + QString().sprintf(
"%05i", ( ii + 1 ) ) + fext;
506 ofpath = odirname + ofname;
510 hsecs = qRound( dscan->
seconds );
516 + QString().sprintf(
"%2i%5.1f%6i %07i%11.4E",
517 hcell, htemp, hrpm, hsecs, homeg ).replace(
"E+",
"E" );
519 oline = oline + ( wldata
520 ? QString().sprintf(
"%6.3f %i\n", hradi, hcoun )
521 : QString().sprintf(
"%4i %i\n", hwavl, hcoun ) );
522 DbgLv(1) <<
"OFNAME" << ofname;
524 QFile legfile( ofpath );
526 if ( ! legfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
528 qDebug() <<
"*ERROR* Opening file" << ofpath;
532 QTextStream ts( &legfile );
535 DbgLv(1) <<
" LINE:" << QString(ddesc).replace(
"\n",
"");
536 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
538 for (
int jj = 0; jj < nvalu; jj++ )
544 QString oline = QString().sprintf(
"%9.4f %12.5E %13.5E\n",
546 .replace(
"E+",
"E+00" ).replace(
"E-",
"E-00" );
547 if (jj < 3 || jj > (nvalu-4))
548 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
566 QString odirname = legadir +
"/" +
runID +
"/";
574 QString htype = QString(
"U" );
575 htype = (
rawDtype ==
"RA" ) ?
"R" : htype;
576 htype = (
rawDtype ==
"RI" ) ?
"I" : htype;
577 htype = (
rawDtype ==
"IP" ) ?
"P" : htype;
578 htype = (
rawDtype ==
"FI" ) ?
"F" : htype;
579 htype = (
rawDtype ==
"WA" ) ?
"W" : htype;
580 htype = (
rawDtype ==
"WI" ) ?
"V" : htype;
582 bool wldata = ( QString(
rawDtype ).left( 1 ) ==
"W" );
585 int hrpm = qRound( dscan->
rpm );
586 int hsecs = qRound( dscan->
seconds );
593 QString fext =
"." +
rawDtype + QString::number( hcell );
600 for (
int drow = 0; drow < ntriples; drow++ )
605 fext =
"." +
rawDtype + QString::number( hcell );
607 twofer = tripa.contains(
"A" );
612 QString tripa =
triples[ drow ];
613 if ( erow < ntriples &&
614 triples[ erow ].contains(
"B" ) &&
615 QString(
triples[ erow ] ).replace(
"B",
"A" ) == tripa )
627 for (
int ii = 0; ii < nscan; ii++ )
629 ofname = QString().sprintf(
"%05i", ( ii + 1 ) ) + fext;
630 ofpath = odirname + ofname;
634 hsecs = qRound( dscan->
seconds );
640 + QString().sprintf(
"%2i%5.1f%6i %07i%11.4E",
641 hcell, htemp, hrpm, hsecs, homeg ).replace(
"E+",
"E" );
643 oline = oline + ( wldata
644 ? QString().sprintf(
"%6.3f %i\n", hradi, hcoun )
645 : QString().sprintf(
"%4i %i\n", hwavl, hcoun ) );
646 DbgLv(1) <<
"OFNAME" << ofname;
648 QFile legfile( ofpath );
650 if ( ! legfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
652 qDebug() <<
"*ERROR* Opening file" << ofpath;
656 QTextStream ts( &legfile );
659 DbgLv(1) <<
" LINE:" << QString(ddesc).replace(
"\n",
"");
660 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
662 for (
int jj = 0; jj < nvalu; jj++ )
666 double stdd = twofer ? rdat2->
value( ii, jj ) : 0.0;
667 stdd = bfirst ? valu : stdd;
668 valu = bfirst ? 0.0 : valu;
670 QString oline = QString().sprintf(
"%9.4f %12.5E %13.5E\n",
672 .replace(
"E+",
"E+00" ).replace(
"E-",
"E-00" );
673 if (jj < 3 || jj > (nvalu-4))
674 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
692 QString odirname = legadir +
"/" +
runID +
"/";
700 QString htype = QString(
"U" );
701 htype = (
rawDtype ==
"RA" ) ?
"R" : htype;
702 htype = (
rawDtype ==
"RI" ) ?
"I" : htype;
703 htype = (
rawDtype ==
"IP" ) ?
"P" : htype;
704 htype = (
rawDtype ==
"FI" ) ?
"F" : htype;
705 htype = (
rawDtype ==
"WA" ) ?
"W" : htype;
706 htype = (
rawDtype ==
"WI" ) ?
"V" : htype;
708 bool wldata = ( QString(
rawDtype ).left( 1 ) ==
"W" );
711 int hrpm = qRound( dscan->
rpm );
712 int hsecs = qRound( dscan->
seconds );
720 QString fext =
"." +
rawDtype + QString::number( hcell );
722 for (
int drow = 0; drow < ntriples; drow++ )
727 fext =
"." +
rawDtype + QString::number( hcell );
729 for (
int ii = 0; ii < nscan; ii++ )
731 ofname = QString().sprintf(
"%05i", ( ii + 1 ) ) + fext;
732 ofpath = odirname + ofname;
736 hsecs = qRound( dscan->
seconds );
742 + QString().sprintf(
"%2i%5.1f%6i %07i%11.4E",
743 hcell, htemp, hrpm, hsecs, homeg ).replace(
"E+",
"E" );
745 oline = oline + ( wldata
746 ? QString().sprintf(
"%6.3f %i\n", hradi, hcoun )
747 : QString().sprintf(
"%4i %i\n", hwavl, hcoun ) );
748 DbgLv(1) <<
"OFNAME" << ofname;
750 QFile legfile( ofpath );
752 if ( ! legfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
754 qDebug() <<
"*ERROR* Opening file" << ofpath;
758 QTextStream ts( &legfile );
761 DbgLv(1) <<
" LINE:" << QString(ddesc).replace(
"\n",
"");
762 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
764 for (
int jj = 0; jj < nvalu; jj++ )
769 QString oline = QString().sprintf(
"%9.4f %12.5E\n", radi, valu );
770 if (jj < 3 || jj > (nvalu-4))
771 DbgLv(1) <<
" LINE:" << QString(oline).replace(
"\n",
"");
786 QTextStream ts( &mtext );
793 editd->setWindowTitle( tr(
"Report: FE Match Model Simulation" ) );
794 editd->move( this->pos() + QPoint( 100, 100 ) );
795 editd->resize( 740, 700 );
798 editd->
e->setHtml( mtext );
807 ts <<
" </body>\n</html>\n";
813 return ( QString(
" " ).leftJustified( spaces,
' ' ) );
819 QString dataType = tr(
"Unknown" );
820 if (
rawDtype ==
"RA" ) dataType = tr(
"Radial Absorbance" );
821 if (
rawDtype ==
"RI" ) dataType = tr(
"Radial Intensity" );
822 if (
rawDtype ==
"WA" ) dataType = tr(
"Wavelength Absorbance" );
823 if (
rawDtype ==
"WI" ) dataType = tr(
"Wavelength Intensity" );
824 if (
rawDtype ==
"IP" ) dataType = tr(
"Interference" );
825 if (
rawDtype ==
"FI" ) dataType = tr(
"Fluourescence Intensity" );
826 dataType = dataType +
" (" +
rawDtype +
")";
830 "\n" +
indent( 4 ) + tr(
"<h3>Detailed Run Information:</h3>\n" )
831 +
indent( 4 ) +
"<table>\n"
834 +
table_row( tr(
"Export Directory:" ), expDir )
835 +
table_row( tr(
"Data Type:" ), dataType )
841 double maxTemp = -1.0e99;
842 double minTemp = 1.0e99;
848 maxTemp =
max( maxTemp, t );
849 minTemp =
min( minTemp, t );
852 QString average = QString::number( sum /
rdata->
scanCount(),
'f', 1 );
854 s +=
table_row( tr(
"Average Temperature:" ), average +
" " +
MLDEGC );
857 s +=
table_row( tr(
"Temperature Variation:" ), tr(
"Within tolerance" ) );
859 s +=
table_row( tr(
"Temperature Variation:" ),
860 tr(
"(!) OUTSIDE TOLERANCE (!)" ) );
864 int minutes = (int)tcorrec / 60;
865 int seconds = (int)tcorrec % 60;
867 QString m = ( minutes == 1 ) ? tr(
" minute " ) : tr(
" minutes " );
868 QString sec = ( seconds == 1 ) ? tr(
" second" ) : tr(
" seconds" );
869 s +=
table_row( tr(
"Time Correction:" ),
870 QString::number( minutes ) + m +
871 QString::number( seconds ) + sec );
873 double duration =
rawList.last().scanData.last().seconds;
875 int hours = (int) duration / 3600;
876 minutes = (int) duration / 60 - hours * 60;
877 seconds = (int) duration % 60;
880 h = ( hours == 1 ) ? tr(
" hour " ) : tr(
" hours " );
881 m = ( minutes == 1 ) ? tr(
" minute " ) : tr(
" minutes " );
882 sec = ( seconds == 1 ) ? tr(
" second " ) : tr(
" seconds " );
885 QString::number( hours ) + h +
886 QString::number( minutes ) + m +
887 QString::number( seconds ) + sec );
898 QDir().mkpath( baseDir );
900 QDir folder( baseDir );
903 if ( folder.exists( subdir ) )
return true;
906 if ( folder.mkdir( subdir ) )
return true;
909 QMessageBox::warning(
this,
911 tr(
"Could not create the directory:\n" ) + baseDir +
"/" + subdir );
949 le_id ->setText(
"" );
958 return(
indent( 6 ) +
"<tr><td>" + s1 +
"</td><td>" + s2 +
"</td></tr>\n" );
967 QString s = QString(
"<?xml version=\"1.0\"?>\n" );
968 s +=
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n";
969 s +=
" \"http://www.w3.org/TR/xhtml1/DTD"
970 "/xhtml1-strict.dtd\">\n";
971 s +=
"<html xmlns=\"http://www.w3.org/1999/xhtml\""
972 " xml:lang=\"en\" lang=\"en\">\n";
974 s +=
" <title> " + title +
" </title>\n";
975 s +=
" <meta http-equiv=\"Content-Type\" content="
976 "\"text/html; charset=iso-8859-1\"/>\n";
977 s +=
" <style type=\"text/css\" >\n";
978 s +=
" td { padding-right: 1em; }\n";
979 s +=
" body { background-color: white; }\n";
981 s +=
" </head>\n <body>\n";
982 s +=
" <h1>" + head1 +
"</h1>\n";
983 s +=
indent( 4 ) + tr(
"<h2>Data Report for Run \"" ) +
runID;
984 s +=
"\",<br/>\n" +
indent( 4 ) +
" " + tr(
" Cell " ) +
rawCell;
986 s += tr(
", Wavelength " ) +
rawWaveln +
"<br/></h2>\n";
993 QString& Dtype, QString& Cell, QString& Chann, QString& Waveln )
995 Dtype = QString( QChar( rdata->
type[ 0 ] ) )
996 + QString( QChar( rdata->
type[ 1 ] ) );
997 Cell = QString::number( rdata->
cell );
998 Chann = QString( QChar( rdata->
channel ) );
999 Waveln = QString::number( rdata->
scanData[ 0 ].wavelength );
1005 int size =
rawList[ 0 ].scanCount();
1007 for (
int ii = 1; ii <
rawList.size(); ii++ )
1012 QVector< double > vecx( size );
1013 QVector< double > vecy( size );
1014 double* x = vecx.data();
1015 double* y = vecy.data();
1019 for (
int ii = 0; ii <
rawList.size(); ii++ )
1023 for (
int jj = 0; jj < d->
scanCount(); jj++ )
1025 if ( d->
scanData[ jj ].omega2t > 9.99999e10 )
break;
1027 x[ count ] = d->
scanData[ jj ].omega2t;
1028 y[ count ] = d->
scanData[ jj ].seconds;
1050 query <<
"get_experiment_info_by_runID"
1057 ripxml = db.value( 16 ).toString();
1064 QFile fi( filename );
1066 if ( !fi.open( QIODevice::ReadOnly | QIODevice::Text ) )
1069 ripxml = fi.readAll();
1073 if ( ripxml.isEmpty() )
1078 return RIProfile.size();
1084 int ntriples =
rawList.size();
1085 int lrip = RIProfile.size() - 1;
1088 DbgLv(1) <<
"CnvPA: ntrip lrip" << ntriples << lrip;
1090 for (
int kk = 0; kk < ntriples; kk++ )
1097 for (
int ii = 0; ii <
scanCount; ii++ )
1100 double rip = RIProfile[ qMin( ii, lrip ) ];
1101 DbgLv(1) <<
"CnvPA: ii rip" << ii << rip;
1103 <<
"pow" << pow(10.0,rscan->
rvalues[0]);
1107 double aval = rscan->
rvalues[ jj ];
1108 rscan->
rvalues[ jj ] = rip / pow( 10.0, aval );
1117 QVector< double >& RIProfile )
1120 QXmlStreamReader xml( ripxml );
1121 QXmlStreamAttributes atts;
1123 while ( ! xml.atEnd() )
1127 if ( xml.isStartElement() && xml.name() ==
"RI" )
1129 atts = xml.attributes();
1130 RIProfile << atts.value(
"value" ).toString().toDouble();
1133 int nprof=RIProfile.size();
1134 DbgLv(1) <<
"ParsRIProf: nprof" << RIProfile.size();
1135 if(nprof>0)
DbgLv(1) <<
"ParsRIProf: RIP0" << RIProfile[0];
1136 if(nprof>1)
DbgLv(1) <<
"ParsRIProf: RIPn" << RIProfile[nprof-1];