diff --git a/src/gui_epilogue.m b/src/gui_epilogue.m index 948ce725204b73d57d6e89cc33bda119658bd9c4..57457cd79918186c306810000241dc2b84ec8fb4 100644 --- a/src/gui_epilogue.m +++ b/src/gui_epilogue.m @@ -11,7 +11,7 @@ function gui_epilogue(tabId) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2019 Dynare Team +% Copyright (C) 2019-2020 Dynare Team % % This file is part of Dynare. % @@ -28,7 +28,7 @@ function gui_epilogue(tabId) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -global project_info dynare_gui_ options_ model_settings oo_ M_ +global M_ bg_color = char(getappdata(0, 'bg_color')); special_color = char(getappdata(0, 'special_color')); @@ -68,12 +68,12 @@ handles.equations = uicontrol( ... 'Max', 3, ... 'Min', 1); -if exist(['+' M_.fname filesep 'epilogue.m'], 'file') == 2 +if exist(['+' M_.fname filesep 'epilogue_dynamic.m'], 'file') == 2 % If the epilogue file already exists, parse it and set the edit box % string equal to the equations in the file - eqs = regexp(fileread(['+' M_.fname filesep 'epilogue.m']), 'from.*', 'match', 'dotexceptnewline'); - eqs = strrep(eqs, 'from simul_begin_date to simul_end_date do dseries__.', ''); - eqs = strrep(eqs, 'dseries__.', ''); + eqs = regexp(fileread(['+' M_.fname filesep 'epilogue_dynamic.m']), 'from.*', 'match', 'dotexceptnewline'); + eqs = strrep(eqs, 'from simul_begin_date to simul_end_date do ds.', ''); + eqs = strrep(eqs, 'ds.', ''); eqs = regexprep(eqs, '\s', ''); eqs = regexprep(eqs, ['\<(' strjoin(M_.endo_names, '|') ')\(t\)'], '$1'); eqs = regexprep(eqs, '\(t\)=', '='); @@ -116,25 +116,48 @@ handles.pushbuttonEpilogue = uicontrol( ... max_lag(i) = abs(min(cellfun(@str2num, max_lag_eqs{i}))); end end - equations = regexprep(equations, '(\w*)=', 'dseries__.$1(t)='); - equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')(?!\()\>'], 'dseries__.$1(t)'); - equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')\>\(\-'], 'dseries__.$1(t-'); + equations = regexprep(equations, '(\w*)=', 'ds.$1(t)='); + equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')(?!\()\>'], 'ds.$1(t)'); + equations = regexprep(equations, ['\<(' strjoin([M_.endo_names; M_.exo_names], '|') ')\>\(\-'], 'ds.$1(t-'); equations = regexprep(equations, ['\<(' strjoin(M_.param_names, '|') ')\>'], '${[''params('' num2str(find(not(cellfun(''isempty'',strfind(M_.param_names,$1))))) '')'']}'); - fidw = fopen(['+' M_.fname filesep 'epilogue.m'], 'w'); + fidw = fopen(['+' M_.fname filesep 'epilogue_dynamic.m'], 'w'); if fidw < 0 - gui_tools.show_warning(['Couldn''t open +' M_.fname filesep 'epilogue.m for writing']); + gui_tools.show_warning(['Couldn''t open +' M_.fname filesep 'epilogue_dynamic.m for writing']); return end - fprintf(fidw, 'function dseries__ = epilogue(params, dseries__)\n'); - fprintf(fidw, '%s\n', '% function dseries__ = epilogue(params, dseries__)'); - fprintf(fidw, '%s\n', '% Epilogue file generated by Dynare GUI'); - fprintf(fidw, 'simul_end_date = lastdate(dseries__);\n\n'); + fprintf(fidw, 'function ds = epilogue_dynamic(params, ds)\n'); + fprintf(fidw, '%s\n', '% function ds = epilogue_dynamic(params, ds)'); + fprintf(fidw, '%s\n\n', '% Epilogue file generated by Dynare GUI'); + fprintf(fidw, 'simul_end_date = lastdate(ds);\n\n'); for i = 1:length(equations) - fprintf(fidw, 'simul_begin_date = firstobservedperiod(dseries__{''%s''}) + %d + 1;\n', strjoin(rhs{i}, ''','''), max_lag(i)); - fprintf(fidw, 'if ~dseries__.exist(''%s'')\n', lhs{i}); - fprintf(fidw, ' dseries__ = [dseries__ dseries(NaN(dseries__.nobs,1), dseries__.firstdate, ''%s'')];\n', lhs{i}); + fprintf(fidw, 'if ~ds.exist(''%s'')\n', lhs{i}); + fprintf(fidw, ' ds = [ds dseries(NaN(ds.nobs,1), ds.firstdate, ''%s'')];\n', lhs{i}); + fprintf(fidw, 'end\n'); + fprintf(fidw, 'try\n'); + fprintf(fidw, ' simul_begin_date = firstobservedperiod(ds{''%s''}) + %d;\n', strjoin(rhs{i}, ''','''), max_lag(i)); + fprintf(fidw, ' from simul_begin_date to simul_end_date do %s;\n\n', equations{i}); + fprintf(fidw, 'catch\n'); + fprintf(fidw, 'end\n'); + end + fprintf(fidw, 'end\n'); + fclose(fidw); + fidw = fopen(['+' M_.fname filesep 'epilogue_static.m'], 'w'); + if fidw < 0 + gui_tools.show_warning(['Couldn''t open +' M_.fname filesep 'epilogue_static.m for writing']); + return + end + fprintf(fidw, 'function ds = epilogue_static(params, ds)\n'); + fprintf(fidw, '%s\n', '% function ds = epilogue_static(params, ds)'); + fprintf(fidw, '%s\n\n', '% Epilogue file generated by Dynare GUI'); + equations = regexprep(equations, '.*=', ''); + equations = regexprep(equations, '\(t((-\d)|(+d))?\)', ''); + for i = 1:length(equations) + fprintf(fidw, 'epilogue_static_tmp_term = %s;\n', equations{i}); + fprintf(fidw, 'if isdseries(epilogue_static_tmp_term)\n'); + fprintf(fidw, ' ds.%s = epilogue_static_tmp_term;\n', lhs{i}); + fprintf(fidw, 'else\n'); + fprintf(fidw, ' ds.%s = dseries(ones(ds.nobs,1)*epilogue_static_tmp_term, ds.firstdate, ''%s'');\n', lhs{i}, lhs{i}); fprintf(fidw, 'end\n'); - fprintf(fidw, 'from simul_begin_date to simul_end_date do %s;\n\n', equations{i}); end fprintf(fidw, 'end\n'); fclose(fidw);