Cantera  2.0
ck2cti.cpp
Go to the documentation of this file.
1 /**
2  * @file ck2cti.cpp
3  *
4  * Program to convert Chemkin-II-format reaction mechanism files to
5  * Cantera input format. The resulting Cantera input file contains a
6  * definition of one ideal_gas entry that represents an ideal gas
7  * mixture corresponding to the Chemkin-II reaction mechanism. The
8  * file also contains Cantera-format definitions for each species and
9  * each reaction in the input reaction mechanism file.
10  *
11  * Usage: ck2cti -i input -t thermo -tr transport -id idtag
12  *
13  * The Cantera-format text is written to the standard output.
14  *
15  * @param input Chemkin-II reaction mechanism file to be converted. Required.
16  *
17  * @param thermo Thermodynamic property database. If the THERMO section of the
18  * input file is missing or does not have entries for one or more species,
19  * this file will be searched for the required thermo data. This file may
20  * be another reaction mechanism file containing a THERMO section, or
21  * a Chemkin-II-compatible thermodynamic database file.
22  *
23  * @param transport Transport property database. If this file name is supplied,
24  * transport property parameters will be taken from this file and
25  * included in the output Cantera-format file. If this parameter is omitted,
26  * no transport property parameters will be included in the output.
27  *
28  * @param id idtag. The ideal_gas entry in the Cantera-format output
29  * has name \i idtag. If this parameter is omitted, it will be set to the
30  * input file name without the extension. Since only one phase definition
31  * is present in the ck2cti output, this parameter is not required.
32  */
33 #include <iostream>
34 #include <string>
35 using namespace std;
36 
37 #include "cantera/base/ct_defs.h"
38 #include "cantera/base/global.h"
39 #include "converters/ck2ct.h"
40 
41 using namespace Cantera;
42 
43 int showHelp()
44 {
45  cout << "\nck2cti: convert a CK-format reaction mechanism file to Cantera input format.\n"
46  << "\n D. G. Goodwin, Caltech \n"
47  << " Version 1.0, August 2003.\n\n"
48  << endl;
49  cout << "options:" << endl;
50  cout << " -i <input file> \n"
51  << " -t <thermo database> \n"
52  << " -tr <transport database> \n"
53  << " -id <identifier> \n"
54  << " -d print debugging output \n\n"
55  << " -v validate the input file \n\n"
56  << "The results are written to the standard output.\n";
57  return 0;
58 }
59 
60 string getp(int& i, int argc, char** args)
61 {
62  string a="--";
63  if (i < argc-1) {
64  a = string(args[i+1]);
65  }
66  if (a[0] == '-') {
67  a = "<missing>";
68  } else {
69  i += 1;
70  }
71  return a;
72 }
73 
74 
75 int main(int argc, char** argv)
76 {
77 #ifdef _MSC_VER
78  _set_output_format(_TWO_DIGIT_EXPONENT);
79 #endif
80  string infile="chem.inp", dbfile="", trfile="", logfile;
81  string idtag = "gas";
82  bool debug = false;
83  bool validate = false;
84  int i=1;
85  if (argc == 1) {
86  return showHelp();
87  }
88 
89  while (i < argc) {
90  string arg = string(argv[i]);
91  if (arg == "-i") {
92  infile = getp(i,argc,argv);
93  } else if (arg == "-t") {
94  dbfile = getp(i,argc,argv);
95  } else if (arg == "-tr") {
96  trfile = getp(i,argc,argv);
97  } else if (arg == "-id") {
98  idtag = getp(i,argc,argv);
99  } else if (arg == "-d") {
100  debug = true;
101  cout << "### DEBUG MODE ###" << endl;
102  } else if (arg == "-v") {
103  validate = true;
104  cout << "### VALIDATION ENABLED ###" << endl;
105  } else if (arg == "-h" || argc < 3) {
106  return showHelp();
107  } else {
108  cout << "unknown option:" << arg << endl;
109  exit(-1);
110  }
111  ++i;
112  }
113 
114  int ierr = pip::convert_ck(infile.c_str(), dbfile.c_str(), trfile.c_str(),
115  idtag.c_str(), debug, validate);
116 
117  if (ierr < 0) {
118  showErrors(std::cerr);
119  }
120  return ierr;
121 }