source: prextra/isvalidmeta.m @ 100

Last change on this file since 100 was 5, checked in by bduin, 14 years ago
File size: 1.4 KB
Line 
1%ISVALIDMETA meta validity check for datasets
2%
3%   I=ISVALIDMETA(A,KEYS)
4%
5% INPUT
6%   A       input dataset
7%   KEYS  (opt) name or cell array with names of required meta keys
8%
9% OUTPUT
10%   I       logical output: the dataset is/is not valid
11%
12% DESCRIPTION
13% This function validates if the dataset contains meta capability i.e.
14% can store additional named sets of identifiers for each object.
15% The metalist containing the names of ident columns is stored in the
16% dataset user field. If a name or a cell array with column names is
17% supplied in KEYS parameter, these are checked for existence.
18
19function i=isvalidmeta(a,inkeys)
20
21    if ~exist('inkeys','var'), inkeys=[]; end
22    if ischar(inkeys), inkeys={inkeys}; end
23   
24    isdataset(a);
25
26    i=0;
27    user=a.user;
28    if isfield(user,'meta')
29        t=user.meta;
30        if isstruct(t) & isfield(t,'keys') & iscell(t.keys) & isfield(t,'values') & iscell(t.values)
31            i=1;
32        end
33    end
34
35    if (nargout == 0) & (i == 0)
36        error(['Dataset with meta structure in user field expected. Use help enablemeta for details.'])
37    end
38   
39    % validate the required keys, if supplied
40    if ~isempty(inkeys)
41        for j=1:length(inkeys)
42            if ~any(strcmp(user.meta.keys,inkeys{j}))
43                i=0;
44                if (nargout == 0) & (i == 0)
45                    error(['required key ''' inkeys{j} ''' is not present in a dataset']);
46                end
47            end
48        end
49    end
50   
51   
52    return
53       
Note: See TracBrowser for help on using the repository browser.