*** empty log message ***
This commit is contained in:
parent
25f4dac3cb
commit
0e5c5bcf7b
2 changed files with 122 additions and 26 deletions
|
|
@ -1,26 +0,0 @@
|
|||
#include "ct_defs.h"
|
||||
#include <ofstream>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Cantera {
|
||||
void ct2ctml(char* file) {
|
||||
ofstream f(".cttmp.py");
|
||||
f << "from Cantera import *\n"
|
||||
<< "from Cantera.ctml_writer import *\n"
|
||||
<< "import sys, os, os.path\n"
|
||||
<< "file = " << file << endl
|
||||
<< "base = os.path.basename(file)\n"
|
||||
<< "root, ext = os.path.splitext(base)\n"
|
||||
<< "dataset(root)\n"
|
||||
<< "execfile(file)\n"
|
||||
<< "write()\n";
|
||||
f.close();
|
||||
string PY_CMD = getenv("PYTHON_CMD");
|
||||
if (!PY_CMD) PY_CMD = "python";
|
||||
int ierr = system(PY_CMD+" .cttmp.py");
|
||||
if (ierr != 0)
|
||||
throw CanteraError("ct2ctml", "could not convert input file to CTML.");
|
||||
}
|
||||
|
||||
}
|
||||
122
Cantera/src/ct2ctml.cpp
Normal file
122
Cantera/src/ct2ctml.cpp
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
#include "ct_defs.h"
|
||||
#include "ctexceptions.h"
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include "ctml.h"
|
||||
#include "../../include/pypath.h"
|
||||
|
||||
using namespace Cantera;
|
||||
|
||||
namespace ctml {
|
||||
|
||||
static string pypath() {
|
||||
string s = "python";
|
||||
#ifdef PYTHON_EXE
|
||||
s = string(PYTHON_EXE);
|
||||
return s;
|
||||
#else
|
||||
const char* py = getenv("PYTHON_CMD");
|
||||
if (py) s = string(py);
|
||||
return s;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool checkPython() {
|
||||
string path = tmpDir() + "/check.py";
|
||||
ofstream f(path.c_str());
|
||||
if (!f) {
|
||||
throw CanteraError("checkPython","cannot write to "+tmpDir());
|
||||
}
|
||||
f << "from Cantera import *\n";
|
||||
f.close();
|
||||
string cmd = pypath() + " " + path + " &> " + tmpDir() + "/log";
|
||||
int ierr = system(cmd.c_str());
|
||||
if (ierr != 0) {
|
||||
string msg;
|
||||
msg = cmd + "\n\n########################################################################\n\n"
|
||||
"The Cantera Python interface is required in order to process\n"
|
||||
"Cantera input files, but it does not seem to be correctly installed.\n\n"
|
||||
"Check that you can invoke the Python interpreter with \n"
|
||||
"the command \"python\", and that typing \"from Cantera import *\"\n"
|
||||
"at the Python prompt does not produce an error. If Python on your system\n"
|
||||
"is invoked with some other command, set environment variable PYTHON_CMD\n"
|
||||
"to the full path to the Python interpreter. \n\n"
|
||||
"#########################################################################\n\n";
|
||||
writelog(msg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ct2ctml(const char* file) {
|
||||
string path = tmpDir()+"/.cttmp.py";
|
||||
ofstream f(path.c_str());
|
||||
if (!f) {
|
||||
throw CanteraError("ct2ctml","cannot write to "+tmpDir());
|
||||
}
|
||||
f << "from Cantera import *\n"
|
||||
<< "from Cantera.ctml_writer import *\n"
|
||||
<< "import sys, os, os.path\n"
|
||||
<< "file = \"" << file << "\"\n"
|
||||
<< "base = os.path.basename(file)\n"
|
||||
<< "root, ext = os.path.splitext(base)\n"
|
||||
<< "dataset(root)\n"
|
||||
<< "execfile(file)\n"
|
||||
<< "write()\n";
|
||||
f.close();
|
||||
string cmd = pypath() + " " + path + " &> ct2ctml.log";
|
||||
int ierr = system(cmd.c_str());
|
||||
if (ierr != 0) {
|
||||
string msg = cmd;
|
||||
ifstream ferr("ct2ctml.log");
|
||||
if (ferr) {
|
||||
char line[80];
|
||||
while (!ferr.eof()) {
|
||||
//msg += "\n";
|
||||
ferr.getline(line, 80);
|
||||
writelog(string(line)+"\n");
|
||||
}
|
||||
ferr.close();
|
||||
}
|
||||
bool pyok = checkPython();
|
||||
if (!pyok)
|
||||
msg += "\nError in Python installation.";
|
||||
else
|
||||
msg += "\nCheck error messages above for syntax errors.";
|
||||
throw CanteraError("ct2ctml", "could not convert input file to CTML\n command line was: "+msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an CTML tree from a file, possibly preprocessing the file
|
||||
* first.
|
||||
*/
|
||||
void get_CTML_Tree(XML_Node* rootPtr, string file) {
|
||||
string ff;
|
||||
|
||||
// find the input file on the Cantera search path
|
||||
string inname = findInputFile(file);
|
||||
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.
|
||||
*/
|
||||
int idot = file.find('.');
|
||||
string ext = file.substr(idot,file.size());
|
||||
if (ext != ".xml" && ext != ".ctml") {
|
||||
ct2ctml(file.c_str());
|
||||
ff = file.substr(0,idot)+".xml";
|
||||
}
|
||||
else
|
||||
ff = file;
|
||||
|
||||
ifstream fin(ff.c_str());
|
||||
rootPtr->build(fin);
|
||||
fin.close();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue