1function o = tag(o, a, b, c) % --*-- Unitary tests --*-- 2 3% Add tag to a dseries oject (in place modification). 4 5% INPUTS 6% - o [dseries] 7% - a [string] Name of the tag. 8% - b [string] Name of the variable. 9% - c [any] Value of the variable tag. 10% 11% OUTPUT 12% - o [dseries] Updated with tag 13 14% Copyright (C) 2017 Dynare Team 15% 16% This file is part of Dynare. 17% 18% Dynare is free software: you can redistribute it and/or modify 19% it under the terms of the GNU General Public License as published by 20% the Free Software Foundation, either version 3 of the License, or 21% (at your option) any later version. 22% 23% Dynare is distributed in the hope that it will be useful, 24% but WITHOUT ANY WARRANTY; without even the implied warranty of 25% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26% GNU General Public License for more details. 27% 28% You should have received a copy of the GNU General Public License 29% along with Dynare. If not, see <http://www.gnu.org/licenses/>. 30 31if nargin<3 32 % Initialize a new tag name 33 if ~ismember(a, fieldnames(o.tags)) 34 o.tags.(a) = cell(vobs(o), 1); 35 end 36else 37 % Test if tag name (a) exists 38 if ~ismember(a, fieldnames(o.tags)) 39 error('dseries::tag: Tag name %s is unknown!', a) 40 end 41 % Test if variable (b) exists 42 if ~ismember(b, o.name) 43 error('dseries::tag: Variable %s is unknown!', b) 44 else 45 id = strmatch(b, o.name, 'exact'); 46 end 47 o.tags.(a)(id) = {c}; 48end 49 50%@test:1 51%$ ts = dseries(randn(10, 3)); 52%$ try 53%$ tag(ts, 'name'); 54%$ tag(ts, 'name', 'Variable_1', 'Flow'); 55%$ tag(ts, 'name', 'Variable_2', 'Stock'); 56%$ tag(ts, 'name', 'Variable_3', 'Flow'); 57%$ t(1) = 1; 58%$ catch 59%$ t(1) = 0; 60%$ end 61%$ 62%$ if t(1) 63%$ t(2) = dassert(ts.tags.name, {'Flow'; 'Stock'; 'Flow'}); 64%$ end 65%$ 66%$ T = all(t); 67%@eof:1 68 69%@test:2 70%$ ts = dseries(randn(10, 3)); 71%$ try 72%$ tag(ts, 'name'); 73%$ tag(ts, 'name', 'Variable_1', 'Flow'); 74%$ tag(ts, 'name', 'Variable_3', 'Flow'); 75%$ t(1) = 1; 76%$ catch 77%$ t(1) = 0; 78%$ end 79%$ 80%$ if t(1) 81%$ t(2) = dassert(ts.tags.name, {'Flow'; []; 'Flow'}); 82%$ end 83%$ 84%$ T = all(t); 85%@eof:2 86 87%@test:3 88%$ ts = dseries(randn(10, 3)); 89%$ try 90%$ tag(ts, 'name'); 91%$ tag(ts, 'name', 'Variable_1', 'Flow'); 92%$ tag(ts, 'noname', 'Variable_3', 1); 93%$ t(1) = 0; 94%$ catch 95%$ t(1) = 1; 96%$ end 97%$ 98%$ if t(1) 99%$ t(2) = dassert(ts.tags.name, {'Flow'; []; []}); 100%$ end 101%$ 102%$ T = all(t); 103%@eof:3 104 105%@test:4 106%$ ts = dseries(randn(10, 3)); 107%$ try 108%$ ts.tag('name'); 109%$ ts.tag('name', 'Variable_1', 'Flow'); 110%$ ts.tag('name', 'Variable_2', 'Stock'); 111%$ ts.tag('name', 'Variable_3', 'Flow'); 112%$ t(1) = 1; 113%$ catch 114%$ t(1) = 0; 115%$ end 116%$ 117%$ if t(1) 118%$ t(2) = dassert(ts.tags.name, {'Flow'; 'Stock'; 'Flow'}); 119%$ end 120%$ 121%$ T = all(t); 122%@eof:4 123 124 125