diff --git a/doc/dynare.texi b/doc/dynare.texi index ce9d47b1c..c70abc7d0 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -730,6 +730,14 @@ By default, @code{dynare} will issue a @code{clear all} command to MATLAB or Octave, thereby deleting all workspace variables; this options instructs @code{dynare} not to clear the workspace +@item onlyclearglobals +By default, @code{dynare} will issue a @code{clear all} command to +MATLAB or Octave, thereby deleting all workspace variables; this +option instructs @code{dynare} to clear only the global variables +(@i{i.e.} @code{M_}, @code{options_}, @code{oo_}, +@code{estim_params_}, @code{bayestopt_}, and @code{dataset_}), leaving +the other variables in the workspace. + @item debug Instructs the preprocessor to write some debugging information about the scanning and parsing of the @file{.mod} file diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 7fed1e785..19d773b8b 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -35,7 +35,8 @@ Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be included simultaneously (because of Bison limitations). */ -void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, +void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, + bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType lang #if defined(_WIN32) || defined(__CYGWIN32__) @@ -46,7 +47,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool void usage() { - cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" + cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] " << " [-D[=]] [nostrict] [output=dynamic|first|second|third] [language=C|C++]" #if defined(_WIN32) || defined(__CYGWIN32__) @@ -73,6 +74,7 @@ main(int argc, char **argv) } bool clear_all = true; + bool clear_global = false; bool save_macro = false; string save_macro_file; bool debug = false; @@ -106,6 +108,11 @@ main(int argc, char **argv) debug = true; else if (!strcmp(argv[arg], "noclearall")) clear_all = false; + else if (!strcmp(argv[arg], "onlyclearglobals")) + { + clear_all = false; + clear_global = true; + } else if (!strcmp(argv[arg], "onlymacro")) only_macro = true; else if (strlen(argv[arg]) >= 9 && !strncmp(argv[arg], "savemacro", 9)) @@ -277,7 +284,7 @@ main(int argc, char **argv) return EXIT_SUCCESS; // Do the rest - main2(macro_output, basename, debug, clear_all, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, + main2(macro_output, basename, debug, clear_all, clear_global, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, output_mode, language #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc diff --git a/preprocessor/DynareMain2.cc b/preprocessor/DynareMain2.cc index 8f82a059f..376dd20a9 100644 --- a/preprocessor/DynareMain2.cc +++ b/preprocessor/DynareMain2.cc @@ -25,7 +25,7 @@ #include "ExtendedPreprocessorTypes.hh" void -main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, +main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, bool parallel_test, bool nostrict, FileOutputType output_mode, LanguageOutputType language #if defined(_WIN32) || defined(__CYGWIN32__) @@ -60,7 +60,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm if (output_mode != none) mod_file->writeExternalFiles(basename, output_mode, language); else - mod_file->writeOutputFiles(basename, clear_all, no_log, no_warn, console, nograph, nointeractive, config_file + mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, nointeractive, config_file #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 667e7ac63..809255973 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -522,7 +522,7 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) } void -ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file +ModFile::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 #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -559,6 +559,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool no_log, b if (clear_all) mOutputFile << "clear all" << endl; + else if (clear_global) + mOutputFile << "clear M_ options_ oo_ estim_params_ bayestopt_ dataset_;" << endl; mOutputFile << "tic;" << endl << "% Save empty dates and dseries objects in memory." << endl diff --git a/preprocessor/ModFile.hh b/preprocessor/ModFile.hh index d8b042a73..04aa1b5e4 100644 --- a/preprocessor/ModFile.hh +++ b/preprocessor/ModFile.hh @@ -136,7 +136,7 @@ public: \param cygwin Should the MEX command of use_dll be adapted for Cygwin? \param msvc Should the MEX command of use_dll be adapted for MSVC? */ - void writeOutputFiles(const string &basename, bool clear_all, bool no_log, bool no_warn, bool console, bool nograph, bool nointeractive, const ConfigFile &config_file + 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 #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif