Home > mml > elem2dev.m

elem2dev

PURPOSE ^

ELEM2DEV - Converts a device list to an element list

SYNOPSIS ^

function Output = elem2dev(Family, ElementList)

DESCRIPTION ^

ELEM2DEV - Converts a device list to an element list
  [Sector Device#] = elem2dev(Family, Element#)

  This function convects between the two methods of representing
  the same device in the ring.  The "Device" method is a two column
  matrix with the first being sector number and the seconds being
  the device number in the sector.  The "Element" method is a one column
  matrix with each entry being the element number starting at sector 1.

  The following are equivalent devices for VCMs at the ALS:
                     | 1  2 |                    |  2 |
                     | 1  3 |                    |  3 |
  [Sector Device#] = | 2  1 |    [ElementList] = |  9 |
                     | 2  2 |                    | 10 |
                     | 3  4 |                    | 20 |

  NOTES
  1. If ElementList is empty, the entire family list will be returned.
  2. If the device is not found, then an error will occur.
  3. If the Family is not found, then empty, [], is returned.

  Written by Greg Portmann

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Output = elem2dev(Family, ElementList)
0002 %ELEM2DEV - Converts a device list to an element list
0003 %  [Sector Device#] = elem2dev(Family, Element#)
0004 %
0005 %  This function convects between the two methods of representing
0006 %  the same device in the ring.  The "Device" method is a two column
0007 %  matrix with the first being sector number and the seconds being
0008 %  the device number in the sector.  The "Element" method is a one column
0009 %  matrix with each entry being the element number starting at sector 1.
0010 %
0011 %  The following are equivalent devices for VCMs at the ALS:
0012 %                     | 1  2 |                    |  2 |
0013 %                     | 1  3 |                    |  3 |
0014 %  [Sector Device#] = | 2  1 |    [ElementList] = |  9 |
0015 %                     | 2  2 |                    | 10 |
0016 %                     | 3  4 |                    | 20 |
0017 %
0018 %  NOTES
0019 %  1. If ElementList is empty, the entire family list will be returned.
0020 %  2. If the device is not found, then an error will occur.
0021 %  3. If the Family is not found, then empty, [], is returned.
0022 %
0023 %  Written by Greg Portmann
0024 
0025 
0026 if nargin == 0
0027     error('One input required.');
0028 end
0029 if nargin == 1
0030     Output = getlist(Family);
0031     return
0032 end
0033 if isempty(ElementList)
0034     Output = getlist(Family);
0035     return
0036 end
0037 if size(ElementList,2) == 2
0038     % Assume that the input was already a device list
0039     Output = ElementList;
0040     return
0041 end
0042 
0043 %Output = getfamilydata(Family, 'DeviceList', DevList);
0044 
0045 [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family);
0046 if FamilyIndex    
0047     DeviceListTotal  = ACCELERATOR_OBJECT.DeviceList;
0048     ElementListTotal = ACCELERATOR_OBJECT.ElementList;
0049     Err = 0;
0050     
0051     % Intersect removes duplicate devices so first store index of how to unsort in j_unique
0052     ElementListOld = ElementList;
0053     [ElementList, i_unique, j_unique] = unique(ElementList);        
0054     
0055     % Find the indexes in the full device list (reorder and remove duplicates)
0056     [ElementList, ii, DeviceIndex] = intersect(ElementList, ElementListTotal);
0057     if size(ElementList,1) ~= size(ElementListOld,1)
0058         % All devices must exist (duplicate devices ok)
0059         [ElementListNotFound, iNotFound] = setdiff(ElementListOld, ElementListTotal);
0060         if length(iNotFound) > 0
0061             % Device not found
0062             for i = 1:length(iNotFound)
0063                 fprintf('   No devices to get for Family %s(%d)\n', ACCELERATOR_OBJECT.FamilyName, ElementListNotFound(i));
0064             end
0065             error(sprintf('%d Devices not found', length(iNotFound)));
0066         end
0067     end
0068     Output = DeviceListTotal(DeviceIndex,:);   % Only data referenced to DeviceList
0069     Output = Output(j_unique,:);               % Reorder and add multiple elements back
0070 else
0071     error(sprintf('%s family not found', Family));
0072 end
0073

Generated on Mon 21-May-2007 15:29:18 by m2html © 2003