diff --git a/matlab/@dynTimeIndex/display.m b/matlab/@dynTimeIndex/display.m new file mode 100644 index 000000000..87162fd40 --- /dev/null +++ b/matlab/@dynTimeIndex/display.m @@ -0,0 +1,20 @@ +function display(t) + +% 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 . + +fprintf('%s = \n', inputname(1), int2str(t.index)); diff --git a/matlab/@dynTimeIndex/dynTimeIndex.m b/matlab/@dynTimeIndex/dynTimeIndex.m new file mode 100644 index 000000000..f310d96cb --- /dev/null +++ b/matlab/@dynTimeIndex/dynTimeIndex.m @@ -0,0 +1,61 @@ +function t = dynTimeIndex() % --*-- Unitary tests --*-- + +% t = dynTimeIndex() +% +% Constructor for the dynTimeIndex class. +% +% INPUTS: +% None. +% +% OUTPUTS: +% * t, dynTimeIndex object. +% +% DESCRIPTION: +% The dynTimeIndex object is used to shift backward or forward dynSeries objects. For instance, if ts +% is a dynSeries object and t is a dynTimeIndex object then the following expressions are equivalent: +% +% us = ts.lag() +% us = ts.lag(1) +% us = lag(ts,1) +% us = ts(t-1) +% +% This class has only one member: t = int8(0) when instantiated. + +% 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 . + +t = struct(); + +t.index = int8(0); + +t = class(t,'dynTimeIndex'); + +%@test:1 +%$ % Instantiate a dynTimeIndex object +%$ try +%$ u = dynTimeIndex(); +%$ t(1) = 1; +%$ catch +%$ t(1) = 0; +%$ end +%$ +%$ if t(1) +%$ t(2) = isa(u,'dynTimeIndex'); +%$ end +%$ +%$ T = all(t); +%@eof:1 \ No newline at end of file diff --git a/matlab/@dynTimeIndex/minus.m b/matlab/@dynTimeIndex/minus.m new file mode 100644 index 000000000..dff65f42d --- /dev/null +++ b/matlab/@dynTimeIndex/minus.m @@ -0,0 +1,62 @@ +function C = minus(A,B) % --*-- Unitary tests --*-- + +% C = minus(A,B) +% +% Overloads binary minus operator. +% +% INPUTS: +% * A, dynTimeIndex object. +% * B, integer scalar. +% +% OUTPUTS: +% * C, dynTimeIndex object. +% +% EXAMPLE: +% +% >> t = dynTimeIndex(); +% >> t.index +% +% ans = +% +% 0 +% +% >> s = t-1; +% >> s.index +% +% ans = +% +% -1 +% + +% 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 . + +if ~(isa(A,'dynTimeIndex') || isint(B)) + error(['dynTimeIndex::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be a dynTimeIndex object and an integer!']) +end + +C = struct(); +C.index = A.index-B; +C = class(C,'dynTimeIndex'); + +%@test:1 +%$ a = dynTimeIndex(); +%$ b = a-1; +%$ t(1) = isa(b,'dynTimeIndex'); +%$ t(2) = isequal(b.index,-int8(1)); +%$ T = all(t); +%@eof:1 \ No newline at end of file diff --git a/matlab/@dynTimeIndex/plus.m b/matlab/@dynTimeIndex/plus.m new file mode 100644 index 000000000..7b4752db9 --- /dev/null +++ b/matlab/@dynTimeIndex/plus.m @@ -0,0 +1,62 @@ +function C = plus(A,B) % --*-- Unitary tests --*-- + +% C = plus(A,B) +% +% Overloads binary plus operator. +% +% INPUTS: +% * A, dynTimeIndex object. +% * B, integer scalar. +% +% OUTPUTS: +% * C, dynTimeIndex object. +% +% EXAMPLE: +% +% >> t = dynTimeIndex(); +% >> t.index +% +% ans = +% +% 0 +% +% >> s = t+1; +% >> s.index +% +% ans = +% +% 1 +% + +% 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 . + +if ~(isa(A,'dynTimeIndex') || isint(B)) + error(['dynTimeIndex::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be a dynTimeIndex object and an integer!']) +end + +C = struct(); +C.index = A.index+B; +C = class(C,'dynTimeIndex'); + +%@test:1 +%$ a = dynTimeIndex(); +%$ b = a+1; +%$ t(1) = isa(b,'dynTimeIndex'); +%$ t(2) = isequal(b.index,int8(1)); +%$ T = all(t); +%@eof:1 \ No newline at end of file diff --git a/matlab/@dynTimeIndex/subsasgn.m b/matlab/@dynTimeIndex/subsasgn.m new file mode 100644 index 000000000..b03987c86 --- /dev/null +++ b/matlab/@dynTimeIndex/subsasgn.m @@ -0,0 +1,20 @@ +function val = subsasgn(val, idx, rhs) + +% 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 . + +error('dynTimeIndex::subsasgn: Members of dynDate class are private!') \ No newline at end of file diff --git a/matlab/@dynTimeIndex/subsref.m b/matlab/@dynTimeIndex/subsref.m new file mode 100644 index 000000000..6c8aa79d4 --- /dev/null +++ b/matlab/@dynTimeIndex/subsref.m @@ -0,0 +1,54 @@ +function B = subsref(A,S) % --*-- Unitary tests --*-- + +% B = subsref(A,S) +% +% Overloads the subsref method for dynTimeIndex class. This method only allows to get +% the value of the field `index`. + +% 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 . + +if length(S)>1 + error('dynTimeIndex::subsref: Something is wrong in your syntax!') +end + +if isequal(S.type,'.') + if isequal(S.subs,'index') + B = builtin('subsref', A, S(1)); + else + error(['dynTimeIndex::subsref: ' S.subs ' is not a known member!']) + end +else + error('dynTimeIndex::subsref: Something is wrong in your syntax!') +end + +%@test:1 +%$ % Instantiate a dynTimeIndex object +%$ u = dynTimeIndex(); +%$ try +%$ v = u.index; +%$ t(1) = 1; +%$ catch +%$ t(1) = 0; +%$ end +%$ +%$ if t(1) +%$ t(2) = isequal(v,int8(0)); +%$ end +%$ +%$ T = all(t); +%@eof:1 \ No newline at end of file