From a4ef5a01d3f4ade9dd6f7fc8def781fc45a22a2f Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 18 Dec 2019 15:54:50 +0100 Subject: [PATCH] Epilogue: handle case where `dseries.firstobservedperiod` ends in an error issue #36 --- src/ModelEquationBlock.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ModelEquationBlock.cc b/src/ModelEquationBlock.cc index d4c5121c..49da9d09 100644 --- a/src/ModelEquationBlock.cc +++ b/src/ModelEquationBlock.cc @@ -447,7 +447,12 @@ Epilogue::writeDynamicEpilogueFile(const string & basename) const expr->collectVariables(SymbolType::exogenous, used_symbols); expr->collectVariables(SymbolType::epilogue, used_symbols); - output << "simul_begin_date = firstobservedperiod(ds{"; + output << endl + << "if ~ds.exist('" << symbol_table.getName(symb_id) << "')" << endl + << " ds = [ds dseries(NaN(ds.nobs,1), ds.firstdate, '" << symbol_table.getName(symb_id)<< "')];" << endl + << "end" << endl + << "try" << endl + << " simul_begin_date = firstobservedperiod(ds{"; for (auto it1 = used_symbols.begin(); it1 != used_symbols.end(); ++it1) { if (it1 != used_symbols.begin()) @@ -455,14 +460,12 @@ Epilogue::writeDynamicEpilogueFile(const string & basename) const output << "'" << symbol_table.getName(*it1) << "'"; } output << "}) + " << max_lag << ";" << endl - << "if ~ds.exist('" << symbol_table.getName(symb_id) << "')" << endl - << " ds = [ds dseries(NaN(ds.nobs,1), ds.firstdate, '" << symbol_table.getName(symb_id)<< "')];" << endl - << "end" << endl - << "from simul_begin_date to simul_end_date do " + << " from simul_begin_date to simul_end_date do " << "ds." << symbol_table.getName(symb_id) << "(t) = "; - expr->writeOutput(output, ExprNodeOutputType::epilogueFile, temporary_terms, temporary_terms_idxs, tef_terms); - output << ";" << endl << endl; + output << ";" << endl + << "catch" << endl + << "end" << endl; } output << "end" << endl; output.close(); -- GitLab