Commit 14478ca1 authored by Stéphane Adjemian's avatar Stéphane Adjemian

Added the ability to tag variables in dseries objects.

 - New class member tags

 - Member tags is a structure, initialized to empty.

 - Each user-defined field of this structure must be a vobs(o)*1 cell
   array (each element is associated to a variable).

 - To add a new tag name:

      >> o.tag('type')

 - To associate a tag value to a variable:

      >> o.tag('type', 'Consumption', 'Flow')

   the first argument is the tag name, the second argument is the name
   of the variable, the last argument is the value of the tag.
parent 03b223fa
......@@ -29,6 +29,7 @@ p.name = o.name;
p.tex = o.tex;
p.dates = o.dates;
p.ops = o.ops;
p.tags = o.tags;
%@test:1
%$ % Define a dates object
......
......@@ -23,6 +23,7 @@ properties
tex = {}; % TeX names of the variables.
dates = dates(); % Dates associated to the observations.
ops = {}; % History of operations on the variables.
tags = struct(); % User defined tags on the variables.
end
methods
......@@ -54,6 +55,7 @@ methods
o.tex = {};
o.dates = dates();
o.ops = {};
o.tags = struct();
return
case 1
if isdates(varargin{1})
......@@ -67,17 +69,19 @@ methods
o.tex = {};
o.dates = varargin{1};
o.ops = {};
o.tags = struct();
otherwise
error('dseries:WrongInputArguments', 'Input (identified as a dates object) must have a unique element!');
end
return
elseif ischar(varargin{1})
[init, data, varlist, tex, ops] = load_data(varargin{1});
[init, data, varlist, tex, ops, tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = init:init+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
elseif ~isoctave() && istable(varargin{1})
% It is assumed that the dates are in the first column.
thistable = varargin{1};
......@@ -86,36 +90,40 @@ methods
o.data = varargin{1}{:,2:end};
o.dates = dates(varargin{1}{1,1}{1})+(0:size(varargin{1}, 1)-1);
o.ops = cell(length(o.name), 1);
o.tags = struct();
elseif isnumeric(varargin{1}) && isequal(ndims(varargin{1}),2)
o.data = varargin{1};
o.name = default_name(vobs(o));
o.tex = name2tex(o.name);
o.dates = dates(1,1):dates(1,1)+(nobs(o)-1);
o.ops = cell(length(o.name), 1);
o.tags = struct();
end
case {2,3,4}
if isequal(nargin,2) && ischar(varargin{1}) && isdates(varargin{2})
% Instantiate dseries object with a data file and force the initial date to
% be as given by the second input argument (initial period represented
% with a dates object).
[init, data, varlist, tex, ops] = load_data(varargin{1});
[init, data, varlist, tex, ops, tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = varargin{2}:varargin{2}+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
return
end
if isequal(nargin,2) && ischar(varargin{1}) && ischar(varargin{2}) && isdate(varargin{2})
% Instantiate dseries object with a data file and force the initial date to
% be as given by the second input argument (initial period represented with a
% string).
[init, data, varlist, tex, ops] = load_data(varargin{1});
[init, data, varlist, tex, ops, tags] = load_data(varargin{1});
o.data = data;
o.name = varlist;
o.dates = dates(varargin{2}):dates(varargin{2})+(nobs(o)-1);
o.tex = tex;
o.ops = ops;
o.tags = tags;
return
end
a = varargin{1};
......@@ -177,6 +185,7 @@ methods
o.name = default_name(vobs(o));
end
o.ops = cell(length(o.name), 1);
o.tags = struct();
if ~isempty(d)
if vobs(o)==length(d)
for i=1:vobs(o)
......
......@@ -78,6 +78,25 @@ end
a.ops = vertcat(b.ops,c.ops);
a.name = vertcat(b.name,c.name);
a.tex = vertcat(b.tex,c.tex);
btagnames = fieldnames(b.tags);
ctagnames = fieldnames(c.tags);
atagnames = union(btagnames, ctagnames);
if isempty(atagnames)
a.tags = struct();
else
for i=1:length(atagnames)
if ismember(atagnames{i}, btagnames) && ismember(atagnames{i}, ctagnames)
a.tags.(atagnames{i}) = vertcat(b.tags.(atagnames{i}), b.tags.(atagnames{i}));
elseif ismember(atagnames{i}, btagnames)
a.tags.(atagnames{i}) = vertcat(b.tags.(atagnames{i}), cell(vobs(c), 1));
elseif ismember(atagnames{i}, ctagnames)
a.tags.(atagnames{i}) = vertcat(cell(vobs(b), 1), c.tags.(atagnames{i}));
else
error('dseries::horzcat: This is a bug!')
end
end
end
if ~( d_nobs_flag(1) || d_init_flag(1) )
a.data = [b.data,c.data];
a.dates = b.dates;
......@@ -331,3 +350,48 @@ end
%$
%$ T = t;
%@eof:7
%@test:8
%$ % Define a data set.
%$ A = [transpose(1:10),2*transpose(1:10)];
%$ B = [transpose(1:10),2*transpose(1:10)];
%$
%$ % Define names
%$ A_name = {'A1';'A2'};
%$ B_name = {'B1';'B2'};
%$
%$ % Define expected results.
%$ e.init = dates(1,1);
%$ e.freq = 1;
%$ e.name = {'A1';'A2';'B1';'B2'};
%$ e.data = [A,B];
%$
%$ % Instantiate two time series objects.
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts2 = dseries(B,[],B_name,[]);
%$ ts1.tag('t1');
%$ ts1.tag('t1', 'A1', 'Stock');
%$ ts1.tag('t1', 'A2', 'Flow');
%$ ts2.tag('t2');
%$ ts2.tag('t2', 'B1', 0);
%$ ts2.tag('t2', 'B2', 1);
%$
%$ % Call the tested method.
%$ try
%$ ts3 = [ts1,ts2];
%$ t(1) = true;
%$ catch
%$ t(1) = false;
%$ end
%$
%$ % Check the results.
%$ if t(1)
%$ t(2) = dassert(ts3.init,e.init);
%$ t(3) = dassert(ts3.freq,e.freq);
%$ t(4) = dassert(ts3.data,e.data);
%$ t(5) = dassert(ts3.name,e.name);
%$ t(6) = dassert(ts3.tags.t1,{'Stock';'Flow';[];[]});
%$ t(7) = dassert(ts3.tags.t2,{[];[];0;1});
%$ end
%$ T = all(t);
%@eof:8
......@@ -48,23 +48,64 @@ end
% Keep the second input argument constant.
p = copy(p);
% Add NaNs if necessary.
[o, p] = align(o, p);
n = length(id);
% Get tag names in p
ptagnames = fieldnames(p.tags);
if n>1
[id, jd] = sort(id);
p.data = p.data(:,jd);
p.name = p.name(jd);
p.tex = p.tex(jd);
p.ops = p.ops(jd);
if ~isempty(ptagnames)
for i = 1:length(ptagnames)
p.tags.(ptagnames{i}) = p.tags.(ptagnames{i})(jd);
end
end
end
% Get tag names in o
otagnames = fieldnames(o.tags);
% Merge tag names
if isempty(otagnames) && isempty(ptagnames)
notags = true;
else
notags = false;
dtagnames_o = setdiff(ptagnames, otagnames);
dtagnames_p = setdiff(otagnames, ptagnames);
if ~isempty(dtagnames_o)
% If p has tags that are not in o...
for i=1:length(dtagnames_o)
o.tags.(dtagnames_o{i}) = cell(vobs(o), 1);
end
end
if ~isempty(dtagnames_p)
% If o has tags that are not in p...
for i=1:length(dtagnames_p)
p.tags.(dtagnames_p{i}) = cell(vobs(p), 1);
end
end
end
% Update list of tag names in o.
otagnames = fieldnames(o.tags);
for i=1:n
o.data = insert_column_vector_in_a_matrix(o.data, p.data(:,i),id(i));
o.name = insert_object_in_a_one_dimensional_cell_array(o.name, p.name{i}, id(i));
o.tex = insert_object_in_a_one_dimensional_cell_array(o.tex, p.tex{i}, id(i));
o.ops = insert_object_in_a_one_dimensional_cell_array(o.ops, p.ops{i}, id(i));
if ~notags
for j=1:length(otagnames)
o.tags.(otagnames{j}) = insert_object_in_a_one_dimensional_cell_array(o.tags.(otagnames{j}), p.tags.(otagnames{j}){i}, id(i));
end
end
id = id+1;
end
......@@ -83,6 +124,16 @@ end
%$ % Instantiate two dseries objects.
%$ ts1 = dseries(A, A_init, A_name,[]);
%$ ts2 = dseries(B, B_init, B_name,[]);
%$ ts1.tag('t1');
%$ ts1.tag('t1','A1',1);
%$ ts1.tag('t1','A2',1);
%$ ts1.tag('t1','A3',0);
%$ ts2.tag('t1');
%$ ts2.tag('t1','B1',1);
%$ ts2.tag('t1','B2',1);
%$ ts2.tag('t2');
%$ ts2.tag('t2','B1','toto');
%$ ts2.tag('t2','B2','titi');
%$
%$ try
%$ ts1 = insert(ts1,ts2,[1,2]);
......@@ -91,11 +142,14 @@ end
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ t(2) = dassert(ts1.vobs,{'B1';'A1';'B2';'A3'});
%$
%$ if t(1)
%$ t(2) = dassert(ts1.name,{'B1';'A1';'B2';'A2';'A3'});
%$ t(3) = dassert(ts1.nobs,10);
%$ eB = [NaN(2,2); B; NaN(3,2)];
%$ t(4) = dassert(ts1.data,[eB(:,1), A(:,1), eB(:,2), A(:,2:3)], 1e-15);
%$ t(5) = dassert(ts1.tags.t1,{1; 1; 1; 1; 0});
%$ t(6) = dassert(ts1.tags.t2,{'toto'; []; 'titi'; []; []});
%$ end
%$ T = all(t);
%@eof:1
......
......@@ -73,6 +73,13 @@ if ~isequal(o.ops, p.ops)
warning on backtrace
end
if ~isequal(o.tags, p.tags)
warning off backtrace
warning('dseries::isequal: Both input arguments have different tags!')
warning on backtrace
end
if nargin<3
b = isequal(o.data, p.data);
else
......
......@@ -42,12 +42,35 @@ if ~isequal(frequency(o), frequency(p))
end
q = dseries();
[q.name, IBC, junk] = unique([o.name; p.name], 'last');
tex = [o.tex; p.tex];
q.tex = tex(IBC);
ops = [o.ops; p.ops];
q.ops = ops(IBC);
otagnames = fieldnames(o.tags);
ptagnames = fieldnames(p.tags);
qtagnames = union(otagnames, ptagnames);
if isempty(qtagnames)
q.tags = struct();
else
for i=1:length(qtagnames)
if ismember(qtagnames{i}, otagnames) && ismember(qtagnames{i}, ptagnames)
q.tags.(qtagnames{i}) = vertcat(o.tags.(otagnames{i}), p.tags.(ptagnames{i}));
elseif ismember(qtagnames{i}, otagnames)
q.tags.(qtagnames{i}) = vertcat(o.tags.(qtagnames{i}), cell(vobs(p), 1));
elseif ismember(qtagnames{i}, ptagnames)
q.tags.(qtagnames{i}) = vertcat(cell(vobs(o), 1), p.tags.(qtagnames{i}));
else
error('dseries::horzcat: This is a bug!')
end
q.tags.(qtagnames{i}) = q.tags.(qtagnames{i})(IBC);
end
end
if nobs(o) == 0
q = copy(p);
elseif nobs(p) == 0
......@@ -93,22 +116,26 @@ q.dates = q_init:q_init+(nobs(q)-1);
%$ % Define names
%$ A_name = {'A1';'A2'}; B_name = {'A1'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ % Instantiate two time series objects and merge.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts1.tag('type');
%$ ts1.tag('type', 'A1', 'Stock');
%$ ts1.tag('type', 'A2', 'Flow');
%$ ts2 = dseries(B,[],B_name,[]);
%$ ts2.tag('type');
%$ ts2.tag('type', 'A1', 'Flow');
%$ ts3 = merge(ts1,ts2);
%$ t(1) = 1;
%$ catch
%$ t = 0;
%$ end
%$
%$ if length(t)>1
%$ if t(1)
%$ t(2) = dassert(ts3.vobs,2);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[B, A(:,2)],1e-15);
%$ t(5) = dassert(ts3.tags.type, {'Flow';'Flow'});
%$ end
%$ T = all(t);
%@eof:1
......@@ -120,12 +147,15 @@ q.dates = q_init:q_init+(nobs(q)-1);
%$ % Define names
%$ A_name = {'A1';'A2'}; B_name = {'B1'};
%$
%$ t = zeros(4,1);
%$
%$ % Instantiate a time series object.
%$ % Instantiate two time series objects and merge them.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts1.tag('t1');
%$ ts1.tag('t1', 'A1', 'Stock');
%$ ts1.tag('t1', 'A2', 'Flow');
%$ ts2 = dseries(B,[],B_name,[]);
%$ ts2.tag('t2');
%$ ts2.tag('t2', 'B1', 1);
%$ ts3 = merge(ts1,ts2);
%$ t(1) = 1;
%$ catch
......@@ -136,6 +166,8 @@ q.dates = q_init:q_init+(nobs(q)-1);
%$ t(2) = dassert(ts3.vobs,3);
%$ t(3) = dassert(ts3.nobs,10);
%$ t(4) = dassert(ts3.data,[A, B],1e-15);
%$ t(5) = dassert(ts3.tags.t1, {'Flow';'Flow';[]});
%$ t(6) = dassert(ts3.tags.t2, {[];[];1});
%$ end
%$ T = all(t);
%@eof:2
......@@ -69,6 +69,10 @@ if ~isequal(o.tex, p.tex)
warning('dseries::ne: Both input arguments do not have the same tex names!')
end
if ~isequal(o.tags, p.tags)
warning('dseries::ne: Both input arguments do not have the same tags!')
end
b = ne(o.data, p.data);
%@test:1
......
......@@ -42,6 +42,10 @@ o.data(:,id) = [];
o.name(id) = [];
o.tex(id) = [];
o.ops(id) = [];
otagnames = fieldnames(o.tags);
for i=1:length(otagnames)
o.tags.(otagnames{i})(id) = [];
end
%@test:1
%$ % Define a datasets.
......@@ -53,16 +57,21 @@ o.ops(id) = [];
%$ % Instantiate a time series object.
%$ try
%$ ts1 = dseries(A,[],A_name,[]);
%$ ts1.tag('type');
%$ ts1.tag('type', 'A1', 1);
%$ ts1.tag('type', 'A2', 2);
%$ ts1.tag('type', 'A3', 3);
%$ ts1.pop_('A2');
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if length(t)>1
%$ if t(1)
%$ t(2) = dassert(ts1.vobs,2);
%$ t(3) = dassert(ts1.nobs,10); ts1
%$ t(3) = dassert(ts1.nobs,10);
%$ t(4) = dassert(ts1.data,[A(:,1), A(:,3)],1e-15);
%$ t(5) = dassert(ts1.tags.type, {1;3});
%$ end
%$ T = all(t);
%@eof:1
\ No newline at end of file
......@@ -65,10 +65,31 @@ switch format
fprintf(fid,[ '''' o.ops{i} '''']);
end
if i<vobs(o)
fprintf(fid,'; ');
fprintf(fid,';');
end
end
fprintf(fid,'};\n\n');
if ~isempty(fieldnames(o.tags))
% User has defined tags on the variables.
tagnames = fieldnames(o.tags);
TAGS__ = fprintf(fid, 'struct();\n');
for i=1:length(tagnames)
fprintf(fid, 'TAGS__.%s = cell(%s, 1);\n', tagnames{i}, num2str(vobs(o)));
for j=1:vobs(o)
if ~isempty(o.tags.(tagnames{i}){j})
if ischar(o.tags.(tagnames{i}){j})
fprintf(fid, 'TAGS__.%s(%s) = {''%s''};\n', tagnames{i}, num2str(j), o.tags.(tagnames{i}){j});
elseif isnumeric(o.tags.(tagnames{i}){j}) && iscalar(o.tags.(tagnames{i}){j})
fprintf(fid, 'TAGS__.%s(%s) = {%s};\n', tagnames{i}, num2str(j), o.tags.(tagnames{i}){j});
else
error('dseries::tags: Cannot save this type of tag!')
end
end
end
fprintf(fid, '\n');
end
fprintf(fid,'\n\n');
end
for v = 1:vobs(o)
fprintf(fid,'%s = [\n', o.name{v});
fprintf(fid,'%15.8g\n', o.data(1:end-1,v));
......@@ -81,6 +102,7 @@ switch format
NAMES__ = o.name;
TEX__ = o.tex;
OPS__ = o.ops;
TAGS__ = o.tags;
str = [];
for v = 1:vobs(o)
str = sprintf('%s %s = o.data(:,%s);', str, o.name{v}, num2str(v));
......@@ -90,7 +112,7 @@ switch format
if ismember([basename, '.mat'], {currentdirectorycontent.name})
copyfile([basename, '.mat'], [basename, '.old.mat']);
end
save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', o.name{:});
save([basename '.mat'], 'INIT__', 'FREQ__', 'NAMES__', 'TEX__', 'OPS__', 'TAGS__', o.name{:});
case 'csv'
currentdirectorycontent = dir();
if ismember([basename, '.csv'],{currentdirectorycontent.name})
......
......@@ -65,7 +65,7 @@ function B = subsref(A, S) % --*-- Unitary tests --*--
switch S(1).type
case '.'
switch S(1).subs
case {'data','name','tex','dates','ops'} % Public members.
case {'data','name','tex','dates','ops', 'tags'} % Public members.
if length(S)>1 && isequal(S(2).type,'()') && isempty(S(2).subs)
error(['dseries::subsref: ' S(1).subs ' is not a method but a member!'])
end
......@@ -169,7 +169,7 @@ switch S(1).type
else
error('dseries::subsref: Call to size method must come in last position!')
end
case {'set_names','rename','rename_','tex_rename','tex_rename_'}
case {'set_names','rename','rename_','tex_rename','tex_rename_', 'tag'}
B = feval(S(1).subs,A,S(2).subs{:});
S = shiftS(S,1);
case {'disp'}
......
function o = tag(o, a, b, c) % --*-- Unitary tests --*--
% Add tag to a dseries oject (in place modification).
% INPUTS
% - o [dseries]
% - a [string] Name of the tag.
% - b [string] Name of the variable.
% - c [any] Value of the variable tag.
%
% OUTPUT
% - o [dseries] Updated with tag
% Copyright (C) 2017 Dynare Team
%
% 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/>.
if nargin<3
% Initialize a new tag name
if ~ismember(a, fieldnames(o.tags))
o.tags.(a) = cell(vobs(o), 1);
end
else
% Test if tag name (a) exists
if ~ismember(a, fieldnames(o.tags))
error('dseries::tag: Tag name %s is unknown!', a)
end
% Test if variable (b) exists
if ~ismember(b, o.name)
error('dseries::tag: Variable %s is unknown!', b)
else
id = strmatch(b, o.name, 'exact');
end
o.tags.(a)(id) = {c};
end
%@test:1
%$ ts = dseries(randn(10, 3));
%$ try
%$ tag(ts, 'name');
%$ tag(ts, 'name', 'Variable_1', 'Flow');
%$ tag(ts, 'name', 'Variable_2', 'Stock');
%$ tag(ts, 'name', 'Variable_3', 'Flow');
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ts.tags.name, {'Flow'; 'Stock'; 'Flow'});
%$ end
%$
%$ T = all(t);
%@eof:1
%@test:2
%$ ts = dseries(randn(10, 3));
%$ try
%$ tag(ts, 'name');
%$ tag(ts, 'name', 'Variable_1', 'Flow');
%$ tag(ts, 'name', 'Variable_3', 'Flow');
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ts.tags.name, {'Flow'; []; 'Flow'});
%$ end
%$
%$ T = all(t);
%@eof:2
%@test:3
%$ ts = dseries(randn(10, 3));
%$ try
%$ tag(ts, 'name');
%$ tag(ts, 'name', 'Variable_1', 'Flow');
%$ tag(ts, 'noname', 'Variable_3', 1);
%$ t(1) = 0;
%$ catch
%$ t(1) = 1;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ts.tags.name, {'Flow'; []; []});
%$ end
%$
%$ T = all(t);
%@eof:3
%@test:4
%$ ts = dseries(randn(10, 3));
%$ try
%$ ts.tag('name');
%$ ts.tag('name', 'Variable_1', 'Flow');
%$ ts.tag('name', 'Variable_2', 'Stock');
%$ ts.tag('name', 'Variable_3', 'Flow');
%$ t(1) = 1;
%$ catch
%$ t(1) = 0;
%$ end
%$
%$ if t(1)
%$ t(2) = dassert(ts.tags.name, {'Flow'; 'Stock'; 'Flow'});
%$ end
%$
%$ T = all(t);
%@eof:4
function [init, data, varlist, tex, ops] = load_data(filename)
function [init, data, varlist, tex, ops, tags] = load_data(filename)
% INPUTS
% - filename [string] Name of the file containing data.
......@@ -27,13 +27,14 @@ function [init, data, varlist, tex, ops] = load_data(filename)
if ~nargin || ~ischar(filename) || isempty(filename)
error('dseries:load_data: WrongInputArguments', 'Input argument cannot be an empty string!')
elseif check_file_extension(filename,'m')
[freq, init, data, varlist, tex, ops] = load_m_file_data(filename);
[freq, init, data, varlist, tex, ops, tags] = load_m_file_data(filename);
elseif check_file_extension(filename,'mat')
[freq, init, data, varlist, tex, ops] = load_mat_file_data(filename);
[freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(filename);
elseif check_file_extension(filename,'csv')
[freq, init, data, varlist] = load_csv_file_data(filename);
tex = [];
ops = cell(length(varlist), 1);
tags = struct();
elseif check_file_extension(filename,'xls') || check_file_extension(filename,'xlsx')
if isglobalinbase('options_')
% Check that the object is instantiated within a dynare session so that options_ global structure exists.
......@@ -48,6 +49,7 @@ elseif check_file_extension(filename,'xls') || check_file_extension(filename,'xl
[freq, init, data, varlist] = load_xls_file_data(filename, sheet, range);
tex = [];
ops = cell(length(varlist), 1);
tags = struct();
else
error('dseries:WrongInputArguments', 'I''m not able to load data from %s!', filename);
end
......
function [freq, init, data, varlist, tex, ops] = load_m_file_data(file) % --*-- Unitary tests --*--
function [freq, init, data, varlist, tex, ops, tags] = load_m_file_data(file) % --*-- Unitary tests --*--
% Loads data in a matlab/octave script.
%
......@@ -84,6 +84,13 @@ else
ops = [];
end
if exist('TAGS__','var')
tags = TAGS__;
clear('TAGS__');
else
tags = struct();
end
if isempty(varlist0)
list_of_variables = whos();
end
......@@ -101,6 +108,7 @@ if isempty(varlist0)
|| isequal(list_of_variables(current_variable_index).name,'list_of_variables') ...
|| isequal(list_of_variables(current_variable_index).name,'tex') ...
|| isequal(list_of_variables(current_variable_index).name,'ops') ...
|| isequal(list_of_variables(current_variable_index).name,'tags') ...
continue
end
if list_of_variables(current_variable_index).global || list_of_variables(current_variable_index).persistent
......@@ -141,6 +149,10 @@ end
%$ fprintf(fid,'NAMES__ = {''azert'';''yuiop''};');
%$ fprintf(fid,'TEX__ = {''azert'';''yuiop''};');
%$ fprintf(fid,'OPS__ = {''method1(azert)'';''method2(yuiop)''};');
%$ fprintf(fid,'TAGS__ = struct();');
%$ fprintf(fid,'TAGS__.type = cell(2, 1);');
%$ fprintf(fid,'TAGS__.type(1) = {''Haut''};');
%$ fprintf(fid,'TAGS__.type(2) = {''Bas''};');
%$ fprintf(fid,'azert = [1; 2; 3; 4; 5];');
%$ fprintf(fid,'yuiop = [2; 3; 4; 5; 6];');
%$ fclose(fid);
......@@ -148,7 +160,7 @@ end
%$ % Try to read the data m-file
%$ try
%$ datafile = 'data_m_file.m';
%$ [freq, init, data, varlist, tex, ops] = load_m_file_data(datafile);
%$ [freq, init, data, varlist, tex, ops, tags] = load_m_file_data(datafile);
%$ delete('data_m_file.m');
%$ t(1) = 1;
%$ catch exception
......@@ -166,7 +178,8 @@ end
%$ t(6) = dassert(varlist,{'azert';'yuiop'});
%$ t(7) = dassert(tex,{'azert';'yuiop'});
%$ t(8) = dassert(ops,{'method1(azert)';'method2(yuiop)'});
%$ t(9) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(10) = dassert(data(:,2),[2;3;4;5;6]);
%$ t(9) = dassert(tags.type,{'Haut';'Bas'});
%$ t(10) = dassert(data(:,1),[1;2;3;4;5]);
%$ t(11) = dassert(data(:,2),[2;3;4;5;6]);
%$ T = all(t);
%@eof:1
function [freq, init, data, varlist, tex, ops] = load_mat_file_data(file) % --*-- Unitary tests --*--
function [freq, init, data, varlist, tex, ops, tags] = load_mat_file_data(file) % --*-- Unitary tests --*--
% Loads data in a matlab/octave mat-file.
%
......@@ -78,6 +78,13 @@ else
ops = [];
end
if isfield(datafile,'TAGS__')
tags = datafile.TAGS__;
datafile = rmfield(datafile, 'TAGS__');
else
tags = struct();
end
data = [];
if isempty(varlist)
varlist = fieldnames(datafile);
......@@ -103,6 +110,8 @@ end
%$ NAMES__ = {'hagop'; 'bedros'};
%$ TEX__ = NAMES__;
%$ OPS__ = {'grandad(hagop)'; 'dad(bedros)'};
%$ TAGS__ = struct();
%$ TAGS__.gender = {'M'; 'M'};
%$ hagop = [1; 2; 3; 4; 5];
%$ bedros = [2; 3; 4; 5; 6];
%$ save('datafile_for_test.mat');
......@@ -110,7 +119,7 @@ end
%$ % Try to read the data mat-file
%$ t = zeros(10,1);
%$ try
%$ [freq, init, data, varlist, tex, ops] = load_mat_file_data('datafile_for_test');
%$ [freq, init, data, varlist, tex, ops, tags] = load_mat_file_data('datafile_for_test');
%$ t(1) = 1;
%$ catch exception