set_names.m 2.02 KB
Newer Older
1
function o = set_names(o, varargin) % --*-- Unitary tests --*--
2

3 4
% Specifies names of the variables in a dseries object (in place modification).
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
5
% INPUTS
6 7 8
% - o                 [dseries]
% - s1, s2, s3, ...   [string]
%
Stéphane Adjemian's avatar
Stéphane Adjemian committed
9
% OUTPUTS
10
% - o                 [dseries]
11

12
% Copyright (C) 2017 Dynare Team
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
%
% 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 <http://www.gnu.org/licenses/>.

n = nargin-1;

31
if ~isdseries(o)
32 33 34 35 36
    if isempty(inputname(1))
        error(['dseries::set_names: First input must be a dseries object!'])
    else
        error(['dseries::set_names: ' inputname(1) ' must be a dseries object!'])
    end
37 38
end

39
if ~isequal(vobs(o), n)
40 41 42 43 44
    if isempty(inputname(1))
        error(['dseries::set_names: The number of variables in first input does not match the number of declared names!'])
    else
        error(['dseries::set_names: The number of variables in ' inputname(1) ' does not match the number of declared names!'])
    end
45 46
end

47
for i=1:vobs(o)
48
    if ~isempty(varargin{i})
49
        o.name(i) = { varargin{i} };
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    end
end

%@test:1
%$ % Define a datasets.
%$ A = rand(10,3);
%$
%$ % Define names
%$ A_name = {'A1';'Variable_2';'A3'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ try
%$    ts1 = dseries(A,[],[],[]);
65
%$    ts1.set_names('A1',[],'A3');
66 67 68 69
%$    t(1) = 1;
%$ catch
%$    t = 0;
%$ end
Stéphane Adjemian's avatar
Stéphane Adjemian committed
70
%$
71 72 73 74 75 76
%$ if length(t)>1
%$    t(2) = dassert(ts1.vobs,3);
%$    t(3) = dassert(ts1.nobs,10);
%$    t(4) = dassert(ts1.name,A_name);
%$ end
%$ T = all(t);
77
%@eof:1