Cantera  2.0
CKParser.h
Go to the documentation of this file.
1 /**
2  * @file CKParser.h
3  *
4  */
5 
6 // Copyright 2001 California Institute of Technology
7 
8 #ifndef CKR_CKPARSER_H
9 #define CKR_CKPARSER_H
10 
11 #include <fstream>
12 #include <string>
13 #include <iostream>
14 
15 #include "ckr_defs.h"
16 #include "Element.h"
17 #include "Species.h"
18 #include "Reaction.h"
19 
20 namespace ckr
21 {
22 
23 
24 // typedefs
25 
26 /// readability constants
27 //@{
28 const int NoThermoDatabase = 10;
29 const int HasTempRange = 11;
30 //@}
31 
32 
33 /// Exception class for syntax errors.
34 class CK_SyntaxError : public CK_Exception
35 {
36 public:
37  CK_SyntaxError(std::ostream& f, const std::string& s, int linenum = -1);
38  std::ostream& m_out;
39 };
40 
41 /**
42  * Chemkin mechanism file parser. For internal use by class CKReader.
43  */
44 class CKParser
45 {
46 
47 public:
48 
49  CKParser(std::string ckfile, std::ostream* log);
50  CKParser(std::istream* infile, const std::string& fname,
51  std::ostream* log);
52 
53  /// Destructor.
54  ~CKParser() {}
55 
56  bool readElementSection(elementList& elements);
57  bool readSpeciesSection(speciesList& species);
58  bool readThermoSection(std::vector<std::string>& names,
59  speciesTable& speciesData, vector_fp& temp,
60  int& optionFlag, std::ostream& log);
61  bool readReactionSection(const std::vector<std::string>& speciesNames,
62  std::vector<std::string>& elementNames,
63  reactionList& reactions, ReactionUnits& units);
64  bool advanceToKeyword(const std::string& kw, const std::string& stop);
65  bool verbose;
66  bool debug;
67 
68  bool readNASA9ThermoSection(std::vector<std::string>& names,
69  speciesTable& species, vector_fp& temp,
70  int& optionFlag, std::ostream& log);
71 
73 
74 private:
75 
76  //! Local value of the line number being read
77  /*!
78  * This is used for debug IO printout purposes
79  */
80  int m_line;
81 
82  std::string m_buf;
83  std::string m_comment;
84 
85  //! This is the input file that is read
86  /*!
87  * It's an istream
88  */
89  std::istream* m_ckfile;
90 
91  std::string m_ckfilename;
92 
93  //! Pointer to the ostream for writing debugging output log info
94  std::ostream* m_log;
95 
96  bool m_nasafmt;
97 
98  //! Boolean indicating new NASA input file format
99  /*!
100  * If this is true, a completely different input file parser is
101  * used.
102  */
104 
105  char m_last_eol;
106  void readThermoRecord(Species& sp);
107 
108  //! Get a line from the input file, and return it in string s.
109  /*!
110  * If the line contains a comment character (!), then return only the
111  * portion preceding it. Non-printing characters are replaced by
112  * spaces.
113  *
114  * The input file is m_ckfile, an istream.
115  *
116  * @param s On return, s contains the line read from the
117  * input file.
118  * @param comment On return, comment contains the text following the
119  * comment character on the line, if any.
120  */
121  void getCKLine(std::string& s, std::string& comment);
122 
123  void putCKLine(std::string& s, std::string& comment);
124  void missingAuxData(const std::string& kw);
125 
126  void checkSpeciesName(std::string spname);
127 };
128 }
129 
130 
131 #endif