12 #include <qwt_legend.h>
17 dsets( dsets ), loadDB( loadDB )
25 setObjectName(
"US_AnalysisControl2D" );
26 setAttribute( Qt::WA_DeleteOnClose,
true );
31 setWindowTitle( tr(
"2-D Spectrum Analysis Controls" ) );
43 QLabel* lb_fitting =
us_banner( tr(
"Fitting Controls:" ) );
44 QLabel* lb_lolimits =
us_label( tr(
"Lower Limit (s x 1e-13):" ) );
45 QLabel* lb_uplimits =
us_label( tr(
"Upper Limit (s):" ) );
46 QLabel* lb_nstepss =
us_label( tr(
"Number Grid Points (s):" ) );
51 QLabel* lb_thrdcnt =
us_label( tr(
"Thread Count:" ) );
52 QLabel* lb_estmemory =
us_label( tr(
"Estimated Memory:" ) );
53 QLabel* lb_iteration =
us_label( tr(
"Completed Iteration:" ) );
54 QLabel* lb_oldvari =
us_label( tr(
"Old Variance:" ) );
55 QLabel* lb_newvari =
us_label( tr(
"New Variance:" ) );
56 QLabel* lb_improve =
us_label( tr(
"Improvement:" ) );
57 QLabel* lb_status =
us_label( tr(
"Status:" ) );
59 QLabel* lb_optimiz =
us_banner( tr(
"Optimization Methods:" ) );
60 QLabel* lb_gridreps =
us_label( tr(
"Grid Repetitions:" ) );
61 QLabel* lb_menisrng =
us_label( tr(
"Meniscus Fit Range (cm):" ) );
62 QLabel* lb_menispts =
us_label( tr(
"Meniscus Grid Points:" ) );
63 QLabel* lb_mciters =
us_label( tr(
"Monte Carlo Iterations:" ) );
64 QLabel* lb_iters =
us_label( tr(
"Maximum Iterations:" ) );
65 QLabel* lb_statinfo =
us_banner( tr(
"Status Information:" ) );
74 QPushButton* pb_advance =
us_pushbutton( tr(
"Advanced Analysis Controls" ));
88 nthr = ( nthr > 1 ) ? nthr : QThread::idealThreadCount();
89 DbgLv(1) <<
"idealThrCout" << nthr;
113 tr(
"8 ( -> 64 64-point subgrids )" ), -1,
true );
219 connect(
ck_unifgr, SIGNAL( toggled(
bool ) ),
221 connect(
ck_custgr, SIGNAL( toggled(
bool ) ),
223 connect(
ck_menisc, SIGNAL( toggled(
bool ) ),
225 connect(
ck_mcarlo, SIGNAL( toggled(
bool ) ),
227 connect(
ck_iters, SIGNAL( toggled(
bool ) ),
229 connect(
ck_varvbar, SIGNAL( toggled(
bool ) ),
232 connect(
ct_nstepss, SIGNAL( valueChanged(
double ) ),
234 connect(
ct_nstepsk, SIGNAL( valueChanged(
double ) ),
236 connect(
ct_thrdcnt, SIGNAL( valueChanged(
double ) ),
238 connect(
ct_lolimits, SIGNAL( valueChanged(
double ) ),
240 connect(
ct_uplimits, SIGNAL( valueChanged(
double ) ),
242 connect(
ct_lolimitk, SIGNAL( valueChanged(
double ) ),
244 connect(
ct_nstepsk, SIGNAL( valueChanged(
double ) ),
248 this, SLOT(
start() ) );
253 connect(
pb_plot, SIGNAL( clicked() ),
254 this, SLOT(
plot() ) );
255 connect(
pb_save, SIGNAL( clicked() ),
256 this, SLOT(
save() ) );
257 connect( pb_help, SIGNAL( clicked() ),
258 this, SLOT(
help() ) );
259 connect( pb_close, SIGNAL( clicked() ),
261 connect( pb_advance, SIGNAL( clicked() ),
264 edata = &dsets[ 0 ]->run_data;
296 if ( ckflag > 3 )
ck_unifgr->setChecked(
false );
297 if ( ckflag == 3 )
ck_menisc->setChecked(
false );
298 if ( ckflag == 2 )
ck_mcarlo->setChecked(
false );
321 nthr = ( nthr > 1 ) ? nthr : QThread::idealThreadCount();
331 connect(
ck_custgr, SIGNAL( toggled(
bool ) ),
404 ct_iters->setValue( ( checked ? 3 : 1 ) );
415 double vblo =
dsets[ 0 ]->vbar20 - 0.02;
416 double vbhi =
dsets[ 0 ]->vbar20 + 0.02;
417 vblo = (double)( (
int)( vblo * 1000.0 ) ) * 0.001;
418 vbhi = (double)( (
int)( vbhi * 1000.0 ) + 1 ) * 0.001;
419 lb_lolimitk->setText( tr(
"Lower Limit (vbar):" ) );
420 lb_uplimitk->setText( tr(
"Upper Limit (vbar):" ) );
421 lb_nstepsk ->setText( tr(
"Number Grid Points (vbar):" ) );
435 lb_lolimitk->setText( tr(
"Lower Limit (f/f0):" ) );
436 lb_uplimitk->setText( tr(
"Upper Limit (f/f0):" ) );
437 lb_nstepsk ->setText( tr(
"Number Grid Points (f/f0):" ) );
481 tr(
"The \"s\" or \"f/f0\" ranges are inconsistent.\n"
482 "Please re-check the limits and correct them\n"
483 "before again clicking \"Start Fit\"." );
486 msg = msg.replace(
"f/f0",
"vbar" );
488 QMessageBox::critical(
this, tr(
"Limits Inconsistent!" ), msg );
497 double hmenis = bmenis + menrng * 0.5;
500 if ( hmenis >= lrdata )
502 QMessageBox::critical(
this, tr(
"Meniscus-Data Overlap!" ),
503 tr(
"The highest meniscus (%1), implied in the range given,\n"
504 "equals or exceeds the low data range radius (%2).\n\n"
505 "You must either quit this program and re-edit the data\n"
506 "to have a low radius value farther from the meniscus;\n"
507 "or change the fit-meniscus range given here." )
508 .arg( hmenis ).arg( lrdata ) );
519 QMessageBox::critical(
this,
520 tr(
"Implied Grid Size is Too Large!" ),
551 int noif = (
ck_tinoise->isChecked() ? 1 : 0 ) +
565 connect(
processor, SIGNAL( progress_update(
int ) ),
567 connect(
processor, SIGNAL( message_update( QString,
bool ) ),
569 connect(
processor, SIGNAL( stage_complete(
int,
int ) ),
571 connect(
processor, SIGNAL( process_complete(
int ) ),
574 int mxiter = (int)
ct_iters->value();
579 double vtoler = 1.0e-12;
603 DbgLv(1) <<
"AC:SF:StopFit";
606 DbgLv(1) <<
"AC:SF: processor stopping...";
609 DbgLv(1) <<
"AC:SF: processor stopped";
611 DbgLv(1) <<
"AC:SF: processor deleted";
618 qApp->processEvents();
625 qApp->processEvents();
633 qApp->processEvents();
640 QString mfilter(
"" );
647 mfilter = QString(
"CustomGrid" );
653 if ( dialog.exec() == QDialog::Accepted )
657 int sgsize = nsol / nsubg;
663 nsubg = ( nsol / 100 + 1 ) | 1;
664 sgsize = nsol / nsubg;
665 DbgLv(0) <<
"Subgrid count adjusted from" << ksubg <<
"to" << nsubg;
666 DbgLv(0) <<
"Subgrid size adjusted from" << kssiz <<
"to" << sgsize;
671 tr(
"Grid from loaded model\n ( " )
672 + QString::number( nsol ) + tr(
" solutes, " )
673 + QString::number( nsubg ) + tr(
" subgrids )" );
682 dsets[ 0 ]->model = cusmodel;
720 int ntconc = nconc * nscan;
721 double megas =
sq( 1024.0 );
725 int ngstep = nsteps * nstepk;
739 const double x_fact = 17.20;
740 const double y_fact = 2.28;
741 const int nxdata = 4;
742 int nsstep = ( nsteps / ngrrep ) * ( nstepk / ngrrep );
743 int noif = (
ck_tinoise->isChecked() ? 1 : 0 ) +
745 int ndatas = nsstep + nxdata + noif;
746 double mdata = ( (double)ntconc * ndatas *
sizeof(
double ) ) / megas;
747 double tdata = x_fact + mdata * y_fact;
749 DbgLv(1) <<
"GC: baserss tdata mdata ndatas nthrd" <<
baserss
750 << qRound(tdata) << qRound(mdata) << ndatas << nthrd <<
"memneed" <<
memneed;
755 le_estmemory->setText( tr(
"%1 MB (of %2 MB total real)" )
756 .arg( memneed ).arg( memtot ) );
758 DbgLv(1) <<
"GC: ngrrep nsteps nstepk" << ngrrep << nsteps << nstepk;
763 int nss = nsteps / ngrrep;
764 int nsk = nstepk / ngrrep;
765 int nspts = nss * nsk;
766 int nsubg =
sq( ngrrep );
767 QString gmsg = tr(
"Total grid is approximately %1 points (%2 x %3).\n" )
768 .arg( ngstep ).arg( nsteps ).arg( nstepk );
769 gmsg += tr(
"Subgrid repetitions is %1 subgrids (%2 ^ 2)\n"
770 " with a maximum of %3 points each (%4 x %5)." )
771 .arg( nsubg ).arg( ngrrep ).arg( nspts ).arg( nss ).arg( nsk );
773 le_gridreps->setText( tr(
"%1 ( -> %2 %3-point subgrids )" )
774 .arg( ngrrep ).arg( nsubg ).arg( nspts ) );
782 double limlo = -1.e6;
787 if ( loval < -1.e5 || upval > 1.e5 )
789 if ( loval < -1.e6 || upval > 1.e6 )
791 if ( loval < -1.e7 || upval > 1.e7 )
839 nthr = ( nthr > 1 ) ? nthr : QThread::idealThreadCount();
868 amsg =
te_status->toPlainText() +
"\n" + pmsg;
879 qApp->processEvents();
885 DbgLv(1) <<
"AC:cs: prmx nct kcs" <<
b_progress->maximum() << nct << kcs;
892 qApp->processEvents();
898 bool alldone = ( stage == 9 );
899 DbgLv(1) <<
"AC:cp: stage alldone" << stage << alldone;
902 qApp->processEvents();
927 for (
int jj=0; jj<knoi; jj++ )
929 DbgLv(1) <<
"AC:cp DTOT" << dtot <<
"edata" <<
edata <<
"NTOT" << ntot
930 <<
"nnoi knoi" << nnoi << knoi <<
"STOT" << stot;
936 int iternum = (int)rscan0->
rpm;
937 int mmitnum = (
int)rscan0->
seconds;
938 double varinew = rscan0->
delta_r;
939 double meniscus = rscan0->
plateau;
940 double variold =
le_newvari ->text().toDouble();
941 double vimprov = variold - varinew;
942 le_oldvari ->setText( QString::number( variold ) );
943 le_newvari ->setText( QString::number( varinew ) );
944 le_improve ->setText( QString::number( vimprov ) );
950 .arg( mmitnum ).arg( varinew );
957 .arg( mmitnum ).arg( varinew ).arg( meniscus );
958 le_iteration->setText( QString::number( iternum ) +
" ( Model " +
959 QString::number( mmitnum ) +
" , Meniscus " +
960 QString::number( meniscus ) +
" )" );
967 .arg( mmitnum ).arg( varinew );
968 le_iteration->setText( QString::number( iternum ) +
" ( MC Model " +
969 QString::number( mmitnum ) +
" )" );
989 else if ( mmitnum > 0 && stage > 0 )
1002 if ( aadiag->exec() == QDialog::Accepted )
1005 double grpar1 = 0.0;
1006 double grpar2 = 0.0;
1007 double grpar3 = 0.0;
1009 double repar1 = 0.0;
1013 modpar, reg, repar1 );
1014 DbgLv(1) <<
"Adv ACCEPT";
1015 DbgLv(1) <<
"Adv grtype par123" <<
grtype << grpar1 << grpar2 << grpar3;
1017 DbgLv(1) <<
"Adv reg par1 " << reg << repar1;
1023 int sgsize = nsol / nsubg;
1029 nsubg = ( nsol / 100 + 1 ) | 1;
1030 sgsize = nsol / nsubg;
1031 DbgLv(0) <<
"Subgrid count adjusted from" << ksubg <<
"to" << nsubg;
1032 DbgLv(0) <<
"Subgrid size adjusted from" << kssiz <<
"to" << sgsize;
1036 QString amsg = (
grtype == (-1 )
1037 ? tr(
"Grid from loaded model\n ( " )
1038 : tr(
"Grid and signal ratios from loaded model\n\n ( " ) )
1039 + QString::number( nsol ) + tr(
" solutes, " )
1040 + QString::number( nsubg ) + tr(
" subgrids )" );
1046 dsets[ 0 ]->model = modpar;
1069 DbgLv(1) <<
"Adv REJECT";
1071 qApp->processEvents();
1079 const int pc_ava = 90;
1081 int memava, memtot, memuse;
1083 int memsafe = ( memava * pc_ava ) / 100;
1085 if (
memneed > memsafe || mempca < 20 )
1087 QString title = tr(
"High Memory Usage" );
1088 QString memp = tr(
"\n\nMemory Profile --\n"
1090 " Available: %2 MB\n"
1092 " Estimated Need: %4 MB\n\n" )
1093 .arg( memtot ).arg( memava ).arg( memuse ).arg(
memneed );
1097 QMessageBox::critical(
this, title,
1098 tr(
"Memory needed for this fit exceeds total available." )
1099 + memp + tr(
"This fit will not proceed.\n"
1100 "Re-parameterize the fit with adjusted\n"
1101 "Grid Refinements and/or Thread Count." ) );
1107 QMessageBox msgBox(
this );
1108 msgBox.setWindowTitle( title );
1109 msgBox.setText( tr(
"Memory needed for this fit is a\n"
1110 "high percentage of the available memory." )
1112 tr(
"You may proceed if you wish (\"Yes\")\n"
1113 "Or you may stop this fit (\"No\")\n"
1114 "then re-parameterize the fit with adjusted\n"
1115 "Grid Refinements and/or Thread Count.\n\nProceed?" ) );
1116 msgBox.addButton( QMessageBox::No );
1117 msgBox.addButton( QMessageBox::Yes );
1118 msgBox.setDefaultButton( QMessageBox::No );
1120 if ( msgBox.exec() == QMessageBox::No )