Commit 5aabe16a authored by Houtan Bastani's avatar Houtan Bastani
Browse files

reporting: @report: check user input

parent e8e9b241
function validateOrientation(orientation)
%function validateOrientation(orientation)
% Validate orientation string
%
% INPUTS
% orientation [char] orientation (one of 'portrait' or 'landscape')
%
% 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/>.
assert(any(strcmpi(orientation, {'portrait', 'landscape'})), ['Valid ' ...
'orientation arguments are: ''portrait'' and ' ...
'''landscape''.']);
end
\ No newline at end of file
function validatePaper(paper)
%function validatePaper(paper)
% Validate paper string
%
% INPUTS
% paper [char] valid LaTeX paper type
%
% 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/>.
assert(any(strcmpi(paper, {'a4', 'letter'})), ['Valid paper arguments ' ...
'are: ''a4'' and ''letter''.']);
end
\ No newline at end of file
......@@ -35,7 +35,8 @@ o = struct;
o.title = '';
o.orientation = 'portrait';
o.paper = 'a4';
o.margin = '2.5cm';
o.margin = 2.5;
o.margin_unit = 'cm';
o.pages = pages();
o.filename = 'report.tex';
o.config = '';
......@@ -58,11 +59,6 @@ elseif nargin > 1
for pair = reshape(varargin, 2, [])
field = lower(pair{1});
if any(strmatch(field, optNames, 'exact'))
if strcmp(field, 'orientation')
validateOrientation(pair{2});
elseif strcmp(field, 'paper')
validatePaper(pair{2});
end
o.(field) = pair{2};
else
error('@report.report: %s is not a recognized option.', ...
......@@ -71,6 +67,25 @@ elseif nargin > 1
end
end
% Check options provided by user
assert(ischar(o.title), '@report.report: title must be a string');
assert(ischar(o.filename), '@report.report: filename must be a string');
assert(ischar(o.config), '@report.report: config file must be a string');
assert(islogical(o.showdate), '@report.report: showdate must be either true or false');
assert(isfloat(o.margin) && o.margin > 0, '@report.report: margin must be a float > 0.');
valid_margin_unit = {'cm', 'in'};
assert(any(strcmp(o.margin_unit, valid_margin_unit)), ...
['@report.report: margin_unit must be one of ' strjoin(valid_margin_unit, ' ')]);
valid_paper = {'a4', 'letter'};
assert(any(strcmp(o.paper, valid_paper)), ...
['@report.report: paper must be one of ' strjoin(valid_paper, ' ')]);
valid_orientation = {'portrait', 'landscape'};
assert(any(strcmp(o.orientation, valid_orientation)), ...
['@report.report: orientation must be one of ' strjoin(valid_orientation, ' ')]);
% Create report object
o = class(o, 'report');
end
\ No newline at end of file
......@@ -36,7 +36,7 @@ end
fprintf(fid, '%% Report Object\n');
fprintf(fid, '\\documentclass[11pt]{article}\n');
fprintf(fid, '\\usepackage[%spaper,margin=%s', o.paper, o.margin);
fprintf(fid, '\\usepackage[%spaper,margin=%f%s', o.paper, o.margin, o.margin_unit);
if strcmpi(o.orientation, 'landscape')
fprintf(fid, ',landscape');
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment