convert to classdef. closes #10 closes #9

parent 240b6f57
before_script: before_script:
- git clone https://git.dynare.org/Dynare/dynare.git
- git clone https://git.dynare.org/Dynare/dseries.git - git clone https://git.dynare.org/Dynare/dseries.git
testsuite_matlab: testsuite_matlab:
......
...@@ -5,7 +5,7 @@ all: check-octave check-matlab ...@@ -5,7 +5,7 @@ all: check-octave check-matlab
check-octave: check-octave:
@cd test ;\ @cd test ;\
$(OCTAVE) --silent --no-history runtest.m && [ -f report.pdf ] $(OCTAVE) --no-init-file --silent --no-history --eval "addpath([pwd() '/../dseries/src']); addpath([pwd() '/../src']); runtest;" && [ -f report.pdf ]
check-matlab: check-matlab:
@$(MATLAB) -nosplash -nodisplay -r "cd test; runtest; quit" && [ -f test/report.pdf ] @$(MATLAB) -nosplash -nodisplay -r "addpath dseries/src; addpath src; cd test; runtest; quit" && [ -f test/report.pdf ]
% Script to set the necessary paths for the Reporting toolbox
% Copyright (C) 2015-2017 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/>.
% Find reporting source directory
reporting_src_root = [strrep(which('initialize_reporting_toolbox'),'initialize_reporting_toolbox.m','') 'src'];
% Add path to reporting source
addpath(reporting_src_root);
addpath([reporting_src_root filesep '..' filesep 'macros']);
% Reminder to add and initialize dates & dseries toolboxes
if ~exist('emptydatesobject', 'var')
disp('Remember to add the paths to the dates toolbox before working with the reporting toolbox');
end
if ~exist('emptydseriesobject', 'var')
disp('Remember to add the paths to the dseries toolbox before working with the reporting toolbox');
end
function o = addSeries(o, varargin) function o = addSeries(o, varargin)
% function o = addSeries(o, varargin) %function o = addSeries(o, varargin)
% Add a series
%
% INPUTS
% o [graph] graph object
% varargin arguments to report_series()
%
% OUTPUTS
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2013-2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
......
This diff is collapsed.
function B = subsasgn(A, S, V)
% function B = subsasgn(A, S, V)
% Copyright (C) 2013-2017 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.series{index} = V;
case '.'
switch S.subs
case fieldnames(A)
B.(S.subs) = V;
otherwise
error(['@graph.subsasgn: field ' S.subs 'does not exist']);
end
case '{}'
assert(isint(S.subs{1}));
B{S.subs{1}} = V;
otherwise
error('@graph.subsasgn: syntax error');
end
end
\ No newline at end of file
function A = subsref(A, S)
%function A = subsref(A, S)
% Copyright (C) 2013-2017 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,1);
else
A = feval(S(1).subs, A);
end
otherwise
error(['@graph.subsref: unknown field or method: ' S(1).subs]);
end
case '()'
if isempty(S(1).subs{:})
A = A.series;
else
assert(isnumeric(S(1).subs{:}));
A = A.series{S(1).subs{:}};
end
case '{}'
A = A.series{S(1).subs{:}};
otherwise
error('@graph.subsref: impossible case')
end
S = shiftS(S,1);
if length(S) >= 1
A = subsref(A, S);
end
end
function o = write(o, fid, pg, sec, row, col) function write(o, fid, pg, sec, row, col)
%function o = write(o, fid, pg, sec, row, col) %function write(o, fid, pg, sec, row, col)
% Write a Graph object % Write a Graph object
% %
% INPUTS % INPUTS
...@@ -16,7 +16,7 @@ function o = write(o, fid, pg, sec, row, col) ...@@ -16,7 +16,7 @@ function o = write(o, fid, pg, sec, row, col)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2013-2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -34,6 +34,6 @@ function o = write(o, fid, pg, sec, row, col) ...@@ -34,6 +34,6 @@ function o = write(o, fid, pg, sec, row, col)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid ~= -1); assert(fid ~= -1);
o = writeGraphFile(o, pg, sec, row, col); graphName = writeGraphFile(o, pg, sec, row, col);
fprintf(fid, '\\input{%s}', o.graphName); fprintf(fid, '\\input{%s}', graphName);
end end
\ No newline at end of file
function o = writeGraphFile(o, pg, sec, row, col) function graphName = writeGraphFile(o, pg, sec, row, col)
%function o = writeGraphFile(o, pg, sec, row, col) %function graphName = writeGraphFile(o, pg, sec, row, col)
% Write the tikz file that contains the graph % Write the tikz file that contains the graph
% %
% INPUTS % INPUTS
...@@ -10,7 +10,7 @@ function o = writeGraphFile(o, pg, sec, row, col) ...@@ -10,7 +10,7 @@ function o = writeGraphFile(o, pg, sec, row, col)
% col [integer] this col number % col [integer] this col number
% %
% OUTPUTS % OUTPUTS
% o [graph] graph object % graphName [string] name of graph written
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
...@@ -35,16 +35,16 @@ function o = writeGraphFile(o, pg, sec, row, col) ...@@ -35,16 +35,16 @@ function o = writeGraphFile(o, pg, sec, row, col)
ne = length(o.series); ne = length(o.series);
if ne < 1 if ne < 1
warning('@graph.writeGraphFile: no series to plot, returning'); warning('@graph.writeGraphFile: no series to plot, returning');
return; return
end end
if isempty(o.graphName) if isempty(o.graphName)
o.graphName = sprintf('%s/graph_pg%d_sec%d_row%d_col%d.tex', o.graphDirName, pg, sec, row, col); graphName = sprintf('%s/graph_pg%d_sec%d_row%d_col%d.tex', o.graphDirName, pg, sec, row, col);
else else
o.graphName = [o.graphDirName '/' o.graphName]; graphName = [o.graphDirName '/' o.graphName];
end end
[fid, msg] = fopen(o.graphName, 'w'); [fid, msg] = fopen(graphName, 'w');
if fid == -1 if fid == -1
error(['@graph.writeGraphFile: ' msg]); error(['@graph.writeGraphFile: ' msg]);
end end
......
function display(o) function o = addData(o, varargin)
%function display(o) %function o = addData(o, varargin)
% Display a Report object % Add a series
% %
% INPUTS % INPUTS
% o [report] report object % o [page] page object
% varargin arguments to report_data()
% %
% OUTPUTS % OUTPUTS
% none % updated section object
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,5 +29,7 @@ function display(o) ...@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o); assert(~isempty(o.sections), ...
'@page.addData: Before adding data, you must add a section.');
o.sections{end}.addData(varargin{:});
end end
function display(o) function o = addGraph(o, varargin)
%function display(o) %function o = addGraph(o, varargin)
% Display a Graph object % Add a report_table
% %
% INPUTS % INPUTS
% o [graph] graph object % o [page] page object
% varargin arguments to graph()
% %
% OUTPUTS % OUTPUTS
% none % updated section object
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,5 +29,7 @@ function display(o) ...@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o); assert(~isempty(o.sections), ...
'@page.addGraph: Before adding a graph, you must add a section.');
o.sections{end}.addGraph(varargin{:});
end end
function tf = allCellsAreDates(dcell) function o = addParagraph(o, varargin)
%function tf = allCellsAreDates(dcell) %function o = addParagraph(o, varargin)
% Determines if all the elements of dcell are dates objects % Add a series
% %
% INPUTS % INPUTS
% dcell cell of dates objects % o [page] page object
% varargin arguments to paragraph()
% %
% OUTPUTS % OUTPUTS
% tf true if every entry of dcell is a dates object % updated section object
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2014-2015 Dynare Team % Copyright (C) 2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,12 +29,7 @@ function tf = allCellsAreDates(dcell) ...@@ -28,12 +29,7 @@ function tf = allCellsAreDates(dcell)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(iscell(dcell)); assert(~isempty(o.sections), ...
tf = true; '@page.addParagraph: Before adding a paragraph, you must add a section.');
for i=1:length(dcell) o.sections{end}.addParagraph(varargin{:});
if ~isdates(dcell{i})
tf = false;
return;
end
end
end end
function p = addSection(p, varargin) function o = addSection(o, varargin)
%function p = addSection(p, varargin) %function o = addSection(o, varargin)
% Add a section to the Cell Array of sections in the report % Add a section
% %
% INPUTS % INPUTS
% 1 args => add empty section % o [page] page object
% 2 args => add given section % varargin arguments to section()
% 3 args => add section at index
% %
% OUTPUTS % OUTPUTS
% updated page object % updated page object
...@@ -13,7 +12,7 @@ function p = addSection(p, varargin) ...@@ -13,7 +12,7 @@ function p = addSection(p, varargin)
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2013-2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -30,5 +29,5 @@ function p = addSection(p, varargin) ...@@ -30,5 +29,5 @@ function p = addSection(p, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
p.sections{end+1} = section(varargin{:}); o.sections{end+1} = section(varargin{:});
end end
function display(o) function o = addSeries(o, varargin)
%function display(o) %function o = addSeries(o, varargin)
% Display a Page object % Add a series
% %
% INPUTS % INPUTS
% o [page] page object % o [page] page object
% varargin arguments to report_series()
% %
% OUTPUTS % OUTPUTS
% none % updated section object
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2013-2015 Dynare Team % Copyright (C) 2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,5 +29,7 @@ function display(o) ...@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o); assert(~isempty(o.sections), ...
'@page.addSeries: Before adding a series, you must add a section.');
o.sections{end}.addSeries(varargin{:});
end end
function o = addTable(o, varargin)
%function o = addTable(o, varargin)
% Add a report_table
%
% INPUTS
% o [page] page object
% varargin arguments to report_table()
%
% OUTPUTS
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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(~isempty(o.sections), ...
'@page.addTable: Before adding a table, you must add a section.');
o.sections{end}.addTable(varargin{:});
end
function display(o) function o = addVspace(o, varargin)
%function display(o) %function o = addVspace(o, varargin)
% Display a Paragraph object % Add a vspace
% %
% INPUTS % INPUTS
% o [paragraph] paragraph object % o [page] page object
% varargin arguments to vspace()
% %
% OUTPUTS % OUTPUTS
% none % updated section object
% %
% SPECIAL REQUIREMENTS % SPECIAL REQUIREMENTS
% none % none
% Copyright (C) 2014-2015 Dynare Team % Copyright (C) 2019 Dynare Team
% %
% This file is part of Dynare. % This file is part of Dynare.
% %
...@@ -28,5 +29,7 @@ function display(o) ...@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o); assert(~isempty(o.sections), ...
'@page.addVspace: Before adding a vspace, you must add a section.');
o.sections{end}.addVspace(varargin{:});
end end
function o = page(varargin) classdef page < handle
%function o = page(varargin) % page Class
% Page Class Constructor %
% % Copyright (C) 2013-2019 Dynare Team
% INPUTS %
% 0 args => empty page % This file is part of Dynare.
% 1 arg (page class) => copy object %
% % Dynare is free software: you can redistribute it and/or modify
% OUTPUTS % it under the terms of the GNU General Public License as published by
% none % the Free Software Foundation, either version 3 of the License, or
% % (at your option) any later version.
% SPECIAL REQUIREMENTS %
% none % Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% Copyright (C) 2013-2017 Dynare Team % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% % GNU General Public License for more details.
% This file is part of Dynare. %
% % You should have received a copy of the GNU General Public License
% Dynare is free software: you can redistribute it and/or modify % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% it under the terms of the GNU General Public License as published by properties (Access = private, Constant = true)
% the Free Software Foundation, either version 3 of the License, or titleFormatDefalut = {'\large\bfseries'}
% (at your option) any later version. end
% properties (Access = private)
% Dynare is distributed in the hope that it will be useful, sections = {}
% but WITHOUT ANY WARRANTY; without even the implied warranty of end
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the properties (SetAccess = private)
% GNU General Public License for more details. paper = '' % Paper size. Default: `a4'.