From 8a58b126981044e4ee4bab60a0a2a777a2dbdc46 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 12 Sep 2013 16:04:04 +0000 Subject: [PATCH] [ck2cti] Fix to work with Cython module when called from Matlab or C++ --- src/base/ct2ctml.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/base/ct2ctml.cpp b/src/base/ct2ctml.cpp index 5f73ccaf4..0a4e2c074 100644 --- a/src/base/ct2ctml.cpp +++ b/src/base/ct2ctml.cpp @@ -150,11 +150,14 @@ void ck2cti(const std::string& in_file, const std::string& thermo_file, stringstream output_stream; ostream& pyin = python.in(); - pyin << "if True:\n"; // Use this so that the rest is a single block - pyin << " import sys\n"; - pyin << " sys.stderr = sys.stdout\n"; - pyin << " import ck2cti\n"; - pyin << " ck2cti.Parser().convertMech(r'" << in_file << "',"; + pyin << "if True:\n" << // Use this so that the rest is a single block + " import sys\n" << + " sys.stderr = sys.stdout\n" << + " try:\n" << + " from cantera import ck2cti\n" << // Cython module + " except ImportError:\n" << + " import ck2cti\n" << // legacy Python module + " ck2cti.Parser().convertMech(r'" << in_file << "',"; if (thermo_file != "" && thermo_file != "-") { pyin << " thermoFile=r'" << thermo_file << "',"; }