writeSeriesForTable.m 3.63 KB
Newer Older
1
2
function o = writeSeriesForTable(o, fid, dates, precision, ncols)
%function o = writeSeriesForTable(o, fid, dates, precision, ncols)
3
4
5
% Write Table Row
%
% INPUTS
6
%   o            [report_series]    report_series object
7
8
9
%   fid          [int]              file id
%   dates        [dates]            dates for report_series slice
%   precision    [float]            precision with which to print the data
10
%   ncols        [int]              total number of columns in table
11
%
12
13
%
% OUTPUTS
14
%   o            [report_series]    report_series object
15
16
17
18
%
% SPECIAL REQUIREMENTS
%   none

19
% Copyright (C) 2013-2014 Dynare Team
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
%
% 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/>.

%% Validate options passed to function
assert(fid ~= -1);
38
for i=1:length(dates)
39
    assert(isdates(dates{i}));
40
end
41
42
43
assert(isint(precision));

%% Validate options provided by user
44
assert(ischar(o.tableSubSectionHeader), '@report_series.writeSeriesForTable: tableSubSectionHeader must be a string');
45
if isempty(o.tableSubSectionHeader)
46
    assert(~isempty(o.data) && isdseries(o.data), ...
47
           '@report_series.writeSeriesForTable: must provide data as a dseries');
48
49

    if ~isempty(o.tableDataRhs)
50
        assert(~isempty(o.tableDataRhs) && isdseries(o.tableDataRhs), ...
51
               '@report_series.writeSeriesForTable: must provide tableDataRhs as a dseries');
52
        assert(iscell(dates) && length(dates) == 2, ...
53
               '@report_series.writeSeriesForTable: must provide second range with tableDataRhs');
54
    end
55
end
56

57
58
59
assert(ischar(o.tableNegColor), '@report_series.writeSeriesForTable: tableNegColor must be a string');
assert(ischar(o.tablePosColor), '@report_series.writeSeriesForTable: tablePosColor must be a string');
assert(ischar(o.tableRowColor), '@report_series.writeSeriesForTable: tableRowColor must be a string');
60
61
assert(isint(o.tableRowIndent) && o.tableRowIndent >= 0, ...
       '@report_series.writeSeriesForTable: tableRowIndent must be an integer >= 0');
62
63
64
assert(islogical(o.tableShowMarkers), '@report_series.writeSeriesForTable: tableShowMarkers must be true or false');
assert(islogical(o.tableAlignRight), '@report_series.writeSeriesForTable: tableAlignRight must be true or false');
assert(isfloat(o.tableMarkerLimit), '@report_series.writeSeriesForTable: tableMarkerLimit must be a float');
65
66

%% Write Output
67
fprintf(fid, '%% Table Row (report_series)\n');
68
69
70
if ~isempty(o.tableRowColor)
    fprintf(fid, '\\rowcolor{%s}', o.tableRowColor);
end
71
if ~isempty(o.tableSubSectionHeader)
72
    fprintf(fid, '\\textbf{%s}', o.tableSubSectionHeader);
73
74
75
    for i=1:ncols-1
        fprintf(fid, ' &');
    end
76
77
78
    fprintf(fid, '\\\\%%\n');
    return;
end
79
if o.tableAlignRight
80
81
    fprintf(fid, '\\multicolumn{1}{r}{');
end
82
83
84
85
86
87
88
89
if o.tableRowIndent == 0
    fprintf(fid, '\\noindent');
else
    for i=1:o.tableRowIndent
        fprintf(fid,'\\indent');
    end
end
fprintf(fid, ' %s', o.data.tex{:});
90
if o.tableAlignRight
91
92
    fprintf(fid, '}');
end
93

94
95
96
printSeries(o, fid, o.data, dates{1}, precision);
if ~isempty(o.tableDataRhs)
    printSeries(o, fid, o.tableDataRhs, dates{2}, precision);
97
end
98

99
fprintf(fid, '\\\\%%\n');
100
end