1function o = set_names(o, varargin) % --*-- Unitary tests --*--
2
3% Specifies names of the variables in a dseries object (in place modification).
4%
5% INPUTS
6% - o                 [dseries]
7% - s1, s2, s3, ...   [string]
8%
9% OUTPUTS
10% - o                 [dseries]
11
12% Copyright (C) 2017 Dynare Team
13%
14% This file is part of Dynare.
15%
16% Dynare is free software: you can redistribute it and/or modify
17% it under the terms of the GNU General Public License as published by
18% the Free Software Foundation, either version 3 of the License, or
19% (at your option) any later version.
20%
21% Dynare is distributed in the hope that it will be useful,
22% but WITHOUT ANY WARRANTY; without even the implied warranty of
23% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24% GNU General Public License for more details.
25%
26% You should have received a copy of the GNU General Public License
27% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
28
29n = nargin-1;
30
31if ~isdseries(o)
32    if isempty(inputname(1))
33        error(['dseries::set_names: First input must be a dseries object!'])
34    else
35        error(['dseries::set_names: ' inputname(1) ' must be a dseries object!'])
36    end
37end
38
39if ~isequal(vobs(o), n)
40    if isempty(inputname(1))
41        error(['dseries::set_names: The number of variables in first input does not match the number of declared names!'])
42    else
43        error(['dseries::set_names: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
44    end
45end
46
47for i=1:vobs(o)
48    if ~isempty(varargin{i})
49        o.name(i) = { varargin{i} };
50    end
51end
52
53%@test:1
54%$ % Define a datasets.
55%$ A = rand(10,3);
56%$
57%$ % Define names
58%$ A_name = {'A1';'Variable_2';'A3'};
59%$
60%$ t = zeros(4,1);
61%$
62%$ % Instantiate a time series object.
63%$ try
64%$    ts1 = dseries(A,[],[],[]);
65%$    ts1.set_names('A1',[],'A3');
66%$    t(1) = 1;
67%$ catch
68%$    t = 0;
69%$ end
70%$
71%$ if length(t)>1
72%$    t(2) = dassert(ts1.vobs,3);
73%$    t(3) = dassert(ts1.nobs,10);
74%$    t(4) = dassert(ts1.name,A_name);
75%$ end
76%$ T = all(t);
77%@eof:1