1 | function [FamRes,DevRes,PosRes]=proche2(FamR,FamC,DevC,valdes,FamRloc); |
---|
2 | % function [FamRes,DevRes,PosRes]=proche2(FamR,FamC,DevC,valdes,FamRloc); |
---|
3 | % |
---|
4 | % INPUTS -> VALUES |
---|
5 | % |
---|
6 | % 1. FamR: Family of the element looked for -> 'HCOR' |
---|
7 | % 2. FamC: Family of the element studied -> 'BPMx' |
---|
8 | % 3. DevC: [cell elt] of FamC -> [2 3] |
---|
9 | % 4. valdes: integer to choose the relative location of the element of FamR |
---|
10 | % valdes=-1 : FamR element located before (FamC,DevC) -> -1 |
---|
11 | % valdes= 1 : FamR element located after (FamC,DevC) -> 1 |
---|
12 | % valdes= 0 : closest element of FamR from (FamC,DevC) -> 0 |
---|
13 | % 5. FamRloc: [cell elt;cell elt; ...] -> [1 2;3 6;8 4;...] |
---|
14 | % optional input, used if it is necessary to reduce the FamR element list |
---|
15 | % |
---|
16 | % |
---|
17 | % OUPUTS |
---|
18 | % |
---|
19 | % 1. FamRes: Family of the element found (FamRes=FamR) |
---|
20 | % generally FamRes=FamR |
---|
21 | % but if FamR='Q', FamRes='Q1' | 'Q2' | ... | 'Q10' |
---|
22 | % 2. DevRes: [cell elt] of the element found |
---|
23 | % 3. PosRes: "s" position of the element found |
---|
24 | % |
---|
25 | |
---|
26 | %NOTES |
---|
27 | %FamRes = Famr dans tout les cas sauf lorsque FamR='Q' |
---|
28 | % <=> recherche du Qp le plus proche de FamC @DevC |
---|
29 | % ATTENTION MAchine dependent |
---|
30 | % Use getcircumference instead |
---|
31 | % Use number of quad instead |
---|
32 | % trick of 3 rings instead of one |
---|
33 | |
---|
34 | % RECHERCHE DES POSITIONS DES BPMx |
---|
35 | %FamRloc=getlist(FamR); |
---|
36 | %dim=length(FamRloc); |
---|
37 | |
---|
38 | %i=1:dim; |
---|
39 | %pos=getspos(FamR,FamRloc(i,:)); |
---|
40 | |
---|
41 | % CREATION AUTOMATIQUE D'UN TABLEAU AVEC TOUTES LES FAMILLES DES QP |
---|
42 | % <=>FamQp=['Q1' 'Q2' 'Q3' 'Q4' 'Q5' 'Q6' 'Q7' 'Q8' 'Q9' 'Q10' ] |
---|
43 | |
---|
44 | |
---|
45 | for i=1:10 |
---|
46 | FamQp(i)=cellstr(strcat('Q',num2str(i))); |
---|
47 | end |
---|
48 | |
---|
49 | |
---|
50 | % Traduction des variables d'entrï¿œe |
---|
51 | nameC=char(FamC); |
---|
52 | cellule=DevC(1); |
---|
53 | element=DevC(2); |
---|
54 | |
---|
55 | % cell1 = cellules oᅵ on trouve Q1,Q2,Q3,Q4,Q5 |
---|
56 | cell1=[1 4 5 8 9 12 13 16]; |
---|
57 | % cell2 = cellules oᅵ on trouve Q9,Q10 |
---|
58 | cell2=[2 3 6 7 10 11 14 15]; |
---|
59 | % Q6,Q7,Q8 dans toutes les cellules : OK |
---|
60 | |
---|
61 | longN=length(nameC); |
---|
62 | %FamRloc=zeros() |
---|
63 | nameC(1)=='Q' |
---|
64 | nameC(2)=='T' |
---|
65 | if(FamR=='Q') % Si la Famille d'entrï¿œe est seulement 'Q' <=> on veut scruter tous les Qp |
---|
66 | init=0; |
---|
67 | FamR=FamQp; % FamR doit contenir toutes les Fammilles de QP |
---|
68 | for j=1:10 |
---|
69 | |
---|
70 | FamRloc=getlist(char(FamR(j))); |
---|
71 | % FamRloc=[cell elt] de la Famille 'Qj' |
---|
72 | |
---|
73 | %listFamR |
---|
74 | |
---|
75 | |
---|
76 | lfQ=length(FamRloc); % length(FamRloc)=8 pour Q1,Q2,Q3| =16 pour Q4,Q5,Q9,Q10| =24 pour Q6,Q7,Q8 |
---|
77 | for i=1:lfQ |
---|
78 | % FamQloc = [ 'Q1' ; 'Q1' ;'Q1';...;'Q1';'Q2';...;'Q2';.......;'Q10' ] |
---|
79 | % FamRloc = [cell elt;cell elt;....;...;....;....;...;....;.......;....% ] |
---|
80 | % posQint = [ spos spos .... ... .... .... ... .... ....... ......] |
---|
81 | FamQloc(i+init,:)=FamR(j); |
---|
82 | FamRloc2(i+init,:)=FamRloc(i,:); |
---|
83 | posQint(i+init)=getspos(char(FamR(j)),FamRloc(i,:)); % posQint = position s de [cell elt] de 'Qj' |
---|
84 | end |
---|
85 | init=init+length(FamRloc); |
---|
86 | end |
---|
87 | |
---|
88 | posQ=getspos(char(nameC),DevC); % posQ = position s de DevC=[cell elt] de de la Famille FamC=nameC |
---|
89 | for i=1:160 |
---|
90 | if (abs(posQint(i)-posQ)>177 && posQint(i)-posQ>0) || (abs(posQint(i)-posQ)<177 && posQint(i)-posQ<0) |
---|
91 | condit=-1; |
---|
92 | elseif (abs(posQint(i)-posQ)<177 && posQint(i)-posQ>0) || (abs(posQint(i)-posQ)>177 && posQint(i)-posQ<0) |
---|
93 | condit=1; |
---|
94 | else |
---|
95 | condit=0; |
---|
96 | end |
---|
97 | poscalc(i)=min([abs(posQint(i)-posQ) 354-abs(posQint(i)-posQ)]); |
---|
98 | poscalcBis(i,:)=[min([abs(posQint(i)-posQ) 354-abs(posQint(i)-posQ)]) condit]; |
---|
99 | |
---|
100 | end |
---|
101 | %tri |
---|
102 | [posTri,indTri]=sort(poscalc,'ascend'); |
---|
103 | FamQloc; |
---|
104 | FamRloc2; |
---|
105 | indNear=indTri(1); |
---|
106 | % OUTPUT |
---|
107 | FamRes=FamQloc(indNear,:); % FamRes = Famille du Qp le plus proche |
---|
108 | DevRes=FamRloc2(indNear,:); % DevRes = [cell elt] du Qp le plus proche |
---|
109 | PosRes=getspos(char(FamQloc(indNear,:)),FamRloc2(indNear,:));% PosRes = position s du Qp le plus proche |
---|
110 | |
---|
111 | cond=poscalcBis(indTri(1),2); |
---|
112 | |
---|
113 | %TRAITEMENT DES CONDITIONS AVANT / APRES : 1 0 -1 |
---|
114 | if (valdes==0) |
---|
115 | FamRes=FamRes; % FamRes = Famille du Qp le plus proche |
---|
116 | DevRes=DevRes; % DevRes = [cell elt] du Qp le plus proche |
---|
117 | PosRes=PosRes; |
---|
118 | elseif(valdes==1) |
---|
119 | if(cond>0) |
---|
120 | FamRes=FamRes; |
---|
121 | DevRes=DevRes; |
---|
122 | PosRes=PosRes; |
---|
123 | elseif(cond<=0) |
---|
124 | i=1; |
---|
125 | while cond<=0 |
---|
126 | indNear=indTri(i); |
---|
127 | cond=poscalcBis(indTri(i),2); |
---|
128 | FamRes=FamQloc(indNear,:); |
---|
129 | DevRes=FamRloc2(indNear,:); |
---|
130 | PosRes=getspos(char(FamQloc(indNear,:)),FamRloc2(indNear,:)); |
---|
131 | i=i+1; |
---|
132 | end |
---|
133 | end |
---|
134 | elseif(valdes==-1) |
---|
135 | if(cond<0) |
---|
136 | FamRes=FamRes; |
---|
137 | DevRes=DevRes; |
---|
138 | PosRes=PosRes; |
---|
139 | elseif(cond>=0) |
---|
140 | i=1; |
---|
141 | while cond>=0 |
---|
142 | |
---|
143 | indNear=indTri(i); |
---|
144 | cond=poscalcBis(indTri(i),2); |
---|
145 | FamRes=FamQloc(indNear,:); |
---|
146 | DevRes=FamRloc2(indNear,:); |
---|
147 | PosRes=getspos(cellstr(FamRes),DevRes); |
---|
148 | i=i+1; |
---|
149 | end |
---|
150 | end |
---|
151 | end |
---|
152 | |
---|
153 | |
---|
154 | % si nameC=FamR = Qi, il se peut que DevC=[cell elt] n'existe pas! |
---|
155 | %CAS 1 |
---|
156 | elseif (nameC(2)~='T') && (nameC(1)=='Q') && (str2num(nameC(longN))< 6) && (str2num(nameC(longN))> 0) && isempty(find(cell1==cellule)) |
---|
157 | disp('cas1'); |
---|
158 | disp(nameC(1)); |
---|
159 | disp(nameC(longN)); |
---|
160 | FamRes='error'; |
---|
161 | DevRes='error'; |
---|
162 | PosRes='error'; |
---|
163 | disp('la Famille existe pas dans la cellule demandï¿œe') |
---|
164 | |
---|
165 | %CAS 2 |
---|
166 | elseif (nameC(2)~='T') && (nameC(1)=='Q') && ((str2num(nameC(longN)) > 8) | (str2num(nameC(longN)) < 1)) && isempty(find(cell2==cellule)) |
---|
167 | disp('cas2'); |
---|
168 | disp(nameC(1)); |
---|
169 | disp(nameC(longN)+1); |
---|
170 | FamRes='error'; |
---|
171 | DevRes='error'; |
---|
172 | PosRes='error'; |
---|
173 | disp('la Famille existe pas dans la cellule demandï¿œe') |
---|
174 | %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
---|
175 | %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
---|
176 | %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
---|
177 | %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ |
---|
178 | |
---|
179 | %PAS DE PROBLEME !!! |
---|
180 | else |
---|
181 | if nargin < 5 |
---|
182 | FamRloc=getlist(FamR); |
---|
183 | end |
---|
184 | |
---|
185 | dim=length(FamRloc); |
---|
186 | |
---|
187 | for i=1:dim |
---|
188 | pos(i)=getspos(FamR,FamRloc(i,:)); |
---|
189 | end |
---|
190 | |
---|
191 | posC1=getspos(nameC,DevC); %Recheche position "s" de nameC |
---|
192 | %nearest=abs(pos-posC1); |
---|
193 | %indNear=find(nearest==min(nearest)); |
---|
194 | %PosRes=getspos(FamR,FamRloc(indNear,:)); |
---|
195 | |
---|
196 | %PosRes=PosRes; |
---|
197 | %DevRes=FamRloc(indNear,:); |
---|
198 | %FamRes=FamR; |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | for i=1:dim |
---|
203 | if (abs(pos(i)-posC1)>177 && pos(i)-posC1>0) || (abs(pos(i)-posC1)<177 && pos(i)-posC1<0) |
---|
204 | condit=-1; |
---|
205 | elseif (abs(pos(i)-posC1)<177 && pos(i)-posC1>0) || (abs(pos(i)-posC1)>177 && pos(i)-posC1<0) |
---|
206 | condit=1; |
---|
207 | else |
---|
208 | condit=0; |
---|
209 | end |
---|
210 | poscalc(i)=min([abs(pos(i)-posC1) 354-abs(pos(i)-posC1)]); |
---|
211 | poscalcBis(i,:)=[min([abs(pos(i)-posC1) 354-abs(pos(i)-posC1)]) condit]; |
---|
212 | end |
---|
213 | %tri |
---|
214 | [posTri,indTri]=sort(abs(poscalc),'ascend'); |
---|
215 | %nearest=abs(poscalc); |
---|
216 | indNear=indTri(1); |
---|
217 | % OUTPUT |
---|
218 | FamRes=FamR; % FamRes = Famille du Qp le plus proche |
---|
219 | DevRes=FamRloc(indNear,:); % DevRes = [cell elt] du Qp le plus proche |
---|
220 | PosRes=getspos(char(FamR),FamRloc(indNear,:)); % PosRes = position s du Qp le plus proche |
---|
221 | |
---|
222 | cond=poscalcBis(indTri(1),2); |
---|
223 | |
---|
224 | %TRAITEMENT DES CONDITIONS AVANT / APRES : 1 0 -1 |
---|
225 | if (valdes==0) |
---|
226 | FamRes=FamRes; % FamRes = Famille du Qp le plus proche |
---|
227 | DevRes=DevRes; % DevRes = [cell elt] du Qp le plus proche |
---|
228 | PosRes=PosRes; % PosRes = position s du Qp le plus proche |
---|
229 | elseif(valdes==1) |
---|
230 | if(cond>0) |
---|
231 | FamRes=FamRes; |
---|
232 | DevRes=DevRes; |
---|
233 | PosRes=PosRes; |
---|
234 | elseif(cond<=0) |
---|
235 | i=1; |
---|
236 | while cond<=0 |
---|
237 | indNear=indTri(i); |
---|
238 | cond=poscalcBis(indTri(i),2); |
---|
239 | FamRes=FamR; |
---|
240 | DevRes=FamRloc(indNear,:); |
---|
241 | PosRes=getspos(char(FamR),FamRloc(indNear,:)); |
---|
242 | i=i+1; |
---|
243 | end |
---|
244 | end |
---|
245 | elseif(valdes==-1) |
---|
246 | if(cond<0) |
---|
247 | FamRes=FamRes; |
---|
248 | DevRes=DevRes; |
---|
249 | PosRes=PosRes; |
---|
250 | elseif(cond>=0) |
---|
251 | i=1; |
---|
252 | while cond>=0 |
---|
253 | indNear=indTri(i); |
---|
254 | cond=poscalcBis(indTri(i),2); |
---|
255 | FamRes=FamR; |
---|
256 | DevRes=FamRloc(indNear,:); |
---|
257 | PosRes=getspos(char(FamR),FamRloc(indNear,:)); |
---|
258 | i=i+1; |
---|
259 | end |
---|
260 | end |
---|
261 | end |
---|
262 | end |
---|
263 | save('data.mat','poscalc','poscalcBis','PosRes','cond','posTri','indTri','FamRloc'); |
---|
264 | |
---|