Commit 56be6eb4 authored by Stéphane Adjemian's avatar Stéphane Adjemian
Browse files

Added new interface to dynDate. The constructor accepts a character ('Y', 'A',...

Added new interface to dynDate. The constructor accepts a character ('Y', 'A', 'Q', 'M' or 'W') as the second input to specify the frequency instead of an integer (1, 4, 12, or 52). The following expressions are equivalent:

a = dynDate([1945 3],4);
a = dynDate([1945 3],'Q');
parent d44732a8
......@@ -144,31 +144,45 @@ switch nargin
date = dynDate();
if isnumeric(b) && isscalar(b) && ismember(b,[1,4,12,52])
date.freq = b;
if ~isnumeric(a)
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be numeric!'])
end
if ~all(isint(a))
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a scalar or a 1*2 vector of integers!'])
end
if ~isequal(size(a),[1,2])
if b>1
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a 1*2 vector of integers.'])
end
else
if isequal(b,1) && isequal(a(2),1)
error(['dynDate:: Can''t instantiate the class! The second element of the first input argument ' inputname(a) ' must be equal to one (because freq==1)!'])
end
elseif ischar(b) && isequal(length(b),1) && ismember(upper(b),{'Y','A','W','M','Q'})
b = upper(b);
switch b
case {'Y','A'}
date.freq = 1;
case 'W'
date.freq = 52;
case 'M'
date.freq = 12;
case 'Q'
date.freq = 4;
otherwise
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
end
if a(2)<=0 || a(2)>b
error(['dynDate:: Can''t instantiate the class! The second element of the first argument ' inputname(a) ' must be a positive integer be <=' int2str(b) '!' ])
else
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be an integer equal to 1, 4, 12 or 52, or a character equal to ''Y'', ''A'', ''W'', ''M'' or ''Q''!'])
end
if ~isnumeric(a)
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be numeric!'])
end
if ~all(isint(a))
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a scalar or a 1*2 vector of integers!'])
end
if ~isequal(size(a),[1,2])
if date.freq>1
error(['dynDate:: Can''t instantiate the class! The first argument ' inputname(a) ' must be a 1*2 vector of integers.'])
end
if length(a)==1
date.time = [a, 1];
else
date.time = a;
else
if isequal(date.freq,1) && isequal(a(2),1)
error(['dynDate:: Can''t instantiate the class! The second element of the first input argument ' inputname(a) ' must be equal to one (because freq==1)!'])
end
end
if a(2)<=0 || a(2)>date.freq
error(['dynDate:: Can''t instantiate the class! The second element of the first argument ' inputname(a) ' must be a positive integer be <=' int2str(b) '!' ])
end
if length(a)==1
date.time = [a, 1];
else
error(['dynDate:: Can''t instantiate the class! The second argument ' inputname(b) ' must be equal to 1, 4, 12 or 52.'])
date.time = a;
end
otherwise
error('dynDate:: Can''t instantiate the class, wrong calling sequence!')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment