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.
%
......
function o = graph(varargin)
%function o = graph(varargin)
% Graph Class Constructor
%
% INPUTS
% varargin 0 args : empty graph object
% 1 arg : must be graph object (return a copy of arg)
% > 1 args: option/value pairs (see structure below for
% options)
%
% OUTPUTS
% o [graph] graph object
%
% 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.series = {};
o.title = '';
o.titleFormat = '';
o.titleFontSize = 'normalsize';
o.ylabel = '';
o.xlabel = '';
o.axisShape = 'box';
o.graphDirName = 'tmpRepDir';
o.graphName = '';
o.data = '';
o.seriesToUse = '';
o.xrange = '';
o.xAxisTight = true;
o.yrange = '';
o.yAxisTight = false;
o.shade = '';
o.shadeColor = 'green';
o.shadeOpacity = 20;
o.showGrid = true;
o.showLegend = false;
o.legendAt = [];
o.showLegendBox = false;
o.legendLocation = 'south east';
o.legendOrientation = 'horizontal';
o.legendFontSize = 'tiny';
o.showZeroline = false;
o.zeroLineColor = 'black';
o.xTicks = [];
o.xTickLabels = {};
o.xTickLabelRotation = 0;
o.xTickLabelAnchor = 'east';
o.yTickLabelScaled = true;
o.yTickLabelPrecision = 0;
o.yTickLabelFixed = true;
o.yTickLabelZeroFill = true;
o.tickFontSize = 'normalsize';
o.width = 6;
o.height = 4.5;
o.miscTikzPictureOptions = '';
o.miscTikzAxisOptions = '';
o.writeCSV = false;
if nargin == 1
assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ...
'must pass a graph object']);
classdef graph < handle
% graph 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)
series = {}
end
properties (SetAccess = private)
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 = '' % The format to use for the graph title. Unlike other titleFormat options, due to a constraint of TikZ, this format applies to the title and subtitles. Default: TikZ default.
titleFontSize = 'normalsize' % The font size for title. Default: normalsize.
ylabel = '' % The x-axis label. Default: none.
xlabel = '' % The y-axis label. Default: none.
axisShape = 'box' % The shape the axis should have. `box' means that there is an axis line to the left, right, bottom, and top of the graphed line(s). ?L??? means that there is an axis to the left and bottom of the graphed line(s). Default: `box'.
graphDirName = 'tmpRepDir' % The name of the folder in which to store this figure. Default: tmpRepDir.
graphName = '' % The name to use when saving this figure. Default: something of the form graph_pg1_sec2_row1_col3.tex.
data = '' % The dseries that provides the data for the graph. Default: none.
seriesToUse = '' % The names of the series contained in the dseries provided to the data option. If empty, use all series provided to data option. Default: empty.
xrange = '' % The boundary on the x-axis to display in the graph. Default: all.
xAxisTight = true % Use a tight x axis. If false, uses PGFPLOTS/TikZ enlarge x limits to choose appropriate axis size. Default: true.
yrange = '' % The boundary on the y-axis to display in the graph, represented as a NUMERICAL_VECTOR of size 2, with the first entry less than the second entry. Default: all.
yAxisTight = false % Use a tight y axis. If false, uses PGFPLOTS/TikZ enlarge y limits to choose appropriate axis size. Default: false.
shade = '' % The date range showing the portion of the graph that should be shaded. Default: none.
shadeColor = 'green' % The color to use in the shaded portion of the graph. All valid color strings defined for use by PGFPLOTS/TikZ are valid. Furthermore, You can use combinations of these colors. For example, if you wanted a color that is 20% green and 80% purple, you could pass the string 'green!20!purple'. You can also use RGB colors, following the syntax: `rgb,255:red,231;green,84;blue,121' which corresponds to the RGB color (231;84;121). More examples are available in the section 4.7.5 of the PGFPLOTS/TikZ manual, revision 1.10. Default: `green'
shadeOpacity = 20 % The opacity of the shaded area, must be in [0,100]. Default: 20.
showGrid = true % Whether or not to display the major grid on the graph. Default: true.
showLegend = false % Whether or not to display the legend. Unless you use the graphLegendName option, the name displayed in the legend is the tex name associated with the dseries. You can modify this tex name by using tex_rename. Default: false.
legendAt = [] % The coordinates for the legend location. If this option is passed, it overrides the legendLocation option. Must be of size 2. Default: empty.
showLegendBox = false % Whether or not to display a box around the legend. Default: false.
legendLocation = 'south east' % Where to place the legend in the graph. Default: `south east'.
legendOrientation = 'horizontal' % Orientation of the legend. Default: `horizontal'.
legendFontSize = 'tiny' % The font size for legend entries. Default: tiny.
showZeroline = false % Display a solid black line at y = 0. Default: false.
zeroLineColor = 'black' % The color to use for the zero line. Only used if showZeroLine is true. See the explanation in shadeColor for how to use colors with reports. Default: `black'.
xTicks = [] % Used only in conjunction with xTickLabels, this option denotes the numerical position of the label along the x-axis. The positions begin at 1. Default: the indices associated with the first and last dates of the dseries and, if passed, the index associated with the first date of the shade option.
xTickLabels = {} % The labels to be mapped to the ticks provided by xTicks. Default: the first and last dates of the dseries and, if passed, the date first date of the shade option.
xTickLabelRotation = 0 % The amount to rotate the x tick labels by. Default: 0.
xTickLabelAnchor = 'east' % Where to anchor the x tick label. Default: `east'.
yTickLabelScaled = true % Determines whether or not there is a common scaling factor for the y axis. Default: true.
yTickLabelPrecision = 0 % The precision with which to report the yTickLabel. Default: 0.
yTickLabelFixed = true % Round the y tick labels to a fixed number of decimal places, given by yTickLabelPrecision. Default: true.
yTickLabelZeroFill = true % Whether or not to fill missing precision spots with zeros. Default: true.
tickFontSize = 'normalsize' % The font size for x- and y-axis tick labels. Default: normalsize.
width = 6 % The width of the graph, in inches. Default: 6.0.
height = 4.5 % The height of the graph, in inches. Default: 4.5.
miscTikzPictureOptions = '' % If you are comfortable with PGFPLOTS/TikZ, you can use this option to pass arguments directly to the PGFPLOTS/TikZ tikzpicture environment command. (e.g., to scale the graph in the x and y dimensions, you can pass following to this option: ?xscale=2.5, yscale=0.5?). Specifically to be used for desired ``PGFPLOTS/TikZoptionsthathavenotbeenincorporatedinto Dynare Reporting. Default: empty.
miscTikzAxisOptions = '' % If you are comfortable with PGFPLOTS/TikZ, you can use this option to pass arguments directly to the PGFPLOTS/TikZ axis environment command. Specifically to be used for desired PGFPLOTS/ TikZ options that have not been incorporated into Dynare Reporting. Default: empty.
writeCSV = false % Whether or not to write a CSV file with only the plotted data. The file will be saved in the directory specified by graphDirName with the same base name as specified by graphName with the ending .csv. Default: false.
end
methods
function o = graph(varargin)
%function o = graph(varargin)
% Graph Class Constructor
%
% INPUTS
% varargin 0 args : empty graph object
% 1 arg : must be graph object (return a copy of arg)
% > 1 args: option/value pairs (see structure below for
% options)
%
% OUTPUTS
% o [graph] graph object
%
% SPECIAL REQUIREMENTS
% none
if nargin == 0
return
elseif nargin == 1
assert(isa(varargin{1}, 'graph'), ...
'With one arg to the Graph constructor, you must pass a graph object');
o = varargin{1};
return;
elseif nargin > 1
return
elseif nargin > 1
if round(nargin/2) ~= nargin/2
error(['@graph.graph: options must be supplied in name/value ' ...
'pairs.']);
error('@graph.graph: options must be supplied in name/value pairs.');
end
% Octave 5.1.0 has not implemented `properties` and issues a warning when using `fieldnames`
warning('off')
optNames = fieldnames(o);
warning('on')
% overwrite default values
for pair = reshape(varargin, 2, [])
......@@ -111,92 +105,92 @@ elseif nargin > 1
error('@graph.graph: %s is not a recognized option.', pair{1});
end
end
end
end
% Check options provided by user
if ischar(o.title)
% Check options provided by user
if ischar(o.title)
o.title = {o.title};
end
assert(iscellstr(o.title), '@graph.graph: title must be a cell array of string(s)');
assert(ischar(o.titleFormat), '@graph.graph: titleFormat file must be a string');
assert(ischar(o.xlabel), '@graph.graph: xlabel file must be a string');
assert(ischar(o.ylabel), '@graph.graph: ylabel file must be a string');
assert(ischar(o.miscTikzPictureOptions), '@graph.graph: miscTikzPictureOptions file must be a string');
assert(ischar(o.miscTikzAxisOptions), '@graph.graph: miscTikzAxisOptions file must be a string');
assert(ischar(o.graphName), '@graph.graph: graphName must be a string');
assert(ischar(o.graphDirName), '@graph.graph: graphDirName must be a string');
assert(islogical(o.showGrid), '@graph.graph: showGrid must be either true or false');
assert(islogical(o.xAxisTight), '@graph.graph: xAxisTight must be either true or false');
assert(islogical(o.yAxisTight), '@graph.graph: yAxisTight must be either true or false');
assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or false');
assert(isempty(o.legendAt) || (isfloat(o.legendAt) && length(o.legendAt)==2), ...
end
assert(iscellstr(o.title), '@graph.graph: title must be a cell array of string(s)');
assert(ischar(o.titleFormat), '@graph.graph: titleFormat file must be a string');
assert(ischar(o.xlabel), '@graph.graph: xlabel file must be a string');
assert(ischar(o.ylabel), '@graph.graph: ylabel file must be a string');
assert(ischar(o.miscTikzPictureOptions), '@graph.graph: miscTikzPictureOptions file must be a string');
assert(ischar(o.miscTikzAxisOptions), '@graph.graph: miscTikzAxisOptions file must be a string');
assert(ischar(o.graphName), '@graph.graph: graphName must be a string');
assert(ischar(o.graphDirName), '@graph.graph: graphDirName must be a string');
assert(islogical(o.showGrid), '@graph.graph: showGrid must be either true or false');
assert(islogical(o.xAxisTight), '@graph.graph: xAxisTight must be either true or false');
assert(islogical(o.yAxisTight), '@graph.graph: yAxisTight must be either true or false');
assert(islogical(o.showLegend), '@graph.graph: showLegend must be either true or false');
assert(isempty(o.legendAt) || (isfloat(o.legendAt) && length(o.legendAt)==2), ...
'@graph.graph: legendAt must be a double array of size two');
assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false');
assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false');
assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
assert(islogical(o.showLegendBox), '@graph.graph: showLegendBox must be either true or false');
assert(islogical(o.showZeroline), '@graph.graph: showZeroline must be either true or false');
assert(isfloat(o.shadeOpacity) && length(o.shadeOpacity)==1 && ...
o.shadeOpacity >= 0 && o.shadeOpacity <= 100, ...
'@graph.graph: o.shadeOpacity must be a real in [0 100]');
assert(isfloat(o.width), '@graph.graph: o.width must be a real number');
assert(isfloat(o.height), '@graph.graph: o.height must be a real number');
assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number');
assert(ischar(o.xTickLabelAnchor), '@graph.graph: xTickLabelAnchor must be a string');
assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must be an integer');
assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false');
assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false');
assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false');
assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false');
assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string');
assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ...
assert(isfloat(o.width), '@graph.graph: o.width must be a real number');
assert(isfloat(o.height), '@graph.graph: o.height must be a real number');
assert(isfloat(o.xTickLabelRotation), '@graph.graph: o.xTickLabelRotation must be a real number');
assert(ischar(o.xTickLabelAnchor), '@graph.graph: xTickLabelAnchor must be a string');
assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must be an integer');
assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false');
assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false');
assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false');
assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false');
assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string');
assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string');
assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ...
'must be one of ''box'' or ''L''']);
valid_legend_locations = ...
valid_legend_locations = ...
{'south west','south east','north west','north east','outer north east'};
assert(any(strcmp(o.legendLocation, valid_legend_locations)), ...
assert(any(strcmp(o.legendLocation, valid_legend_locations)), ...
['@graph.graph: legendLocation must be one of ' addCommasToCellStr(valid_legend_locations)]);
valid_font_sizes = {'tiny', 'scriptsize', 'footnotesize', 'small', ...
valid_font_sizes = {'tiny', 'scriptsize', 'footnotesize', 'small', ...
'normalsize', 'large', 'Large', 'LARGE', 'huge', 'Huge'};
assert(any(strcmp(o.legendFontSize, valid_font_sizes)), ...
assert(any(strcmp(o.legendFontSize, valid_font_sizes)), ...
['@graph.graph: legendFontSize must be one of ' addCommasToCellStr(valid_font_sizes)]);
assert(any(strcmp(o.titleFontSize, valid_font_sizes)), ...
assert(any(strcmp(o.titleFontSize, valid_font_sizes)), ...
['@graph.graph: titleFontSize must be one of ' addCommasToCellStr(valid_font_sizes)]);
assert(any(strcmp(o.tickFontSize, valid_font_sizes)), ...
assert(any(strcmp(o.tickFontSize, valid_font_sizes)), ...
['@graph.graph: tickFontSize must be one of ' addCommasToCellStr(valid_font_sizes)]);
valid_legend_orientations = {'vertical', 'horizontal'};
assert(any(strcmp(o.legendOrientation, valid_legend_orientations)), ...
valid_legend_orientations = {'vertical', 'horizontal'};
assert(any(strcmp(o.legendOrientation, valid_legend_orientations)), ...
['@graph.graph: legendOrientation must be one of ' addCommasToCellStr(valid_legend_orientations)]);
assert(isempty(o.shade) || (isdates(o.shade) && o.shade.ndat >= 2), ...
assert(isempty(o.shade) || (isdates(o.shade) && o.shade.ndat >= 2), ...
['@graph.graph: shade is specified as a dates range, e.g. ' ...
'''dates(''1999q1''):dates(''1999q3'')''.']);
assert(isempty(o.xrange) || (isdates(o.xrange) && o.xrange.ndat >= 2), ...
assert(isempty(o.xrange) || (isdates(o.xrange) && o.xrange.ndat >= 2), ...
['@graph.graph: xrange is specified as a dates range, e.g. ' ...
'''dates(''1999q1''):dates(''1999q3'')''.']);
assert(isempty(o.yrange) || (isfloat(o.yrange) && length(o.yrange) == 2 && ...
assert(isempty(o.yrange) || (isfloat(o.yrange) && length(o.yrange) == 2 && ...
o.yrange(1) < o.yrange(2)), ...
['@graph.graph: yrange is specified an array with two float entries, ' ...
'the lower bound and upper bound.']);
assert(isempty(o.data) || isdseries(o.data), ['@graph.graph: data must ' ...
assert(isempty(o.data) || isdseries(o.data), ['@graph.graph: data must ' ...
'be a dseries']);
assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ['@graph.graph: ' ...
assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ['@graph.graph: ' ...
'seriesToUse must be a cell array of string(s)']);
assert(isempty(o.xTicks) || isfloat(o.xTicks),...
assert(isempty(o.xTicks) || isfloat(o.xTicks),...
'@graph.graph: xTicks must be a numerical array');
assert(iscellstr(o.xTickLabels) || (ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')), ...
assert(iscellstr(o.xTickLabels) || (ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')), ...
['@graph.graph: xTickLabels must be a cell array of strings or ' ...
'equivalent to the string ''ALL''']);
if ~isempty(o.xTickLabels)
if ~isempty(o.xTickLabels)
assert((ischar(o.xTickLabels) && strcmpi(o.xTickLabels, 'ALL')) || ...
~isempty(o.xTicks), ['@graph.graph: if you set xTickLabels and ' ...
'it''s not equal to ''ALL'', you must set xTicks']);
end
if ~isempty(o.xTicks)
end
if ~isempty(o.xTicks)
assert(~isempty(o.xTickLabels), '@graph.graph: if you set xTicks, you must set xTickLabels');
end
end
% using o.seriesToUse, create series objects and put them in o.series
if ~isempty(o.data)
% using o.seriesToUse, create series objects and put them in o.series
if ~isempty(o.data)
if isempty(o.seriesToUse)
for i=1:o.data.vobs
o.series{end+1} = report_series('data', o.data{o.data.name{i}});
......@@ -206,14 +200,21 @@ if ~isempty(o.data)
o.series{end+1} = report_series('data', o.data{o.seriesToUse{i}});
end
end
end
o = rmfield(o, 'seriesToUse');
o = rmfield(o, 'data');
if ~exist(o.graphDirName, 'file')
end
o.seriesToUse = '';
o.data = '';
if ~exist(o.graphDirName, 'file')
mkdir(o.graphDirName);
end
% Create graph object
o = class(o, 'graph');
end
end
end
methods (Access = ?section, Hidden = true)
o = addSeries(o, varargin)
write(o, fid, pg, sec, row, col)
end
methods (Access = private)
% Methods defined in separate files
lastIndex = end(o, k, n)
graphName = writeGraphFile(o, pg, sec, row, col)
end
end
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);