source: prextra/isvalidilab.m @ 70

Last change on this file since 70 was 5, checked in by bduin, 14 years ago
File size: 1.4 KB
Line 
1%ISVALIDILAB validity check for named-identifier support in a dataset
2%
3%   I=ISVALIDILAB(A,FIELDS)
4%
5% INPUT
6%   A       input dataset
7%   FIELDS  (opt) name or cell array with required identifier names
8%
9% OUTPUT
10%   I       logical output: the dataset is/is not valid
11%
12% DESCRIPTION
13% This function validates if the dataset contains named identifiers.  IN
14% order to enable the use of named identifiers in a dataset, use
15% ENABLEILAB.  If a name or a cell array with identifier names is supplied
16% in the FIELDS parameter, these are checked for existence.
17%
18% SEE ALSO
19% ENABLEILAB, REMOVEILAB, GETILAB, SETILAB, GETILABLIST
20
21% $Id: isvalidilab.m,v 1.2 2005/05/02 13:05:46 pavel Exp $
22
23function i=isvalidilab(a,fields)
24
25    if ~exist('fields','var'), fields=[]; end
26    if ischar(fields), fields={fields}; end
27   
28    isdataset(a);
29
30    i=0;
31    user=a.user;
32    if isfield(user,'ilab')
33        t=user.ilab;
34        if isstruct(t) & isfield(t,'names') & iscell(t.names)
35            i=1;
36        end
37    end
38
39    if (nargout == 0) & (i == 0)
40        error(['Dataset with ilab structure in user field expected. Use help enableilab for details.'])
41    end
42   
43    % validate the required fields, if supplied
44    if ~isempty(fields)
45        for j=1:length(fields)
46            if ~any(strcmp(user.ilab.names,fields{j}))
47                i=0;
48                if (nargout == 0) & (i == 0)
49                    error(['required field ''' fields{j} ''' is not present in a dataset']);
50                end
51            end
52        end
53    end
54   
55   
56    return
57       
Note: See TracBrowser for help on using the repository browser.