Expanded the capability of getFloatArray to read the current XML node

or a child node with a specified name. Before it would just read
an XML node named floatArray.
This commit is contained in:
Harry Moffat 2009-12-05 15:40:33 +00:00
parent cad06c4ace
commit b6c6d090f6
2 changed files with 31 additions and 17 deletions

View file

@ -5,8 +5,8 @@
*/
/*
* $Revision: 1.24 $
* $Date: 2009/03/13 03:18:08 $
* $Revision: 255 $
* $Date: 2009-11-09 16:36:49 -0700 (Mon, 09 Nov 2009) $
*/
// Copyright 2002 California Institute of Technology
@ -883,17 +883,27 @@ namespace ctml {
* units converter is used.
* @param nodeName XML Name of the XML node to read.
* The default value for the node name is floatArray
*
* @return Returns the number of floats read
*/
void getFloatArray(const Cantera::XML_Node& node, vector_fp& v, const bool convert,
int getFloatArray(const Cantera::XML_Node& node, vector_fp& v, const bool convert,
const std::string unitsString, const std::string nodeName) {
string::size_type icom;
string numstr;
doublereal dtmp;
string nn = node.name();
if (nn != nodeName)
throw CanteraError("getFloatArray",
"wrong xml element type/name: was expecting "
const Cantera::XML_Node *readNode = &node;
if (nn != nodeName) {
vector<Cantera::XML_Node *> ll;
node.getChildren(nodeName, ll);
if (ll.size() == 0) {
throw CanteraError("getFloatArray",
"wrong xml element type/name: was expecting "
+ nodeName + "but accessed " + node.name());
} else {
readNode = ll[0];
}
}
v.clear();
doublereal vmin = Undef, vmax = Undef;
@ -902,7 +912,7 @@ namespace ctml {
/*
* Get the attributes field, units, from the XML node
*/
std::string units = node["units"];
std::string units = (*readNode)["units"];
if (units != "" && convert) {
if (unitsString == "actEnergy" && units != "") {
funit = actEnergyToSI(units);
@ -911,13 +921,13 @@ namespace ctml {
}
}
if (node["min"] != "")
vmin = atofCheck(node["min"].c_str());
if (node["max"] != "")
vmax = atofCheck(node["max"].c_str());
if ((*readNode)["min"] != "")
vmin = atofCheck((*readNode)["min"].c_str());
if ((*readNode)["max"] != "")
vmax = atofCheck((*readNode)["max"].c_str());
doublereal vv;
std::string val = node.value();
std::string val = readNode->value();
while (1 > 0) {
icom = val.find(',');
if (icom != string::npos) {
@ -956,6 +966,7 @@ namespace ctml {
for (int n = 0; n < nv; n++) {
v[n] *= funit;
}
return v.size();
}
// This routine is used to interpret the value portions of XML

View file

@ -6,8 +6,8 @@
*/
/*
* $Revision: 1.22 $
* $Date: 2009/07/11 17:20:19 $
* $Revision: 255 $
* $Date: 2009-11-09 16:36:49 -0700 (Mon, 09 Nov 2009) $
*/
// Copyright 2002 California Institute of Technology
@ -311,10 +311,12 @@ namespace ctml {
const std::string &valueString, const std::string typeString="");
//! This function reads a child node with the default name, "floatArray", with a value
//! This function reads the current node or a child node of the current node
//! with the default name, "floatArray", with a value field
//! consisting of a comma separated list of floats
/*!
* This function will read a child node to the current XML node, with the
* This function will read either the current XML node or a child node
* to the current XML node, with the
* name "floatArray". It will have a title attribute, and the body
* of the XML node will be filled out with a comma separated list of
* doublereals.
@ -363,8 +365,9 @@ namespace ctml {
* units converter is used.
* @param nodeName XML Name of the XML node to read.
* The default value for the node name is floatArray
* @return Returns the number of floats read into v.
*/
void getFloatArray(const Cantera::XML_Node& node, Cantera::vector_fp& v,
int getFloatArray(const Cantera::XML_Node& node, Cantera::vector_fp& v,
const bool convert=true, const std::string typeString="",
const std::string nodeName = "floatArray");