30 QDir ddir(
cur_dir,
"*", QDir::Name, QDir::Files | QDir::Readable );
41 QMessageBox::critical( 0,
42 tr(
"No mwrs XML File Found" ),
43 tr(
"No proper mwrs XML file was found in directory \"%1\".\n"
44 "No import of MWRS data is possible without"
45 " such a file." ).arg(
cur_dir ) );
50 QString old_runID =
runID;
52 runID.replace( QRegExp(
"![A-Za-z0-9_-]" ),
"_" );
54 if (
runID != old_runID )
56 QMessageBox::warning( 0,
57 tr(
"RunID Name Changed" ),
58 tr(
"The runID name has been changed. It may consist only\n"
59 "of alphanumeric characters, underscore, or hyphen.\n"
60 " New runID: " ) +
runID );
64 QStringList mwrfs = ddir.entryList( QStringList(
"*.mwrs" ),
65 QDir::Files, QDir::Name );
67 QVector< int > ccscans;
74 ccscans.fill( 0,
nfile );
75 le_status->setText( QString(
"%1 files from %2 ..." )
77 qApp->processEvents();
80 for (
int ii = 0; ii <
nfile; ii++ )
82 QString fname = mwrfs.at( ii );
83 QString fpath =
cur_dir + fname;
84 QString acell = fname.section(
".", -5, -5 );
85 QString chann = fname.section(
".", -4, -4 );
86 QString adesc = fname.section(
".", -3, -3 );
87 QString ascan = fname.section(
".", -2, -2 );
89 if ( !
cells.contains( acell ) )
cells << acell;
90 if ( !chans.contains( chann ) ) chans << chann;
92 int scann = ascan.toInt();
94 scnmin = qMin( scnmin, scann );
99 QString celchn = acell +
"." + chann;
108 ccscans[ ccx ] = qMax( ccscans[ ccx ], scann );
113 nchan = chans.size();
118 qDebug() <<
"kcelchn ncelchn" << kcelchn <<
ncelchn;
125 qDebug() <<
"*** nfile" << nfile <<
"ncelchn*nscn" <<
ncelchn*
nscan;
126 int scn_lo = ccscans[ 0 ];
129 for (
int ii = 1; ii <
cellchans.size(); ii++ )
131 scn_lo = qMin( scn_lo, ccscans[ ii ] );
132 scn_hi = qMax( scn_hi, ccscans[ ii ] );
135 scn_lo = ( scn_lo - scnmin ) + 1;
136 scn_hi = ( scn_hi - scnmin ) + 1;
138 if ( scn_lo != scn_hi )
140 QApplication::restoreOverrideCursor();
141 QApplication::restoreOverrideCursor();
143 int response = QMessageBox::warning( 0,
144 tr(
"Varying Number of Scans" ),
145 tr(
"The number of scans in each cell varies"
146 " from %1 to %2.<br/><br/>Select <b>[ Cancel ]</b>"
147 " to abort the import<br/>or <b>[ OK ]</b> to"
148 " process only the first %3 scans of each cell." )
149 .arg( scn_lo ).arg( scn_hi ).arg( scn_lo ),
150 QMessageBox::Cancel|QMessageBox::Ok, QMessageBox::Ok );
152 if ( response == QMessageBox::Cancel )
155 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
161 le_status->setText( QString(
"%1 cells and %2 channels ..." )
162 .arg(
ncell ).arg( nchan ) );
163 qApp->processEvents();
165 for (
int ii = 0; ii <
ncell; ii++ )
167 for (
int jj = 0; jj <
nchan; jj++ )
169 QString celchn =
cells[ ii ] +
" / " + chans[ jj ];
175 for (
int ii = 0; ii <
nfile; ii++ )
177 QString fname =
fnames[ ii ];
178 QString fpath =
fpaths[ ii ];
179 QString acell = fname.section(
".", -5, -5 );
180 QString chann = fname.section(
".", -4, -4 );
181 QString ascan = fname.section(
".", -2, -2 );
182 int scann = ascan.toInt() - scnmin + 1;
183 QString celchn = acell +
" / " + chann;
185 if ( scann > nscan )
continue;
188 if ( ! fi.open( QIODevice::ReadOnly ) )
190 qDebug() <<
"*ERROR* Unable to open" << fname;
196 QDataStream ds( &fi );
217 for (
int jj = 1; jj <
nlamb_i; jj++ )
223 DbgLv(1) <<
"MwDa: jj" << jj <<
"ndup lmb" << nlmb_dup <<
ri_wavelns[jj];
230 DbgLv(1) <<
"MwDa: read_lambdas COMPLETE";
233 nlambda = nlamb_i - nlmb_dup;
240 le_status->setText( tr(
"%1 wavelengths ..." )
245 le_status->setText( tr(
"%1 wavelengths ..."
246 " (%2 duplicate(s) removed)" )
247 .arg( nlambda ).arg( nlmb_dup ) );
249 qApp->processEvents();
252 QVector< double > wave_reads(
npointt, 0.0 );
256 for (
int tx = 0; tx <
ntriple; tx++ )
268 DbgLv(1) <<
"MwDa: cell chann celchn ccx" << acell << chann << celchn << ccx;
271 ccscans[ ccx ] = ccscans[ ccx ] + 1;
273 int scnx = ( fname.section(
".", -2, -2 ).toInt() - scnmin ) *
npoint;
274 DbgLv(1) <<
"MwDa: PREPARE rdata ccx tripx scnx" << ccx << tripx << scnx;
275 DbgLv(1) <<
"MwDa: PREPARE icell ichan nchan" << hd.icell << hd.ichan
276 << nchan <<
"channel" << hd.channel;
279 for (
int wavx = 0; wavx <
nlamb_i; wavx++ )
284 ds.skipRawData(
npoint * 4 );
287 le_status->setText( QString(
"Data in for triple %1, scan %2 ..." )
288 .arg( tripx + 1 ).arg( scnx + 1 ) );
289 qApp->processEvents();
301 le_status->setText( tr(
"Initial MWL import from %1 files is complete." )
306 le_status->setText( tr(
"Initial MWL import from %1 files is complete."
307 " (%2 duplicate(s) encountered!)" )
308 .arg( nfile ).arg( nlmb_dup ) );
311 for (
int ii = 0; ii <
nlamb_i; ii++ )
313 if ( ri_wavelns[ ii ] > 0 )
314 ri_wavelns[ kk++ ] = ri_wavelns[ ii ];
322 qApp->processEvents();
327 for (
int cc = 0; cc <
ncelchn; cc++ )
332 DbgLv(1) <<
"MwDa: status" << status <<
" stat_text" <<
le_status->text();
340 nfile = allData.size();
344 nscan = allData[ 0 ].scanCount();
345 npoint = allData[ 0 ].pointCount();
347 DbgLv(1) <<
"MwDa:LdMw: nfile" <<
nfile <<
"nscan npoint" << nscan <<
npoint;
361 for (
int trx = 0; trx <
nfile; trx++ )
365 int icell = edata->
cell;
366 QString cell = QString::number( icell );
367 QString chan = QString( edata->
channel );
368 QString celchn = cell +
" / " + chan;
369 int iwvl = qRound( edata->
scanData[ 0 ].wavelength );
373 if ( iwvl < 300 && iwvl_p > 655 && celchn == cech_p )
376 DbgLv(1) <<
"MwDa:L trx" << trx <<
"kwvl iwvl_p iwvl cech cech_p"
377 << kwvl << iwvl_p << iwvl << celchn << cech_p;
378 double wvlen = (double)iwvl;
380 for (
int jj = 0; jj < edata->
scanCount(); jj++ )
382 edata->
scanData[ jj ].wavelength = wvlen;
389 QString wavl = QString::number( iwvl );
390 QString triple = celchn +
" / " + wavl;
392 if ( !
cells.contains( cell ) )
395 if ( ! chans.contains( chan ) )
404 if ( !
triples.contains( triple ) )
411 else if ( chans.size() < 2 )
415 DbgLv(1) <<
"MwDa:L trx" << trx <<
"duplicate iwvl" << iwvl << triple
416 <<
"dup wx" << wx <<
"trip[wx]" << tripd;
419 for (
int ss = 0; ss <
nscan; ss++ )
426 nchan = chans.size();
435 DbgLv(1) <<
"MwDa:LdMw: wl k.."
442 if ( ( nlambda *
ncelchn ) == ntriple )
444 DbgLv(1) <<
"MwDa:LdMw: All Cells Same #Wavelengths";
445 DbgLv(1) <<
"MwDa:LdMw: ri_wavelns size" << ri_wavelns.size();
446 for (
int ccx = 0; ccx <
ncelchn; ccx++ )
455 DbgLv(1) <<
"MwDa:LdMw: All Cells NOT Same #Wavelengths";
457 for (
int ccx = 0; ccx <
ncelchn; ccx++ )
462 for (
int trx = 0; trx <
ntriple; trx++ )
464 QString triple =
triples[ trx ];
465 QString celchn = triple.section(
" / ", 0, 1 );
466 int iwvl = triple.section(
" / ", 2, 2 ).toInt();
472 qDebug() <<
"load_mwl:*ERROR* unexpected missing cell" << celchn;
487 rvs.reserve( npoint );
489 for (
int ii = 0; ii <
npoint; ii++ )
506 for (
int ii = 0; ii <
nlambda; ii++ )
520 for (
int ii = 0; ii <
nlamb_i; ii++ )
564 unsigned char* cbuf = (
unsigned char*)cc;
565 int j0 = (int)cbuf[ 0 ] & 255;
566 int j1 = (int)cbuf[ 1 ] & 255;
567 return ( ( j0 << 8 ) | j1 );
573 int j0 =
hword( cbuf );
574 int j1 =
hword( cbuf + 2 );
575 return ( ( j0 << 16 ) | j1 );
581 int ival =
iword( cbuf );
583 float* fptr = (
float*)iptr;
590 qDebug() <<
"fval" << *fptr <<
" kk" << kk;
599 float fval =
fword( cbuf );
607 char* cbuf = (
char*)chary;
609 int nhbyte = (
evers == 1.0 ) ? 24 : 26;
610 ds.readRawData( cbuf, nhbyte );
612 hd.
cell = QChar(
'0' | cbuf[ 0 ] );
613 hd.
channel = QChar( cbuf[ 1 ] );
650 wvs.reserve( klambda );
652 for (
int ii = 0; ii < klambda; ii++ )
654 ds.readRawData( cbuf, 2 );
655 int wvv =
hword( cbuf );
662 int& scnx,
int& npoint )
667 double rscl = (
evers > 1.2 ) ? 1.0 : 0.001;
671 for (
int ii = 0; ii <
npoint; ii++ )
673 ds.readRawData( cbuf, 4 );
674 int ival =
iword( cbuf );
675 double rvv = (double)ival * rscl;
687 DbgLv(1) <<
"MwDa:SetLamb s/e" << start << end;
700 while ( wvx <= wvxe )
704 DbgLv(1) <<
"SetLamb (2)n" <<
nlambda << wvxs << wvxe << wvx;
711 int old_start = wkwaves[ 0 ];
712 int old_end = wkwaves[
nlambda - 1 ];
713 slambda = ( start > 0 ) ? start : old_start;
714 elambda = ( end > 0 ) ? end : old_end;
719 int wvxs = wkwaves.indexOf(
slambda );
720 int wvxe = wkwaves.indexOf(
elambda );
721 wvxe = ( wvxe < 0 ) ? (
nlambda - 1 ) : wvxe;
723 DbgLv(1) <<
"SetLamb wvxs wvxe" << wvxs << wvxe;
738 while ( wvx <= wvxe )
743 DbgLv(1) <<
"SetLamb elambda old_end" <<
elambda << old_end;
749 DbgLv(1) <<
"SetLamb wvx s,e" << wvxs << wvxe <<
"old_end" << old_end;
759 DbgLv(1) <<
"SetLamb (4)n" <<
nlambda << wvxs << wvxe << wvx;
791 for (
int ii = 0; ii <
nlamb_i; ii++ )
793 int difval = qAbs( lambda -
ri_wavelns[ ii ] );
795 if ( difval < diflow )
816 const double signif_dif=100.0;
817 const int low_memApc=20;
822 QVector< double > xout;
823 double rad_val =
headers[ 0 ].radius_start;
824 double rad_inc =
headers[ 0 ].radius_step;
829 DbgLv(1) <<
"BldRawD radv radi" << rad_val << rad_inc <<
"npoint" <<
npoint
830 <<
" evers" <<
evers;
832 for (
int ii = 0; ii <
npoint; ii++ )
837 DbgLv(1) <<
"BldRawD xout size ntrip" << xout.size() << npoint <<
ntrip_i;
840 int nbytei = ( npoint + 7 ) / 8;
841 QByteArray interpo( nbytei,
'\0' );
853 for (
int trx = 0; trx <
ntrip_i; trx++ )
855 DbgLv(1) <<
"BldRawD trx" << trx <<
" building scans... ccx" << ccx;
860 rdata.
type[ 0 ] = dtype0;
861 rdata.
type[ 1 ] = dtype1;
862 rdata.
cell = QString(
headers[ hdx ].cell ).toInt();
871 double rpm_min = 1e+9;
872 double rpm_max = 1e-9;
873 double rpm_sum = 0.0;
874 double rpm_setp = 0.0;
875 double rpm_set =
headers[ jhx ].set_speed;
876 double rpm_avg = 0.0;
877 double rpm_stdd = 0.0;
879 DbgLv(1) <<
"BldRawD hdx" << hdx <<
"hdsize" <<
headers.size();
881 for (
int scx = 0; scx <
nscan; scx++ )
884 if(scx<3 || (scx+4)>nscan)
885 DbgLv(1) <<
"BldRawD scx" << scx <<
"jhx" << jhx <<
"wvx" << wvx;
888 rpm_set =
headers[ jhx ].set_speed;
894 scan.
rvalues.reserve( npoint );
897 if ( scx > 0 && scan.
rpm !=
r_rpms[ scx - 1 ] )
900 if(scx<3 || (scx+4)>nscan)
901 DbgLv(1) <<
"BldRawD rpm_set rpm_setp" << rpm_set << rpm_setp;
902 if ( rpm_set != rpm_setp )
905 rpm_avg = rpm_sum / (double)kscan;
908 for (
int jsx = kscx; jsx < scx; jsx++ )
911 rdata.
scanData[ jsx ].rpm = (double)qRound( rpm_avg );
914 rpm_stdd +=
sq(
r_rpms[ jsx ] - rpm_avg );
918 rpm_stdd = sqrt( rpm_stdd ) / (double)kscan;
937 rpm_min = qMin( rpm_min, scan.
rpm );
938 rpm_max = qMax( rpm_max, scan.
rpm );
942 DbgLv(1) <<
"BldRawD scx" << scx <<
"jhx" << jhx
943 <<
"seconds" << scan.
seconds <<
"rpm" << scan.
rpm <<
"ss" << rpm_set
944 <<
"speed step" << kspstep << nspstep+1;
950 if(scx<3 || (scx+4)>nscan)
951 DbgLv(1) <<
"BldRawD trx jhx rdx" << trx << jhx << rdx;
952 if(scx<3 || (scx+4)>nscan)
955 for (
int kk = 0; kk <
npoint; kk++ )
962 DbgLv(1) <<
"BldRawD EoSl: trx rdx" << trx << rdx;
970 for (
int scx = 0; scx <
nscan; scx++ )
972 double srpm = rdata.
scanData[ scx ].rpm;
973 rpm_min = qMin( rpm_min, srpm );
974 rpm_max = qMax( rpm_max, srpm );
981 rpm_set = (double)qRound( ( rpm_min + rpm_max ) * 0.5 );
987 rpm_avg = rpm_sum / (double)kscan;
988 DbgLv(1) <<
"BldRawD kscx" << kscx;
990 for (
int scx = kscx; scx <
nscan; scx++ )
993 rdata.
scanData[ scx ].rpm = (double)qRound( rpm_avg );
996 rpm_stdd +=
sq(
r_rpms[ scx ] - rpm_avg );
1000 rpm_stdd = sqrt( rpm_stdd ) / (double)kscan;
1001 DbgLv(1) <<
"BldRawD rpm_stdd" << rpm_stdd;
1011 if ( qAbs( rpm_avg - rpm_set ) > signif_dif )
1013 QMessageBox::warning( 0,
1014 tr(
"Set/Average Speed Difference" ),
1015 tr(
"The stored set_speed (%1) and the average of"
1016 " recorded rotor_speeds (%2) differ"
1017 " significantly!" ).arg( rpm_set ).arg( rpm_avg ) );
1023 DbgLv(1) <<
"BldRawD trx=" << trx <<
"rpm_min rpm_max rpm_avg rpm_set"
1024 << rpm_min << rpm_max << rpm_avg << rpm_set <<
"speed steps" << nspstep;
1028 DbgLv(1) <<
"BldRawD trx" << trx <<
" saving allData...";
1030 le_status->setText( tr(
"Of %1 raw AUCs, built %2" )
1031 .arg(
ntriple ).arg( trx + 1 ) );
1032 qApp->processEvents();
1035 if ( wvx >= nlambda )
1044 if ( memAv < low_memApc )
1046 for (
int rr = ( trx - nlambda + 1 ); rr < ( trx + 1 ); rr++ )
1049 DbgLv(1) <<
"BldRawD memfree %: 1memAV" << memAv <<
"2memAV" << memAv2;
1052 DbgLv(1) <<
"BldRawD ccx wvx hdx" << ccx << wvx << hdx <<
headers.size();
1055 le_status->setText( tr(
"All %1 raw AUCs have been build." )
1057 qApp->processEvents();
1075 return ( ccx < 0 ?
"" :
ccdescs.at( ccx ) );
1106 QStringList mwrfs = ddir.entryList( QStringList(
"*.mwrs.xml" ),
1107 QDir::Files, QDir::Name );
1108 int nxfile = mwrfs.count();
1112 qDebug() <<
"*ERROR* '*.mwrs.xml' count > 1" << nxfile << curdir;
1116 else if ( nxfile == 0 )
1118 qDebug() <<
"*ERROR* '*.mwrs.xml' does not exist in " << curdir;
1122 QString fname = mwrfs.at( 0 );
1123 QString fpath =
cur_dir + fname;
1126 if ( ! xfi.open( QIODevice::ReadOnly ) )
1128 qDebug() <<
"*ERROR* Unable to open" << fname;
1133 QXmlStreamReader xml( &xfi );
1139 while( ! xml.atEnd() )
1142 if ( xml.isStartElement() )
1144 QXmlStreamAttributes att = xml.attributes();
1145 if ( xml.name() ==
"runID" )
1147 runID = att.value(
"name" ).toString();
1148 is_absorb = att.value(
"take_intensity" ).toString() ==
"N";
1149 DbgLv(1) <<
"MwDa:RdXML take_i" << att.value(
"take_intensity" ).toString()
1152 else if ( xml.name() ==
"cell" )
1154 celi = att.value(
"id" ).toString();
1155 celi = QString::number( celi.toInt() );
1157 else if ( xml.name() ==
"channel" )
1159 chni = att.value(
"id" ).toString();
1160 cech = celi +
" / " + chni;
1161 QString desc = att.value(
"sample" ).toString();
1169 else if ( xml.name() ==
"settings_mwrs_experiment" )
1171 evers = att.value(
"version" ).toString().toDouble();
1199 for (
int ii = 0; ii <
curccx; ii++ )
1222 int nsteps =
s_rpms.size();
1223 DbgLv(1) <<
"MwDa:uSS: nsteps" << nsteps << speedsteps.size() <<
s_rpms.size();
1227 const int mxstep = 10;
1228 speedsteps.resize( nsteps );
1230 for (
int jj = 0; jj < nsteps; jj++ )
1232 speedsteps[ jj ].set_speed = (int)
s_rpms[ jj ];
1233 speedsteps[ jj ].avg_speed =
a_rpms[ jj ];
1234 speedsteps[ jj ].speed_stddev =
d_rpms[ jj ];
1235 speedsteps[ jj ].rotorspeed = qRound(
a_rpms[ jj ] );
1236 DbgLv(1) <<
"MwDa:uSS: jj" << jj <<
"set_speed avg_speed speed_stddev"
1239 speedsteps[ jj ].set_speed < speedsteps[ jj - 1 ].set_speed )
1245 if ( nsteps > mxstep )
1255 int nscans =
r_rpms.size();