write.m 2.49 KB
Newer Older
1
2
3
4
5
function o = write(o, fid, dates, precision)
%function o = write(o, fid, dates, precision)
% Write Table Row
%
% INPUTS
Houtan Bastani's avatar
Houtan Bastani committed
6
7
8
%   o            [series]    series object
%   dates        [dynDates]  dates for series slice
%   precision    [float]     precision with which to print the data
9
10
%
% OUTPUTS
Houtan Bastani's avatar
Houtan Bastani committed
11
%   o            [series]    series object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%
% 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/>.

%% Validate options passed to function
assert(fid ~= -1);
assert(isa(dates, 'dynDates'));
assert(isint(precision));

%% Validate options provided by user
assert(~isempty(o.data) && isa(o.data, 'dynSeries'), ...
       '@series.write: must provide data as a dynSeries');

assert(ischar(o.color), '@series.write: color must be a string');
43
44
assert(ischar(o.tableNegColor), '@series.write: tableNegColor must be a string');
assert(ischar(o.tablePosColor), '@series.write: tablePosColor must be a string');
45
assert(islogical(o.showTableMarkers), '@series.write: showTableMarkers must be a string');
46
assert(islogical(o.tableAlignRight), '@series.write: tableAlignRight must be a string');
47
48
49
50
51
52

%% Write Output
dataString = ['%.' num2str(precision) 'f'];
precision  = 10^precision;

fprintf(fid, '%% Table Row (series)\n');
53
if o.tableAlignRight
54
55
    fprintf(fid, '\\multicolumn{1}{r}{');
end
56
fprintf(fid, '%s', o.data.tex{:});
57
if o.tableAlignRight
58
59
    fprintf(fid, '}');
end
60
61
62
63
64
65
data = o.data(dates);
data = data.data;
for i=1:size(data,1)
    thisCellData = round(data(i)*precision)/precision;

    fprintf(fid, ' &');
66
    if o.showTableMarkers
67
        if thisCellData < 0
68
            fprintf(fid, '\\color{%s}', o.tableNegColor);
69
        elseif thisCellData > 0
70
            fprintf(fid, '\\color{%s}', o.tablePosColor);
71
72
73
74
75
76
        end
        fprintf(fid, '[');
    end

    fprintf(fid, dataString, thisCellData);

77
    if o.showTableMarkers
78
79
80
81
82
        fprintf(fid, ']');
    end
end
fprintf(fid, ' \\\\\n\n');
end