From 5aabe16a03176778b7b25dcb7e8fbeab8d7fb44f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 15 Mar 2013 17:03:50 +0100 Subject: [PATCH] reporting: @report: check user input --- .../@report/private/validateOrientation.m | 34 ------------------- .../reports/@report/private/validatePaper.m | 33 ------------------ matlab/reports/@report/report.m | 27 +++++++++++---- matlab/reports/@report/write.m | 2 +- 4 files changed, 22 insertions(+), 74 deletions(-) delete mode 100644 matlab/reports/@report/private/validateOrientation.m delete mode 100644 matlab/reports/@report/private/validatePaper.m diff --git a/matlab/reports/@report/private/validateOrientation.m b/matlab/reports/@report/private/validateOrientation.m deleted file mode 100644 index 41bf58eed..000000000 --- a/matlab/reports/@report/private/validateOrientation.m +++ /dev/null @@ -1,34 +0,0 @@ -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 . - -assert(any(strcmpi(orientation, {'portrait', 'landscape'})), ['Valid ' ... - 'orientation arguments are: ''portrait'' and ' ... - '''landscape''.']); -end \ No newline at end of file diff --git a/matlab/reports/@report/private/validatePaper.m b/matlab/reports/@report/private/validatePaper.m deleted file mode 100644 index 73b6bb367..000000000 --- a/matlab/reports/@report/private/validatePaper.m +++ /dev/null @@ -1,33 +0,0 @@ -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 . - -assert(any(strcmpi(paper, {'a4', 'letter'})), ['Valid paper arguments ' ... - 'are: ''a4'' and ''letter''.']); -end \ No newline at end of file diff --git a/matlab/reports/@report/report.m b/matlab/reports/@report/report.m index 62cedefbb..d55984b26 100644 --- a/matlab/reports/@report/report.m +++ b/matlab/reports/@report/report.m @@ -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 diff --git a/matlab/reports/@report/write.m b/matlab/reports/@report/write.m index 39b965f19..e247c2557 100644 --- a/matlab/reports/@report/write.m +++ b/matlab/reports/@report/write.m @@ -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