reporting (WIP)

time-shift
Houtan Bastani 2013-02-12 14:23:41 +01:00
parent 73218bd88e
commit fe5f61db61
40 changed files with 1445 additions and 0 deletions

View File

@ -62,6 +62,7 @@ addpath([dynareroot '/utilities/tests/'])
addpath([dynareroot '/utilities/dates/'])
addpath([dynareroot '/utilities/dataset/'])
addpath([dynareroot '/utilities/general/'])
addpath([dynareroot '/reports/'])
% For functions that exist only under some Octave versions
% or some MATLAB versions, and for which we provide some replacement functions

View File

@ -0,0 +1,32 @@
function oa = addObj(oa, varargin)
%function oa = addObj(oa, 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 >= 2 && nargin <= 3)
assert(isa(oa, 'objArray'), 'First argument must be an objArray');
assert(isobject(varargin{1}), 'Optional 2nd arg must be an object');
if nargin == 3
assert(isnumeric(varargin{2}), 'Optional 3rd arg must be an index');
end
if nargin == 2
oa.objs{end+1} = varargin{1};
elseif nargin == 3
oa.objs{varargin{2}} = varargin{1};
end

View File

@ -0,0 +1,35 @@
function display(oa)
%function display(oa)
% Display an objArray 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/>.
disp(' ');
disp([inputname(1) '.objs = ']);
disp(' ');
disp(oa.objs);
end

View File

@ -0,0 +1,29 @@
function e = getObjs(oa, varargin)
%function e = getObjs(oa, 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/>.
switch nargin
case 1
e = oa.objs;
case 2
e = oa.objs{varargin{1}};
otherwise
error('objArray getObjs: invalid number of arguments');
end
end

View File

@ -0,0 +1,22 @@
function no = numObjs(oa)
%function no = numObjs(oa)
% 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/>.
no = size(oa.objs, 2);
end

View File

@ -0,0 +1,43 @@
function oa = objArray(varargin)
%function oa = objArray(varargin)
% ObjArray Class Constructor
%
% 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/>.
switch nargin
case 0
oa = struct;
oa.objs = cell(0);
oa = class(oa, 'objArray');
case 1
assert(isa(varargin{1}, 'objArray'), ['ObjArray constructor: the only ' ...
'valid arguments are objArray objects']);
oa = varargin{1};
otherwise
error('ObjArray constructor: invalid number of arguments');
end
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.objs{index} = V;
otherwise
error('objArray subsasgn 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(['ObjArray Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getObjs(A, S(1).subs{:});
case '{}'
error(['ObjArray Class: ' S(1).type ' indexing not supported.']);
otherwise
error('ObjArray Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,50 @@
function p = addSection(p, varargin)
%function p = addSection(p, varargin)
% Add a section to the Cell Array of sections in the report
%
% INPUTS
% 1 args => add empty section
% 2 args => add given section
% 3 args => add section at index
%
% OUTPUTS
% updated report 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(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
'to addSection']);
assert(isa(p, 'page'), 'First argument must be a page object');
if nargin > 1
assert(isa(varargin{1},'section'), ['Optional 2nd arg to addSection must be a ' ...
'Section']);
if nargin > 2
assert(isnumeric(varargin{2}), ['Optional 3rd arg to addSection must be ' ...
'an index']);
end
end
if nargin == 1
p.sections = p.sections.addSection(section());
elseif nargin == 2 || nargin == 3
p.sections = p.sections.addSection(varargin{:});
end
end

View File

@ -0,0 +1,32 @@
function ns = numSections(p)
%function ns = numSections(p)
% return the number of sections currently in the page
%
% 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/>.
ns = p.sections.numSections();
end

View File

@ -0,0 +1,45 @@
function p = page(varargin)
%function p = page(varargin)
% Page Class Constructor
%
% INPUTS
% 0 args => empty page
% 1 arg (page 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/>.
p = struct;
p.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');
end
end

View File

@ -0,0 +1,46 @@
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{index} = V;
case '.'
switch S.subs
case fields(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,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(['Page Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getSections(A, S(1).subs{:});
case '{}'
error(['Page Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Page Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,27 @@
function ps = addPage(ps, varargin)
% function ps = addPage(ps, 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
ps.objArray = ps.objArray.addObj(page());
else
ps.objArray = ps.objArray.addObj(varargin{:});
end
end

View File

@ -0,0 +1,22 @@
function e = getPages(ps, varargin)
% function e = getPages(ps, 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/>.
e = ps.objArray.getObjs(varargin{:});
end

View File

@ -0,0 +1,22 @@
function np = numPages(ps)
% function np = numPages(ps)
% 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/>.
np = ps.objArray.numObjs();
end

View File

@ -0,0 +1,42 @@
function ps = pages(varargin)
%function ps = pages(varargin)
% Pages Class Constructor
%
% INPUTS
% Optional pages object
%
% OUTPUTS
% pages 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
ps = class(struct, 'pages', objArray());
case 1
assert(isa(varargin{1}, 'pages'), ...
['With one arg to pages constructor, you must pass an ' ...
'pages object or a char.']);
ps = varargin{1};
otherwise
error('Pages constructor: invalid number of arguments');
end
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('objArray 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(['Pages Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getPages(A, S(1).subs{:});
case '{}'
error(['Pages Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Pages Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,50 @@
function r = addPage(r, varargin)
%function r = addPage(r, varargin)
% Add a page to the Cell Array of pages in the report
%
% INPUTS
% 1 args => add empty page
% 2 args => add given page
% 3 args => add page at index
%
% OUTPUTS
% updated report 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(nargin >= 1 && nargin <= 3, ['incorrect number of arguments passed ' ...
'to addPage']);
assert(isa(r, 'report'), 'First argument must be a report object');
if nargin > 1
assert(isa(varargin{1},'page'), ['Optional 2nd arg to addPage must be a ' ...
'Page']);
if nargin > 2
assert(isnumeric(varargin{2}), ['Optional 3rd arg to addPage must be ' ...
'an index']);
end
end
if nargin == 1
r.pages = r.pages.addPage(page());
elseif nargin == 2 || nargin == 3
r.pages = r.pages.addPage(varargin{:});
end
end

View File

@ -0,0 +1,47 @@
function display(r)
%function display(r)
% Display a 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/>.
disp(' ');
disp([inputname(1) '.title = ']);
disp(' ');
disp([' ''' r.title '''']);
disp(' ')
disp([inputname(1) '.orientation = ']);
disp(' ');
disp([' ''' r.orientation '''']);
disp(' ')
disp([inputname(1) '.numPages() = ']);
disp(' ');
disp([' ' num2str(numPages(r))]);
disp(' ');
disp([inputname(1) '.pages = ']);
disp(' ');
disp(r.pages.getPages());
end

View File

@ -0,0 +1,32 @@
function np = numPages(r)
%function np = numPages(r)
% return the number of pages currently in the report
%
% 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/>.
np = r.pages.numPages();
end

View File

@ -0,0 +1,35 @@
function orientation = validateOrientation(orientation)
%function orientation = validateOrientation(orientation)
% Validate orientation string
%
% INPUTS
% char : the orientation
%
% OUTPUTS
% char : lowercase orientation
%
% 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(orientation, {'portrait', 'landscape'})), ...
['Valid orientation arguments are: ''portrait'' and ' ...
'''landscape''.']);
orientation = lower(orientation);
end

View File

@ -0,0 +1,83 @@
function r = report(varargin)
%function r = 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
%
% 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/>.
% default values
r = struct;
r.title = '';
r.orientation = 'portrait';
r.pages = pages();
r.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
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.']);
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');
end

View File

@ -0,0 +1,46 @@
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.pages(index) = V;
case '.'
switch S.subs
case fields(A)
B.(S.subs) = V;
otherwise
error(['field ' S.subs 'does not exist in the report class']);
end
otherwise
error('report subsasign syntax error');
end
end

View File

@ -0,0 +1,50 @@
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(['Report Class: unknown field or method: ' S(1).subs]);
end
case '()'
index = S(1).subs{:};
assert(isnumeric(index));
A = A(index);
case '{}'
error(['Report Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Report Class: subsref.m impossible case');
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,27 @@
function ss = addSection(ss, varargin)
% function ss = addSection(ss, 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
ss.objArray = ss.objArray.addObj(section());
else
ss.objArray = ss.objArray.addObj(varargin{:});
end
end

View File

@ -0,0 +1,22 @@
function e = getSections(ss, varargin)
% function e = getSections(ss, 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/>.
e = ss.objArray.getObjs(varargin{:});
end

View File

@ -0,0 +1,22 @@
function ns = numSections(ss)
% function ns = numSections(ss)
% 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/>.
ns = ss.objArray.numObjs();
end

View File

@ -0,0 +1,32 @@
function s = section(varargin)
%function s = section(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/>.
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
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(index) = V;
otherwise
error('objArray 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(['Section Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getSections(A, S(1).subs{:});
case '{}'
error(['Section Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Section Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,27 @@
function ss = addSection(ss, varargin)
% function ss = addSection(ss, 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
ss.objArray = ss.objArray.addObj(section());
else
ss.objArray = ss.objArray.addObj(varargin{:});
end
end

View File

@ -0,0 +1,22 @@
function e = getSections(ss, varargin)
% function e = getSections(ss, 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/>.
e = ss.objArray.getObjs(varargin{:});
end

View File

@ -0,0 +1,22 @@
function ns = numSections(ss)
% function ns = numSections(ss)
% 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/>.
ns = ss.objArray.numObjs();
end

View File

@ -0,0 +1,32 @@
function s = sections(varargin)
%function s = sections(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/>.
switch nargin
case 0
s = class(struct, 'sections', objArray());
case 1
assert(isa(varargin{1}, 'sections'), ['Sections constructor: the only ' ...
'valid arguments are sections objects']);
s = varargin{1};
otherwise
error('Sections constructor: invalid number of arguments');
end
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(index) = V;
otherwise
error('objArray 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(['Sections Class: unknown field or method: ' S(1).subs]);
end
case '()'
A = getSections(A, S(1).subs{:});
case '{}'
error(['Sections Class: ' S(1).type ' indexing not supported.']);
otherwise
error('Sections Class: subsref.m impossible case')
end
S = shiftS(S);
if length(S) >= 1
A = subsref(A, S);
end
end

View File

@ -0,0 +1,26 @@
function tf = areParensNext(S)
%function tf = areParensNext(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/>.
if length(S) > 1 && strcmp(S(2).type, '()')
tf = true;
else
tf = false;
end
end

26
matlab/reports/shiftS.m Normal file
View File

@ -0,0 +1,26 @@
function S = shiftS(S)
%function S = shiftS(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/>.
if length(S) > 1
S = S(2:end);
else
S = {};
end
end