1 | function varargout = sortbpms(varargin) |
---|
2 | %SORTBPMS - Compares vectors for several cases: |
---|
3 | %(1) available electronically (BPM.status) |
---|
4 | %(2) available in reference orbit (BPM.iref) |
---|
5 | %(3) available in response matrix (RSP.ib) |
---|
6 | %*** BPM.avail requires reference, response matrix, status |
---|
7 | % |
---|
8 | % INPUTS |
---|
9 | % 1. Bpm structure |
---|
10 | % 2. Response matrix structure |
---|
11 | % |
---|
12 | % OUTPUTS |
---|
13 | % 1. Updated BPM structure |
---|
14 | |
---|
15 | % |
---|
16 | % Written by Jeff Corbett |
---|
17 | % Modified by Laurent S. Nadolski |
---|
18 | |
---|
19 | BPM = varargin{1}; |
---|
20 | RSP = varargin{2}; |
---|
21 | |
---|
22 | % [C,IA,IB] = INTERSECT(A,B) returns index vectors IA and IB |
---|
23 | % such that C = A(IA) and C = B(IB) |
---|
24 | % [C,I] = SETDIFF(...) returns an index vector I such that C = A(I) |
---|
25 | |
---|
26 | for ip = 1:2 |
---|
27 | % compare status with reference orbit |
---|
28 | [BPM(ip).avail,IA,IB] = intersect(BPM(ip).iref,BPM(ip).status); %BPM.iref and BPM.status are compressed |
---|
29 | [C,IA] = setdiff(BPM(ip).iref,BPM(ip).iref(IA)); %check for rejected reference BPMs |
---|
30 | if ~isempty(IA) |
---|
31 | disp('SortBPMs Warning 1A: BPMs in reference orbit do not have valid status'); |
---|
32 | for ii = IA |
---|
33 | disp(BPM(ip).name(ii,:)); |
---|
34 | end |
---|
35 | end |
---|
36 | |
---|
37 | % compare result with response matrix |
---|
38 | [BPM(ip).avail,IA,IB] = intersect(BPM(ip).avail,RSP(ip).ib); %BPM.avail and RSP.ib are compressed |
---|
39 | [C,IA] = setdiff(BPM(ip).avail,BPM(ip).avail(IA)); %check for rejected available BPMs |
---|
40 | if ~isempty(IA) |
---|
41 | disp('SortBPMs Warning 2A: BPMs with valid status and in reference orbit not in response matrix'); |
---|
42 | for ii=IA |
---|
43 | disp(BPM(ip).name(ii,:)); |
---|
44 | end |
---|
45 | end |
---|
46 | |
---|
47 | % compare result with fit selection |
---|
48 | [BPM(ip).ifit,IA,IB] = intersect(BPM(ip).avail,BPM(ip).ifit); %BPM.avail and BPM.ifit are compressed |
---|
49 | [C,IA] = setdiff(BPM(ip).avail,BPM(ip).avail(IA)); %check for rejected available BPMs |
---|
50 | if ~isempty(IA) |
---|
51 | disp('SortBPMs Warning 3A: BPMs with valid status, in reference orbit, and in response matrix not in fit'); |
---|
52 | for ii = IA |
---|
53 | disp(BPM(ip).name(ii,:)); |
---|
54 | end |
---|
55 | end |
---|
56 | |
---|
57 | end %end of plane loop |
---|
58 | |
---|
59 | varargout{1} = BPM; |
---|