report_table.m 4.06 KB
Newer Older
1
2
3
function o = report_table(varargin)
%function o = report_table(varargin)
% Report_Table Class Constructor
Houtan Bastani's avatar
Houtan Bastani committed
4
5
%
% INPUTS
6
7
%   0 args => empty report_table
%   1 arg (report_table class) => copy object
Houtan Bastani's avatar
Houtan Bastani committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
%
% OUTPUTS
%   none
%
% SPECIAL REQUIREMENTS
%   none

% 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 = struct;
Houtan Bastani's avatar
Houtan Bastani committed
33

34
35
o.seriesElements = seriesElements();

Houtan Bastani's avatar
Houtan Bastani committed
36
o.title = '';
37
o.titleSize = 'large';
Houtan Bastani's avatar
Houtan Bastani committed
38

39
o.showHlines = false;
40
o.showVlines = false;
41
o.vlineAfter = '';
42
o.vlineAfterEndOfPeriod = false;
Houtan Bastani's avatar
Houtan Bastani committed
43

44
45
o.annualAverages = false;

Houtan Bastani's avatar
Houtan Bastani committed
46
o.data = '';
47
o.seriesToUse = '';
48
o.range = {};
Houtan Bastani's avatar
Houtan Bastani committed
49
o.precision = 1;
Houtan Bastani's avatar
Houtan Bastani committed
50
51

if nargin == 1
52
53
    assert(isa(varargin{1}, 'report_table'),['With one arg to Report_Table constructor, ' ...
                        'you must pass a report_table object']);
Houtan Bastani's avatar
Houtan Bastani committed
54
55
56
57
    o = varargin{1};
    return;
elseif nargin > 1
    if round(nargin/2) ~= nargin/2
58
        error(['Options to Report_Table constructor must be supplied in name/value ' ...
Houtan Bastani's avatar
Houtan Bastani committed
59
60
61
               'pairs.']);
    end

62
    optNames = fieldnames(o);
Houtan Bastani's avatar
Houtan Bastani committed
63
64
65

    % overwrite default values
    for pair = reshape(varargin, 2, [])
66
        ind = strmatch(lower(pair{1}), lower(optNames), 'exact');
67
68
69
        assert(isempty(ind) || length(ind) == 1);
        if ~isempty(ind)
            o.(optNames{ind}) = pair{2};
Houtan Bastani's avatar
Houtan Bastani committed
70
        else
71
            error('%s is not a recognized option to the Report_Table constructor.', pair{1});
Houtan Bastani's avatar
Houtan Bastani committed
72
73
74
75
        end
    end
end

76
% Check options provided by user
77
78
79
80
81
assert(ischar(o.title), '@report_table.report_table: title must be a string');
assert(islogical(o.annualAverages), '@report_table.report_table: annualAverages must be true or false');
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');
82
assert(isempty(o.range) || (isa(o.range, 'dynDates') && o.range.ndat >= 2), ...
83
       ['@report_table.report_table: range is specified as a dynDates range, e.g. ' ...
84
        '''dynDates(''1999q1''):dynDates(''1999q3'')''.']);
85
assert(isempty(o.data) || isa(o.data, 'dynSeries'), ...
86
       '@report_table.report_table: data must be a dynSeries');
87
assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ...
88
       '@report_table.report_table: seriesToUse must be a cell array of string(s)');
89
assert(isempty(o.vlineAfter) || isa(o.vlineAfter, 'dynDate'), ...
90
       '@report_table.report_table: vlineAfter must be a dynDate');
91
if o.showVlines
92
    o.vlineAfter = '';
93
end
94
assert(islogical(o.vlineAfterEndOfPeriod), ...
95
       '@report_table.report_table: vlineAfterEndOfPeriod must be true or false');
96
97
valid_title_sizes = {'Huge', 'huge', 'LARGE', 'Large', 'large', 'normalsize', ...
                    'small', 'footnotesize', 'scriptsize', 'tiny'};
98
assert(any(strcmp(o.titleSize, valid_title_sizes)), ...
99
       ['@report_table.report_table: titleSize must be one of ' strjoin(valid_title_sizes, ' ')]);
100

101
% using o.seriesToUse, create series objects and put them in o.seriesElements
102
if ~isempty(o.data)
103
    if isempty(o.seriesToUse)
104
105
106
107
        for i=1:o.data.vobs
            o.seriesElements = o.seriesElements.addSeries('data', o.data{o.data.name{i}});
        end
    else
108
109
        for i=1:length(o.seriesToUse)
            o.seriesElements = o.seriesElements.addSeries('data', o.data{o.seriesToUse{i}});
110
111
112
        end
    end
end
113
o = rmfield(o, 'seriesToUse');
114
o = rmfield(o, 'data');
115

116
117
% Create report_table object
o = class(o, 'report_table');
Houtan Bastani's avatar
Houtan Bastani committed
118
end