Skip to content
Snippets Groups Projects
Verified Commit 6d540dec authored by Houtan Bastani's avatar Houtan Bastani
Browse files

update epilogue tab for changes in epilogue block

parent 6d0e4722
Branches
Tags
No related merge requests found
...@@ -11,7 +11,7 @@ function gui_epilogue(tabId) ...@@ -11,7 +11,7 @@ function gui_epilogue(tabId)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2019 Dynare Team % Copyright (C) 2019-2020 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,7 +28,7 @@ function gui_epilogue(tabId) ...@@ -28,7 +28,7 @@ function gui_epilogue(tabId)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % 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')); bg_color = char(getappdata(0, 'bg_color'));
special_color = char(getappdata(0, 'special_color')); special_color = char(getappdata(0, 'special_color'));
...@@ -68,12 +68,12 @@ handles.equations = uicontrol( ... ...@@ -68,12 +68,12 @@ handles.equations = uicontrol( ...
'Max', 3, ... 'Max', 3, ...
'Min', 1); '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 % If the epilogue file already exists, parse it and set the edit box
% string equal to the equations in the file % string equal to the equations in the file
eqs = regexp(fileread(['+' M_.fname filesep 'epilogue.m']), 'from.*', 'match', 'dotexceptnewline'); eqs = regexp(fileread(['+' M_.fname filesep 'epilogue_dynamic.m']), 'from.*', 'match', 'dotexceptnewline');
eqs = strrep(eqs, 'from simul_begin_date to simul_end_date do dseries__.', ''); eqs = strrep(eqs, 'from simul_begin_date to simul_end_date do ds.', '');
eqs = strrep(eqs, 'dseries__.', ''); eqs = strrep(eqs, 'ds.', '');
eqs = regexprep(eqs, '\s', ''); eqs = regexprep(eqs, '\s', '');
eqs = regexprep(eqs, ['\<(' strjoin(M_.endo_names, '|') ')\(t\)'], '$1'); eqs = regexprep(eqs, ['\<(' strjoin(M_.endo_names, '|') ')\(t\)'], '$1');
eqs = regexprep(eqs, '\(t\)=', '='); eqs = regexprep(eqs, '\(t\)=', '=');
...@@ -116,25 +116,48 @@ handles.pushbuttonEpilogue = uicontrol( ... ...@@ -116,25 +116,48 @@ handles.pushbuttonEpilogue = uicontrol( ...
max_lag(i) = abs(min(cellfun(@str2num, max_lag_eqs{i}))); max_lag(i) = abs(min(cellfun(@str2num, max_lag_eqs{i})));
end end
end end
equations = regexprep(equations, '(\w*)=', 'dseries__.$1(t)='); equations = regexprep(equations, '(\w*)=', 'ds.$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], '|') ')(?!\()\>'], 'ds.$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], '|') ')\>\(\-'], 'ds.$1(t-');
equations = regexprep(equations, ['\<(' strjoin(M_.param_names, '|') ')\>'], '${[''params('' num2str(find(not(cellfun(''isempty'',strfind(M_.param_names,$1))))) '')'']}'); 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 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 return
end end
fprintf(fidw, 'function dseries__ = epilogue(params, dseries__)\n'); fprintf(fidw, 'function ds = epilogue_dynamic(params, ds)\n');
fprintf(fidw, '%s\n', '% function dseries__ = epilogue(params, dseries__)'); fprintf(fidw, '%s\n', '% function ds = epilogue_dynamic(params, ds)');
fprintf(fidw, '%s\n', '% Epilogue file generated by Dynare GUI'); fprintf(fidw, '%s\n\n', '% Epilogue file generated by Dynare GUI');
fprintf(fidw, 'simul_end_date = lastdate(dseries__);\n\n'); fprintf(fidw, 'simul_end_date = lastdate(ds);\n\n');
for i = 1:length(equations) 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 ~ds.exist(''%s'')\n', lhs{i});
fprintf(fidw, 'if ~dseries__.exist(''%s'')\n', lhs{i}); fprintf(fidw, ' ds = [ds dseries(NaN(ds.nobs,1), ds.firstdate, ''%s'')];\n', lhs{i});
fprintf(fidw, ' dseries__ = [dseries__ dseries(NaN(dseries__.nobs,1), dseries__.firstdate, ''%s'')];\n', lhs{i});
fprintf(fidw, 'end\n'); 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, ' 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');
end end
fprintf(fidw, 'end\n'); fprintf(fidw, 'end\n');
fclose(fidw); fclose(fidw);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment