Rewrote display and disp methods.

parent 2f7ba99d
function disp(dd)
function disp(o)
% Copyright (C) 2013 Dynare Team
% Overloads the disp function for dates object.
%
% This file is part of Dynare.
% INPUTS
% - o [dates]
%
% Dynare is free software: you can redistribute it and/or modify
% OUTPTS
% None
% Copyright (C) 2013-2014 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
......@@ -17,33 +23,4 @@ function disp(dd)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(dd)
fprintf('Empty dates object.\n');
return
end
max_displayed = 5;
first_displayed = 2;
fprintf('<dates: ');
if dd.ndat<=max_displayed
for i=1:dd.ndat
fprintf(date2string(dd.time(i,:),dd.freq))
if i<dd.ndat
fprintf(', ')
else
fprintf('>\n')
end
end
else
for i=1:first_displayed
fprintf(date2string(dd.time(i,:),dd.freq))
fprintf(', ')
end
fprintf(' ..., ')
fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq))
fprintf(', ')
fprintf(date2string(dd.time(dd.ndat,:),dd.freq))
fprintf('>\n')
end
fprintf(['\n' dates4display(o, inputname(1), Inf) '\n\n']);
\ No newline at end of file
function display(dd)
function display(o)
% Copyright (C) 2013 Dynare Team
% Overloads display method for dates object.
%
% This file is part of Dynare.
% INPUTS
% - o [dates]
%
% Dynare is free software: you can redistribute it and/or modify
% OUTPTS
% None
% Copyright (C) 2013-2014 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
......@@ -17,33 +23,4 @@ function display(dd)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(dd)
fprintf('%s is an empty dates object.\n', inputname(1));
return
end
max_displayed = 5;
first_displayed = 2;
fprintf('%s = <dates: ', inputname(1));
if dd.ndat<=max_displayed
for i=1:dd.ndat
fprintf(date2string(dd.time(i,:),dd.freq))
if i<dd.ndat
fprintf(', ')
else
fprintf('>\n')
end
end
else
for i=1:first_displayed
fprintf(date2string(dd.time(i,:),dd.freq))
fprintf(', ')
end
fprintf(' ..., ')
fprintf(date2string(dd.time(dd.ndat-1,:),dd.freq))
fprintf(', ')
fprintf(date2string(dd.time(dd.ndat,:),dd.freq))
fprintf('>\n')
end
\ No newline at end of file
fprintf(['\n' dates4display(o, inputname(1), 5) '\n\n']);
\ No newline at end of file
function str = dates4display(o, name, max_number_of_elements)
% Converts a list object to a string.
%
% INPUTS
% - o [list] A dates object to be displayed.
% - name [string] Name of the dates object o.
% - max_number_of_elements [integer] Maximum number of elements displayed.
%
% OUTPUTS
% - str [string] Representation of the dates object as a string.
% Copyright (C) 2014 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if isempty(o)
str = sprintf('%s is an empty dates object.\n', name);
return
end
str = sprintf('%s = <dates: ', name);
if o.length()<=max_number_of_elements
% All the elements are displayed
for i=1:length(o)-1
str = sprintf('%s%s, ', str, date2string(o.time(i,:),o.freq));
end
else
% Only display four elements (two first and two last)
for i=1:2
str = sprintf('%s%s, ', str, date2string(o.time(i,:),o.freq));
end
str = sprintf('%s%s, ', str, '...');
str = sprintf('%s%s, ', str, date2string(o.time(o.length()-1,:),o.freq));
end
str = sprintf('%s%s>', str, date2string(o.time(o.length(),:),o.freq));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment