source: MML/trunk/machine/SOLEIL/StorageRing/steerette/steerette.m @ 17

Last change on this file since 17 was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 109.5 KB
Line 
1function varargout = steerette(varargin)
2% STEERETTE M-file for steerette.fig
3%      STEERETTE, by itself, creates a new STEERETTE or raises the existing
4%      singleton*.
5%
6%      H = STEERETTE returns the handle to a new STEERETTE or the handle to
7%      the existing singleton*.
8%
9%      STEERETTE('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in STEERETTE.M with the given input arguments.
11%
12%      STEERETTE('Property','Value',...) creates a new STEERETTE or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before steerette_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to steerette_OpeningFcn via varargin.
17%
18%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
19%      instance to run (singleton)".
20%
21% See also: GUIDE, GUIDATA, GUIHANDLES
22
23% Copyright 2002-2003 The MathWorks, Inc.
24
25% Edit the above text to modify the response to help steerette
26
27% Last Modified by GUIDE v2.5 30-May-2006 17:40:55
28
29% Begin initialization code - DO NOT EDIT
30gui_Singleton = 1;
31gui_State = struct('gui_Name',       mfilename, ...
32                   'gui_Singleton',  gui_Singleton, ...
33                   'gui_OpeningFcn', @steerette_OpeningFcn, ...
34                   'gui_OutputFcn',  @steerette_OutputFcn, ...
35                   'gui_LayoutFcn',  [] , ...
36                   'gui_Callback',   []);
37if nargin && ischar(varargin{1})
38    gui_State.gui_Callback = str2func(varargin{1});
39end
40
41if nargout
42    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
43else
44    gui_mainfcn(gui_State, varargin{:});
45end
46% End initialization code - DO NOT EDIT
47
48% --- Executes just before steerette is made visible.
49function steerette_OpeningFcn(hObject, eventdata, handles, varargin)
50% This function has no output args, see OutputFcn.
51% hObject    handle to figure
52% eventdata  reserved - to be defined in a future version of MATLAB
53% handles    structure with handles and user data (see GUIDATA)
54% varargin   command line arguments to steerette (see VARARGIN)
55
56% Choose default command line output for steerette
57handles.output = hObject;
58
59setappdata(handles.figure1, 'BPMxList', family2dev('BPMx'));
60setappdata(handles.figure1, 'BPMzList', family2dev('BPMz'));
61setappdata(handles.figure1,'BPMxDeviceListPR',[]);
62% orbite premier tour avec  kick pour mesure partie entiere nombre d'onde
63setappdata(handles.figure1,'orbite_x_coup1',0);
64setappdata(handles.figure1,'orbite_z_coup1',0);
65setappdata(handles.figure1,'orbite_x_coup2',0);
66setappdata(handles.figure1,'orbite_z_coup2',0);
67% enregistrement valeur correcteurs fermeture tour
68setappdata(handles.figure1,'val_corr_CH_PR',0);
69setappdata(handles.figure1,'val_corr_CV_PR',0);
70
71% compteur du nombre d'acquisition orbite transport pour calcul nombre d'onde
72setappdata(handles.figure1,'compteur',0);
73
74% initialisation de la machine
75if isempty(getao)
76        disp('Warning: CHARGER L''AcceleratorObjects !!!!!!!');
77        return
78else
79        Machine = getfamilydata('SubMachine');
80        switch Machine
81            case 'StorageRing'
82                %%
83            case 'Booster'
84                %%%
85            otherwise               
86            disp('Warning: Machine not recognized!');
87            return
88        end
89end
90
91% nom nomenclature et positions des correcteurs actifs, positions BPM actifs
92HCOR.DeviceName = family2tangodev('HCOR');% getfamilydata('HCOR','DeviceName',family2dev('HCOR'));
93VCOR.DeviceName = family2tangodev('VCOR');% getfamilydata('VCOR','DeviceName',family2dev('VCOR'));
94HCOR.DeviceList = family2dev('HCOR');% getfamilydata('HCOR','DeviceName',family2dev('HCOR'));
95VCOR.DeviceList = family2dev('VCOR');% getfamilydata('VCOR','DeviceName',family2dev('VCOR'));
96HCOR.Position = getspos('HCOR');% getfamilydata('HCOR','Position',family2dev('HCOR'));
97VCOR.Position =  getspos('VCOR');% getfamilydata('VCOR','Position',family2dev('VCOR'));
98BPMx.Position = getspos('BPMx');% getfamilydata('BPMx','Position',family2dev('BPMx'));
99BPMz.Position = getspos('BPMz');% getfamilydata('BPMz','Position',family2dev('BPMz'));
100BPMx.DeviceList = family2dev('BPMx');
101BPMz.DeviceList = family2dev('BPMz');
102setappdata(handles.figure1,'HCOR',HCOR);
103setappdata(handles.figure1,'VCOR',VCOR);
104setappdata(handles.figure1,'BPMx',BPMx);
105setappdata(handles.figure1,'BPMz',BPMz);
106
107% initalisation popupmenu
108set(handles.CH_popupmenu2, 'String', {'liste correcteurs horizontaux', HCOR.DeviceName{:}});
109set(handles.CV_popupmenu3, 'String', {'liste correcteurs verticaux', VCOR.DeviceName{:}});
110
111% initialisation matrice singular values en H et V
112S = [];S_V = [];
113setappdata(handles.figure1,'S',S);
114setappdata(handles.figure1,'S_V',S_V);
115
116% initialisation nbre de correcteurs utilisᅵs pour la SVD (ᅵ 2 !)
117setappdata(handles.nb_correcteurs_H_edit17,'String',num2str(2));
118setappdata(handles.nb_correcteurs_V_edit,'String',num2str(2));
119
120% initialisation du nombre de valeurs propres utilisï¿œes
121% setappdata(handles.figure1,'valvp',size(S,2));
122% setappdata(handles.figure1,'valvp_V',size(S_V,2));
123DiagS = diag(S); DiagS_V = diag(S_V);
124setappdata(handles.figure1,'valvp',length(DiagS));
125setappdata(handles.figure1,'valvp_V',length(DiagS_V));
126
127
128
129% liste des correcteurs H actifs  type : numero cellule numero correcteur
130% dans la cellule
131HCOR_liste = family2dev('HCOR');
132VCOR_liste = family2dev('VCOR');
133setappdata(handles.figure1,'HCOR_liste',HCOR_liste);
134setappdata(handles.figure1,'VCOR_liste',VCOR_liste);
135
136
137% nombre max de correcteurs
138setappdata(handles.figure1,'maxvalCH',size(HCOR.DeviceName,1));
139setappdata(handles.figure1,'maxvalCV',size(VCOR.DeviceName,1));
140
141% numero du correcteur courant (initialisation)
142setappdata(handles.figure1,'n_selection_CH',0);
143setappdata(handles.figure1,'n_selection_CV',0);
144
145% desactiver le pushbutton "correcteur precedent"
146set(handles.CH_precedent_pushbutton4,'Enable','off');
147set(handles.CV_precedent_pushbutton23,'Enable','off');
148% desactiver le pushbutton "correcteur suivant"
149set(handles.CH_suivant_pushbutton5,'Enable','off');
150set(handles.CV_suivant_pushbutton24,'Enable','off');
151%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152% button group sur switch mode transport ou orbite fermée
153
154set(handles.Ntours_edit,'Enable','on');% rendre impossible le controle du nombre de tours
155set(handles.tour_fixe_OF_edit,'Enable','on');% rendre impossible le controle du 1er tour moyenne OF
156set(handles.tour_fixe_T_edit,'Enable','on');% rendre impossible le controle du 1er tour fixe transport
157
158w = uibuttongroup('visible','off','Position',[0.41 0.945 .55 .045],...
159    'Title','Orbite','TitlePosition','centertop',...
160    'BackgroundColor',[0.696 1.0 0.924]);
161w1 = uicontrol('Style','Radio','String','transport - max Sum','Tag','radiobutton1',...
162    'pos',[10 0.95 120 20],'parent',w,'HandleVisibility','off',...
163    'BackgroundColor',[0.696 1.0 0.924]);
164w2 = uicontrol('Style','Radio','String','orbite fermée','Tag','radiobutton2',...
165    'pos',[320. 0.95 90 20],'parent',w,'HandleVisibility','off',...
166    'BackgroundColor',[0.696 1.0 0.924]);
167w3 = uicontrol('Style','Radio','String','transport - tour fixe','Tag','radiobutton3',...
168    'pos',[140 0.95 120 20],'parent',w,'HandleVisibility','off',...
169    'BackgroundColor',[0.696 1.0 0.924]);
170
171% handles.orbite = 'transport - tour fixe';
172% setappdata(handles.figure1,'Orbite','transport - tour fixe');
173
174handles.orbite = 'transport - max Sum';
175setappdata(handles.figure1,'Orbite','transport - max Sum');
176
177
178% set(w,'SelectedObject',w3);  % No selection
179
180set(w,'SelectedObject',w1);  % No selection
181set(w,'Visible','on');
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183% button group sur switch mode simulation ou online
184h = uibuttongroup('visible','off','Position',[0.25 0.945 .15 .045],...
185    'Title','Mode','TitlePosition','centertop',...
186    'BackgroundColor',[0.696 1.0 0.924]);
187u1 = uicontrol('Style','Radio','String','MODEL','Tag','radiobutton1',...
188    'pos',[10 0.95 70 20],'parent',h,'HandleVisibility','off',...
189    'BackgroundColor',[0.696 1.0 0.924]);
190u2 = uicontrol('Style','Radio','String','Online','Tag','radiobutton2',...
191    'pos',[70. 0.95 70 20],'parent',h,'HandleVisibility','off',...
192    'BackgroundColor',[0.696 1.0 0.924]);
193
194%handles.model = u1;
195%handles.online = u2;
196% 2 façons d'enregistrer la variable mode : pas propre mais fait pour gérer pb variable appelée par timer
197%handles.mode = 'Model';
198%setappdata(handles.figure1,'Mode','Model');
199% TEST RUN !
200handles.mode = 'Online';
201setappdata(handles.figure1,'Mode','Online');
202
203
204
205
206set(h,'SelectedObject',u2);  % No selection
207set(h,'Visible','on');
208
209%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210% Creates timer Infinite loop for TIME
211timer2=timer('StartDelay',1,...
212    'ExecutionMode','fixedRate','Period',20.,'TasksToExecute',Inf);
213timer2.TimerFcn = {@mycallback_steerette_heure, hObject,eventdata, handles};
214setappdata(handles.figure1,'Timer2',timer2);
215start(timer2);
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217
218% Creates timer Infinite loop
219timer1=timer('StartDelay',1,...
220    'ExecutionMode','fixedRate','Period',4.,'TasksToExecute',Inf);
221timer1.TimerFcn = {@mycallback_steerette_new, hObject,eventdata, handles};
222setappdata(handles.figure1,'Timer',timer1);
223
224%start(timer1);
225
226
227% button group sur switch timer rafraichissement orbites ON OFF
228g = uibuttongroup('visible','off','Position',[0.45 0.57 .15 .045],...
229    'Title','Rafraichissement','TitlePosition','centertop',...
230    'BackgroundColor',[0.696 1.0 0.924]);
231v1 = uicontrol('Style','Radio','String','ON','Tag','radiobutton1',...
232    'pos',[10 0.95 60 25],'parent',g,'HandleVisibility','off',...
233    'BackgroundColor',[0.696 1.0 0.924]);
234v2 = uicontrol('Style','Radio','String','  OFF','Tag','radiobutton2',...
235    'pos',[90. 0.95 60 25],'parent',g,'HandleVisibility','off',...
236    'BackgroundColor',[0.696 1.0 0.924]);
237
238% handles.on  = v1;
239% handles.off = v2;
240
241% Update handles structure
242guidata(hObject, handles); % ça ne mange pas de pain
243
244set(g,'SelectedObject',v2);  % No selection
245set(g,'Visible','on');
246
247% Update handles structure
248guidata(hObject, handles); % ça ne mange pas de pain
249
250set(h,'SelectionChangeFcn',...
251    {@uibuttongroup_SelectionChangeFcn,handles});
252set(w,'SelectionChangeFcn',...
253    {@uibuttongroup_SelectionChangeFcn_orbite,handles});
254set(g,'SelectionChangeFcn',...
255    {@uibuttongroup_SelectionChangeFcn_timer,handles});
256
257% Update handles structure
258guidata(hObject, handles); % ça ne mange pas de pain
259
260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261% This sets up the initial plot - only do when we are invisible
262% so window can get raised using steerette.
263if strcmp(get(hObject,'Visible'),'off')
264
265
266    if strcmp(handles.mode,'Model')
267
268        %t% version transport
269        % gï¿œnï¿œration d'une ellipse 1 sigma et dï¿œcentrement
270        eps = 150e-9;betax = 3 ;betaz = 3 ;alphax = 0;alphaz = 0;
271        deltax = 2e-3;deltaz = 2e-3;deltaxp = 1e-3;deltazp = 1e-3;
272        X0 = [sqrt(eps * betax) + deltax 0 sqrt(eps * betaz) + deltaz 0 0 0 ;...
273            0  sqrt(eps / betax) + deltaxp 0 sqrt(eps / betaz) + deltazp 0 0 ;...
274            -sqrt(eps * betax)+ deltax 0 -sqrt(eps * betaz)+ deltaz 0 0 0 ;...
275            0  -sqrt(eps / betax)+deltaxp 0 -sqrt(eps / betaz)+deltazp 0 0 ]';
276        setappdata(handles.figure1,'orbite_entry',X0);
277
278        % nP = nbre de particules trackees
279        nP = size(X0,2);
280        BPMindex = family2atindex('BPMx');
281        global THERING
282        nbtour = 1;
283        X01 = zeros(nbtour, 6, nP*length(BPMindex));
284
285        for k=1:nbtour,
286            X01(k,:,:) = linepass(THERING, X0, BPMindex);
287            %X0 = X01(k,:,end)';
288        end
289        Xa = squeeze(X01(1,1,:));
290        Za = squeeze(X01(1,3,:));
291        if nP>1
292            X = [];
293            Z = [];
294            for nBPM = 1:length(BPMindex)
295                X = [X mean(Xa((nP*(nBPM-1)+1):nP*nBPM))];
296                Z = [Z mean(Za((nP*(nBPM-1)+1):nP*nBPM))];
297            end
298            orbite_x = X'*1000;orbite_z = Z'*1000;
299            orbite_sum = 1e6*(0.75 + 0.5*rand(length(BPMindex),1))';
300        else
301            orbite_x = Xa*1000;orbite_z = Za*1000;
302            orbite_sum = 1e6*(0.75 + 0.5*rand(length(BPMindex),1))';
303        end
304
305    else
306        % entrer lecture BPM tour par tour :selectionner le premier tour
307        % sortir un orbite_x et orbite_z
308        % test anneau
309        %BPMx.DeviceList = [1     2;1     3;1     4;1     5;1     6]
310        [X Z Sum] = anabpmnfirstturns( BPMx.DeviceList ,1,7,'NoDisplay', 'NoDisplay2','MaxSum');
311
312        %
313        orbite_x = X';
314        orbite_z = Z';
315        orbite_sum = Sum';
316    end
317
318    setappdata(handles.figure1,'orbite_x',orbite_x);
319    setappdata(handles.figure1,'orbite_z',orbite_z);
320    setappdata(handles.figure1,'orbite_sum',orbite_sum);
321
322    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323    %% graphe 1 : signal somme
324    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325
326    name=['axes' num2str(8)];
327    axes(handles.(name));
328    xdata = BPMx.Position;
329    %xdata = 1:length(orbite_sum);
330    plot(xdata,orbite_sum,'c.-','Tag','line8');
331    set(handles.(name), 'YGrid','On','Xgrid','On');
332    set(gca, 'YMinorTick','On');
333    set(handles.(name), 'XMinorTick','On');
334    xlabel(handles.(name),'position du BPM');
335    ylabel(handles.(name),'signal somme');
336    %xlim([xdata(1) xdata(end)]);
337    %ylim([0 max(orbite_sum)]);
338    %ylim([0 1.e8]);
339    ylim([0 1.e9]);
340
341    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
342    %% graphe 2 : orbite x et z
343    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344
345    name=['axes' num2str(3)];
346    axes(handles.(name));
347    % plot des orbites
348    xdata = BPMx.Position;
349    %xdata = 1:length(orbite_x);
350    plot(xdata,orbite_x,'r.-','Tag','line1');
351    hold on
352    ydata = BPMz.Position;
353    %ydata = 1:length(orbite_z);
354    plot(ydata,orbite_z,'b.-','Tag','line2');
355    hold on
356
357    % plot des BPM initiaux
358    k = 1;
359    plot(xdata(k),orbite_x(k),'rp','MarkerEdgeColor','k',...
360        'MarkerFaceColor','r',...
361        'MarkerSize',12,'Tag','line3');
362    hold on
363    plot(xdata(k),orbite_z(k),'rp','MarkerEdgeColor','k',...
364        'MarkerFaceColor','b',...
365        'MarkerSize',12,'Tag','line4');
366    hold off
367
368    %% Set defaults
369    set(handles.(name), 'Nextplot','Add');
370    set(handles.(name), 'YGrid','On','Xgrid','On');
371    set(gca, 'YMinorTick','On');
372    set(handles.(name), 'XMinorTick','On');
373    xlabel(handles.(name),'position du BPM');
374    ylabel(handles.(name),'orbites (mm)');
375    %xlim([xdata(1) xdata(end)]);
376    %ylim([-10 10]);
377    ylim([-5 5]);
378
379    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380    %% graphe 3 et 4 : correcteurs
381    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382
383    name=['axes' num2str(9)];
384    axes(handles.(name));
385    xbar = HCOR.Position;
386    %xbar = 1: size(HCOR.DeviceName,1);
387    ybar = VCOR.Position;
388    %ybar = 1:size(VCOR.DeviceName,1);
389    liste = getam('HCOR',handles.mode);
390    h0 = bar(xbar,liste,'r','Tag','bar1');
391    xlim(handles.(name),[0 max(HCOR.Position)]);
392    %xlim(handles.(name),[0 size(HCOR.DeviceName,1)+1]);
393    %ylim([-1.5 1.5]);
394    ylim(handles.(name),[-10 10]);
395    ylabel(handles.(name),'Icorr H (A)');
396    set(h0, 'FaceColor','r');
397
398    name=['axes' num2str(10)];
399    axes(handles.(name));
400    liste = getam('VCOR',handles.mode);
401    h1 = bar(ybar,liste,'b','Tag','bar2');
402    set(h1, 'FaceColor','b');
403    xlim(handles.(name),[0 max(VCOR.Position)]);
404    %xlim(handles.(name),[0 size(VCOR.DeviceName,1)+1]);
405    ylim(handles.(name),[-13 13]);
406    xlabel(handles.(name),'position du correcteur');
407    ylabel(handles.(name),'Icorr V (A)');
408
409
410    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411    %% graphe 11 : signal somme tour 1 et 2
412    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
413    name=['axes' num2str(11)];
414    axes(handles.(name));
415
416    % plot le tour 1 et 2 des BPM [1 2] à [1  7]
417    List = getappdata(handles.figure1, 'BPMxList'); % BPM non deselectionné et status 1
418    BPMxDeviceListPR = [ 1 2; 1 3 ; 1 4; 1 5; 1 6 ; 1 7];
419    % tests !!!!!!!!!!!!!!!!!!!!!!!!!
420    BPMxDeviceListPR = intersect(List,BPMxDeviceListPR,'rows');
421    setappdata(handles.figure1,'BPMxDeviceListPR',BPMxDeviceListPR);
422
423    if strcmp(handles.mode,'Model')
424        disp('nothing')
425        X = zeros(size(BPMxDeviceListPR,1),1);
426        orbite_x_1  = X ;  orbite_x_2  = X;
427        orbite_z_1 = X  ;  orbite_z_2 = X;
428        orbite_sum_1  = X; orbite_sum_2  = X;
429    else
430        % on préfÚre chercher les 2 orbites lorsque on appuyera sur
431        % "rafraichir orbites" ce qui supposera qu'elles auront un sens
432        %X  = zeros(size(BPMxDeviceListPR),1)';Z = X;Sum = X;
433        [X Y Sum] = anabpmnfirstturns(BPMxDeviceListPR,2,'NoDisplay2', 'NoDisplay');   % 2 tours
434       
435        %
436        orbite_x_1 = X(1,:)';
437        orbite_z_1 = Y(1,:)';
438        orbite_sum_1 = Sum(1,:)';
439
440        orbite_x_2 = X(2,:)';
441        orbite_z_2 = Y(2,:)';
442        orbite_sum_2 = Sum(2,:)';
443    end
444
445
446    xdata = getspos('BPMx',BPMxDeviceListPR);
447    plot(xdata,orbite_sum_1,'c.--','Tag','line1');
448    hold on
449    plot(xdata,orbite_sum_2,'c.-','Tag','line2');
450    set(handles.(name), 'YGrid','On','Xgrid','On');
451    set(gca, 'YMinorTick','On');
452    set(handles.(name), 'XMinorTick','On');
453
454    ylabel(handles.(name),'signal somme');
455    xlim([xdata(1) xdata(end)]);
456    %ylim([0 max(orbite_sum)]);
457
458    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
459    %% graphe 13 : orbite x et z
460    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461
462    name=['axes' num2str(13)];
463    axes(handles.(name));
464    % plot des orbites
465    xdata =getspos('BPMx',BPMxDeviceListPR);
466    %xdata = 1:length(orbite_x);
467    plot(xdata,orbite_x_1,'r.--','Tag','line1');
468    hold on
469    plot(xdata,orbite_x_2,'r.-','Tag','line2');
470    hold on
471    %ydata = BPMz.Position;
472    %ydata = 1:length(orbite_z);
473    plot(xdata,orbite_z_1,'b.--','Tag','line3');
474    hold on
475    plot(xdata,orbite_z_2,'b.-','Tag','line4');
476    set(handles.(name), 'YGrid','On','Xgrid','On');
477    set(gca, 'YMinorTick','On');
478    set(handles.(name), 'XMinorTick','On');
479
480    xlabel(handles.(name),'position du BPM');
481    ylabel(handles.(name),'orbite (mm)');
482    xlim([xdata(1) xdata(end)]);
483    ylim([-10 10]);
484
485end
486
487
488%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
489%  matrice efficacite :
490%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
491
492enregistrement = 1;
493if enregistrement
494    if strcmp(handles.orbite,'transport - max Sum')
495        % calcul des efficacitï¿œs des correcteurs type transport
496        % eff (CORRI, BPMJ) = sqrt( betaI  * betaJ )  * sin ( phase J - phase I)
497        % SI BPMJ situï¿œ au delï¿œ de CORRI
498
499        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
500        % plan H
501        [bxHCOR,bzHCOR] = modelbeta('HCOR');
502        [bxBPM,bzBPM] = modelbeta('BPMx');
503        [phixHCOR,phizHCOR] = modelphase('HCOR');
504        [phixBPM,phizBPM] = modelphase('BPMx');
505        COEFF = hw2physics('HCOR','Setpoint',1) * 1e3 ;  % mrad/A
506
507        for k = 1:length(HCOR.Position)
508            for j = 1:length(BPMx.Position)
509
510                if BPMx.Position(j) > HCOR.Position(k)
511                    % calcul de l'efficacitï¿œ
512                    Meff(j,k) = sqrt(bxHCOR(k)*bxBPM(j)) * sin(phixBPM(j) - phixHCOR(k))*COEFF(k); % mm/A
513                else
514                    Meff(j,k)= 0;
515                end
516
517            end
518        end
519
520        disp('***  Matrice d''efficacitï¿œ H type transport calculée en mm/A ***')
521
522        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523        % plan V
524        [bxVCOR,bzVCOR] = modelbeta('VCOR');
525        [bxBPM,bzBPM] = modelbeta('BPMz');
526        [phixVCOR,phizVCOR] = modelphase('VCOR');
527        [phixBPM,phizBPM] = modelphase('BPMz');
528        COEFF = hw2physics('VCOR','Setpoint',1) * 1e3 ;
529
530        for k = 1:length(VCOR.Position)
531            for j = 1:length(BPMz.Position)
532
533                if BPMz.Position(j) > VCOR.Position(k)
534                    % calcul de l'efficacitï¿œ
535                    Meff_V(j,k) = sqrt(bzVCOR(k)*bzBPM(j)) * sin(phizBPM(j) - phizVCOR(k))*COEFF(k);
536                else
537                    Meff_V(j,k)= 0;
538                end
539
540            end
541        end
542
543        disp('***  Matrice d''efficacitï¿œ V type transport calculée en mm/A ***')
544
545        % enregistrement
546        directory = getfamilydata('Directory','Steerette');
547        directory_actuelle = pwd;
548
549        cd(directory)
550        % nouvelle maille avec champ de fuite dans les dipoles
551        %Name = 'Maher_alphaover20_5nov07_Meff';
552        Name = 'AMOR_alphaover10_10dec10_Meff';
553        save(Name,'Meff','Meff_V','-mat');
554
555        cd(directory_actuelle);
556    else
557        disp('matrice réponse déjà enregistrée');
558
559    end
560else
561    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
562    % chargement de la matrice efficacite
563    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
564    if strcmp(handles.orbite,'transport - max Sum')
565        directory = getfamilydata('Directory','Steerette');
566        Name = 'Maher_alphaover20_5nov07_Meff'  ;% 'solamor2linb_new_13mai_Meff';
567        filename = strcat(directory,Name);
568        S = load('-mat',filename);
569        Meff = S.Meff ; Meff_V = S.Meff_V;
570    else
571        M = getbpmresp('Struct'); % matrice réponse type anneau
572        Meff = M(1,1).Data ; Meff_V = M(2,2).Data ;
573    end
574end
575setappdata(handles.figure1,'Meff',Meff);
576setappdata(handles.figure1,'Meff_V',Meff_V);
577
578%% Set closing gui function
579set(handles.figure1,'CloseRequestFcn',{@Closinggui,timer1,handles.figure1});
580
581
582
583% Update handles structure
584guidata(hObject, handles);
585
586% UIWAIT makes steerette wait for user response (see UIRESUME)
587% uiwait(handles.figure1);
588
589
590% --- Outputs from this function are returned to the command line.
591function varargout = steerette_OutputFcn(hObject, eventdata, handles)
592% varargout  cell array for returning output args (see VARARGOUT);
593% hObject    handle to figure
594% eventdata  reserved - to be defined in a future version of MATLAB
595% handles    structure with handles and user data (see GUIDATA)
596
597% Get default command line output from handles structure
598varargout{1} = handles.output;
599
600
601% --------------------------------------------------------------------
602function FileMenu_Callback(hObject, eventdata, handles)
603% hObject    handle to FileMenu (see GCBO)
604% eventdata  reserved - to be defined in a future version of MATLAB
605% handles    structure with handles and user data (see GUIDATA)
606
607
608% --------------------------------------------------------------------
609function OpenMenuItem_Callback(hObject, eventdata, handles)
610% hObject    handle to OpenMenuItem (see GCBO)
611% eventdata  reserved - to be defined in a future version of MATLAB
612% handles    structure with handles and user data (see GUIDATA)
613file = uigetfile('*.fig');
614if ~isequal(file, 0)
615    open(file);
616end
617
618% --------------------------------------------------------------------
619function PrintMenuItem_Callback(hObject, eventdata, handles)
620% hObject    handle to PrintMenuItem (see GCBO)
621% eventdata  reserved - to be defined in a future version of MATLAB
622% handles    structure with handles and user data (see GUIDATA)
623printdlg(handles.figure1)
624
625% % --------------------------------------------------------------------
626% function CloseMenuItem_Callback(hObject, eventdata, handles)
627% % hObject    handle to CloseMenuItem (see GCBO)
628% % eventdata  reserved - to be defined in a future version of MATLAB
629% % handles    structure with handles and user data (see GUIDATA)
630% selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
631%                      ['Close ' get(handles.figure1,'Name') '...'],...
632%                      'Yes','No','Yes');
633% if strcmp(selection,'No')
634%     return;
635% end
636%
637% delete(handles.figure1)
638
639function uibuttongroup_SelectionChangeFcn(hObject,eventdata,handles)
640% hObject    handle to uipanel1 (see GCBO)
641% eventdata  reserved - to be defined in a future version of MATLAB
642% handles    structure with handles and user data (see GUIDATA)
643
644switch get(get(hObject,'SelectedObject'),'Tag')  % Get Tag of selected object
645    case 'radiobutton1'
646        % code piece when radiobutton1 is selected goes here       
647        handles.mode = 'Model';
648        setappdata(handles.figure1,'Mode','Model'); % special timer !
649       
650    case 'radiobutton2'
651        % code piece when radiobutton2 is selected goes here
652        handles.mode = 'Online';
653        setappdata(handles.figure1,'Mode','Online'); % special timer !
654end
655
656% Update handles structure
657guidata(hObject, handles);
658
659function uibuttongroup_SelectionChangeFcn_timer(hObject,eventdata,handles)
660% hObject    handle to uipanel1 (see GCBO)
661% eventdata  reserved - to be defined in a future version of MATLAB
662% handles    structure with handles and user data (see GUIDATA)
663
664timer1 = getappdata(handles.figure1,'Timer');
665switch get(get(hObject,'SelectedObject'),'Tag')  % Get Tag of selected object
666    case 'radiobutton1'
667        % code piece when radiobutton1 is selected goes here
668        start(timer1);
669       
670    case 'radiobutton2'
671        % code piece when radiobutton2 is selected goes here
672        stop(timer1);
673       
674end
675
676
677function uibuttongroup_SelectionChangeFcn_orbite(hObject,eventdata,handles)
678% hObject    handle to uipanel1 (see GCBO)
679% eventdata  reserved - to be defined in a future version of MATLAB
680% handles    structure with handles and user data (see GUIDATA)
681
682switch get(get(hObject,'SelectedObject'),'Tag')  % Get Tag of selected object
683    case 'radiobutton1'
684        % code piece when radiobutton1 is selected goes here       
685        handles.orbite = 'transport - max Sum';
686        setappdata(handles.figure1,'Orbite','transport - max Sum'); %
687        % charger la matrice efficacite type transport
688        directory = getfamilydata('Directory','Steerette');
689        Name = 'solamor2linb_new_13mai_Meff';
690        filename = strcat(directory,Name);
691        S = load('-mat',filename);
692        Meff = S.Meff ; Meff_V = S.Meff_V;
693
694        setappdata(handles.figure1,'Meff',Meff);
695        setappdata(handles.figure1,'Meff_V',Meff_V);
696       
697        set(handles.Ntours_edit,'Enable','off');% rendre impossible le controle du nombre de tours
698        set(handles.tour_fixe_OF_edit,'Enable','off');% rendre impossible le controle du 1er tour moyenne OF
699        set(handles.tour_fixe_T_edit,'Enable','off');% rendre impossible le controle du 1er tour fixe transport
700       
701    case 'radiobutton2'
702        % code piece when radiobutton2 is selected goes here
703        handles.orbite = 'orbite fermée';
704        setappdata(handles.figure1,'Orbite','orbite fermée'); %
705        set(handles.Ntours_edit,'Enable','on');% rendre possible le controle du nombre de tours
706        % charger la matrice efficacite type anneau
707        M = getbpmresp('Struct'); % matrice réponse type anneau
708        Meff = M(1,1).Data ; Meff_V = M(2,2).Data ;
709        setappdata(handles.figure1,'Meff',Meff);
710        setappdata(handles.figure1,'Meff_V',Meff_V);
711       
712        set(handles.Ntours_edit,'Enable','on');% rendre impossible le controle du nombre de tours
713        set(handles.tour_fixe_OF_edit,'Enable','on');% rendre impossible le controle du 1er tour moyenne OF
714        set(handles.tour_fixe_T_edit,'Enable','off');% rendre impossible le controle du 1er tour fixe transport
715       
716   case 'radiobutton3'
717        % code piece when radiobutton3 is selected goes here       
718        handles.orbite = 'transport - tour fixe';
719        setappdata(handles.figure1,'Orbite','transport - tour fixe'); %
720        % charger la matrice efficacite type transport
721        directory = getfamilydata('Directory','Steerette');
722        Name = 'solamor2linb_new_13mai_Meff';
723        filename = strcat(directory,Name);
724        S = load('-mat',filename);
725        Meff = S.Meff ; Meff_V = S.Meff_V;
726
727        setappdata(handles.figure1,'Meff',Meff);
728        setappdata(handles.figure1,'Meff_V',Meff_V);
729       
730        set(handles.Ntours_edit,'Enable','off');% rendre impossible le controle du nombre de tours moyenne OF
731        set(handles.tour_fixe_OF_edit,'Enable','off');% rendre impossible le controle du 1er tour moyenne OF
732        set(handles.tour_fixe_T_edit,'Enable','on');% rendre impossible le controle du 1er tour fixe transport
733end
734
735% Update handles structure
736guidata(hObject, handles);
737disp('eh ben !');
738
739% % --- Executes on selection change in popupmenu1.
740% function popupmenu1_Callback(hObject, eventdata, handles)
741% % hObject    handle to popupmenu1 (see GCBO)
742% % eventdata  reserved - to be defined in a future version of MATLAB
743% % handles    structure with handles and user data (see GUIDATA)
744%
745% % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
746% %        contents{get(hObject,'Value')} returns selected item from popupmenu1
747
748
749% % --- Executes during object creation, after setting all properties.
750% function popupmenu1_CreateFcn(hObject, eventdata, handles)
751% % hObject    handle to popupmenu1 (see GCBO)
752% % eventdata  reserved - to be defined in a future version of MATLAB
753% % handles    empty - handles not created until after all CreateFcns called
754%
755% % Hint: popupmenu controls usually have a white background on Windows.
756% %       See ISPC and COMPUTER.
757% if ispc
758%     set(hObject,'BackgroundColor','white');
759% else
760%     set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
761% end
762%
763% set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'});
764
765
766% --- Executes on selection change in CH_popupmenu2.
767function CH_popupmenu2_Callback(hObject, eventdata, handles)
768% hObject    handle to CH_popupmenu2 (see GCBO)
769% eventdata  reserved - to be defined in a future version of MATLAB
770% handles    structure with handles and user data (see GUIDATA)
771
772% Hints: contents = get(hObject,'String') returns CH_popupmenu2 contents as cell array
773%        contents{get(hObject,'Value')} returns selected item from CH_popupmenu2
774
775
776HCOR = getappdata(handles.figure1,'HCOR');
777% attribution du numero du correcteur (on enlï¿œve le titre)
778valCH = get(hObject,'Value')-1;
779% attribution du nom du device selectionne dans "device"
780
781switch valCH
782    case 1
783            %device = HCOR.DeviceName(1);
784            % desactiver le pushbutton "correcteur precedent"
785            set(handles.CH_precedent_pushbutton4,'Enable','off');
786            % activer le pushbutton "correcteur suivant"
787            set(handles.CH_suivant_pushbutton5,'Enable','on');
788    case size(HCOR.DeviceName,1)
789            %device = HCOR.DeviceName(size(HCOR.DeviceName,1));
790            % activer le pushbutton "correcteur precedent"
791            set(handles.CH_precedent_pushbutton4,'Enable','on');
792            % desactiver le pushbutton "correcteur suivant"
793            set(handles.CH_suivant_pushbutton5,'Enable','off');
794end
795
796for k = 2:size(HCOR.DeviceName,1)-1
797    switch valCH
798        case k
799            %device = HCOR.DeviceName(k);
800            % activer le pushbutton "correcteur precedent"
801            set(handles.CH_precedent_pushbutton4,'Enable','on');
802            % activer le pushbutton "correcteur suivant"
803            set(handles.CH_suivant_pushbutton5,'Enable','on');
804    end
805end
806
807
808%disp('coucou')
809
810% afficher dans ICH_edit1 la valeur actuelle du courant du correcteur selectionne
811liste = getam('HCOR',handles.mode);
812valeur_corr = liste(valCH);
813set(handles.ICH_edit1,'String',sprintf('%3.2f',valeur_corr));
814
815% re-initaliser le slider ᅵ cette valeur de courant
816set(handles.ICH_slider1,'Value',valeur_corr);
817
818% afficher dans le text l'autre nomenclature type [cell Nᅵ HCOR]
819HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
820set(handles.HCOR_text18,'String',...
821    strcat(num2str(valCH),'   [',num2str(HCOR_liste(valCH,:)),']'));
822
823if valCH>0
824    % enregistrer le numero du correcteur selectionne
825    setappdata(handles.figure1,'n_selection_CH',valCH);
826%     % enregistrer le nom du correcteur selectionne
827%     setappdata(handles.figure1,'device_CH',device);
828else
829    % initialiser le nom du correcteur
830    setappdata(handles.figure1,'device_CH','');
831    % desactiver le pushbutton "correcteur precedent"
832    set(handles.CH_precedent_pushbutton4,'Enable','off');
833    % desactiver le pushbutton "correcteur suivant"
834    set(handles.CH_suivant_pushbutton5,'Enable','off');
835end
836
837
838% rafraichir le BPM consecutif selectionnᅵ
839mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
840disp('hep !')
841
842
843function HCOR_text18_CreateFcn(hObject, eventdata, handles)
844
845function date_et_heure_text20_CreateFcn(hObject, eventdata, handles)
846
847% --- Executes during object creation, after setting all properties.
848function CH_popupmenu2_CreateFcn(hObject, eventdata, handles)
849% hObject    handle to CH_popupmenu2 (see GCBO)
850% eventdata  reserved - to be defined in a future version of MATLAB
851% handles    empty - handles not created until after all CreateFcns called
852
853% Hint: popupmenu controls usually have a white background on Windows.
854%       See ISPC and COMPUTER.
855% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
856%     set(hObject,'BackgroundColor','white');
857% end
858if ispc
859    set(hObject,'BackgroundColor','white');
860else
861    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
862end
863
864%HCOR = getfamilydata('HCOR');
865%HCOR = getappdata(handles.figure1,'HCOR');
866
867% cellule = {};
868% for j = 1:size(HCOR.DeviceName,1)
869%     cellule = {cellule{:},strcat(num2str(HCOR.ElementList(j)),' : ',HCOR.DeviceName{j})};
870% end
871% set(hObject, 'String', {'liste correcteurs horizontaux', cellule{:}});       
872
873
874
875
876   
877% --- Executes on button press in CH_precedent_pushbutton4.
878function CH_precedent_pushbutton4_Callback(hObject, eventdata, handles)
879% hObject    handle to CH_precedent_pushbutton4 (see GCBO)
880% eventdata  reserved - to be defined in a future version of MATLAB
881% handles    structure with handles and user data (see GUIDATA)
882
883% nombre max de correcteurs H
884maxvalCH = getappdata(handles.figure1,'maxvalCH');
885
886% numero du correcteur actuellement selectionne
887valCH = getappdata(handles.figure1,'n_selection_CH');
888%selectionner dans la liste le correcteur precedent
889set(handles.CH_popupmenu2,'Value',valCH);
890% enregistrer le nouveau numero de correcteur de la liste
891valCH = valCH - 1;
892setappdata(handles.figure1,'n_selection_CH',valCH);
893% enregistrer le correcteur
894%setappdata(handles.figure1,'
895
896if valCH>=maxvalCH
897    % activer le pushbutton "correcteur precedent"
898    set(handles.CH_precedent_pushbutton4,'Enable','on');
899    % desactiver le pushbutton "correcteur suivant"
900    set(handles.CH_suivant_pushbutton5,'Enable','off');
901elseif 1>=valCH
902    % desactiver le pushbutton "correcteur precedent"
903    set(handles.CH_precedent_pushbutton4,'Enable','off');
904    % activer le pushbutton "correcteur suivant"
905    set(handles.CH_suivant_pushbutton5,'Enable','on');
906else
907    % activer le pushbutton "correcteur precedent"
908    set(handles.CH_precedent_pushbutton4,'Enable','on');
909    % activer le pushbutton "correcteur suivant"
910    set(handles.CH_suivant_pushbutton5,'Enable','on');
911end
912
913
914% afficher dans ICH_edit1 la valeur actuelle du courant du correcteur selectionne
915liste = getam('HCOR',handles.mode);
916valeur_corr = liste(valCH);
917set(handles.ICH_edit1,'String',sprintf('%3.2f',valeur_corr));
918
919% re-initaliser le slider ᅵ cette valeur de courant
920set(handles.ICH_slider1,'Value',valeur_corr);
921
922% afficher dans le text l'autre nomenclature type [cell Nᅵ HCOR]
923HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
924set(handles.HCOR_text18,'String',...
925    strcat(num2str(valCH),'   [',num2str(HCOR_liste(valCH,:)),']'));
926
927% rafraichir le BPM consecutif selectionnᅵ
928mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
929
930
931
932% --- Executes on button press in CH_suivant_pushbutton5.
933function CH_suivant_pushbutton5_Callback(hObject, eventdata, handles)
934% hObject    handle to CH_suivant_pushbutton5 (see GCBO)
935% eventdata  reserved - to be defined in a future version of MATLAB
936% handles    structure with handles and user data (see GUIDATA)
937
938% nombre max de correcteurs H + en tete popupmenu
939maxvalCH = getappdata(handles.figure1,'maxvalCH');
940
941% numero du correcteur actuellement selectionne
942valCH = getappdata(handles.figure1,'n_selection_CH');
943%selectionner dans la liste le correcteur suivant
944set(handles.CH_popupmenu2,'Value',valCH+2);
945% enregistrer la nouvelle valeur de la liste
946valCH = valCH + 1;
947setappdata(handles.figure1,'n_selection_CH',valCH);
948if valCH>=maxvalCH
949    % activer le pushbutton "correcteur precedent"
950    set(handles.CH_precedent_pushbutton4,'Enable','on');
951    % desactiver le pushbutton "correcteur suivant"
952    set(handles.CH_suivant_pushbutton5,'Enable','off');
953elseif 1>=valCH
954    % desactiver le pushbutton "correcteur precedent"
955    set(handles.CH_precedent_pushbutton4,'Enable','off');
956    % activer le pushbutton "correcteur suivant"
957    set(handles.CH_suivant_pushbutton5,'Enable','on');
958else
959    % activer le pushbutton "correcteur precedent"
960    set(handles.CH_precedent_pushbutton4,'Enable','on');
961    % activer le pushbutton "correcteur suivant"
962    set(handles.CH_suivant_pushbutton5,'Enable','on');
963end
964
965
966% afficher dans ICH_edit1 la valeur actuelle du courant du correcteur selectionne
967liste = getam('HCOR',handles.mode);
968valeur_corr = liste(valCH);
969set(handles.ICH_edit1,'String',sprintf('%3.2f',valeur_corr));
970
971% re-initaliser le slider ᅵ cette valeur de courant
972set(handles.ICH_slider1,'Value',valeur_corr);
973
974% afficher dans le text l'autre nomenclature type [cell Nᅵ HCOR]
975HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
976set(handles.HCOR_text18,'String',...
977    strcat(num2str(valCH),'   [',num2str(HCOR_liste(valCH,:)),']'));
978
979% rafraichir le BPM consecutif selectionnᅵ
980mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
981
982
983function ICH_edit1_Callback(hObject, eventdata, handles)
984% hObject    handle to ICH_edit1 (see GCBO)
985% eventdata  reserved - to be defined in a future version of MATLAB
986% handles    structure with handles and user data (see GUIDATA)
987
988% Hints: get(hObject,'String') returns contents of ICH_edit1 as text
989%        str2double(get(hObject,'String')) returns contents of ICH_edit1 as a double
990
991
992% rechercher le numero du correcteur selectionne
993valCH = getappdata(handles.figure1,'n_selection_CH');
994
995% rechercher le nom du correcteur selectionne
996%device = getappdata(handles.figure1,'device_CH');
997
998
999% appliquer le courant entrᅵ manuellement
1000HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
1001ICH = get(handles.ICH_edit1,'String');
1002setsp('HCOR',str2num(ICH),HCOR_liste(valCH,:),handles.mode);
1003
1004% re-initaliser le slider ᅵ cette valeur de courant
1005set(handles.ICH_slider1,'Value',str2num(ICH));
1006
1007% replot des orbites et point et correcteur H
1008
1009mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1010mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
1011mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1012
1013% %
1014% % k = getappdata(handles.figure1,'n_selection_BPMx');
1015% % h3     = get(handles.axes3,'Children');
1016% % hline2 = findobj(h3,'-regexp','Tag','line[1,2,3]');
1017% % h9     = get(handles.axes9,'Children');
1018% % hbar9  = findobj(h9,'-regexp','Tag','bar[1]');
1019% % %h10     = get(handles.axes10,'Children');
1020% % %hbar10  = findobj(h10,'-regexp','Tag','bar[2]');
1021% % [orbite_x,orbite_z] = getbpm;
1022% % xdata = 1:length(orbite_x);
1023% % ydata = 1:length(orbite_z);
1024% % zdata = k;
1025% %
1026% % liste_HCOR = getam('HCOR');
1027% % liste_VCOR = getam('VCOR');
1028% %
1029% % % linegraphes
1030% % set(hline2(3),'XData',xdata,'YData',orbite_x,'Visible','On');
1031% % set(hline2(2),'XData',ydata,'YData',orbite_z,'Visible','On');
1032% % set(hline2(1),'XData',zdata,'YData',orbite_x(zdata),'Visible','On');
1033% %
1034% % % bargraphes
1035% % set(hbar9(1),'YData',liste_HCOR,'Visible','On');
1036% % %set(hbar10(1),'YData',liste_VCOR,'Visible','On');
1037
1038%disp('je craque');
1039
1040
1041% --- Executes during object creation, after setting all properties.
1042function ICH_edit1_CreateFcn(hObject, eventdata, handles)
1043% hObject    handle to ICH_edit1 (see GCBO)
1044% eventdata  reserved - to be defined in a future version of MATLAB
1045% handles    empty - handles not created until after all CreateFcns called
1046
1047% Hint: edit controls usually have a white background on Windows.
1048%       See ISPC and COMPUTER.
1049if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1050    set(hObject,'BackgroundColor','white');
1051end
1052
1053
1054% --- Executes on slider movement.
1055function ICH_slider1_Callback(hObject, eventdata, handles)
1056% hObject    handle to ICH_slider1 (see GCBO)
1057% eventdata  reserved - to be defined in a future version of MATLAB
1058% handles    structure with handles and user data (see GUIDATA)
1059
1060% Hints: get(hObject,'Value') returns position of slider
1061%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
1062
1063% afficher dans l'editeur la valeur de courant
1064 set(handles.ICH_edit1,'String',...
1065             num2str(get(handles.ICH_slider1,'Value')));
1066
1067% rechercher le numero du correcteur selectionne
1068valCH = getappdata(handles.figure1,'n_selection_CH');
1069
1070% rechercher le nom du correcteur selectionne
1071%device = getappdata(handles.figure1,'device_CH');
1072
1073
1074% appliquer le courant entrᅵ manuellement
1075HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
1076ICH = get(handles.ICH_edit1,'String');
1077setsp('HCOR',str2num(ICH),HCOR_liste(valCH,:),handles.mode);
1078
1079
1080% replot des orbites et point et correcteur H
1081mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1082mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
1083mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1084
1085% % % replot des orbites et point
1086% % k = getappdata(handles.figure1,'n_selection_BPMx');
1087% % h3     = get(handles.axes3,'Children');
1088% % hline2 = findobj(h3,'-regexp','Tag','line[1,2,3]');
1089% % h9     = get(handles.axes9,'Children');
1090% % hbar9  = findobj(h9,'-regexp','Tag','bar[1]');
1091% %
1092% % % rafraichir les orbites
1093% % [orbite_x,orbite_z] = getbpm;
1094% % xdata = 1:length(orbite_x);
1095% % ydata = 1:length(orbite_z);
1096% % zdata = k;
1097% % liste_HCOR = getam('HCOR');
1098% %
1099% % set(hline2(3),'XData',xdata,'YData',orbite_x,'Visible','On');
1100% % set(hline2(2),'XData',ydata,'YData',orbite_z,'Visible','On');
1101% % set(hline2(1),'XData',zdata,'YData',orbite_x(zdata),'Visible','On');
1102% %
1103% % % bargraphes
1104% % set(hbar9(1),'YData',liste_HCOR,'Visible','On');
1105%disp('je craque')
1106
1107% --- Executes during object creation, after setting all properties.
1108function ICH_slider1_CreateFcn(hObject, eventdata, handles)
1109% hObject    handle to ICH_slider1 (see GCBO)
1110% eventdata  reserved - to be defined in a future version of MATLAB
1111% handles    empty - handles not created until after all CreateFcns called
1112
1113% Hint: slider controls usually have a light gray background.
1114if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1115    set(hObject,'BackgroundColor',[.9 .9 .9]);
1116end
1117
1118
1119
1120function fichier_sauvegarde_CH_edit13_Callback(hObject, eventdata, handles)
1121% hObject    handle to fichier_sauvegarde_CH_edit13 (see GCBO)
1122% eventdata  reserved - to be defined in a future version of MATLAB
1123% handles    structure with handles and user data (see GUIDATA)
1124
1125% Hints: get(hObject,'String') returns contents of fichier_sauvegarde_CH_edit13 as text
1126%        str2double(get(hObject,'String')) returns contents of fichier_sauvegarde_CH_edit13 as a double
1127
1128
1129
1130
1131% --- Executes during object creation, after setting all properties.
1132function fichier_sauvegarde_CH_edit13_CreateFcn(hObject, eventdata, handles)
1133% hObject    handle to fichier_sauvegarde_CH_edit13 (see GCBO)
1134% eventdata  reserved - to be defined in a future version of MATLAB
1135% handles    empty - handles not created until after all CreateFcns called
1136
1137% Hint: edit controls usually have a white background on Windows.
1138%       See ISPC and COMPUTER.
1139if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1140    set(hObject,'BackgroundColor','white');
1141end
1142
1143
1144% --- Executes on button press in sauvegarder_CH_pushbutton20.
1145function sauvegarder_CH_pushbutton20_Callback(hObject, eventdata, handles)
1146% hObject    handle to sauvegarder_CH_pushbutton20 (see GCBO)
1147% eventdata  reserved - to be defined in a future version of MATLAB
1148% handles    structure with handles and user data (see GUIDATA)
1149
1150% Determine file and directory name
1151FileName = 'H';
1152%DirectoryName = '/home/PM/nadolski/controlroom/measdata/Ringdata/';
1153DirectoryName = getfamilydata('Directory','Steerette');
1154%DirectoryName = '/home/PM/tordeux/matlab/applications/Ring/';
1155%% exemple pour le RCM : DirectoryName = getfamilydata('Directory','FAEData');
1156
1157TimeStamp = clock;
1158% Append date_Time to FileName
1159FileName = sprintf('%s_%s', datestr(TimeStamp,31), FileName);
1160FileName(11) = '_';
1161FileName(14) = '-';
1162FileName(17) = '-';
1163
1164[FileName, DirectoryName] = uiputfile('*','Save Lattice to ...', [DirectoryName FileName]);
1165if FileName == 0
1166    fprintf('   File not saved (getmachineconfig)\n');
1167    return;
1168end
1169
1170% afficher le nom du fichier
1171set(handles.fichier_sauvegarde_CH_edit13,'String',FileName);
1172
1173% Save all data in structure to file
1174
1175%DirStart = '/home/PM/nadolski/controlroom/measdata/Ringdata/'
1176DirStart = pwd;
1177[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName);
1178xdata = getam('HCOR',handles.mode);
1179% xdata = getappdata(handles.figure1,'xdata');
1180% ydata = getappdata(handles.figure1,'ydata');
1181try
1182   
1183    save(FileName, 'xdata');
1184
1185catch
1186    cd(DirStart);
1187    return
1188end
1189cd(DirStart);
1190
1191
1192% --- Executes on button press in restaurer_CH_pushbutton21.
1193function restaurer_CH_pushbutton21_Callback(hObject, eventdata, handles)
1194% hObject    handle to restaurer_CH_pushbutton21 (see GCBO)
1195% eventdata  reserved - to be defined in a future version of MATLAB
1196% handles    structure with handles and user data (see GUIDATA)
1197
1198%DirectoryName = '/home/PM/nadolski/controlroom/measdata/Ringdata/';
1199DirectoryName = getfamilydata('Directory','Steerette');
1200DirStart = pwd;
1201[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName); 
1202[FileName, DirectoryName] = uigetfile('*','Select a file ...');
1203if FileName == 0
1204    fprintf('  no File picked (getmachineconfig)\n');
1205    return;
1206else
1207    load(FileName)
1208end
1209
1210
1211% afficher
1212try
1213    setsp('HCOR',xdata,handles.mode);
1214    %setsp('VCOR',ydata);
1215   
1216   
1217catch
1218    cd(DirStart);
1219    return
1220end
1221cd(DirStart);
1222
1223
1224mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1225mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
1226mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1227
1228
1229
1230% --- Executes on button press in CH_SVD_pushbutton22.
1231function CH_SVD_pushbutton22_Callback(hObject, eventdata, handles)
1232% hObject    handle to CH_SVD_pushbutton22 (see GCBO)
1233% eventdata  reserved - to be defined in a future version of MATLAB
1234% handles    structure with handles and user data (see GUIDATA)
1235
1236
1237% nbre de correcteurs utilisï¿œs dans la correction SVD
1238nbcorrSVD = get(handles.nb_correcteurs_H_edit17,'String');
1239nbcorrSVD = str2num(nbcorrSVD);
1240
1241% relire le pourcentage ᅵ appliquer sur les valeurs de correcteurs
1242pourcentage_H = str2num(get(handles.pourcentage_H_edit16,'String'));
1243
1244% correcteur actuellement selectionnᅵ
1245valCH = getappdata(handles.figure1,'n_selection_CH');
1246%if isequal(valCH,0)|isequal(valCH,1)
1247if valCH<nbcorrSVD
1248    errordlg('selectionnez un nombre adéquat de correcteurs !','Attention');
1249    % sortir de la fonction
1250    return
1251end
1252
1253% chargement de la matrice efficacité. Son type est géré par le radiobutton
1254% "transport" "orbite fermée" :
1255% % if strcmp(handles.orbite,'transport - max Sum')
1256% %     Meff = getappdata(handles.figure1,'Meff'); % matrice d'efficacite type transport
1257% % else
1258% %     Meff = ones(120,56)*0;% introduire matrice type orbite fermée
1259% % end
1260Meff = getappdata(handles.figure1,'Meff');
1261handles.mode = getappdata(handles.figure1,'Mode');
1262handles.orbite = getappdata(handles.figure1,'Orbite');
1263BPMx = getappdata(handles.figure1,'BPMx'); % Orbit H
1264HCOR = getappdata(handles.figure1,'HCOR'); % Correcteurs H
1265
1266% enregistrement des correcteurs avant correction
1267liste = getam('HCOR',handles.mode);
1268val_corr_CH = liste(valCH-nbcorrSVD+1:valCH); % Dangerux de pas travailler sur deviceliste
1269setappdata(handles.figure1,'val_corr_CH',val_corr_CH);
1270
1271% correction SVD avec les N correcteurs et...
1272% tous les BPM compris entre depuis le valCH-N+1 correcteur et jusqu'au correcteur
1273% suivant  valCH + 1
1274
1275% on tiend compte du status du BPM, eventuellement mis ᅵ 0 pour cause de
1276% lecture non fiable, ou bien ??
1277BPMxList = getappdata(handles.figure1, 'BPMxList');
1278if 1
1279    Family = 'BPMx';
1280    FullList = family2dev(Family);
1281    i = findrowindex(BPMxList, FullList);
1282    BPMx_status = family2status(Family)*0;
1283    BPMx_status(i) = 1;
1284else
1285    BPMx_status = family2status('BPMx');
1286
1287end
1288
1289% extraire la matrice
1290% l'efficacitᅵ vis ᅵ vis d'un BPMx "inactif" est mise ᅵ 0
1291flag = 0;
1292liste_elem_BPM = [];
1293for j = 1 : length(BPMx.Position)
1294    if BPMx.Position(j)>HCOR.Position(valCH-nbcorrSVD+1)
1295        if valCH~=length(HCOR.Position)&BPMx.Position(j)>HCOR.Position(valCH+1)
1296            break
1297        end
1298        flag = flag + 1;
1299        liste_elem_BPM = [liste_elem_BPM j];
1300        Meffloc(flag,:) = Meff(j,valCH-nbcorrSVD+1:valCH) * BPMx_status(j);
1301    end
1302end
1303nbBPM  = flag;
1304% controle :
1305%Meffloc = Meffloc
1306%disp('coucou')    ;
1307
1308% correction SVD
1309liste_dev_BPM = elem2dev('BPMx',liste_elem_BPM');
1310%% tests
1311%liste_dev_BPM = liste_dev_BPM(3:4,1:2)
1312%Meffloc = Meffloc(3:4,1:2)
1313HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
1314liste_dev_HCOR = HCOR_liste(valCH-nbcorrSVD+1:valCH,:);
1315
1316%%%%
1317BPMindex = family2atindex('BPMx',liste_dev_BPM);
1318spos = getspos('BPMx');
1319
1320if strcmp(handles.mode,'Model')
1321    clear X01;
1322    %X0 = [0.5e-3 0.5e-3 1e-3 1e-3 0 0]';
1323    % gï¿œnï¿œration d'une ellipse 1 sigma ï¿œventuellement dï¿œcentrï¿œe
1324    eps = 150e-9;betax = 3 ;betaz = 3 ;alphax = 0;alphaz = 0;
1325    deltax = 2e-3;deltaz = 2e-3;deltaxp = 1e-3;deltazp = 1e-3;
1326    X0 = [sqrt(eps * betax) + deltax 0 sqrt(eps * betaz) + deltaz 0 0 0 ;...
1327        0  sqrt(eps / betax) + deltaxp 0 sqrt(eps / betaz) + deltazp 0 0 ;...
1328        -sqrt(eps * betax)+ deltax 0 -sqrt(eps * betaz)+ deltaz 0 0 0 ;...
1329        0  -sqrt(eps / betax)+deltaxp 0 -sqrt(eps / betaz)+deltazp 0 0 ]';
1330
1331    % nP = nbre de particules trackï¿œes
1332    nP = size(X0,2);
1333    setappdata(handles.figure1,'orbite_entry',X0);
1334    global THERING
1335    nbtour = 1;
1336    X01 = zeros(nbtour, 6, nP*length(BPMindex));
1337
1338    for k=1:nbtour,
1339        X01(k,:,:) = linepass(THERING, X0, BPMindex);
1340        %X0 = X01(k,:,end)';
1341    end
1342    Xa = squeeze(X01(1,1,:));
1343    %Za = squeeze(X01(1,3,:));
1344    if nP>1
1345        X = [];
1346        %Z = [];
1347        for nBPM = 1:length(BPMindex)
1348            X = [X mean(Xa((nP*(nBPM-1)+1):nP*nBPM))];
1349            %Z = [Z mean(Za((nP*(nBPM-1)+1):nP*nBPM))];
1350        end
1351        X = X'; % X en m
1352        X = X * 1000; % X en mm
1353        %Z = Z';
1354    else
1355        X = Xa; % X en m
1356        X = X * 1000; % X en mm
1357        %Z = Za;
1358    end
1359else % online
1360    if strcmp(handles.orbite,'transport - max Sum') % orbite à corriger type transport
1361        %[X] = anabpmfirstturn( BPMx.DeviceList );
1362        %[X] = anabpmfirstturn( liste_dev_BPM,'NoDisplay' ); % X en mm premier tour ANCIENNE VERSION
1363        nbturns = 1;
1364        [X Z Sum idx] = anabpmnfirstturns( liste_dev_BPM,nbturns,'NoDisplay2'); % X en mm premier tour
1365        idx
1366        X = X';
1367    elseif strcmp(handles.orbite,'transport - tour fixe') % orbite à corriger type transport
1368        ifirstturn = str2num(get(handles.tour_fixe_T_edit,'String')); % numero du premier tour
1369        nbturns = 1;
1370        X = anabpmnfirstturns( liste_dev_BPM,nbturns,ifirstturn,'NoDisplay2','NoMaxSum'); % X en mm premier tour
1371        %X = anabpmnfirstturns( liste_dev_BPM,nbturns,ifirstturn,'NoDisplay2','MaxSum'); % X en mm premier tour
1372        X = X';
1373    else
1374        % moyenne de l'orbite à corriger sur n tours
1375        ifirstturn = str2num(get(handles.tour_fixe_OF_edit,'String')); % numero du premier tour
1376        nturns = str2num(get(handles.Ntours_edit,'String'));
1377        [X] = anabpmnfirstturns(liste_dev_BPM,nturns,ifirstturn,'NoDisplay2','NoMaxSum');
1378        X = mean(X) ;% moyenne par BPM
1379        X = X'; % ?? VERIFIER
1380    end
1381end
1382%%%
1383
1384[U,S,V] = svd(Meffloc);
1385setappdata(handles.figure1,'S',S);
1386DiagS = diag(S);
1387
1388% test si le nombre de valeurs propres a ᅵtᅵ modifiᅵ dans l'interface
1389% "valeurs singuliï¿œres"
1390nbvp = getappdata(handles.figure1,'valvp');
1391
1392
1393% si le nbre n'a pas ᅵtᅵ modifiᅵ et qu'il est incompatible :
1394% if nbvp ==0||nbvp>size(S,2)
1395%     nbvp = size(S,2);
1396if nbvp ==0||nbvp>length(DiagS)
1397    nbvp = length(DiagS);   
1398end
1399% affichage
1400disp(strcat('nombre de valeurs propres sélectionnees :',num2str(nbvp)))
1401
1402%Rmod = Meffloc * V;
1403Rmod1 = Meffloc * V(:,1:nbvp);
1404%B = Rmod\ (X );
1405B1 = Rmod1\ (X ); % X en mm
1406%DeltaCM = V * B;
1407DeltaCM1 = V(:,1:nbvp) * B1;
1408consigne = getsp('HCOR',liste_dev_HCOR,handles.mode);
1409% test
1410val_max = getmaxsp('HCOR',liste_dev_HCOR);
1411val_min = getminsp('HCOR',liste_dev_HCOR);
1412if all((consigne-DeltaCM1* pourcentage_H*0.01)<val_max)*all((consigne-DeltaCM1* pourcentage_H*0.01)>val_min);
1413    stepsp('HCOR',-DeltaCM1* pourcentage_H*0.01 ,liste_dev_HCOR,handles.mode);
1414
1415    mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1416    mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
1417    mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1418   
1419
1420    % ï¿œcrire la nouvelle valeur correcteur nï¿œvalCH dans l'edit
1421    liste = getam('HCOR',handles.mode);
1422    valeur_corr = liste(valCH);
1423    set(handles.ICH_edit1,'String',sprintf('%3.2f',valeur_corr));
1424
1425    % re-initaliser le slider ï¿œ cette valeur de courant
1426    set(handles.ICH_slider1,'Value',valeur_corr);
1427
1428    disp('eh oui')
1429else
1430    consigne-DeltaCM1
1431    liste_dev_HCOR
1432    errordlg('un correcteur au moins dépasse les valeurs admises !','Attention');
1433    return
1434end
1435disp('hep !')
1436
1437% --- Executes on selection change in CV_popupmenu3.
1438function CV_popupmenu3_Callback(hObject, eventdata, handles)
1439% hObject    handle to CV_popupmenu3 (see GCBO)
1440% eventdata  reserved - to be defined in a future version of MATLAB
1441% handles    structure with handles and user data (see GUIDATA)
1442
1443% Hints: contents = get(hObject,'String') returns CV_popupmenu3 contents as cell array
1444%        contents{get(hObject,'Value')} returns selected item from CV_popupmenu3
1445
1446
1447VCOR = getappdata(handles.figure1,'VCOR');
1448% attribution du numero du correcteur (on enlï¿œve le titre)
1449valCV = get(hObject,'Value')-1;
1450% attribution du nom du device selectionne dans "device"
1451
1452switch valCV
1453    case 1
1454            %device = HCOR.DeviceName(1);
1455            % desactiver le pushbutton "correcteur precedent"
1456            set(handles.CV_precedent_pushbutton23,'Enable','off');
1457            % activer le pushbutton "correcteur suivant"
1458            set(handles.CV_suivant_pushbutton24,'Enable','on');
1459    case size(VCOR.DeviceName,1)
1460            %device = HCOR.DeviceName(size(HCOR.DeviceName,1));
1461            % activer le pushbutton "correcteur precedent"
1462            set(handles.CV_precedent_pushbutton23,'Enable','on');
1463            % desactiver le pushbutton "correcteur suivant"
1464            set(handles.CV_suivant_pushbutton24,'Enable','off');
1465end
1466
1467for k = 2:size(VCOR.DeviceName,1)-1
1468    switch valCV
1469        case k
1470            %device = HCOR.DeviceName(k);
1471            % activer le pushbutton "correcteur precedent"
1472            set(handles.CV_precedent_pushbutton23,'Enable','on');
1473            % activer le pushbutton "correcteur suivant"
1474            set(handles.CV_suivant_pushbutton24,'Enable','on');
1475    end
1476end
1477
1478
1479%disp('coucou')
1480
1481% afficher dans ICH_edit1 la valeur actuelle du courant du correcteur selectionne
1482liste = getam('VCOR',handles.mode);
1483valeur_corr = liste(valCV);
1484set(handles.ICV_edit14,'String',sprintf('%3.2f',valeur_corr));
1485
1486% re-initaliser le slider ᅵ cette valeur de courant
1487set(handles.ICV_slider2,'Value',valeur_corr);
1488
1489% afficher dans le text l'autre nomenclature type [cell Nᅵ VCOR]
1490VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1491set(handles.VCOR_text23,'String',...
1492    strcat(num2str(valCV),'   [',num2str(VCOR_liste(valCV,:)),']'));
1493
1494if valCV>0
1495    % enregistrer le numero du correcteur selectionne
1496    setappdata(handles.figure1,'n_selection_CV',valCV);
1497%     % enregistrer le nom du correcteur selectionne
1498%     setappdata(handles.figure1,'device_CH',device);
1499else
1500    % initialiser le nom du correcteur
1501    setappdata(handles.figure1,'device_CV','');
1502    % desactiver le pushbutton "correcteur precedent"
1503    set(handles.CV_precedent_pushbutton23,'Enable','off');
1504    % desactiver le pushbutton "correcteur suivant"
1505    set(handles.CV_suivant_pushbutton24,'Enable','off');
1506end
1507
1508% rafraichir le BPM consecutif selectionnᅵ
1509mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
1510
1511% % rafraichir le BPM consecutif selectionnᅵ
1512% h3     = get(handles.axes3,'Children');
1513% hline3 = findobj(h3,'-regexp','Tag','line[4]');
1514% BPMz = getappdata(handles.figure1,'BPMz');
1515% VCOR = getappdata(handles.figure1,'VCOR');
1516% valCV = getappdata(handles.figure1,'n_selection_CV');
1517% [orbite_x,orbite_z] = getbpm;
1518% if valCV>0
1519%     for k = valCV:length(BPMz.Position)
1520%         if BPMz.Position(k) > VCOR.Position(valCV)
1521%             setappdata(handles.figure1,'n_selection_BPMz',k)
1522%             set(hline3(1),'XData', k, 'YData', orbite_z(k),'Visible','On');
1523%             break
1524%         end
1525%     end
1526% end
1527
1528
1529function VCOR_text23_CreateFcn(hObject, eventdata, handles)
1530
1531
1532
1533% --- Executes during object creation, after setting all properties.
1534function CV_popupmenu3_CreateFcn(hObject, eventdata, handles)
1535% hObject    handle to CV_popupmenu3 (see GCBO)
1536% eventdata  reserved - to be defined in a future version of MATLAB
1537% handles    empty - handles not created until after all CreateFcns called
1538
1539% Hint: popupmenu controls usually have a white background on Windows.
1540%       See ISPC and COMPUTER.
1541if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1542    set(hObject,'BackgroundColor','white');
1543end
1544
1545
1546% --- Executes on button press in CV_precedent_pushbutton23.
1547function CV_precedent_pushbutton23_Callback(hObject, eventdata, handles)
1548% hObject    handle to CV_precedent_pushbutton23 (see GCBO)
1549% eventdata  reserved - to be defined in a future version of MATLAB
1550% handles    structure with handles and user data (see GUIDATA)
1551
1552% nombre max de correcteurs V
1553maxvalCV = getappdata(handles.figure1,'maxvalCV');
1554
1555% numero du correcteur actuellement selectionne
1556valCV = getappdata(handles.figure1,'n_selection_CV');
1557%selectionner dans la liste le correcteur precedent
1558set(handles.CV_popupmenu3,'Value',valCV);
1559% enregistrer le nouveau numero de correcteur de la liste
1560valCV = valCV - 1;
1561setappdata(handles.figure1,'n_selection_CV',valCV);
1562% enregistrer le correcteur
1563%setappdata(handles.figure1,'
1564
1565if valCV>=maxvalCV
1566    % activer le pushbutton "correcteur precedent"
1567    set(handles.CV_precedent_pushbutton23,'Enable','on');
1568    % desactiver le pushbutton "correcteur suivant"
1569    set(handles.CV_suivant_pushbutton24,'Enable','off');
1570elseif 1>=valCV
1571    % desactiver le pushbutton "correcteur precedent"
1572    set(handles.CV_precedent_pushbutton23,'Enable','off');
1573    % activer le pushbutton "correcteur suivant"
1574    set(handles.CV_suivant_pushbutton24,'Enable','on');
1575else
1576    % activer le pushbutton "correcteur precedent"
1577    set(handles.CV_precedent_pushbutton23,'Enable','on');
1578    % activer le pushbutton "correcteur suivant"
1579    set(handles.CV_suivant_pushbutton24,'Enable','on');
1580end
1581
1582
1583% afficher dans ICV_edit14 la valeur actuelle du courant du correcteur selectionne
1584liste = getam('VCOR',handles.mode);
1585valeur_corr = liste(valCV);
1586set(handles.ICV_edit14,'String',sprintf('%3.2f',valeur_corr));
1587
1588% re-initaliser le slider ᅵ cette valeur de courant
1589set(handles.ICV_slider2,'Value',valeur_corr);
1590
1591% afficher dans le text l'autre nomenclature type [cell Nᅵ VCOR]
1592VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1593set(handles.VCOR_text23,'String',...
1594    strcat(num2str(valCV),'   [',num2str(VCOR_liste(valCV,:)),']'));
1595
1596% rafraichir le BPM consecutif selectionnᅵ
1597mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
1598
1599% % % rafraichir le BPM consecutif selectionnᅵ
1600% % h3     = get(handles.axes3,'Children');
1601% % hline3 = findobj(h3,'-regexp','Tag','line[4]');
1602% % BPMz = getappdata(handles.figure1,'BPMz');
1603% % VCOR = getappdata(handles.figure1,'VCOR');
1604% % valCV = getappdata(handles.figure1,'n_selection_CV');
1605% % [orbite_x,orbite_z] = getbpm;
1606% % if valCV>0
1607% %     for k = valCV:length(BPMz.Position)
1608% %         if BPMz.Position(k) > VCOR.Position(valCV)
1609% %             setappdata(handles.figure1,'n_selection_BPMz',k)
1610% %             set(hline3(1),'XData', k, 'YData', orbite_z(k),'Visible','On');
1611% %             break
1612% %         end
1613% %     end
1614% % end
1615
1616
1617% --- Executes on button press in CV_suivant_pushbutton24.
1618function CV_suivant_pushbutton24_Callback(hObject, eventdata, handles)
1619% hObject    handle to CV_suivant_pushbutton24 (see GCBO)
1620% eventdata  reserved - to be defined in a future version of MATLAB
1621% handles    structure with handles and user data (see GUIDATA)
1622
1623% nombre max de correcteurs V + en tete popupmenu
1624maxvalCV = getappdata(handles.figure1,'maxvalCV');
1625
1626% numero du correcteur actuellement selectionne
1627valCV = getappdata(handles.figure1,'n_selection_CV');
1628%selectionner dans la liste le correcteur suivant
1629set(handles.CV_popupmenu3,'Value',valCV+2);
1630% enregistrer la nouvelle valeur de la liste
1631valCV = valCV + 1;
1632setappdata(handles.figure1,'n_selection_CV',valCV);
1633if valCV>=maxvalCV
1634    % activer le pushbutton "correcteur precedent"
1635    set(handles.CV_precedent_pushbutton23,'Enable','on');
1636    % desactiver le pushbutton "correcteur suivant"
1637    set(handles.CV_suivant_pushbutton24,'Enable','off');
1638elseif 1>=valCV
1639    % desactiver le pushbutton "correcteur precedent"
1640    set(handles.CV_precedent_pushbutton23,'Enable','off');
1641    % activer le pushbutton "correcteur suivant"
1642    set(handles.CV_suivant_pushbutton24,'Enable','on');
1643else
1644    % activer le pushbutton "correcteur precedent"
1645    set(handles.CV_precedent_pushbutton23,'Enable','on');
1646    % activer le pushbutton "correcteur suivant"
1647    set(handles.CV_suivant_pushbutton24,'Enable','on');
1648end
1649
1650
1651% afficher dans ICV_edit14 la valeur actuelle du courant du correcteur selectionne
1652liste = getam('VCOR',handles.mode);
1653valeur_corr = liste(valCV);
1654set(handles.ICV_edit14,'String',sprintf('%3.2f',valeur_corr));
1655
1656% re-initaliser le slider ᅵ cette valeur de courant
1657set(handles.ICV_slider2,'Value',valeur_corr);
1658
1659% afficher dans le text l'autre nomenclature type [cell Nᅵ VCOR]
1660VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1661set(handles.VCOR_text23,'String',...
1662    strcat(num2str(valCV),'   [',num2str(VCOR_liste(valCV,:)),']'));
1663
1664% rafraichir le BPM consecutif selectionnᅵ
1665mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
1666
1667% % rafraichir le BPM consecutif selectionnᅵ
1668% h3     = get(handles.axes3,'Children');
1669% hline3 = findobj(h3,'-regexp','Tag','line[4]');
1670% BPMz = getappdata(handles.figure1,'BPMz');
1671% VCOR = getappdata(handles.figure1,'VCOR');
1672% valCV = getappdata(handles.figure1,'n_selection_CV');
1673% [orbite_x,orbite_z] = getbpm;
1674% if valCV>0
1675%     for k = valCV:length(BPMz.Position)
1676%         if BPMz.Position(k) > VCOR.Position(valCV)
1677%             setappdata(handles.figure1,'n_selection_BPMz',k)
1678%             set(hline3(1),'XData', k, 'YData', orbite_z(k),'Visible','On');
1679%             break
1680%         end
1681%     end
1682% end
1683
1684
1685function ICV_edit14_Callback(hObject, eventdata, handles)
1686% hObject    handle to ICV_edit14 (see GCBO)
1687% eventdata  reserved - to be defined in a future version of MATLAB
1688% handles    structure with handles and user data (see GUIDATA)
1689
1690% Hints: get(hObject,'String') returns contents of ICV_edit14 as text
1691%        str2double(get(hObject,'String')) returns contents of ICV_edit14 as a double
1692
1693
1694% rechercher le numero du correcteur selectionne
1695valCV = getappdata(handles.figure1,'n_selection_CV');
1696
1697% rechercher le nom du correcteur selectionne
1698%device = getappdata(handles.figure1,'device_CV');
1699
1700
1701% appliquer le courant entrᅵ manuellement
1702VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1703ICV = get(handles.ICV_edit14,'String');
1704setsp('VCOR',str2num(ICV),VCOR_liste(valCV,:),handles.mode)
1705
1706% re-initaliser le slider ᅵ cette valeur de courant
1707set(handles.ICV_slider2,'Value',str2num(ICV));
1708
1709% replot des orbites et point et correcteur V
1710
1711mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1712mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
1713mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1714% k = getappdata(handles.figure1,'n_selection_BPMz');
1715% h3     = get(handles.axes3,'Children');
1716% hline2 = findobj(h3,'-regexp','Tag','line[1,2,4]');
1717% % h9     = get(handles.axes9,'Children');
1718% % hbar9  = findobj(h9,'-regexp','Tag','bar[1]');
1719% h10     = get(handles.axes10,'Children');
1720% hbar10  = findobj(h10,'-regexp','Tag','bar[2]');
1721% [orbite_x,orbite_z] = getbpm;
1722% xdata = 1:length(orbite_x);
1723% ydata = 1:length(orbite_z);
1724% zdata = k;
1725%
1726% liste_HCOR = getam('HCOR');
1727% liste_VCOR = getam('VCOR');
1728%
1729% % linegraphes
1730% set(hline2(3),'XData',xdata,'YData',orbite_x,'Visible','On');
1731% set(hline2(2),'XData',ydata,'YData',orbite_z,'Visible','On');
1732% set(hline2(1),'XData',zdata,'YData',orbite_z(zdata),'Visible','On');
1733%
1734%
1735% % bargraphes
1736% %set(hbar9(1),'YData',liste_HCOR,'Visible','On');
1737% set(hbar10(1),'YData',liste_VCOR,'Visible','On');
1738
1739%disp('je craque');
1740
1741% --- Executes during object creation, after setting all properties.
1742function ICV_edit14_CreateFcn(hObject, eventdata, handles)
1743% hObject    handle to ICV_edit14 (see GCBO)
1744% eventdata  reserved - to be defined in a future version of MATLAB
1745% handles    empty - handles not created until after all CreateFcns called
1746
1747% Hint: edit controls usually have a white background on Windows.
1748%       See ISPC and COMPUTER.
1749if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1750    set(hObject,'BackgroundColor','white');
1751end
1752
1753
1754% --- Executes on slider movement.
1755function ICV_slider2_Callback(hObject, eventdata, handles)
1756% hObject    handle to ICV_slider2 (see GCBO)
1757% eventdata  reserved - to be defined in a future version of MATLAB
1758% handles    structure with handles and user data (see GUIDATA)
1759
1760% Hints: get(hObject,'Value') returns position of slider
1761%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
1762
1763% afficher dans l'editeur la valeur de courant
1764 set(handles.ICV_edit14,'String',...
1765             num2str(get(handles.ICV_slider2,'Value')));
1766
1767% rechercher le numero du correcteur selectionne
1768valCV = getappdata(handles.figure1,'n_selection_CV');
1769
1770% rechercher le nom du correcteur selectionne
1771%device = getappdata(handles.figure1,'device_CV');
1772
1773
1774% appliquer le courant entrᅵ manuellement
1775VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1776ICV = get(handles.ICV_edit14,'String');
1777setsp('VCOR',str2num(ICV),VCOR_liste(valCV,:),handles.mode);
1778
1779% replot des orbites et point et correcteur V
1780
1781mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
1782mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
1783mycallback_steerette_corr(1,1,hObject, eventdata, handles)
1784
1785% % replot des orbites et point
1786% k = getappdata(handles.figure1,'n_selection_BPMz');
1787% h3     = get(handles.axes3,'Children');
1788% hline2 = findobj(h3,'-regexp','Tag','line[1,2,4]');
1789% h10     = get(handles.axes10,'Children');
1790% hbar10  = findobj(h10,'-regexp','Tag','bar[2]');
1791%
1792% % rafraichir les orbites
1793% [orbite_x,orbite_z] = getbpm;
1794% xdata = 1:length(orbite_x);
1795% ydata = 1:length(orbite_z);
1796% zdata = k;
1797% liste_VCOR = getam('VCOR');
1798%
1799% set(hline2(3),'XData',xdata,'YData',orbite_x,'Visible','On');
1800% set(hline2(2),'XData',ydata,'YData',orbite_z,'Visible','On');
1801% set(hline2(1),'XData',zdata,'YData',orbite_z(zdata),'Visible','On');
1802%
1803% % bargraphes
1804% set(hbar10(1),'YData',liste_VCOR,'Visible','On');
1805% %disp('je craque')
1806
1807
1808
1809% --- Executes during object creation, after setting all properties.
1810function ICV_slider2_CreateFcn(hObject, eventdata, handles)
1811% hObject    handle to ICV_slider2 (see GCBO)
1812% eventdata  reserved - to be defined in a future version of MATLAB
1813% handles    empty - handles not created until after all CreateFcns called
1814
1815% Hint: slider controls usually have a light gray background.
1816if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1817    set(hObject,'BackgroundColor',[.9 .9 .9]);
1818end
1819
1820
1821
1822function fichier_sauvegarde_CV_edit15_Callback(hObject, eventdata, handles)
1823% hObject    handle to fichier_sauvegarde_CV_edit15 (see GCBO)
1824% eventdata  reserved - to be defined in a future version of MATLAB
1825% handles    structure with handles and user data (see GUIDATA)
1826
1827% Hints: get(hObject,'String') returns contents of fichier_sauvegarde_CV_edit15 as text
1828%        str2double(get(hObject,'String')) returns contents of fichier_sauvegarde_CV_edit15 as a double
1829
1830
1831% --- Executes during object creation, after setting all properties.
1832function fichier_sauvegarde_CV_edit15_CreateFcn(hObject, eventdata, handles)
1833% hObject    handle to fichier_sauvegarde_CV_edit15 (see GCBO)
1834% eventdata  reserved - to be defined in a future version of MATLAB
1835% handles    empty - handles not created until after all CreateFcns called
1836
1837% Hint: edit controls usually have a white background on Windows.
1838%       See ISPC and COMPUTER.
1839if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1840    set(hObject,'BackgroundColor','white');
1841end
1842
1843
1844% --- Executes on button press in sauvegarder_CV_pushbutton25.
1845function sauvegarder_CV_pushbutton25_Callback(hObject, eventdata, handles)
1846% hObject    handle to sauvegarder_CV_pushbutton25 (see GCBO)
1847% eventdata  reserved - to be defined in a future version of MATLAB
1848% handles    structure with handles and user data (see GUIDATA)
1849
1850
1851% Determine file and directory name
1852
1853FileName = 'V';
1854DirectoryName = getfamilydata('Directory','Steerette');
1855TimeStamp = clock;
1856% Append date_Time to FileName
1857FileName = sprintf('%s_%s', datestr(TimeStamp,31), FileName);
1858FileName(11) = '_';
1859FileName(14) = '-';
1860FileName(17) = '-';
1861
1862[FileName, DirectoryName] = uiputfile('*','Save Lattice to ...', [DirectoryName FileName]);
1863if FileName == 0
1864    fprintf('   File not saved (getmachineconfig)\n');
1865    return;
1866end
1867
1868% afficher le nom du fichier
1869set(handles.fichier_sauvegarde_CV_edit15,'String',FileName);
1870
1871% Save all data in structure to file
1872
1873%DirStart = '/home/PM/nadolski/controlroom/measdata/Ringdata/'
1874DirStart = pwd;
1875[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName);
1876ydata = getam('VCOR',handles.mode);
1877% xdata = getappdata(handles.figure1,'xdata');
1878% ydata = getappdata(handles.figure1,'ydata');
1879try
1880   
1881    save(FileName, 'ydata');
1882
1883catch
1884    cd(DirStart);
1885    return
1886end
1887cd(DirStart);
1888
1889
1890% --- Executes on button press in restaurer_CV_pushbutton26.
1891function restaurer_CV_pushbutton26_Callback(hObject, eventdata, handles)
1892% hObject    handle to restaurer_CV_pushbutton26 (see GCBO)
1893% eventdata  reserved - to be defined in a future version of MATLAB
1894% handles    structure with handles and user data (see GUIDATA)
1895
1896
1897DirectoryName = getfamilydata('Directory','Steerette');
1898DirStart = pwd;
1899[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName); 
1900[FileName, DirectoryName] = uigetfile('*','Select a file ...');
1901if FileName == 0
1902    fprintf('  no File picked (getmachineconfig)\n');
1903    return;
1904else
1905    load(FileName)
1906end
1907
1908
1909
1910% afficher
1911try
1912    %setsp('HCOR',xdata);
1913    setsp('VCOR',ydata,handles.mode);
1914   
1915   
1916catch
1917    cd(DirStart);
1918    return
1919end
1920cd(DirStart);
1921
1922
1923% --- Executes on button press in CV_SVD_pushbutton.
1924function CV_SVD_pushbutton_Callback(hObject, eventdata, handles)
1925% hObject    handle to CV_SVD_pushbutton (see GCBO)
1926% eventdata  reserved - to be defined in a future version of MATLAB
1927% handles    structure with handles and user data (see GUIDATA)
1928
1929% nbre de correcteurs utilisï¿œs dans la correction SVD
1930nbcorrSVD_V = get(handles.nb_correcteurs_V_edit,'String');
1931nbcorrSVD_V = str2num(nbcorrSVD_V);
1932
1933% relire le pourcentage ᅵ appliquer sur les valeurs de correcteurs
1934pourcentage_V = str2num(get(handles.pourcentage_V_edit,'String'));
1935
1936% correcteur actuellement selectionnᅵ
1937valCV = getappdata(handles.figure1,'n_selection_CV');
1938%if isequal(valCV,0)|isequal(valCV,1)
1939if valCV<nbcorrSVD_V
1940    errordlg('selectionnez un nombre adï¿œquat de correcteurs !','Attention');
1941    % sortir de la fonction
1942    return
1943end
1944
1945Meff_V = getappdata(handles.figure1,'Meff_V');
1946BPMz = getappdata(handles.figure1,'BPMz');
1947VCOR = getappdata(handles.figure1,'VCOR');
1948
1949% enregistrement des correcteurs avant correction
1950liste = getam('VCOR',handles.mode);
1951val_corr_CV = liste(valCV-nbcorrSVD_V+1:valCV);
1952setappdata(handles.figure1,'val_corr_CV',val_corr_CV);
1953
1954% correction SVD avec les N correcteurs et...
1955% tous les BPM compris entre depuis le valCV-N+1 correcteur et jusqu'au correcteur
1956% suivant  valCV + 1
1957
1958% on tiend compte du status du BPM, eventuellement mis ᅵ 0 pour cause de
1959% lecture non fiable, ou bien ??
1960BPMz_status = family2status('BPMz');
1961
1962% extraire la matrice
1963% l'efficacitᅵ vis ᅵ vis d'un BPMz "inactif" est mise ᅵ 0
1964flag = 0;
1965liste_elem_BPM = [];
1966for j = 1 : length(BPMz.Position)
1967    if BPMz.Position(j)>VCOR.Position(valCV-nbcorrSVD_V+1)
1968        if valCV < length(VCOR.Position)
1969            if valCV~=length(VCOR.Position)&BPMz.Position(j)>VCOR.Position(valCV+1)
1970                break
1971            end
1972        end
1973       
1974        flag = flag + 1;
1975        liste_elem_BPM = [liste_elem_BPM j];
1976        Meffloc_V(flag,:) = Meff_V(j,valCV-nbcorrSVD_V+1:valCV) * BPMz_status(j);
1977    end
1978end
1979nbBPM  = flag;
1980
1981% correction SVD
1982liste_dev_BPM = elem2dev('BPMz',liste_elem_BPM');
1983%% tests
1984%liste_dev_BPM = liste_dev_BPM(3:4,1:2)
1985%Meffloc = Meffloc(3:4,1:2)
1986VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
1987liste_dev_VCOR = VCOR_liste(valCV-nbcorrSVD_V+1:valCV,:);
1988
1989%%%%
1990BPMindex = family2atindex('BPMz',liste_dev_BPM);
1991spos = getspos('BPMz');
1992
1993if strcmp(handles.mode,'Model')
1994    clear X01;
1995    %X0 = [0.5e-3 0.5e-3 1e-3 1e-3 0 0]';
1996    % gï¿œnï¿œration d'une ellipse 1 sigma ï¿œventuellement dï¿œcentrï¿œe
1997    eps = 150e-9;betax = 3 ;betaz = 3 ;alphax = 0;alphaz = 0;
1998    deltax = 2e-3;deltaz = 2e-3;deltaxp = 1e-3;deltazp = 1e-3;
1999    X0 = [sqrt(eps * betax) + deltax 0 sqrt(eps * betaz) + deltaz 0 0 0 ;...
2000        0  sqrt(eps / betax) + deltaxp 0 sqrt(eps / betaz) + deltazp 0 0 ;...
2001        -sqrt(eps * betax)+ deltax 0 -sqrt(eps * betaz)+ deltaz 0 0 0 ;...
2002        0  -sqrt(eps / betax)+deltaxp 0 -sqrt(eps / betaz)+deltazp 0 0 ]';
2003
2004    % nP = nbre de particules trackï¿œes
2005    nP = size(X0,2);
2006    setappdata(handles.figure1,'orbite_entry',X0);
2007    global THERING
2008    nbtour = 1;
2009    X01 = zeros(nbtour, 6, nP*length(BPMindex));
2010
2011    for k=1:nbtour,
2012        X01(k,:,:) = linepass(THERING, X0, BPMindex);
2013        %X0 = X01(k,:,end)';
2014    end
2015    %Xa = squeeze(X01(1,1,:));
2016    Za = squeeze(X01(1,3,:));
2017    if nP>1
2018        %X = [];
2019        Z = [];
2020        for nBPM = 1:length(BPMindex)
2021            %X = [X mean(Xa((nP*(nBPM-1)+1):nP*nBPM))];
2022            Z = [Z mean(Za((nP*(nBPM-1)+1):nP*nBPM))];
2023        end
2024        %X = X';
2025        Z = Z';
2026        Z = Z * 1000; % z en mm
2027    else
2028        %X = Xa;
2029        Z = Za;
2030        Z = Z * 1000; % z en mm
2031    end
2032else % online
2033
2034    %[X Z] = anabpmfirstturn( liste_dev_BPM,'NoDisplay' ); % ancienne version
2035    %Z = Z';
2036    if strcmp(handles.orbite,'transport - max Sum') % orbite à corriger type transport
2037        %[X] = anabpmfirstturn( BPMx.DeviceList );
2038        %[X] = anabpmfirstturn( liste_dev_BPM,'NoDisplay' ); % X en mm premier tour ANCIENNE VERSION
2039        nbturns = 1;
2040        [X Z Sum idx] = anabpmnfirstturns( liste_dev_BPM,nbturns,'NoDisplay2'); % X en mm premier tour
2041        idx
2042        Z = Z';
2043    elseif strcmp(handles.orbite,'transport - tour fixe') % orbite à corriger type transport
2044        ifirstturn = str2num(get(handles.tour_fixe_T_edit,'String')); % numero du premier tour
2045        nbturns = 1;
2046        [X Z] = anabpmnfirstturns( liste_dev_BPM,nbturns,ifirstturn,'NoDisplay2','NoMaxSum'); % X en mm premier tour
2047        Z = Z';
2048    else
2049        % moyenne de l'orbite à corriger sur n tours
2050        ifirstturn = str2num(get(handles.tour_fixe_OF_edit,'String')); % numero du premier tour
2051        nturns = str2num(get(handles.Ntours_edit,'String'));
2052        [X Z] = anabpmnfirstturns(liste_dev_BPM,nturns,ifirstturn,'NoDisplay2','NoMaxSum');
2053        Z = mean(Z) ;% moyenne par BPM
2054        Z = Z'; % ?? VERIFIER
2055    end
2056end
2057%%%
2058
2059% hcm = getsp('VCOR',liste_dev_VCOR,'struct');
2060[U,S_V,V] = svd(Meffloc_V);
2061setappdata(handles.figure1,'S_V',S_V);
2062DiagS_V = diag(S_V);
2063
2064% test si le nombre de valeurs propres a ᅵtᅵ modifiᅵ dans l'interface
2065% "valeurs singuliï¿œres"
2066nbvp_V = getappdata(handles.figure1,'valvp_V');
2067
2068
2069% si le nbre n'a pas ᅵtᅵ modifiᅵ et qu'il est incompatible :
2070if nbvp_V ==0||nbvp_V>length(DiagS_V)
2071    nbvp_V = length(DiagS_V);
2072end
2073% affichage
2074disp(strcat('nombre de valeurs propres sélectionnées :',num2str(nbvp_V)))
2075
2076
2077Rmod1 = Meffloc_V * V(:,1:nbvp_V);
2078B1 = Rmod1\ (Z ); % Z en mm
2079DeltaCM1_V = V(:,1:nbvp_V) * B1;
2080consigne = getsp('VCOR',liste_dev_VCOR,handles.mode);
2081% test
2082val_max = getmaxsp('VCOR',liste_dev_VCOR);
2083val_min = getminsp('VCOR',liste_dev_VCOR);
2084if all((consigne-DeltaCM1_V* pourcentage_V*0.01)<val_max)*all((consigne-DeltaCM1_V* pourcentage_V*0.01)>val_min);
2085    stepsp('VCOR',-DeltaCM1_V* pourcentage_V*0.01 ,liste_dev_VCOR,handles.mode);
2086
2087
2088    mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
2089    mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
2090    mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2091   
2092
2093    % ï¿œcrire la nouvelle valeur correcteur nï¿œvalCV dans l'edit
2094    liste = getam('VCOR',handles.mode);
2095    valeur_corr = liste(valCV);
2096    set(handles.ICV_edit14,'String',sprintf('%3.2f',valeur_corr));
2097
2098    % re-initaliser le slider ï¿œ cette valeur de courant
2099    set(handles.ICV_slider2,'Value',valeur_corr);
2100
2101    disp('eh oui')
2102else
2103    consigne-DeltaCM1_V
2104    liste_dev_VCOR
2105    errordlg('un correcteur au moins dépasse les valeurs admises !','Attention');
2106    return
2107end
2108
2109
2110% --- Executes on button press in Undo_H_pushbutton28.
2111function Undo_H_pushbutton28_Callback(hObject, eventdata, handles)
2112% hObject    handle to Undo_H_pushbutton28 (see GCBO)
2113% eventdata  reserved - to be defined in a future version of MATLAB
2114% handles    structure with handles and user data (see GUIDATA)
2115
2116% rechercher le numero du correcteur selectionne
2117valCH = getappdata(handles.figure1,'n_selection_CH');
2118val_corr_CH = getappdata(handles.figure1,'val_corr_CH');
2119
2120% appliquer les courants precedant la correction SVD
2121HCOR_liste = getappdata(handles.figure1,'HCOR_liste');
2122setsp('HCOR',val_corr_CH,HCOR_liste(valCH-size(val_corr_CH,1)+1:valCH,:),handles.mode)
2123
2124% ï¿œcrire l'ancienne valeur correcteur nï¿œvalCH dans l'edit
2125liste = getam('HCOR',handles.mode);
2126valeur_corr = liste(valCH);
2127set(handles.ICH_edit1,'String',sprintf('%3.2f',valeur_corr));
2128
2129% re-initaliser le slider ᅵ cette valeur de courant
2130set(handles.ICH_slider1,'Value',valeur_corr);
2131
2132disp('nous y re-voilᅵ')
2133
2134% replot des orbites et point et correcteur H
2135
2136mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
2137mycallback_steerette_point_H(1,1,hObject, eventdata, handles)
2138mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2139
2140
2141
2142function pourcentage_H_edit16_Callback(hObject, eventdata, handles)
2143% hObject    handle to pourcentage_H_edit16 (see GCBO)
2144% eventdata  reserved - to be defined in a future version of MATLAB
2145% handles    structure with handles and user data (see GUIDATA)
2146
2147% Hints: get(hObject,'String') returns contents of pourcentage_H_edit16 as text
2148%        str2double(get(hObject,'String')) returns contents of pourcentage_H_edit16 as a double
2149
2150
2151% --- Executes during object creation, after setting all properties.
2152function pourcentage_H_edit16_CreateFcn(hObject, eventdata, handles)
2153% hObject    handle to pourcentage_H_edit16 (see GCBO)
2154% eventdata  reserved - to be defined in a future version of MATLAB
2155% handles    empty - handles not created until after all CreateFcns called
2156
2157% Hint: edit controls usually have a white background on Windows.
2158%       See ISPC and COMPUTER.
2159if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2160    set(hObject,'BackgroundColor','white');
2161end
2162
2163
2164
2165function nb_correcteurs_H_edit17_Callback(hObject, eventdata, handles)
2166% hObject    handle to nb_correcteurs_H_edit17 (see GCBO)
2167% eventdata  reserved - to be defined in a future version of MATLAB
2168% handles    structure with handles and user data (see GUIDATA)
2169
2170% Hints: get(hObject,'String') returns contents of nb_correcteurs_H_edit17 as text
2171%        str2double(get(hObject,'String')) returns contents of nb_correcteurs_H_edit17 as a double
2172
2173
2174% --- Executes during object creation, after setting all properties.
2175function nb_correcteurs_H_edit17_CreateFcn(hObject, eventdata, handles)
2176% hObject    handle to nb_correcteurs_H_edit17 (see GCBO)
2177% eventdata  reserved - to be defined in a future version of MATLAB
2178% handles    empty - handles not created until after all CreateFcns called
2179
2180% Hint: edit controls usually have a white background on Windows.
2181%       See ISPC and COMPUTER.
2182if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2183    set(hObject,'BackgroundColor','white');
2184end
2185
2186
2187% --- Executes on button press in valeurs_singulieres_H_pushbutton29.
2188function valeurs_singulieres_H_pushbutton29_Callback(hObject, eventdata, handles)
2189% hObject    handle to valeurs_singulieres_H_pushbutton29 (see GCBO)
2190% eventdata  reserved - to be defined in a future version of MATLAB
2191% handles    structure with handles and user data (see GUIDATA)
2192
2193correction_tour1_singval(handles);
2194
2195
2196% --- Executes on button press in Undo_V_pushbutton.
2197function Undo_V_pushbutton_Callback(hObject, eventdata, handles)
2198% hObject    handle to Undo_V_pushbutton (see GCBO)
2199% eventdata  reserved - to be defined in a future version of MATLAB
2200% handles    structure with handles and user data (see GUIDATA)
2201
2202% rechercher le numero du correcteur selectionne
2203valCV = getappdata(handles.figure1,'n_selection_CV');
2204val_corr_CV = getappdata(handles.figure1,'val_corr_CV');
2205
2206% appliquer les courants precedant la correction SVD
2207VCOR_liste = getappdata(handles.figure1,'VCOR_liste');
2208setsp('VCOR',val_corr_CV,VCOR_liste(valCV-size(val_corr_CV,1)+1:valCV,:),handles.mode)
2209
2210% ï¿œcrire l'ancienne valeur correcteur nï¿œvalCH dans l'edit
2211liste = getam('VCOR',handles.mode);
2212valeur_corr = liste(valCV);
2213set(handles.ICV_edit14,'String',sprintf('%3.2f',valeur_corr));
2214
2215% re-initaliser le slider ᅵ cette valeur de courant
2216set(handles.ICV_slider2,'Value',valeur_corr);
2217
2218disp('nous y re-voilᅵ')
2219
2220% replot des orbites et point et correcteur H
2221
2222mycallback_steerette_orbites(1,1,hObject, eventdata, handles)
2223mycallback_steerette_point_V(1,1,hObject, eventdata, handles)
2224mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2225
2226
2227function pourcentage_V_edit_Callback(hObject, eventdata, handles)
2228% hObject    handle to pourcentage_V_edit (see GCBO)
2229% eventdata  reserved - to be defined in a future version of MATLAB
2230% handles    structure with handles and user data (see GUIDATA)
2231
2232% Hints: get(hObject,'String') returns contents of pourcentage_V_edit as text
2233%        str2double(get(hObject,'String')) returns contents of pourcentage_V_edit as a double
2234
2235
2236% --- Executes during object creation, after setting all properties.
2237function pourcentage_V_edit_CreateFcn(hObject, eventdata, handles)
2238% hObject    handle to pourcentage_V_edit (see GCBO)
2239% eventdata  reserved - to be defined in a future version of MATLAB
2240% handles    empty - handles not created until after all CreateFcns called
2241
2242% Hint: edit controls usually have a white background on Windows.
2243%       See ISPC and COMPUTER.
2244if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2245    set(hObject,'BackgroundColor','white');
2246end
2247
2248
2249
2250function nb_correcteurs_V_edit_Callback(hObject, eventdata, handles)
2251% hObject    handle to nb_correcteurs_V_edit (see GCBO)
2252% eventdata  reserved - to be defined in a future version of MATLAB
2253% handles    structure with handles and user data (see GUIDATA)
2254
2255% Hints: get(hObject,'String') returns contents of nb_correcteurs_V_edit as text
2256%        str2double(get(hObject,'String')) returns contents of nb_correcteurs_V_edit as a double
2257
2258
2259% --- Executes during object creation, after setting all properties.
2260function nb_correcteurs_V_edit_CreateFcn(hObject, eventdata, handles)
2261% hObject    handle to nb_correcteurs_V_edit (see GCBO)
2262% eventdata  reserved - to be defined in a future version of MATLAB
2263% handles    empty - handles not created until after all CreateFcns called
2264
2265% Hint: edit controls usually have a white background on Windows.
2266%       See ISPC and COMPUTER.
2267if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2268    set(hObject,'BackgroundColor','white');
2269end
2270
2271
2272% --- Executes on button press in valeurs_singulieres_V_pushbutton.
2273function valeurs_singulieres_V_pushbutton_Callback(hObject, eventdata, handles)
2274% hObject    handle to valeurs_singulieres_V_pushbutton (see GCBO)
2275% eventdata  reserved - to be defined in a future version of MATLAB
2276% handles    structure with handles and user data (see GUIDATA)
2277
2278%correction_tour1_singval_V(handles);
2279essai_V(handles);
2280
2281
2282%% What to do before closing the application
2283function Closinggui(obj, event, handles, figure1)
2284
2285%device_name = getappdata(handles.figure1,'device_name');
2286
2287% Get default command line output from handles structure
2288answer = questdlg('Fermer Steerette ?',...
2289    'Exit Programme Steerette',...
2290    'Yes','No','Yes');
2291
2292switch answer
2293    case 'Yes'           
2294        delete(handles); %Delete Timer       
2295        delete(figure1); %Close gui
2296        %% extraire l'écran YAG
2297        %tango_command_inout(device_name.ecran,'Extract');
2298        %fonction_error;
2299    otherwise
2300        disp('Closing aborted')
2301end
2302
2303
2304% --------------------------------------------------------------------
2305function menu_BPMx_Callback(hObject, eventdata, handles)
2306% hObject    handle to menu_BPMx (see GCBO)
2307% eventdata  reserved - to be defined in a future version of MATLAB
2308% handles    structure with handles and user data (see GUIDATA)
2309
2310%% Build List display
2311Family = 'BPMx';
2312List = getappdata(handles.figure1, 'BPMxList');
2313FullList = family2dev(Family,0);    % Include bad status
2314CheckList = zeros(size(FullList,1),1);
2315i = findrowindex(List, FullList); % Find all selected Devices
2316CheckList(i) = 1;
2317List = editlist(FullList, Family, CheckList);
2318List = intersect(List,family2dev(Family,1)); % Exclude bad status
2319setappdata(handles.figure1, 'BPMxList', List);
2320
2321
2322% --------------------------------------------------------------------
2323function Untitled_2_Callback(hObject, eventdata, handles)
2324% hObject    handle to Untitled_2 (see GCBO)
2325% eventdata  reserved - to be defined in a future version of MATLAB
2326% handles    structure with handles and user data (see GUIDATA)
2327
2328
2329% --------------------------------------------------------------------
2330function menu_BPMz_Callback(hObject, eventdata, handles)
2331% hObject    handle to menu_BPMz (see GCBO)
2332% eventdata  reserved - to be defined in a future version of MATLAB
2333% handles    structure with handles and user data (see GUIDATA)
2334
2335%% Build List display
2336Family = 'BPMz';
2337List = getappdata(handles.figure1, 'BPMzList');
2338FullList = family2dev(Family,0);    % Include bad status
2339CheckList = zeros(size(FullList,1),1);
2340i = findrowindex(List, FullList); % Find all selected Devices
2341CheckList(i) = 1;
2342List = editlist(FullList, Family, CheckList);
2343List = intersect(List,family2dev(Family,1)); % Exclude bad status
2344setappdata(handles.figure1, 'BPMzList', List);
2345
2346
2347% --- Executes on button press in SVD_H_PR_pushbutton.
2348function SVD_H_PR_pushbutton_Callback(hObject, eventdata, handles)
2349% hObject    handle to SVD_H_PR_pushbutton (see GCBO)
2350% eventdata  reserved - to be defined in a future version of MATLAB
2351% handles    structure with handles and user data (see GUIDATA)
2352
2353% relire le pourcentage ᅵ appliquer sur les valeurs de correcteurs
2354pourcentage_H_PR = str2num(get(handles.pourcentage_H_PR_edit,'String'));
2355% BPMx = getappdata(handles.figure1,'BPMx'); % Orbit H
2356HCOR = getappdata(handles.figure1,'HCOR'); % Correcteurs H
2357
2358%nbpm = 4;
2359nbpm = str2num(get(handles.nbBPM_PR_edit,'String'));
2360
2361% liste des 2 BPM concernés (les 2 premiers valides)
2362BPMxDeviceListPR = getappdata(handles.figure1,'BPMxDeviceListPR');
2363BPMxliste = BPMxDeviceListPR(1:nbpm,:);
2364
2365ncor = 6;
2366ncor = str2num(get(handles.nbcorr_PR_edit,'String'));
2367
2368% liste des 2 correcteurs concernés (les 2 derniers valides)
2369HCORliste = HCOR.DeviceList(end-ncor+1:end,:);
2370setappdata(handles.figure1,'HCORliste_PR',HCORliste);
2371% enregistrement des correcteurs avant correction
2372
2373%%%attention !
2374%%handles.mode = 'Model';
2375%%%attention !
2376
2377liste = getam('HCOR',handles.mode);
2378liste = liste(end-ncor+1:end,:);% courant dans les derniers valides
2379% val_corr_CH = liste(valCH-nbcorrSVD+1:valCH); % Dangerux de pas travailler sur deviceliste
2380setappdata(handles.figure1,'val_corr_CH_PR',liste);
2381
2382%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2383% plan H
2384[bxHCOR,bzHCOR] = modelbeta('HCOR',HCORliste);
2385[bxBPM,bzBPM] = modelbeta('BPMx',BPMxliste);
2386[phixHCOR,phizHCOR] = modelphase('HCOR',HCORliste);
2387[phixBPM,phizBPM] = modelphase('BPMx',BPMxliste);
2388COEFF = hw2physics('HCOR','Setpoint',1) * 1e3 ;  % mrad/A
2389nu = modeltune;
2390deltaphi = 2*pi*nu(1) ; % 2 pi nux
2391
2392for k = 1:ncor
2393    for j = 1:nbpm
2394        % calcul de l'efficacité
2395        Meff(j,k) = sqrt(bxHCOR(k)*bxBPM(j)) * sin(deltaphi + phixBPM(j) - phixHCOR(k))*COEFF(k); % mm/A
2396    end
2397end
2398
2399%[X ] = anabpmnfirstturns(BPMxliste,2,'NoDisplay2');   % 2 tours sur les 2 premiers BPM valides
2400
2401if strcmp(handles.orbite,'transport - max Sum') % orbite à corriger type transport
2402    %[X] = anabpmfirstturn( BPMx.DeviceList );
2403    %[X] = anabpmfirstturn( liste_dev_BPM,'NoDisplay' ); % X en mm premier tour ANCIENNE VERSION
2404    nbturns = 2;
2405    [X Z Sum idx] = anabpmnfirstturns( BPMxliste,nbturns,'NoDisplay2'); % X en mm premier tour
2406    idx
2407
2408elseif strcmp(handles.orbite,'transport - tour fixe') % orbite à corriger type transport
2409    ifirstturn = str2num(get(handles.tour_fixe_T_edit,'String')); % numero du premier tour
2410    nbturns = 2;
2411    [X ] = anabpmnfirstturns( BPMxliste,nbturns,ifirstturn,'NoDisplay2','NoMaxSum'); % X en mm premier tour
2412
2413else
2414    errordlg('selectionnez une option transport ! ', 'attention');
2415end
2416%
2417orbite_x_1 = X(1,:)';
2418%orbite_z_1 = Y(1,:)';
2419%orbite_sum_1 = Sum(1,:)';
2420
2421orbite_x_2 = X(2,:)';
2422%orbite_z_2 = Y(2,:)';
2423%orbite_sum_2 = Sum(2,:)';
2424
2425% delta d'orbite à corriger :
2426X = orbite_x_2 - orbite_x_1  ;% mm
2427difference_orbite_x = X
2428
2429% end
2430
2431%%%
2432
2433[U,S,V] = svd(Meff);
2434%setappdata(handles.figure1,'S',S);
2435DiagS = diag(S);
2436
2437% % test si le nombre de valeurs propres a ᅵtᅵ modifiᅵ dans l'interface
2438% % "valeurs singuliï¿œres"
2439% nbvp = getappdata(handles.figure1,'valvp');
2440%
2441%
2442% % si le nbre n'a pas ᅵtᅵ modifiᅵ et qu'il est incompatible :
2443% % if nbvp ==0||nbvp>size(S,2)
2444% %     nbvp = size(S,2);
2445% if nbvp ==0||nbvp>length(DiagS)
2446%     nbvp = length(DiagS);   
2447% end
2448% % affichage
2449% disp(strcat('nombre de valeurs propres sélectionnees :',num2str(nbvp)))
2450nbvp = 2
2451%Rmod = Meff * V;
2452Rmod1 = Meff * V(:,1:nbvp);
2453%B = Rmod\ (X );
2454B1 = Rmod1\ (X );
2455%DeltaCM = V * B;
2456DeltaCM1 = V(:,1:nbvp) * B1
2457%DeltaCM1 = V(:,1:nbvp) * B1;
2458consigne = getsp('HCOR',HCORliste,handles.mode);
2459% test
2460val_max = getmaxsp('HCOR',HCORliste);
2461val_min = getminsp('HCOR',HCORliste);
2462if all((consigne-DeltaCM1* pourcentage_H_PR*0.01)<val_max)*all((consigne-DeltaCM1* pourcentage_H_PR*0.01)>val_min);
2463    %%%% attention  !
2464    stepsp('HCOR',-DeltaCM1* pourcentage_H_PR*0.01 ,HCORliste,handles.mode);
2465    mycallback_steerette_orbites_PR(1,1,hObject, eventdata, handles)
2466    mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2467    disp('eh oui')
2468else
2469    consigne-DeltaCM1
2470    HCORliste
2471    errordlg('un correcteur au moins dépasse les valeurs admises !','Attention');
2472    return
2473end
2474
2475
2476% --- Executes on button press in SVD_V_PR_pushbutton.
2477function SVD_V_PR_pushbutton_Callback(hObject, eventdata, handles)
2478% hObject    handle to SVD_V_PR_pushbutton (see GCBO)
2479% eventdata  reserved - to be defined in a future version of MATLAB
2480% handles    structure with handles and user data (see GUIDATA)
2481
2482% relire le pourcentage ᅵ appliquer sur les valeurs de correcteurs
2483pourcentage_V_PR = str2num(get(handles.pourcentage_V_PR_edit,'String'));
2484% BPMx = getappdata(handles.figure1,'BPMx'); % Orbit H
2485VCOR = getappdata(handles.figure1,'VCOR'); % Correcteurs V
2486
2487%nbpm = 4;
2488nbpm = str2num(get(handles.nbBPM_PR_edit,'String'));
2489
2490% liste des 2 BPM concernés (les 2 premiers valides)
2491BPMxDeviceListPR = getappdata(handles.figure1,'BPMxDeviceListPR');
2492BPMxliste = BPMxDeviceListPR(1:nbpm,:);
2493
2494ncor = 6;
2495ncor = str2num(get(handles.nbcorr_PR_edit,'String'));
2496
2497% liste des 2 correcteurs concernés (les 2 derniers valides)
2498VCORliste = VCOR.DeviceList(end-ncor+1:end,:);
2499setappdata(handles.figure1,'VCORliste_PR',VCORliste);
2500% enregistrement des correcteurs avant correction
2501
2502%%%attention !
2503%%handles.mode = 'Model';
2504%%%attention !
2505
2506% enregistrement des correcteurs avant correction
2507liste = getam('VCOR',handles.mode);
2508liste = liste(end-ncor+1:end,:);% courant dans les derniers valides
2509% val_corr_CH = liste(valCH-nbcorrSVD+1:valCH); % Dangerux de pas travailler sur deviceliste
2510setappdata(handles.figure1,'val_corr_CV_PR',liste);
2511
2512%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2513% plan V
2514[bxVCOR,bzVCOR] = modelbeta('VCOR',VCORliste);
2515[bxBPM,bzBPM] = modelbeta('BPMx',BPMxliste);
2516[phixVCOR,phizVCOR] = modelphase('VCOR',VCORliste);
2517[phixBPM,phizBPM] = modelphase('BPMx',BPMxliste);
2518COEFF = hw2physics('VCOR','Setpoint',1) * 1e3 ;  % mrad/A
2519nu = modeltune;
2520deltaphi = 2*pi*nu(2) ; % 2 pi nuz
2521
2522for k = 1:ncor
2523    for j = 1:nbpm
2524        % calcul de l'efficacité
2525        Meff_V(j,k) = sqrt(bzVCOR(k)*bzBPM(j)) * sin(deltaphi + phizBPM(j) - phizVCOR(k))*COEFF(k); % mm/A
2526    end
2527end
2528
2529%[X Y] = anabpmnfirstturns(BPMxliste,2,'NoDisplay2');   % 2 tours sur les 2 premiers BPM valides
2530%
2531if strcmp(handles.orbite,'transport - max Sum') % orbite à corriger type transport
2532    %[X] = anabpmfirstturn( BPMx.DeviceList );
2533    %[X] = anabpmfirstturn( liste_dev_BPM,'NoDisplay' ); % X en mm premier tour ANCIENNE VERSION
2534    nbturns = 2;
2535    [X Y Sum idx] = anabpmnfirstturns( BPMxliste,nbturns,'NoDisplay2'); % X en mm premier tour
2536    idx
2537
2538elseif strcmp(handles.orbite,'transport - tour fixe') % orbite à corriger type transport
2539    ifirstturn = str2num(get(handles.tour_fixe_T_edit,'String')); % numero du premier tour
2540    nbturns = 2;
2541    [X Y] = anabpmnfirstturns( BPMxliste,nbturns,ifirstturn,'NoDisplay2','NoMaxSum'); % X en mm premier tour
2542
2543else
2544    errordlg('selectionnez une option transport ! ', 'attention');
2545end
2546%
2547%
2548%orbite_x_1 = X(1,:)';
2549orbite_z_1 = Y(1,:)';
2550%orbite_sum_1 = Sum(1,:)';
2551
2552%orbite_x_2 = X(2,:)';
2553orbite_z_2 = Y(2,:)';
2554%orbite_sum_2 = Sum(2,:)';
2555
2556% delta d'orbite à corriger :
2557Z = orbite_z_2 - orbite_z_1  ;% mm
2558difference_orbite_z = Z
2559
2560
2561%%%%%%%%%%%%%%%%%%%%%%%
2562[U,S,V] = svd(Meff_V);
2563DiagS = diag(S);
2564nbvp = 2
2565%Rmod = Meff_V * V;
2566Rmod1 = Meff_V* V(:,1:nbvp);
2567%B = Rmod\ (Z );
2568B1 = Rmod1\ (Z);
2569%DeltaCM = V * B;
2570DeltaCM1 = V(:,1:nbvp) * B1;
2571consigne = getsp('VCOR',VCORliste,handles.mode);
2572% test
2573val_max = getmaxsp('VCOR',VCORliste);
2574val_min = getminsp('VCOR',VCORliste);
2575if all((consigne-DeltaCM1* pourcentage_V_PR*0.01)<val_max)*all((consigne-DeltaCM1* pourcentage_V_PR*0.01)>val_min);
2576    stepsp('VCOR',-DeltaCM1* pourcentage_V_PR*0.01 ,VCORliste,handles.mode);
2577    mycallback_steerette_orbites_PR(1,1,hObject, eventdata, handles)
2578    mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2579    disp('eh oui')
2580else
2581    consigne-DeltaCM1
2582    VCORliste
2583    errordlg('un correcteur au moins dépasse les valeurs admises !','Attention');
2584    return
2585end
2586
2587
2588% --- Executes on button press in orbites_PR_pushbutton.
2589function orbites_PR_pushbutton_Callback(hObject, eventdata, handles)
2590% hObject    handle to orbites_PR_pushbutton (see GCBO)
2591% eventdata  reserved - to be defined in a future version of MATLAB
2592% handles    structure with handles and user data (see GUIDATA)
2593
2594% plot le tour 1 et 2 des BPM [1 2] à [1  7]
2595List = getappdata(handles.figure1, 'BPMxList'); % BPM non deselectionné et status 1
2596BPMxDeviceListPR = [ 1 2; 1 3 ; 1 4; 1 5; 1 6 ; 1 7];
2597% tests
2598%BPMxDeviceListPR = [ 1 5];
2599BPMxDeviceListPR = intersect(List,BPMxDeviceListPR,'rows');
2600setappdata(handles.figure1,'BPMxDeviceListPR',BPMxDeviceListPR);
2601%handles.mode = getappdata(handles.figure1,'Mode')
2602
2603if strcmp(handles.mode,'Model')
2604    errordlg('changer le mode  en "online" !','Attention');
2605    return
2606else
2607
2608    %     [X Y Sum] = anabpmnfirstturns(BPMxDeviceListPR,2,'NoDisplay');   % 2 tours
2609    %     %
2610    %     orbite_x_1 = X(1)';
2611    %     orbite_z_1 = Z(1)';
2612    %     orbite_sum_1 = Sum(1)';
2613    %
2614    %     orbite_x_2 = X(2)';
2615    %     orbite_z_2 = Z(2)';
2616    %     orbite_sum_2 = Sum(2)';
2617    %
2618    %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2619    %     %% graphe 11 : signal somme tour 1 et 2
2620    %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2621    %     name=['axes' num2str(11)];
2622    %     axes(handles.(name));
2623    %
2624    %     xdata = getspos(BPMxDeviceListPR);
2625    %     plot(xdata,orbite_sum_1,'c-','Tag','line1');
2626    %     hold on
2627    %     plot(xdata,orbite_sum_2,'c-','Tag','line2');
2628    %     set(handles.(name), 'YGrid','On');
2629    %     set(gca, 'YMinorTick','On');
2630    %     set(handles.(name), 'XMinorTick','On');
2631    %
2632    %     ylabel(handles.(name),'signal somme');
2633    %     %xlim([xdata(1) xdata(end)]);
2634    %     %ylim([0 max(orbite_sum)]);
2635    %
2636    %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2637    %     %% graphe 13 : orbite x et z
2638    %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2639    %
2640    %     name=['axes' num2str(13)];
2641    %     axes(handles.(name));
2642    %     % plot des orbites
2643    %     xdata =getspos(BPMxDeviceListPR);
2644    %     %xdata = 1:length(orbite_x);
2645    %     plot(xdata,orbite_x_1,'r-','Tag','line1');
2646    %     hold on
2647    %     plot(xdata,orbite_x_2,'r--','Tag','line3');
2648    %     hold on
2649    %     ydata = BPMz.Position;
2650    %     %ydata = 1:length(orbite_z);
2651    %     plot(ydata,orbite_z_1,'b-','Tag','line2');
2652    %     hold on
2653    %     plot(ydata,orbite_z_2,'b--','Tag','line4');
2654    %     xlabel(handles.(name),'position du BPM');
2655    mycallback_steerette_orbites_PR(1,1,hObject, eventdata, handles)
2656
2657end
2658
2659
2660% --- Executes on button press in Undo_V_PR_pushbutton.
2661function Undo_V_PR_pushbutton_Callback(hObject, eventdata, handles)
2662% hObject    handle to Undo_V_PR_pushbutton (see GCBO)
2663% eventdata  reserved - to be defined in a future version of MATLAB
2664% handles    structure with handles and user data (see GUIDATA)
2665
2666%
2667% % --- Executes on button press in pushbutton36.
2668% function Trace_nombre_onde_pushbutton_Callback(hObject, eventdata, handles)
2669% % hObject    handle to pushbutton36 (see GCBO)
2670% % eventdata  reserved - to be defined in a future version of MATLAB
2671% % handles    structure with handles and user data (see GUIDATA)
2672
2673ncor = str2num(get(handles.nbcorr_PR_edit,'String'));
2674% liste = getam('HCOR',handles.mode);
2675% liste = liste(end-ncor+1:end,:);
2676valliste = getappdata(handles.figure1,'val_corr_CV_PR');
2677VCORliste = getappdata(handles.figure1,'VCORliste_PR');
2678
2679%%%%%%%%%%%%%%%%%%%%%%%%%
2680% attention !!
2681handles.mode = 'Model'
2682%%%%%%%%%%%%%%%%%%%%%%%%%%%
2683setsp('VCOR',valliste,VCORliste,handles.mode);
2684disp('nous y re-voilà')
2685% replot des orbites et point et correcteur V
2686
2687mycallback_steerette_orbites_PR(1,1,hObject, eventdata, handles)
2688mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2689
2690
2691
2692% --- Executes on button press in Nombre_onde_pushbutton.
2693function Nombre_onde_pushbutton_Callback(hObject, eventdata, handles)
2694% hObject    handle to Nombre_onde_pushbutton (see GCBO)
2695% eventdata  reserved - to be defined in a future version of MATLAB
2696% handles    structure with handles and user data (see GUIDATA)
2697
2698handles.orbite = getappdata(handles.figure1,'Orbite');
2699
2700BPMx = getappdata(handles.figure1,'BPMx');
2701BPMxlist = BPMx.DeviceList;
2702
2703if strcmp(handles.orbite,'orbite fermée')
2704    errordlg('changer le mode orbite en "transport" !','Attention');
2705    return
2706else
2707    compteur = getappdata(handles.figure1,'compteur');
2708    if compteur >1
2709        errordlg('Un coup de trop ! Faire Reset','Attention');
2710        return
2711    else
2712
2713        if strcmp(handles.orbite,'transport - max Sum') % orbite à corriger type transport
2714
2715            compteur = compteur + 1;
2716            nbturns = 1;
2717            [X Z Sum idx] = anabpmnfirstturns( BPMxlist,nbturns,'NoDisplay2'); % X en mm premier tour
2718            idx
2719
2720        elseif strcmp(handles.orbite,'transport - tour fixe') % orbite à corriger type transport
2721            compteur = compteur + 1;
2722            ifirstturn = str2num(get(handles.tour_fixe_T_edit,'String')); % numero du premier tour
2723            nbturns = 1;
2724            [X Z Sum] = anabpmnfirstturns( BPMxlist,nbturns,ifirstturn,'NoDisplay2','NoMaxSum'); % X en mm premier tour
2725
2726        else
2727            errordlg('erreur sur option transport !','attention')
2728        end
2729
2730        %compteur = compteur + 1;
2731        % acquérir l'orbite premier tour (on suppose qu'on a actionné un correcteur)
2732        %[X Z Sum] = anabpmfirstturn(BPMxlist,'NoDisplay'); % ancienne version
2733        % enregistrement
2734        if compteur == 1
2735            setappdata(handles.figure1,'orbite_x_coup1',X);
2736            setappdata(handles.figure1,'orbite_z_coup1',Z);
2737        else
2738            setappdata(handles.figure1,'orbite_x_coup2',X);
2739            setappdata(handles.figure1,'orbite_z_coup2',Z);
2740        end
2741    end
2742    setappdata(handles.figure1,'compteur',compteur);
2743end
2744
2745% --- Executes on button press in Undo_H_PR_pushbutton.
2746function Undo_H_PR_pushbutton_Callback(hObject, eventdata, handles)
2747% hObject    handle to Undo_H_PR_pushbutton (see GCBO)
2748% eventdata  reserved - to be defined in a future version of MATLAB
2749% handles    structure with handles and user data (see GUIDATA)
2750
2751ncor = str2num(get(handles.nbcorr_PR_edit,'String'));
2752% liste = getam('HCOR',handles.mode);
2753% liste = liste(end-ncor+1:end,:);
2754valliste = getappdata(handles.figure1,'val_corr_CH_PR');
2755HCORliste = getappdata(handles.figure1,'HCORliste_PR');
2756
2757%%%%%%%%%%%%%%%%%%%%%%%%%
2758% attention !!
2759handles.mode = 'Model'
2760%%%%%%%%%%%%%%%%%%%%%%%%%%%
2761setsp('HCOR',valliste,HCORliste,handles.mode);
2762disp('nous y re-voilà')
2763% replot des orbites et point et correcteur H
2764
2765mycallback_steerette_orbites_PR(1,1,hObject, eventdata, handles)
2766mycallback_steerette_corr(1,1,hObject, eventdata, handles)
2767
2768
2769% --- Executes on button press in reset_nombre_onde_pushbutton.
2770function reset_nombre_onde_pushbutton_Callback(hObject, eventdata, handles)
2771% hObject    handle to reset_nombre_onde_pushbutton (see GCBO)
2772% eventdata  reserved - to be defined in a future version of MATLAB
2773% handles    structure with handles and user data (see GUIDATA)
2774
2775setappdata(handles.figure1,'compteur',0);
2776
2777function pourcentage_H_PR_edit_Callback(hObject, eventdata, handles)
2778% hObject    handle to pourcentage_H_PR_edit (see GCBO)
2779% eventdata  reserved - to be defined in a future version of MATLAB
2780% handles    structure with handles and user data (see GUIDATA)
2781
2782% Hints: get(hObject,'String') returns contents of pourcentage_H_PR_edit as text
2783%        str2double(get(hObject,'String')) returns contents of pourcentage_H_PR_edit as a double
2784
2785
2786% --- Executes during object creation, after setting all properties.
2787function pourcentage_H_PR_edit_CreateFcn(hObject, eventdata, handles)
2788% hObject    handle to pourcentage_H_PR_edit (see GCBO)
2789% eventdata  reserved - to be defined in a future version of MATLAB
2790% handles    empty - handles not created until after all CreateFcns called
2791
2792% Hint: edit controls usually have a white background on Windows.
2793%       See ISPC and COMPUTER.
2794if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2795    set(hObject,'BackgroundColor','white');
2796end
2797
2798
2799% --- Executes on button press in Trace_nombre_onde_pushbutton.
2800function Trace_nombre_onde_pushbutton_Callback(hObject, eventdata, handles)
2801% hObject    handle to Trace_nombre_onde_pushbutton (see GCBO)
2802% eventdata  reserved - to be defined in a future version of MATLAB
2803% handles    structure with handles and user data (see GUIDATA)
2804
2805BPMx = getappdata(handles.figure1,'BPMx');
2806BPMxlist = BPMx.DeviceList;
2807s = getspos('BPMx',BPMxlist);
2808orbite_x_coup1 = getappdata(handles.figure1,'orbite_x_coup1');
2809orbite_z_coup1 = getappdata(handles.figure1,'orbite_z_coup1');
2810orbite_x_coup2 = getappdata(handles.figure1,'orbite_x_coup2');
2811orbite_z_coup2 = getappdata(handles.figure1,'orbite_z_coup2');
2812
2813difference_x = orbite_x_coup2 - orbite_x_coup1;
2814difference_z = orbite_z_coup2 - orbite_z_coup1;
2815figure(1)
2816
2817plot(s,difference_x,'r.-',s,difference_z,'b.-')
2818%xlabel(handles.(name),'position en m');
2819xlabel('position en m');
2820%ylabel(handles.(name),'différence d''orbite en mm');
2821ylabel('différence d''orbite en mm');
2822grid on
2823hold off
2824
2825
2826function pourcentage_V_PR_edit_Callback(hObject, eventdata, handles)
2827% hObject    handle to pourcentage_V_PR_edit (see GCBO)
2828% eventdata  reserved - to be defined in a future version of MATLAB
2829% handles    structure with handles and user data (see GUIDATA)
2830
2831% Hints: get(hObject,'String') returns contents of pourcentage_V_PR_edit as text
2832%        str2double(get(hObject,'String')) returns contents of pourcentage_V_PR_edit as a double
2833
2834
2835% --- Executes during object creation, after setting all properties.
2836function pourcentage_V_PR_edit_CreateFcn(hObject, eventdata, handles)
2837% hObject    handle to pourcentage_V_PR_edit (see GCBO)
2838% eventdata  reserved - to be defined in a future version of MATLAB
2839% handles    empty - handles not created until after all CreateFcns called
2840
2841% Hint: edit controls usually have a white background on Windows.
2842%       See ISPC and COMPUTER.
2843if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2844    set(hObject,'BackgroundColor','white');
2845end
2846
2847
2848
2849function nbcorr_PR_edit_Callback(hObject, eventdata, handles)
2850% hObject    handle to nbcorr_PR_edit (see GCBO)
2851% eventdata  reserved - to be defined in a future version of MATLAB
2852% handles    structure with handles and user data (see GUIDATA)
2853
2854% Hints: get(hObject,'String') returns contents of nbcorr_PR_edit as text
2855%        str2double(get(hObject,'String')) returns contents of nbcorr_PR_edit as a double
2856
2857
2858% --- Executes during object creation, after setting all properties.
2859function nbcorr_PR_edit_CreateFcn(hObject, eventdata, handles)
2860% hObject    handle to nbcorr_PR_edit (see GCBO)
2861% eventdata  reserved - to be defined in a future version of MATLAB
2862% handles    empty - handles not created until after all CreateFcns called
2863
2864% Hint: edit controls usually have a white background on Windows.
2865%       See ISPC and COMPUTER.
2866if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2867    set(hObject,'BackgroundColor','white');
2868end
2869
2870
2871
2872function nbBPM_PR_edit_Callback(hObject, eventdata, handles)
2873% hObject    handle to nbBPM_PR_edit (see GCBO)
2874% eventdata  reserved - to be defined in a future version of MATLAB
2875% handles    structure with handles and user data (see GUIDATA)
2876
2877% Hints: get(hObject,'String') returns contents of nbBPM_PR_edit as text
2878%        str2double(get(hObject,'String')) returns contents of nbBPM_PR_edit as a double
2879
2880
2881% --- Executes during object creation, after setting all properties.
2882function nbBPM_PR_edit_CreateFcn(hObject, eventdata, handles)
2883% hObject    handle to nbBPM_PR_edit (see GCBO)
2884% eventdata  reserved - to be defined in a future version of MATLAB
2885% handles    empty - handles not created until after all CreateFcns called
2886
2887% Hint: edit controls usually have a white background on Windows.
2888%       See ISPC and COMPUTER.
2889if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2890    set(hObject,'BackgroundColor','white');
2891end
2892
2893
2894
2895function Ntours_edit_Callback(hObject, eventdata, handles)
2896% hObject    handle to Ntours_edit (see GCBO)
2897% eventdata  reserved - to be defined in a future version of MATLAB
2898% handles    structure with handles and user data (see GUIDATA)
2899
2900% Hints: get(hObject,'String') returns contents of Ntours_edit as text
2901%        str2double(get(hObject,'String')) returns contents of Ntours_edit as a double
2902
2903
2904% --- Executes during object creation, after setting all properties.
2905function Ntours_edit_CreateFcn(hObject, eventdata, handles)
2906% hObject    handle to Ntours_edit (see GCBO)
2907% eventdata  reserved - to be defined in a future version of MATLAB
2908% handles    empty - handles not created until after all CreateFcns called
2909
2910% Hint: edit controls usually have a white background on Windows.
2911%       See ISPC and COMPUTER.
2912if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2913    set(hObject,'BackgroundColor','white');
2914end
2915
2916
2917% --- Executes on button press in fourturns_pushbutton.
2918function fourturns_pushbutton_Callback(hObject, eventdata, handles)
2919% hObject    handle to fourturns_pushbutton (see GCBO)
2920% eventdata  reserved - to be defined in a future version of MATLAB
2921% handles    structure with handles and user data (see GUIDATA)
2922
2923BPMxList = getappdata(handles.figure1, 'BPMxList');
2924
2925[X Z] = anabpmnfirstturns(BPMxList,4,8,'NoDisplay','NoMaxSum');
2926[X1 X2 X3 X4] = deal(X(1,:),X(2,:),X(3,:),X(4,:));
2927[Z1 Z2 Z3 Z4] = deal(Z(1,:),Z(2,:),Z(3,:),Z(4,:));
2928
2929
2930%% Algo 4 turns de Laurent fourturnalogothm.m
2931nux = acos((X2-X1+X4-X3)/2./(X3-X2))/2/pi;
2932nuz = acos((Z2-Z1+Z4-Z3)/2./(Z3-Z2))/2/pi;
2933
2934Xcod = (X3.*(X1+X3)-X2.*(X2+X4))./((X1-X4) + 3*(X3-X2));
2935Zcod = (Z3.*(Z1+Z3)-Z2.*(Z2+Z4))./((Z1-Z4) + 3*(Z3-Z2));
2936
2937spos = getspos('BPMx',BPMxList);
2938figure(78)
2939plot(spos,Xcod,'b',spos,Zcod,'r');
2940xlabel('s-position [m]');
2941ylabel('Close orbit [mm]');
2942legend('Xcod','Zcod');
2943grid on
2944
2945figure(79)
2946plot(spos,nux,'b',spos,nuz,'r')
2947xlabel('s-position [m]')
2948ylabel('tune fractionnal part')
2949title('4-turn Algorithm')
2950legend('nux','nuz');
2951grid on
2952
2953
2954
2955function tour_fixe_OF_edit_Callback(hObject, eventdata, handles)
2956% hObject    handle to tour_fixe_OF_edit (see GCBO)
2957% eventdata  reserved - to be defined in a future version of MATLAB
2958% handles    structure with handles and user data (see GUIDATA)
2959
2960% Hints: get(hObject,'String') returns contents of tour_fixe_OF_edit as text
2961%        str2double(get(hObject,'String')) returns contents of tour_fixe_OF_edit as a double
2962
2963
2964% --- Executes during object creation, after setting all properties.
2965function tour_fixe_OF_edit_CreateFcn(hObject, eventdata, handles)
2966% hObject    handle to tour_fixe_OF_edit (see GCBO)
2967% eventdata  reserved - to be defined in a future version of MATLAB
2968% handles    empty - handles not created until after all CreateFcns called
2969
2970% Hint: edit controls usually have a white background on Windows.
2971%       See ISPC and COMPUTER.
2972if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2973    set(hObject,'BackgroundColor','white');
2974end
2975
2976
2977
2978function tour_fixe_T_edit_Callback(hObject, eventdata, handles)
2979% hObject    handle to tour_fixe_T_edit (see GCBO)
2980% eventdata  reserved - to be defined in a future version of MATLAB
2981% handles    structure with handles and user data (see GUIDATA)
2982
2983% Hints: get(hObject,'String') returns contents of tour_fixe_T_edit as text
2984%        str2double(get(hObject,'String')) returns contents of tour_fixe_T_edit as a double
2985
2986
2987% --- Executes during object creation, after setting all properties.
2988function tour_fixe_T_edit_CreateFcn(hObject, eventdata, handles)
2989% hObject    handle to tour_fixe_T_edit (see GCBO)
2990% eventdata  reserved - to be defined in a future version of MATLAB
2991% handles    empty - handles not created until after all CreateFcns called
2992
2993% Hint: edit controls usually have a white background on Windows.
2994%       See ISPC and COMPUTER.
2995if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
2996    set(hObject,'BackgroundColor','white');
2997end
2998
2999
Note: See TracBrowser for help on using the repository browser.