From 2673729a2decb63100b9d39f0e3f14320b5194b2 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 Mar 2013 18:17:36 +0100 Subject: [PATCH] reporting: @vspace --- matlab/reports/@elements/addVspace.m | 22 ++++++++++ matlab/reports/@elements/numVspace.m | 28 ++++++++++++ matlab/reports/@section/addVspace.m | 33 ++++++++++++++ matlab/reports/@section/numVspace.m | 22 ++++++++++ matlab/reports/@section/write.m | 19 ++++++-- matlab/reports/@vspace/subsasgn.m | 46 +++++++++++++++++++ matlab/reports/@vspace/subsref.m | 48 ++++++++++++++++++++ matlab/reports/@vspace/vspace.m | 66 ++++++++++++++++++++++++++++ matlab/reports/@vspace/write.m | 44 +++++++++++++++++++ 9 files changed, 324 insertions(+), 4 deletions(-) create mode 100644 matlab/reports/@elements/addVspace.m create mode 100644 matlab/reports/@elements/numVspace.m create mode 100644 matlab/reports/@section/addVspace.m create mode 100644 matlab/reports/@section/numVspace.m create mode 100644 matlab/reports/@vspace/subsasgn.m create mode 100644 matlab/reports/@vspace/subsref.m create mode 100644 matlab/reports/@vspace/vspace.m create mode 100644 matlab/reports/@vspace/write.m diff --git a/matlab/reports/@elements/addVspace.m b/matlab/reports/@elements/addVspace.m new file mode 100644 index 000000000..748ac35ce --- /dev/null +++ b/matlab/reports/@elements/addVspace.m @@ -0,0 +1,22 @@ +function e = addVspace(e, varargin) +% function e = addVspace(e, varargin) + +% 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 . + +e.objArray = e.objArray.addObj(vspace(varargin{:})); +end \ No newline at end of file diff --git a/matlab/reports/@elements/numVspace.m b/matlab/reports/@elements/numVspace.m new file mode 100644 index 000000000..266063c98 --- /dev/null +++ b/matlab/reports/@elements/numVspace.m @@ -0,0 +1,28 @@ +function n = numVspace(o) +% function n = numVspace(o) + +% 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 . + +objs = o.objArray.getObjs(); +n = 0; +for i=1:length(objs) + if isa(objs{i}, 'vspace') + n = n+1; + end +end +end \ No newline at end of file diff --git a/matlab/reports/@section/addVspace.m b/matlab/reports/@section/addVspace.m new file mode 100644 index 000000000..b572b1942 --- /dev/null +++ b/matlab/reports/@section/addVspace.m @@ -0,0 +1,33 @@ +function o = addVspace(o, varargin) +%function o = addVspace(o, varargin) +% Add a vspace to the Cell Array of vspaces in the report +% +% INPUTS +% 1 args => add empty vspace +% 2 args => add given vspace +% +% OUTPUTS +% updated section object +% +% 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 . + +o.elements = o.elements.addVspace(varargin{:}); +end diff --git a/matlab/reports/@section/numVspace.m b/matlab/reports/@section/numVspace.m new file mode 100644 index 000000000..4bb53e3b1 --- /dev/null +++ b/matlab/reports/@section/numVspace.m @@ -0,0 +1,22 @@ +function n = numVspace(o) +% function n = numVspace(o) + +% 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 . + +n = o.elements.numVspace(); +end \ No newline at end of file diff --git a/matlab/reports/@section/write.m b/matlab/reports/@section/write.m index 15b3925bf..c592b93ce 100644 --- a/matlab/reports/@section/write.m +++ b/matlab/reports/@section/write.m @@ -38,12 +38,23 @@ for i=1:o.cols end fprintf(fid, '}\n'); ne = numElements(o); +nvspace = numVspace(o); +nlcounter = 0; for i=1:ne - o.elements(i).write(fid); - if rem(i, o.cols) - fprintf(fid, ' & '); - else + if isa(o.elements(i), 'vspace') + assert(rem(nlcounter, o.cols) == 0, ['@section.write: must place ' ... + 'vspace command after a linebreak in the table ' ... + 'or series of charts']); + o.elements(i).write(fid); fprintf(fid, '\\\\\n'); + else + o.elements(i).write(fid); + nlcounter = nlcounter + 1; + if rem(nlcounter, o.cols) + fprintf(fid, ' & '); + else + fprintf(fid, '\\\\\n'); + end end end fprintf(fid, '\\end{tabular}}\n'); diff --git a/matlab/reports/@vspace/subsasgn.m b/matlab/reports/@vspace/subsasgn.m new file mode 100644 index 000000000..82c444722 --- /dev/null +++ b/matlab/reports/@vspace/subsasgn.m @@ -0,0 +1,46 @@ +function B = subsasgn(A, S, V) +% function B = subsasgn(A, S, V) + +% 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 . + +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{index} = V; + case '.' + switch S.subs + case fieldnames(A) + B.(S.subs) = V; + otherwise + error(['@vspace.subsasgn: field ' S.subs 'does not exist']); + end + otherwise + error('@vspace.subsasgn: syntax error'); +end +end \ No newline at end of file diff --git a/matlab/reports/@vspace/subsref.m b/matlab/reports/@vspace/subsref.m new file mode 100644 index 000000000..fafc63ade --- /dev/null +++ b/matlab/reports/@vspace/subsref.m @@ -0,0 +1,48 @@ +function A = subsref(A, S) +%function A = subsref(A, S) + +% 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 . + +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); + else + A = feval(S(1).subs, A); + end + otherwise + error(['@vspace.subsref: unknown field or method: ' S(1).subs]); + end + case '()' + A = getSections(A, S(1).subs{:}); + case '{}' + error(['@vspace.subsref: ' S(1).type ' indexing not supported.']); + otherwise + error('@vspace.subsref: impossible case') +end + +S = shiftS(S); +if length(S) >= 1 + A = subsref(A, S); +end +end diff --git a/matlab/reports/@vspace/vspace.m b/matlab/reports/@vspace/vspace.m new file mode 100644 index 000000000..4958c48be --- /dev/null +++ b/matlab/reports/@vspace/vspace.m @@ -0,0 +1,66 @@ +function o = vspace(varargin) +%function o = vspace(varargin) +% Vspace Class Constructor +% +% INPUTS +% 0 args => empty vspace +% 1 arg (vspace class) => copy object +% +% 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 . + +o = struct; +o.number = 1; +o.hline = 0; + +if nargin == 1 + assert(isa(varargin{1}, 'vspace'), ['@vspace.vspace: with one arg to Vspace ' ... + 'constructor, you must pass a vspace object']); + o = varargin{1}; + return; +elseif nargin > 1 + if round(nargin/2) ~= nargin/2 + error(['@vspace.vspace: options must be supplied in name/value ' ... + 'pairs.']); + end + + optNames = lower(fieldnames(o)); + + % overwrite default values + for pair = reshape(varargin, 2, []) + field = lower(pair{1}); + if any(strmatch(field, optNames, 'exact')) + o.(field) = pair{2}; + else + error('@vspace.vspace: %s is not a recognized option.', field); + end + end +end + +% Check options provided by user +assert(isint(o.number), '@vspace.vspace: number must be an integer'); +assert(isint(o.hline), '@vspace.vspace: hline must be an integer'); + +% Create vspace object +o = class(o, 'vspace'); +end diff --git a/matlab/reports/@vspace/write.m b/matlab/reports/@vspace/write.m new file mode 100644 index 000000000..fe5a8b200 --- /dev/null +++ b/matlab/reports/@vspace/write.m @@ -0,0 +1,44 @@ +function o = write(o, fid) +%function o = write(o, fid) +% Write a Vspace object +% +% INPUTS +% o [vspace] vspace object +% fid [integer] file id +% +% OUTPUTS +% o [vspace] vspace object +% +% 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(fid ~= -1); + +for i=1:o.number + fprintf(fid, ' \\par \\medskip '); +end + +if o.hline > 0 + fprintf(fid, '\\\\\n'); + for i=1:o.hline + fprintf(fid, '\\midrule'); + end +end +end \ No newline at end of file