diff --git a/matlab/reporting/@report/addSeries.m b/matlab/reporting/@report/addSeries.m index 31dde315f257916a001bceeec5318c87163331c7..95f90e4d0fec95132124e6009229431271a52f00 100644 --- a/matlab/reporting/@report/addSeries.m +++ b/matlab/reporting/@report/addSeries.m @@ -29,7 +29,8 @@ function o = addSeries(o, varargin) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -assert(isa(o.pages(end).sections(end).elements(end), 'graph'), ... +assert(isa(o.pages(end).sections(end).elements(end), 'graph') || ... + isa(o.pages(end).sections(end).elements(end), 'table'), ... '@report.addSeries: you can only add a series to a table or graph object'); o.pages(end).sections(end).elements(end) = ... diff --git a/matlab/reporting/@series/getData.m b/matlab/reporting/@series/getData.m new file mode 100644 index 0000000000000000000000000000000000000000..7323f075689045d1df52c50b1504cabeb08c7aa4 --- /dev/null +++ b/matlab/reporting/@series/getData.m @@ -0,0 +1,23 @@ +function ds = getData(o, dates) +%function ds = getData(o, dates) + +% Copyright (C) 2013 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(~isempty(o.data) && size(o.data, 2) == 1 && isa(dates, 'dynDates')); +ds = o.data(dates); +end \ No newline at end of file diff --git a/matlab/reporting/@table/addSeries.m b/matlab/reporting/@table/addSeries.m new file mode 100644 index 0000000000000000000000000000000000000000..ddfcb413253610a857c86ccc6b77162e5ad7daa2 --- /dev/null +++ b/matlab/reporting/@table/addSeries.m @@ -0,0 +1,22 @@ +function o = addSeries(o, varargin) +% function o = addSeries(o, varargin) + +% Copyright (C) 2013 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/>. + +o.seriesElements = o.seriesElements.addSeries(varargin{:}); +end \ No newline at end of file diff --git a/matlab/reporting/@table/table.m b/matlab/reporting/@table/table.m index 0eb76538ae2000057fc803f57d65d38cfed175b1..7eca19d9a3eef7eac4074c44133b6f99f3f997e7 100644 --- a/matlab/reporting/@table/table.m +++ b/matlab/reporting/@table/table.m @@ -31,6 +31,8 @@ function o = table(varargin) o = struct; +o.seriesElements = seriesElements(); + o.title = ''; o.footnote = ''; @@ -78,10 +80,25 @@ assert(isint(o.precision), '@table.table: precision must be an int'); assert(isempty(o.range) || (isa(o.range, 'dynDates') && o.range.ndat >= 2), ... ['@table.table: range is specified as a dynDates range, e.g. ' ... '''dynDates(''1999q1''):dynDates(''1999q3'')''.']); -assert(~isempty(o.data) && isa(o.data, 'dynSeries'), ['@table.table: must ' ... - 'provide data as a dynSeries']); +assert(isempty(o.data) || isa(o.data, 'dynSeries'), ['@table.table: data must ' ... + 'be a dynSeries']); assert(isempty(o.seriestouse) || iscellstr(o.seriestouse), ['@table.table: ' ... - 'series to use must be a cell array of string(s)']); + 'seriestouse must be a cell array of string(s)']); + +% using o.seriestouse, create series objects and put them in o.seriesElements +if ~isempty(o.data) + if isempty(o.seriestouse) + for i=1:o.data.vobs + o.seriesElements = o.seriesElements.addSeries('data', o.data{o.data.name{i}}); + end + else + for i=1:length(o.seriestouse) + o.seriesElements = o.seriesElements.addSeries('data', o.data{o.seriestouse{i}}); + end + end +end +o = rmfield(o, 'seriestouse'); +o = rmfield(o, 'data'); % Create table object o = class(o, 'table'); diff --git a/matlab/reporting/@table/write.m b/matlab/reporting/@table/write.m index 5736021d2921fee9015aaafcf3c2a68f36f7cad5..1571b7068fef617d87983dacab251df00e04544b 100644 --- a/matlab/reporting/@table/write.m +++ b/matlab/reporting/@table/write.m @@ -30,18 +30,9 @@ function o = write(o, fid) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. assert(fid ~= -1); -if isempty(o.data) - return -end - -if isempty(o.seriestouse) - ds = o.data; -else - ds = o.data{o.seriestouse{:}}; -end - -if ~isempty(o.range) - ds = ds(o.range); +if ~o.seriesElements.numElements() + warning('@table.write: no series to plot, returning'); + return; end %number of left-hand columns, 1 until we allow the user to group data, @@ -51,14 +42,28 @@ end % this example would be two lh columns, with GDP Europe spanning both nlhc = 1; +if isempty(o.range) + dates = o.seriesElements.getMaxRange(); +else + dates = o.range; +end +ndates = dates.ndat; + +ne = o.seriesElements.numElements(); +ds = dynSeries(); +for i=1:ne + if isempty(ds) + ds = o.seriesElements(i).getData(dates); + else + ds = [ds o.seriesElements(i).getData(dates)]; + end +end + disp('creating table.........'); fprintf(fid, '%% Table Object\n'); fprintf(fid, '\\setlength{\\tabcolsep}{4pt}\n'); fprintf(fid, '\\begin{tabular}{@{}l'); -dates = ds.time; -ndates = dates.ndat; - for i=1:ndates if o.vlines fprintf(fid, '|');