From 17a10c513f47016e4499422cf0f57db8d1b15bd1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 2 Jan 2014 09:35:45 +0100 Subject: [PATCH] reporting: make vlineAfter accept a cell array of dates(cherry picked from commit 26d834a42a16f0a1e0ae50fc39359e427a069ea9) --- doc/dynare.texi | 7 ++-- matlab/reports/@report_table/report_table.m | 8 +++-- matlab/reports/@report_table/write.m | 8 +++-- matlab/reports/allCellsAreDates.m | 39 +++++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 matlab/reports/allCellsAreDates.m diff --git a/doc/dynare.texi b/doc/dynare.texi index f7aff57a5..9598ed0d2 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -95,7 +95,7 @@ @c %**end of header @copying -Copyright @copyright{} 1996-2013, Dynare Team. +Copyright @copyright{} 1996-2014, Dynare Team. @quotation Permission is granted to copy, distribute and/or modify this document @@ -10511,8 +10511,9 @@ Title for the table. Default: @code{none} @item titleSize, @code{STRING} @LaTeX{} string representing the size of the table title. Default: @code{large} -@item vlineAfter, @code{dates} -Show a vertical line after the specified date. Default: @code{empty} +@item vlineAfter, @code{dates} || @code{CELL_ARRAY_DATES} +Show a vertical line after the specified date (or dates if a cell +array of dates is passed). Default: @code{empty} @item vlineAfterEndOfPeriod, @code{BOOLEAN} Show a vertical line after the end of every period (@i{i.e.} after diff --git a/matlab/reports/@report_table/report_table.m b/matlab/reports/@report_table/report_table.m index e84803dce..6d68f0253 100644 --- a/matlab/reports/@report_table/report_table.m +++ b/matlab/reports/@report_table/report_table.m @@ -12,7 +12,7 @@ function o = report_table(varargin) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2013 Dynare Team +% Copyright (C) 2013-2014 Dynare Team % % This file is part of Dynare. % @@ -71,6 +71,10 @@ elseif nargin > 1 end end +if isa(o.vlineAfter, 'dates') + o.vlineAfter = {o.vlineAfter}; +end + % Check options provided by user assert(ischar(o.title), '@report_table.report_table: title must be a string'); assert(islogical(o.showHlines), '@report_table.report_table: showHlines must be true or false'); @@ -83,7 +87,7 @@ assert(isempty(o.data) || isa(o.data, 'dseries'), ... '@report_table.report_table: data must be a dseries'); assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ... '@report_table.report_table: seriesToUse must be a cell array of string(s)'); -assert(isempty(o.vlineAfter) || isa(o.vlineAfter, 'dates'), ... +assert(isempty(o.vlineAfter) || allCellsAreDates(o.vlineAfter), ... '@report_table.report_table: vlineAfter must be a dates'); if o.showVlines o.vlineAfter = ''; diff --git a/matlab/reports/@report_table/write.m b/matlab/reports/@report_table/write.m index 0325a7455..2e00b0c46 100644 --- a/matlab/reports/@report_table/write.m +++ b/matlab/reports/@report_table/write.m @@ -64,9 +64,11 @@ for i=1:ndates end end if ~isempty(o.vlineAfter) - if dates(i) == o.vlineAfter - if ~(o.vlineAfterEndOfPeriod && dates(i).time(2) == dates(i).freq) - fprintf(fid, '|'); + for j=1:length(o.vlineAfter) + if dates(i) == o.vlineAfter{j} + if ~(o.vlineAfterEndOfPeriod && dates(i).time(2) == dates(i).freq) + fprintf(fid, '|'); + end end end end diff --git a/matlab/reports/allCellsAreDates.m b/matlab/reports/allCellsAreDates.m new file mode 100644 index 000000000..533ff49e4 --- /dev/null +++ b/matlab/reports/allCellsAreDates.m @@ -0,0 +1,39 @@ +function tf = allCellsAreDates(dcell) +%function tf = allCellsAreDates(dcell) +% Determines if all the elements of dcell are dates objects +% +% INPUTS +% dcell cell of dates objects +% +% OUTPUTS +% tf true if every entry of dcell is a dates object +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2014 Dynare Team +% +% This file is part of Dynare. +% +% Dynare 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, +% 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/>. + +assert(iscell(dcell)); +tf = true; +for i=1:length(dcell) + if ~isa(dcell{i}, 'dates') + tf = false; + return; + end +end +end \ No newline at end of file -- GitLab