1 | function 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 | |
---|
25 | global THERING |
---|
26 | |
---|
27 | if nargin < 2 |
---|
28 | FamName = Family; |
---|
29 | end |
---|
30 | |
---|
31 | if 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); |
---|
38 | elseif ischar(FamName) |
---|
39 | ATIndexList = findcells(THERING, 'FamName', FamName)'; |
---|
40 | else |
---|
41 | ATIndexList = FamName; |
---|
42 | end |
---|
43 | |
---|
44 | ATIndexList = ATIndexList(:); |
---|
45 | |
---|
46 | |
---|
47 | if ischar(Family) |
---|
48 | Ndev = size(family2dev(Family,0),1); |
---|
49 | else |
---|
50 | Ndev = size(Family,1); |
---|
51 | end |
---|
52 | |
---|
53 | N = length(ATIndexList); |
---|
54 | Nmag = N / Ndev; |
---|
55 | |
---|
56 | |
---|
57 | if 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 | |
---|
64 | else |
---|
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 | |
---|
89 | end |
---|
90 | |
---|
91 | % Return a column vector if not split element |
---|
92 | if N > 0 && Nmag == 1, |
---|
93 | ATIndexDev = ATIndexDev(:); |
---|
94 | end |
---|