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