diff --git a/include/cantera/base/ctml.h b/include/cantera/base/ctml.h index 043f945f6..1a5becdca 100644 --- a/include/cantera/base/ctml.h +++ b/include/cantera/base/ctml.h @@ -756,6 +756,7 @@ std::string getChildValue(const Cantera::XML_Node& parent, * @param node Root of the tree * @param file Name of the file * @param debug Turn on debugging printing + * @deprecated To be removed after Cantera 2.2. Use get_XML_File() instead. */ void get_CTML_Tree(Cantera::XML_Node* node, const std::string& file, const int debug = 0); @@ -763,6 +764,7 @@ void get_CTML_Tree(Cantera::XML_Node* node, const std::string& file, //! Read an ctml file from a file and fill up an XML tree. //! @param file Name of the file //! @return Root of the tree +//! @deprecated To be removed after Cantera 2.2. Use get_XML_File() instead. Cantera::XML_Node getCtmlTree(const std::string& file); //! Convert a cti file into a ctml file diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 085728649..42c5990b1 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -13,13 +13,11 @@ cdef extern from "cantera/base/xml.h" namespace "Cantera": XML_Node* findID(string) int nChildren() -cdef extern from "cantera/base/ctml.h" namespace "ctml": - XML_Node getCtmlTree(string) except + - cdef extern from "cantera/base/global.h" namespace "Cantera": cdef void CxxAddDirectory "Cantera::addDirectory" (string) cdef size_t CxxNpos "Cantera::npos" cdef void CxxAppdelete "Cantera::appdelete" () + cdef XML_Node* CxxGetXmlFile "Cantera::get_XML_File" (string) except + cdef extern from "cantera/thermo/mix_defs.h": cdef int thermo_type_ideal_gas "Cantera::cIdealGas" diff --git a/interfaces/cython/cantera/base.pyx b/interfaces/cython/cantera/base.pyx index 0ff62fea1..608394fd7 100644 --- a/interfaces/cython/cantera/base.pyx +++ b/interfaces/cython/cantera/base.pyx @@ -18,7 +18,7 @@ cdef class _SolutionBase: return # Instantiate a set of new Cantera C++ objects - rootNode = getCtmlTree(stringify(infile)) + rootNode = CxxGetXmlFile(stringify(infile)) # Get XML data cdef XML_Node* phaseNode diff --git a/src/base/ct2ctml.cpp b/src/base/ct2ctml.cpp index 55fe1c77f..02f69a224 100644 --- a/src/base/ct2ctml.cpp +++ b/src/base/ct2ctml.cpp @@ -262,46 +262,19 @@ void ck2cti(const std::string& in_file, const std::string& thermo_file, void get_CTML_Tree(Cantera::XML_Node* rootPtr, const std::string& file, const int debug) { - std::string ext = ""; - - // find the input file on the Cantera search path - std::string inname = findInputFile(file); - writelog("Found file: "+inname+"\n", debug); - - if (inname == "") { - throw CanteraError("get_CTML_Tree", "file "+file+" not found"); - } - - /* - * Check whether or not the file is XML. If not, it will be first - * processed with the preprocessor. - */ - std::string::size_type idot = inname.rfind('.'); - if (idot != string::npos) { - ext = inname.substr(idot, inname.size()); - } - if (ext != ".xml" && ext != ".ctml") { - string phase_xml = ctml::ct2ctml_string(inname); - stringstream s(phase_xml); - rootPtr->build(s); - return; - } - - writelog("Attempting to parse xml file " + inname + "\n", debug); - ifstream fin(inname.c_str()); - if (!fin) { - throw - CanteraError("get_CTML_Tree", - "XML file " + inname + " not found"); - } - rootPtr->build(fin); - fin.close(); + warn_deprecated("get_CTML_Tree", "To be removed after Cantera 2.2. " + "Use get_XML_File instead."); + XML_Node* src = get_XML_File(file); + src->copy(rootPtr); } Cantera::XML_Node getCtmlTree(const std::string& file) { - Cantera::XML_Node root; - get_CTML_Tree(&root, file); + warn_deprecated("getCtmlTree", "To be removed after Cantera 2.2. " + "Use get_XML_File instead."); + XML_Node root; + XML_Node* src = get_XML_File(file); + src->copy(&root); return root; } diff --git a/src/clib/ctxml.cpp b/src/clib/ctxml.cpp index 6d18704f0..b10c4828f 100644 --- a/src/clib/ctxml.cpp +++ b/src/clib/ctxml.cpp @@ -115,7 +115,7 @@ extern "C" { int xml_preprocess_and_build(int i, const char* file, int debug) { try { - get_CTML_Tree(&XmlCabinet::item(i), file, debug); + XmlCabinet::item(i) = *get_XML_File(file); return 0; } catch (...) { return handleAllExceptions(-1, ERR); diff --git a/test_problems/diamondSurf/runDiamond.cpp b/test_problems/diamondSurf/runDiamond.cpp index cfe4b6cab..1019df89a 100644 --- a/test_problems/diamondSurf/runDiamond.cpp +++ b/test_problems/diamondSurf/runDiamond.cpp @@ -38,9 +38,7 @@ int main(int argc, char** argv) int i, k; try { - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); + XML_Node* xc = get_XML_File(infile); XML_Node* const xg = xc->findNameID("phase", "gas"); ThermoPhase* gasTP = newPhase(*xg); diff --git a/test_problems/diamondSurf_dupl/runDiamondDupl.cpp b/test_problems/diamondSurf_dupl/runDiamondDupl.cpp index 5c32fc3f2..5bb0c6309 100644 --- a/test_problems/diamondSurf_dupl/runDiamondDupl.cpp +++ b/test_problems/diamondSurf_dupl/runDiamondDupl.cpp @@ -30,9 +30,7 @@ int main(int argc, char** argv) string infile = "diamond.xml"; try { - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); + XML_Node* xc = get_XML_File(infile); cout.precision(3); XML_Node* const xg = xc->findNameID("phase", "gas"); diff --git a/test_problems/fracCoeff/fracCoeff.cpp b/test_problems/fracCoeff/fracCoeff.cpp index 18e3af716..7edcf8c66 100644 --- a/test_problems/fracCoeff/fracCoeff.cpp +++ b/test_problems/fracCoeff/fracCoeff.cpp @@ -34,9 +34,7 @@ int main(int argc, char** argv) double cdot[10], ddot[10]; //double fwd_rop[10]; try { - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); + XML_Node* xc = get_XML_File(infile); XML_Node* const xg = xc->findNameID("phase", "gas"); ThermoPhase* gasTP = newPhase(*xg); @@ -150,7 +148,6 @@ int main(int argc, char** argv) delete iKin_ptr; iKin_ptr = 0; delete gasTP; - delete xc; appdelete(); diff --git a/test_problems/negATest/negATest.cpp b/test_problems/negATest/negATest.cpp index 2f06696bd..b7708c96a 100644 --- a/test_problems/negATest/negATest.cpp +++ b/test_problems/negATest/negATest.cpp @@ -22,10 +22,7 @@ int main(int argc, char** argv) double x[20]; double cdot[20], ddot[20]; - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); - + XML_Node* xc = get_XML_File(infile); XML_Node* const xg = xc->findNameID("phase", "air"); ThermoPhase* gasTP = newPhase(*xg); size_t nsp = gasTP->nSpecies(); diff --git a/test_problems/stoichSolidKinetics/stoichSolidKinetics.cpp b/test_problems/stoichSolidKinetics/stoichSolidKinetics.cpp index af077985a..3520b365e 100644 --- a/test_problems/stoichSolidKinetics/stoichSolidKinetics.cpp +++ b/test_problems/stoichSolidKinetics/stoichSolidKinetics.cpp @@ -43,9 +43,8 @@ void printRates(InterfaceKinetics& iKin) void testProblem() { ss << std::scientific << std::setprecision(3) << std::uppercase; - XML_Node xc; - ctml::get_CTML_Tree(&xc, "ReactionSurf.xml"); - XML_Node* xg = xc.findNameID("phase", "reaction_surface"); + XML_Node* xc = get_XML_File("ReactionSurf.xml"); + XML_Node* xg = xc->findNameID("phase", "reaction_surface"); if (!xg) { throw CanteraError("couldn't find file", ""); } diff --git a/test_problems/surfSolverTest/surfaceSolver.cpp b/test_problems/surfSolverTest/surfaceSolver.cpp index df1ddc005..3c7865f6b 100644 --- a/test_problems/surfSolverTest/surfaceSolver.cpp +++ b/test_problems/surfSolverTest/surfaceSolver.cpp @@ -217,9 +217,7 @@ int main(int argc, char** argv) } /************************************************************/ - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); + XML_Node* xc = get_XML_File(infile); XML_Node* const xg = (XML_Node*) findXMLPhase(xc, gasPhaseName); if (!xg) { @@ -436,7 +434,6 @@ int main(int argc, char** argv) bulkPhaseTP = 0; delete surfPhaseTP; surfPhaseTP = 0; - delete xc; appdelete(); } catch (CanteraError& err) { std::cout << err.what() << std::endl; diff --git a/test_problems/surfSolverTest/surfaceSolver2.cpp b/test_problems/surfSolverTest/surfaceSolver2.cpp index e44e034d6..69aeee185 100644 --- a/test_problems/surfSolverTest/surfaceSolver2.cpp +++ b/test_problems/surfSolverTest/surfaceSolver2.cpp @@ -219,10 +219,7 @@ int main(int argc, char** argv) } /************************************************************/ - XML_Node* xc = new XML_Node(); - string path = findInputFile(infile); - ctml::get_CTML_Tree(xc, path); - + XML_Node* xc = get_XML_File(infile); XML_Node* const xg = (XML_Node*) findXMLPhase(xc, gasPhaseName); if (!xg) { printf("ERROR: Could not find gas phase named, %s, in file\n", @@ -479,7 +476,6 @@ int main(int argc, char** argv) surfPhaseTP = 0; delete surfPhaseTP2; surfPhaseTP2 = 0; - delete xc; appdelete(); } catch (CanteraError& err) { std::cout << err.what() << std::endl;