source: MML/trunk/machine/SOLEIL/common/family2elem.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.4 KB
Line 
1function ElementList = family2elem(Family, varargin);
2%FAMILY2elem - Returns the element list for a family
3%  ElementList = family2elem(FamilyName, StatusFlag)
4%
5%  INPUTS
6%  1. Family = Family name ('BEND', 'Q1', 'S1', 'S2', 'HCOR', 'VCOR', etc.)
7%              Data Structure (only the FamilyName field is used)
8%              Accelerator Object (only the FamilyName field is used)
9%              Cell Array
10%  2. StatusFlag - 0 return all elements
11%                  1 return only elements with good status {Default}
12%
13%  OUTPUTS
14%  1. ElementList - Element list corresponding to the Family
15%                  Empty if not found
16%
17%  EXAMPLES
18%  1. family2elem('HCOR')
19%  2. family2elem({'HCOR','VCOR'})
20%
21%  See Also dev2family, family2common, family2dev, family2handle
22%          family2status, family2tol, family2units, family2tango
23         
24%
25%  Written by Laurent S. Nadolski
26
27if nargin == 0
28    error('Must have at least one input.');
29end
30
31% Status input
32if nargin >= 2
33    StatusFlag = varargin{1};
34else
35    % This choice changes the default behavior for the entire middle layer !!!!
36    StatusFlag = 1;  % Only return good status devices
37end
38
39%%%%%%%%%%%%%%%%%%%%%
40%% Cell Array Inputs %
41%%%%%%%%%%%%%%%%%%%%%
42if iscell(Family)
43    for i = 1:length(Family)
44        if iscell(StatusFlag)
45            ElementList{i} = family2elem(Family{i}, StatusFlag{i});
46        else
47            ElementList{i} = family2elem(Family{i}, StatusFlag);
48        end
49    end
50    return   
51end
52
53
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55%% Family or data structure inputs beyond this point %
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57if isstruct(Family)
58    % Structures can be an accelerator object or a data structure (as returned by getpv)
59    if isfield(Family, 'FamilyName')
60        % Data structure
61        Family = Family.FamilyName;   
62    else
63        error('Family input of unknown type');
64    end
65end
66
67% gets device list for Family
68[DeviceList, ErrorFlag] = getfamilydata(Family, 'DeviceList');
69if isempty(DeviceList)
70    error(sprintf('%s family not found', Family));
71end
72
73% return all elements whatever status
74ElementList = dev2elem(Family,DeviceList);
75
76% return status 1 elements
77if StatusFlag
78    Status = getfamilydata(Family, 'Status', DeviceList);
79    if isempty(Status)
80        fprintf('   WARNING:  Status field not in the AO, hence ignored.\n');
81    else
82        ElementList = dev2elem(Family,DeviceList(find(Status),:));
83    end
84end
Note: See TracBrowser for help on using the repository browser.