00001 /** 00002 * @file ctml.h 00003 * CTML ("Cantera Markup Language") is the variant of XML that Cantera uses 00004 * to store data. These functions read and write it. 00005 * (see \ref inputfiles and importCTML, ck2ctml) 00006 */ 00007 00008 /* 00009 * $Revision: 374 $ 00010 * $Date: 2010-01-12 16:27:32 -0500 (Tue, 12 Jan 2010) $ 00011 */ 00012 00013 // Copyright 2002 California Institute of Technology 00014 00015 #ifndef CT_CTML_H 00016 #define CT_CTML_H 00017 00018 #include "ct_defs.h" 00019 #include "xml.h" 00020 #include "Array.h" 00021 00022 //! The ctml namespace adds functionality to the XML object, by providing 00023 //! standard functions that read, write, and interpret XML files and 00024 //! object trees. 00025 namespace ctml { 00026 00027 //! const Specifying the CTML version number 00028 /*! 00029 * @todo Codify what the CTML_Version number means. 00030 */ 00031 const std::string CTML_Version = "1.4.1"; 00032 00033 //! This function adds a child node with the name, "bool", with a value 00034 //! consisting of a single bool 00035 /*! 00036 * This function will add a child node to the current XML node, with the 00037 * name "bool". It will have a title attribute, and the body 00038 * of the XML node will be filled out with a single bool. 00039 * 00040 * Example: 00041 * 00042 * Code snipet: 00043 * @verbatim 00044 const XML_Node &node; 00045 std::string titleString = "doSpecialOp"; 00046 bool value = true; 00047 addBool(node, titleString, value); 00048 @endverbatim 00049 * 00050 * Creates the following the snippet in the XML file: 00051 * @verbatim 00052 <parentNode> 00053 <bool title="doSpecialOp" type="optional"> 00054 true 00055 <\integer> 00056 <\parentNode> 00057 @endverbatim 00058 * 00059 * @param node reference to the XML_Node object of the parent XML element 00060 * @param titleString String name of the title attribute 00061 * @param value Value - single bool 00062 * 00063 * @todo I don't think this is used. Figure out what is used for writing bools, 00064 * and codify that. 00065 */ 00066 void addBool(Cantera::XML_Node& node, const std::string &titleString, 00067 const bool value); 00068 00069 //! This function adds a child node with the name, "integer", with a value 00070 //! consisting of a single integer 00071 /*! 00072 * This function will add a child node to the current XML node, with the 00073 * name "integer". It will have a title attribute, and the body 00074 * of the XML node will be filled out with a single integer 00075 * 00076 * Example: 00077 * 00078 * Code snipet: 00079 * @verbatim 00080 const XML_Node &node; 00081 std::string titleString = "maxIterations"; 00082 int value = 1000; 00083 std::string typeString = "optional"; 00084 std::string units = ""; 00085 addInteger(node, titleString, value, typeString, units); 00086 @endverbatim 00087 * 00088 * Creates the following the snippet in the XML file: 00089 * @verbatim 00090 <parentNode> 00091 <integer title="maxIterations" type="optional"> 00092 100 00093 <\integer> 00094 <\parentNode> 00095 @endverbatim 00096 * 00097 * @param node reference to the XML_Node object of the parent XML element 00098 * @param titleString String name of the title attribute 00099 * @param value Value - single integer 00100 * @param unitsString String name of the Units attribute. The default is to 00101 * have an empty string. 00102 * @param typeString String type. This is an optional parameter. The default 00103 * is to have an empty string. 00104 * 00105 * @todo I don't think this is used. Figure out what is used for writing integers, 00106 * and codify that. unitsString shouldn't be here, since it's an int. 00107 * typeString should be codified as to its usage. 00108 */ 00109 void addInteger(Cantera::XML_Node& node, const std::string &titleString, 00110 const int value, const std::string unitsString="", 00111 const std::string typeString=""); 00112 00113 //! This function adds a child node with the name, "float", with a value 00114 //! consisting of a single floating point number 00115 /*! 00116 * This function will add a child node to the current XML node, with the 00117 * name "float". It will have a title attribute, and the body 00118 * of the XML node will be filled out with a single float 00119 * 00120 * Example: 00121 * 00122 * Code snipet: 00123 * @verbatim 00124 const XML_Node &node; 00125 std::string titleString = "activationEnergy"; 00126 doublereal value = 50.3; 00127 doublereal maxval = 1.0E3; 00128 doublereal minval = 0.0; 00129 std::string typeString = "optional"; 00130 std::string unitsString = "kcal/gmol"; 00131 addFloat(node, titleString, value, unitsString, typeString, minval, maxval); 00132 @endverbatim 00133 * 00134 * Creates the following the snippet in the XML file: 00135 * @verbatim 00136 <parentNode> 00137 <float title="activationEnergy" type="optional" units="kcal/gmol" min="0.0" max="1.0E3"> 00138 50.3 00139 <\float> 00140 <\parentNode> 00141 @endverbatim 00142 * 00143 * @param node reference to the XML_Node object of the parent XML element 00144 * @param titleString String name of the title attribute 00145 * @param value Value - single integer 00146 * @param unitsString String name of the Units attribute. The default is to 00147 * have an empty string. 00148 * @param typeString String type. This is an optional parameter. The default 00149 * is to have an empty string. 00150 * @param minval Minimum allowed value of the float. The default is the 00151 * special double, Cantera::Undef, which means to ignore the 00152 * entry. 00153 * @param maxval Maximum allowed value of the float. The default is the 00154 * special double, Cantera::Undef, which means to ignore the 00155 * entry. 00156 * 00157 * @todo I don't think this is used. Figure out what is used for writing floats, 00158 * and codify that. minval and maxval should be codified. 00159 * typeString should be codified as to its usage. 00160 */ 00161 void addFloat(Cantera::XML_Node& node, const std::string &titleString, 00162 const doublereal value, const std::string unitsString="", 00163 const std::string typeString="", const doublereal minval = Cantera::Undef, 00164 const doublereal maxval = Cantera::Undef); 00165 00166 //! This function adds a child node with the name, "intArray", with a value 00167 //! consisting of a comma separated list of integers 00168 /*! 00169 * This function will add a child node to the current XML node, with the 00170 * name "intArray". It will have a title attribute, and the body 00171 * of the XML node will be filled out with a comma separated list of 00172 * integers 00173 * 00174 * Example: 00175 * 00176 * Code snipet: 00177 * @verbatim 00178 const XML_Node &node; 00179 std::string titleString = "additionalCases"; 00180 int n = 3; 00181 int cases[3] = [3, 6, 10]; 00182 std::string typeString = "optional"; 00183 std::string units = ""; 00184 addIntegerArray(node, titleString, n, &cases[0], typeString, units); 00185 @endverbatim 00186 * 00187 * Creates the following the snippet in the XML file: 00188 * @verbatim 00189 <parentNode> 00190 <intArray title="additionalCases" type="optional"> 00191 3, 6, 10 00192 <\intArray> 00193 <\parentNode> 00194 @endverbatim 00195 * 00196 * @param node reference to the XML_Node object of the parent XML element 00197 * @param titleString String name of the title attribute 00198 * @param n Length of the integer vector. 00199 * @param values Pointer to a vector of integers 00200 * @param unitsString String name of the Units attribute. This is an optional 00201 * parameter. The default is to 00202 * have an empty string. 00203 * @param typeString String type. This is an optional parameter. The default 00204 * is to have an empty string. 00205 * @param minval Minimum allowed value of the int. This is an optional 00206 * parameter. The default is the 00207 * special double, Cantera::Undef, which means to ignore the 00208 * entry. 00209 * @param maxval Maximum allowed value of the int. This is an optional 00210 * parameter. The default is the 00211 * special double, Cantera::Undef, which means to ignore the 00212 * entry. 00213 * 00214 * @todo I don't think this is used. Figure out what is used for writing integers, 00215 * and codify that. unitsString shouldn't be here, since it's an int. 00216 * typeString should be codified as to its usage. 00217 */ 00218 void addIntegerArray(Cantera::XML_Node& node, const std::string &titleString, 00219 const int n, const int* const values, 00220 const std::string unitsString="", const std::string typeString="", 00221 const doublereal minval=Cantera::Undef, 00222 const doublereal maxval=Cantera::Undef); 00223 00224 //! This function adds a child node with the name, "floatArray", with a value 00225 //! consisting of a comma separated list of floats 00226 /*! 00227 * This function will add a child node to the current XML node, with the 00228 * name "floatArray". It will have a title attribute, and the body 00229 * of the XML node will be filled out with a comma separated list of 00230 * doublereals. 00231 * 00232 * Example: 00233 * 00234 * Code snipet: 00235 * @verbatim 00236 const XML_Node &node; 00237 std::string titleString = "additionalTemperatures"; 00238 int n = 3; 00239 int Tcases[3] = [273.15, 298.15, 373.15]; 00240 std::string typeString = "optional"; 00241 std::string units = "Kelvin"; 00242 addFloatArray(node, titleString, n, &cases[0], typeString, units); 00243 @endverbatim 00244 * 00245 * Creates the following the snippet in the XML file: 00246 * @verbatim 00247 <parentNode> 00248 <floatArray title="additionalTemperatures" type="optional" units="Kelvin"> 00249 273.15, 298.15, 373.15 00250 <\floatArray> 00251 <\parentNode> 00252 @endverbatim 00253 * 00254 * @param node reference to the XML_Node object of the parent XML element 00255 * @param titleString String name of the title attribute 00256 * @param n Length of the doubles vector. 00257 * @param values Pointer to a vector of doubles 00258 * @param unitsString String name of the Units attribute. This is an optional 00259 * parameter. The default is to 00260 * have an empty string. 00261 * @param typeString String type. This is an optional parameter. The default 00262 * is to have an empty string. 00263 * @param minval Minimum allowed value of the int. This is an optional 00264 * parameter. The default is the 00265 * special double, Cantera::Undef, which means to ignore the 00266 * entry. 00267 * @param maxval Maximum allowed value of the int. This is an optional 00268 * parameter. The default is the 00269 * special double, Cantera::Undef, which means to ignore the 00270 * entry. 00271 * 00272 * @todo I don't think this is used. Figure out what is used for writing integers, 00273 * and codify that. unitsString shouldn't be here, since it's an int. 00274 * typeString should be codified as to its usage. 00275 */ 00276 void addFloatArray(Cantera::XML_Node& node, const std::string &titleString, 00277 const int n, const doublereal* const values, 00278 const std::string unitsString="", const std::string typeString="", 00279 const doublereal minval = Cantera::Undef, 00280 const doublereal maxval = Cantera::Undef); 00281 00282 //! This function adds a child node with the name string with a string value 00283 //! to the current node 00284 /*! 00285 * This function will add a child node to the current XML node, with the 00286 * name "string". It will have a title attribute, and the body 00287 * of the XML node will be filled out with the valueString argument verbatim. 00288 * 00289 * Example: 00290 * 00291 * Code snipet: 00292 * @verbatim 00293 const XML_Node &node; 00294 addString(XML_Node& node, std::string titleString, std::string valueString, 00295 std::string typeString); 00296 @endverbatim 00297 * 00298 * Creates the following the snippet in the XML file: 00299 * @verbatim 00300 <string title="titleString" type="typeString"> 00301 valueString 00302 <\string> 00303 @endverbatim 00304 * 00305 * @param node reference to the XML_Node object of the parent XML element 00306 * @param valueString Value string to be used in the new XML node. 00307 * @param titleString String name of the title attribute 00308 * @param typeString String type. This is an optional parameter. 00309 */ 00310 void addString(Cantera::XML_Node& node, const std::string &titleString, 00311 const std::string &valueString, const std::string typeString=""); 00312 00313 00314 //! This function reads the current node or a child node of the current node 00315 //! with the default name, "floatArray", with a value field 00316 //! consisting of a comma separated list of floats 00317 /*! 00318 * This function will read either the current XML node or a child node 00319 * to the current XML node, with the 00320 * name "floatArray". It will have a title attribute, and the body 00321 * of the XML node will be filled out with a comma separated list of 00322 * doublereals. 00323 * Get an array of floats from the XML Node. The argument field 00324 * is assumed to consist of an arbitrary number of comma 00325 * separated floats, with an arbitrary amount of white space 00326 * separating each field. 00327 * If the node array has an units attribute field, then 00328 * the units are used to convert the floats, iff convert is true. 00329 * 00330 * Example: 00331 * 00332 * Code snipet: 00333 * @verbatim 00334 const XML_Node &State_XMLNode; 00335 vector_fp v; 00336 bool convert = true; 00337 unitsString = ""; 00338 nodeName="floatArray"; 00339 getFloatArray(State_XMLNode, v, convert, unitsString, nodeName); 00340 @endverbatim 00341 * 00342 * reads the corresponding XML file: 00343 * 00344 * @verbatim 00345 <state> 00346 <floatArray units="m3"> 32.4, 1, 100. <\floatArray> 00347 <\state> 00348 @endverbatim 00349 * 00350 * Will produce the vector 00351 * 00352 * v[0] = 32.4 00353 * v[1] = 1.0 00354 * v[2] = 100. 00355 * 00356 * 00357 * @param node XML parent node of the floatArray 00358 * @param v Output vector of floats containing the floatArray information. 00359 * @param convert Conversion to SI is carried out if this boolean is 00360 * True. The default is true. 00361 * @param unitsString String name of the type attribute. This is an optional 00362 * parameter. The default is to have an empty string. 00363 * The only string that is recognized is actEnergy. 00364 * Anything else has no effect. This affects what 00365 * units converter is used. 00366 * @param nodeName XML Name of the XML node to read. 00367 * The default value for the node name is floatArray 00368 * @return Returns the number of floats read into v. 00369 */ 00370 int getFloatArray(const Cantera::XML_Node& node, Cantera::vector_fp& v, 00371 const bool convert=true, const std::string unitsString="", 00372 const std::string nodeName = "floatArray"); 00373 00374 //! This function interprets the value portion of an XML element 00375 //! as a string. It then separates the string up into tokens 00376 //! according to the location of white space. 00377 /*! 00378 * The separate tokens are returned in the string vector 00379 * 00380 * @param node Node to get the value from 00381 * @param v Output vector containing the string tokens 00382 */ 00383 void getStringArray(const Cantera::XML_Node& node, std::vector<std::string>& v); 00384 00385 00386 //! This routine is used to interpret the value portions of XML 00387 //! elements that contain colon separated pairs. 00388 /*! 00389 * These are used, for example, in describing the element 00390 * composition of species. 00391 * @verbatim 00392 <atomArray> H:4 C:1 <atomArray> 00393 @endverbatim 00394 * The string is first separated into a string vector according 00395 * to the location of white space. Then each string is again 00396 * separated into two parts according to the location of a 00397 * colon in the string. The first part of the string is 00398 * used as the key, while the second part of the string is 00399 * used as the value, in the return map. 00400 * It is an error to not find a colon in each string pair. 00401 * 00402 * @param node Current node 00403 * @param m Output Map containing the pairs of values found 00404 * in the XML Node 00405 */ 00406 void getMap(const Cantera::XML_Node& node, std::map<std::string, std::string>& m); 00407 00408 //! This function interprets the value portion of an XML element 00409 //! as a series of "Pairs" separated by white space. 00410 /*! 00411 * Each pair consists of nonwhite-space characters. 00412 * The first ":" found in the pair string is used to separate 00413 * the string into two parts. The first part is called the "key" 00414 * The second part is called the "val". 00415 * String vectors of key[i] and val[i] are returned in the 00416 * argument list. 00417 * Warning: No spaces are allowed in each pair. Quotes get included as part 00418 * of the string. 00419 * Example: 00420 * @verbatim 00421 <xmlNode> 00422 red:112 blue:34 00423 green:banana 00424 </xmlNode> 00425 @endverbatim 00426 * 00427 * Returns: 00428 * key val 00429 * 0: "red" "112" 00430 * 1: "blue" "34" 00431 * 2: "green" "banana" 00432 * 00433 * 00434 * @param node XML Node 00435 * @param key Vector of keys for each entry 00436 * @param val Vector of values for each entry 00437 * 00438 * @return Returns the number of pairs found 00439 */ 00440 int getPairs(const Cantera::XML_Node& node, std::vector<std::string>& key, 00441 std::vector<std::string>& val); 00442 00443 //! This function interprets the value portion of an XML element 00444 //! as a series of "Matrix ids and entries" separated by white space. 00445 /*! 00446 * Each pair consists of nonwhite-space characters. 00447 * The first two ":" found in the pair string is used to separate 00448 * the string into three parts. The first part is called the first 00449 * key. The second part is the second key. Both parts must match 00450 * an entry in the keyString1 and keyString2, respectively, 00451 * in order to provide a location to 00452 * place the object in the matrix. 00453 * The third part is called the value. It is expected to be 00454 * a double. It is translated into a double and placed into the 00455 * correct location in the matrix. 00456 * 00457 * Warning: No spaces are allowed in each triplet. Quotes are part 00458 * of the string. 00459 * Example 00460 * keyString = red, blue, black, green 00461 * 00462 * @verbatim 00463 <xmlNode> 00464 red:green:112 00465 blue:black:3.3E-23 00466 00467 </xmlNode> 00468 @endverbatim 00469 * Returns: 00470 * retnValues(0, 3) = 112 00471 * retnValues(1, 2) = 3.3E-23 00472 * 00473 * 00474 * @param node XML Node containing the information for the matrix 00475 * @param keyStringRow Key string for the row 00476 * @param keyStringCol Key string for the column entries 00477 * @param returnValues Return Matrix. 00478 * @param convert If this is true, and if the node has a units 00479 * attribute, then conversion to si units is carried 00480 * out. Default is true. 00481 * @param matrixSymmetric If true entries are made so that the matrix 00482 * is always symmetric. Default is false. 00483 */ 00484 void getMatrixValues(const Cantera::XML_Node& node, 00485 const std::vector<std::string>& keyStringRow, 00486 const std::vector<std::string>& keyStringCol, 00487 Cantera::Array2D &returnValues, const bool convert = true, 00488 const bool matrixSymmetric = false); 00489 00490 00491 //! Get a vector of integer values from a child element. 00492 /*! 00493 * Returns a std::map containing a keyed values for child XML_Nodes 00494 * of the current node with the name, "integer". 00495 * In the keyed mapping there will be a list of titles vs. values 00496 * for all of the XML nodes. 00497 * The integer XML_nodes are expected to be in a particular form created 00498 * by the function addInteger(). One value per XML_node is expected. 00499 * 00500 * 00501 * Example: 00502 * 00503 * Code snipet: 00504 * @verbatim 00505 const XML_Node &State_XMLNode; 00506 std::map<std::string, integer> v; 00507 getinteger(State_XMLNode, v); 00508 @endverbatim 00509 * 00510 * reads the corresponding XML file: 00511 * 00512 * @verbatim 00513 <state> 00514 <integer title="i1"> 1 <\integer> 00515 <integer title="i2"> 2 <\integer> 00516 <integer title="i3"> 3 <\integer> 00517 <\state> 00518 @endverbatim 00519 * 00520 * Will produce the mapping: 00521 * 00522 * v["i1"] = 1 00523 * v["i2"] = 2 00524 * v["i3"] = 3 00525 * 00526 * 00527 * @param node Current XML node to get the values from 00528 * @param v Output map of the results. 00529 */ 00530 void getIntegers(const Cantera::XML_Node& node, std::map<std::string,int>& v); 00531 00532 00533 //! Get a floating-point value from a child element. 00534 /*! 00535 * Returns a doublereal value for the child named 'name' of element 'parent'. If 00536 * 'type' is supplied and matches a known unit type, unit 00537 * conversion to SI will be done if the child element has an attribute 00538 * 'units'. 00539 * 00540 * Note, it's an error for the child element not to exist. 00541 * 00542 * Example: 00543 * 00544 * Code snipet: 00545 * @verbatim 00546 const XML_Node &State_XMLNode; 00547 doublereal pres = OneAtm; 00548 if (state_XMLNode.hasChild("pressure")) { 00549 pres = getFloat(State_XMLNode, "pressure", "toSI"); 00550 } 00551 @endverbatim 00552 * 00553 * reads the corresponding XML file: 00554 * @verbatim 00555 <state> 00556 <pressure units="Pa"> 101325.0 </pressure> 00557 <\state> 00558 @endverbatim 00559 * 00560 * @param parent reference to the XML_Node object of the parent XML element 00561 * @param name Name of the XML child element 00562 * @param type String type. Currently known types are "toSI" and "actEnergy", 00563 * and "" , for no conversion. The default value is "", 00564 * which implies that no conversion is allowed. 00565 */ 00566 doublereal getFloat(const Cantera::XML_Node& parent, const std::string &name, 00567 const std::string type=""); 00568 00569 //! Get a floating-point value from the current XML element 00570 /*! 00571 * Returns a doublereal value from the current element. If 00572 * 'type' is supplied and matches a known unit type, unit 00573 * conversion to SI will be done if the child element has an attribute 00574 * 'units'. 00575 * 00576 * Note, it's an error for the child element not to exist. 00577 * 00578 * Example: 00579 * 00580 * Code snipet: 00581 * @verbatim 00582 const XML_Node &State_XMLNode; 00583 doublereal pres = OneAtm; 00584 if (state_XMLNode.hasChild("pressure")) { 00585 XML_Node *pres_XMLNode = State_XMLNode.getChild("pressure"); 00586 pres = getFloatCurrent(pres_XMLNode, "toSI"); 00587 } 00588 @endverbatim 00589 * 00590 * reads the corresponding XML file: 00591 * @verbatim 00592 <state> 00593 <pressure units="Pa"> 101325.0 </pressure> 00594 <\state> 00595 @endverbatim 00596 * 00597 * @param currXML reference to the current XML_Node object 00598 * @param type String type. Currently known types are "toSI" and "actEnergy", 00599 * and "" , for no conversion. The default value is "", 00600 * which implies that no conversion is allowed. 00601 */ 00602 doublereal getFloatCurrent(const Cantera::XML_Node& currXML, const std::string type=""); 00603 00604 //! Get an optional floating-point value from a child element. 00605 /*! 00606 * Returns a doublereal value for the child named 'name' of element 'parent'. If 00607 * 'type' is supplied and matches a known unit type, unit 00608 * conversion to SI will be done if the child element has an attribute 00609 * 'units'. 00610 * 00611 * 00612 * 00613 * Example: 00614 * 00615 * Code snipet: 00616 * @verbatim 00617 const XML_Node &State_XMLNode; 00618 doublereal pres = OneAtm; 00619 bool exists = getOptionalFloat(State_XMLNode, "pressure", pres, "toSI"); 00620 @endverbatim 00621 * 00622 * reads the corresponding XML file: 00623 * @verbatim 00624 <state> 00625 <pressure units="Pa"> 101325.0 </pressure> 00626 <\state> 00627 @endverbatim 00628 * 00629 * @param parent reference to the XML_Node object of the parent XML element 00630 * @param name Name of the XML child element 00631 * @param fltRtn Float Return. It will be overridden if the XML 00632 * element exists. 00633 * @param type String type. Currently known types are "toSI" 00634 * and "actEnergy", 00635 * and "" , for no conversion. The default value is "", 00636 * which implies that no conversion is allowed. 00637 * 00638 * @return returns true if the child element named "name" exists 00639 */ 00640 bool getOptionalFloat(const Cantera::XML_Node& parent, const std::string &name, 00641 doublereal &fltRtn, const std::string type=""); 00642 00643 00644 //! Get a vector of floating-point values from a child element. 00645 /*! 00646 * Returns a std::map containing a keyed values for child XML_Nodes 00647 * of the current node with the name, "float". 00648 * In the keyed mapping there will be a list of titles vs. values 00649 * for all of the XML nodes. 00650 * The float XML_nodes are expected to be in a particular form created 00651 * by the function addFloat(). One value per XML_node is expected. 00652 * 00653 * 00654 * Example: 00655 * 00656 * Code snipet: 00657 * @verbatim 00658 const XML_Node &State_XMLNode; 00659 std::map<std::string,double> v; 00660 bool convert = true; 00661 getFloats(State_XMLNode, v, convert); 00662 @endverbatim 00663 * 00664 * reads the corresponding XML file: 00665 * 00666 * @verbatim 00667 <state> 00668 <float title="a1" units="m3"> 32.4 <\float> 00669 <float title="a2" units="cm3"> 1. <\float> 00670 <float title="a3"> 100. <\float> 00671 <\state> 00672 @endverbatim 00673 * 00674 * Will produce the mapping: 00675 * 00676 * v["a1"] = 32.4 00677 * v["a2"] = 1.0E-6 00678 * v["a3"] = 100. 00679 * 00680 * 00681 * @param node Current XML node to get the values from 00682 * @param v Output map of the results. 00683 * @param convert Turn on conversion to SI units 00684 */ 00685 void getFloats(const Cantera::XML_Node& node, std::map<std::string, double>& v, 00686 const bool convert=true); 00687 00688 //! Get an integer value from a child element. 00689 /*! 00690 * Returns an integer value for the child named 'name' of element 'parent'. 00691 * 00692 * Note, it's an error for the child element not to exist. 00693 * 00694 * Example: 00695 * 00696 * Code snipet: 00697 * @verbatim 00698 const XML_Node &State_XMLNode; 00699 int number = 1; 00700 if (state_XMLNode.hasChild("NumProcs")) { 00701 number = getInteger(State_XMLNode, "numProcs"); 00702 } 00703 @endverbatim 00704 * 00705 * reads the corresponding XML file: 00706 * @verbatim 00707 <state> 00708 <numProcs> 10 <numProcs/> 00709 <\state> 00710 @endverbatim 00711 * 00712 * @param parent reference to the XML_Node object of the parent XML element 00713 * @param name Name of the XML child element 00714 */ 00715 int getInteger(const Cantera::XML_Node& parent, std::string name); 00716 00717 //! Get a floating-point value from a child element with a defined units field 00718 /*! 00719 * Returns a doublereal value for the child named 'name' of element 'parent'. 00720 * 'type' must be supplied and match a known unit type. 00721 * 00722 * Note, it's an error for the child element not to exist. 00723 * 00724 * Example: 00725 * 00726 * Code snipet: 00727 * @verbatim 00728 const XML_Node &State_XMLNode; 00729 doublereal pres = OneAtm; 00730 if (state_XMLNode.hasChild("pressure")) { 00731 pres = getFloatDefaultUnits(State_XMLNode, "pressure", "Pa", "toSI"); 00732 } 00733 @endverbatim 00734 * 00735 * reads the corresponding XML file: 00736 * @verbatim 00737 <state> 00738 <pressure units="Pa"> 101325.0 </pressure> 00739 <\state> 00740 @endverbatim 00741 * 00742 * @param parent reference to the XML_Node object of the parent XML element 00743 * @param name Name of the XML child element 00744 * @param defaultUnits Default units string to be found in the units attribute. 00745 * If the units string in the XML field is equal to defaultUnits, 00746 * no units conversion will be carried out. 00747 * @param type String type. Currently known types are "toSI" and "actEnergy", 00748 * and "" , for no conversion. The default value is "", 00749 * which implies that no conversion is allowed. 00750 */ 00751 doublereal getFloatDefaultUnits(const Cantera::XML_Node& parent, std::string name, 00752 std::string defaultUnits, std::string type="toSI"); 00753 00754 //! Get an optional model name from a named child node. 00755 /*! 00756 * Returns the model name attribute for the child named 'nodeName' of element 'parent'. 00757 * Note, it's optional for the child node to exist 00758 * 00759 * Example: 00760 * 00761 * Code snipet: 00762 * @verbatim 00763 std::string modelName = ""; 00764 bool exists = getOptionalModel(transportNode, "compositionDependence", 00765 modelName); 00766 @endverbatim 00767 * 00768 * reads the corresponding XML file: 00769 * @verbatim 00770 <transport model="Simple"> 00771 <compositionDependence model="Solvent_Only"/> 00772 </transport> 00773 @endverbatim 00774 * 00775 * On return modelName is set to "Solvent_Only". 00776 * 00777 * @param parent reference to the XML_Node object of the parent XML element 00778 * @param nodeName Name of the XML child element 00779 * @param modelName On return this contains the contents of the model attribute 00780 * 00781 * @return True if the nodeName XML node exists. False otherwise 00782 */ 00783 bool getOptionalModel(const Cantera::XML_Node& parent, const std::string nodeName, 00784 std::string &modelName); 00785 00786 //! This function reads a child node with the default name, "floatArray", with a value 00787 //! consisting of a comma separated list of floats 00788 /*! 00789 * This function will read a child node to the current XML node, with the 00790 * name "floatArray". It will have a title attribute, and the body 00791 * of the XML node will be filled out with a comma separated list of 00792 * doublereals. 00793 * Get an array of floats from the XML Node. The argument field 00794 * is assumed to consist of an arbitrary number of comma 00795 * separated floats, with an arbitrary amount of white space 00796 * separating each field. 00797 * If the node array has an units attribute field, then 00798 * the units are used to convert the floats, iff convert is true. 00799 * This function is a wrapper around the function getFloatArray(). 00800 * 00801 * Example: 00802 * 00803 * Code snipet: 00804 * @verbatim 00805 const XML_Node &State_XMLNode; 00806 vector_fp v; 00807 bool convert = true; 00808 unitsString = ""; 00809 nodeName="floatArray"; 00810 getFloatArray(State_XMLNode, v, convert, unitsString, nodeName); 00811 @endverbatim 00812 * 00813 * reads the corresponding XML file: 00814 * 00815 * @verbatim 00816 <state> 00817 <floatArray units="m3"> 32.4, 1, 100. <\floatArray> 00818 <\state> 00819 @endverbatim 00820 * 00821 * Will produce the vector 00822 * 00823 * v[0] = 32.4 00824 * v[1] = 1.0 00825 * v[2] = 100. 00826 * 00827 * 00828 * @param node XML parent node of the floatArray 00829 * @param typeString Returns the type attribute of the current node. 00830 * @param xmin Returns the minimum value attribute of the 00831 * current node. 00832 * @param xmax Returns the maximum value attribute of the 00833 * current node. 00834 * @param v Output vector of floats containing the floatArray 00835 * information. 00836 */ 00837 void getFunction(const Cantera::XML_Node& node, std::string& typeString, 00838 doublereal& xmin, doublereal& xmax, Cantera::vector_fp& v); 00839 00840 00841 //! Search the child nodes of the current node for an XML Node with a Title 00842 //! attribute of a given name. 00843 /*! 00844 * @param node Current node from which to conduct the search 00845 * @param title Name of the title attribute 00846 * 00847 * @return Returns a pointer to the matched child node. Returns 0 if no node is 00848 * found. 00849 */ 00850 Cantera::XML_Node* getByTitle(const Cantera::XML_Node& node, const std::string &title); 00851 00852 //! This function reads a child node with the name string with a specific 00853 //! title attribute named titleString 00854 /*! 00855 * This function will read a child node to the current XML node, with the 00856 * name "string". It must have a title attribute, named titleString, and the body 00857 * of the XML node will be read into the valueString output argument. 00858 * 00859 * If the child node is not found then the empty string is returned. 00860 * 00861 * Example: 00862 * 00863 * Code snipet: 00864 * @verbatim 00865 const XML_Node &node; 00866 getString(XML_Node& node, std::string titleString, std::string valueString, 00867 std::string typeString); 00868 @endverbatim 00869 * 00870 * Reads the following the snippet in the XML file: 00871 * @verbatim 00872 <string title="titleString" type="typeString"> 00873 valueString 00874 <\string> 00875 @endverbatim 00876 * 00877 * @param node reference to the XML_Node object of the parent XML element 00878 * @param titleString String name of the title attribute of the child node 00879 * @param valueString Value string that is found in the child node. output variable 00880 * @param typeString String type. This is an optional output variable 00881 */ 00882 void getString(const Cantera::XML_Node& node, const std::string &titleString, 00883 std::string& valueString, std::string& typeString); 00884 00885 //! This function reads a child node with the name, nameString, and returns 00886 //! its xml value as the return string 00887 /*! 00888 * If the child XML_node named "name" doesn't exist, the empty string is returned. 00889 * 00890 * Code snipet: 00891 * @verbatim 00892 const XML_Node &parent; 00893 string nameString = "vacency_species"; 00894 string valueString = getChildValue(parent, nameString 00895 std::string typeString); 00896 @endverbatim 00897 * 00898 * returns valueString = "O(V)" 00899 * 00900 * from the following the snippet in the XML file: 00901 * 00902 * @verbatim 00903 <vacencySpecies> 00904 O(V) 00905 <\vancencySpecies> 00906 @endverbatim 00907 * 00908 * @param parent parent reference to the XML_Node object of the parent XML element 00909 * @param nameString Name of the childe XML_Node to read the value from. 00910 * 00911 * @return String value of the child XML_Node 00912 */ 00913 std::string getChildValue(const Cantera::XML_Node& parent, 00914 const std::string &nameString); 00915 00916 //! Read an ctml file from a file and fill up an XML tree 00917 /*! 00918 * This is the main routine that reads a ctml file and puts it into 00919 * an XML_Node tree 00920 * 00921 * @param node Root of the tree 00922 * @param file Name of the file 00923 * @param debug Turn on debugging printing 00924 */ 00925 void get_CTML_Tree(Cantera::XML_Node* node, const std::string file, 00926 const int debug = 0); 00927 00928 //! Convert a cti file into a ctml file 00929 /*! 00930 * 00931 * @param file Pointer to the file 00932 * @param debug Turn on debug printing 00933 * 00934 * @ingroup inputfiles 00935 */ 00936 void ct2ctml(const char* file, const int debug = 0); 00937 } 00938 00939 #endif