10 QMap< QString, US_BufferComponent >& componentList )
16 qDebug() <<
"Database Error"
17 <<
"US_BufferComponent ::connectDB: Could not open DB\n"
22 QStringList q(
"get_buffer_component_desc" );
28 cids << db.
value( 0 ).toString();
31 for (
int ii = 0; ii < cids.size(); ii++ )
42 QStringList q(
"get_buffer_component_info" );
50 QString viscosity = db->
value( 2 ).toString();
51 QString density = db->
value( 3 ).toString();
55 QStringList sl = viscosity.split(
" " );
57 for (
int i = 0; i < 6 ; i++ )
60 sl = density.split(
" " );
62 for (
int i = 0; i < 6 ; i++ )
70 QMap< QString, US_BufferComponent >& componentList )
72 componentList.clear();
77 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
80 qDebug() <<
"Cannot open file " << fname;
84 QXmlStreamReader xml( &file );
86 while ( ! xml.atEnd() )
90 if ( xml.isStartElement() )
92 if ( xml.name() ==
"component" )
101 QXmlStreamReader& xml,
102 QMap< QString, US_BufferComponent >& componentList )
106 QXmlStreamAttributes a = xml.attributes();
108 bc.
name = a.value(
"name" ).toString();
109 bc.
unit = a.value(
"unit" ).toString();
110 bc.
range = a.value(
"range" ).toString();
112 a.value(
"gradient_forming" ).toString() );
114 while ( ! xml.atEnd() )
117 if ( xml.isEndElement() && xml.name() ==
"component" )
123 if ( xml.isStartElement() && xml.name() ==
"densityCoefficients" )
125 QXmlStreamAttributes a = xml.attributes();
126 bc.
dens_coeff[ 0 ] = a.value(
"c0" ).toString().toDouble();
127 bc.
dens_coeff[ 1 ] = a.value(
"c1" ).toString().toDouble();
128 bc.
dens_coeff[ 2 ] = a.value(
"c2" ).toString().toDouble();
129 bc.
dens_coeff[ 3 ] = a.value(
"c3" ).toString().toDouble();
130 bc.
dens_coeff[ 4 ] = a.value(
"c4" ).toString().toDouble();
131 bc.
dens_coeff[ 5 ] = a.value(
"c5" ).toString().toDouble();
134 if ( xml.isStartElement() && xml.name() ==
"viscosityCoefficients" )
136 QXmlStreamAttributes a = xml.attributes();
137 bc.
visc_coeff[ 0 ] = a.value(
"c0" ).toString().toDouble();
138 bc.
visc_coeff[ 1 ] = a.value(
"c1" ).toString().toDouble();
139 bc.
visc_coeff[ 2 ] = a.value(
"c2" ).toString().toDouble();
140 bc.
visc_coeff[ 3 ] = a.value(
"c3" ).toString().toDouble();
141 bc.
visc_coeff[ 4 ] = a.value(
"c4" ).toString().toDouble();
142 bc.
visc_coeff[ 5 ] = a.value(
"c5" ).toString().toDouble();
150 const QMap< QString, US_BufferComponent >& componentList )
154 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text) )
160 QXmlStreamWriter xml( &file );
161 xml.setAutoFormatting(
true );
163 xml.writeStartDocument();
164 xml.writeDTD (
"<!DOCTYPE US_BufferComponents>" );
165 xml.writeStartElement(
"BufferComponents" );
166 xml.writeAttribute (
"version",
"1.0" );
168 QStringList keys = componentList.keys();
170 for (
int i = 0; i < keys.size(); i++ )
172 QString key = keys[ i ];
173 xml.writeStartElement(
"component" );
174 xml.writeAttribute(
"id" , componentList[ key ].
componentID );
175 xml.writeAttribute(
"name" , componentList[ key ].
name );
176 xml.writeAttribute(
"unit" , componentList[ key ].
unit );
177 xml.writeAttribute(
"range", componentList[ key ].
range );
178 xml.writeAttribute(
"gradient_forming",
184 xml.writeStartElement(
"densityCoefficients" );
185 for (
int j = 0; j < 6; j++ )
187 factor.sprintf(
"c%i", j );
188 value = QString::number( componentList[ key ].
dens_coeff[ j ],
'f', 5 );
189 xml.writeAttribute( factor, value );
192 xml.writeEndElement();
194 xml.writeStartElement(
"viscosityCoefficients" );
195 for (
int j = 0; j < 6; j++ )
197 factor.sprintf(
"c%i", j );
198 value = QString::number( componentList[ key ].
visc_coeff[ j ],
'f', 5 );
199 xml.writeAttribute( factor, value );
202 xml.writeEndElement();
203 xml.writeEndElement();
206 xml.writeEndElement();
207 xml.writeEndDocument();
235 q <<
"get_spectrum" <<
bufferID <<
"Buffer" << type;
241 double lambda = db->
value( 0 ).toDouble();
242 double value = db->
value( 1 ).toDouble();
244 if ( type ==
"Extinction" )
246 else if ( type ==
"Refraction" )
256 q <<
"new_spectrum" <<
bufferID <<
"Buffer" << type <<
"" <<
"";
258 if ( type ==
"Extinction" )
262 for (
int i = 0; i < keys.size(); i++ )
264 double wavelength = keys[ i ];
265 q[ 4 ] = QString::number( wavelength,
'f', 1 );
266 q[ 5 ] = QString::number(
extinction[ wavelength ],
'e', 4 );
271 else if ( type ==
"Refraction" )
275 for (
int i = 0; i < keys.size(); i++ )
277 double wavelength = keys[ i ];
278 q[ 4 ] = QString::number( wavelength,
'f', 1 );
279 q[ 5 ] = QString::number(
refraction[ wavelength ],
'e', 4 );
288 for (
int i = 0; i < keys.size(); i++ )
290 double wavelength = keys[ i ];
291 q[ 4 ] = QString::number( wavelength,
'f', 1 );
292 q[ 5 ] = QString::number(
fluorescence[ wavelength ],
'e', 4 );
300 QFile file( filename );
301 if ( ! file.open( QIODevice::WriteOnly | QIODevice::Text) )
303 qDebug() <<
"Cannot open file for writing: " << filename;
307 QXmlStreamWriter xml( &file );
308 xml.setAutoFormatting(
true );
310 xml.writeStartDocument();
311 xml.writeDTD (
"<!DOCTYPE US_Buffer>" );
312 xml.writeStartElement(
"BufferData" );
313 xml.writeAttribute (
"version",
"1.0" );
315 xml.writeStartElement(
"buffer" );
316 xml.writeAttribute(
"id" ,
"0" );
317 xml.writeAttribute(
"guid" ,
GUID );
319 xml.writeAttribute(
"ph" , QString::number(
pH ,
'f', 5 ) );
320 xml.writeAttribute(
"density" , QString::number(
density ,
'f', 6 ) );
321 xml.writeAttribute(
"viscosity" , QString::number(
viscosity,
'f', 5 ) );
322 xml.writeAttribute(
"compressibility",
326 for (
int i = 0; i <
component.size(); i++ )
328 xml.writeStartElement(
"component" );
330 xml.writeAttribute(
"concentration",
332 xml.writeEndElement();
335 xml.writeStartElement(
"spectrum" );
341 xml.writeStartElement(
"extinction" );
342 double wavelength = keys[ i ];
344 xml.writeAttribute(
"wavelength", QString::number( wavelength,
'f', 1 ) );
345 xml.writeAttribute(
"value" , QString::number( value,
'e', 4 ) );
346 xml.writeEndElement();
351 xml.writeStartElement(
"refraction" );
352 double wavelength = keys[ i ];
354 xml.writeAttribute(
"wavelength", QString::number( wavelength,
'f', 1 ) );
355 xml.writeAttribute(
"value" , QString::number( value,
'e', 4 ) );
356 xml.writeEndElement();
361 xml.writeStartElement(
"fluorescence" );
362 double wavelength = keys[ i ];
364 xml.writeAttribute(
"wavelength", QString::number( wavelength,
'f', 1 ) );
365 xml.writeAttribute(
"value" , QString::number( value,
'e', 4 ) );
366 xml.writeEndElement();
369 xml.writeEndElement();
370 xml.writeEndElement();
371 xml.writeEndElement();
372 xml.writeEndDocument();
379 QStringList q(
"get_buffer_info" );
383 if ( db->
lastErrno() != 0 )
return false;
391 pH = db->
value( 3 ).toString().toDouble();
408 q <<
"get_buffer_components" <<
bufferID;
414 qDebug() <<
"get_buffer_components error=" << status;
450 int manx = descrip.indexOf(
" [M]" );
453 descrip = descrip.left( manx ).simplified();
458 qDebug() <<
"get_bufferID error=" << status;
469 << QString::number(
pH ,
'f', 4 )
470 << QString::number(
density ,
'f', 6 )
481 qDebug() <<
"new_buffer error=" << db->
lastErrno();
492 QString bufID = db->
value( 0 ).toString();
493 idBuffer = bufID.toInt();
500 << QString::number(
pH ,
'f', 4 )
501 << QString::number(
density ,
'f', 6 )
511 qDebug() <<
"update_buffer error=" << db->
lastErrno();
517 q <<
"delete_buffer_components" << bufID;
523 qDebug() <<
"delete_buffer_components error=" << db->
lastErrno();
528 for (
int i = 0; i < ncomp; i++ )
531 q <<
"add_buffer_component"
532 << QString::number( idBuffer )
540 qDebug() <<
"add_buffer_component i,error=" << i << db->
lastErrno();
561 QFile file( filename );
563 if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
565 qDebug() <<
"Cannot open file for reading: " << filename;
569 QXmlStreamReader xml( &file );
571 while ( ! xml.atEnd() )
575 if ( xml.isStartElement() )
577 if ( xml.name() ==
"buffer" )
587 const QString& path,
const QString& guid,
bool& newFile )
595 QXmlStreamAttributes a = xml.attributes();
597 bufferID = a.value(
"id" ).toString();
598 GUID = a.value(
"guid" ).toString();
601 pH = a.value(
"ph" ).toString().toDouble();
602 density = a.value(
"density" ).toString().toDouble();
603 viscosity = a.value(
"viscosity" ).toString().toDouble();
609 while ( ! xml.atEnd() )
611 if ( xml.isEndElement() && xml.name() ==
"buffer" )
break;
613 if ( xml.isStartElement() && xml.name() ==
"component" )
615 QXmlStreamAttributes a = xml.attributes();
616 concentration << a.value(
"concentration" ).toString().toDouble();
620 if ( xml.isStartElement() && xml.name() ==
"spectrum" )
629 while ( ! xml.atEnd() )
631 if ( xml.isEndElement() && xml.name() ==
"spectrum" )
break;
633 if ( xml.isStartElement() && xml.name() ==
"extinction" )
635 QXmlStreamAttributes a = xml.attributes();
636 extinction[ a.value(
"wavelength" ).toString().toDouble() ] =
637 a.value(
"value" ).toString().toDouble();
640 if ( xml.isStartElement() && xml.name() ==
"refraction" )
642 QXmlStreamAttributes a = xml.attributes();
643 refraction[ a.value(
"wavelength" ).toString().toDouble() ] =
644 a.value(
"value" ).toString().toDouble();
647 if ( xml.isStartElement() && xml.name() ==
"fluorescence" )
649 QXmlStreamAttributes a = xml.attributes();
650 fluorescence[ a.value(
"wavelength" ).toString().toDouble() ] =
651 a.value(
"value" ).toString().toDouble();
666 d_coeff[ 0 ] = (double)( 1 - ncomp ) *
DENS_20W;
667 v_coeff[ 0 ] = (double)( 1 - ncomp ) *
VISC_20W;
669 for (
int ii = 1; ii < 6; ii++ )
681 for (
int ii = 0; ii < ncomp; ii++ )
684 double cr = sqrt( c1 );
695 d_coeff[ 0 ] +=
component[ ii ].dens_coeff[ 0 ];
696 d_coeff[ 1 ] +=
component[ ii ].dens_coeff[ 1 ] * cr;
697 d_coeff[ 2 ] +=
component[ ii ].dens_coeff[ 2 ] * c1;
698 d_coeff[ 3 ] +=
component[ ii ].dens_coeff[ 3 ] * c2;
699 d_coeff[ 4 ] +=
component[ ii ].dens_coeff[ 4 ] * c3;
700 d_coeff[ 5 ] +=
component[ ii ].dens_coeff[ 5 ] * c4;
702 v_coeff[ 0 ] +=
component[ ii ].visc_coeff[ 0 ];
703 v_coeff[ 1 ] +=
component[ ii ].visc_coeff[ 1 ] * cr;
704 v_coeff[ 2 ] +=
component[ ii ].visc_coeff[ 2 ] * c1;
705 v_coeff[ 3 ] +=
component[ ii ].visc_coeff[ 3 ] * c2;
706 v_coeff[ 4 ] +=
component[ ii ].visc_coeff[ 4 ] * c3;
707 v_coeff[ 5 ] +=
component[ ii ].visc_coeff[ 5 ] * c4;
711 v_coeff[ 1 ] *= ( 1.0e-3 / sumcr );
712 v_coeff[ 2 ] *= ( 1.0e-2 / sumc1 );
713 v_coeff[ 3 ] *= ( 1.0e-3 / sumc2 );
714 v_coeff[ 4 ] *= ( 1.0e-4 / sumc3 );
715 v_coeff[ 5 ] *= ( 1.0e-6 / sumc4 );
717 d_coeff[ 1 ] *= ( 1.0e-3 / sumcr );
718 d_coeff[ 2 ] *= ( 1.0e-2 / sumc1 );
719 d_coeff[ 3 ] *= ( 1.0e-3 / sumc2 );
720 d_coeff[ 4 ] *= ( 1.0e-4 / sumc3 );
721 d_coeff[ 5 ] *= ( 1.0e-6 / sumc4 );
726 qDebug() <<
"person " <<
person;
727 qDebug() <<
"bufferID " <<
bufferID;
728 qDebug() <<
"GUID " <<
GUID;
731 qDebug() <<
"pH " <<
pH;
732 qDebug() <<
"density " <<
density;
737 qDebug() <<
"manual " <<
manual;
738 qDebug() <<
"Components " <<
component.size();
739 for (
int i = 0; i <
component.size(); i++ )