1 | function [BPMFamilyOutput, BPMDevOutput, DeltaSpos] = sext2bpm(SEXTFamily, SEXTDev) |
---|
2 | %SEXT2BPM - Returns the nearest BPM to the specified sextupole |
---|
3 | % [BPMFamily, BPMDeviceList, DeltaSpos] = sext2bpm(SEXTFamily, SEXTDev) |
---|
4 | % |
---|
5 | % INPUTS |
---|
6 | % 1. SEXTFamily - Quadrupole family (1 family only (row string)) |
---|
7 | % 2. SEXTDeviceList - Quadrupole device list |
---|
8 | % |
---|
9 | % OUTPUTS |
---|
10 | % 1. BPMFamily |
---|
11 | % 2. BPMDeviceList |
---|
12 | % 3. DeltaSpos - Distance from the Quad to the BPM |
---|
13 | % |
---|
14 | % Written by Greg Portmann |
---|
15 | |
---|
16 | |
---|
17 | if nargin < 1 |
---|
18 | SEXTFamily = 'SF'; |
---|
19 | end |
---|
20 | if nargin < 2 |
---|
21 | SEXTDev = family2dev(SEXTFamily); |
---|
22 | end |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | % Get all the BPM families |
---|
27 | BPMFamilyList = getfamilylist; |
---|
28 | [tmp, i] = ismemberof(BPMFamilyList, 'BPM'); |
---|
29 | if ~isempty(i) |
---|
30 | BPMFamilyList = BPMFamilyList(i,:); |
---|
31 | else |
---|
32 | BPMFamilyList = ['BPMx','BPMy']; |
---|
33 | end |
---|
34 | |
---|
35 | |
---|
36 | % Find the BPM next to the Quad |
---|
37 | BPMFamilyOutput = []; |
---|
38 | for k = 1:size(SEXTDev,1) |
---|
39 | SEXTspos = getspos(SEXTFamily, SEXTDev(k,:)); |
---|
40 | |
---|
41 | Del = inf; |
---|
42 | for j = 1:size(BPMFamilyList,1) |
---|
43 | Family = deblank(BPMFamilyList(j,:)); |
---|
44 | BPMDevList = getlist(Family); |
---|
45 | BPMspos = getspos(Family); |
---|
46 | |
---|
47 | i = find(abs(BPMspos-SEXTspos)==min(abs(BPMspos-SEXTspos))); |
---|
48 | BPMDev{j} = BPMDevList(i,:); |
---|
49 | |
---|
50 | if abs(BPMspos(i)-SEXTspos) < Del |
---|
51 | BPMFamilyMin = Family; |
---|
52 | BPMDevMin = BPMDev{j}; |
---|
53 | Del = abs(BPMspos(i)-SEXTspos); |
---|
54 | DelwithSign = BPMspos(i)-SEXTspos; |
---|
55 | end |
---|
56 | end |
---|
57 | |
---|
58 | BPMFamilyOutput = strvcat(BPMFamilyOutput, BPMFamilyMin); |
---|
59 | BPMDevOutput(k,:) = BPMDevMin; |
---|
60 | DeltaSpos(k,1) = DelwithSign; |
---|
61 | end |
---|