1 | function Output = elem2dev(Family, ElementList) |
---|
2 | %ELEM2DEV - Converts a device list to an element list |
---|
3 | % [Sector Device#] = elem2dev(Family, Element#) |
---|
4 | % |
---|
5 | % This function convects between the two methods of representing |
---|
6 | % the same device in the ring. The "Device" method is a two column |
---|
7 | % matrix with the first being sector number and the seconds being |
---|
8 | % the device number in the sector. The "Element" method is a one column |
---|
9 | % matrix with each entry being the element number starting at sector 1. |
---|
10 | % |
---|
11 | % The following are equivalent devices for VCMs at the ALS: |
---|
12 | % | 1 2 | | 2 | |
---|
13 | % | 1 3 | | 3 | |
---|
14 | % [Sector Device#] = | 2 1 | [ElementList] = | 9 | |
---|
15 | % | 2 2 | | 10 | |
---|
16 | % | 3 4 | | 20 | |
---|
17 | % |
---|
18 | % NOTES |
---|
19 | % 1. If ElementList is empty, the entire family list will be returned. |
---|
20 | % 2. If the device is not found, then an error will occur. |
---|
21 | % 3. If the Family is not found, then empty, [], is returned. |
---|
22 | % |
---|
23 | % Written by Greg Portmann |
---|
24 | |
---|
25 | |
---|
26 | if nargin == 0 |
---|
27 | error('One input required.'); |
---|
28 | end |
---|
29 | if nargin == 1 |
---|
30 | Output = getlist(Family); |
---|
31 | return |
---|
32 | end |
---|
33 | if isempty(ElementList) |
---|
34 | Output = getlist(Family); |
---|
35 | return |
---|
36 | end |
---|
37 | if size(ElementList,2) == 2 |
---|
38 | % Assume that the input was already a device list |
---|
39 | Output = ElementList; |
---|
40 | return |
---|
41 | end |
---|
42 | |
---|
43 | %Output = getfamilydata(Family, 'DeviceList', DevList); |
---|
44 | |
---|
45 | [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family); |
---|
46 | if FamilyIndex |
---|
47 | DeviceListTotal = ACCELERATOR_OBJECT.DeviceList; |
---|
48 | ElementListTotal = ACCELERATOR_OBJECT.ElementList; |
---|
49 | Err = 0; |
---|
50 | |
---|
51 | % Intersect removes duplicate devices so first store index of how to unsort in j_unique |
---|
52 | ElementListOld = ElementList; |
---|
53 | [ElementList, i_unique, j_unique] = unique(ElementList); |
---|
54 | |
---|
55 | % Find the indexes in the full device list (reorder and remove duplicates) |
---|
56 | [ElementList, ii, DeviceIndex] = intersect(ElementList, ElementListTotal); |
---|
57 | if size(ElementList,1) ~= size(ElementListOld,1) |
---|
58 | % All devices must exist (duplicate devices ok) |
---|
59 | [ElementListNotFound, iNotFound] = setdiff(ElementListOld, ElementListTotal); |
---|
60 | if length(iNotFound) > 0 |
---|
61 | % Device not found |
---|
62 | for i = 1:length(iNotFound) |
---|
63 | fprintf(' No devices to get for Family %s(%d)\n', ACCELERATOR_OBJECT.FamilyName, ElementListNotFound(i)); |
---|
64 | end |
---|
65 | error(sprintf('%d Devices not found', length(iNotFound))); |
---|
66 | end |
---|
67 | end |
---|
68 | Output = DeviceListTotal(DeviceIndex,:); % Only data referenced to DeviceList |
---|
69 | Output = Output(j_unique,:); % Reorder and add multiple elements back |
---|
70 | else |
---|
71 | error(sprintf('%s family not found', Family)); |
---|
72 | end |
---|
73 | |
---|