11 #define CTML_VERSION_1_4_1
23 using namespace Cantera;
28 std::string FP_Format =
"%23.15E";
29 std::string INT_Format =
"%8d";
38 static doublereal
fpValue(std::string val)
40 return atof(
stripws(val).c_str());
78 std::string v = (val ?
"true" :
"false");
79 XML_Node& f = node.addChild(
"bool", v);
120 const std::string units,
const std::string type)
122 #ifdef CTML_VERSION_1_4
123 XML_Node& f = node.addChild(
"integer", val);
126 XML_Node& f = node.addChild(title, val);
190 const int*
const vals,
const std::string units,
const std::string type,
191 const doublereal minval,
const doublereal maxval)
194 for (
size_t i = 0; i < n; i++) {
195 v +=
int2str(vals[i],INT_Format);
198 }
else if (i > 0 && (i+1) % 3 == 0) {
204 #ifdef CTML_VERSION_1_4
205 XML_Node& f = node.addChild(
"intArray",v);
208 XML_Node& f = node.addChild(title, v);
214 #ifndef CTML_VERSION_1_4
220 if (minval !=
Undef) {
223 if (maxval !=
Undef) {
270 const doublereal val,
const std::string units,
271 const std::string type,
const doublereal minval,
272 const doublereal maxval)
274 #ifdef CTML_VERSION_1_4
275 XML_Node& f = node.addChild(
"float", val, ctml::FP_Format);
278 XML_Node& f = node.addChild(title, val, ctml::FP_Format);
287 if (minval !=
Undef) {
290 if (maxval !=
Undef) {
346 const doublereal*
const vals,
const std::string units,
347 const std::string type,
348 const doublereal minval,
const doublereal maxval)
352 for (i = 0; i < n; i++) {
353 v +=
fp2str(vals[i],FP_Format);
356 }
else if (i > 0 && (i+1) % 3 == 0) {
362 XML_Node& f = node.addChild(
"floatArray",v);
371 if (minval !=
Undef) {
374 if (maxval !=
Undef) {
431 void addNamedFloatArray(
Cantera::XML_Node& node,
const std::string& name,
const int n,
432 const doublereal*
const vals,
const std::string units,
433 const std::string type,
const doublereal minval,
434 const doublereal maxval)
438 for (i = 0; i < n; i++) {
439 v +=
fp2str(vals[i],FP_Format);
442 }
else if (i > 0 && (i+1) % 3 == 0) {
448 XML_Node& f = node.addChild(name, v);
462 if (minval !=
Undef) {
465 if (maxval !=
Undef) {
499 const std::string& valueString,
500 const std::string typeString)
502 XML_Node& f = node.addChild(
"string", valueString);
504 if (typeString !=
"") {
515 if (s->
parent() == &node) {
554 return parent(nameString);
587 std::string& typeString)
593 if (s->
name() ==
"string") {
594 valueString = (*s).value();
595 typeString = (*s)[
"type"];
644 std::string& typeString)
650 valueString = xc.
value();
651 typeString = xc[
"type"];
655 if (s->
name() ==
"string") {
656 valueString = (*s).value();
657 typeString = (*s)[
"type"];
704 std::map<std::string, int>& v)
706 std::vector<XML_Node*> f;
708 int n =
static_cast<int>(f.size());
710 std::string typ, title, vmin, vmax;
711 for (
int i = 0; i < n; i++) {
713 x = atoi(fi().c_str());
718 if (fi[
"max"] !=
"") {
769 std::vector<XML_Node*> f;
771 int n =
static_cast<int>(f.size());
772 doublereal x, x0, x1, fctr;
773 std::string typ, title, units, vmin, vmax;
774 for (
int i = 0; i < n; i++) {
776 x = atof(fi().c_str());
785 x0 = atof(vmin.c_str());
787 writelog(
"\nWarning: value "+fi()+
" is below lower limit of "
791 if (fi[
"max"] !=
"") {
792 x1 = atof(vmax.c_str());
794 writelog(
"\nWarning: value "+fi()+
" is above upper limit of "
798 fctr = (convert ?
toSI(units) : 1.0);
838 const std::string& name,
839 const std::string type)
842 throw CanteraError(
"getFloat (called from XML Node \"" +
843 parent.
name() +
"\"): ",
844 "no child XML element named \"" + name +
"\" exists");
883 const std::string type)
885 doublereal x, x0, x1, fctr = 1.0;
886 string units, vmin, vmax;
887 x = atof(node().c_str());
890 units = node[
"units"];
894 x0 = atof(vmin.c_str());
896 writelog(
"\nWarning: value "+node()+
" is below lower limit of "
900 if (node[
"max"] !=
"") {
901 x1 = atof(vmax.c_str());
903 writelog(
"\nWarning: value "+node()+
" is above upper limit of "
909 if (type ==
"actEnergy" && units !=
"") {
911 }
else if (type ==
"toSI" && units !=
"") {
913 }
else if (type ==
"temperature" && units !=
"") {
915 }
else if (type ==
"density" && units !=
"") {
917 }
else if (type ==
"pressure" && units !=
"") {
919 }
else if (type !=
"" && units !=
"") {
922 writelog(
"\nWarning: conversion toSI() was done on node value " + node.
name() +
923 "but wasn't explicity requested. Type was \"" + type +
"\"\n");
928 #ifdef DEBUG_MODE_MORE
929 else if (type ==
"" && units !=
"") {
931 "has a units attribute, \"" + units +
"\","
932 "but no conversion was done because the getFloat() command didn't have a type\n");
940 const std::string& name,
942 const std::string type)
945 fltRtn=
getFloat(parent, name, type);
988 std::string defaultUnits, std::string type)
991 doublereal fctr = 1.0;
992 if (defaultUnits ==
"") {
994 "need to supply an actual value of defaultUnits");
996 if (type ==
"actEnergy") {
998 }
else if (type ==
"toSI") {
999 fctr =
toSI(defaultUnits);
1000 }
else if (defaultUnits ==
"temperature") {
1001 fctr =
toSI(defaultUnits);
1002 }
else if (type ==
"density") {
1003 fctr =
toSI(defaultUnits);
1004 }
else if (type ==
"pressure") {
1005 fctr =
toSI(defaultUnits);
1008 "type of units must be supplied and understood");
1010 doublereal val =
getFloat(parent, name, type);
1046 std::string& modelName)
1050 modelName = node[
"model"];
1086 throw CanteraError(
"getInteger (called from XML Node \"" +
1087 parent.
name() +
"\"): ",
1088 "no child XML element named " + name);
1092 string units, vmin, vmax;
1093 x = atoi(node().c_str());
1099 x0 = atoi(vmin.c_str());
1101 writelog(
"\nWarning: value "+node()+
" is below lower limit of "
1105 if (node[
"max"] !=
"") {
1106 x1 = atoi(vmax.c_str());
1108 writelog(
"\nWarning: value "+node()+
" is above upper limit of "
1175 const bool convert,
const std::string unitsString,
1176 const std::string nodeName)
1178 std::string::size_type icom;
1181 string nn = node.
name();
1183 if (nn != nodeName) {
1184 vector<Cantera::XML_Node*> ll;
1186 if (ll.size() == 0) {
1188 "wrong xml element type/name: was expecting "
1189 + nodeName +
"but accessed " + node.
name());
1194 if (ll.size() > 0) {
1203 doublereal funit = 1.0;
1207 std::string units = (*readNode)[
"units"];
1208 if (units !=
"" && convert) {
1209 if (unitsString ==
"actEnergy" && units !=
"") {
1211 }
else if (unitsString !=
"" && units !=
"") {
1212 funit =
toSI(units);
1216 if ((*readNode)[
"min"] !=
"") {
1217 vmin =
atofCheck((*readNode)[
"min"].c_str());
1219 if ((*readNode)[
"max"] !=
"") {
1220 vmax =
atofCheck((*readNode)[
"max"].c_str());
1224 std::string val = readNode->
value();
1226 icom = val.find(
',');
1228 numstr = val.substr(0,icom);
1229 val = val.substr(icom+1,val.size());
1248 if (vmin !=
Undef && vv < vmin -
Tiny) {
1250 " is below lower limit of " +
fp2str(vmin)+
".\n");
1252 if (vmax !=
Undef && vv > vmax +
Tiny) {
1254 " is above upper limit of " +
fp2str(vmin)+
".\n");
1257 for (
size_t n = 0; n < v.size(); n++) {
1263 size_t getNamedFloatArray(
const Cantera::XML_Node& parentNode,
const std::string& nodeName, std::vector<doublereal> & v,
1264 const bool convert,
const std::string unitsString)
1266 std::string::size_type icom;
1269 std::string nn = parentNode.
name();
1276 doublereal vmin =
Undef;
1277 doublereal vmax =
Undef;
1278 doublereal funit = 1.0;
1282 std::string units = (*readNode)[
"units"];
1283 if (units !=
"" && convert) {
1284 if (unitsString ==
"actEnergy" && units !=
"") {
1286 }
else if (unitsString !=
"" && units !=
"") {
1287 funit =
toSI(units);
1291 if ((*readNode)[
"min"] !=
"") {
1292 vmin =
atofCheck((*readNode)[
"min"].c_str());
1294 if ((*readNode)[
"max"] !=
"") {
1295 vmax =
atofCheck((*readNode)[
"max"].c_str());
1298 size_t expectedSize = 0;
1299 nn = (*readNode)[
"size"];
1300 expectedSize = atoi(nn.c_str());
1302 nn = (*readNode)[
"vtype"];
1303 if (nn !=
"floatArray") {
1305 "node named " + nodeName +
"didn't have correct vtype");
1309 std::string val = readNode->
value();
1311 icom = val.find(
',');
1313 numstr = val.substr(0,icom);
1314 val = val.substr(icom+1,val.size());
1326 size_t nlen = strlen(val.c_str());
1334 if (vmin !=
Undef && vv < vmin -
Tiny) {
1336 " is below lower limit of " +
fp2str(vmin)+
".\n");
1338 if (vmax !=
Undef && vv > vmax +
Tiny) {
1340 " is above upper limit of " +
fp2str(vmin)+
".\n");
1343 size_t nv = v.size();
1344 for (
size_t n = 0; n < nv; n++) {
1347 if (nv != expectedSize) {
1349 "node named " + nodeName +
"didn't have correct number of floats"
1377 std::vector<std::string> v;
1379 std::string key, val;
1380 int n =
static_cast<int>(v.size());
1381 string::size_type icolon;
1382 for (
int i = 0; i < n; i++) {
1383 icolon = v[i].find(
":");
1385 throw CanteraError(
"getMap",
"missing colon in map entry ("
1388 key = v[i].substr(0,icolon);
1389 val = v[i].substr(icolon+1, v[i].size());
1426 std::vector<std::string>& val)
1430 int n =
static_cast<int>(v.size());
1431 string::size_type icolon;
1432 for (
int i = 0; i < n; i++) {
1433 icolon = v[i].find(
":");
1435 throw CanteraError(
"getPairs",
"Missing a colon in the Pair entry ("
1438 key.push_back(v[i].substr(0,icolon));
1439 val.push_back(v[i].substr(icolon+1, v[i].size()));
1485 const std::vector<std::string>& keyStringRow,
1486 const std::vector<std::string>& keyStringCol,
1488 const bool matrixSymmetric)
1490 size_t szKey1 = keyStringRow.size();
1491 size_t szKey2 = keyStringCol.size();
1492 size_t nrow = retnValues.
nRows();
1493 size_t ncol = retnValues.
nColumns();
1494 if (szKey1 > nrow) {
1496 "size of key1 greater than numrows");
1498 if (szKey2 > ncol) {
1500 "size of key2 greater than num cols");
1502 if (matrixSymmetric) {
1505 "nrow != ncol for a symmetric matrix");
1513 doublereal funit = 1.0;
1514 string units = node[
"units"];
1515 if (units !=
"" && convert) {
1516 funit =
toSI(units);
1525 string::size_type icolon;
1526 for (
size_t i = 0; i < v.size(); i++) {
1527 icolon = v[i].find(
":");
1529 throw CanteraError(
"getMatrixValues",
"Missing two colons ("
1532 key1 = v[i].substr(0,icolon);
1533 rmm = v[i].substr(icolon+1, v[i].size());
1534 icolon = rmm.find(
":");
1536 throw CanteraError(
"getMatrixValues",
"Missing one colon ("
1539 key2 = rmm.substr(0,icolon);
1540 val = rmm.substr(icolon+1, rmm.size());
1544 for (
size_t j = 0; j < szKey1; j++) {
1545 if (key1 == keyStringRow[j]) {
1551 throw CanteraError(
"getMatrixValues",
"Row not matched by string: "
1554 for (
size_t j = 0; j < szKey2; j++) {
1555 if (key2 == keyStringCol[j]) {
1561 throw CanteraError(
"getMatrixValues",
"Col not matched by string: "
1569 retnValues(irow, icol) = dval;
1570 if (matrixSymmetric) {
1571 retnValues(icol, irow) = dval;
1587 std::string val = node.
value();
1642 doublereal& xmax, std::vector<doublereal> & coeffs)
1649 if (node[
"min"] !=
"") {
1652 if (node[
"max"] !=
"") {
1655 type = node[
"type"];