reporting (WIP)

time-shift
Houtan Bastani 2013-02-15 16:52:35 +01:00
parent 4fa141762d
commit 78f8f04598
42 changed files with 1257 additions and 94 deletions

View File

@ -1,5 +1,5 @@
function ss = addSection(ss, varargin)
% function ss = addSection(ss, varargin)
function e = addGraph(e, varargin)
% function e = addGraph(e, varargin)
% Copyright (C) 2013 Dynare Team
%
@ -20,8 +20,8 @@ function ss = addSection(ss, varargin)
assert(nargin >= 1 && nargin <= 3)
if nargin == 1
ss.objArray = ss.objArray.addObj(section());
e.objArray = e.objArray.addObj(graph());
else
ss.objArray = ss.objArray.addObj(varargin{:});
e.objArray = e.objArray.addObj(varargin{:});
end
end

View File

@ -0,0 +1,27 @@
function e = addTable(e, varargin)
% function e = addTable(e, 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/>.
assert(nargin >= 1 && nargin <= 3)
if nargin == 1
e.objArray = e.objArray.addObj(table());
else
e.objArray = e.objArray.addObj(varargin{:});
end
end

View File

@ -0,0 +1,36 @@
function display(o)
%function display(o)
% Display a Elements object
%
% INPUTS
% none
%
% 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/>.
name = 'report.page.section.elements';
disp(' ');
disp([name ' = ']);
disp(' ');
disp(getElements(o));
end

View File

@ -0,0 +1,42 @@
function e = elements(varargin)
%function e = elements(varargin)
% Elements Class Constructor
%
% INPUTS
% Optional elements object
%
% OUTPUTS
% elements object
%
% 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/>.
switch nargin
case 0
e = class(struct, 'elements', objArray());
case 1
assert(isa(varargin{1}, 'elements'), ...
['With one arg to elements constructor, you must pass an ' ...
'elements object or a char.']);
e = varargin{1};
otherwise
error('Elements constructor: invalid number of arguments');
end
end

View File

@ -1,5 +1,5 @@
function e = getSections(ss, varargin)
% function e = getSections(ss, varargin)
function e = getElements(ps, varargin)
% function e = getElements(ps, varargin)
% Copyright (C) 2013 Dynare Team
%
@ -18,5 +18,5 @@ function e = getSections(ss, varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
e = ss.objArray.getObjs(varargin{:});
e = ps.objArray.getObjs(varargin{:});
end

View File

@ -1,5 +1,5 @@
function ns = numSections(ss)
% function ns = numSections(ss)
function n = numElements(o)
% function n = numElements(o)
% Copyright (C) 2013 Dynare Team
%
@ -18,5 +18,5 @@ function ns = numSections(ss)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
ns = ss.objArray.numObjs();
n = o.objArray.numObjs();
end

View File

@ -0,0 +1,39 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% 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/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B.objArray(index) = V;
otherwise
error('Elements subsasign syntax error')
end
end

View File

@ -0,0 +1,48 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% 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/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S);
else
A = feval(S(1).subs, A);
end
otherwise
error(['Elements Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getElements(A, S(1).subs{:});
case '{}'
error(['Elements Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Elements Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,46 @@
function display(o)
%function display(o)
% Display a Graph object
%
% INPUTS
% none
%
% 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/>.
name = 'report.page.section.graph';
disp(' ');
disp([name '.caption = ']);
disp(' ');
disp([' ''' o.caption '''']);
disp(' ');
disp([name '.footnote = ']);
disp(' ');
disp([' ''' o.footnote '''']);
disp(' ');
disp([name '.filename = ']);
disp(' ');
disp([' ''' o.filename '''']);
end

View File

@ -0,0 +1,66 @@
function o = graph(varargin)
%function o = graph(varargin)
% Graph Class Constructor
%
% INPUTS
% 0 args => empty graph
% 1 arg (graph class) => copy object
%
% 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;
o.caption = '';
o.footnote = '';
o.filename = '';
o.data = '';
o.config = '';
if nargin == 1
assert(isa(varargin{1}, 'graph'),['With one arg to Graph constructor, ' ...
'you must pass a graph object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['Options to Graph constructor must be supplied in name/value ' ...
'pairs.']);
end
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
o.(field) = pair{2};
else
error('%s is not a recognized option to the Graph constructor.', ...
field);
end
end
end
% Create graph object
o = class(o, 'graph');
end

View File

@ -0,0 +1,42 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% 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/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['field ' S.subs 'does not exist in the page class'])
end
otherwise
error('report subsasign syntax error')
end
end

View File

@ -0,0 +1,46 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% 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/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S);
else
A = feval(S(1).subs, A);
end
otherwise
error(['Graph Class: unknown field or method: ' S(1).subs]);
end
case {'()', '{}'}
error(['Graph Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Graph Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,40 @@
function write(o, fid, texIndent)
%function write(o, fid)
% Write a Page object
%
% INPUTS
% none
%
% 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/>.
assert(fid > 0);
assert(isnumeric(texIndent));
fprintf(fid, '%d\% Page Object\n', texIndent);
fprintf(fid, '%d\newpage\n', texIndent);
o.sections.write(fid, texIndent+2);
fprintf(fid, '%d\% End Page Object\n', texIndent);
end

View File

@ -8,7 +8,7 @@ function p = addSection(p, varargin)
% 3 args => add section at index
%
% OUTPUTS
% updated report object
% updated page object
%
% SPECIAL REQUIREMENTS
% none

View File

@ -1,5 +1,5 @@
function p = page(varargin)
%function p = page(varargin)
function o = page(varargin)
%function o = page(varargin)
% Page Class Constructor
%
% INPUTS
@ -29,17 +29,36 @@ function p = page(varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
p = struct;
p.sections = sections();
o = struct;
o.caption = '';
o.orientation = 'portrait';
o.sections = sections();
switch nargin
case 0
p = class(p, 'page');
case 1
assert(isa(varargin{1}, 'page'), ['Page constructor: the only valid ' ...
'arguments are page objects']);
p = varargin{1};
otherwise
error('Page constructor: invalid number of arguments');
if nargin == 1
assert(isa(varargin{1}, 'page'),['With one arg to Page constructor, ' ...
'you must pass a page object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['Options to Page constructor must be supplied in name/value ' ...
'pairs.']);
end
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
o.(field) = pair{2};
else
error('%s is not a recognized option to the Page constructor.', ...
field);
end
end
end
% Create page object
o = class(o, 'page');
end
end

View File

@ -23,6 +23,13 @@ switch S(1).type
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});

View File

@ -0,0 +1,44 @@
function write(o, fid, indent)
%function write(o, fid, indent)
% Write a Page object
%
% INPUTS
% fid - int, file id
% indent - char, number of spaces to indent tex code
%
% 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/>.
assert(fid ~= -1);
fprintf(fid, '\n%s%% Page Object\n', indent);
if strcmpi(o.orientation, 'landscape')
fprintf(fid, '%s\\begin{landscape}\n', indent);
end
o.sections.write(fid, addIndentation(indent));
if strcmpi(o.orientation, 'landscape')
fprintf(fid, '%s\\end{landscape}\n', indent);
end
fprintf(fid, '%s\\clearpage\n', indent);
fprintf(fid, '%s%% End Page Object\n\n', indent);
end

View File

@ -34,6 +34,6 @@ switch S.type
assert(isnumeric(index));
B.objArray(index) = V;
otherwise
error('objArray subsasign syntax error')
error('Pages subsasign syntax error');
end
end

View File

@ -23,6 +23,13 @@ switch S(1).type
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});

View File

@ -0,0 +1,39 @@
function write(o, fid, indent)
%function write(o, fid, indent)
% Write Pages object
%
% INPUTS
% fid - int, file id
% indent - char, number of spaces to indent tex code
%
% 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/>.
assert(fid ~= -1);
fprintf(fid, '\n%s%% Pages Object\n', indent);
nps = numPages(o);
for i=1:nps
o.objArray(i).write(fid, addIndentation(indent));
end
fprintf(fid, '%s%% End Pages Object\n\n', indent);
end

View File

@ -33,14 +33,32 @@ disp(' ');
disp([name '.title = ']);
disp(' ');
disp([' ''' o.title '''']);
disp(' ')
disp([name '.paper = ']);
disp(' ');
disp([' ''' o.paper '''']);
disp(' ')
disp([name '.orientation = ']);
disp(' ');
disp([' ''' o.orientation '''']);
disp(' ')
disp([name '.filename = ']);
disp(' ');
disp([' ''' o.filename '''']);
disp(' ')
disp([name '.config = ']);
disp(' ');
disp([' ''' o.config '''']);
disp(' ')
disp([name '.numPages() = ']);
disp(' ');
disp([' ' num2str(numPages(o))]);
disp(' ');
disp([name '.pages = ']);
disp(' ');

View File

@ -1,5 +1,5 @@
function orientation = validateOrientation(orientation)
%function orientation = validateOrientation(orientation)
function validateOrientation(orientation)
%function validateOrientation(orientation)
% Validate orientation string
%
% INPUTS
@ -28,8 +28,6 @@ function orientation = validateOrientation(orientation)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(any(strcmpi(orientation, {'portrait', 'landscape'})), ...
['Valid orientation arguments are: ''portrait'' and ' ...
'''landscape''.']);
orientation = lower(orientation);
assert(any(strcmpi(orientation, {'portrait', 'landscape'})), ['Valid ' ...
'orientation arguments are: ''portrait'' and ''landscape''.']);
end

View File

@ -0,0 +1,33 @@
function validatePaper(paper)
%function validatePaper(paper)
% Validate paper string
%
% INPUTS
% char : paper size
%
% OUTPUTS
% char : lowercase paper
%
% 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/>.
assert(any(strcmpi(paper, {'a4', 'letter'})), ['Valid paper arguments ' ...
'are: ''a4'' and ''letter''.']);
end

View File

@ -1,13 +1,10 @@
function r = report(varargin)
%function r = report(varargin)
function o = report(varargin)
%function o = report(varargin)
% Report Class Constructor
%
% INPUTS
% 0 args => no title, portrait orientation
% 1 arg (report class) => copy class
% 1 arg (not report class) => title
% 2 args (1st not report class) => title, orientation
% 3 args (1st not report class) => title, orientation, configuraiton
% 1 report class object => make a copy
% Otherwise, option/value pairs (see structure below for options)
%
% OUTPUTS
% none
@ -33,51 +30,44 @@ function r = report(varargin)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% default values
r = struct;
r.title = '';
r.orientation = 'portrait';
r.pages = pages();
r.config = '';
o = struct;
o.title = '';
o.orientation = 'portrait';
o.paper = 'a4';
o.pages = pages();
o.filename = 'report.tex';
o.config = '';
% Check arguments
if nargin == 1
assert(isa(varargin{1}, 'report') || ischar(varargin{1}), ...
['With one arg to report constructor, you must pass either '...
'a report object or a char.']);
end
assert(isa(varargin{1}, 'report'),['With one arg to Report constructor, ' ...
'you must pass a report object']);
r = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['Options to Report constructor must be supplied in name/value ' ...
'pairs.']);
end
if nargin > 1
assert(~isa(varargin{1}, 'report'), ...
['With multiple args to report constructor, first argument ' ...
'cannot be a report object.']);
for i=1:nargin
assert(ischar(varargin{i}), ...
['With muliple args to report constructor, all '...
'arguments must be char.']);
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
if strcmp(field, 'orientation')
validateOrientation(pair{2});
elseif strcmp(field, 'paper')
validatePaper(pair{2});
end
o.(field) = pair{2};
else
error('%s is not a recognized option to the Report constructor.', ...
field);
end
end
end
% Initialize fields
switch nargin
case 0
case 1
if isa(varargin{1}, 'report')
r = varargin{1};
return
else
r.title = varargin{1};
end
case 2
r.title = varargin{1};
r.orientation = validateOrientation(varargin{2});
case 3
r.title = varargin{1};
r.orientation = validateOrientation(varargin{2});
r.config = varargin{3};
otherwise
error('Report constructor: invalid number of arguments');
end
% Create report object
r = class(r, 'report');
o = class(o, 'report');
end

View File

@ -23,6 +23,13 @@ switch S(1).type
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
write(A);
end
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});

View File

@ -0,0 +1,56 @@
function write(o)
%function write(o)
% Write Report object
%
% INPUTS
% none
%
% 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/>.
[fid, msg] = fopen(o.filename, 'w');
if fid == -1
error(msg);
end
fprintf(fid, '%% Report Object\n');
fprintf(fid, '\\documentclass[11pt]{article}\n');
fprintf(fid, '\\usepackage[%spaper,margin=2.5cm', o.paper);
if strcmpi(o.orientation, 'landscape')
fprintf(fid, ',landscape');
end
fprintf(fid, ']{geometry}\n');
fprintf(fid, '\\usepackage{graphicx}\n');
fprintf(fid, '\\usepackage{pdflscape}\n')
fprintf(fid, '\\begin{document}\n');
o.pages.write(fid, addIndentation(''));
fprintf(fid, '\\end{document}\n');
fprintf(fid, '%% End Report Object\n');
status = fclose(fid);
if status == -1
error('Error closing %s\n', o.filename);
end
end

View File

@ -0,0 +1,39 @@
function o = addGraph(o, varargin)
%function o = addGraph(o, varargin)
% Add a graph to the Cell Array of graphs in the report
%
% INPUTS
% 1 args => add empty graph
% 2 args => add given graph
% 3 args => add graph at index
%
% OUTPUTS
% updated section object
%
% 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/>.
assert(isa(o, 'section'), 'First argument must be a section object');
if nargin == 1
o.elements = o.elements.addGraph();
elseif nargin == 2 || nargin == 3
o.elements = o.elements.addGraph(varargin{:});
end
end

View File

@ -0,0 +1,39 @@
function o = addTable(o, varargin)
%function o = addTable(o, varargin)
% Add a table to the Cell Array of tables in the report
%
% INPUTS
% 1 args => add empty table
% 2 args => add given table
% 3 args => add table at index
%
% OUTPUTS
% updated section object
%
% 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/>.
assert(isa(o, 'section'), 'First argument must be a section object');
if nargin == 1
o.elements = o.elements.addTable();
elseif nargin == 2 || nargin == 3
o.elements = o.elements.addTable(varargin{:});
end
end

View File

@ -30,5 +30,13 @@ function display(o)
name = 'report.page.section';
disp(' ');
disp([name '.x = ']);
disp([name '.align = ']);
disp(' ');
disp([' ''' o.align '''']);
disp(' ');
disp([name '.elements = ']);
disp(' ');
disp(o.elements.getElements());
end

View File

@ -0,0 +1,22 @@
function n = numElements(o)
% function n = numElements(o)
% 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/>.
n = o.elements.numElements();
end

View File

@ -1,5 +1,7 @@
function s = section(varargin)
%function s = section(varargin)
function o = section(varargin)
%function o = section(varargin)
% Section produces a latex minipage
% Copyright (C) 2013 Dynare Team
%
@ -18,15 +20,39 @@ function s = section(varargin)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
switch nargin
case 0
s = class(struct, 'section', objArray());
case 1
assert(isa(varargin{1}, 'section'), ['Section constructor: the only ' ...
'valid arguments are section objects']);
s = varargin{1};
otherwise
error('Section constructor: invalid number of arguments');
end
o = struct;
o.align = 't';
o.elements = elements();
o.rows = 1;
o.cols = 1;
if nargin == 1
assert(isa(varargin{1}, 'section'),['With one arg to Section constructor, ' ...
'you must pass a section object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['Options to Section constructor must be supplied in name/' ...
'value pairs.']);
end
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
o.(field) = pair{2};
else
error('%s is not a recognized option to the Section constructor.', ...
field);
end
end
end
% Create section object
o = class(o, 'section');
end

View File

@ -23,6 +23,13 @@ switch S(1).type
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
@ -34,7 +41,7 @@ switch S(1).type
error(['Section Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getSections(A, S(1).subs{:});
A = getElements(A, S(1).subs{:});
case '{}'
error(['Section Class: ' S(1).type ' indexing not supported.']);
otherwise

View File

@ -0,0 +1,44 @@
function write(o, fid, indent)
%function write(o, fid, indent)
% Write Section object
%
% INPUTS
% fid - int, file id
% indent - char, number of spaces to indent tex code
%
% 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/>.
assert(fid ~= -1);
fprintf(fid, '\n%s%% Section Object\n', indent);
fprintf(fid, '%s\\noindent\\begin{minipage}[%s]{0.32\\hsize}\n', indent, o.align);
ne = numElements(o);
for i=1:ne
o.elements(i).write(fid, addIndentation(indent));
end
fprintf(fid, '%s\\end{minipage}\n', indent);
fprintf(fid, '%s%% End Section Object\n\n', indent);
end

View File

@ -32,7 +32,7 @@ switch S.type
case '()'
index = S.subs{:};
assert(isnumeric(index));
B(index) = V;
B.objArray(index) = V;
otherwise
error('objArray subsasign syntax error')
end

View File

@ -23,6 +23,13 @@ switch S(1).type
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case {'write'}
if areParensNext(S)
write(A, S(2).subs{:})
S = shiftS(S);
else
assert(false);
end
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});

View File

@ -0,0 +1,39 @@
function write(o, fid, indent)
%function write(o, fid, indent)
% Write Sections object
%
% INPUTS
% fid - int, file id
% indent - char, number of spaces to indent tex code
%
% 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/>.
assert(fid ~= -1);
fprintf(fid, '\n%s%% Sections Object\n', indent);
nps = numSections(o);
for i=1:nps
o.objArray(i).write(fid, indent);
end
fprintf(fid, '%s%% End Sections Object\n\n', indent);
end

View File

@ -0,0 +1,57 @@
function display(o)
%function display(o)
% Display a Table object
%
% INPUTS
% none
%
% 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/>.
name = 'report.page.section.table';
disp(' ');
disp([name '.caption = ']);
disp(' ');
disp([' ''' o.caption '''']);
disp(' ');
disp([name '.footnote = ']);
disp(' ');
disp([' ''' o.footnote '''']);
disp(' ');
disp([name '.hlines = ']);
disp(' ');
disp([' ''' o.hlines '''']);
disp(' ');
disp([name '.vlines = ']);
disp(' ');
disp([' ''' o.vlines '''']);
disp(' ');
disp([name '.data = ']);
disp(' ');
disp([' ''' o.data '''']);
end

View File

@ -0,0 +1,42 @@
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% 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/>.
B = A;
if length(S) > 1
for i=1:(length(S)-1)
B = subsref(B, S(i));
end
B = subsasgn(B, S(end), V);
B = subsasgn(A, S(1:(end-1)), B);
return
end
switch S.type
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['field ' S.subs 'does not exist in the page class'])
end
otherwise
error('report subsasign syntax error')
end
end

View File

@ -0,0 +1,46 @@
function A = subsref(A, S)
%function A = subsref(A, S)
% 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/>.
switch S(1).type
case '.'
switch S(1).subs
case fieldnames(A)
A = A.(S(1).subs);
case methods(A)
if areParensNext(S)
A = feval(S(1).subs, A, S(2).subs{:});
S = shiftS(S);
else
A = feval(S(1).subs, A);
end
otherwise
error(['Table Class: unknown field or method: ' S(1).subs]);
end
case {'()', '{}'}
error(['Table Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Table Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,66 @@
function o = table(varargin)
%function o = table(varargin)
% Table Class Constructor
%
% INPUTS
% 0 args => empty table
% 1 arg (table class) => copy object
%
% 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;
o.caption = '';
o.footnote = '';
o.hlines = false;
o.vlines = false;
o.data = '';
if nargin == 1
assert(isa(varargin{1}, 'table'),['With one arg to Table constructor, ' ...
'you must pass a table object']);
o = varargin{1};
return;
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['Options to Table constructor must be supplied in name/value ' ...
'pairs.']);
end
optNames = lower(fieldnames(o));
% overwrite default values
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
o.(field) = pair{2};
else
error('%s is not a recognized option to the Table constructor.', ...
field);
end
end
end
% Create table object
o = class(o, 'table');
end

View File

@ -0,0 +1,40 @@
function write(o, fid, texIndent)
%function write(o, fid)
% Write a Page object
%
% INPUTS
% none
%
% 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/>.
assert(fid > 0);
assert(isnumeric(texIndent));
fprintf(fid, '%d\% Page Object\n', texIndent);
fprintf(fid, '%d\newpage\n', texIndent);
o.sections.write(fid, texIndent+2);
fprintf(fid, '%d\% End Page Object\n', texIndent);
end

View File

@ -0,0 +1,31 @@
function spaces=addIndentation(spaces)
% Return new level of indentation for latex output
%
% INPUTS
% spaces - char, current level of indentation
%
% OUTPUTS
% spaces - char, new level of indentation
%
% 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/>.
spaces = [spaces ' '];
end