void PDSS_IonsFromNeutral::constructPDSSFile(VPStandardStateTP* tp, size_t spindex, const std::string& inputFile, const std::string& id) { warn_deprecated("PDSS_IonsFromNeutral::constructPDSSFile", "To be removed after Cantera 2.3."); if (inputFile.size() == 0) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile", "input file is null"); } std::string path = findInputFile(inputFile); ifstream fin(path); if (!fin) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile","could not open " +path+" for reading."); } // The phase object automatically constructs an XML object. Use this object // to store information. XML_Node fxml; fxml.build(fin); XML_Node* fxml_phase = findXMLPhase(&fxml, id); if (!fxml_phase) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile", "ERROR: Can not find phase named " + id + " in file named " + inputFile); } XML_Node& speciesList = fxml_phase->child("speciesArray"); XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"], &fxml_phase->root()); const XML_Node* s = speciesDB->findByAttr("name", tp->speciesName(spindex)); constructPDSSXML(tp, spindex, *s, *fxml_phase, id); }
void PDSS_IdealGas::constructPDSSFile(VPStandardStateTP *tp, int spindex, std::string inputFile, std::string id) { if (inputFile.size() == 0) { throw CanteraError("PDSS_IdealGas::constructPDSSFile", "input file is null"); } std::string path = findInputFile(inputFile); ifstream fin(path.c_str()); if (!fin) { throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open " +path+" for reading."); } /* * The phase object automatically constructs an XML object. * Use this object to store information. */ XML_Node *fxml = new XML_Node(); fxml->build(fin); XML_Node *fxml_phase = findXMLPhase(fxml, id); if (!fxml_phase) { throw CanteraError("PDSS_IdealGas::constructPDSSFile", "ERROR: Can not find phase named " + id + " in file named " + inputFile); } constructPDSSXML(tp, spindex, *fxml_phase, id); delete fxml; }
void PDSS_IdealGas::constructPDSSFile(VPStandardStateTP* tp, size_t spindex, const std::string& inputFile, const std::string& id) { warn_deprecated("PDSS_IdealGas::constructPDSSFile", "To be removed after Cantera 2.3."); if (inputFile.size() == 0) { throw CanteraError("PDSS_IdealGas::constructPDSSFile", "input file is null"); } std::string path = findInputFile(inputFile); ifstream fin(path); if (!fin) { throw CanteraError("PDSS_IdealGas::constructPDSSFile","could not open " +path+" for reading."); } /* * The phase object automatically constructs an XML object. * Use this object to store information. */ XML_Node fxml; fxml.build(fin); XML_Node* fxml_phase = findXMLPhase(&fxml, id); if (!fxml_phase) { throw CanteraError("PDSS_IdealGas::constructPDSSFile", "ERROR: Can not find phase named " + id + " in file named " + inputFile); } constructPDSSXML(tp, spindex, *fxml_phase, id); }
/* * Import, construct, and initialize a phase * specification from an XML tree into the current object. * * This routine is a precursor to constructPhaseXML(XML_Node*) * routine, which does most of the work. * * @param infile XML file containing the description of the * phase * * @param id Optional parameter identifying the name of the * phase. If none is given, the first XML * phase element will be used. */ void MargulesVPSSTP::constructPhaseFile(std::string inputFile, std::string id) { if (inputFile.size() == 0) { throw CanteraError("MargulesVPSSTP:constructPhaseFile", "input file is null"); } string path = findInputFile(inputFile); std::ifstream fin(path.c_str()); if (!fin) { throw CanteraError("MargulesVPSSTP:constructPhaseFile","could not open " +path+" for reading."); } /* * The phase object automatically constructs an XML object. * Use this object to store information. */ XML_Node &phaseNode_XML = xml(); XML_Node *fxml = new XML_Node(); fxml->build(fin); XML_Node *fxml_phase = findXMLPhase(fxml, id); if (!fxml_phase) { throw CanteraError("MargulesVPSSTP:constructPhaseFile", "ERROR: Can not find phase named " + id + " in file named " + inputFile); } fxml_phase->copy(&phaseNode_XML); constructPhaseXML(*fxml_phase, id); delete fxml; }
/* * This is the main routine that reads a ctml file and puts it into * an XML_Node tree * * @param node Root of the tree * @param file Name of the file * @param debug Turn on debugging printing */ void get_CTML_Tree(Cantera::XML_Node* rootPtr, const std::string file, const int debug) { std::string ff, ext = ""; // find the input file on the Cantera search path std::string inname = findInputFile(file); #ifdef DEBUG_PATHS writelog("Found file: "+inname+"\n"); #endif if (debug > 0) writelog("Found file: "+inname+"\n"); 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") { try { ctml::ct2ctml(inname.c_str(), debug); } catch (...) { writelog("get_CTML_Tree: caught something \n");; } string ffull = inname.substr(0,idot) + ".xml"; ff = "./" + getBaseName(ffull) + ".xml"; #ifdef DEBUG_PATHS writelogf("ffull name = %s\n", ffull.c_str()); writelogf("ff name = %s\n", ff.c_str()); #endif } else { ff = inname; } #ifdef DEBUG_PATHS writelog("Attempting to parse xml file " + ff + "\n"); #else if (debug > 0) writelog("Attempting to parse xml file " + ff + "\n"); #endif ifstream fin(ff.c_str()); if (!fin) { throw CanteraError("get_CTML_Tree", "XML file " + ff + " not found"); } rootPtr->build(fin); fin.close(); }
XML_Node* Application::get_XML_File(const std::string& file, int debug) { std::unique_lock<std::mutex> xmlLock(xml_mutex); std::string path = ""; path = findInputFile(file); int mtime = get_modified_time(path); if (xmlfiles.find(path) != xmlfiles.end()) { // Already have a parsed XML tree for this file cached. Check the // last-modified time. std::pair<XML_Node*, int> cache = xmlfiles[path]; if (cache.second == mtime) { return cache.first; } } /* * Check whether or not the file is XML (based on the file extension). If * not, it will be first processed with the preprocessor. */ string::size_type idot = path.rfind('.'); string ext; if (idot != string::npos) { ext = path.substr(idot, path.size()); } else { ext = ""; } XML_Node* x = new XML_Node("doc"); if (ext != ".xml" && ext != ".ctml") { // Assume that we are trying to open a cti file. Do the conversion to XML. std::stringstream phase_xml(ct2ctml_string(path)); x->build(phase_xml); } else { std::ifstream s(path.c_str()); if (s) { x->build(s); } else { throw CanteraError("get_XML_File", "cannot open "+file+" for reading.\n" "Note, this error indicates a possible configuration problem."); } } x->lock(); xmlfiles[path] = {x, mtime}; return x; }
/* * * This routine is a precursor to constructPDSSXML(XML_Node*) * routine, which does most of the work. * * @param vptp_ptr Pointer to the Variable pressure %ThermoPhase object * This object must have already been malloced. * * @param spindex Species index within the phase * * @param inputFile XML file containing the description of the * phase * * @param id Optional parameter identifying the name of the * phase. If none is given, the first XML * phase element will be used. */ void PDSS_IonsFromNeutral::constructPDSSFile(VPStandardStateTP* tp, size_t spindex, const std::string& inputFile, const std::string& id) { if (inputFile.size() == 0) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile", "input file is null"); } std::string path = findInputFile(inputFile); ifstream fin(path.c_str()); if (!fin) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile","could not open " +path+" for reading."); } /* * The phase object automatically constructs an XML object. * Use this object to store information. */ XML_Node* fxml = new XML_Node(); fxml->build(fin); XML_Node* fxml_phase = findXMLPhase(fxml, id); if (!fxml_phase) { throw CanteraError("PDSS_IonsFromNeutral::constructPDSSFile", "ERROR: Can not find phase named " + id + " in file named " + inputFile); } XML_Node& speciesList = fxml_phase->child("speciesArray"); XML_Node* speciesDB = get_XML_NameID("speciesData", speciesList["datasrc"], &(fxml_phase->root())); const vector<string>&sss = tp->speciesNames(); const XML_Node* s = speciesDB->findByAttr("name", sss[spindex]); constructPDSSXML(tp, spindex, *s, *fxml_phase, id); delete fxml; }