diff --git a/src/@dates/append.m b/src/@dates/append.m index f81740cd75f929b0a493d9a79b2a126128f01d25..359cb0def37ece307f4f06b9d1262a3ecfdc5074 100644 --- a/src/@dates/append.m +++ b/src/@dates/append.m @@ -9,7 +9,7 @@ function o = append(o, d) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] dates object containing dates defined in o and d. -% Copyright (C) 2012-2014 Dynare Team +% Copyright (C) 2012-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -39,7 +39,6 @@ if ~isequal(o.freq, d.freq) error('dates:append:ArgCheck','dates must have common frequency!') end -o.ndat = o.ndat+1; o.time = [o.time; d.time]; %@test:1 @@ -53,7 +52,6 @@ o.time = [o.time; d.time]; %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -62,7 +60,6 @@ o.time = [o.time; d.time]; %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); %$ T = all(t); %@eof:1 @@ -77,7 +74,6 @@ o.time = [o.time; d.time]; %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -86,6 +82,5 @@ o.time = [o.time; d.time]; %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/colon.m b/src/@dates/colon.m index d8fb843f3e54b451e56a054ec43d7e9d25aef04d..3cf5b7d87910429859ae42480f24b991859876e9 100644 --- a/src/@dates/colon.m +++ b/src/@dates/colon.m @@ -14,7 +14,7 @@ function q = colon(varargin) % --*-- Unitary tests --*-- % 1. p must be greater than o if d>0. % 2. p and q are dates objects with one element. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -78,7 +78,6 @@ q.freq = o.freq; if isequal(q.freq, 1) % Yearly - q.ndat = m; q.time = NaN(m,2); q.time(:,1) = o.time(1)+transpose(0:d:n-1); q.time(:,2) = 1; @@ -106,9 +105,6 @@ else end if d>1 q.time = q.time(1:d:n,:); - q.ndat = m; - else - q.ndat = n; end end @@ -193,4 +189,4 @@ end %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); %$ T = all(t); -%$ @eof:4 \ No newline at end of file +%$ @eof:4 diff --git a/src/@dates/copy.m b/src/@dates/copy.m index 660ebbd0d3aae55aed3157a21d57eb5ab680e5b8..e15a508871a5418e3e7dd3bc345926e36f64f9ac 100644 --- a/src/@dates/copy.m +++ b/src/@dates/copy.m @@ -8,7 +8,7 @@ function p = copy(o) % OUTPUTS % - p [dates] -% Copyright (C) 2014 Dynare Team +% Copyright (C) 2014-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -25,5 +25,4 @@ function p = copy(o) p = dates(); p.freq = o.freq; -p.ndat = o.ndat; -p.time = o.time; \ No newline at end of file +p.time = o.time; diff --git a/src/@dates/dates.m b/src/@dates/dates.m index d5da4746f20226e9737c1f76a16f191a7ab2154b..554d0ef3a34b9bb40c7484ca321c86477bfd131b 100644 --- a/src/@dates/dates.m +++ b/src/@dates/dates.m @@ -16,16 +16,14 @@ classdef dates<handle % along with Dynare. If not, see <http://www.gnu.org/licenses/>. properties - ndat = []; % Number of dates (integer scalar) freq = []; % Frequency (integer scalar) - time = []; % Array (ndat rows and two columns) + time = []; % Array (one row for every date. first column is the year, second is the period) end - + methods function o = dates(varargin) if ~nargin % Returns empty dates object. - o.ndat = 0; o.freq = NaN(0); o.time = NaN(0,2); return @@ -43,8 +41,7 @@ classdef dates<handle else error('dates:ArgCheck', 'All dates passed as inputs must have the same frequency!') end - o.ndat = length(tmp); - o.time = transpose(reshape([tmp.time],2,o.ndat)); + o.time = transpose(reshape([tmp.time], 2, length(tmp))); return end if isequal(nargin,1) && isfreq(varargin{1}) @@ -68,7 +65,6 @@ classdef dates<handle if isnumeric(varargin{3}) && isvector(varargin{3}) && all(isint(varargin{3})) if all(varargin{3}>=1) && all(varargin{3}<=o.freq) o.time = [varargin{2}(:), varargin{3}(:)]; - o.ndat = size(o.time,1); else error('dates:ArgCheck','Third input must contain integers between 1 and %i.', o.freq) end @@ -90,7 +86,6 @@ classdef dates<handle if isequal(o.freq, 1) if (isnumeric(varargin{2}) && isvector(varargin{2}) && all(isint(varargin{2}))) o.time = [varargin{2}, ones(length(varargin{2}),1)]; - o.ndat = size(o.time,1); return else error('dates:ArgCheck','Second input must be a vector of integers.') @@ -100,7 +95,6 @@ classdef dates<handle if all(isint(varargin{2}(:,1))) && all(isint(varargin{2}(:,1))) if all(varargin{2}(:,2)>=1) && all(varargin{2}(:,2)<=o.freq) o.time = [varargin{2}(:,1), varargin{2}(:,2)]; - o.ndat = size(o.time,1); else error('dates:ArgCheck','Second column of the last input must contain integers between 1 and %i.',o.freq) end @@ -129,7 +123,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 3; 1950 2; 1950 1; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -137,7 +130,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:1 @@ -151,7 +144,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 3; 1950 2; 1950 10; 1953 12]; %$ e.freq = 12; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -159,7 +151,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:2 @@ -173,7 +165,6 @@ end % classdef %$ % Define expected results. %$ e.time = [1945 1; 1950 1; 1950 1; 1953 1]; %$ e.freq = 1; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -181,7 +172,7 @@ end % classdef %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = dassert(d.ndat(),e.ndat()); %$ T = all(t); %@eof:3 diff --git a/src/@dates/end.m b/src/@dates/end.m index 6e6abdb5747b3d92cf52958c49339bde799094b7..5de7f0b9cbfbca80eb342e9935f28a3924c86dfc 100644 --- a/src/@dates/end.m +++ b/src/@dates/end.m @@ -10,7 +10,7 @@ function lastIndex = end(o, k, n) % OUTPUTS % lastIndex [integer] last dates index -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,4 +26,4 @@ function lastIndex = end(o, k, n) % along with Dynare. If not, see <http://www.gnu.org/licenses/>. assert(k==1 && n==1, 'dates:end:ArgCheck', 'dates only has one dimension'); -lastIndex = o.ndat; \ No newline at end of file +lastIndex = o.ndat(); diff --git a/src/@dates/eq.m b/src/@dates/eq.m index 69866795bf30f9fdadb27571142a12162633a9e5..cb941691450e038d61c13772836a30a29104c97b 100644 --- a/src/@dates/eq.m +++ b/src/@dates/eq.m @@ -9,7 +9,7 @@ function l = eq(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ function l = eq(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = logical(transpose(all(transpose(eq(o.time,p.time))))); else l = logical(transpose(all(transpose(bsxfun(@eq,o.time,p.time))))); diff --git a/src/@dates/ge.m b/src/@dates/ge.m index cf3d289dbea6d02575615e6d25a6949fbf5ac5e5..b4c41e58af85ea8290db038309daa913b06498fc 100644 --- a/src/@dates/ge.m +++ b/src/@dates/ge.m @@ -9,7 +9,7 @@ function l = ge(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,21 +26,21 @@ function l = ge(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = (o==p); idx = find(l==false); for i=1:length(idx) l(idx(i)) = greaterorequal(o.time(idx(i),:), p.time(idx(i),:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = greaterorequal(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterorequal(o.time(i,:), p.time); end end @@ -92,4 +92,4 @@ end %$ t(5) = dassert(dates(B5)>=dd,true(4,1)); %$ t(6) = dassert(dates(B1)>=dd,[true; false(3,1)]); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/gt.m b/src/@dates/gt.m index 36d553ef436479ae77a85ecd67b5e52f7d33bf78..727aed0739dddcfe0191cb245d2c1e23d106f74b 100644 --- a/src/@dates/gt.m +++ b/src/@dates/gt.m @@ -9,7 +9,7 @@ function l = gt(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,20 +26,20 @@ function l = gt(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) - l = false(o.ndat,1); - for i=1:o.ndat +if isequal(o.ndat(), p.ndat()) + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterthan(o.time(i,:), p.time(i,:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = greaterthan(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = greaterthan(o.time(i,:), p.time); end end @@ -89,4 +89,4 @@ end %$ t(5) = dassert(dates(B5)>dd,true(4,1)); %$ t(6) = dassert(dates(B1)>dd,false(4,1)); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/horzcat.m b/src/@dates/horzcat.m index b9217f5863cb908ebb37c913d24860295d6b0a96..dca4f2fb231f6e063d58ec28d18cd67f3054872a 100644 --- a/src/@dates/horzcat.m +++ b/src/@dates/horzcat.m @@ -8,7 +8,7 @@ function o = horzcat(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] object containing dates defined in varargin{:} -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -38,7 +38,6 @@ for i=2:n p = varargin{i}; if isequal(o.freq,p.freq) if ~isempty(p) - o.ndat = o.ndat + p.ndat; o.time = [o.time; p.time]; end else @@ -57,7 +56,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2,B1); @@ -66,7 +64,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:1 @@ -81,7 +79,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -90,7 +87,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:2 @@ -105,7 +102,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -114,7 +110,7 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); %@eof:3 @@ -129,7 +125,6 @@ end %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine. %$ d = dates(B4,B3,B2); @@ -138,6 +133,6 @@ end %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1)==d.ndat(); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/intersect.m b/src/@dates/intersect.m index 738e32ed59c7c138ea32596386bd6c8d9c061d2e..85d954eb6d145be04129d3ef12a63cc22662c853 100644 --- a/src/@dates/intersect.m +++ b/src/@dates/intersect.m @@ -9,7 +9,7 @@ function q = intersect(o, p) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] All the common elements in o and p. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -51,7 +51,6 @@ end q.freq = o.freq; q.time = time; -q.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -67,4 +66,4 @@ q.ndat = rows(time); %$ t(1) = dassert(c1,d2); %$ t(2) = dassert(isempty(c2),true); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/isempty.m b/src/@dates/isempty.m index cb10ef180da4bbb12068f32bf5b7c44c617c749e..ba1396214ae14aa26ddf3b20c9faa5accc164549 100644 --- a/src/@dates/isempty.m +++ b/src/@dates/isempty.m @@ -8,7 +8,7 @@ function l = isempty(o) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -22,8 +22,8 @@ function l = isempty(o) % --*-- Unitary tests --*-- % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. - -l = isequal(o.ndat,0); + +l = isequal(o.ndat(),0); %@test:1 %$ % Instantiate an empty dates object @@ -39,4 +39,4 @@ l = isequal(o.ndat,0); %$ % Test if this object is empty %$ t(1) = ~isempty(d); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/isequal.m b/src/@dates/isequal.m index ca5660562c824887365972995a75a55f67bc0fc1..bfd0784627e7685429c501ad11297476fb85a065 100644 --- a/src/@dates/isequal.m +++ b/src/@dates/isequal.m @@ -9,7 +9,7 @@ function l = isequal(o, p, fake) % OUTPUTS % - l [logical] -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ if ~isequal(o.freq, p.freq) return end -if ~isequal(o.ndat, p.ndat) +if ~isequal(o.ndat(), p.ndat()) l = false; return end diff --git a/src/@dates/le.m b/src/@dates/le.m index 4d18b0b991bff6e234706c998e1a4f043444cc9c..d254407980b089c919efa5711ad41b9b3e04cbd9 100644 --- a/src/@dates/le.m +++ b/src/@dates/le.m @@ -9,7 +9,7 @@ function l = le(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,21 +26,21 @@ function l = le(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = (o==p); idx = find(l==0); for i=1:length(idx) l(idx(i)) = lessorequal(o.time(idx(i),:), p.time(idx(i),:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = lessorequal(o.time, p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessorequal(o.time(i,:), p.time); end end @@ -92,4 +92,4 @@ end %$ t(5) = dassert(dates(B5)<=dd,false(4,1)); %$ t(6) = dassert(dates(B1)<=dd,true(4,1)); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/length.m b/src/@dates/length.m index a30111f05429f34ab0a467a2272ae85c292a56d1..6ee6ae8c31b2fae243604151fb227c2d145c5d9c 100644 --- a/src/@dates/length.m +++ b/src/@dates/length.m @@ -8,7 +8,7 @@ function n = length(o) % OUTPUTS % - n [integer] Number of elements in o. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ function n = length(o) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -n = o.ndat; +n = o.ndat(); %@test:1 %$ d = dates('1938Q1'); @@ -44,4 +44,4 @@ n = o.ndat; %$ % Test if this object is empty %$ t(1) = isequal(d.length(),3); %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/lt.m b/src/@dates/lt.m index 10b12bcbe40c8f3c155b509d867cd32c70736a7b..31bfb35cc443c9dfd05f48daf00c61bf354acf2b 100644 --- a/src/@dates/lt.m +++ b/src/@dates/lt.m @@ -9,7 +9,7 @@ function l = lt(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,20 +26,20 @@ function l = lt(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) - l = false(o.ndat,1); - for i=1:o.ndat +if isequal(o.ndat(), p.ndat()) + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessthan(o.time(i,:),p.time(i,:)); end else - if isequal(o.ndat,1) - l = false(p.ndat,1); - for i=1:p.ndat + if isequal(o.ndat(),1) + l = false(p.ndat(),1); + for i=1:p.ndat() l(i) = lessthan(o.time,p.time(i,:)); end else - l = false(o.ndat,1); - for i=1:o.ndat + l = false(o.ndat(),1); + for i=1:o.ndat() l(i) = lessthan(o.time(i,:),p.time); end end @@ -89,4 +89,4 @@ end %$ t(5) = dassert(dates(B5)<dd,false(4,1)); %$ t(6) = dassert(dates(B1)<dd,[false; true(3,1)]); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/max.m b/src/@dates/max.m index 837071acbc530dab80d76db2b32fef0e52da0ab2..d5b43bc263fe094f00463a98a1cdf38f126c3684 100644 --- a/src/@dates/max.m +++ b/src/@dates/max.m @@ -8,7 +8,7 @@ function q = max(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -32,8 +32,7 @@ switch nargin sorted_time_member = sortrows(varargin{1}.time); q = dates(); q.freq = varargin{1}.freq; - q.ndat = 1; - q.time = sorted_time_member(varargin{1}.ndat,:); + q.time = sorted_time_member(varargin{1}.ndat(),:); otherwise q = max(horzcat(varargin{:})); end @@ -84,4 +83,4 @@ end %$ % Check the results. %$ t(1) = dassert(i,true); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/min.m b/src/@dates/min.m index 3cdbfa7a870421b5f902b1733dcfdab6f6c02197..8fb3005a50c44e1006b562e4245cddc7260fb78c 100644 --- a/src/@dates/min.m +++ b/src/@dates/min.m @@ -8,7 +8,7 @@ function q = min(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - q [dates] -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -32,7 +32,6 @@ switch nargin sorted_time_member = sortrows(varargin{1}.time); q = dates(); q.freq = varargin{1}.freq; - q.ndat = 1; q.time = sorted_time_member(1,:); otherwise q = min(horzcat(varargin{:})); @@ -84,4 +83,4 @@ end %$ % Check the results. %$ t(1) = dassert(i,true); %$ T = all(t); -%@eof:4 \ No newline at end of file +%@eof:4 diff --git a/src/@dates/minus.m b/src/@dates/minus.m index 50520283fc4c634a11f6768d83e398c92d65451e..011d2f394fc39ab6523d22b494d27d0f180a1a96 100644 --- a/src/@dates/minus.m +++ b/src/@dates/minus.m @@ -18,7 +18,7 @@ function q = minus(o,p) % --*-- Unitary tests --*-- % p periods backward. % 3. If o is not a dates object, an error is returned. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -44,11 +44,9 @@ if isa(o,'dates') && isa(p,'dates') v = copy(p); if ~isequal(u.length(),v.length()) if isequal(u.length(),1) - u.time = repmat(u.time,v.ndat,1); - u.ndat = v.ndat; + u.time = repmat(u.time,v.ndat(),1); elseif isequal(v.length(),1) - v.time = repmat(v.time,u.ndat,1); - v.ndat = u.ndat; + v.time = repmat(v.time,u.ndat(),1); else error('dates:minus:ArgCheck','Input arguments lengths are not consistent!') end @@ -59,11 +57,10 @@ if isa(o,'dates') && isa(p,'dates') q(id) = u.time(id,2)-v.time(id,2) + (u.time(id,1)-v.time(id,1))*v.freq; end elseif isa(o,'dates') && ~isa(p,'dates') - if (isvector(p) && isequal(length(p),o.ndat) && all(isint(p))) || (isscalar(p) && isint(p)) || (isequal(o.length(),1) && isvector(p) && all(isint(p))) + if (isvector(p) && isequal(length(p),o.ndat()) && all(isint(p))) || (isscalar(p) && isint(p)) || (isequal(o.length(),1) && isvector(p) && all(isint(p))) q = dates(); q.freq = o.freq; q.time = add_periods_to_array_of_dates(o.time, o.freq, -p(:)); - q.ndat = rows(q.time); else error('dates:minus:ArgCheck','Second argument has to be a vector of integers or scalar integer. You should read the manual.') end @@ -169,4 +166,4 @@ end %$ t(2) = dassert(e1,f1); %$ end %$ T = all(t); -%@eof:5 \ No newline at end of file +%@eof:5 diff --git a/src/@dates/mtimes.m b/src/@dates/mtimes.m index a83465b599182031282e3f6c9a559662e9175f85..b85703b41b0fd0e73c238730c717de8b0b94eb3d 100644 --- a/src/@dates/mtimes.m +++ b/src/@dates/mtimes.m @@ -12,7 +12,7 @@ function p = mtimes(o,n) % --*-- Unitary tests --*-- % 1. If A = dates('2000Q1'), then B=A*3 is a dates object equal to dates('2000Q1','2000Q1','2000Q1') % 2. If A = dates('2003Q1','2009Q2'), then B=A*2 is a dates object equal to dates('2003Q1','2009Q2','2003Q1','2009Q2') -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -33,7 +33,6 @@ end p = copy(o); p.time = repmat(p.time, n, 1); -p.ndat = o.ndat*n; %@test:1 %$ % Define some dates diff --git a/src/@dates/ndat.m b/src/@dates/ndat.m new file mode 100644 index 0000000000000000000000000000000000000000..e817626d2c36ef5b0d2d2db4a988673163d12aaa --- /dev/null +++ b/src/@dates/ndat.m @@ -0,0 +1,26 @@ +function s = ndat(o) + +% Given a one element dates object, returns a string with the formatted date. +% +% INPUTS +% - o [dates] +% +% OUTPUTS +% - s [integer] + +% Copyright (C) 2015 Dynare Team +% +% This code 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 dates submodule 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/>. + +s = size(o.time, 1); diff --git a/src/@dates/ne.m b/src/@dates/ne.m index b8e2a6800e87d86d55ce052e292d62ac57aec335..351166ec473cc77e676cd67842a69802fc409b3e 100644 --- a/src/@dates/ne.m +++ b/src/@dates/ne.m @@ -9,7 +9,7 @@ function l = ne(varargin) % --*-- Unitary tests --*-- % OUTPUTS % - l [logical] column vector of max(n,1) elements (zeros or ones). -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ function l = ne(varargin) % --*-- Unitary tests --*-- [o, p] = comparison_arg_checks(varargin{:}); -if isequal(o.ndat, p.ndat) +if isequal(o.ndat(), p.ndat()) l = logical(transpose(any(transpose(ne(o.time,p.time))))); else l = logical(transpose(any(transpose(bsxfun(@ne,o.time,p.time))))); diff --git a/src/@dates/plus.m b/src/@dates/plus.m index 1417d26524642a259887e3d3add1d0b779d065da..0ad0d43e786052c9c4dfe02ae393a7dc19d2736b 100644 --- a/src/@dates/plus.m +++ b/src/@dates/plus.m @@ -14,7 +14,7 @@ function q = plus(o,p) % --*-- Unitary tests --*-- % 2. If one of the inputs is an integer or a vector of integers, the method shifts the dates % object by X (the interger input) periods forward. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -45,22 +45,19 @@ if isa(o,'dates') && isa(p,'dates') q = dates(); q.freq = o.freq; q.time = [o.time; p.time]; - q.ndat = o.ndat+p.ndat; elseif isa(o,'dates') || isa(p,'dates') - if isa(o,'dates') && ((isvector(p) && isequal(length(p),o.ndat) && all(isint(p))) || ... + if isa(o,'dates') && ((isvector(p) && isequal(length(p),o.ndat()) && all(isint(p))) || ... (isequal(o.length(),1) && isvector(p) && all(isint(p))) || ... (isscalar(p) && isint(p))) q = dates(); q.freq = o.freq; q.time = add_periods_to_array_of_dates(o.time, q.freq, p(:)); - q.ndat = rows(q.time); - elseif isa(p,'dates') && ((isvector(o) && isequal(length(o),p.ndat) && all(isint(o))) || ... + elseif isa(p,'dates') && ((isvector(o) && isequal(length(o),p.ndat()) && all(isint(o))) || ... (isequal(p.length(),1) && isvector(o) && all(isint(o))) || ... (isscalar(o) && isint(o)) ) q = dates(); q.freq = p.freq; q.time = add_periods_to_array_of_dates(p.time, q.freq, o(:)); - q.ndat = rows(q.time); else error('dates:plus:ArgCheck','Please read the manual.') end @@ -150,4 +147,4 @@ end %$ t(6) = dassert(e5,f5); %$ end %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/pop.m b/src/@dates/pop.m index 78da6459769dd938b1049f26b5a6334ddda664be..bc9c25ad41ca0710f13c3cafa3752af286776399 100644 --- a/src/@dates/pop.m +++ b/src/@dates/pop.m @@ -15,7 +15,7 @@ function o = pop(o, p) % --*-- Unitary tests --*-- % % See also remove, setdiff. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -36,7 +36,6 @@ end if nargin<2 % Remove last date - o.ndat = o.ndat-1; o.time = o.time(1:end-1,:); return end @@ -50,9 +49,8 @@ if ischar(p) end if isnumeric(p) - idx = find(transpose(1:o.ndat)~=p); + idx = find(transpose(1:o.ndat())~=p); o.time = o.time(idx,:); - o.ndat = o.ndat-1; else if ~isequal(o.freq,p.freq) error('dates:pop','Inputs must have common frequency!') @@ -64,9 +62,8 @@ else return end idx = find(o==p); - jdx = find(transpose(1:o.ndat)~=idx(end)); + jdx = find(transpose(1:o.ndat())~=idx(end)); o.time = o.time(jdx,:); - o.ndat = o.ndat-1; end %@test:1 @@ -80,7 +77,6 @@ end %$ % Define expected results %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4; 2009 2]; %$ e.freq = 4; -%$ e.ndat = 5; %$ %$ % Call the tested routine %$ d = dates(B4,B3,B2,B1); @@ -88,16 +84,16 @@ end %$ d.pop(); %$ t(1) = dassert(d.time,e.time(1:end-1,:)); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat-1); +%$ t(3) = size(e.time,1)-1==d.ndat(); %$ f = copy(d); %$ d.pop(B1); %$ t(4) = dassert(d.time,[1945 3; 1950 1; 1950 2]); %$ t(5) = dassert(d.freq,e.freq); -%$ t(6) = dassert(d.ndat,e.ndat-2); +%$ t(6) = size(e.time,1)-2==d.ndat(); %$ f.pop(dates(B1)); %$ t(7) = dassert(f.time,[1945 3; 1950 1; 1950 2]); %$ t(8) = dassert(f.freq,e.freq); -%$ t(9) = dassert(f.ndat,e.ndat-2); +%$ t(9) = size(e.time,1)-2==f.ndat(); %$ %$ % Check the results. %$ T = all(t); @@ -137,4 +133,4 @@ end %$ d.pop(1); %$ t(3) = isempty(d); %$ T = all(t); -%@eof:3 \ No newline at end of file +%@eof:3 diff --git a/src/@dates/remove.m b/src/@dates/remove.m index 54377e1b2045e4a4afa4f3d8bbf5af21ed017ea7..d11830af31e11a603c447cae69ab931fa94410a4 100644 --- a/src/@dates/remove.m +++ b/src/@dates/remove.m @@ -15,7 +15,7 @@ function o = remove(o, p) % --*-- Unitary tests --*-- % % See also pop, setdiff -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -49,7 +49,6 @@ else end o.time = time; -o.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -77,4 +76,4 @@ o.ndat = rows(time); %$ % Check the results. %$ t(1) = dassert(d,f); %$ T = all(t); -%@eof:2 \ No newline at end of file +%@eof:2 diff --git a/src/@dates/setdiff.m b/src/@dates/setdiff.m index 8e5ef089498b16f3c0f2bf1d7b8fb757d768e1b0..1abe6943bf626a60446edff3cf6d59a81c289715 100644 --- a/src/@dates/setdiff.m +++ b/src/@dates/setdiff.m @@ -11,7 +11,7 @@ function q = setdiff(o,p) % --*-- Unitary tests --*-- % % See also pop, remove. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -51,7 +51,6 @@ if isempty(time) end q.time = time; -q.ndat = rows(time); %@test:1 %$ % Define some dates objects @@ -67,4 +66,4 @@ q.ndat = rows(time); %$ t(1) = dassert(c1,d2); %$ t(2) = dassert(isempty(c2),logical(1)); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/sort.m b/src/@dates/sort.m index d1c032857e1f69703fbabab82e04a7da1db626b3..882decb4d6a411e679516c2c4d4256488e34cb39 100644 --- a/src/@dates/sort.m +++ b/src/@dates/sort.m @@ -8,7 +8,7 @@ function o = sort(o) % --*-- Unitary tests --*-- % OUTPUTS % - o [dates] with dates sorted by increasing order. -% Copyright (C) 2011-2014 Dynare Team +% Copyright (C) 2011-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ function o = sort(o) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if isequal(o.ndat,1) +if isequal(o.ndat(),1) return end @@ -39,7 +39,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -48,7 +47,7 @@ o.time = sortrows(o.time,[1,2]); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); %@eof:1 @@ -62,7 +61,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Define expected results. %$ e.time = [1945 3; 1950 1; 1950 2; 1953 4]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4); @@ -71,6 +69,6 @@ o.time = sortrows(o.time,[1,2]); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1 diff --git a/src/@dates/strings.m b/src/@dates/strings.m index 0e3d47bd5d6519148e2187a2186969f70247c7ea..0198d15c1e69fcc354683e451f65c578bf2006ad 100644 --- a/src/@dates/strings.m +++ b/src/@dates/strings.m @@ -8,7 +8,7 @@ function m = strings(o) % OUTPUTS % - m [cell of char] object with n elements. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -23,8 +23,8 @@ function m = strings(o) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -m = cell(1,o.ndat); +m = cell(1,o.ndat()); for i = 1:o.length() m(i) = { date2string(o.time(i,:), o.freq) }; -end \ No newline at end of file +end diff --git a/src/@dates/subsref.m b/src/@dates/subsref.m index 8d8bb5723c97e9dd20144cca26466c2c1a7326f6..d442598857a62919a79e0b13824837f7ac94e2b0 100644 --- a/src/@dates/subsref.m +++ b/src/@dates/subsref.m @@ -13,7 +13,7 @@ function B = subsref(A,S) % --*-- Unitary tests --*-- % 1. The type of the returned argument depends on the content of S. % 2. See the matlab's documentation about the subsref method. -% Copyright (C) 2011-2014 Dynare Team +% Copyright (C) 2011-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -31,12 +31,12 @@ function B = subsref(A,S) % --*-- Unitary tests --*-- switch S(1).type case '.' switch S(1).subs - case {'time','freq','ndat'}% Access public members. + case {'time','freq'}% Access public members. if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) error(['dates::subsref: ' S(1).subs ' is not a method but a member!']) end B = builtin('subsref', A, S(1)); - case {'sort','unique','double','isempty','length','char'}% Public methods (without input arguments) + case {'sort','unique','double','isempty','length','char','ndat'}% Public methods (without input arguments) B = feval(S(1).subs,A); if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs) S = shiftS(S,1); @@ -94,7 +94,6 @@ switch S(1).type else error('dates::subsref: This is a bug!') end - B.ndat = rows(B.time); elseif isequal(length(S(1).subs),3) % If three inputs are provided, the second and third inputs are column verctors of integers (years and subperiods). if ~iscolumn(S(1).subs{2}) && ~all(isint(S(1).subs{2})) @@ -109,7 +108,6 @@ switch S(1).type error('dates::subsref: Second and third input arguments must have the same number of elements!') end B.time = [S(1).subs{2}, S(1).subs{3}]; - B.ndat = rows(B.time); else error('dates::subsref: Wrong calling sequence!') end @@ -130,7 +128,6 @@ switch S(1).type error('dates::subsref: First and second argument must have the same number of rows!') end B.time = [S(1).subs{1}, S(1).subs{2}]; - B.ndat = rows(B.time); elseif isequal(length(S(1).subs),1) [n, m] = size(S(1).subs{1}); if ~isequal(m,2) && ~isequal(B.freq,1) @@ -149,20 +146,18 @@ switch S(1).type else error('dates::subsref: This is a bug!') end - B.ndat = rows(B.time); else error('dates::subsref: Wrong number of inputs!') end end else % dates object A is not empty. We extract some dates - if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat) + if isvector(S(1).subs{1}) && all(isint(S(1).subs{1})) && all(S(1).subs{1}>0) && all(S(1).subs{1}<=A.ndat()) B = dates(); B.freq = A.freq; B.time = A.time(S(1).subs{1},:); - B.ndat = rows(B.time); else - error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat) '!']) + error(['dates::subsref: indices has to be a vector of positive integers less than or equal to ' int2str(A.ndat()) '!']) end end otherwise @@ -190,7 +185,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:1 @@ -212,7 +207,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:2 @@ -234,7 +229,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2; 1950 3]); -%$ t(4) = dassert(d.ndat,2); +%$ t(4) = dassert(d.ndat(),2); %$ end %$ T = all(t); %@eof:3 @@ -255,7 +250,7 @@ end %$ if t(1) %$ t(2) = dassert(d.freq,B.freq); %$ t(3) = dassert(d.time,[1950 2]); -%$ t(4) = dassert(d.ndat,1); +%$ t(4) = dassert(d.ndat(),1); %$ end %$ T = all(t); %@eof:4 diff --git a/src/@dates/unique.m b/src/@dates/unique.m index 1d744322e65d778208a9baafe178e8f6626caeec..5ace4bd7f164711199ce93e4216a7996b2c83942 100644 --- a/src/@dates/unique.m +++ b/src/@dates/unique.m @@ -11,7 +11,7 @@ function o = unique(o) % --*-- Unitary tests --*-- % REMARKS % 1. Only the last occurence of a date is kept. -% Copyright (C) 2013-2014 Dynare Team +% Copyright (C) 2013-2015 Dynare Team % % This code is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -26,7 +26,7 @@ function o = unique(o) % --*-- Unitary tests --*-- % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <http://www.gnu.org/licenses/>. -if o.ndat<=1 +if o.ndat()<=1 return end @@ -37,7 +37,6 @@ else end o.time = o.time(sort(id),:); -o.ndat = size(o.time,1); %@test:1 %$ % Define some dates @@ -50,7 +49,6 @@ o.ndat = size(o.time,1); %$ % Define expected results. %$ e.time = [1953 4; 1950 1; 1945 3; 1950 2]; %$ e.freq = 4; -%$ e.ndat = 4; %$ %$ % Call the tested routine. %$ d = dates(B1,B2,B3,B4,B5); @@ -59,6 +57,6 @@ o.ndat = size(o.time,1); %$ % Check the results. %$ t(1) = dassert(d.time,e.time); %$ t(2) = dassert(d.freq,e.freq); -%$ t(3) = dassert(d.ndat,e.ndat); +%$ t(3) = size(e.time,1) == d.ndat(); %$ T = all(t); -%@eof:1 \ No newline at end of file +%@eof:1