From 27587e1ea56f057651e2894441e7153292527d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Scylla=29?= Date: Fri, 2 May 2014 13:12:38 +0200 Subject: [PATCH] Factorized code for the displayed error messages. --- matlab/utilities/dseries/from.m | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/matlab/utilities/dseries/from.m b/matlab/utilities/dseries/from.m index b666726f0..c0c817c62 100644 --- a/matlab/utilities/dseries/from.m +++ b/matlab/utilities/dseries/from.m @@ -20,26 +20,30 @@ function from(varargin) lvarargin = lower(varargin); if ~(ismember('to',lvarargin) && ismember('do',lvarargin)) - error('This command must be followed by TO and DO keywords (in that order).') + error(get_error_message_0()) end to_id = strmatch('to',lvarargin); do_id = strmatch('do',lvarargin); if do_idd2 end if ~isequal(do_id,4) - error('Wrong syntax! The second dates object must be immediately followed by the DO keyword.') + msg = sprintf('Wrong syntax! The second dates object must be immediately followed by the DO keyword.\n'); + error(get_error_message_0(msg)) end % Build the recursive expression. @@ -116,4 +121,15 @@ EXPRESSION = [EXPRESSION(1:equal_id),expression]; eval(sprintf('t=dates(''%s''); while t<=dates(''%s''), %s; t = t+1; end',char(d1),char(d2),EXPRESSION)) % Put assigned variable back in the caller workspace... -eval(sprintf('assignin(''caller'', assignedvariablename, %s)',assignedvariablename)); \ No newline at end of file +eval(sprintf('assignin(''caller'', assignedvariablename, %s)',assignedvariablename)); + + + +function msg = get_error_message_0(msg) + if ~nargin + msg = sprintf('Wrong syntax! The correct syntax is:\n\n'); + else + msg = [msg, sprintf('The correct syntax is:\n\n')]; + end + msg = [msg, sprintf(' from d1 to d2 do SOMETHING\n\n')]; + msg = [msg, sprintf('where d1