Fixed indentation.

parent da02ca32
......@@ -2,11 +2,11 @@ function o = append(o, d) % --*-- Unitary tests --*--
% append method for dates class.
%
% INPUTS
% INPUTS
% - o [dates]
% - a [dates or string] dates object with one element or string that can be interpreted as a date.
%
% OUTPUTS
% OUTPUTS
% - o [dates] dates object containing dates defined in o and d.
% Copyright (C) 2012-2015 Dynare Team
......
......@@ -2,11 +2,11 @@ function o = append_(o, d) % --*-- Unitary tests --*--
% append method for dates class (in place modification).
%
% INPUTS
% INPUTS
% - o [dates]
% - a [dates or string] dates object with one element or string that can be interpreted as a date.
%
% OUTPUTS
% OUTPUTS
% - o [dates] dates object containing dates defined in o and d.
% Copyright (C) 2012-2015 Dynare Team
......
......@@ -2,7 +2,7 @@ function s = char(o) % --*-- Unitary tests --*--
% Given a one element dates object, returns a string with the formatted date.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPUTS
......@@ -118,4 +118,3 @@ s = date2string(o.time, o.freq);
%$ end
%$ T = all(t);
%@eof:5
......@@ -2,15 +2,15 @@ function q = colon(varargin) % --*-- Unitary tests --*--
% Overloads the colon operator (:). This method can be used to create ranges of dates.
%
% INPUTS
% INPUTS
% o o [dates] Initial date.
% o d [integer] Number of periods between each date (default value, if nargin==2, is one)
% o p [dates] Terminal date.
%
% OUTPUTS
% OUTPUTS
% o q [dates] Object with length(p-o) elements (if d==1).
%
% REMARKS
% REMARKS
% 1. p must be greater than o if d>0.
% 2. p and q are dates objects with one element.
......@@ -70,7 +70,7 @@ q = dates();
n = (p-o)+1; % The number of elements in q dates object if d==1.
m = n;
if d>1 % Correction of the number of elements (if d is not equal to one).
m = length(1:d:n);
m = length(1:d:n);
end
% Set the frequency in q
......
......@@ -39,7 +39,7 @@ p.time = o.time;
%$ catch
%$ t(1) = false;
%$ end
%$
%$
%$ if t(1)
%$ o.sort_();
%$ t(2) = dassert(p, q);
......
......@@ -15,116 +15,116 @@ classdef dates<handle % --*-- 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/>.
properties
freq = []; % Frequency (integer scalar)
time = []; % Array (one row for every date. first column is the year, second is the period)
end
properties
freq = []; % Frequency (integer scalar)
time = []; % Array (one row for every date. first column is the year, second is the period)
end
methods
methods
function o = dates(varargin)
if ~nargin
% Returns empty dates object.
o.freq = NaN(0);
o.time = NaN(0,2);
return
if ~nargin
% Returns empty dates object.
o.freq = NaN(0);
o.time = NaN(0,2);
return
end
if all(cellfun(@isdates, varargin))
% Concatenates dates objects in a dates object.
o = horzcat(varargin{:});
return
end
if all(cellfun(@isstringdate,varargin))
% Concatenates dates in a dates object.
tmp = cellfun(@string2date,varargin);
if all([tmp.freq]-tmp(1).freq==0)
o.freq = tmp(1).freq;
else
error('dates:ArgCheck', 'All dates passed as inputs must have the same frequency!')
end
if all(cellfun(@isdates, varargin))
% Concatenates dates objects in a dates object.
o = horzcat(varargin{:});
return
o.time = transpose(reshape([tmp.time], 2, length(tmp)));
return
end
if isequal(nargin,1) && isfreq(varargin{1})
% Instantiate an empty dates object (only set frequency)
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
else
o.freq = varargin{1};
end
if all(cellfun(@isstringdate,varargin))
% Concatenates dates in a dates object.
tmp = cellfun(@string2date,varargin);
if all([tmp.freq]-tmp(1).freq==0)
o.freq = tmp(1).freq;
else
error('dates:ArgCheck', 'All dates passed as inputs must have the same frequency!')
end
o.time = transpose(reshape([tmp.time], 2, length(tmp)));
return
end
if isequal(nargin,1) && isfreq(varargin{1})
% Instantiate an empty dates object (only set frequency)
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
else
o.freq = varargin{1};
end
return
return
end
if isequal(nargin,3) && isfreq(varargin{1})
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
else
o.freq = varargin{1};
end
if isequal(nargin,3) && isfreq(varargin{1})
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
else
o.freq = varargin{1};
end
if (isnumeric(varargin{2}) && isvector(varargin{2}) && all(isint(varargin{2})))
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}(:)];
else
error('dates:ArgCheck','Third input must contain integers between 1 and %i.', o.freq)
end
if (isnumeric(varargin{2}) && isvector(varargin{2}) && all(isint(varargin{2})))
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}(:)];
else
error('dates:ArgCheck','Third input must be a vector of integers.')
error('dates:ArgCheck','Third input must contain integers between 1 and %i.', o.freq)
end
else
error('dates:ArgCheck','Second input must be a vector of integers.')
error('dates:ArgCheck','Third input must be a vector of integers.')
end
return
else
error('dates:ArgCheck','Second input must be a vector of integers.')
end
return
end
if isequal(nargin,2) && isfreq(varargin{1})
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
else
o.freq = varargin{1};
end
if isequal(nargin,2) && isfreq(varargin{1})
o.time = NaN(0,2);
if ischar(varargin{1})
o.freq = string2freq(varargin{1});
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)];
return
else
o.freq = varargin{1};
error('dates:ArgCheck','Second input must be a vector of integers.')
end
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)];
return
else
error('dates:ArgCheck','Second input must be a vector of integers.')
end
else
if isequal(size(varargin{2},2), 2)
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)];
else
error('dates:ArgCheck','Second column of the last input must contain integers between 1 and %i.',o.freq)
end
else
if isequal(size(varargin{2},2), 2)
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)];
else
error('dates:ArgCheck','Second input argument must be an array of integers.')
error('dates:ArgCheck','Second column of the last input must contain integers between 1 and %i.',o.freq)
end
else
error('dates:ArgCheck','Wrong calling sequence!')
error('dates:ArgCheck','Second input argument must be an array of integers.')
end
else
error('dates:ArgCheck','Wrong calling sequence!')
end
return
end
error('dates:ArgCheck','You should first read the manual!')
return
end
error('dates:ArgCheck','You should first read the manual!')
end % dates constructor.
% Other methods
p = sort(o);
o = sort_(o);
p = unique(o);
o = unique_(o);
p = append(o, d);
o = append_(o, d);
p = pop(o, d);
o = pop_(o, d);
p = remove(o, d);
o = remove_(o, d);
s = char(o);
a = double(o);
n = ndat(o);
n = length(o);
end % methods
% Other methods
p = sort(o);
o = sort_(o);
p = unique(o);
o = unique_(o);
p = append(o, d);
o = append_(o, d);
p = pop(o, d);
o = pop_(o, d);
p = remove(o, d);
o = remove_(o, d);
s = char(o);
a = double(o);
n = ndat(o);
n = length(o);
end % methods
end % classdef
......@@ -140,7 +140,7 @@ end % classdef
%$ e.freq = 4;
%$
%$ % Call the tested routine.
%$ d = dates(B1,B2,B3,B4);
%$ d = dates(B1,B2,B3,B4);
%$
%$ % Check the results.
%$ t(1) = dassert(d.time, e.time);
......
......@@ -2,10 +2,10 @@ function disp(o)
% Overloads the disp function for dates object.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPTS
% OUTPTS
% None
% Copyright (C) 2013-2014 Dynare Team
......
......@@ -2,10 +2,10 @@ function display(o)
% Overloads display method for dates object.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPTS
% OUTPTS
% None
% Copyright (C) 2013-2014 Dynare Team
......
......@@ -3,14 +3,14 @@ function [m, f] = double(o) % --*-- Unitary tests --*--
% Returns a vector of doubles with the fractional part corresponding
% to the subperiod. Used for plots and to store dates in a matrix.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPUTS
% OUTPUTS
% - m [double] o.ndat*1 vector of doubles.
% - f [integer] scalar, the frequency (1, 4, 12 or 52).
%
% REMARKS
% REMARKS
% Obviously the frequency is lost during the conversion.
% Copyright (C) 2013-2014 Dynare Team
......
......@@ -40,7 +40,7 @@ lastIndex = o.ndat();
%$ catch
%$ t(1) = false;
%$ end
%$
%$
%$ if t(1)
%$ t(2) = dassert(p, q);
%$ end
......
......@@ -2,11 +2,11 @@ function l = ge(varargin) % --*-- Unitary tests --*--
% Overloads the >= operator for dates objects.
%
% INPUTS
% INPUTS
% - o [dates] dates object with n or 1 elements.
% - p [dates] dates object with n or 1 elements.
%
% OUTPUTS
% OUTPUTS
% - l [logical] column vector of max(n,1) elements (zeros or ones).
% Copyright (C) 2013-2015 Dynare Team
......@@ -62,7 +62,7 @@ end
%$ i2 = (d3>=d4);
%$ i3 = (d4>=d2);
%$ i4 = (d5>=d4);
%$ i5 = (d5>=d5);
%$ i5 = (d5>=d5);
%$
%$ % Check the results.
%$ t(1) = dassert(i1,false);
......
......@@ -2,10 +2,10 @@ function o = horzcat(varargin) % --*-- Unitary tests --*--
% Overloads the horzcat method for dates objects.
%
% INPUTS
% INPUTS
% - varargin [dates]
%
% OUTPUTS
% OUTPUTS
% - o [dates] object containing dates defined in varargin{:}
% Copyright (C) 2013-2017 Dynare Team
......
......@@ -2,11 +2,11 @@ function q = intersect(o, p) % --*-- Unitary tests --*--
% Overloads intersect function for dates objects.
%
% INPUTS
% INPUTS
% - o [dates]
% - p [dates]
%
% OUTPUTS
% OUTPUTS
% - q [dates] All the common elements in o and p.
% Copyright (C) 2013-2015 Dynare Team
......
......@@ -2,10 +2,10 @@ function l = isempty(o) % --*-- Unitary tests --*--
% Returns true (1) if and only if o dates object is empty.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPUTS
% OUTPUTS
% - l [logical]
% Copyright (C) 2013-2015 Dynare Team
......
......@@ -2,11 +2,11 @@ function l = isequal(o, p, fake) % --*-- Unitary tests --*--
% Overloads isequal function for dates objects. Returns true (1) iff o and p have the same elements.
%
% INPUTS
% INPUTS
% - o [dates]
% - p [dates]
%
% OUTPUTS
% OUTPUTS
% - l [logical]
% Copyright (C) 2013-2015 Dynare Team
......@@ -69,4 +69,3 @@ l = isequal(o.freq, p.freq) && isequal(o.time, p.time);
%$ t(1) = ~isequal(d1,d2);
%$ T = all(t);
%@eof:5
......@@ -2,11 +2,11 @@ function l = le(varargin) % --*-- Unitary tests --*--
% Overloads the <= operator for dates objects.
%
% INPUTS
% INPUTS
% - o [dates] dates object with n or 1 elements.
% - p [dates] dates object with n or 1 elements.
%
% OUTPUTS
% OUTPUTS
% - l [logical] column vector of max(n,1) elements (zeros or ones).
% Copyright (C) 2013-2015 Dynare Team
......
......@@ -2,10 +2,10 @@ function n = length(o) % --*-- Unitary tests --*--
% Returns the number of elements in a dates object.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPUTS
% OUTPUTS
% - n [integer] Number of elements in o.
% Copyright (C) 2013-2015 Dynare Team
......
......@@ -2,11 +2,11 @@ function l = lt(varargin) % --*-- Unitary tests --*--
% Overloads the < operator for dates objects.
%
% INPUTS
% INPUTS
% - o [dates] dates object with n or 1 elements.
% - p [dates] dates object with n or 1 elements.
%
% OUTPUTS
% OUTPUTS
% - l [logical] column vector of max(n,1) elements (zeros or ones).
% Copyright (C) 2013-2015 Dynare Team
......
function q = max(varargin) % --*-- Unitary tests --*--
% Overloads the max function for dates objects.
%
% INPUTS
% INPUTS
% - varargin [dates]
%
% OUTPUTS
% OUTPUTS
% - q [dates]
% Copyright (C) 2013-2015 Dynare Team
......
......@@ -2,10 +2,10 @@ function q = min(varargin) % --*-- Unitary tests --*--
% Overloads the min function for dates objects.
%
% INPUTS
% INPUTS
% - varargin [dates]
%
% OUTPUTS
% OUTPUTS
% - q [dates]
% Copyright (C) 2013-2015 Dynare Team
......
function q = minus(o,p) % --*-- Unitary tests --*--
% Overloads the minus operator (-). If o and p are dates objects, the method . If
% Overloads the minus operator (-). If o and p are dates objects, the method . 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 backward.
% Overloads the minus (-) binary operator.
%
% INPUTS
% INPUTS
% - o [dates]
% - p [dates or integer]
%
% OUTPUTS
% OUTPUTS
% - q [dates]
%
% REMARKS
% REMARKS
% 1. If o and p are dates objects the method returns the number of periods between o and p (so that q+o=p).
% 2. If o is a dates object and p is an integer (scalar or vector), the method shifts the dates object by
% p periods backward.
......
......@@ -2,14 +2,14 @@ function p = mtimes(o,n) % --*-- Unitary tests --*--
% Overloads the times operator (*). Returns dates object o replicated n times.
%
% INPUTS
% INPUTS
% - o [dates] object with m elements.
%
% OUTPUTS
% OUTPUTS
% - p [dates] object with m*n elements.
%
% EXAMPLES
% 1. If A = dates('2000Q1'), then B=A*3 is a dates object equal to dates('2000Q1','2000Q1','2000Q1')
% EXAMPLES
% 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-2015 Dynare Team
......
......@@ -2,7 +2,7 @@ function s = ndat(o) % --*-- Unitary tests --*--
% Given a one element dates object, returns a string with the formatted date.
%
% INPUTS
% INPUTS
% - o [dates]
%
% OUTPUTS
......@@ -96,5 +96,3 @@ s = size(o.time, 1);
%$ end
%$ T = all(t);
%@eof:4
......@@ -2,14 +2,14 @@ function q = plus(o,p) % --*-- Unitary tests --*--
% Overloads the plus (+) binary operator.
%
% INPUTS
% INPUTS
% - o [dates or integer]
% - p [dates or integer]
%
% OUTPUTS
% OUTPUTS
% - q [dates]
%
% REMARKS
% REMARKS
% 1. If o and p are dates objects the method combines o and p without removing repetitions.
% 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.
......@@ -80,7 +80,7 @@ end
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ if t(1)
%$ t(2) = dassert(e1,d3);
%$ t(3) = dassert(e2,dates('1950Q1','1950Q2','1950Q3','1950Q4','1950Q1','1950Q2','1950Q3','1950Q4'));
%$ end
......
......@@ -2,19 +2,19 @@ function o = pop(o, p) % --*-- Unitary tests --*--
% pop method for dates class (removes a date).
%
% INPUTS
% INPUTS
% - o [dates]
% - p [dates] object with one element, string which can be interpreted as a date or integer scalar.
%
% OUTPUTS
% OUTPUTS
% - o [dates]
%
% REMARKS
% REMARKS
% 1. If a is a date appearing more than once in o, then only the last occurence is removed. If one wants to
% remove all the occurences of p in o, the remove method should be used instead.
%
% See also remove, setdiff.
% Copyright (C) 2013-2015 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
......
......@@ -2,19 +2,19 @@ function o = pop_(o, p) % --*-- Unitary tests --*--
% pop method for dates class (in place modification).
%
% INPUTS
% INPUTS
% - o [dates]
% - p [dates] object with one element, string which can be interpreted as a date or integer scalar.
%
% OUTPUTS
% OUTPUTS
% - o [dates]
%
% REMARKS
% REMARKS
% 1. If a is a date appearing more than once in o, then only the last occurence is removed. If one wants to
% remove all the occurences of p in o, the remove method should be used instead.
%
% See also remove, setdiff.
% Copyright (C) 2013-2015 Dynare Team
%
% This code is free software: you can redistribute it and/or modify
......@@ -33,7 +33,7 @@ function o = pop_(o, p) % --*-- Unitary tests --*--
if o.isempty()
return
end
if nargin<2
% Remove last date
o.time = o.time(1:end-1,:);
......@@ -197,7 +197,7 @@ end
%$ if t(5)
%$ t(6) = isempty(d);
%$ end
%$ end
%$ end
%$ end
%$ T = all(t);
%@eof:3
......
......@@ -2,10 +2,10 @@ function [o, p] = comparison_arg_checks(varargin) % --*-- Unitary tests --*--
% Returns two dates objects or an error if objects to be compared are not compatible.
%
% INPUTS
% INPUTS
% - varargin
%
% OUTPUTS
% OUTPUTS
% - o [dates] dates object with n or 1 elements.
% - p [dates] dates object with n or 1 elements.
......
......@@ -2,13 +2,13 @@ function str = dates4display(o, name, max_number_of_elements) % --*-- Unitary te
% Converts a list object to a string.
%
% INPUTS
% INPUTS
% - o [list] A dates object to be displayed.
% - name [string] Name of the dates object o.
% - max_number_of_elements [integer] Maximum number of elements displayed.
%
% OUTPUTS
% - str [string] Representation of the dates object as a string.
% OUTPUTS