From 5f5fd569dd3127df457e8f17cb6c010c7fc52e30 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 7 Nov 2018 15:24:57 +0100 Subject: [PATCH] add onlymodel command line option --- src/DynareMain.cc | 9 ++-- src/DynareMain2.cc | 4 +- src/ModFile.cc | 109 ++++++++++++++++++++++++++------------------- src/ModFile.hh | 3 +- 4 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/DynareMain.cc b/src/DynareMain.cc index 03c8e7c0..39290f34 100644 --- a/src/DynareMain.cc +++ b/src/DynareMain.cc @@ -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 &defines, vector &path, stringstream ¯o_output); @@ -60,7 +60,7 @@ usage() << " [-D[=]] [-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=] [matlabroot=]" + << " [mexext=] [matlabroot=] [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; } diff --git a/src/DynareMain2.cc b/src/DynareMain2.cc index 3d7b6dc6..3f8d1179 100644 --- a/src/DynareMain2.cc +++ b/src/DynareMain2.cc @@ -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; diff --git a/src/ModFile.cc b/src/ModFile.cc index 9881d863..ac14a8ee 100644 --- a/src/ModFile.cc +++ b/src/ModFile.cc @@ -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(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(statement.get()); - if (ivs != nullptr) + auto *ss = dynamic_cast(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 initval block: insert initial values for the + auxiliary variables and initialize exo det */ + auto ivs = dynamic_cast(statement.get()); + if (ivs != nullptr) + { + static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel); + ivs->writeOutputPostInit(mOutputFile); + } + + // Special treatment for endval block: insert initial values for the auxiliary variables + auto evs = dynamic_cast(statement.get()); + if (evs != nullptr) + static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel); + + // Special treatment for load params and steady state statement: insert initial values for the auxiliary variables + auto lpass = dynamic_cast(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(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; - // Special treatment for load params and steady state statement: insert initial values for the auxiliary variables - auto lpass = dynamic_cast(statement.get()); - if (lpass && !no_static) - static_model.writeAuxVarInitval(mOutputFile, ExprNodeOutputType::matlabOutsideModel); - } + config_file.writeEndParallel(mOutputFile); - 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; + mOutputFile << endl << endl + << "disp(['Total computing time : ' dynsec2hms(toc(tic0)) ]);" << endl; - config_file.writeEndParallel(mOutputFile); + if (!no_warn) + { + if (warnings.countWarnings() > 0) + mOutputFile << "disp('Note: " << warnings.countWarnings() << " warning(s) encountered in the preprocessor')" << endl; - 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; + mOutputFile << "if ~isempty(lastwarn)" << endl + << " disp('Note: warning(s) encountered in MATLAB/Octave code')" << endl + << "end" << endl; + } } if (!no_log) diff --git a/src/ModFile.hh b/src/ModFile.hh index 22a27a4c..5f0f68c3 100644 --- a/src/ModFile.hh +++ b/src/ModFile.hh @@ -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;