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