11 #define DbgLv(a) if(dbg_level>=a)qDebug()
72 QString channel = QChar(rawdata.
channel);
73 int iechan = QString(
"ABCDEFGH" ).indexOf( channel );
74 int ch = qMax( 0, iechan ) / 2;
75 iechan = qMax( 0, iechan ) + 1;
76 QString ecell = QString::number(rawdata.
cell);
77 int iecell = ecell.toInt();
78 DbgLv(1) <<
"SP:iFD: cell chan ch" << ecell << channel << ch
83 + runID +
"." + dataType +
".xml";
86 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
88 QXmlStreamReader xml( &file );
93 while ( ! xml.atEnd() )
97 if ( xml.isStartElement() && xml.name() ==
"calibration" )
99 QXmlStreamAttributes a = xml.attributes();
101 rotorcoeffs[ 0 ] = a.value(
"coeff1" ).toString().toDouble();
102 rotorcoeffs[ 1 ] = a.value(
"coeff2" ).toString().toDouble();
105 if ( xml.isStartElement() && xml.name() ==
"dataset" )
107 QXmlStreamAttributes a = xml.attributes();
108 dcell = a.value(
"cell" ).toString().toInt();
109 dchan = a.value(
"channel" ).toString();
112 if ( xml.isStartElement() && xml.name() ==
"centerpiece" )
114 QXmlStreamAttributes a = xml.attributes();
115 dcp_id = a.value(
"id" ).toString().toInt();
116 DbgLv(1) <<
"SP:iFD: dcell dchan" << dcell << dchan;
117 if ( dcell == iecell && dchan == channel )
120 DbgLv(1) <<
"SP:iFD: cp_id" << cp_id;
138 double rpm = rawdata.
scanData[ 0 ].rpm;
149 query <<
"get_experiment_info_by_runID"
161 expID = db->
value( 1 ).toString();
169 if (
rotorCalID.isEmpty() && ! expID.isEmpty() )
172 query <<
"get_experiment_info" << expID;
187 if ( ! expID.isEmpty() )
190 query <<
"all_cell_experiments" << expID;
194 int cell = db->
value( 2 ).toInt();
195 int ichan = db->
value( 3 ).toInt();
196 int cellCpId = db->
value( 4 ).toInt();
198 DbgLv(1) <<
"Sim parms: cell iecell ichan iechan" << cell << iecell
199 << ichan << iechan <<
"ccId" << cellCpId;
200 if ( cellCpId > 0 && cell == iecell && ichan == iechan )
208 DbgLv(1) <<
"Sim parms: cp_id" << cp_id <<
"sv" << cpIDsv;
237 QString channel = editdata.
channel;
238 int iechan = QString(
"ABCDEFGH" ).indexOf( channel );
239 int ch = qMax( 0, iechan ) / 2;
240 iechan = qMax( 0, iechan ) + 1;
241 QString ecell = editdata.
cell;
242 int iecell = ecell.toInt();
243 DbgLv(1) <<
"SP:iFD: cell chan ch" << ecell << channel << ch
251 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
253 QXmlStreamReader xml( &file );
258 while ( ! xml.atEnd() )
262 if ( xml.isStartElement() && xml.name() ==
"calibration" )
264 QXmlStreamAttributes a = xml.attributes();
266 rotorcoeffs[ 0 ] = a.value(
"coeff1" ).toString().toDouble();
267 rotorcoeffs[ 1 ] = a.value(
"coeff2" ).toString().toDouble();
270 if ( xml.isStartElement() && xml.name() ==
"dataset" )
272 QXmlStreamAttributes a = xml.attributes();
273 dcell = a.value(
"cell" ).toString().toInt();
274 dchan = a.value(
"channel" ).toString();
277 if ( xml.isStartElement() && xml.name() ==
"centerpiece" )
279 QXmlStreamAttributes a = xml.attributes();
280 dcp_id = a.value(
"id" ).toString().toInt();
281 DbgLv(1) <<
"SP:iFD: dcell dchan" << dcell << dchan;
282 if ( dcell == iecell && dchan == channel )
285 DbgLv(1) <<
"SP:iFD: cp_id" << cp_id;
304 double rpm = editdata.
scanData[ 0 ].rpm;
315 query <<
"get_experiment_info_by_runID"
327 expID = db->
value( 1 ).toString();
335 if (
rotorCalID.isEmpty() && ! expID.isEmpty() )
338 query <<
"get_experiment_info" << expID;
353 if ( ! expID.isEmpty() )
356 query <<
"all_cell_experiments" << expID;
360 int cell = db->
value( 2 ).toInt();
361 int ichan = db->
value( 3 ).toInt();
362 int cellCpId = db->
value( 4 ).toInt();
364 DbgLv(1) <<
"Sim parms: cell iecell ichan iechan" << cell << iecell
365 << ichan << iechan <<
"ccId" << cellCpId;
366 if ( cellCpId > 0 && cell == iecell && ichan == iechan )
374 DbgLv(1) <<
"Sim parms: cp_id" << cp_id <<
"sv" << cpIDsv;
397 QVector< US_SimulationParameters::SpeedProfile >& speedsteps )
404 + runID +
"." + dataType +
".xml";
407 if ( filei.open( QIODevice::ReadOnly | QIODevice::Text ) )
409 DbgLv(1) <<
"SP:rSS: fn" << fn;
410 QXmlStreamReader xml( &filei );
412 while ( ! xml.atEnd() )
416 if ( xml.isStartElement() && xml.name() ==
"speedstep" )
422 DbgLv(1) <<
"SP:rSS: step" << nsteps <<
"rotorspeed" << sp.rotorspeed
423 <<
"avg_speed" << sp.avg_speed;
435 QVector< US_DataIO::Scan >* scans,
436 QVector< US_SimulationParameters::SpeedProfile >& speedsteps )
441 int scanCount = (*scans).size();
442 double time1 = (*scans)[ 0 ].seconds;
444 double w2t1 = (*scans)[ 0 ].omega2t;
446 double delay_secs = time1;
447 double rpm = (*scans)[ 0 ].rpm;
448 double rpmnext = rpm;
449 double step_secs = 0.0;
451 double rpm_sum = rpm;
452 DbgLv(1) <<
"SP:cSS: scan" << 1 <<
"rpm time omega2t"
453 << rpm << qRound(time1) << (*scans)[ 0 ].omega2t;
455 for (
int ii = 1; ii < scanCount; ii++ )
458 rpmnext = (*scans)[ ii ].rpm;
460 int ss_next = qRound( rpmnext * 0.01 ) * 100;
461 int ss_curr = qRound( rpm * 0.01 ) * 100;
462 DbgLv(1) <<
"SP:cSS: scan" << (ii+1) <<
"rpm time omega2t"
463 << rpmnext << qRound((*scans)[ii].seconds) << (*scans)[ii].omega2t;
465 if ( ss_curr != ss_next )
467 time2 = (*scans)[ ii - 1 ].seconds;
468 w2t2 = (*scans)[ ii - 1 ].omega2t;
469 step_secs = time2 - time1 + delay_secs;
476 sp.
scans = ii - lscx;
485 for (
int jj = lscx; jj < ii; jj++ )
490 DbgLv(1) <<
"SP:cSS: speedsteps" << speedsteps.size() <<
"scans" << sp.
scans
500 time1 = (*scans)[ ii ].seconds;
501 w2t1 = (*scans)[ ii ].omega2t;
502 delay_secs = time1 - time2;
510 time2 = (*scans)[ scanCount - 1 ].seconds;
511 w2t2 = (*scans)[ scanCount - 1 ].omega2t;
512 step_secs = time2 - time1 + delay_secs;
519 sp.
scans = scanCount - lscx;
528 for (
int jj = lscx; jj < scanCount; jj++ )
533 DbgLv(1) <<
"SP:cSS: speedsteps" << speedsteps.size() <<
"scans" << sp.
scans
551 QList< US_AbstractCenterpiece > cp_list;
552 QMap < QString, QString > rotor_map;
562 for (
int jj = 0; jj < cp_list.size(); jj++ )
564 if ( cp_id == cp_list[ jj ].serial_number )
570 DbgLv(1) <<
"sH: cp ch cp_id" << cp << ch << cp_id;
575 shapes <<
"sector" <<
"standard" <<
"rectangular" <<
"band forming"
576 <<
"meniscus matching" <<
"circular" <<
"synthetic";
577 QString shape = cp_list[ cp ].shape;
579 cp_pathlen = cp_list[ cp ].path_length [ ch ];
582 cp_sector = qMax( 0, shapes.indexOf( shape ) );
593 qDebug() <<
"setHardware:readRotorMap *ERROR*";
609 QStringList meshlist;
610 QStringList gridlist;
611 meshlist <<
"ASTFEM" <<
"Claverie" <<
"MovingHat" <<
"User" <<
"ASTFVM";
612 gridlist <<
"Fixed" <<
"Moving";
615 QFile xfile( fname );
617 if ( xfile.open( QIODevice::ReadOnly | QIODevice::Text ) )
619 QXmlStreamReader xml( &xfile );
620 QXmlStreamAttributes a;
625 while ( ! xml.atEnd() )
629 if ( xml.isStartElement() && xml.name() ==
"params" )
631 a = xml.attributes();
633 astr = a.value(
"meshType" ).toString();
634 if ( !astr.isEmpty() )
636 kk = meshlist.indexOf( astr );
639 astr = a.value(
"gridType" ).toString();
640 if ( !astr.isEmpty() )
642 kk = gridlist.indexOf( astr );
645 astr = a.value(
"simpoints" ).toString();
646 if ( !astr.isEmpty() )
648 astr = a.value(
"radialres" ).toString();
649 if ( !astr.isEmpty() )
651 astr = a.value(
"meniscus" ).toString();
652 if ( !astr.isEmpty() )
654 astr = a.value(
"bottom" ).toString();
655 if ( !astr.isEmpty() )
657 astr = a.value(
"rnoise" ).toString();
658 if ( !astr.isEmpty() )
660 astr = a.value(
"tinoise" ).toString();
661 if ( !astr.isEmpty() )
663 astr = a.value(
"rinoise" ).toString();
664 if ( !astr.isEmpty() )
666 astr = a.value(
"temperature" ).toString();
667 if ( !astr.isEmpty() )
669 astr = a.value(
"bandform" ).toString();
670 if ( !astr.isEmpty() )
675 band_volume = a.value(
"bandvolume" ).toString().toDouble();
678 astr = a.value(
"rotorCalID" ).toString();
679 if ( !astr.isEmpty() )
681 astr = a.value(
"rotorcoeffs" ).toString().simplified();
682 if ( !astr.isEmpty() )
684 rotorcoeffs[ 0 ] = astr.section(
" ", 0, 0 ).toDouble();
685 rotorcoeffs[ 1 ] = astr.section(
" ", 1, 1 ).toDouble();
687 astr = a.value(
"sector" ).toString();
688 if ( !astr.isEmpty() )
690 astr = a.value(
"pathlength" ).toString();
691 if ( !astr.isEmpty() )
693 astr = a.value(
"angle" ).toString();
694 if ( !astr.isEmpty() )
696 astr = a.value(
"width" ).toString();
697 if ( !astr.isEmpty() )
701 else if ( xml.isStartElement() && xml.name() ==
"speedstep" )
708 else if ( xml.isStartElement() && xml.name() ==
"usermesh" )
710 a = xml.attributes();
716 mesh_radius << a.value(
"radius" ).toString().toDouble();
733 const char* mesh[] = {
"ASTFEM",
"Claverie",
"MovingHat",
"User",
"ASTFVM" };
734 const char* grid[] = {
"Fixed",
"Moving" };
737 QFile xfile( fname );
739 if ( xfile.open( QIODevice::WriteOnly | QIODevice::Text ) )
741 QXmlStreamWriter xml( &xfile );
742 xml.setAutoFormatting(
true );
744 xml.writeStartDocument();
745 xml.writeDTD (
"<!DOCTYPE US_SimParams>" );
746 xml.writeStartElement(
"SimParams" );
747 xml.writeAttribute (
"version",
"1.0" );
749 xml.writeStartElement(
"params" );
750 xml.writeAttribute (
"meshType", QString( mesh[ (
int)
meshType ] ) );
751 xml.writeAttribute (
"gridType", QString( grid[ (
int)
gridType ] ) );
752 xml.writeAttribute (
"simpoints", QString::number(
simpoints ) );
754 xml.writeAttribute (
"meniscus", QString::number(
meniscus ) );
755 xml.writeAttribute (
"bottom", QString::number(
bottom ) );
756 xml.writeAttribute (
"rnoise", QString::number(
rnoise ) );
757 xml.writeAttribute (
"tinoise", QString::number(
tinoise ) );
758 xml.writeAttribute (
"rinoise", QString::number(
rinoise ) );
759 xml.writeAttribute (
"temperature", QString::number(
temperature ) );
762 xml.writeAttribute (
"rotorCalID",
rotorCalID );
766 xml.writeAttribute (
"rotorcoeffs", QString().sprintf(
"%.3e %.3e",
770 xml.writeAttribute (
"bandform",
band_forming ?
"1" :
"0" );
773 xml.writeAttribute (
"bandvolume", QString::number(
band_volume ) );
775 xml.writeAttribute (
"sector", QString::number(
cp_sector ) );
776 xml.writeAttribute (
"pathlength", QString::number(
cp_pathlen ) );
777 xml.writeAttribute (
"angle", QString::number(
cp_angle ) );
778 xml.writeAttribute (
"width", QString::number(
cp_width ) );
784 xml.writeStartElement(
"usermesh" );
785 xml.writeAttribute(
"radius",
786 QString().sprintf(
"%11.5e",
mesh_radius[ ii ] ).simplified() );
787 xml.writeEndElement();
791 for (
int ii = 0; ii <
speed_step.size(); ii++ )
798 xml.writeEndElement ();
799 xml.writeEndElement ();
801 xml.writeEndDocument ();
831 const QString trueStr(
" 1YesyesTruetrue" );
832 QXmlStreamAttributes attr = xmli.attributes();
835 astr = attr.value(
"duration_hrs" ).toString();
836 if ( !astr.isEmpty() )
838 astr = attr.value(
"duration_mins" ).toString();
839 if ( !astr.isEmpty() )
841 astr = attr.value(
"delay_hrs" ).toString();
842 if ( !astr.isEmpty() )
844 astr = attr.value(
"delay_mins" ).toString();
845 if ( !astr.isEmpty() )
847 astr = attr.value(
"rotorspeed" ).toString();
848 if ( !astr.isEmpty() )
850 astr = attr.value(
"acceleration" ).toString();
851 if ( !astr.isEmpty() )
853 astr = attr.value(
"accelerflag" ).toString();
854 if ( !astr.isEmpty() )
856 astr = attr.value(
"scans" ).toString();
857 if ( !astr.isEmpty() )
858 spo.
scans = astr.toInt();
859 astr = attr.value(
"w2tfirst" ).toString();
860 if ( !astr.isEmpty() )
862 astr = attr.value(
"w2tlast" ).toString();
863 if ( !astr.isEmpty() )
865 astr = attr.value(
"timefirst" ).toString();
866 if ( !astr.isEmpty() )
868 astr = attr.value(
"timelast" ).toString();
869 if ( !astr.isEmpty() )
873 astr = attr.value(
"set_speed" ).toString();
874 if ( !astr.isEmpty() )
876 astr = attr.value(
"avg_speed" ).toString();
877 if ( !astr.isEmpty() )
879 astr = attr.value(
"speed_stddev" ).toString();
880 if ( !astr.isEmpty() )
888 xmlo.writeStartElement(
"speedstep" );
889 xmlo.writeAttribute (
"rotorspeed",
891 xmlo.writeAttribute (
"scans",
892 QString::number( spi->
scans ) );
893 xmlo.writeAttribute (
"timefirst",
895 xmlo.writeAttribute (
"timelast",
897 xmlo.writeAttribute (
"w2tfirst",
899 xmlo.writeAttribute (
"w2tlast",
901 xmlo.writeAttribute (
"duration_hrs",
903 xmlo.writeAttribute (
"duration_mins",
905 xmlo.writeAttribute (
"delay_hrs",
907 xmlo.writeAttribute (
"delay_mins",
909 xmlo.writeAttribute (
"acceleration",
911 xmlo.writeAttribute (
"accelerflag",
917 xmlo.writeAttribute (
"set_speed",
919 xmlo.writeAttribute (
"avg_speed",
921 xmlo.writeAttribute (
"speed_stddev",
925 xmlo.writeEndElement ();
930 QVector< SpeedProfile >& sps )
935 if ( dbP == NULL || expID < 1 )
939 QString idExp = QString::number( expID );
941 query <<
"all_speedsteps" << idExp;
947 int sspeedID = dbP->
value( 0 ).toInt();
955 QString aflag = dbP->
value( 8 ).toString();
966 DbgLv(1) <<
"SP:ssFromDB: speedstep" << nspeeds <<
"id" << sspeedID;
977 DbgLv(1) <<
"SP:ssToDB: dbP expid spi" << dbP << expID << spi;
980 if ( dbP == NULL || expID < 0 || spi == NULL )
983 QString idExp = QString::number( expID );
985 query <<
"new_speedstep" << idExp
986 << QString::number( spi->scans )
987 << QString::number( spi->duration_hours )
988 << QString::number( spi->duration_minutes )
989 << QString::number( spi->delay_hours )
990 << QString::number( spi->delay_minutes )
991 << QString::number( spi->rotorspeed )
992 << QString::number( spi->acceleration )
993 << QString( spi->acceleration_flag ?
"1" :
"0" )
994 << QString::number( spi->w2t_first )
995 << QString::number( spi->w2t_last )
996 << QString::number( spi->time_first )
997 << QString::number( spi->time_last )
998 << QString::number( spi->set_speed )
999 << QString::number( spi->avg_speed )
1000 << QString::number( spi->speed_stddev );
1003 DbgLv(1) <<
"SP:ssToDB: speedstep" << sstepID << dbP->
lastError();
1004 DbgLv(1) <<
"SP:ssToDB: w2t" << spi->w2t_first << spi->w2t_last
1005 << QString::number(spi->w2t_first) << QString::number(spi->w2t_last);
1013 qDebug() <<
"Sim parms Dump";
1014 qDebug() <<
"Mesh radius size:" <<
mesh_radius.size();
1016 qDebug() <<
"Mesh Type :" <<
meshType;
1017 qDebug() <<
"Grid Type :" <<
gridType;
1019 qDebug() <<
"Meniscus :" <<
meniscus;
1021 qDebug() <<
"Bottom :" <<
bottom;
1023 qDebug() <<
"Random noise :" <<
rnoise;
1024 qDebug() <<
"Time Inv Noise :" <<
tinoise;
1025 qDebug() <<
"Radial Inv Noise:" <<
rinoise;
1028 qDebug() <<
"Rotor Calibr.ID :" <<
rotorCalID;
1032 qDebug() <<
"CP Angle :" <<
cp_angle;
1033 qDebug() <<
"CP Width :" <<
cp_width;
1035 for (
int i = 0; i <
speed_step.size(); i++ )
1037 qDebug() <<
" Step" << i;
1038 qDebug() <<
" Duration Hours" <<
speed_step[ i ].duration_hours;
1039 qDebug() <<
" Duration Mins " <<
speed_step[ i ].duration_minutes;
1040 qDebug() <<
" Delay Hours " <<
speed_step[ i ].delay_hours;
1041 qDebug() <<
" Delay Mins " <<
speed_step[ i ].delay_minutes;
1042 qDebug() <<
" Scans " <<
speed_step[ i ].scans;
1043 qDebug() <<
" Acceleration " <<
speed_step[ i ].acceleration;
1044 qDebug() <<
" Rotor Speed " <<
speed_step[ i ].rotorspeed;
1045 qDebug() <<
" Accel Flag " <<
speed_step[ i ].acceleration_flag;
1046 qDebug() <<
" Omega2t First " <<
speed_step[ i ].w2t_first;
1047 qDebug() <<
" Omega2t Last " <<
speed_step[ i ].w2t_last;
1048 qDebug() <<
" Time First " <<
speed_step[ i ].time_first;
1049 qDebug() <<
" Time Last " <<
speed_step[ i ].time_last;
1050 qDebug() <<
" Set Speed " <<
speed_step[ i ].set_speed;
1051 qDebug() <<
" Average Speed " <<
speed_step[ i ].avg_speed;
1052 qDebug() <<
" Speed StdDev " <<
speed_step[ i ].speed_stddev;