1function l = exist(o, varname) % --*-- Unitary tests --*--
2
3% Tests if a variable exists in dseries object o.
4%
5% INPUTS
6%  - o       [dseries], dseries object.
7%  - varname [string],  name of a variable.
8%
9% OUTPUTS
10%  - l       [logical], equal to 1 (true) iff varname is a variable in dseries object o.
11
12% Copyright (C) 2014-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
29if ~ischar(varname)
30    if isempty(inputname(2))
31        error(['dseries::exist: Input argument (variable name) has to be string!'])
32    else
33        error(['dseries::exist: Second input argument ''' inputname(2) ''' has to be string!'])
34    end
35end
36
37l = ~isempty(strmatch(varname, o.name, 'exact'));
38
39%@test:1
40%$ % Define a datasets.
41%$ data = randn(10,4);
42%$
43%$ % Define names
44%$ names = {'Noddy';'Jumbo';'Sly';'Gobbo'};
45%$ t = zeros(4,1);
46%$
47%$ % Instantiate a time series object and compute the absolute value.
48%$ try
49%$    ts = dseries(data,[],names,[]);
50%$    t(1) = 1;
51%$ catch
52%$    t = 0;
53%$ end
54%$
55%$ if t(1)
56%$    t(2) = dassert(ts.exist('Noddy'),true);
57%$    t(3) = dassert(ts.exist('noddy'),false);
58%$    t(4) = dassert(ts.exist('Boots'),false);
59%$ end
60%$ T = all(t);
61%@eof:1
62