source: MML/trunk/mml/at/buildatindex.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.0 KB
Line 
1function ATIndexDev = buildatindex(Family, FamName)
2%BUILDATINDEX - Return AT indices for a given Family
3%
4%  INPUTS
5%  1. Family  - MML Family name
6%  2. FamName - AT Family name {optional if same as Family}
7%
8%  OUTPUTS
9%  1. ATIndexDev -AT index
10%
11%  EXAMPLES
12%  1. buildatindex('Q1')
13%  2. buildatindex('BPMx','BPM')
14%     BPMx - AO name
15%     BPM  - AT name
16%
17%  See Also findcells
18
19%
20%  Written by Spear people
21%  Modified by Laurent S. Nadolski
22%  add FamName per default
23%  October 2010, Modified to have column vector ouput
24
25global THERING
26
27if nargin < 2
28    FamName = Family;
29end
30
31if iscell(FamName)
32    ATIndexList = [];
33    for i = 1:length(FamName)
34        tmp = findcells(THERING, 'FamName', FamName{i});
35        ATIndexList = [ATIndexList; tmp(:)];
36    end
37    ATIndexList = sort(ATIndexList);
38elseif ischar(FamName)
39    ATIndexList = findcells(THERING, 'FamName', FamName)';
40else
41    ATIndexList = FamName;
42end
43
44ATIndexList = ATIndexList(:);
45
46
47if ischar(Family)
48    Ndev = size(family2dev(Family,0),1);
49else
50    Ndev = size(Family,1);
51end
52
53N = length(ATIndexList);
54Nmag = N / Ndev;
55
56
57if rem(Nmag,1) == 0
58   
59    % Assume the number of splits are the same for each magnet
60    for i = 1:Nmag
61        ATIndexDev(:,i) = ATIndexList(i:Nmag:end);
62    end
63   
64else
65   
66    % Find the splits based on positions
67    pos1 = findspos(THERING, ATIndexList);
68    pos2 = findspos(THERING, ATIndexList+1);
69   
70    Nmax = 1;
71    j = 1;
72    ATIndexCell{j} = ATIndexList(1);
73    for i = 2:length(ATIndexList)       
74        if  pos1(i) ~= pos2(i-1)
75            j = j + 1;
76            ATIndexCell{j,1} = [];
77        end
78        ATIndexCell{j,1} = [ATIndexCell{j} ATIndexList(i)];
79        if length(ATIndexCell{j}) > Nmax
80            Nmax = length(ATIndexCell{j});
81        end
82    end
83   
84    ATIndexDev = NaN * ones(Ndev, Nmax);
85    for i = 1:Ndev
86        ATIndexDev(i,1:length(ATIndexCell{i})) = ATIndexCell{i};
87    end
88   
89end
90
91% Return a column vector if not split element   
92if N > 0 && Nmag == 1,
93    ATIndexDev = ATIndexDev(:);
94end
Note: See TracBrowser for help on using the repository browser.