source: MML/trunk/mml/isfamily.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.9 KB
Line 
1function  [FamilyFlag, AO] = isfamily(Family, Field)
2%ISFAMILY - True for family names
3%  [Flag, Structure] = isfamily(Family)
4%
5%  INPUTS
6%  1. FamilyName or Data Structure
7%     (only the FamilyName field is used for Data Structure inputs)
8%  2. Field - Middlelayer field name (optional)
9%
10%  OUTPUTS
11%  1. Flag = 1 if FamilyName is a family
12%            0 if no family name was found
13%  2. Structure - the middle layer data structure for that family
14%                 or the data structure for that field if Field is input.
15%
16%  NOTES
17%  1. For string matrix inputs a column vector is returned.
18%     However, the Structure output will be for the last row.
19%  2. Family and Field names are case sensitive.
20
21%
22%  Written by Gregory J. Portmann
23%  Modified by Laurent S. Nadolski
24%  19/01/06 If Family is not a String, force conversion instead of isplaying
25%  error message. Usefull feature for TANGO channel access
26
27
28if nargin == 0,
29    error('Must have at least one input (''Family'')!');
30end                   
31
32if isstruct(Family)
33   
34    if isfield(Family,'FamilyName') & isfield(Family, 'Field')
35        % Data structure: find the AO
36        [FamilyFlag, AO] = isfamily(Family.FamilyName);
37    elseif isfield(Family,'FamilyName')
38        % AO structure: use the same structure
39        FamilyFlag = 1;
40        AO = Family;
41    else
42        %error('Family input of unknown type');
43        AO = [];
44        FamilyFlag = 0;
45    end
46   
47elseif size(Family,1) > 1
48   
49    for i = 1:size(Family, 1)
50        if nargin == 1
51            [FamilyFlag(i,1), AO] = isfamily(Family(i,:));
52        else
53            if size(Family,1) == size(Field,1)
54                [FamilyFlag(i,1), AO] = isfamily(Family(i,:), Field(i,:));
55            elseif size(Field,1) == 1
56                [FamilyFlag(i,1), AO] = isfamily(Family(i,:), Field);
57            else
58                error('Field must be 1 row or equal to the number of rows in Family');
59            end
60        end
61    end
62       
63else
64   
65    AO = getao;
66    if isempty(AO)
67        fprintf('   ACCELERATOR_OBJECT is empty.  Initialization is needed (aoinit).');
68        AO = [];
69        FamilyFlag = 0;       
70        return
71    end
72       
73    if ~ischar(Family)
74        % error('Family input must be a string.');
75        Family = Family{:};
76    end
77    Family = deblank(Family);
78   
79    if nargin > 1
80        if ~ischar(Field)
81            error('Field input must be a string.');
82        end
83        Field = deblank(Field);
84    end
85
86    if isfield(AO, Family)
87        FamilyFlag = 1;
88        AO = AO.(Family);
89
90        if nargin > 1
91            if ~isempty(Field)
92                if isfield(AO, Field)
93                    FamilyFlag = 1;
94                    AO = AO.(Field);
95                else
96                    FamilyFlag = 0;
97                    AO = [];
98                end
99            end
100        end
101    else
102        FamilyFlag = 0;
103        AO = [];
104    end
105end
Note: See TracBrowser for help on using the repository browser.