source: MML/trunk/mml/getspos.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.0 KB
Line 
1function S = getspos(Family, DeviceList)
2%GETSPOS - Returns the longitudinal position in meters
3%
4%  If using family name, device list method,
5%  S = getspos(Family, DeviceList)
6%
7%  If using AT family name
8%  S = getspos(FamName, IndexVector)
9%
10%  If using tango name method,
11%  S = getspos(TangoNames)
12%
13%  If using common name method,
14%  S = getspos(Family, CommonName)
15%
16%  INPUTS
17%  1. Family = MiddleLayer or AT Family Name
18%             Accelerator Object
19%             Cell Array of Accelerator Objects or Family Names
20%             For CommonNames, Family=[] searches all families
21%     TangoName = Tango access Tango name
22%                Matrix of tango names
23%                Cell array of tango names
24%     CommonName = Common name
25%                 Matrix of common names
26%                 Cell array of common names
27%     DeviceList = [Sector Device #] or [element #] list {default or empty list: whole family}
28%                 Cell Array of DeviceList
29%
30%  OUTPUTS
31%  1. S = the position of the device along the ring (S) [meters]
32%        Empty if Family or CommonName is found not found
33%
34%  See also getphysdata
35
36%
37%  Written by Gregory J. Portmann
38%  Modified by Laurent S. Nadolski
39
40if nargin == 0
41    error('At least one input required');
42end
43
44
45%%%%%%%%%%%%%%%%%%%%%
46% Cell Array Inputs %
47%%%%%%%%%%%%%%%%%%%%%
48if iscell(Family)
49    for i = 1:length(Family)
50        if nargin < 2
51            S{i} = getspos(Family{i});
52        else
53            if iscell(DeviceList)
54                S{i} = getspos(Family{i}, DeviceList{i});
55            else
56                S{i} = getspos(Family{i}, DeviceList);
57            end
58        end
59    end
60    return
61end
62
63
64%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65% Family or data structure inputs beyond this point %
66%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67if isstruct(Family)
68    % Data structure inputs
69    if nargin < 2
70        if isfield(Family,'DeviceList')
71            DeviceList = Family.DeviceList;
72        else
73            DeviceList = [];
74        end
75    end
76    if isfield(Family,'FamilyName')
77        Family = Family.FamilyName;
78    else
79        error('For data structure inputs FamilyName field must exist')
80    end
81else
82    % Family string input
83    if nargin < 2
84        DeviceList = [];
85    end
86end
87
88
89if isfamily(Family(1,:))
90    %%%%%%%%%%%%%%%%%%%%%%
91    % Family name method %
92    %%%%%%%%%%%%%%%%%%%%%%
93
94    if isempty(DeviceList)
95        DeviceList = family2dev(Family);
96    end
97    % if (size(DeviceList,2) == 1)
98    %     DeviceList = elem2dev(Family, DeviceList);
99    % end
100
101    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102    % CommonName Input:  Convert common names to a DeviceList %
103    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104    if isstr(DeviceList)
105        DeviceList = common2dev(DeviceList, Family);
106        if isempty(DeviceList)
107            error('DeviceList was a string but common names could not be found.');
108        end
109    end
110
111    % Get data
112    S = getfamilydata(Family, 'Position', DeviceList);
113
114else
115
116    %%%%%%%%%%%%%%%%%%%%%%%
117    % Tango name method %
118    %%%%%%%%%%%%%%%%%%%%%%%
119    ATIndex = family2atindex(Family(1,:), DeviceList);
120
121    global THERING
122    if ~isempty(ATIndex)
123        S = findspos(THERING, ATIndex);
124        S = S(:);
125
126    else
127
128        %%%%%%%%%%%%%%%%%%%%%%%
129        % Tango name method   %
130        %%%%%%%%%%%%%%%%%%%%%%%
131        % Try to convert to a family and device
132
133        TangoNames = Family;
134        for i = 1:size(TangoNames,1)
135            Family = tango2family(TangoNames(i,:));
136            if isempty(Family)
137                error('Tango name could not be converted to a Family.');
138            end
139            [FamilyIndex, ACCELERATOR_OBJECT] = isfamily(Family);
140            DeviceList = tango2dev(TangoNames(i,:), ACCELERATOR_OBJECT);
141            if isempty(DeviceList) | isempty(DeviceList)
142                error('Tango name could not be converted to a Family and DeviceList.');
143            end
144            S(i,:) = getspos(Family, DeviceList);
145        end
146    end
147end
148
Note: See TracBrowser for help on using the repository browser.