From e3ae7dec200405b94cfaa9b20dd8c80e7157f290 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Tue, 30 Apr 2019 17:49:55 +0200 Subject: [PATCH] epilogue: further simplifications --- src/gui_epilogue.m | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/gui_epilogue.m b/src/gui_epilogue.m index 34e401a..948ce72 100644 --- a/src/gui_epilogue.m +++ b/src/gui_epilogue.m @@ -92,22 +92,30 @@ handles.pushbuttonEpilogue = uicontrol( ... function EpilogueCallback(~, ~) if isempty(handles.equations.String) + gui_tools.show_warning('You must first enter an equation'); return end equations_str = sprintf('%s', handles.equations.String'); equations_str = equations_str(~isspace(equations_str)); if equations_str(end) ~= ';' - gui_tools.show_warning('The last equation must end with a semicolon'); + gui_tools.show_warning('Equations must end with a semicolon'); return end - equations = strtrim(strsplit(equations_str, ';')); + equations = strsplit(equations_str, ';'); equations = equations(~cellfun('isempty', equations)); if isempty(equations) + gui_tools.show_warning('No equations found. Did you end each equation with a semilcolon?'); return end - lhs = get_lhs_var(equations); - rhs = get_rhs_endo_exo(equations); - max_lag = get_rhs_max_lag(equations); + lhs = strtok(equations, '='); + rhs = regexp(equations, ['\<(', strjoin([M_.endo_names ; M_.exo_names], '|'),')\>'], 'match'); + max_lag_eqs = regexp(equations, '\(\-(\d*)\)', 'match'); + max_lag = zeros(length(max_lag_eqs), 1); + for i = 1:length(max_lag) + if ~isempty(max_lag_eqs{i}) + 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-'); @@ -130,25 +138,6 @@ handles.pushbuttonEpilogue = uicontrol( ... end fprintf(fidw, 'end\n'); fclose(fidw); - - % Helper functions - function lhs = get_lhs_var(equations) - lhs = strtok(equations, '='); - end - - function rhs = get_rhs_endo_exo(equations) - rhs = regexp(equations, ['\<(', strjoin([M_.endo_names ; M_.exo_names], '|'),')\>'], 'match'); - end - - function max_lag_arr = get_rhs_max_lag(equations) - max_lag_eqs = regexp(equations, '\(\-(\d*)\)', 'match'); - max_lag_arr = zeros(length(max_lag_eqs), 1); - for idx = 1:length(max_lag_arr) - if ~isempty(max_lag_eqs{idx}) - max_lag_arr(idx) = abs(min(cellfun(@str2num, max_lag_eqs{idx}))); - end - end - end end handles.pushbuttonClear = uicontrol( ... -- GitLab