Cantera  2.0
ctml.h
Go to the documentation of this file.
1 /**
2  * @file ctml.h
3  * CTML ("Cantera Markup Language") is the variant of XML that Cantera uses
4  * to store data. These functions read and write it.
5  * (see \ref inputfiles and importCTML, ck2ctml)
6  */
7 // Copyright 2002 California Institute of Technology
8 
9 #ifndef CT_CTML_H
10 #define CT_CTML_H
11 
12 #include "ct_defs.h"
13 #include "xml.h"
14 #include "Array.h"
15 
16 //! The ctml namespace adds functionality to the XML object, by providing
17 //! standard functions that read, write, and interpret XML files and
18 //! object trees.
19 /*!
20  * Standardization of reads and write from Cantera files occur here.
21  */
22 namespace ctml
23 {
24 
25 //! const Specifying the CTML version number
26 /*!
27  * @todo Codify what the CTML_Version number means.
28  */
29 const std::string CTML_Version = "1.4.1";
30 
31 extern std::string FP_Format;
32 
33 extern std::string INT_Format;
34 
35 //! This function adds a child node with the name, "bool", with a value
36 //! consisting of a single bool
37 /*!
38  * This function will add a child node to the current XML node, with the
39  * name "bool". It will have a title attribute, and the body
40  * of the XML node will be filled out with a single bool.
41  *
42  * Example:
43  *
44  * Code snippet:
45  * @verbatim
46  const XML_Node &node;
47  std::string titleString = "doSpecialOp";
48  bool value = true;
49  addBool(node, titleString, value);
50  @endverbatim
51  *
52  * Creates the following the snippet in the XML file:
53  * @verbatim
54  <parentNode>
55  <bool title="doSpecialOp" type="optional">
56  true
57  <\integer>
58  <\parentNode>
59  @endverbatim
60  *
61  * @param node reference to the XML_Node object of the parent XML element
62  * @param titleString String name of the title attribute
63  * @param value Value - single bool
64  *
65  * @deprecated never used
66  */
67 DEPRECATED(void addBool(Cantera::XML_Node& node, const std::string& titleString,
68  const bool value));
69 
70 //! This function adds a child node with the name, "integer", with a value
71 //! consisting of a single integer
72 /*!
73  * This function will add a child node to the current XML node, with the
74  * name "integer". It will have a title attribute, and the body
75  * of the XML node will be filled out with a single integer
76  *
77  * Example:
78  *
79  * Code snippet:
80  * @verbatim
81  const XML_Node &node;
82  std::string titleString = "maxIterations";
83  int value = 1000;
84  std::string typeString = "optional";
85  std::string units = "";
86  addInteger(node, titleString, value, typeString, units);
87  @endverbatim
88  *
89  * Creates the following the snippet in the XML file:
90  * @verbatim
91  <parentNode>
92  <integer title="maxIterations" type="optional">
93  100
94  <\integer>
95  <\parentNode>
96  @endverbatim
97  *
98  * @param node reference to the XML_Node object of the parent XML element
99  * @param titleString String name of the title attribute
100  * @param value Value - single integer
101  * @param unitsString String name of the Units attribute. The default is to
102  * have an empty string.
103  * @param typeString String type. This is an optional parameter. The default
104  * is to have an empty string.
105  *
106  * @todo I don't think this is used. Figure out what is used for writing integers,
107  * and codify that. unitsString shouldn't be here, since it's an int.
108  * typeString should be codified as to its usage.
109  */
110 void addInteger(Cantera::XML_Node& node, const std::string& titleString,
111  const int value, const std::string unitsString="",
112  const std::string typeString="");
113 
114 //! This function adds a child node with the name, "float", with a value
115 //! consisting of a single floating point number
116 /*!
117  * This function will add a child node to the current XML node, with the
118  * name "float". It will have a title attribute, and the body
119  * of the XML node will be filled out with a single float
120  *
121  * Example:
122  *
123  * Code snippet:
124  * @verbatim
125  const XML_Node &node;
126  std::string titleString = "activationEnergy";
127  doublereal value = 50.3;
128  doublereal maxval = 1.0E3;
129  doublereal minval = 0.0;
130  std::string typeString = "optional";
131  std::string unitsString = "kcal/gmol";
132  addFloat(node, titleString, value, unitsString, typeString, minval, maxval);
133  @endverbatim
134  *
135  * Creates the following the snippet in the XML file:
136  * @verbatim
137  <parentNode>
138  <float title="activationEnergy" type="optional" units="kcal/gmol" min="0.0" max="1.0E3">
139  50.3
140  <\float>
141  <\parentNode>
142  @endverbatim
143  *
144  * @param node reference to the XML_Node object of the parent XML element
145  * @param titleString String name of the title attribute
146  * @param value Value - single integer
147  * @param unitsString String name of the Units attribute. The default is to
148  * have an empty string.
149  * @param typeString String type. This is an optional parameter. The default
150  * is to have an empty string.
151  * @param minval Minimum allowed value of the float. The default is the
152  * special double, Cantera::Undef, which means to ignore the
153  * entry.
154  * @param maxval Maximum allowed value of the float. The default is the
155  * special double, Cantera::Undef, which means to ignore the
156  * entry.
157  *
158  * @todo I don't think this is used. Figure out what is used for writing floats,
159  * and codify that. minval and maxval should be codified.
160  * typeString should be codified as to its usage.
161  */
162 void addFloat(Cantera::XML_Node& node, const std::string& titleString,
163  const doublereal value, const std::string unitsString="",
164  const std::string typeString="", const doublereal minval = Cantera::Undef,
165  const doublereal maxval = Cantera::Undef);
166 
167 //! This function adds a child node with the name, "intArray", with a value
168 //! consisting of a comma separated list of integers
169 /*!
170  * This function will add a child node to the current XML node, with the
171  * name "intArray". It will have a title attribute, and the body
172  * of the XML node will be filled out with a comma separated list of
173  * integers
174  *
175  * Example:
176  *
177  * Code snippet:
178  * @verbatim
179  const XML_Node &node;
180  std::string titleString = "additionalCases";
181  int n = 3;
182  int cases[3] = [3, 6, 10];
183  std::string typeString = "optional";
184  std::string units = "";
185  addIntegerArray(node, titleString, n, &cases[0], typeString, units);
186  @endverbatim
187  *
188  * Creates the following the snippet in the XML file:
189  * @verbatim
190  <parentNode>
191  <intArray title="additionalCases" type="optional">
192  3, 6, 10
193  <\intArray>
194  <\parentNode>
195  @endverbatim
196  *
197  * @param node reference to the XML_Node object of the parent XML element
198  * @param titleString String name of the title attribute
199  * @param n Length of the integer vector.
200  * @param values Pointer to a vector of integers
201  * @param unitsString String name of the Units attribute. This is an optional
202  * parameter. The default is to
203  * have an empty string.
204  * @param typeString String type. This is an optional parameter. The default
205  * is to have an empty string.
206  * @param minval Minimum allowed value of the int. This is an optional
207  * parameter. The default is the
208  * special double, Cantera::Undef, which means to ignore the
209  * entry.
210  * @param maxval Maximum allowed value of the int. This is an optional
211  * parameter. The default is the
212  * special double, Cantera::Undef, which means to ignore the
213  * entry.
214  *
215  * @todo unitsString shouldn't be here, since it's an int. typeString should
216  * be codified as to its usage.
217  *
218  * @deprecated Not currently used.
219  */
220 DEPRECATED(void addIntegerArray(Cantera::XML_Node& node, const std::string& titleString,
221  const size_t n, const int* const values,
222  const std::string unitsString="", const std::string typeString="",
223  const doublereal minval=Cantera::Undef,
224  const doublereal maxval=Cantera::Undef));
225 
226 //! This function adds a child node with the name, "floatArray", with a value
227 //! consisting of a comma separated list of floats
228 /*!
229  * This function will add a child node to the current XML node, with the
230  * name "floatArray". It will have a title attribute, and the body
231  * of the XML node will be filled out with a comma separated list of
232  * doublereals.
233  *
234  * Example:
235  *
236  * Code snippet:
237  * @verbatim
238  const XML_Node &node;
239  std::string titleString = "additionalTemperatures";
240  int n = 3;
241  int Tcases[3] = [273.15, 298.15, 373.15];
242  std::string typeString = "optional";
243  std::string units = "Kelvin";
244  addFloatArray(node, titleString, n, &cases[0], typeString, units);
245  @endverbatim
246  *
247  * Creates the following the snippet in the XML file:
248  * @verbatim
249  <parentNode>
250  <floatArray title="additionalTemperatures" type="optional" units="Kelvin">
251  273.15, 298.15, 373.15
252  <\floatArray>
253  <\parentNode>
254  @endverbatim
255  *
256  * @param node reference to the XML_Node object of the parent XML element
257  * @param titleString String name of the title attribute
258  * @param n Length of the doubles vector.
259  * @param values Pointer to a vector of doubles
260  * @param unitsString String name of the Units attribute. This is an optional
261  * parameter. The default is to
262  * have an empty string.
263  * @param typeString String type. This is an optional parameter. The default
264  * is to have an empty string.
265  * @param minval Minimum allowed value of the int. This is an optional
266  * parameter. The default is the
267  * special double, Cantera::Undef, which means to ignore the
268  * entry.
269  * @param maxval Maximum allowed value of the int. This is an optional
270  * parameter. The default is the
271  * special double, Cantera::Undef, which means to ignore the
272  * entry.
273  *
274  * @todo I don't think this is used. Figure out what is used for writing integers,
275  * and codify that. unitsString shouldn't be here, since it's an int.
276  * typeString should be codified as to its usage.
277  */
278 void addFloatArray(Cantera::XML_Node& node, const std::string& titleString,
279  const size_t n, const doublereal* const values,
280  const std::string unitsString="", const std::string typeString="",
281  const doublereal minval = Cantera::Undef,
282  const doublereal maxval = Cantera::Undef);
283 
284 void addNamedFloatArray(Cantera::XML_Node& parentNode, const std::string& name, const int n,
285  const doublereal* const vals, const std::string units = "",
286  const std::string type = "",
287  const doublereal minval = Cantera::Undef,
288  const doublereal maxval = Cantera::Undef);
289 
290 
291 
292 
293 //! This function adds a child node with the name string with a string value
294 //! to the current node
295 /*!
296  * This function will add a child node to the current XML node, with the
297  * name "string". It will have a title attribute, and the body
298  * of the XML node will be filled out with the valueString argument verbatim.
299  *
300  * Example:
301  *
302  * Code snippet:
303  * @verbatim
304  const XML_Node &node;
305  addString(XML_Node& node, std::string titleString, std::string valueString,
306  std::string typeString);
307  @endverbatim
308  *
309  * Creates the following the snippet in the XML file:
310  * @verbatim
311  <string title="titleString" type="typeString">
312  valueString
313  <\string>
314  @endverbatim
315  *
316  * @param node reference to the XML_Node object of the parent XML element
317  * @param valueString Value string to be used in the new XML node.
318  * @param titleString String name of the title attribute
319  * @param typeString String type. This is an optional parameter.
320  */
321 void addString(Cantera::XML_Node& node, const std::string& titleString,
322  const std::string& valueString, const std::string typeString="");
323 
324 
325 //! This function reads the current node or a child node of the current node
326 //! with the default name, "floatArray", with a value field
327 //! consisting of a comma separated list of floats
328 /*!
329  * This function will read either the current XML node or a child node
330  * to the current XML node, with the
331  * name "floatArray". It will have a title attribute, and the body
332  * of the XML node will be filled out with a comma separated list of
333  * doublereals.
334  * Get an array of floats from the XML Node. The argument field
335  * is assumed to consist of an arbitrary number of comma
336  * separated floats, with an arbitrary amount of white space
337  * separating each field.
338  * If the node array has an units attribute field, then
339  * the units are used to convert the floats, iff convert is true.
340  *
341  * Example:
342  *
343  * Code snippet:
344  * @verbatim
345  const XML_Node &State_XMLNode;
346  vector_fp v;
347  bool convert = true;
348  unitsString = "";
349  nodeName="floatArray";
350  getFloatArray(State_XMLNode, v, convert, unitsString, nodeName);
351  @endverbatim
352  *
353  * reads the corresponding XML file:
354  *
355  * @verbatim
356  <state>
357  <floatArray units="m3"> 32.4, 1, 100. <\floatArray>
358  <\state>
359  @endverbatim
360  *
361  * Will produce the vector
362  *
363  * v[0] = 32.4
364  * v[1] = 1.0
365  * v[2] = 100.
366  *
367  *
368  * @param node XML parent node of the floatArray
369  * @param v Output vector of floats containing the floatArray information.
370  * @param convert Conversion to SI is carried out if this boolean is
371  * True. The default is true.
372  * @param unitsString String name of the type attribute. This is an optional
373  * parameter. The default is to have an empty string.
374  * The only string that is recognized is actEnergy.
375  * Anything else has no effect. This affects what
376  * units converter is used.
377  * @param nodeName XML Name of the XML node to read.
378  * The default value for the node name is floatArray
379  * @return Returns the number of floats read into v.
380  */
381 size_t getFloatArray(const Cantera::XML_Node& node, std::vector<doublereal> & v,
382  const bool convert=true, const std::string unitsString="",
383  const std::string nodeName = "floatArray");
384 
385 //! This function interprets the value portion of an XML element
386 //! as a string. It then separates the string up into tokens
387 //! according to the location of white space.
388 /*!
389  * The separate tokens are returned in the string vector
390  *
391  * @param node Node to get the value from
392  * @param v Output vector containing the string tokens
393  */
394 void getStringArray(const Cantera::XML_Node& node, std::vector<std::string>& v);
395 
396 
397 //! This routine is used to interpret the value portions of XML
398 //! elements that contain colon separated pairs.
399 /*!
400  * These are used, for example, in describing the element
401  * composition of species.
402  * @verbatim
403  <atomArray> H:4 C:1 <atomArray>
404  @endverbatim
405  * The string is first separated into a string vector according
406  * to the location of white space. Then each string is again
407  * separated into two parts according to the location of a
408  * colon in the string. The first part of the string is
409  * used as the key, while the second part of the string is
410  * used as the value, in the return map.
411  * It is an error to not find a colon in each string pair.
412  *
413  * @param node Current node
414  * @param m Output Map containing the pairs of values found
415  * in the XML Node
416  */
417 void getMap(const Cantera::XML_Node& node, std::map<std::string, std::string>& m);
418 
419 //! This function interprets the value portion of an XML element
420 //! as a series of "Pairs" separated by white space.
421 /*!
422  * Each pair consists of nonwhite-space characters.
423  * The first ":" found in the pair string is used to separate
424  * the string into two parts. The first part is called the "key"
425  * The second part is called the "val".
426  * String vectors of key[i] and val[i] are returned in the
427  * argument list.
428  * Warning: No spaces are allowed in each pair. Quotes get included as part
429  * of the string.
430  * Example:
431  * @verbatim
432  <xmlNode>
433  red:112 blue:34
434  green:banana
435  </xmlNode>
436  @endverbatim
437  *
438  * Returns:
439  * key val
440  * 0: "red" "112"
441  * 1: "blue" "34"
442  * 2: "green" "banana"
443  *
444  *
445  * @param node XML Node
446  * @param key Vector of keys for each entry
447  * @param val Vector of values for each entry
448  *
449  * @return Returns the number of pairs found
450  */
451 int getPairs(const Cantera::XML_Node& node, std::vector<std::string>& key,
452  std::vector<std::string>& val);
453 
454 //! This function interprets the value portion of an XML element
455 //! as a series of "Matrix ids and entries" separated by white space.
456 /*!
457  * Each pair consists of nonwhite-space characters.
458  * The first two ":" found in the pair string is used to separate
459  * the string into three parts. The first part is called the first
460  * key. The second part is the second key. Both parts must match
461  * an entry in the keyString1 and keyString2, respectively,
462  * in order to provide a location to
463  * place the object in the matrix.
464  * The third part is called the value. It is expected to be
465  * a double. It is translated into a double and placed into the
466  * correct location in the matrix.
467  *
468  * Warning: No spaces are allowed in each triplet. Quotes are part
469  * of the string.
470  * Example
471  * keyString = red, blue, black, green
472  *
473  * @verbatim
474  <xmlNode>
475  red:green:112
476  blue:black:3.3E-23
477 
478  </xmlNode>
479  @endverbatim
480  * Returns:
481  * retnValues(0, 3) = 112
482  * retnValues(1, 2) = 3.3E-23
483  *
484  *
485  * @param node XML Node containing the information for the matrix
486  * @param keyStringRow Key string for the row
487  * @param keyStringCol Key string for the column entries
488  * @param returnValues Return Matrix.
489  * @param convert If this is true, and if the node has a units
490  * attribute, then conversion to si units is carried
491  * out. Default is true.
492  * @param matrixSymmetric If true entries are made so that the matrix
493  * is always symmetric. Default is false.
494  */
495 void getMatrixValues(const Cantera::XML_Node& node,
496  const std::vector<std::string>& keyStringRow,
497  const std::vector<std::string>& keyStringCol,
498  Cantera::Array2D& returnValues, const bool convert = true,
499  const bool matrixSymmetric = false);
500 
501 
502 //! Get a vector of integer values from a child element.
503 /*!
504  * Returns a std::map containing a keyed values for child XML_Nodes
505  * of the current node with the name, "integer".
506  * In the keyed mapping there will be a list of titles vs. values
507  * for all of the XML nodes.
508  * The integer XML_nodes are expected to be in a particular form created
509  * by the function addInteger(). One value per XML_node is expected.
510  *
511  *
512  * Example:
513  *
514  * Code snippet:
515  * @verbatim
516  const XML_Node &State_XMLNode;
517  std::map<std::string, integer> v;
518  getinteger(State_XMLNode, v);
519  @endverbatim
520  *
521  * reads the corresponding XML file:
522  *
523  * @verbatim
524  <state>
525  <integer title="i1"> 1 <\integer>
526  <integer title="i2"> 2 <\integer>
527  <integer title="i3"> 3 <\integer>
528  <\state>
529  @endverbatim
530  *
531  * Will produce the mapping:
532  *
533  * v["i1"] = 1
534  * v["i2"] = 2
535  * v["i3"] = 3
536  *
537  *
538  * @param node Current XML node to get the values from
539  * @param v Output map of the results.
540  */
541 void getIntegers(const Cantera::XML_Node& node, std::map<std::string,int>& v);
542 
543 
544 //! Get a floating-point value from a child element.
545 /*!
546  * Returns a doublereal value for the child named 'name' of element 'parent'. If
547  * 'type' is supplied and matches a known unit type, unit
548  * conversion to SI will be done if the child element has an attribute
549  * 'units'.
550  *
551  * Note, it's an error for the child element not to exist.
552  *
553  * Example:
554  *
555  * Code snippet:
556  * @verbatim
557  const XML_Node &State_XMLNode;
558  doublereal pres = OneAtm;
559  if (state_XMLNode.hasChild("pressure")) {
560  pres = getFloat(State_XMLNode, "pressure", "toSI");
561  }
562  @endverbatim
563  *
564  * reads the corresponding XML file:
565  * @verbatim
566  <state>
567  <pressure units="Pa"> 101325.0 </pressure>
568  <\state>
569  @endverbatim
570  *
571  * @param parent reference to the XML_Node object of the parent XML element
572  * @param name Name of the XML child element
573  * @param type String type. Currently known types are "toSI" and "actEnergy",
574  * and "" , for no conversion. The default value is "",
575  * which implies that no conversion is allowed.
576  */
577 doublereal getFloat(const Cantera::XML_Node& parent, const std::string& name,
578  const std::string type="");
579 
580 //! Get a floating-point value from the current XML element
581 /*!
582  * Returns a doublereal value from the current element. If
583  * 'type' is supplied and matches a known unit type, unit
584  * conversion to SI will be done if the child element has an attribute 'units'.
585  *
586  * Note, it's an error for the child element not to exist.
587  *
588  * Example:
589  *
590  * Code snippet:
591  * @verbatim
592  const XML_Node &State_XMLNode;
593  doublereal pres = OneAtm;
594  if (state_XMLNode.hasChild("pressure")) {
595  XML_Node *pres_XMLNode = State_XMLNode.getChild("pressure");
596  pres = getFloatCurrent(pres_XMLNode, "toSI");
597  }
598  @endverbatim
599  *
600  * Reads the corresponding XML file:
601  * @verbatim
602  <state>
603  <pressure units="Pa"> 101325.0 </pressure>
604  <\state>
605  @endverbatim
606  *
607  * @param currXML reference to the current XML_Node object
608  * @param type String type. Currently known types are "toSI" and "actEnergy",
609  * and "" , for no conversion. The default value is "",
610  * which implies that no conversion is allowed.
611  */
612 doublereal getFloatCurrent(const Cantera::XML_Node& currXML, const std::string type="");
613 
614 //! Get an optional floating-point value from a child element.
615 /*!
616  * Returns a doublereal value for the child named 'name' of element 'parent'. If
617  * 'type' is supplied and matches a known unit type, unit
618  * conversion to SI will be done if the child element has an attribute
619  * 'units'.
620  *
621  *
622  *
623  * Example:
624  *
625  * Code snippet:
626  * @verbatim
627  const XML_Node &State_XMLNode;
628  doublereal pres = OneAtm;
629  bool exists = getOptionalFloat(State_XMLNode, "pressure", pres, "toSI");
630  @endverbatim
631  *
632  * reads the corresponding XML file:
633  * @verbatim
634  <state>
635  <pressure units="Pa"> 101325.0 </pressure>
636  <\state>
637  @endverbatim
638  *
639  * @param parent reference to the XML_Node object of the parent XML element
640  * @param name Name of the XML child element
641  * @param fltRtn Float Return. It will be overridden if the XML
642  * element exists.
643  * @param type String type. Currently known types are "toSI"
644  * and "actEnergy",
645  * and "" , for no conversion. The default value is "",
646  * which implies that no conversion is allowed.
647  *
648  * @return returns true if the child element named "name" exists
649  */
650 bool getOptionalFloat(const Cantera::XML_Node& parent, const std::string& name,
651  doublereal& fltRtn, const std::string type="");
652 
653 
654 //! Get a vector of floating-point values from a child element.
655 /*!
656  * Returns a std::map containing a keyed values for child XML_Nodes
657  * of the current node with the name, "float".
658  * In the keyed mapping there will be a list of titles vs. values
659  * for all of the XML nodes.
660  * The float XML_nodes are expected to be in a particular form created
661  * by the function addFloat(). One value per XML_node is expected.
662  *
663  *
664  * Example:
665  *
666  * Code snippet:
667  * @verbatim
668  const XML_Node &State_XMLNode;
669  std::map<std::string,double> v;
670  bool convert = true;
671  getFloats(State_XMLNode, v, convert);
672  @endverbatim
673  *
674  * reads the corresponding XML file:
675  *
676  * @verbatim
677  <state>
678  <float title="a1" units="m3"> 32.4 <\float>
679  <float title="a2" units="cm3"> 1. <\float>
680  <float title="a3"> 100. <\float>
681  <\state>
682  @endverbatim
683  *
684  * Will produce the mapping:
685  *
686  * v["a1"] = 32.4
687  * v["a2"] = 1.0E-6
688  * v["a3"] = 100.
689  *
690  *
691  * @param node Current XML node to get the values from
692  * @param v Output map of the results.
693  * @param convert Turn on conversion to SI units
694  */
695 void getFloats(const Cantera::XML_Node& node, std::map<std::string, double>& v,
696  const bool convert=true);
697 
698 //! Get an integer value from a child element.
699 /*!
700  * Returns an integer value for the child named 'name' of element 'parent'.
701  *
702  * Note, it's an error for the child element not to exist.
703  *
704  * Example:
705  *
706  * Code snippet:
707  * @verbatim
708  const XML_Node &State_XMLNode;
709  int number = 1;
710  if (state_XMLNode.hasChild("NumProcs")) {
711  number = getInteger(State_XMLNode, "numProcs");
712  }
713  @endverbatim
714  *
715  * reads the corresponding XML file:
716  * @verbatim
717  <state>
718  <numProcs> 10 <numProcs/>
719  <\state>
720  @endverbatim
721  *
722  * @param parent reference to the XML_Node object of the parent XML element
723  * @param name Name of the XML child element
724  */
725 int getInteger(const Cantera::XML_Node& parent, std::string name);
726 
727 //! Get a floating-point value from a child element with a defined units field
728 /*!
729  * Returns a doublereal value for the child named 'name' of element 'parent'.
730  * 'type' must be supplied and match a known unit type.
731  *
732  * Note, it's an error for the child element not to exist.
733  *
734  * Example:
735  *
736  * Code snippet:
737  * @verbatim
738  const XML_Node &State_XMLNode;
739  doublereal pres = OneAtm;
740  if (state_XMLNode.hasChild("pressure")) {
741  pres = getFloatDefaultUnits(State_XMLNode, "pressure", "Pa", "toSI");
742  }
743  @endverbatim
744  *
745  * reads the corresponding XML file:
746  * @verbatim
747  <state>
748  <pressure units="Pa"> 101325.0 </pressure>
749  <\state>
750  @endverbatim
751  *
752  * @param parent reference to the XML_Node object of the parent XML element
753  * @param name Name of the XML child element
754  * @param defaultUnits Default units string to be found in the units attribute.
755  * If the units string in the XML field is equal to defaultUnits,
756  * no units conversion will be carried out.
757  * @param type String type. Currently known types are "toSI" and "actEnergy",
758  * and "" , for no conversion. The default value is "",
759  * which implies that no conversion is allowed.
760  */
761 doublereal getFloatDefaultUnits(const Cantera::XML_Node& parent, std::string name,
762  std::string defaultUnits, std::string type="toSI");
763 
764 //! Get an optional model name from a named child node.
765 /*!
766  * Returns the model name attribute for the child named 'nodeName' of element 'parent'.
767  * Note, it's optional for the child node to exist
768  *
769  * Example:
770  *
771  * Code snippet:
772  * @verbatim
773  std::string modelName = "";
774  bool exists = getOptionalModel(transportNode, "compositionDependence",
775  modelName);
776  @endverbatim
777  *
778  * reads the corresponding XML file:
779  * @verbatim
780  <transport model="Simple">
781  <compositionDependence model="Solvent_Only"/>
782  </transport>
783  @endverbatim
784  *
785  * On return modelName is set to "Solvent_Only".
786  *
787  * @param parent reference to the XML_Node object of the parent XML element
788  * @param nodeName Name of the XML child element
789  * @param modelName On return this contains the contents of the model attribute
790  *
791  * @return True if the nodeName XML node exists. False otherwise.
792  */
793 bool getOptionalModel(const Cantera::XML_Node& parent, const std::string nodeName,
794  std::string& modelName);
795 
796 //! This function reads a child node with the default name, "floatArray", with a value
797 //! consisting of a comma separated list of floats
798 /*!
799  * This function will read a child node to the current XML node, with the
800  * name "floatArray". It will have a title attribute, and the body
801  * of the XML node will be filled out with a comma separated list of
802  * doublereals.
803  * Get an array of floats from the XML Node. The argument field
804  * is assumed to consist of an arbitrary number of comma
805  * separated floats, with an arbitrary amount of white space
806  * separating each field.
807  * If the node array has an units attribute field, then
808  * the units are used to convert the floats, iff convert is true.
809  * This function is a wrapper around the function getFloatArray().
810  *
811  * Example:
812  *
813  * Code snippet:
814  * @verbatim
815  const XML_Node &State_XMLNode;
816  vector_fp v;
817  bool convert = true;
818  unitsString = "";
819  nodeName="floatArray";
820  getFloatArray(State_XMLNode, v, convert, unitsString, nodeName);
821  @endverbatim
822  *
823  * reads the corresponding XML file:
824  *
825  * @verbatim
826  <state>
827  <floatArray units="m3"> 32.4, 1, 100. <\floatArray>
828  <\state>
829  @endverbatim
830  *
831  * Will produce the vector
832  *
833  * v[0] = 32.4
834  * v[1] = 1.0
835  * v[2] = 100.
836  *
837  *
838  * @param node XML parent node of the floatArray
839  * @param typeString Returns the type attribute of the current node.
840  * @param xmin Returns the minimum value attribute of the
841  * current node.
842  * @param xmax Returns the maximum value attribute of the
843  * current node.
844  * @param coeffs Output vector of floats containing the floatArray information.
845  */
846 void getFunction(const Cantera::XML_Node& node, std::string& typeString,
847  doublereal& xmin, doublereal& xmax, std::vector<doublereal> & coeffs);
848 
849 //! Search the child nodes of the current node for an XML Node with a Title
850 //! attribute of a given name.
851 /*!
852  * @param node Current node from which to conduct the search
853  * @param title Name of the title attribute
854  *
855  * @return Returns a pointer to the matched child node. Returns 0 if no node is
856  * found.
857  */
858 Cantera::XML_Node* getByTitle(const Cantera::XML_Node& node, const std::string& title);
859 
860 //! This function reads a child node with the name string with a specific
861 //! title attribute named titleString
862 /*!
863  * This function will read a child node to the current XML node with the name "string".
864  * It must have a title attribute, named titleString, and the body
865  * of the XML node will be read into the valueString output argument.
866  *
867  * If the child node is not found then the empty string is returned.
868  *
869  * Example:
870  *
871  * Code snippet:
872  * @verbatim
873  const XML_Node &node;
874  getString(XML_Node& node, std::string titleString, std::string valueString,
875  std::string typeString);
876  @endverbatim
877  *
878  * Reads the following the snippet in the XML file:
879  * @verbatim
880  <string title="titleString" type="typeString">
881  valueString
882  <\string>
883  @endverbatim
884  *
885  * @param node Reference to the XML_Node object of the parent XML element
886  * @param titleString String name of the title attribute of the child node
887  * @param valueString Value string that is found in the child node. output variable
888  * @param typeString String type. This is an optional output variable. It is filled
889  * with the attribute "type" of the XML entry.
890  */
891 void getString(const Cantera::XML_Node& node, const std::string& titleString,
892  std::string& valueString, std::string& typeString);
893 
894 //! This function attempts to read a named child node and returns with the contents in the value string.
895 //! title attribute named "titleString"
896 /*!
897  * This function will read a child node to the current XML node, with the
898  * name "string". It must have a title attribute, named titleString, and the body
899  * of the XML node will be read into the valueString output argument.
900  *
901  * If the child node is not found then the empty string is returned.
902  *
903  * Example:
904  *
905  * Code snippet:
906  * @verbatim
907  const XML_Node &node;
908  std::string valueString;
909  std::string typeString;
910  std::string nameString = "timeIncrement";
911  getString(XML_Node& node, nameString, valueString, valueString, typeString);
912  @endverbatim
913  *
914  * Reads the following the snippet in the XML file:
915  *
916  * * @verbatim
917  <nameString type="typeString">
918  valueString
919  <\nameString>
920  @endverbatim
921  *
922  * or alternatively as a retrofit and special case, it also reads the following case
923  *
924  * @verbatim
925  <string title="nameString" type="typeString">
926  valueString
927  <\string>
928  @endverbatim
929  *
930  * @param node Reference to the XML_Node object of the parent XML element
931  * @param nameString Name of the XML Node input variable
932  * @param valueString Value string that is found in the child node. output variable
933  * @param typeString String type. This is an optional output variable. It is filled
934  * with the attribute "type" of the XML entry. output variable
935  */
936 void getNamedStringValue(const Cantera::XML_Node& node, const std::string& nameString, std::string& valueString,
937  std::string& typeString);
938 
939 
940 //! This function reads a child node with the name, nameString, and returns
941 //! its xml value as the return string
942 /*!
943  * If the child XML_node named "name" doesn't exist, the empty string is returned.
944  *
945  * Code snippet:
946  * @verbatim
947  const XML_Node &parent;
948  string nameString = "vacency_species";
949  string valueString = getChildValue(parent, nameString
950  std::string typeString);
951  @endverbatim
952  *
953  * returns valueString = "O(V)"
954  *
955  * from the following the snippet in the XML file:
956  *
957  * @verbatim
958  <vacencySpecies>
959  O(V)
960  <\vancencySpecies>
961  @endverbatim
962  *
963  * @param parent parent reference to the XML_Node object of the parent XML element
964  * @param nameString Name of the child XML_Node to read the value from.
965  *
966  * @return String value of the child XML_Node
967  */
968 std::string getChildValue(const Cantera::XML_Node& parent,
969  const std::string& nameString);
970 
971 //! Read an ctml file from a file and fill up an XML tree
972 /*!
973  * This is the main routine that reads a ctml file and puts it into
974  * an XML_Node tree
975  *
976  * @param node Root of the tree
977  * @param file Name of the file
978  * @param debug Turn on debugging printing
979  */
980 void get_CTML_Tree(Cantera::XML_Node* node, const std::string file,
981  const int debug = 0);
982 
983 //! Convert a cti file into a ctml file
984 /*!
985  *
986  * @param file Pointer to the file
987  * @param debug Turn on debug printing
988  *
989  * @ingroup inputfiles
990  */
991 void ct2ctml(const char* file, const int debug = 0);
992 }
993 
994 #endif