13 #include "../../ext/libexecstream/exec-stream.h"
21 using namespace Cantera;
46 const char* py = getenv(
"PYTHON_CMD");
49 string sp =
stripws(
string(py));
65 void ct2ctml(
const char* file,
const int debug)
74 "python cti to ctml conversion requested for file, " + ppath +
75 ", but not available in this computational environment");
82 python.set_wait_timeout(exec_stream_t::s_all, 1800000);
83 python.start(
pypath(),
"-i");
84 stringstream output_stream;
88 " sys.stderr = sys.stdout\n" <<
89 " import ctml_writer\n" <<
90 " ctml_writer.convert(r'" << file <<
"')\n" <<
95 while (python.out().good()) {
96 std::getline(python.out(), line);
97 output_stream << line << std::endl;;
100 python_exit_code = python.exit_code();
101 python_output =
stripws(output_stream.str());
102 }
catch (std::exception& err) {
104 stringstream message;
105 message <<
"Error executing python while converting input file:\n";
106 message <<
"Python command was: '" <<
pypath() <<
"'\n";
107 message << err.what() << std::endl;
111 if (python_exit_code != 0) {
113 stringstream message;
114 message <<
"Error converting input file \"" << file <<
"\" to CTML.\n";
115 message <<
"Python command was: '" <<
pypath() <<
"'\n";
116 message <<
"The exit code was: " << python_exit_code <<
"\n";
117 if (python_output.size() > 0) {
118 message <<
"-------------- start of converter log --------------\n";
119 message << python_output << std::endl;
120 message <<
"--------------- end of converter log ---------------";
122 message <<
"The command did not produce any output." << endl;
127 if (python_output.size() > 0) {
129 stringstream message;
130 message <<
"Warning: Unexpected output from CTI converter\n";
131 message <<
"-------------- start of converter log --------------\n";
132 message << python_output << std::endl;
133 message <<
"--------------- end of converter log ---------------\n";
150 std::string ff, ext =
"";
155 writelog(
"Found file: "+inname+
"\n");
159 throw CanteraError(
"get_CTML_Tree",
"file "+file+
" not found");
166 std::string::size_type idot = inname.rfind(
'.');
168 ext = inname.substr(idot, inname.size());
170 if (ext !=
".xml" && ext !=
".ctml") {
173 }
catch (std::exception& err) {
174 writelog(
"get_CTML_Tree: caught an exception:\n");
177 string ffull = inname.substr(0,idot) +
".xml";
180 writelogf(
"ffull name = %s\n", ffull.c_str());
187 writelog(
"Attempting to parse xml file " + ff +
"\n");
189 ifstream fin(ff.c_str());
193 "XML file " + ff +
" not found");