source: MML/trunk/mml/family2dev.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: 4.5 KB
Line 
1function DeviceList = family2dev(Family, varargin);
2%FAMILY2DEV - Return the device list for a family
3%  DeviceList = family2dev(FamilyName, StatusFlag, PowerSupplyFlag)
4%  DeviceList = family2dev(FamilyName, Field, StatusFlag, PowerSupplyFlag)
5%
6%  INPUTS
7%  1. Family - Family name (ex., 'BEND', 'QFA', 'SF', 'SD', 'HCM', 'VCM', etc.)
8%              Data Structure (only the FamilyName field is used)
9%              Accelerator Object (only the FamilyName field is used)
10%              Cell Array
11%  2. Field - Option field input only effects the PowerSupplyFlag
12%  3. StatusFlag - 0 return all devices
13%                  1 return only devices with good status {Default}
14%
15%  4. PowerSupplyFlag - 0 return all devices {Default}
16%                       1 return only unique channel names (like, power supplies for a magnet)
17%
18%  OUTPUTS
19%  1. DeviceList - Device list corresponding to the Family
20%                  Empty if not found
21%
22%  See Also dev2family, family2common, family2dev, family2handle
23%          family2status, family2tol, family2units, family2tango
24
25%
26%  Written by Gregory J. Portmann
27
28if nargin == 0
29    error('Must have at least one input.');
30end
31
32
33% Look for a field input
34Field = '';
35if length(varargin) >= 1
36    if ischar(varargin{1})
37        Field = varargin{1};
38        varargin(1) = [];
39    end
40end
41
42
43% StatusFlag
44if length(varargin) >= 1
45    StatusFlag = varargin{1};
46else
47    % This choice changes the default behavior for the entire middle layer !!!!
48    StatusFlag = 1;  % Only return good status devices
49end
50
51
52% PowerSupplyFlag
53if length(varargin) >= 2
54    PowerSupplyFlag = varargin{2};
55else
56    PowerSupplyFlag = 0;
57end
58
59
60%%%%%%%%%%%%%%%%%%%%%
61% Cell Array Inputs %
62%%%%%%%%%%%%%%%%%%%%%
63if iscell(Family)
64    for i = 1:length(Family)
65        if iscell(StatusFlag) & iscell(PowerSupplyFlag)
66            DeviceList{i} = family2dev(Family{i}, StatusFlag{i}, PowerSupplyFlag{i});
67        elseif iscell(StatusFlag)
68            DeviceList{i} = family2dev(Family{i}, StatusFlag{i}, PowerSupplyFlag);
69        elseif iscell(PowerSupplyFlag)
70            DeviceList{i} = family2dev(Family{i}, StatusFlag, PowerSupplyFlag{i});
71        else
72            DeviceList{i} = family2dev(Family{i}, StatusFlag, PowerSupplyFlag);
73        end
74    end
75    return
76end
77
78
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80% Family or data structure inputs beyond this point %
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82if isstruct(Family)
83    % Structures can be an accelerator object or a data structure (as returned by getpv)
84    if isfield(Family, 'FamilyName')
85        % Data structure
86        Family = Family.FamilyName;   
87    else
88        error('Family input of unknown type');
89    end
90end
91
92
93[DeviceList, ErrorFlag] = getfamilydata(Family, 'DeviceList');
94if isempty(DeviceList)
95    error(sprintf('%s family not found', Family));
96end
97
98
99if StatusFlag
100    Status = getfamilydata(Family, 'Status', DeviceList);
101    if isempty(Status)
102        fprintf('   WARNING:  Status field not in the AO, hence ignored.\n');
103    else
104        DeviceList = DeviceList(find(Status),:);
105    end
106end
107
108
109if PowerSupplyFlag
110    % There can be multiple channel names due to "ganged" power supplies
111    if isempty(Field)
112        ChannelNames0 = family2channel(Family, DeviceList);
113    else
114        ChannelNames0 = family2channel(Family, Field, DeviceList);
115    end
116    [ChannelNames, ii, jj] = unique(ChannelNames0, 'rows');
117
118    if length(ii) ~= size(ChannelNames0,1)
119        % Remove ' ' (' ' should always be the first row)
120        if isempty(deblank(ChannelNames(1,:)))
121            ii(1) = [];
122            jj(jj==1) = [];
123            jj = jj - 1;
124        end
125
126        ChannelNames = ChannelNames0(ii,:);
127
128        % Unique does a sort and keeps the last device.
129       
130        % Remove the sort
131        jjtmp = jj;
132        for i = 1:max(jj)
133            iDev(i) = jjtmp(1);
134            jjtmp(jjtmp==jjtmp(1)) = [];
135        end
136        ChannelNames = ChannelNames(iDev,:);
137       
138        % Find the first device with that name
139        i = findrowindex(ChannelNames, ChannelNames0);
140        DeviceList = DeviceList(i,:);
141    else
142        % Remove ' ' (' ' should always be the first row)
143        if isempty(deblank(ChannelNames(1,:)))
144            iBlank = find(jj==1);
145            DeviceList(iBlank,:) = [];
146        end
147    end
148end
149
150
151% if nargin >= 2
152%     if varargin{1}
153%         Status = getfamilydata(Family, 'Status', DeviceList);
154%         if isempty(Status)
155%             fprintf('   WARNING:  Status field not in the AO, hence ignored.\n');
156%         else
157%             DeviceList = DeviceList(find(Status),:);
158%         end
159%     end
160% end
161
162
Note: See TracBrowser for help on using the repository browser.