3 #include <QApplication>
14 int main(
int argc,
char* argv[] )
16 QApplication application( argc, argv );
24 return application.exec();
29 setWindowTitle( tr(
"Second Moment Analysis" ) );
35 connect(
pb_help, SIGNAL( clicked() ), SLOT(
help() ) );
36 connect(
pb_view, SIGNAL( clicked() ), SLOT(
view() ) );
37 connect(
pb_save, SIGNAL( clicked() ), SLOT(
save() ) );
56 for (
int i = 0; i < scanCount; i++ )
60 double range = d->
scanData[ i ].plateau - baseline;
61 double test_y = baseline + range * positionPct;
63 if ( d->
scanData[ i ].rvalues[ 0 ] > test_y ) exclude++;
66 le_skipped->setText( QString::number( exclude ) );
73 +
" (" + d->
wavelength + tr(
" nm)\nSecond Moment Plot" ) );
75 data_plot1->setAxisTitle( QwtPlot::xBottom, tr(
"Scan Number" ) );
77 tr(
"Corrected Sed. Coeff. (1e-13 s)" ) );
86 for (
int i = 0; i < scanCount; i++ )
95 double range = ( d->
scanData[ i ].plateau - baseline ) * boundaryPct;
96 double test_y = range * positionPct;
98 while ( d->
scanData[ i ].rvalues[ count ] - baseline < test_y )
102 if ( count == 0 ) count = 1;
104 while ( count < points )
106 double value = d->
scanData[ i ].rvalues[ count ] - baseline;
107 double radius = d->
xvalues[ count ];
109 if ( value >= test_y + range )
break;
111 double v0 = d->
scanData[ i ].rvalues[ count - 1 ] - baseline;
112 double dC = value - v0;
114 sum1 += dC *
sq( radius );
119 smPoints [ i ] = sqrt( sum1 / sum2 );
121 double omega = d->
scanData[ i ].rpm * M_PI / 30.0;
129 QVector< double > x( scanCount );
130 QVector< double > y( scanCount );
142 for (
int i = 0; i <
exclude; i++ )
146 x[ count ] = (double)( count + 1 );
153 sym.setStyle( QwtSymbol::Ellipse );
154 sym.setPen ( QPen( Qt::white ) );
155 sym.setBrush( QBrush( Qt::red ) );
158 curve->setStyle ( QwtPlotCurve::NoCurve );
159 curve->setSymbol( sym );
160 curve->setData ( x.data(), y.data(), count );
164 double average = 0.0;
166 for (
int i = exclude; i < scanCount; i++ )
170 x[ count ] = (double)( count + 1 + exclude );
176 average_2nd = (count > 0 ) ? average / count : 0.0;
178 sym.setPen ( QPen ( Qt::blue ) );
179 sym.setBrush( QBrush( Qt::white ) );
182 curve->setSymbol( sym );
183 curve->setData( x.data(), y.data(), count );
194 curve->setPen( QPen( Qt::green ) );
195 curve->setData( x.data(), y.data(), 2 );
198 data_plot1->setAxisScale ( QwtPlot::xBottom, 0.0, x[ 1 ] + 0.25, 0.0 );
199 data_plot1->setAxisMaxMinor( QwtPlot::xBottom, 0 );
202 int from = (int)
ct_from->value();
203 int to = (int)
ct_to ->value();
209 for (
int i = 0; i < scanCount; i++ )
214 if ( index < from )
continue;
215 if ( index > to )
break;
223 tr(
"Scan %1 Exclude Marker" ).arg( index + 1 ) );
225 curve->setPen( QPen( QBrush( Qt::red ), 1.0 ) );
226 curve->setData( x.data(), y.data(), 2 );
245 table_row( tr(
"Average Second Moment S: " ),
246 QString::number(
average_2nd,
'f', 5 ) +
" s * 10e-13" );
249 QString(
"Second Moment Analysis" ),
252 ts <<
indent( 2 ) +
"</body>\n</html>\n";
259 QTextStream ts( &rtext );
285 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
287 QString filebase = dir +
"/" + d->
runID +
"/secmo."
288 + QString(
triples.at( index ) ).replace(
" / ",
"" ) +
".";
290 QString plot1File = filebase +
"2ndmoment.svgz";
291 QString plot2File = filebase +
"velocity.svgz";
292 QString textFile = filebase +
"2ndmoment.csv";
293 QString htmlFile = filebase +
"report.html";
294 QString dsinfFile = QString( filebase ).replace(
"/secmo.",
"/dsinfo." )
295 +
"dataset_info.html";
301 QFile reportf( htmlFile );
303 if ( ! reportf.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
305 QMessageBox::warning(
this,
307 tr(
"Could not open\n" ) + htmlFile +
"\n" +
308 tr(
"\nfor writing" ) );
309 QApplication::restoreOverrideCursor();
313 QTextStream ts( &reportf );
322 QFile sm_data( textFile );
323 if ( ! sm_data.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
325 QMessageBox::warning(
this,
327 tr(
"Could not open\n" ) + textFile +
"\n" +
328 tr(
"\nfor writing" ) );
329 QApplication::restoreOverrideCursor();
333 const QString sep(
"\",\"" );
334 const QString quo(
"\"" );
335 const QString eln(
"\"\n" );
336 QTextStream ts_data( &sm_data );
341 if ( excludes == scanCount )
342 ts_data <<
"No valid scans\n";
345 ts_data << quo <<
"Count" << sep <<
"Points" << sep <<
"Seconds" << eln;
347 for (
int i = excludes; i < scanCount; i++ )
351 QString strK = QString::number( count ).simplified();
352 QString strP = QString::number(
smPoints [ i ],
'f', 5 ).simplified();
353 QString strS = QString::number(
smSeconds[ i ],
'f', 5 ).simplified();
354 ts_data << quo << strK << sep << strP << sep << strS << eln;
360 QStringList repfiles;
368 htmlFile = htmlFile .mid( htmlFile .lastIndexOf(
"/" ) + 1 );
369 plot1File = plot1File.mid( plot1File.lastIndexOf(
"/" ) + 1 );
370 plot2File = plot2File.mid( plot2File.lastIndexOf(
"/" ) + 1 );
371 textFile = textFile .mid( textFile .lastIndexOf(
"/" ) + 1 );
372 dsinfFile = dsinfFile.mid( dsinfFile.lastIndexOf(
"/" ) + 1 );
374 QString wmsg = tr(
"Wrote:\n " ) + htmlFile +
"\n "
375 + plot1File +
"\n " + plot2File +
"\n " + textFile +
"\n "
382 wmsg += tr(
"\n\nReport files were also saved to the database." );
385 QApplication::restoreOverrideCursor();
386 QMessageBox::warning(
this, tr(
"Success" ), wmsg );