From 25bf43983ff96e073cf15d07034f99a542293aa4 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 1 Sep 2017 17:58:25 +0200 Subject: [PATCH 01/16] Add write_latex_steady_state_model to collect_latex_files.m --- matlab/collect_latex_files.m | 1 + tests/TeX/fs2000_corr_ME.mod | 1 + 2 files changed, 2 insertions(+) diff --git a/matlab/collect_latex_files.m b/matlab/collect_latex_files.m index 45902f1ba..53886f390 100644 --- a/matlab/collect_latex_files.m +++ b/matlab/collect_latex_files.m @@ -48,6 +48,7 @@ for ii=1:length(TeX_Files) ~strcmp(TeX_Files(ii).name,[M_.fname,'_dynamic.tex']) && ... ~strcmp(TeX_Files(ii).name,[M_.fname,'_static.tex']) && ... ~strcmp(TeX_Files(ii).name,[M_.fname,'_original.tex']) && ... + ~strcmp(TeX_Files(ii).name,[M_.fname,'_steady_state.tex']) && ... ~strcmp(TeX_Files(ii).name,[M_.fname,'_TeX_binder.tex']) fprintf(fid,'%s \n',['\include{',f_name,'}']); end diff --git a/tests/TeX/fs2000_corr_ME.mod b/tests/TeX/fs2000_corr_ME.mod index c226ef835..33123e54b 100644 --- a/tests/TeX/fs2000_corr_ME.mod +++ b/tests/TeX/fs2000_corr_ME.mod @@ -142,6 +142,7 @@ write_latex_static_model; write_latex_dynamic_model(write_equation_tags); write_latex_parameter_table; write_latex_definitions; +write_latex_steady_state_model; estimated_params; alp, 0.356; From c026113314c66301d3feb4096209cc9b3c209c99 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 11:06:37 +0200 Subject: [PATCH 02/16] preprocessor: add backslashes to log output in latex. closes #1507 --- preprocessor/ExprNode.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc index 4e09b5b0e..60e46de0b 100644 --- a/preprocessor/ExprNode.cc +++ b/preprocessor/ExprNode.cc @@ -2056,11 +2056,14 @@ UnaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type, output << "exp"; break; case oLog: - output << "log"; + if (IS_LATEX(output_type)) + output << "\\log"; + else + output << "log"; break; case oLog10: if (IS_LATEX(output_type)) - output << "log_{10}"; + output << "\\log_{10}"; else output << "log10"; break; From a302b7af99fa73ca5bbc5ef1701bd938671d7a70 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 14:57:53 +0200 Subject: [PATCH 03/16] =?UTF-8?q?simplify=20check=20for=20=E2=80=98.?= =?UTF-8?q?=E2=80=99=20in=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matlab/dynare.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 2cb1bdee0..7b4f3c13e 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -99,11 +99,7 @@ end % Testing if filename has more than one period (not allowed). dot_location=(strfind(fname,'.')); -if length(dot_location)>1 - error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') -end - -if dot_location==length(fname) +if length(dot_location) > 1 || dot_location == length(fname) error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') end From 9c86168d6305193656a6b6b268ec4198872a4356 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 15:07:23 +0200 Subject: [PATCH 04/16] =?UTF-8?q?Revert=20"simplify=20check=20for=20?= =?UTF-8?q?=E2=80=98.=E2=80=99=20in=20name"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a302b7af99fa73ca5bbc5ef1701bd938671d7a70. --- matlab/dynare.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 7b4f3c13e..2cb1bdee0 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -99,7 +99,11 @@ end % Testing if filename has more than one period (not allowed). dot_location=(strfind(fname,'.')); -if length(dot_location) > 1 || dot_location == length(fname) +if length(dot_location)>1 + error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') +end + +if dot_location==length(fname) error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') end From 43bed00e3f7f7938d347ce1e5f438ba5e3303012 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 15:03:19 +0200 Subject: [PATCH 05/16] =?UTF-8?q?dynare.m:=20don=E2=80=99t=20redo=20strfin?= =?UTF-8?q?d=20as=20value=20exists=20in=20dot=5Flocation=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matlab/dynare.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 2cb1bdee0..efc035467 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -108,7 +108,7 @@ if dot_location==length(fname) end % Add dyn or mod extension to the file name if not already provided. -if isempty(strfind(fname,'.')) +if isempty(dot_location) fnamelength = length(fname); fname1 = [fname '.dyn']; d = dir(fname1); From d648f7646231d245169ae83bfda20f56a1a8d169 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 15:09:05 +0200 Subject: [PATCH 06/16] dynare.m: aesthetic fix: remove unnecessary parenthesis --- matlab/dynare.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index efc035467..939dfeb28 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -98,7 +98,7 @@ if ~ischar(fname) end % Testing if filename has more than one period (not allowed). -dot_location=(strfind(fname,'.')); +dot_location=strfind(fname,'.'); if length(dot_location)>1 error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') end From 24a03ee29064f66f5fe6dc47b46a7e23edf338ea Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 16:18:48 +0200 Subject: [PATCH 07/16] preprocessor: allow passing mod file as string. Closes #1509 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Usage: ./dynare_m $'<>' The $’’ expands special characters. This is necessary because our setup for native matlab statements require that they end with a newline. In other words, the rest of the mod file can be sent on one line, but if there is a native matlab statement you must enter a `\n` after it. NB: In this case, apostrophes must be escaped: ' becomes \' e.g., to run tests/example1.mod: ./dynare_m $'//Example 1 from Collard\'s guide to Dynare\nvar y, c, k, a, h, b;varexo e, u;verbatim;% I want these comments included in\n% example1.m 1999q1 1999y\n%\nvar = 1;\nend;parameters beta, rho, alpha, delta, theta, psi, tau;alpha = 0.36;rho = 0.95;tau = 0.025;beta = 0.99;delta = 0.025;psi = 0;theta = 2.95;phi = 0.1;\nmodel;c*theta*h^(1+psi)=(1-alpha)*y;k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));k = exp(b)*(y-c)+(1-delta)*k(-1);a = rho*a(-1)+tau*b(-1) + e;b = tau*a(-1)+rho*b(-1) + u;end;initval;y = 1.08068253095672;c = 0.80359242014163;h = 0.29175631001732;k = 11.08360443260358;a = 0;b = 0;e = 0;u = 0;end;shocks;var e; stderr 0.009;var u; stderr 0.009;var e, u = phi*0.009*0.009;end; stoch_simul;' --- preprocessor/DynareMain.cc | 38 +++++++++++++++++++++++++------ preprocessor/DynareMain1.cc | 6 ++--- preprocessor/macro/MacroDriver.cc | 11 ++------- preprocessor/macro/MacroDriver.hh | 2 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/preprocessor/DynareMain.cc b/preprocessor/DynareMain.cc index 8176d6f99..d37b2314d 100644 --- a/preprocessor/DynareMain.cc +++ b/preprocessor/DynareMain.cc @@ -48,9 +48,8 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool , JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple ); -void main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file, - bool no_line_macro, - map &defines, vector &path, stringstream ¯o_output); +void main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file, + bool no_line_macro, map &defines, vector &path, stringstream ¯o_output); void usage() @@ -339,9 +338,34 @@ main(int argc, char **argv) // Construct basename (i.e. remove file extension if there is one) string basename = argv[1]; - size_t pos = basename.find_last_of('.'); - if (pos != string::npos) - basename.erase(pos); + string modfile, modfiletxt; + size_t fsc = basename.find_first_of(';'); + if (fsc != string::npos) + { + // If a semicolon is found in argv[1], treat it as the text of the modfile + modfile = "mod_file_passed_as_string.mod"; + basename = "mod_file_passed_as_string"; + modfiletxt = argv[1]; + } + else + { + // If a semicolon is NOT found in argv[1], treat it as the name of the modfile + modfile = argv[1]; + size_t pos = basename.find_last_of('.'); + if (pos != string::npos) + basename.erase(pos); + + ifstream modfile(argv[1], ios::binary); + if (modfile.fail()) + { + cerr << "ERROR: Could not open file: " << argv[1] << endl; + exit(EXIT_FAILURE); + } + + stringstream buffer; + buffer << modfile.rdbuf(); + modfiletxt = buffer.str(); + } WarningConsolidation warnings(no_warn); @@ -360,7 +384,7 @@ main(int argc, char **argv) // Do macro processing stringstream macro_output; - main1(argv[1], basename, debug, save_macro, save_macro_file, no_line_macro, defines, path, macro_output); + main1(modfile, basename, modfiletxt, debug, save_macro, save_macro_file, no_line_macro, defines, path, macro_output); if (only_macro) return EXIT_SUCCESS; diff --git a/preprocessor/DynareMain1.cc b/preprocessor/DynareMain1.cc index 3cbd33f37..fe87ba83b 100644 --- a/preprocessor/DynareMain1.cc +++ b/preprocessor/DynareMain1.cc @@ -23,13 +23,13 @@ #include "macro/MacroDriver.hh" void -main1(char *modfile, string &basename, bool debug, bool save_macro, string &save_macro_file, bool no_line_macro, - map &defines, vector &path, stringstream ¯o_output) +main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file, + bool no_line_macro, map &defines, vector &path, stringstream ¯o_output) { // Do macro processing MacroDriver m; - m.parse(modfile, macro_output, debug, no_line_macro, defines, path); + m.parse(modfile, modfiletxt, macro_output, debug, no_line_macro, defines, path); if (save_macro) { if (save_macro_file.empty()) diff --git a/preprocessor/macro/MacroDriver.cc b/preprocessor/macro/MacroDriver.cc index 71d53b9cb..4d2399ec0 100644 --- a/preprocessor/macro/MacroDriver.cc +++ b/preprocessor/macro/MacroDriver.cc @@ -37,18 +37,11 @@ MacroDriver::~MacroDriver() } void -MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro, +MacroDriver::parse(const string &f, const string &modfiletxt, ostream &out, bool debug, bool no_line_macro, map defines, vector path) { file = f; - ifstream in(f.c_str(), ios::binary); - if (in.fail()) - { - cerr << "ERROR: Could not open file: " << f << endl; - exit(EXIT_FAILURE); - } - /* Copy the file into a stringstream, and add an extra end-of-line. This is a workaround for trac ticket #73: with this workaround, MOD files ending with @@ -66,7 +59,7 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro { file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; } - file_with_endl << in.rdbuf() << endl; + file_with_endl << modfiletxt << endl; lexer = new MacroFlex(&file_with_endl, &out, no_line_macro, path); lexer->set_debug(debug); diff --git a/preprocessor/macro/MacroDriver.hh b/preprocessor/macro/MacroDriver.hh index 773a99dcf..c76947de2 100644 --- a/preprocessor/macro/MacroDriver.hh +++ b/preprocessor/macro/MacroDriver.hh @@ -182,7 +182,7 @@ public: //! Starts parsing a file, returns output in out /*! \param no_line_macro should we omit the @#line statements ? */ - void parse(const string &f, ostream &out, bool debug, bool no_line_macro, + void parse(const string &f, const string &modfiletxt, ostream &out, bool debug, bool no_line_macro, map defines, vector path); //! Name of main file being parsed From 513abe445f824908b8375c87d7b554fabc600a06 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 8 Sep 2017 18:20:56 +0200 Subject: [PATCH 08/16] doc: update for change in 24a03ee29064f66f5fe6dc47b46a7e23edf338ea. #1509 --- doc/dynare.texi | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/doc/dynare.texi b/doc/dynare.texi index f05011886..cf674053e 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -191,6 +191,7 @@ Running Dynare * Dynare invocation:: * Dynare hooks:: * Understanding Preprocessor Error Messages:: +* Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line:: The Model file @@ -723,6 +724,7 @@ required by the user. Its contents are described in @ref{The Model file}. * Dynare invocation:: * Dynare hooks:: * Understanding Preprocessor Error Messages:: +* Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line:: @end menu @node Dynare invocation @@ -1102,6 +1104,41 @@ it did not expect. Hence, it throws an error of the form: @code{ERROR: PARAMETERS}. In this case, you would simply place a semicolon at the end of line one and the parser would continue processing. +@node Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line +@section Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line + +You can invoke the preprocessor directly from the command line. In this way, +the preprocessor can be called a @file{.mod} file as explained above or on the +text of a @file{.mod} file as explained herein. + +In certain circumstances, it may be useful to invoke the preprocessor on the +text of a @file{.mod} file. To do so, simply invoke the preprocessor by passing +it the text of your @file{.mod} file as the first argument. This argument +requires special care. First, any native Matlab statements contained in the +string representing your @file{.mod} file must be followed by a newline +character (@code{\n}). Further, any single-line comments must also be followed +by a newline character. Finally, any apostrophe's must be escaped with a +backslash (@i{i.e.}, @code{\'} instead of @code{'}. + +Taking into account the considerations above, the file located in +@code{examples/example1.mod} could be run by executing: +@example +./dynare_m $'/* * Example 1 from F. Collard (2001): "Stochastic simulations +with DYNARE: * A practical guide" (see "guide.pdf" in the documentation +directory). */var y, c, k, a, h, b;varexo e, u;parameters beta, rho, alpha, +delta, theta, psi, tau;alpha = 0.36;rho = 0.95;tau = 0.025;beta = 0.99;delta = +0.025;psi = 0;theta = 2.95;phi = 0.1;\nmodel;c*theta*h^(1+psi)=(1-alpha)*y;k = +beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));y += exp(a)*(k(-1)^alpha)*(h^(1-alpha));k = exp(b)*(y-c)+(1-delta)*k(-1);a = +rho*a(-1)+tau*b(-1) + e;b = tau*a(-1)+rho*b(-1) + u;end;initval;y = +1.08068253095672;c = 0.80359242014163;h = 0.29175631001732;k = +11.08360443260358;a = 0;b = 0;e = 0;u = 0;end;shocks;var e; stderr 0.009;var u; +stderr 0.009;var e, u = phi*0.009*0.009;end;stoch_simul;' +@end example + +This produces the same output as when running dynare on a @file{.mod} file with +the basename of the output files being set to @code{mod_file_passed_as_string_}. + @node The Model file @chapter The Model file From 4cfaa2545e3dfb529f80cd0b901c99b6bdba3acd Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 11 Sep 2017 18:14:56 +0200 Subject: [PATCH 09/16] preprocessor: allow variables that become state variables in ramsey_policy to be set in histval. closes #1193 --- preprocessor/ComputingTasks.cc | 5 +++++ preprocessor/ModFile.cc | 23 +++++++++++++++++++++++ preprocessor/NumericalInitialization.cc | 3 +++ preprocessor/NumericalInitialization.hh | 3 +++ preprocessor/ParsingDriver.cc | 8 ++------ preprocessor/ParsingDriver.hh | 2 ++ preprocessor/Statement.hh | 4 ++++ 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 1926b67ac..7bf65090d 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -604,6 +604,11 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.order_option = max(mod_file_struct.order_option, order + 1); } + OptionsList::symbol_list_options_t::const_iterator itsl = + options_list.symbol_list_options.find("instruments"); + if (itsl != options_list.symbol_list_options.end()) + mod_file_struct.ramsey_state_variables = itsl->second.get_symbols(); + // Fill in mod_file_struct.partial_information it = options_list.num_options.find("partial_information"); if (it != options_list.num_options.end() && it->second == "1") diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 3af3faa58..32a721154 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -149,6 +149,29 @@ ModFile::checkPass(bool nostrict, bool stochastic) exit(EXIT_FAILURE); } + // Workaround for #1193 + if (!mod_file_struct.hist_vals_wrong_lag.empty()) + { + for (vector::const_iterator it = mod_file_struct.ramsey_state_variables.begin(); + it != mod_file_struct.ramsey_state_variables.end(); it++) + { + int symb_id = symbol_table.getID(*it); + map::const_iterator it1 = mod_file_struct.hist_vals_wrong_lag.find(symb_id); + if (it1 != mod_file_struct.hist_vals_wrong_lag.end() && it1->second < 0) + mod_file_struct.hist_vals_wrong_lag.erase(symb_id); + } + + if (!mod_file_struct.hist_vals_wrong_lag.empty()) + { + for (map::const_iterator it = mod_file_struct.hist_vals_wrong_lag.begin(); + it != mod_file_struct.hist_vals_wrong_lag.end(); it++) + cerr << "ERROR: histval: variable " << symbol_table.getName(it->first) + << " does not appear in the model with the lag " << it->second + << " (see the reference manual for the timing convention in 'histval')" << endl; + exit(EXIT_FAILURE); + } + } + if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) && mod_file_struct.discretionary_policy_present) { diff --git a/preprocessor/NumericalInitialization.cc b/preprocessor/NumericalInitialization.cc index 843026517..ad199014b 100644 --- a/preprocessor/NumericalInitialization.cc +++ b/preprocessor/NumericalInitialization.cc @@ -308,9 +308,11 @@ EndValStatement::writeJsonOutput(ostream &output) const } HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, + const hist_vals_wrong_lag_t hist_vals_wrong_lag_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : hist_values(hist_values_arg), + hist_vals_wrong_lag(hist_vals_wrong_lag_arg), symbol_table(symbol_table_arg), all_values_required(all_values_required_arg) { @@ -356,6 +358,7 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat if (unused_endo.size() > 0 || unused_exo.size() > 0) exit(EXIT_FAILURE); } + mod_file_struct.hist_vals_wrong_lag = hist_vals_wrong_lag; } void diff --git a/preprocessor/NumericalInitialization.hh b/preprocessor/NumericalInitialization.hh index 58a7e6e04..16f5acd1d 100644 --- a/preprocessor/NumericalInitialization.hh +++ b/preprocessor/NumericalInitialization.hh @@ -107,12 +107,15 @@ public: Maps pairs (symbol_id, lag) to expr_t */ typedef map, expr_t> hist_values_t; + typedef map hist_vals_wrong_lag_t; private: const hist_values_t hist_values; + const hist_vals_wrong_lag_t hist_vals_wrong_lag; const SymbolTable &symbol_table; const bool all_values_required; public: HistValStatement(const hist_values_t &hist_values_arg, + const hist_vals_wrong_lag_t hist_vals_wrong_lag_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg); //! Workaround for trac ticket #157 diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 565db4b1a..52f1177ba 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -549,11 +549,7 @@ ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) pair key(symb_id, ilag); if (mod_file->dynamic_model.minLagForSymbol(symb_id) > ilag - 1) - { - ostringstream s; - s << ilag-1; - error("histval: variable " + *name + " does not appear in the model with the lag " + s.str() + " (see the reference manual for the timing convention in 'histval')"); - } + hist_vals_wrong_lag[symb_id] = ilag-1; if (hist_values.find(key) != hist_values.end()) error("hist_val: (" + *name + ", " + *lag + ") declared twice"); @@ -669,7 +665,7 @@ ParsingDriver::end_endval(bool all_values_required) void ParsingDriver::end_histval(bool all_values_required) { - mod_file->addStatement(new HistValStatement(hist_values, mod_file->symbol_table, all_values_required)); + mod_file->addStatement(new HistValStatement(hist_values, hist_vals_wrong_lag, mod_file->symbol_table, all_values_required)); hist_values.clear(); } diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 2504b8084..6a2da6ef6 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -157,6 +157,8 @@ private: InitOrEndValStatement::init_values_t init_values; //! Temporary storage for histval blocks HistValStatement::hist_values_t hist_values; + //! Temporary storage for histval blocks + HistValStatement::hist_vals_wrong_lag_t hist_vals_wrong_lag; //! Temporary storage for homotopy_setup blocks HomotopyStatement::homotopy_values_t homotopy_values; //! Temporary storage for moment_calibration diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index db7d5606b..70395a35c 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -123,6 +123,10 @@ public: bool steady_state_model_present; //! Whether there is a write_latex_steady_state_model statement present bool write_latex_steady_state_model_present; + //! Set list of variables that become state variables when ramsey_policy is used + vector ramsey_state_variables; + //! Histval values that do not have the appropriate lag + map hist_vals_wrong_lag; }; class Statement From 853a68286a6ff77d7ae09e0a3808b13a0e567005 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 Sep 2017 13:29:43 +0200 Subject: [PATCH 10/16] preprocessor: remove commented RamseyConstraintsStatement code --- preprocessor/ComputingTasks.cc | 57 ---------------------------------- preprocessor/ComputingTasks.hh | 1 - 2 files changed, 58 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 7bf65090d..3d97098f1 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -514,63 +514,6 @@ RamseyConstraintsStatement::writeJsonOutput(ostream &output) const output << "}"; } -// Statement * -// RamseyConstraintsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -// { -// vector errors; -// SymbolList new_symbol_list, new_options_symbol_list; -// OptionsList new_options_list = options_list; -// SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); -// vector symbols = symbol_list.get_symbols(); - -// for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) -// try -// { -// new_symbol_table->getID(*it); -// new_symbol_list.addSymbol(*it); -// } -// catch (SymbolTable::UnknownSymbolIDException &e) -// { -// errors.push_back(orig_symbol_table.getName(e.id)); -// } -// catch (SymbolTable::UnknownSymbolNameException &e) -// { -// errors.push_back(e.name); -// } - -// OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); -// if (it != options_list.symbol_list_options.end()) -// { -// symbols = it->second.get_symbols(); -// for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) -// try -// { -// new_symbol_table->getID(*it1); -// new_options_symbol_list.addSymbol(*it1); -// } -// catch (SymbolTable::UnknownSymbolIDException &e) -// { -// errors.push_back(orig_symbol_table.getName(e.id)); -// } -// catch (SymbolTable::UnknownSymbolNameException &e) -// { -// errors.push_back(e.name); -// } -// new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; -// } - -// if (!errors.empty()) -// { -// cerr << endl -// << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl -// << " This likely means that you declared them as varexo and that they're not in the model" << endl; -// for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) -// cerr << *it << endl; -// exit(EXIT_FAILURE); -// } -// return new RamseyPolicyStatement(new_symbol_list, options_list); -// } - RamseyPolicyStatement::RamseyPolicyStatement(const SymbolTable &symbol_table_arg, const vector &ramsey_policy_list_arg, const OptionsList &options_list_arg) : diff --git a/preprocessor/ComputingTasks.hh b/preprocessor/ComputingTasks.hh index 18ec20d18..bd58c2158 100644 --- a/preprocessor/ComputingTasks.hh +++ b/preprocessor/ComputingTasks.hh @@ -160,7 +160,6 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeJsonOutput(ostream &output) const; - // virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyPolicyStatement : public Statement From 9649f2e9dee4ebab95349d7999e23707d41a1238 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 Sep 2017 14:01:25 +0200 Subject: [PATCH 11/16] preprocessor: remove size filed in Symbol Table class. closes #1380 --- preprocessor/SymbolTable.cc | 14 +++++++------- preprocessor/SymbolTable.hh | 15 ++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/preprocessor/SymbolTable.cc b/preprocessor/SymbolTable.cc index 7a2a3da48..dca0ea8f4 100644 --- a/preprocessor/SymbolTable.cc +++ b/preprocessor/SymbolTable.cc @@ -38,7 +38,7 @@ AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg { } -SymbolTable::SymbolTable() : frozen(false), size(0) +SymbolTable::SymbolTable() : frozen(false) { } @@ -78,7 +78,7 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na else non_long_name_partition_exists = true; - int id = size++; + int id = symbol_table.size(); symbol_table[name] = id; type_table.push_back(type); @@ -110,7 +110,7 @@ SymbolTable::freeze() throw (FrozenException) frozen = true; - for (int i = 0; i < size; i++) + for (int i = 0; i < symbol_table.size(); i++) { int tsi; switch (getType(i)) @@ -156,7 +156,7 @@ SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDExcept if (frozen) throw FrozenException(); - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); type_table[id] = newtype; @@ -732,7 +732,7 @@ SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedExce void SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, FrozenException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); if (frozen) throw FrozenException(); @@ -745,7 +745,7 @@ SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, Fro bool SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); return (predetermined_variables.find(symb_id) != predetermined_variables.end()); @@ -760,7 +760,7 @@ SymbolTable::predeterminedNbr() const void SymbolTable::addObservedVariable(int symb_id) throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id >= size) + if (symb_id < 0 || symb_id > symbol_table.size()) throw UnknownSymbolIDException(symb_id); assert(getType(symb_id) == eEndogenous); diff --git a/preprocessor/SymbolTable.hh b/preprocessor/SymbolTable.hh index fb9a54dd7..20a7d5735 100644 --- a/preprocessor/SymbolTable.hh +++ b/preprocessor/SymbolTable.hh @@ -111,9 +111,6 @@ private: //! Has method freeze() been called? bool frozen; - //! Number of symbols contained in the table - int size; - typedef map symbol_table_type; //! Maps strings to symbol IDs symbol_table_type symbol_table; @@ -375,7 +372,7 @@ SymbolTable::exists(const string &name) const inline string SymbolTable::getName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return name_table[id]; @@ -384,7 +381,7 @@ SymbolTable::getName(int id) const throw (UnknownSymbolIDException) inline string SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return tex_name_table[id]; @@ -393,7 +390,7 @@ SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException) inline string SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return long_name_table[id]; @@ -402,7 +399,7 @@ SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException) inline SymbolType SymbolTable::getType(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); else return type_table[id]; @@ -430,7 +427,7 @@ SymbolTable::getTypeSpecificID(int id) const throw (UnknownSymbolIDException, No if (!frozen) throw NotYetFrozenException(); - if (id < 0 || id >= size) + if (id < 0 || id > symbol_table.size()) throw UnknownSymbolIDException(id); return type_specific_ids[id]; @@ -481,7 +478,7 @@ SymbolTable::param_nbr() const throw (NotYetFrozenException) inline int SymbolTable::maxID() { - return (size-1); + return symbol_table.size() - 1; } inline int From 91a954edf5de04222485c25e119b7b6f2ea9d1ab Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 12 Sep 2017 14:16:29 +0200 Subject: [PATCH 12/16] preprocessor: factorize code that checks for valid symb_id --- preprocessor/SymbolTable.cc | 15 +++++---------- preprocessor/SymbolTable.hh | 36 ++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/preprocessor/SymbolTable.cc b/preprocessor/SymbolTable.cc index dca0ea8f4..cf986b41e 100644 --- a/preprocessor/SymbolTable.cc +++ b/preprocessor/SymbolTable.cc @@ -156,8 +156,7 @@ SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDExcept if (frozen) throw FrozenException(); - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); + validateSymbID(id); type_table[id] = newtype; } @@ -732,8 +731,8 @@ SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedExce void SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, FrozenException) { - if (symb_id < 0 || symb_id > symbol_table.size()) - throw UnknownSymbolIDException(symb_id); + validateSymbID(symb_id); + if (frozen) throw FrozenException(); @@ -745,9 +744,7 @@ SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, Fro bool SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id > symbol_table.size()) - throw UnknownSymbolIDException(symb_id); - + validateSymbID(symb_id); return (predetermined_variables.find(symb_id) != predetermined_variables.end()); } @@ -760,9 +757,7 @@ SymbolTable::predeterminedNbr() const void SymbolTable::addObservedVariable(int symb_id) throw (UnknownSymbolIDException) { - if (symb_id < 0 || symb_id > symbol_table.size()) - throw UnknownSymbolIDException(symb_id); - + validateSymbID(symb_id); assert(getType(symb_id) == eEndogenous); varobs.push_back(symb_id); } diff --git a/preprocessor/SymbolTable.hh b/preprocessor/SymbolTable.hh index 20a7d5735..b97ad162a 100644 --- a/preprocessor/SymbolTable.hh +++ b/preprocessor/SymbolTable.hh @@ -219,6 +219,8 @@ private: int addLeadAuxiliaryVarInternal(bool endo, int index, expr_t arg) throw (FrozenException); //! Factorized code for Json writing void writeJsonVarVector(ostream &output, const vector &varvec) const; + //! Factorized code for asserting that 0 <= symb_id <= symbol_table.size() + inline void validateSymbID(int symb_id) const throw (UnknownSymbolIDException); public: //! Add a symbol /*! Returns the symbol ID */ @@ -362,6 +364,13 @@ public: set getOrigEndogenous() const; }; +inline void +SymbolTable::validateSymbID(int symb_id) const throw (UnknownSymbolIDException) +{ + if (symb_id < 0 || symb_id > symbol_table.size()) + throw UnknownSymbolIDException(symb_id); +} + inline bool SymbolTable::exists(const string &name) const { @@ -372,37 +381,29 @@ SymbolTable::exists(const string &name) const inline string SymbolTable::getName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); - else - return name_table[id]; + validateSymbID(id); + return name_table[id]; } inline string SymbolTable::getTeXName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); - else - return tex_name_table[id]; + validateSymbID(id); + return tex_name_table[id]; } inline string SymbolTable::getLongName(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); - else - return long_name_table[id]; + validateSymbID(id); + return long_name_table[id]; } inline SymbolType SymbolTable::getType(int id) const throw (UnknownSymbolIDException) { - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); - else - return type_table[id]; + validateSymbID(id); + return type_table[id]; } inline SymbolType @@ -427,8 +428,7 @@ SymbolTable::getTypeSpecificID(int id) const throw (UnknownSymbolIDException, No if (!frozen) throw NotYetFrozenException(); - if (id < 0 || id > symbol_table.size()) - throw UnknownSymbolIDException(id); + validateSymbID(id); return type_specific_ids[id]; } From 8113c88a0b6eba6e0214e157ef10489967e85fff Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 Sep 2017 10:16:19 +0200 Subject: [PATCH 13/16] preprocessor: histval should only accept lag values <= 0. closes #1510 --- preprocessor/ParsingDriver.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 52f1177ba..30c4336aa 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -546,6 +546,9 @@ ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) error("histval: " + *name + " should be an endogenous or exogenous variable"); int ilag = atoi(lag->c_str()); + if (ilag > 0) + error("histval: the lag on " + *name + " should be less than or equal to 0"); + pair key(symb_id, ilag); if (mod_file->dynamic_model.minLagForSymbol(symb_id) > ilag - 1) From 79e510a99ee07bd5b6f745c26210895dc1cf0456 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 12 Sep 2017 21:29:17 +0200 Subject: [PATCH 14/16] Add integration tests for #1193 and #1510 --- tests/Makefile.am | 2 + .../optimal_policy/Ramsey/ramsey_histval.mod | 44 +++++++++++++++++++ .../Ramsey/ramsey_histval_xfail.mod | 44 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tests/optimal_policy/Ramsey/ramsey_histval.mod create mode 100644 tests/optimal_policy/Ramsey/ramsey_histval_xfail.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index e28ed34a0..76e091856 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -84,6 +84,7 @@ MODFILES = \ optimal_policy/Ramsey/ramsey_ex.mod \ optimal_policy/Ramsey/ramsey_ex_initval_AR2.mod \ optimal_policy/Ramsey/ramsey_ex_aux.mod \ + optimal_policy/Ramsey/ramsey_histval.mod \ optimal_policy/Ramsey/Gali_commitment.mod \ optimal_policy/RamseyConstraints/test1.mod \ discretionary_policy/dennis_1.mod \ @@ -356,6 +357,7 @@ XFAIL_MODFILES = ramst_xfail.mod \ estimation/fs2000_stochastic_singularity_xfail.mod \ identification/ident_unit_root/ident_unit_root_xfail.mod \ steady_state/Linear_steady_state_xfail.mod \ + optimal_policy/Ramsey/ramsey_histval_xfail.mod \ example1_extra_exo_xfail.mod MFILES = initval_file/ramst_initval_file_data.m diff --git a/tests/optimal_policy/Ramsey/ramsey_histval.mod b/tests/optimal_policy/Ramsey/ramsey_histval.mod new file mode 100644 index 000000000..bb9cdb0f8 --- /dev/null +++ b/tests/optimal_policy/Ramsey/ramsey_histval.mod @@ -0,0 +1,44 @@ +% Test whether preprocessor recognizes state variables introduced by optimal policy Github #1193 + +var pai, c, n, r, a; +varexo u; +parameters beta, rho, epsilon, omega, phi, gamma; + +beta=0.99; +gamma=3; +omega=17; +epsilon=8; +phi=1; +rho=0.95; + +model; +a = rho*a(-1)+u; +1/c = beta*r/(c(+1)*pai(+1)); +pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c); +exp(a)*n = c+(omega/2)*(pai-1)^2; +end; + +initval; +r=1; +end; + +histval; +r(0)=1; +end; + +steady_state_model; +a = 0; +pai = beta*r; +c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega); +n = c+(omega/2)*(pai-1)^2; +end; + +shocks; +var u; stderr 0.008; +var u; +periods 1; +values 1; +end; +options_.dr_display_tol=0; +planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); +ramsey_policy(planner_discount=0.99,order=1,instruments=(r),periods=500); \ No newline at end of file diff --git a/tests/optimal_policy/Ramsey/ramsey_histval_xfail.mod b/tests/optimal_policy/Ramsey/ramsey_histval_xfail.mod new file mode 100644 index 000000000..0af81202d --- /dev/null +++ b/tests/optimal_policy/Ramsey/ramsey_histval_xfail.mod @@ -0,0 +1,44 @@ +% Test whether preprocessor fails if histval set future lags + +var pai, c, n, r, a; +varexo u; +parameters beta, rho, epsilon, omega, phi, gamma; + +beta=0.99; +gamma=3; +omega=17; +epsilon=8; +phi=1; +rho=0.95; + +model; +a = rho*a(-1)+u; +1/c = beta*r/(c(+1)*pai(+1)); +pai*(pai-1)/c = beta*pai(+1)*(pai(+1)-1)/c(+1)+epsilon*phi*n^(gamma+1)/omega -exp(a)*n*(epsilon-1)/(omega*c); +exp(a)*n = c+(omega/2)*(pai-1)^2; +end; + +initval; +r=1; +end; + +histval; +a(5)=1; +end; + +steady_state_model; +a = 0; +pai = beta*r; +c = find_c(0.96,pai,beta,epsilon,phi,gamma,omega); +n = c+(omega/2)*(pai-1)^2; +end; + +shocks; +var u; stderr 0.008; +var u; +periods 1; +values 1; +end; +options_.dr_display_tol=0; +planner_objective(ln(c)-phi*((n^(1+gamma))/(1+gamma))); +ramsey_policy(planner_discount=0.99,order=1,instruments=(r),periods=500); \ No newline at end of file From 71ee63dc0d94671076cb95d315a80e0798b4b376 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 13 Sep 2017 11:36:14 +0200 Subject: [PATCH 15/16] preprocessor: histval lag check must be made after transformation to the dynamic model due to ramsey_policy. closes #1193 --- preprocessor/ComputingTasks.cc | 5 ----- preprocessor/ModFile.cc | 40 +++++++++++++++------------------- preprocessor/ParsingDriver.cc | 2 +- preprocessor/Statement.hh | 2 -- 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 3d97098f1..9ff522f8d 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -547,11 +547,6 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.order_option = max(mod_file_struct.order_option, order + 1); } - OptionsList::symbol_list_options_t::const_iterator itsl = - options_list.symbol_list_options.find("instruments"); - if (itsl != options_list.symbol_list_options.end()) - mod_file_struct.ramsey_state_variables = itsl->second.get_symbols(); - // Fill in mod_file_struct.partial_information it = options_list.num_options.find("partial_information"); if (it != options_list.num_options.end() && it->second == "1") diff --git a/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 32a721154..42fa7f64e 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -149,29 +149,6 @@ ModFile::checkPass(bool nostrict, bool stochastic) exit(EXIT_FAILURE); } - // Workaround for #1193 - if (!mod_file_struct.hist_vals_wrong_lag.empty()) - { - for (vector::const_iterator it = mod_file_struct.ramsey_state_variables.begin(); - it != mod_file_struct.ramsey_state_variables.end(); it++) - { - int symb_id = symbol_table.getID(*it); - map::const_iterator it1 = mod_file_struct.hist_vals_wrong_lag.find(symb_id); - if (it1 != mod_file_struct.hist_vals_wrong_lag.end() && it1->second < 0) - mod_file_struct.hist_vals_wrong_lag.erase(symb_id); - } - - if (!mod_file_struct.hist_vals_wrong_lag.empty()) - { - for (map::const_iterator it = mod_file_struct.hist_vals_wrong_lag.begin(); - it != mod_file_struct.hist_vals_wrong_lag.end(); it++) - cerr << "ERROR: histval: variable " << symbol_table.getName(it->first) - << " does not appear in the model with the lag " << it->second - << " (see the reference manual for the timing convention in 'histval')" << endl; - exit(EXIT_FAILURE); - } - } - if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) && mod_file_struct.discretionary_policy_present) { @@ -417,6 +394,23 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs) mod_file_struct.ramsey_eq_nbr = dynamic_model.equation_number() - mod_file_struct.orig_eq_nbr; } + // Workaround for #1193 + if (!mod_file_struct.hist_vals_wrong_lag.empty()) + { + bool err = false; + for (map::const_iterator it = mod_file_struct.hist_vals_wrong_lag.begin(); + it != mod_file_struct.hist_vals_wrong_lag.end(); it++) + if (dynamic_model.minLagForSymbol(it->first) > it->second - 1) + { + cerr << "ERROR: histval: variable " << symbol_table.getName(it->first) + << " does not appear in the model with the lag " << it->second - 1 + << " (see the reference manual for the timing convention in 'histval')" << endl; + err = true; + } + if (err) + exit(EXIT_FAILURE); + } + if (mod_file_struct.stoch_simul_present || mod_file_struct.estimation_present || mod_file_struct.osr_present diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 30c4336aa..419727860 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/ParsingDriver.cc @@ -552,7 +552,7 @@ ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) pair key(symb_id, ilag); if (mod_file->dynamic_model.minLagForSymbol(symb_id) > ilag - 1) - hist_vals_wrong_lag[symb_id] = ilag-1; + hist_vals_wrong_lag[symb_id] = ilag; if (hist_values.find(key) != hist_values.end()) error("hist_val: (" + *name + ", " + *lag + ") declared twice"); diff --git a/preprocessor/Statement.hh b/preprocessor/Statement.hh index 70395a35c..a6a1d5c32 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -123,8 +123,6 @@ public: bool steady_state_model_present; //! Whether there is a write_latex_steady_state_model statement present bool write_latex_steady_state_model_present; - //! Set list of variables that become state variables when ramsey_policy is used - vector ramsey_state_variables; //! Histval values that do not have the appropriate lag map hist_vals_wrong_lag; }; From 768a3e8be6e6a56552ff09cc8e585404262b0185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Wed, 13 Sep 2017 17:58:45 +0200 Subject: [PATCH 16/16] Fixed typo (historical values for exogenous variables). --- matlab/set_historical_values.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/set_historical_values.m b/matlab/set_historical_values.m index ef42f2563..af72e2981 100644 --- a/matlab/set_historical_values.m +++ b/matlab/set_historical_values.m @@ -78,7 +78,7 @@ if M_.maximum_exo_lag for t = 1:M_.maximum_exo_lag for i=1:M_.exo_nbr if available_exo_variables(i) - exo_histval(M_.maximum_exo_lag+1-t,i) = ds{exo_list{i}}(initialperiod-t).data; + M_.exo_histval(M_.maximum_exo_lag+1-t,i) = ds{exo_list{i}}(initialperiod-t).data; end end end