1 | function varargout=SortBPMss(varargin) |
---|
2 | % SortBPMss compares vectors for: |
---|
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 | BPM=varargin{1}; |
---|
9 | RSP=varargin{2}; |
---|
10 | |
---|
11 | % [C,IA,IB] = INTERSECT(A,B) returns index vectors IA and IB |
---|
12 | % such that C = A(IA) and C = B(IB) |
---|
13 | % [C,I] = SETDIFF(...) returns an index vector I such that C = A(I) |
---|
14 | |
---|
15 | for ip=1:2 |
---|
16 | % compare status with reference orbit |
---|
17 | [BPM(ip).avail,IA,IB]=intersect(BPM(ip).iref,BPM(ip).status); %BPM.iref and BPM.status are compressed |
---|
18 | [C,IA]=setdiff(BPM(ip).iref,BPM(ip).iref(IA)); %check for rejected reference BPMs |
---|
19 | if ~isempty(IA) |
---|
20 | %disp('SortBPMs Warning 1A: BPMs in reference orbit do not have valid status'); |
---|
21 | for ii=IA |
---|
22 | %disp(BPM(ip).name(ii,:)); |
---|
23 | end |
---|
24 | end |
---|
25 | % [C,IB]=setdiff(BPM(ip).status,BPM(ip).status(IB)); %check for rejected status BPMs |
---|
26 | % if ~isempty(IB) |
---|
27 | % disp('SortBPMs Warning 1B: BPMs with valid status not in reference orbit'); |
---|
28 | % for ii=IB |
---|
29 | % disp(BPM(ip).name(ii,:)); |
---|
30 | % end |
---|
31 | % end |
---|
32 | |
---|
33 | % compare result with response matrix |
---|
34 | [BPM(ip).avail,IA,IB]=intersect(BPM(ip).avail,RSP(ip).ib); %BPM.avail and RSP.ib are compressed |
---|
35 | [C,IA]=setdiff(BPM(ip).avail,BPM(ip).avail(IA)); %check for rejected available BPMs |
---|
36 | if ~isempty(IA) |
---|
37 | %disp('SortBPMs Warning 2A: BPMs with valid status and in reference orbit not in response matrix'); |
---|
38 | for ii=IA |
---|
39 | %disp(BPM(ip).name(ii,:)); |
---|
40 | end |
---|
41 | end |
---|
42 | % [C,IB]=setdiff(RSP(ip).ib,RSP(ip).ib(IB)); %check for rejected response matrix BPMs |
---|
43 | % if ~isempty(IB) |
---|
44 | % disp('SortBPMs Warning 2B: BPMs in response matrix do not have valid status or not in reference orbit'); |
---|
45 | % for ii=IB |
---|
46 | % disp(BPM(ip).name(ii,:)); |
---|
47 | % end |
---|
48 | % end |
---|
49 | |
---|
50 | % compare result with fit selection |
---|
51 | [BPM(ip).ifit,IA,IB]=intersect(BPM(ip).avail,BPM(ip).ifit); %BPM.avail and BPM.ifit are compressed |
---|
52 | [C,IA]=setdiff(BPM(ip).avail,BPM(ip).avail(IA)); %check for rejected available BPMs |
---|
53 | % if ~isempty(IA) |
---|
54 | % disp('SortBPMs Warning 3A: BPMs with valid status, in reference orbit, and in response matrix not in fit'); |
---|
55 | % for ii=IA |
---|
56 | % disp(BPM(ip).name(ii,:)); |
---|
57 | % end |
---|
58 | % end |
---|
59 | %%%[C,IB]=setdiff(BPM(ip).ifit,BPM(ip).ifit(IB)); %check for rejected fit BPMs |
---|
60 | if ~isempty(IB) |
---|
61 | %disp('SortBPMs Warning 3B: BPMs in fit not do not have valid status, in reference orbit, or not in response matrix'); |
---|
62 | for ii=IB |
---|
63 | %%%disp(BPM(ip).name(ii,:)); |
---|
64 | end |
---|
65 | end |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | end %end of plane loop |
---|
71 | |
---|
72 | % for ip=1:2 |
---|
73 | % [navail,BPM(ip).avail]=intland(BPM(ip).status,BPM(ip).iref); % compare status matrix with reference orbit |
---|
74 | % [navail,BPM(ip).avail]=intland(BPM(ip).avail,RSP(ip).ib); % compare with response matrix |
---|
75 | % [nfit,BPM(ip).ifit] =intland(BPM(ip).avail,BPM(ip).ifit); % compare with fit selection |
---|
76 | % end |
---|
77 | |
---|
78 | varargout{1}=BPM; |
---|
79 | |
---|
80 | |
---|
81 | function t=testsort |
---|
82 | |
---|
83 | |
---|
84 | family='BPMx'; |
---|
85 | [index,AO]=isfamily(family); |
---|
86 | name=family2common(AO); |
---|
87 | status=[1 2 3 4 5]'; |
---|
88 | avail =[1 2 3 4 5]'; |
---|
89 | ifit =[1 2 3 4 5]'; |
---|
90 | iref =[1 2 3 4 5]'; |
---|
91 | irsp =[1 2 3 4 5]'; |
---|
92 | |
---|
93 | t.name=name; |
---|
94 | t.status=status; |
---|
95 | t.avail=avail; |
---|
96 | t.ifit=ifit; |
---|
97 | t.iref=iref; |
---|
98 | |
---|
99 | BPM(1)=t; |
---|
100 | BPM(2)=t; |
---|
101 | |
---|
102 | RSP(1).ib=irsp; |
---|
103 | RSP(2).ib=irsp; |
---|
104 | RSP(2).ic=irsp; |
---|
105 | RSP(2).ic=irsp; |
---|
106 | |
---|
107 | BPM=SortBPMs(BPM,RSP); |
---|
108 | |
---|
109 | t=BPM(1); |
---|
110 | disp('status') |
---|
111 | t.status |
---|
112 | disp('avail') |
---|
113 | t.avail |
---|
114 | disp('ifit') |
---|
115 | t.ifit |
---|
116 | disp('iref') |
---|
117 | t.iref |
---|
118 | disp('irsp') |
---|
119 | RSP(1).ib |
---|
120 | |
---|