Commit 3daf35d3 authored by Houtan Bastani's avatar Houtan Bastani

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);
% overwrite default values
for pair = reshape(varargin, 2, [])
ind = find(strcmpi(optNames, pair{1}));
assert(isempty(ind) || length(ind) == 1);
if ~isempty(ind)
o.(optNames{ind}) = pair{2};
else
error('@page.page: %s is not a recognized option.', pair{1});
end
properties (Access = private)
sections = {}
end
end
properties (SetAccess = private)
paper = '' % Paper size. Default: `a4'.
title = {''} % With one entry (a STRING), the title of the page. With more than one entry (a CELL_ARRAY_STRINGS), the title and subtitle(s) of the page. Values passed must be valid LATEX code (e.g., % must be \%). Default: none.
titleFormat = '' % A string representing the valid LATEX markup to use on title. The number of cell array entries must be equal to that of the title option if you do not want to use the default value for the title (and subtitles). Default: \large\bfseries.
titleTruncate = '' % Useful when automatically generating page titles that may become too long, titleTruncate can be used to truncate a title (and subsequent subtitles) when they pass the specified number of characters. Default: .off.
orientation = '' % Paper orientation: Default: `portrait'.
footnote = {} % A footnote to be included at the bottom of this page. Default: none.
pageDirName = 'tmpRepDir' % The name of the folder in which to store this page. Only used when the latex command is passed. Default: tmpRepDir.
latex = '' % The valid LATEX code to be used for this page. Alows the user to create a page to be included in the report by passing LATEX code directly. Default: empty.
end
methods (Access = ?report)
function o = page(varargin)
%function o = page(varargin)
% Page Class Constructor
%
% INPUTS
% varargin 0 args : empty page object
% 1 arg : must be page object (return a copy of arg)
% > 1 args: option/value pairs (see structure below for options)
%
% OUTPUTS
% o [page] page object
%
% SPECIAL REQUIREMENTS
% none
o.titleFormat = o.titleFormatDefalut;
if nargin == 0
return
elseif 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
end
% Check options provided by user
if ischar(o.title)
o.title = {o.title};
end
if ischar(o.titleFormat)
o.titleFormat = {o.titleFormat};
end
if length(o.title) ~= length(o.titleFormat)
o.titleFormat = repmat(titleFormatDefalut, 1, length(o.title));
end
assert(iscellstr(o.title), ...
'@page.page: title must be a cell array of strings');
assert(iscellstr(o.titleFormat), ...
'@page.page: titleFormat must be a cell array of strings');
assert((ischar(o.titleTruncate) && isempty(o.titleTruncate)) || ...
isint(o.titleTruncate), ...
'@page.page: titleTruncate must be empty or an integer.');
assert(ischar(o.pageDirName), '@page.page: pageDirName must be a string');
assert(ischar(o.latex), ...
'@page.page: latex must be a string');
valid_paper = {'a4', 'letter'};
assert(any(strcmp(o.paper, valid_paper)), ...
['@page.page: paper must be one of ' addCommasToCellStr(valid_paper)]);
if round(nargin/2) ~= nargin/2
error('@page.page: options must be supplied in name/value pairs.');
end
valid_orientation = {'portrait', 'landscape'};
assert(any(strcmp(o.orientation, valid_orientation)), ...
['@page.page: orientation must be one of ' addCommasToCellStr(valid_orientation)]);
% Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
warning('off')
optNames = fieldnames(o);
warning('on')
if ischar(o.footnote)
o.footnote = {o.footnote};
end
assert(iscellstr(o.footnote), ...
'@page.page: footnote must be a cell array of string(s)');
% overwrite default values
for pair = reshape(varargin, 2, [])
ind = find(strcmpi(optNames, pair{1}));
assert(isempty(ind) || length(ind) == 1);
if ~isempty(ind)
o.(optNames{ind}) = pair{2};
else
error('@page.page: %s is not a recognized option.', pair{1});
end
end
% Create page object
o = class(o, 'page');
% Check input
if ischar(o.title)
o.title = {o.title};
end
if ischar(o.titleFormat)
o.titleFormat = {o.titleFormat};
end
if length(o.title) ~= length(o.titleFormat)
o.titleFormat = repmat(o.titleFormatDefalut, 1, length(o.title));
end
assert(iscellstr(o.title), ...
'@page.page: title must be a cell array of strings');
assert(iscellstr(o.titleFormat), ...