Verified Commit 5f5fd569 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

add onlymodel command line option

parent beb99d98
Pipeline #286 passed with stage
in 1 minute and 18 seconds
......@@ -47,7 +47,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
LanguageOutputType lang, int params_derivs_order, bool transform_unary_ops,
JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
bool nopreprocessoroutput, const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot);
const boost::filesystem::path &dynareroot, bool onlymodel);
void main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file,
bool no_line_macro, bool no_empty_line_macro, map<string, string> &defines, vector<string> &path, stringstream &macro_output);
......@@ -60,7 +60,7 @@ usage()
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=julia]"
<< " [params_derivs_order=0|1|2] [transform_unary_ops]"
<< " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]"
<< " [mexext=<extension>] [matlabroot=<path>]"
<< " [mexext=<extension>] [matlabroot=<path>] [onlymodel]"
<< endl;
exit(EXIT_FAILURE);
}
......@@ -122,6 +122,7 @@ main(int argc, char **argv)
boost::filesystem::path dynareroot{argv[0]};
dynareroot = dynareroot.parent_path();
dynareroot = dynareroot / ".." / "..";
bool onlymodel = false;
// Parse options
for (int arg = 2; arg < argc; arg++)
......@@ -344,6 +345,8 @@ main(int argc, char **argv)
}
matlabroot = boost::filesystem::path{s.substr(11)};
}
else if (s == "onlymodel")
onlymodel = true;
else
{
cerr << "Unknown option: " << s << endl;
......@@ -414,7 +417,7 @@ main(int argc, char **argv)
parallel, config_file, warnings, nostrict, stochastic, check_model_changes, minimal_workspace,
compute_xrefs, output_mode, language, params_derivs_order, transform_unary_ops,
json, json_output_mode, onlyjson, jsonderivsimple, nopreprocessoroutput,
mexext, matlabroot, dynareroot);
mexext, matlabroot, dynareroot, onlymodel);
return EXIT_SUCCESS;
}
......@@ -35,7 +35,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
LanguageOutputType language, int params_derivs_order, bool transform_unary_ops,
JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
bool nopreprocessoroutput, const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot)
const boost::filesystem::path &dynareroot, bool onlymodel)
{
ParsingDriver p(warnings, nostrict);
......@@ -70,7 +70,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear
else
mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph,
nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs,
nopreprocessoroutput, mexext, matlabroot, dynareroot);
nopreprocessoroutput, mexext, matlabroot, dynareroot, onlymodel);
if (!nopreprocessoroutput)
cout << "Preprocessing completed." << endl;
......
......@@ -28,6 +28,7 @@
#include "ModFile.hh"
#include "ConfigFile.hh"
#include "ComputingTasks.hh"
#include "Shocks.hh"
ModFile::ModFile(WarningConsolidation &warnings_arg)
: var_model_table{symbol_table},
......@@ -792,7 +793,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const bool nopreprocessoroutput, const string &mexext,
const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot) const
const boost::filesystem::path &dynareroot, bool onlymodel) const
{
bool hasModelChanged = !dynamic_model.isChecksumMatching(basename, block);
if (!check_model_changes)
......@@ -865,7 +866,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
<< "%" << endl
<< "% Some global variables initialization" << endl
<< "%" << endl;
config_file.writeHooks(mOutputFile);
if (!onlymodel)
config_file.writeHooks(mOutputFile);
mOutputFile << "global_initialization;" << endl
<< "diary off;" << endl;
if (!no_log)
......@@ -946,7 +948,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
mOutputFile << ";" << endl
<< "M_.hessian_eq_zero = isempty(M_.nonzero_hessian_eqs);" << endl;
config_file.writeCluster(mOutputFile);
if (!onlymodel)
config_file.writeCluster(mOutputFile);
if (byte_code)
mOutputFile << "if exist('bytecode') ~= 3" << endl
......@@ -967,57 +970,71 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
static_model.writeOutput(mOutputFile, block);
}
for (auto &statement : statements)
{
statement->writeOutput(mOutputFile, basename, minimal_workspace);
if (onlymodel)
for (auto &statement : statements)
{
auto *ips = dynamic_cast<InitParamStatement *>(statement.get());
if (ips != nullptr)
ips->writeOutput(mOutputFile, basename, minimal_workspace);
/* Special treatment for initval block: insert initial values for the
auxiliary variables and initialize exo det */
auto ivs = dynamic_cast<InitValStatement *>(statement.get());
if (ivs != nullptr)
auto *ss = dynamic_cast<ShocksStatement *>(statement.get());
if (ss != nullptr)
ss->writeOutput(mOutputFile, basename, minimal_workspace);
}
else
{
for (auto &statement : statements)
{
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
ivs->writeOutputPostInit(mOutputFile);
}
statement->writeOutput(mOutputFile, basename, minimal_workspace);
// Special treatment for endval block: insert initial values for the auxiliary variables
auto evs = dynamic_cast<EndValStatement *>(statement.get());
if (evs != nullptr)
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
/* Special treatment for initval block: insert initial values for the
auxiliary variables and initialize exo det */
auto ivs = dynamic_cast<InitValStatement *>(statement.get());
if (ivs != nullptr)
{
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
ivs->writeOutputPostInit(mOutputFile);
}
// Special treatment for load params and steady state statement: insert initial values for the auxiliary variables
auto lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(statement.get());
if (lpass && !no_static)
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
}
// Special treatment for endval block: insert initial values for the auxiliary variables
auto evs = dynamic_cast<EndValStatement *>(statement.get());
if (evs != nullptr)
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl
<< "if exist('estim_params_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'estim_params_', '-append');" << endl << "end" << endl
<< "if exist('bayestopt_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'bayestopt_', '-append');" << endl << "end" << endl
<< "if exist('dataset_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'dataset_', '-append');" << endl << "end" << endl
<< "if exist('estimation_info', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'estimation_info', '-append');" << endl << "end" << endl
<< "if exist('dataset_info', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'dataset_info', '-append');" << endl << "end" << endl
<< "if exist('oo_recursive_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'oo_recursive_', '-append');" << endl << "end" << endl;
config_file.writeEndParallel(mOutputFile);
mOutputFile << endl << endl
<< "disp(['Total computing time : ' dynsec2hms(toc(tic0)) ]);" << endl;
if (!no_warn)
{
if (warnings.countWarnings() > 0)
mOutputFile << "disp('Note: " << warnings.countWarnings() << " warning(s) encountered in the preprocessor')" << endl;
// Special treatment for load params and steady state statement: insert initial values for the auxiliary variables
auto lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(statement.get());
if (lpass && !no_static)
static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel);
}
mOutputFile << "if ~isempty(lastwarn)" << endl
<< " disp('Note: warning(s) encountered in MATLAB/Octave code')" << endl
<< "end" << endl;
mOutputFile << "save('" << basename << "_results.mat', 'oo_', 'M_', 'options_');" << endl
<< "if exist('estim_params_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'estim_params_', '-append');" << endl << "end" << endl
<< "if exist('bayestopt_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'bayestopt_', '-append');" << endl << "end" << endl
<< "if exist('dataset_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'dataset_', '-append');" << endl << "end" << endl
<< "if exist('estimation_info', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'estimation_info', '-append');" << endl << "end" << endl
<< "if exist('dataset_info', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'dataset_info', '-append');" << endl << "end" << endl
<< "if exist('oo_recursive_', 'var') == 1" << endl
<< " save('" << basename << "_results.mat', 'oo_recursive_', '-append');" << endl << "end" << endl;
config_file.writeEndParallel(mOutputFile);
mOutputFile << endl << endl
<< "disp(['Total computing time : ' dynsec2hms(toc(tic0)) ]);" << endl;
if (!no_warn)
{
if (warnings.countWarnings() > 0)
mOutputFile << "disp('Note: " << warnings.countWarnings() << " warning(s) encountered in the preprocessor')" << endl;
mOutputFile << "if ~isempty(lastwarn)" << endl
<< " disp('Note: warning(s) encountered in MATLAB/Octave code')" << endl
<< "end" << endl;
}
}
if (!no_log)
......
......@@ -163,7 +163,8 @@ public:
void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn,
bool console, bool nograph, bool nointeractive, const ConfigFile &config_file,
bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const bool nopreprocessoroutput, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot) const;
const bool nopreprocessoroutput, const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot, bool onlymodel) const;
void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language, const bool nopreprocessoroutput) const;
void writeExternalFilesJulia(const string &basename, FileOutputType output, const bool nopreprocessoroutput) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment