Skip to content
Snippets Groups Projects
Commit 33e80b58 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting: @table: use @series

parent c94f1b98
Branches
Tags
No related merge requests found
......@@ -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) = ...
......
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
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
......@@ -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');
......
......@@ -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, '|');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment