convert to classdef. closes #10 closes #9

parent 240b6f57
before_script:
- git clone https://git.dynare.org/Dynare/dynare.git
- git clone https://git.dynare.org/Dynare/dseries.git
testsuite_matlab:
......
......@@ -5,7 +5,7 @@ all: check-octave check-matlab
check-octave:
@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:
@$(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)
% 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 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 o = write(o, fid, pg, sec, row, col)
function write(o, fid, pg, sec, row, col)
%function write(o, fid, pg, sec, row, col)
% Write a Graph object
%
% INPUTS
......@@ -16,7 +16,7 @@ function o = write(o, fid, pg, sec, row, col)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team
% Copyright (C) 2013-2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -34,6 +34,6 @@ function o = write(o, fid, pg, sec, row, col)
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(fid ~= -1);
o = writeGraphFile(o, pg, sec, row, col);
fprintf(fid, '\\input{%s}', o.graphName);
graphName = writeGraphFile(o, pg, sec, row, col);
fprintf(fid, '\\input{%s}', graphName);
end
\ No newline at end of file
function o = writeGraphFile(o, pg, sec, row, col)
%function o = writeGraphFile(o, pg, sec, row, col)
function graphName = writeGraphFile(o, pg, sec, row, col)
%function graphName = writeGraphFile(o, pg, sec, row, col)
% Write the tikz file that contains the graph
%
% INPUTS
......@@ -10,7 +10,7 @@ function o = writeGraphFile(o, pg, sec, row, col)
% col [integer] this col number
%
% OUTPUTS
% o [graph] graph object
% graphName [string] name of graph written
%
% SPECIAL REQUIREMENTS
% none
......@@ -35,16 +35,16 @@ function o = writeGraphFile(o, pg, sec, row, col)
ne = length(o.series);
if ne < 1
warning('@graph.writeGraphFile: no series to plot, returning');
return;
return
end
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
o.graphName = [o.graphDirName '/' o.graphName];
graphName = [o.graphDirName '/' o.graphName];
end
[fid, msg] = fopen(o.graphName, 'w');
[fid, msg] = fopen(graphName, 'w');
if fid == -1
error(['@graph.writeGraphFile: ' msg]);
end
......@@ -301,17 +301,17 @@ for i=1:ne
o.series{i}.writeSeriesForGraph(fid, dd, i);
if o.writeCSV
csvseries = [csvseries ...
o.series{i}.data(dd).set_names([...
o.series{i}.data.name{:} '_' ...
o.series{i}.graphLegendName '_' ...
o.series{i}.graphLineColor '_' ...
o.series{i}.graphLineStyle '_' ...
num2str(o.series{i}.graphLineWidth) '_' ...
o.series{i}.graphMarker '_' ...
o.series{i}.graphMarkerEdgeColor '_' ...
o.series{i}.graphMarkerFaceColor '_' ...
num2str(o.series{i}.graphMarkerSize)]) ...
];
o.series{i}.data(dd).set_names([...
o.series{i}.data.name{:} '_' ...
o.series{i}.graphLegendName '_' ...
o.series{i}.graphLineColor '_' ...
o.series{i}.graphLineStyle '_' ...
num2str(o.series{i}.graphLineWidth) '_' ...
o.series{i}.graphMarker '_' ...
o.series{i}.graphMarkerEdgeColor '_' ...
o.series{i}.graphMarkerFaceColor '_' ...
num2str(o.series{i}.graphMarkerSize)]) ...
];
end
if o.showLegend
le = o.series{i}.getNameForLegend();
......
function display(o)
%function display(o)
% Display a Report object
function o = addData(o, varargin)
%function o = addData(o, varargin)
% Add a series
%
% INPUTS
% o [report] report object
% o [page] page object
% varargin arguments to report_data()
%
% OUTPUTS
% none
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o);
end
\ No newline at end of file
assert(~isempty(o.sections), ...
'@page.addData: Before adding data, you must add a section.');
o.sections{end}.addData(varargin{:});
end
function display(o)
%function display(o)
% Display a Graph object
function o = addGraph(o, varargin)
%function o = addGraph(o, varargin)
% Add a report_table
%
% INPUTS
% o [graph] graph object
% o [page] page object
% varargin arguments to graph()
%
% OUTPUTS
% none
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o);
end
\ No newline at end of file
assert(~isempty(o.sections), ...
'@page.addGraph: Before adding a graph, you must add a section.');
o.sections{end}.addGraph(varargin{:});
end
function tf = allCellsAreDates(dcell)
%function tf = allCellsAreDates(dcell)
% Determines if all the elements of dcell are dates objects
function o = addParagraph(o, varargin)
%function o = addParagraph(o, varargin)
% Add a series
%
% INPUTS
% dcell cell of dates objects
% o [page] page object
% varargin arguments to paragraph()
%
% OUTPUTS
% tf true if every entry of dcell is a dates object
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014-2015 Dynare Team
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,12 +29,7 @@ function tf = allCellsAreDates(dcell)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
assert(iscell(dcell));
tf = true;
for i=1:length(dcell)
if ~isdates(dcell{i})
tf = false;
return;
end
assert(~isempty(o.sections), ...
'@page.addParagraph: Before adding a paragraph, you must add a section.');
o.sections{end}.addParagraph(varargin{:});
end
end
\ No newline at end of file
function p = addSection(p, varargin)
%function p = addSection(p, varargin)
% Add a section to the Cell Array of sections in the report
function o = addSection(o, varargin)
%function o = addSection(o, varargin)
% Add a section
%
% INPUTS
% 1 args => add empty section
% 2 args => add given section
% 3 args => add section at index
% o [page] page object
% varargin arguments to section()
%
% OUTPUTS
% updated page object
......@@ -13,7 +12,7 @@ function p = addSection(p, varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team
% Copyright (C) 2013-2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -30,5 +29,5 @@ function p = addSection(p, 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.sections{end+1} = section(varargin{:});
o.sections{end+1} = section(varargin{:});
end
function display(o)
%function display(o)
% Display a Page object
function o = addSeries(o, varargin)
%function o = addSeries(o, varargin)
% Add a series
%
% INPUTS
% o [page] page object
% o [page] page object
% varargin arguments to report_series()
%
% OUTPUTS
% none
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-2015 Dynare Team
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o);
end
\ No newline at end of file
assert(~isempty(o.sections), ...
'@page.addSeries: Before adding a series, you must add a section.');
o.sections{end}.addSeries(varargin{:});
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 display(o)
% Display a Paragraph object
function o = addVspace(o, varargin)
%function o = addVspace(o, varargin)
% Add a vspace
%
% INPUTS
% o [paragraph] paragraph object
% o [page] page object
% varargin arguments to vspace()
%
% OUTPUTS
% none
% updated section object
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2014-2015 Dynare Team
% Copyright (C) 2019 Dynare Team
%
% This file is part of Dynare.
%
......@@ -28,5 +29,7 @@ function display(o)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
display_reporting_object(o);
end
\ No newline at end of file
assert(~isempty(o.sections), ...
'@page.addVspace: Before adding a vspace, you must add a section.');
o.sections{end}.addVspace(varargin{:});
end
function o = page(varargin)
%function o = page(varargin)
% Page Class Constructor
%
% INPUTS
% 0 args => empty page
% 1 arg (page class) => copy object
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% 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/>.
o = struct;
o.paper = '';
o.title = {''};
titleFormatDefalut = {'\large\bfseries'};
o.titleFormat = titleFormatDefalut;
o.titleTruncate = '';
o.orientation = '';
o.footnote = {};
o.sections = {};
o.pageDirName = 'tmpRepDir';
o.latex = '';
if nargin == 1
assert(isa(varargin{1}, 'page'), ['@page.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(['@page.page: options must be supplied in name/value ' ...
'pairs.']);
classdef page < handle
% page Class
%
% Copyright (C) 2013-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/>.
properties (Access = private, Constant = true)
titleFormatDefalut = {'\large\bfseries'}
end
optNames = fieldnames(o);