Skip to content
Snippets Groups Projects
Commit ff4a155f authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting (WIP)

parent 95e2dd07
Branches
No related tags found
No related merge requests found
Showing
with 574 additions and 26 deletions
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
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
\ No newline at end of file
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
\ No newline at end of file
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
\ No newline at end of file
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
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
\ No newline at end of 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
......
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
\ No newline at end of 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{:});
......
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
\ No newline at end of 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
\ No newline at end of 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{:});
......
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
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment