3 #include <QDirIterator> 5 #include <QProcessEnvironment> 9 invar_names_ = invar_names;
11 outvar_names_ = outvar_names;
12 outvars_.set_size(outvar_names.n_elem);
14 invar_names_.save(
"interprocess/invar_names.tmp");
15 invars_.save(
"interprocess/invars.tmp");
16 outvar_names_.save(
"interprocess/outvar_names.tmp");
21 DeleteTemporaryFiles();
32 QStringList env_vars = QProcess::systemEnvironment();
33 env_vars <<
"R_HOME="+R_HOME;
34 R_process.setEnvironment(env_vars);
35 std::ofstream cmd_stream(
"interprocess/commands.tmp");
40 args <<
"interprocess/invar_names.tmp" 41 <<
"interprocess/invars.tmp" 42 <<
"interprocess/outvar_names.tmp" 43 <<
"interprocess/outvars.tmp" 44 <<
"interprocess/commands.tmp";
46 R_process.start(
"VespucciR", args);
47 R_process.waitForFinished(-1);
48 return R_process.exitCode();
53 QProcess Octave_process;
54 QStringList env_vars = QProcess::systemEnvironment();
55 Octave_process.setEnvironment(env_vars);
56 std::ofstream cmd_stream(
"interprocess/commands_tmp.m");
58 cmd_stream <<
"function ";
59 if (outvar_names_.n_elem){
61 for (arma::uword i = 0; i < outvar_names_.n_elem - 1; ++i){
62 cmd_stream << outvar_names_(i) <<
",";
64 cmd_stream << outvar_names_(outvar_names_.n_elem - 1) <<
"] = ";
66 cmd_stream <<
"VespucciOctave(";
67 for (arma::uword i = 0; i < invar_names_.n_elem - 1; ++i){
68 cmd_stream << invar_names_(i) <<
",";
70 cmd_stream << invar_names_(invar_names_.n_elem - 1) <<
")" << std::endl;
72 cmd_stream << script << std::endl <<
"endfunction";
76 args <<
"interprocess/invar_names.tmp" 77 <<
"interprocess/invars.tmp" 78 <<
"interprocess/outvar_names.tmp" 79 <<
"interprocess/outvars.tmp" 80 <<
"interprocess/commands_tmp.m";
82 Octave_process.start(
"VespucciOctave", args);
83 Octave_process.waitForFinished(-1);
84 return Octave_process.exitCode();
92 void Vespucci::External::FileInterprocess::GetOutvars()
94 outvars_.load(
"interprocess/outvars.tmp");
97 void Vespucci::External::FileInterprocess::DeleteTemporaryFiles()
99 QDir dir(
"interprocess");
100 QDirIterator it(
"interprocess", QDirIterator::NoIteratorFlags);
102 if (it.fileInfo().suffix() ==
"tmp" || it.fileInfo().suffix() ==
"m"){
103 dir.remove(it.filePath());
arma::field< arma::mat > outvars()
int RunOctave(const std::string &script)
FileInterprocess(const arma::field< std::string > invar_names, const arma::field< arma::mat > invars, const arma::field< std::string > outvar_names)
int RunR(const std::string &script, const QString &R_HOME)