write.m 2.45 KB
Newer Older
1 2
function write(o, fid, pg, rep_dir)
%function write(o, fid, pg, rep_dir)
Houtan Bastani's avatar
Houtan Bastani committed
3 4 5
% Write a Page object
%
% INPUTS
Houtan Bastani's avatar
Houtan Bastani committed
6 7
%   o              [page]     page object
%   fid            [integer]  file id
8
%   pg             [integer]  this page number
9
%   rep_dir        [string]   directory containing report.tex
Houtan Bastani's avatar
Houtan Bastani committed
10 11
%
% OUTPUTS
Houtan Bastani's avatar
Houtan Bastani committed
12
%   o              [page]     page object
Houtan Bastani's avatar
Houtan Bastani committed
13 14 15
%
% SPECIAL REQUIREMENTS
%   none
Houtan Bastani's avatar
Houtan Bastani committed
16

17
% Copyright (C) 2013-2019 Dynare Team
Houtan Bastani's avatar
Houtan Bastani committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
%
% 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/>.

34
fprintf(fid, '\n%% Page Number %d written %s\n', pg, datestr(now));
35
if strcmpi(o.orientation, 'landscape')
36
    fprintf(fid, '\\begin{landscape}\n');
Houtan Bastani's avatar
Houtan Bastani committed
37
end
Houtan Bastani's avatar
Houtan Bastani committed
38

39 40
for i=1:length(o.footnote)
    fprintf(fid, '\\blfootnote{\\tiny %d. %s}', i, o.footnote{i});
Houtan Bastani's avatar
Houtan Bastani committed
41
end
42
fprintf(fid, '\n');
Houtan Bastani's avatar
Houtan Bastani committed
43

44
if ~isempty(o.latex)
45 46 47
    if ~exist(o.pageDirName, 'dir')
        mkdir(o.pageDirName)
    end
48 49 50 51 52
    dir = [rep_dir filesep o.pageDirName];
    if exist(dir, 'file') ~= 7
        mkdir(dir)
    end
    pagename = [dir filesep 'page_' num2str(pg) '.tex'];
53 54 55 56 57 58 59 60 61
    [fidp, msg] = fopen(pagename, 'w');
    if fidp == -1
        error(['@page.write: ' msg]);
    end
    fprintf(fidp, '%s', o.latex);
    if fclose(fidp) == -1
        error('@page.write: closing %s\n', pagename);
    end
    fprintf(fid, '\\input{%s}', pagename);
62 63
else
    fprintf(fid, '\\begin{tabular}[t]{c}\n');
64
    for i = 1:length(o.title)
65 66 67 68
        if isint(o.titleTruncate)
            if length(o.title{i}) > o.titleTruncate
                o.title{i} = o.title{i}(1:o.titleTruncate);
            end
69
        end
70
        fprintf(fid, '\\multicolumn{1}{c}{%s %s}\\\\\n', o.titleFormat{i}, o.title{i});
71
    end
72

73
    for i = 1:length(o.sections)
74
        o.sections{i}.write(fid, pg, i, rep_dir);
75 76
    end
    fprintf(fid, '\\end{tabular}\n');
77
end
Houtan Bastani's avatar
Houtan Bastani committed
78

Houtan Bastani's avatar
Houtan Bastani committed
79
if strcmpi(o.orientation, 'landscape')
Houtan Bastani's avatar
Houtan Bastani committed
80
    fprintf(fid, '\\end{landscape}\n');
Houtan Bastani's avatar
Houtan Bastani committed
81
end
Houtan Bastani's avatar
Houtan Bastani committed
82 83
fprintf(fid, '\\clearpage\n');
fprintf(fid, '%% End Page Object\n\n');
84
end