diff --git a/doc/dynare.texi b/doc/dynare.texi index c5a30f93b6de3a5e4c94764042cb557aa7175a71..730989c4cf29e60378b1789620e4681dec2b8681 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -10525,7 +10525,7 @@ Whether or not to show vertical lines separating the columns. Default: @code{fal @end defmethod @anchor{addSeries} -@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableRowColor, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zerotol +@defmethod Report addSeries data, graphLineColor, graphLineStyle, graphLineWidth, graphMarker, graphMarkerEdgeColor, graphMarkerFaceColor, graphMarkerSize, tableDataRhs, tableRowColor, tableShowMarkers, tableAlignRight, tableNegColor, tablePosColor, tableSubSectionHeader, zerotol Adds a @code{Series} to a @code{Graph} or a @code{Table}. @optionshead @table @code @@ -10554,6 +10554,13 @@ The face color of the graph marker. Default: @code{`auto'} @item graphMarkerSize, @code{DOUBLE} The size of the graph marker. Default: @code{6} +@item tableDataRhs, @code{dseries} +A series to be added to the right of the current series. Usefull for +displaying aggregate data for a series. @i{e.g} if the series is +quarterly @code{tableDataRhs} could point to the yearly averages of +the quarterly series. This would cause quarterly data to be displayed +followed by annual data. Default: @code{empty} + @item tableRowColor, @code{STRING} The color that you want the row to be. Predefined values include @code{LightCyan} and @code{Gray}. Default: @code{white}. diff --git a/matlab/reports/@report_series/printSeries.m b/matlab/reports/@report_series/printSeries.m new file mode 100644 index 0000000000000000000000000000000000000000..b73269064f26802be93f4a5bee405904656a9db0 --- /dev/null +++ b/matlab/reports/@report_series/printSeries.m @@ -0,0 +1,57 @@ +function o = printSeries(o, fid, dser, dates, precision) +%function printSeries(o, fid, dser, dates, precision) +% function to print a row of data, contained in dser +% +% INPUTS +% fid [int] file id +% dser [string] name of data series to be printed +% dates [dates] dates for report_series slice +% precision [float] precision with which to print the data +% +% +% OUTPUTS +% o [report_series] report_series 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/>. + +dataString = ['%.' num2str(precision) 'f']; +precision = 10^precision; + +data = dser(dates); +data = data.data; +for i=1:size(data,1) + fprintf(fid, '&'); + if o.tableShowMarkers + if data(i) < -o.tableMarkerLimit + fprintf(fid, '\\color{%s}', o.tableNegColor); + elseif data(i) > o.tableMarkerLimit + fprintf(fid, '\\color{%s}', o.tablePosColor); + end + fprintf(fid, '['); + end + + fprintf(fid, dataString, round(data(i)*precision)/precision); + + if o.tableShowMarkers + fprintf(fid, ']'); + end +end +end \ No newline at end of file diff --git a/matlab/reports/@report_series/report_series.m b/matlab/reports/@report_series/report_series.m index e630bb9f6e96c6e58c4af38298e4ab353c6de111..0860435152c6d7137f300b32110f9c95adaf1a71 100644 --- a/matlab/reports/@report_series/report_series.m +++ b/matlab/reports/@report_series/report_series.m @@ -14,7 +14,7 @@ function o = report_series(varargin) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2013 Dynare Team +% Copyright (C) 2013-2014 Dynare Team % % This file is part of Dynare. % @@ -54,6 +54,8 @@ o.tableAlignRight = false; o.tableRowColor = 'white'; +o.tableDataRhs = ''; + o.zerotol = 1e-6; if nargin == 1 diff --git a/matlab/reports/@report_series/write.m b/matlab/reports/@report_series/write.m index f2a5d3c0e87f536c76b9c22bafd133c681b4a6e6..fe3512d784e72dccca20e0f7a19b36dd4516a168 100644 --- a/matlab/reports/@report_series/write.m +++ b/matlab/reports/@report_series/write.m @@ -15,7 +15,7 @@ function o = write(o, fid, dates, precision) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2013 Dynare Team +% Copyright (C) 2013-2014 Dynare Team % % This file is part of Dynare. % @@ -34,7 +34,9 @@ function o = write(o, fid, dates, precision) %% Validate options passed to function assert(fid ~= -1); -assert(isa(dates, 'dates')); +for i=1:length(dates) + assert(isa(dates{i}, 'dates')); +end assert(isint(precision)); %% Validate options provided by user @@ -42,6 +44,13 @@ assert(ischar(o.tableSubSectionHeader), '@report_series.write: tableSubSectionHe if isempty(o.tableSubSectionHeader) assert(~isempty(o.data) && isa(o.data, 'dseries'), ... '@report_series.write: must provide data as a dseries'); + + if ~isempty(o.tableDataRhs) + assert(~isempty(o.tableDataRhs) && isa(o.tableDataRhs, 'dseries'), ... + '@report_series.write: must provide tableDataRhs as a dseries'); + assert(iscell(dates) && length(dates) == 2, ... + '@report_series.write: must provide second range with tableDataRhs'); + end end assert(ischar(o.tableNegColor), '@report_series.write: tableNegColor must be a string'); @@ -52,9 +61,6 @@ assert(islogical(o.tableAlignRight), '@report_series.write: tableAlignRight must assert(isfloat(o.tableMarkerLimit), '@report_series,write: tableMarkerLimit must be a float'); %% Write Output -dataString = ['%.' num2str(precision) 'f']; -precision = 10^precision; - fprintf(fid, '%% Table Row (report_series)\n'); if ~isempty(o.tableRowColor) fprintf(fid, '\\rowcolor{%s}', o.tableRowColor); @@ -71,24 +77,11 @@ fprintf(fid, '%s', o.data.tex{:}); if o.tableAlignRight fprintf(fid, '}'); end -data = o.data(dates); -data = data.data; -for i=1:size(data,1) - fprintf(fid, '&'); - if o.tableShowMarkers - if data(i) < -o.tableMarkerLimit - fprintf(fid, '\\color{%s}', o.tableNegColor); - elseif data(i) > o.tableMarkerLimit - fprintf(fid, '\\color{%s}', o.tablePosColor); - end - fprintf(fid, '['); - end - - fprintf(fid, dataString, round(data(i)*precision)/precision); - if o.tableShowMarkers - fprintf(fid, ']'); - end +printSeries(o, fid, o.data, dates{1}, precision); +if ~isempty(o.tableDataRhs) + printSeries(o, fid, o.tableDataRhs, dates{2}, precision); end + fprintf(fid, '\\\\%%\n'); end diff --git a/matlab/reports/@report_table/report_table.m b/matlab/reports/@report_table/report_table.m index 6d68f0253adbbbf8d175b708c75df7bfb6f3dc2e..9e0cac9f33b52b3894ac9158fbf5d9f9ae7caa92 100644 --- a/matlab/reports/@report_table/report_table.m +++ b/matlab/reports/@report_table/report_table.m @@ -70,6 +70,9 @@ elseif nargin > 1 end end end +if ~iscell(o.range) + o.range = {o.range}; +end if isa(o.vlineAfter, 'dates') o.vlineAfter = {o.vlineAfter}; @@ -80,7 +83,7 @@ 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'); assert(islogical(o.showVlines), '@report_table.report_table: showVlines must be true or false'); assert(isint(o.precision), '@report_table.report_table: precision must be an int'); -assert(isempty(o.range) || (isa(o.range, 'dates') && o.range.ndat >= 2), ... +assert(isempty(o.range) || length(o.range) <=2 && allCellsAreDatesRange(o.range), ... ['@report_table.report_table: range is specified as a dates range, e.g. ' ... '''dates(''1999q1''):dates(''1999q3'')''.']); assert(isempty(o.data) || isa(o.data, 'dseries'), ... diff --git a/matlab/reports/@report_table/write.m b/matlab/reports/@report_table/write.m index 2e00b0c469a6e72c5bd4b9464b0f8d7db3bce0c0..886b9543836f30dbc37fd203c72d963f5558de7b 100644 --- a/matlab/reports/@report_table/write.m +++ b/matlab/reports/@report_table/write.m @@ -12,7 +12,7 @@ function o = write(o, fid) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2013 Dynare Team +% Copyright (C) 2013-2014 Dynare Team % % This file is part of Dynare. % @@ -45,7 +45,7 @@ nlhc = 1; if isempty(o.range) dates = o.seriesElements.getMaxRange(); else - dates = o.range; + dates = o.range{1}; end ndates = dates.ndat; @@ -76,11 +76,26 @@ for i=1:ndates end datedata = dates.time; years = unique(datedata(:, 1)); - +if length(o.range) > 1 + rhscols = strings(o.range{2}); + if o.range{2}.freq == 1 + rhscols = strrep(rhscols, 'Y', ''); + end +else + rhscols = {}; +end +for i=1:length(rhscols) + fprintf(fid, 'r'); + if o.showVlines + fprintf(fid, '|'); + end +end +nrhc = length(rhscols); +ncols = ndates+nlhc+nrhc; fprintf(fid, '@{}}%%\n'); if ~isempty(o.title) fprintf(fid, '\\multicolumn{%d}{c}{\\%s %s}\\\\\n', ... - ndates+nlhc, o.titleSize, o.title); + ncols, o.titleSize, o.title); end fprintf(fid, '\\toprule%%\n'); @@ -91,6 +106,9 @@ switch dates.freq for i=1:size(thdr, 1) fprintf(fid, ' & %d', thdr{i, 1}); end + for i=1:length(rhscols) + fprintf(fid, ' & %s', rhscols{i}); + end case 4 thdr{1, 2} = datedata(:, 2)'; if size(thdr, 1) > 1 @@ -107,11 +125,10 @@ switch dates.freq for i=1:size(thdr, 1) fprintf(fid, ' & \\multicolumn{%d}{c}{%d}', size(thdr{i,2}, 2), thdr{i,1}); end - fprintf(fid, '\\\\[-10pt]%%\n'); - for i=1:size(thdr, 1) - fprintf(fid, ' & \\multicolumn{%d}{c}{\\hrulefill}', size(thdr{i,2}, 2)); + for i=1:length(rhscols) + fprintf(fid, ' & %s', rhscols{i}); end - fprintf(fid, '\\\\%%\n'); + fprintf(fid, '\\\\\\cline{%d-%d}%%\n', nlhc+1, ncols); for i=1:size(thdr, 1) quarters = thdr{i, 2}; for j=1:size(quarters, 2) @@ -130,7 +147,7 @@ fprintf(fid, '%%\n'); % Write Report_Table Data ne = o.seriesElements.numSeriesElements(); for i=1:ne - o.seriesElements(i).write(fid, dates, o.precision); + o.seriesElements(i).write(fid, o.range, o.precision); if o.showHlines fprintf(fid, '\\hline\n'); end diff --git a/matlab/reports/allCellsAreDatesRange.m b/matlab/reports/allCellsAreDatesRange.m new file mode 100644 index 0000000000000000000000000000000000000000..4a12ac573acfc17077f4a45b5cf95f09fc1496bd --- /dev/null +++ b/matlab/reports/allCellsAreDatesRange.m @@ -0,0 +1,39 @@ +function tf = allCellsAreDatesRange(dcell) +%function tf = allCellsAreDatesRange(dcell) +% Determines if all the elements of dcell are a range of dates +% +% INPUTS +% dcell cell of dates +% +% OUTPUTS +% tf true if every entry of dcell is a range of dates +% +% 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') && dcell{i}.ndat >= 2) + tf = false; + return; + end +end +end \ No newline at end of file