source: MML/trunk/machine/SOLEIL/LT1/fae/fae_v3.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: 51.2 KB
Line 
1function varargout = fae_v3(varargin)
2% FAE_V3 M-file for fae_v3.fig
3%      FAE_V3, by itself, creates a new FAE_V3 or raises the existing
4%      singleton*.
5%
6%      H = FAE_V3 returns the handle to a new FAE_V3 or the handle to
7%      the existing singleton*.
8%
9%      FAE_V3('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in FAE_V3.M with the given input arguments.
11%
12%      FAE_V3('Property','Value',...) creates a new FAE_V3 or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before fae_v3_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to fae_v3_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 fae_v3
26
27% Last Modified by GUIDE v2.5 20-Jul-2005 15:06:35
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', @fae_v3_OpeningFcn, ...
34                   'gui_OutputFcn',  @fae_v3_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 fae_v3 is made visible.
49function fae_v3_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 fae_v3 (see VARARGIN)
55
56% Choose default command line output for fae_v3
57handles.output = hObject;
58
59% devices Servers Tango
60device_name.morsdroit = 'lt1/dg/fae-mors.droit'
61device_name.morsgauche = 'lt1/dg/fae-mors.gauche'
62device_name.scan = 'lt1/dg/fae-scan'
63device_name.fente = 'lt1/dg/fae-fente'
64device_name.scan1D = 'lt1/dg/fae-scan1D'
65%device_name.dipole = 'LT1/AEsim/D.1'
66device_name.dipole = 'LT1/AE/D.1'
67setappdata(handles.figure1,'device_name',device_name);
68
69%         % ï¿œtalonnage du dipï¿œle (cette partie pourrait ï¿œtre revue avec les fonctions mml
70%         setappdata(handles.figure1,'B0',0.000119);
71%         setappdata(handles.figure1,'B1',4.8861*0.0001);
72
73
74% Creates timer Infinite loop
75timer1=timer('StartDelay',1,...
76    'ExecutionMode','fixedRate','Period',1,'TasksToExecute',Inf);
77    %'ExecutionMode','fixedRate','Period',1,'TasksToExecute',Inf);
78timer1.TimerFcn = {@fae_timer, hObject,eventdata, handles};
79setappdata(handles.figure1,'Timer',timer1);
80
81start(timer1);
82
83%% Set closing gui function
84set(handles.figure1,'CloseRequestFcn',{@Closinggui,timer1,handles.figure1});
85%set(handles.figure1,'CloseRequestFcn',{@Closinggui,handles.figure1});
86
87% Update handles structure
88guidata(hObject, handles);
89   
90
91% % taille_spectrum = size(xdata,2)
92
93   
94% % This sets up the initial plot - only do when we are invisible
95% % so window can get raised using fae_v3.
96% if strcmp(get(hObject,'Visible'),'off')
97%     plot(rand(5));
98% end
99
100% UIWAIT makes fae_v3 wait for user response (see UIRESUME)
101% uiwait(handles.figure1);
102
103
104% --- Outputs from this function are returned to the command line.
105function varargout = fae_v3_OutputFcn(hObject, eventdata, handles)
106% varargout  cell array for returning output args (see VARARGOUT);
107% hObject    handle to figure
108% eventdata  reserved - to be defined in a future version of MATLAB
109% handles    structure with handles and user data (see GUIDATA)
110
111% Get default command line output from handles structure
112varargout{1} = handles.output;
113
114% --- Executes on button press in NewData_pushbutton1.
115function NewData_pushbutton1_Callback(hObject, eventdata, handles)
116% hObject    handle to NewData_pushbutton1 (see GCBO)
117% eventdata  reserved - to be defined in a future version of MATLAB
118% handles    structure with handles and user data (see GUIDATA)
119
120%% ACQUISITION
121device_name = getappdata(handles.figure1,'device_name');
122dev = device_name.scan;
123vectx=tango_read_attribute(dev,'actuators_data');
124fonction_error;
125xdata = vectx.value;
126setappdata(handles.figure1,'xdata',xdata);
127
128% vecty=tango_read_attribute(dev,'sensors_data');
129% ydata = vecty.value;
130
131dev = device_name.scan1D;
132% lecture des deux mesureurs de charge ensemble
133%- build attribute list
134mc_name_list = {'Sensor1Data', 'Sensor2Data'};
135%- read attributes
136mc_val_list = tango_read_attributes(dev, mc_name_list);
137%- always check error
138if (tango_error == -1)
139  %- handle error
140  tango_print_error_stack;
141  return;
142end
143%- store 'Sensor1Data' value in local variable
144ydatamc1 = mc_val_list(1).value;
145%- store 'Sensor2Data' value in local variable
146ydatamc2 = mc_val_list(2).value;
147
148% affichage de la charge et calibre du mesureur 1
149% attention le calibre n'est pour l'instant pas associé à une date... il a
150% pu changer lorsqu'on active le traitement par MATLAB !!!!
151% -> trouver une solution
152set(handles.mc1_charge_edit5,'String',num2str(ydatamc1(1)));
153
154device = 'LT1/DG/MC';
155ict1Gain_val = tango_read_attribute(device,'ict1Gain');
156ict1Gain = ict1Gain_val.value(1);
157if (tango_error == -1)
158  %- handle error
159  tango_print_error_stack;
160  return;
161end
162set(handles.mc1_calibre_edit6,'String',num2str(ict1Gain));
163
164
165% % setappdata(handles.figure1,'ydata',ydata);
166setappdata(handles.figure1,'ydatamc1',ydatamc1);
167setappdata(handles.figure1,'ydatamc2',ydatamc2);
168
169% horodatage du scan :
170dev = device_name.scan;
171res = tango_read_attribute(dev,'measureDate');
172%%res = tango_read_attribute('tests/scanserver/1','measureDate');
173String1 = datenum('1-January-1970');
174% equation correcte :
175%String2 = double(res.value)/(60*60*24) + String1;
176% equation en attendant la remise à l'heure locale du CPU
177String2 = double(res.value + 2*60*60)/(60*60*24) + String1;
178date =  datestr(String2,'dd-mmm-yyyy HH:MM:SS');
179
180% horodatage du scan : en attendant :
181% device_name = getappdata(handles.figure1,'device_name');
182% structure = tango_read_attribute(device_name.dipole,'current');
183% date = datestr(structure.time)
184
185set(handles.horodatage_edit1,'String',date);
186setappdata(handles.figure1,'Date',date);
187
188%% AFFICHAGE ET TRAITEMENT
189% on écrase les vecteurs données re - calculées  (lissées, énergie)
190% et le nom de fichier
191nul = [];
192setappdata(handles.figure1,'yfiltre',nul);
193setappdata(handles.figure1,'Dfiltre',nul);
194setappdata(handles.figure1,'xdata2',nul);
195setappdata(handles.figure1,'ydata2',nul);
196set(handles.nom_fichier_edit7,'String',[]);
197
198% test sur type de spectre
199log1=get(handles.Dipfixe_radiobutton1,'Value');
200log2=get(handles.Fenfixe_radiobutton2,'Value');
201log3=get(handles.Gap_radiobutton3,'Value');
202
203% normaliser les charges !!
204ydata = ydatamc2./ydatamc1;
205% on remplace les valeurs infinies par 0
206ydata(isnan(ydata))=0;
207
208% calcul de l'énergie du faisceau / dispersion à la fente d'analyse
209LT1init;
210global THERING;
211AO = getao;
212
213% sauvegarder le mode du simulateur optics_LT1
214mode = getmode('BEND')
215if isequal(mode,'Simulator')
216    switch2online
217end   
218
219twissdatain.ElemIndex=1;
220twissdatain.SPos=0;
221twissdatain.ClosedOrbit=[1e-3 0 2e-3 0]'*0;
222twissdatain.M44=eye(4);
223twissdatain.beta= [8.1 8.1];
224twissdatain.alpha= [0 0];
225twissdatain.mu= [0 0];
226twissdatain.Dispersion= [0 0 0 0]';
227TD = twissline(THERING,0.0,twissdatain,1:length(THERING),'chroma');
228ETA = cat(2,TD.Dispersion)';
229
230index = atindex(THERING);
231num = index.COLL;
232dispersion = ETA(num,1);
233   
234
235%% cas du dipÃŽle fixe (1 mors actuator)
236if isequal(log1,1)
237   
238%testA    Idip = getam('BEND');
239% %             B0 = getappdata(handles.figure1,'B0');
240% %             B1 = getappdata(handles.figure1,'B1');
241% %
242%     [C, Leff, MagnetType, A] = magnetcoefficients('BEND');
243%     B0 = A(9);
244%     B1 = A(8);
245%     Integrale = B0 + B1 * Idip;
246%     angle = 15 * pi / 180;
247% %             Bro = Integrale / angle
248%     E0 = 0.51099906 ;
249% %             Ec = E0 * ( sqrt(1 + (Bro*0.29979)*(Bro*0.29979)/((E0*0.001)*(E0*0.001))) - 1 )
250%     Ec = getenergy('Online')*1e3 - E0;
251%%Ec = 100   
252%%Idip = 170
253% en attendant la reconnexion des équipements, simulation !
254% %     xdata = [-25:0.25:25];
255    xmin = min(xdata);
256    xmax = max(xdata);
257    sizex = size(xdata,2);
258
259   
260    % test sur une fonction erf pour le spectre integrï¿œ
261% %     z=-200:2:200;
262% %     ydata=(erf(z.*(1/50))-erf(-100.*(1/50)))/(erf(100.*(1/50))-erf(-100.*(1/50)));
263    sizey = size(ydata,2);
264
265   
266% %     % ydatab = donnï¿œes avec bruit superposï¿œ
267% %     coefficient = 0.0003;
268% %     ydatab = ydata+ coefficient *(1./abs(sqrt(ydata))).*randn(size(ydata));
269% %     toto = ydatab(51);
270% %     ydatab(51) = 0;
271    ydatab = ydata;
272    % on dérive les données bruitï¿œes (Dbruit)
273    %D = diff(ydata)./diff(xdata);
274    Dbruit = diff(ydatab)./diff(xdata);
275   
276    xdata2 = Ec *(1 - xdata*0.001 /dispersion );
277    xmin = min(xdata2);
278    xmax = max(xdata2);
279    sizex2 = size(xdata2,2);
280     
281    ResultsStr = {['I dipÃŽle [A] = ',num2str(Idip)],...
282        ['Ec sur l''axe [MeV] = ',num2str(Ec)],['D FAE [m] = ',num2str(dispersion)]};
283    set(handles.listbox1,'String',ResultsStr);
284    setappdata(handles.figure1,'Idip',num2str(Idip));
285    setappdata(handles.figure1,'Ecaxe',num2str(Ec));
286    setappdata(handles.figure1,'DFAE',num2str(dispersion));
287   
288    % graphe avec labels et valeurs ligne de transfert déduits des courants
289    % sur la machine
290    %______________________________________________________________________
291    axes(handles.axes1);
292    cla
293    plot(xdata,ydatab,'r')   
294    xlim([xmin xmax]);
295    xlabel('déplacement du mors en mm');
296    ylabel('charge normalisée');
297    title('intégrale du spectre','FontAngle','italic','FontSize',12,'FontWeight','bold');
298    %axis tight 
299    legend('données brutes',2);
300    legend('boxoff');
301    grid on;
302    drawnow;
303   
304    %__________________________________________________________________________
305    axes(handles.axes2);
306    cla
307 
308% test largeur gaussienne ᅵ +/- 1 sigma___________
309% % x = [-25:0.25:25];
310% % variance = 20.25;
311% % imaxx = 0.1;
312% % centrex = 0;
313% % g=imaxx*exp(-(x-centrex).*(x-centrex)/(2*variance));
314% %     
315% % plot(xdata(1:sizex-1),Dbruit,'r',...
316% %     x,g*max(Dbruit)/max(g),'b')
317% % xlim([min(xdata) max(xdata)]);
318%____________________________________
319
320    plot(xdata2(1:sizex-1),Dbruit,'r');
321    xlim([xmin xmax]);
322    xlabel('Energie en MeV');
323    ylabel('charge normalisée');
324    title('spectre','FontAngle','italic','FontSize',12,'FontWeight','bold');
325    drawnow;
326   
327    setappdata(handles.figure1,'ydata2',Dbruit);
328   
329    %____________________________________________________________________
330    % calcul de largeur du spectre
331    Itot = max(ydata);
332    Ipartielle = 0;
333    sizey = size(ydata,2);
334    j = 1;
335    i = 1;
336   
337    while abs(Ipartielle/Itot) < 0.3173
338       
339        if (ydatab(sizey-j+1)-ydatab(sizey-j)) < (ydatab(i+1)-ydatab(i))
340            Ipartielle = Ipartielle + (ydatab(sizey-j+1)-ydatab(sizey-j));
341            j = j+1;
342        else
343            Ipartielle = Ipartielle + (ydatab(i+1)-ydatab(i));
344            i = i+1;
345        end
346       
347    end
348   
349    ifinal = i;
350    jfinal = j;
351    Nbpx = sizey - ifinal - jfinal + 2;
352    %pasMeV = xdata2(2) - xdata2(1);
353    pasMeVf = (max(xdata)-min(xdata))/sizex;
354    LargeurMeV = Nbpx * pasMeV;
355    pasmm = xdata(2) - xdata(1);
356    Largeurmm = Nbpx * pasmm;
357   
358    % graphe du mesureur de charge n01
359    %______________________________________________________________________
360    axes(handles.axes3);
361    cla
362    plot(xdata2(1:sizex-1),ydatamc1(1:sizex-1),'b');
363    xlim([min(xdata2) max(xdata2)]);
364    xlabel('Energie en MeV');
365    ylabel('charge n01');
366    title('mesureur de charge n°1','FontAngle','italic','FontSize',12,'FontWeight','bold');
367    grid on;
368    drawnow;
369   
370end
371
372%% cas de la fente fixe (dipÃŽle actuator)
373if isequal(log2,1)
374   
375    % valeur de gap et du centre du gap
376    structure = tango_read_attribute(device_name.fente,'Gap');
377    gap = structure.value(1);
378    structure = tango_read_attribute(device_name.fente,'Position');
379    position = structure.value(1);
380    valgap=sprintf('%2.1f',gap);
381    resolution = 100*gap*1e-3/(dispersion);
382    valresolution = sprintf('%2.1f',abs(resolution));
383    valposition=sprintf('%2.1f',position);
384   
385    %     xdata = [30:230];
386    xmin = min(xdata);
387    xmax = max(xdata);
388    sizex = size(xdata,2);
389   
390    % %     z=-100:100;
391    %     %%1% variance = 0.25;
392    %     variance = 0.001;
393    %     imazz = 1;
394    %     centrez = 30;
395    %     ydata=imazz*exp(-(z/50-centrez/50).*(z/50-centrez/50)/(2*variance));
396    sizey = size(ydata,2);
397   
398    %     % ydatab = donnï¿œes avec bruit superposï¿œ
399    %     %%1% coef = 0.0002;
400    %     %coef = 0.001;
401    %     coef = 0.005;
402    %     %ydatab = ydata+coef*(1./abs(sqrt(ydata))).*randn(size(ydata));
403    %     ydatab = ydata+coef*(1./abs(sqrt(ydata + 0.01))).*randn(size(ydata));
404    ydatab = ydata;
405    maxydatab = max(ydatab);
406
407    ResultsStr = {['Gap = ',valgap,' mm'],...
408        ['Position du gap = ',valposition,' mm'],['Résolution = ',valresolution,' %']};
409    set(handles.listbox1,'String',ResultsStr);
410   
411%     [C, Leff, MagnetType, A] = magnetcoefficients('BEND');
412%     B0 = A(9);
413%     B1 = A(8);
414%     angle = 15 * pi / 180;
415%     E0 = 0.51099906 ;
416%     xdata2 = E0 *  (sqrt(1 + ((B0 + xdata* B1 ).*0.29979/ angle).*...
417%         ((B0 + xdata* B1 ).*0.29979/ angle)/((E0*0.001)*(E0*0.001))) - 1 );
418
419   
420    for i = 1:size(xdata,2)
421            xdata2(i) = 1000 * hw2physics('BEND','Setpoint',xdata(i),[1 1]);
422    end
423    xdata2 = xdata2 * (1 - position*0.001/dispersion);
424    xmin2 = min(xdata2);
425    xmax2 = max(xdata2);
426    sizex2 = size(xdata2,2);
427
428     
429%% PLOT   
430    %_____________________________________________________________________
431    axes(handles.axes1);
432    cla
433   
434    % %         % test largeur gaussienne ï¿œ +/- 1 sigma___________
435    % % % %x = [-25:0.25:25];
436    % % x = [30:1:230];
437    % % variance = 625;
438    % % imaxx = 0.1;
439    % % centrex = 160;
440    % % g=imaxx*exp(-(x-centrex).*(x-centrex)/(2*variance));
441    % %     
442    % % plot(xdata(1:sizex),ydatab,'r',...
443    % %     x,g*max(ydatab)/max(g),'b')
444    % % xlim([min(xdata) max(xdata)]);
445    %____________________________________
446    plot(xdata,ydatab,'r');
447    xlim([xmin xmax]);
448    xlabel('courant du dipÃŽle en A');
449    ylabel('charge normalisée');
450    title('spectre brut','FontAngle','italic','FontSize',12,'FontWeight','bold');
451    grid on
452    %_____________________________________________________________________
453    axes(handles.axes2);
454    cla   
455    % le calcul de xdata2 doit tenir compte du dï¿œcalage du gap par rapport
456    % à l'axe théorique (valeur de l'attribut position)
457
458    plot(xdata2,ydatab,'r');
459    xlim([xmin2 xmax2]);
460   
461    xlabel('Energie en MeV');
462    ylabel('charge normalisée');
463    title('spectre corrigé','FontAngle','italic','FontSize',12,'FontWeight','bold');
464    grid on
465    %______________________________________________________________________
466    axes(handles.axes3);
467    cla
468   
469    plot(xdata2(1:sizex-1),ydatamc1(1:sizex-1),'b');
470    xlim([xmin2 xmax2]);
471    xlabel('Energie en MeV');
472    ylabel('charge n01');
473    title('mesureur de charge n°1','FontAngle','italic','FontSize',12,'FontWeight','bold');
474    grid on;
475    drawnow;
476   
477%% calcul de largeur du spectre non lissé
478    %Itot = max(yfiltre1)
479   
480    Itot = trapz(xdata2(1:size(ydatab,2)),ydatab(1:size(ydatab,2)));
481   
482    sizey = size(ydatab,2);
483    Ipartielle = 0;
484    j = 1;
485    i = 1;
486    dx = xdata2(sizey) - xdata2(sizey - 1);
487   
488   
489    while abs(Ipartielle/Itot) < 0.3173
490       
491        if ydatab(sizey-j+1) < ydatab(i+1)
492            Ipartielle = Ipartielle + ydatab(sizey-j)*dx;
493            j = j+1;
494        else
495            Ipartielle = Ipartielle + ydatab(i)*dx;
496            i = i+1;
497        end
498       
499    end
500   
501    ifinal = i;
502    jfinal = j;
503    Nbpxf = sizey - ifinal - jfinal + 2;
504    %pasMeVf = xdata2(2) - xdata2(1);
505    pasMeVf = (max(xdata)-min(xdata))/sizex;
506    LargeurMeVf = Nbpxf * pasMeVf;
507    pasAf = xdata(2) - xdata(1);
508    LargeurAf = Nbpxf * pasAf;
509   
510   
511     [Y,I] = max(ydatab);
512     dpsurp = 100 * LargeurMeVf / xdata2(I);
513     val1=sprintf('%2.2f',dpsurp);
514     %dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
515     dpsurpcorr = sqrt(dpsurp*dpsurp - resolution*resolution);
516     val2=sprintf('%2.2f',dpsurpcorr);
517     ResultsStr = get(handles.listbox1,'String');
518     
519     ResultsStr = {ResultsStr{:},...
520         [],['Largeur corrigée du spectre non lissé : (Epeack =' ,sprintf('%2.3f',xdata2(I)),' MeV)'],...
521        ['68 % des e- dans ',val2,' % de Epeack']}';
522    set(handles.listbox1,'String',ResultsStr);
523%     
524%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
525   
526    Ipartielle = 0;
527    j = 1;
528    i = 1;
529    dx = xdata2(sizey) - xdata2(sizey - 1);
530   
531   
532    while abs(Ipartielle/Itot) < 0.20
533       
534        if ydatab(sizey-j+1) < ydatab(i+1)
535            Ipartielle = Ipartielle + ydatab(sizey-j)*dx;
536            j = j+1;
537        else
538            Ipartielle = Ipartielle + ydatab(i)*dx;
539            i = i+1;
540        end
541       
542    end
543   
544    ifinal = i;
545    jfinal = j;
546    Nbpxf = sizey - ifinal - jfinal + 2;
547    %pasMeVf = xdata2(2) - xdata2(1);
548    pasMeVf = (max(xdata)-min(xdata))/sizex;
549    LargeurMeVf = Nbpxf * pasMeVf;
550    pasAf = xdata(2) - xdata(1);
551    LargeurAf = Nbpxf * pasAf;
552   
553   
554     [Y,I] = max(ydatab);
555     dpsurp = 100 * LargeurMeVf / xdata2(I);
556     val1=sprintf('%2.2f',dpsurp);
557     %dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
558     dpsurpcorr = sqrt(dpsurp*dpsurp - resolution*resolution);
559     val2=sprintf('%2.2f',dpsurpcorr);
560     ResultsStr = get(handles.listbox1,'String');
561     
562     ResultsStr = {ResultsStr{:}, ...
563        ['80 % des e- dans ',val2,' % de Epeack']}';
564    set(handles.listbox1,'String',ResultsStr);
565%     
566%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
567
568    Ipartielle = 0;
569    j = 1;
570    i = 1;
571    dx = xdata2(sizey) - xdata2(sizey - 1);
572   
573   
574    while abs(Ipartielle/Itot) < 0.10
575       
576        if ydatab(sizey-j+1) < ydatab(i+1)
577            Ipartielle = Ipartielle + ydatab(sizey-j)*dx;
578            j = j+1;
579        else
580            Ipartielle = Ipartielle + ydatab(i)*dx;
581            i = i+1;
582        end
583       
584    end
585   
586    ifinal = i;
587    jfinal = j;
588    Nbpxf = sizey - ifinal - jfinal + 2;
589    %pasMeVf = xdata2(2) - xdata2(1);
590    pasMeVf = (max(xdata)-min(xdata))/sizex;
591    LargeurMeVf = Nbpxf * pasMeVf;
592    pasAf = xdata(2) - xdata(1);
593    LargeurAf = Nbpxf * pasAf;
594   
595   
596     [Y,I] = max(ydatab);
597     dpsurp = 100 * LargeurMeVf / xdata2(I);
598     val1=sprintf('%2.2f',dpsurp);
599     %dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
600     dpsurpcorr = sqrt(dpsurp*dpsurp - resolution*resolution);
601     val2=sprintf('%2.2f',dpsurpcorr);
602     ResultsStr = get(handles.listbox1,'String');
603     
604     ResultsStr = {ResultsStr{:}, ...
605        ['90 % des e- dans ',val2,' % de Epeack']}';
606     set(handles.listbox1,'String',ResultsStr);
607   
608
609end
610
611%% cas de la position du gap actuator
612if isequal(log3,1)
613   
614    % valeur de l'aimant et de la largeur du gap
615    % la valeur de l'aimant représente l'énergie sur l'axe
616    structure = tango_read_attribute(device_name.fente,'Gap');
617    gap = structure.value(1);
618    valgap=sprintf('%2.1f',gap);
619   
620    dev = device_name.dipole;
621    structure = tango_read_attribute(dev,'current');
622    courant = structure.value(1);
623    energie = 1000*hw2physics('BEND','Setpoint',courant,[1 1])
624    set(handles.repositionner_edit3,'String',num2str(energie));
625   
626    resolution = 100*gap*1e-3/(dispersion);
627    valresolution = sprintf('%2.1f',abs(resolution));
628   
629    %__________________________________________________________________
630    xdata2 = energie * (1 - xdata.*0.001/dispersion);
631    xmin = min(xdata);xmax = max(xdata);sizex = size(xdata,2);
632    xmin2 = min(xdata2);xmax2 = max(xdata2);sizex2 = size(xdata2,2);
633    sizey = size(ydata,2);
634   
635    %__________________________________________________________________
636    %ydatab = ydata;
637    ydata2 = -ydata./(gap*0.001*xdata2/dispersion);
638    maxydata2 = max(ydata2);
639    ResultsStr = {['Gap = ',valgap,' mm'],...
640        ['Résolution = ',valresolution,' %']};
641    set(handles.listbox1,'String',ResultsStr);
642%% PLOT
643    %_____________________________________________________________________
644    axes(handles.axes1);
645    cla
646    plot(xdata,ydata,'r')   
647    xlim([xmin xmax]);
648    xlabel('deplacement du gap en mm');
649    ylabel('charge normalisée');
650    title('spectre brut','FontAngle','italic','FontSize',12,'FontWeight','bold');
651    grid on
652    %_____________________________________________________________________
653    axes(handles.axes2);
654    cla
655    plot(xdata2,ydata2,'r')   
656    xlim([xmin2 xmax2]);
657   
658    xlabel('Energie en MeV');
659    ylabel('charge normalisée');
660    title('spectre corrigé','FontAngle','italic','FontSize',12,'FontWeight','bold');
661    grid on
662    %______________________________________________________________________
663    axes(handles.axes3);
664    cla
665   
666    plot(xdata2(1:sizex-1),ydatamc1(1:sizex-1),'b');
667    xlim([xmin2 xmax2]);
668    xlabel('Energie en MeV');
669    ylabel('charge n01');
670    title('mesureur de charge n°1','FontAngle','italic','FontSize',12,'FontWeight','bold');
671    grid on;
672    drawnow;
673   
674end
675
676   
677setappdata(handles.figure1,'xdata',xdata);
678setappdata(handles.figure1,'xdata2',xdata2);
679setappdata(handles.figure1,'ydata',ydata);
680setappdata(handles.figure1,'ydata2',ydata2);
681
682
683if isequal(mode,'Simulator')
684    switch2sim
685    test_mode = getmode('BEND')
686end
687
688% --------------------------------------------------------------------
689function FileMenu_Callback(hObject, eventdata, handles)
690% hObject    handle to FileMenu (see GCBO)
691% eventdata  reserved - to be defined in a future version of MATLAB
692% handles    structure with handles and user data (see GUIDATA)
693
694
695% --------------------------------------------------------------------
696function OpenMenuItem_Callback(hObject, eventdata, handles)
697% hObject    handle to OpenMenuItem (see GCBO)
698% eventdata  reserved - to be defined in a future version of MATLAB
699% handles    structure with handles and user data (see GUIDATA)
700file = uigetfile('*.fig');
701if ~isequal(file, 0)
702    open(file);
703end
704
705% --------------------------------------------------------------------
706function PrintMenuItem_Callback(hObject, eventdata, handles)
707% hObject    handle to PrintMenuItem (see GCBO)
708% eventdata  reserved - to be defined in a future version of MATLAB
709% handles    structure with handles and user data (see GUIDATA)
710printdlg(handles.figure1)
711
712% --------------------------------------------------------------------
713function CloseMenuItem_Callback(hObject, eventdata, handles)
714% hObject    handle to CloseMenuItem (see GCBO)
715% eventdata  reserved - to be defined in a future version of MATLAB
716% handles    structure with handles and user data (see GUIDATA)
717selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
718                     ['Close ' get(handles.figure1,'Name') '...'],...
719                     'Yes','No','Yes');
720if strcmp(selection,'No')
721    return;
722end
723
724delete(handles.figure1)
725
726
727% --- Executes on selection change in popupmenu1.
728function popupmenu1_Callback(hObject, eventdata, handles)
729% hObject    handle to popupmenu1 (see GCBO)
730% eventdata  reserved - to be defined in a future version of MATLAB
731% handles    structure with handles and user data (see GUIDATA)
732
733% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
734%        contents{get(hObject,'Value')} returns selected item from popupmenu1
735
736
737% --- Executes during object creation, after setting all properties.
738function popupmenu1_CreateFcn(hObject, eventdata, handles)
739% hObject    handle to popupmenu1 (see GCBO)
740% eventdata  reserved - to be defined in a future version of MATLAB
741% handles    empty - handles not created until after all CreateFcns called
742
743% Hint: popupmenu controls usually have a white background on Windows.
744%       See ISPC and COMPUTER.
745if ispc
746    set(hObject,'BackgroundColor','white');
747else
748    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
749end
750
751set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'});
752
753
754% --- Executes on selection change in listbox1.
755function listbox1_Callback(hObject, eventdata, handles)
756% hObject    handle to listbox1 (see GCBO)
757% eventdata  reserved - to be defined in a future version of MATLAB
758% handles    structure with handles and user data (see GUIDATA)
759
760% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
761%        contents{get(hObject,'Value')} returns selected item from listbox1
762
763
764% --- Executes during object creation, after setting all properties.
765function listbox1_CreateFcn(hObject, eventdata, handles)
766% hObject    handle to listbox1 (see GCBO)
767% eventdata  reserved - to be defined in a future version of MATLAB
768% handles    empty - handles not created until after all CreateFcns called
769
770% Hint: listbox controls usually have a white background on Windows.
771%       See ISPC and COMPUTER.
772if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
773    set(hObject,'BackgroundColor','white');
774end
775
776
777% --- Executes on button press in Dipfixe_radiobutton1.
778function Dipfixe_radiobutton1_Callback(hObject, eventdata, handles)
779% hObject    handle to Dipfixe_radiobutton1 (see GCBO)
780% eventdata  reserved - to be defined in a future version of MATLAB
781% handles    structure with handles and user data (see GUIDATA)
782
783% Hint: get(hObject,'Value') returns toggle state of Dipfixe_radiobutton1
784
785% cas du dipï¿œle fixe
786% log1=get(handles.Dipfixe_radiobutton1,'Value');
787% log2=get(handles.Fenfixe_radiobutton2,'Value');
788%
789% if isequal(log1,1)
790
791
792
793% --- Executes on button press in Fenfixe_radiobutton2.
794function Fenfixe_radiobutton2_Callback(hObject, eventdata, handles)
795% hObject    handle to Fenfixe_radiobutton2 (see GCBO)
796% eventdata  reserved - to be defined in a future version of MATLAB
797% handles    structure with handles and user data (see GUIDATA)
798
799% Hint: get(hObject,'Value') returns toggle state of Fenfixe_radiobutton2
800
801% labels
802
803
804% --- Executes on button press in Lissage_pushbutton2.
805function Lissage_pushbutton2_Callback(hObject, eventdata, handles)
806% hObject    handle to Lissage_pushbutton2 (see GCBO)
807% eventdata  reserved - to be defined in a future version of MATLAB
808% handles    structure with handles and user data (see GUIDATA)
809
810% test du mode
811test_mode = getmode('BEND')
812
813log1=get(handles.Dipfixe_radiobutton1,'Value');
814log2=get(handles.Fenfixe_radiobutton2,'Value');
815
816xdata = getappdata(handles.figure1,'xdata');
817xdata2 = getappdata(handles.figure1,'xdata2');
818ydatab = getappdata(handles.figure1,'ydata');
819xmin = min(xdata);
820xmax = max(xdata);
821xmax2 = max(xdata2);
822sizex = size(xdata,2);
823sizex2 = size(xdata2,2);
824
825%______________________________________________________________________
826axes(handles.axes1);
827hold on
828
829% yfiltre lisse ydata bruitᅵ
830a=1;
831%windowSize=round(sizex/10)
832%windowSize=round(sizex/20)
833windowSize = str2double(get(handles.WindowSize_edit2,'String'));
834
835b = ones(1,windowSize)/windowSize;
836yfiltre=filter(b,a,ydatab);
837
838% yfiltre1 repositionne yfiltre au milieu de la fenï¿œtre windowsize
839yfiltre1=yfiltre(ceil(windowSize/2):sizex);
840
841plot(...
842xdata(1:size(yfiltre1,2)),yfiltre1(1:size(yfiltre1,2)));
843%xdata(1:size(yfiltre1,2)-ceil(windowSize/2)),yfiltre1(1:size(yfiltre1,2)-ceil(windowSize/2)));   
844%xlim([xmin xmax]);
845
846legend('données brutes','données lissées',2);
847legend('boxoff');
848grid on;
849
850%__________________________________________________________________________
851axes(handles.axes2);
852hold on
853% cas du dipï¿œle fixe
854if isequal(log1,1)
855   
856    % on dï¿œrive les donnï¿œes lissï¿œes (Dfiltre)
857
858    %D = diff(ydata)./diff(xdata);
859    Dfiltre = diff(yfiltre1(1:sizex-ceil(windowSize/2)))./diff(xdata(1:sizex-ceil(windowSize/2)));
860    plot(...
861        xdata2(1:size(Dfiltre,2)),Dfiltre(1:size(Dfiltre,2)));
862       % xdata2(ceil(windowSize/2):sizex-ceil(windowSize/2)-1),Dfiltre(ceil(windowSize/2):sizex-ceil(windowSize/2)-1),'b');
863    %xlim([xmin xmax]);
864    %ylim([min(Dfiltre(ceil(windowSize/2):sizex-ceil(windowSize/2)-1) ) ...
865    %    max(Dfiltre(ceil(windowSize/2):sizex-ceil(windowSize/2)-1))]);
866
867    setappdata(handles.figure1,'Dfiltre',Dfiltre);
868   
869    %____________________________________________________________________
870    % calcul de largeur du spectre
871    Itot = max(yfiltre1);
872    sizey = size(yfiltre1,2);
873    Ipartielle = 0;
874    j = 1;
875    i = 1;
876   
877    while abs(Ipartielle/Itot) < 0.3173
878       
879        if (yfiltre1(sizey-j+1)-yfiltre1(sizey-j)) < (yfiltre1(i+1)-yfiltre1(i))
880            Ipartielle = Ipartielle + (yfiltre1(sizey-j+1)-yfiltre1(sizey-j));
881            j = j+1;
882        else
883            Ipartielle = Ipartielle + (yfiltre1(i+1)-yfiltre1(i));
884            i = i+1;
885        end
886       
887    end
888   
889    ifinal = i;
890    jfinal = j;
891    Nbpxf = sizey - ifinal - jfinal + 2;
892    %pasMeVf = xdata2(2) - xdata2(1);
893    pasMeVf = (max(xdata)-min(xdata))/sizex;
894    LargeurMeVf = Nbpxf * pasMeVf;
895    pasmmf = xdata(2) - xdata(1);
896    Largeurmmf = Nbpxf * pasmmf;
897   
898   
899    [Y,I] = max(Dfiltre);
900    dpsurp = 100 * LargeurMeVf / xdata2(I);
901    val=sprintf('%2.2f',dpsurp);
902    ResultsStr = get(handles.listbox1,'String');
903    ResultsStr = {ResultsStr{:},...
904        [],['Largeur du spectre  : (Epeack = ',sprintf('%2.3f',xdata2(I)),' MeV)'],...
905        ['68 % des e- dans ',val,' % de Epeack']}';
906    set(handles.listbox1,'String',ResultsStr);
907   
908    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909   
910    Ipartielle = 0;
911    j = 1;
912    i = 1;
913   
914    while abs(Ipartielle/Itot) < 0.2
915       
916        if (yfiltre1(sizey-j+1)-yfiltre1(sizey-j)) < (yfiltre1(i+1)-yfiltre1(i))
917            Ipartielle = Ipartielle + (yfiltre1(sizey-j+1)-yfiltre1(sizey-j));
918            j = j+1;
919        else
920            Ipartielle = Ipartielle + (yfiltre1(i+1)-yfiltre1(i));
921            i = i+1;
922        end
923       
924    end
925   
926    ifinal = i;
927    jfinal = j;
928    Nbpxf = sizey - ifinal - jfinal + 2;
929    %pasMeVf = xdata2(2) - xdata2(1);
930    pasMeVf = (max(xdata)-min(xdata))/sizex;
931    LargeurMeVf = Nbpxf * pasMeVf;
932    pasmmf = xdata(2) - xdata(1);
933    Largeurmmf = Nbpxf * pasmmf;
934   
935   
936    [Y,I] = max(Dfiltre);
937    dpsurp = 100 * LargeurMeVf / xdata2(I);
938    val=sprintf('%2.2f',dpsurp);
939    ResultsStr = get(handles.listbox1,'String');
940    ResultsStr = {ResultsStr{:}, ...
941        ['80 % des e- dans ',val,' % de Epeack']}'  ; 
942        %['Largeur ï¿œ 80 % =  ',val,' %']}'
943    set(handles.listbox1,'String',ResultsStr);
944   
945    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946   
947    Ipartielle = 0;
948    j = 1;
949    i = 1;
950   
951    while abs(Ipartielle/Itot) < 0.1
952       
953        if (yfiltre1(sizey-j+1)-yfiltre1(sizey-j)) < (yfiltre1(i+1)-yfiltre1(i))
954            Ipartielle = Ipartielle + (yfiltre1(sizey-j+1)-yfiltre1(sizey-j));
955            j = j+1;
956        else
957            Ipartielle = Ipartielle + (yfiltre1(i+1)-yfiltre1(i));
958            i = i+1;
959        end
960       
961    end
962   
963    ifinal = i;
964    jfinal = j;
965    Nbpxf = sizey - ifinal - jfinal + 2;
966    %pasMeVf = xdata2(2) - xdata2(1);
967    pasMeVf = (max(xdata)-min(xdata))/sizex;
968    LargeurMeVf = Nbpxf * pasMeVf;
969    pasmmf = xdata(2) - xdata(1);
970    Largeurmmf = Nbpxf * pasmmf;
971   
972   
973    [Y,I] = max(Dfiltre);
974    dpsurp = 100 * LargeurMeVf / xdata2(I);
975    val=sprintf('%2.2f',dpsurp);
976    ResultsStr = get(handles.listbox1,'String');
977    ResultsStr = {ResultsStr{:}, ...
978        ['90 % des e- dans ',val,' % de Epeack']}';
979        %['Largeur ï¿œ 90 % =  ',val,' %']}'
980    set(handles.listbox1,'String',ResultsStr);
981   
982end
983
984% cas du dipï¿œle fixe
985if isequal(log2,1)
986   
987    % on ï¿œcrase la donnï¿œe Dfiltre
988    setappdata(handles.figure1,'Dfiltre',[]);
989   
990    plot(...
991    xdata2(1:size(yfiltre1,2)),yfiltre1(1:size(yfiltre1,2)));
992    %xdata(1:size(yfiltre1,2)-ceil(windowSize/2)),yfiltre1(1:size(yfiltre1,2)-ceil(windowSize/2)));   
993    %xlim([xmin xmax]);
994
995    %____________________________________________________________________
996    % calcul de largeur du spectre
997    %Itot = max(yfiltre1)
998   
999    Itot = trapz(xdata2(1:size(yfiltre1,2)),yfiltre1(1:size(yfiltre1,2)));
1000   
1001    sizey = size(yfiltre1,2);
1002    Ipartielle = 0;
1003    j = 1;
1004    i = 1;
1005    dx = xdata2(sizey) - xdata2(sizey - 1);
1006   
1007   
1008    while abs(Ipartielle/Itot) < 0.3173
1009       
1010        if yfiltre1(sizey-j+1) < yfiltre1(i+1)
1011            Ipartielle = Ipartielle + yfiltre1(sizey-j)*dx;
1012            j = j+1;
1013        else
1014            Ipartielle = Ipartielle + yfiltre1(i)*dx;
1015            i = i+1;
1016        end
1017       
1018    end
1019   
1020    ifinal = i;
1021    jfinal = j;
1022    Nbpxf = sizey - ifinal - jfinal + 2;
1023    %pasMeVf = xdata2(2) - xdata2(1);
1024    pasMeVf = (max(xdata)-min(xdata))/sizex;
1025    LargeurMeVf = Nbpxf * pasMeVf;
1026    pasmmf = xdata(2) - xdata(1);
1027    Largeurmmf = Nbpxf * pasmmf;
1028   
1029   
1030     [Y,I] = max(yfiltre1);
1031     dpsurp = 100 * LargeurMeVf / xdata2(I);
1032     val1=sprintf('%2.2f',dpsurp);
1033     dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
1034     val2=sprintf('%2.2f',dpsurpcorr);
1035     ResultsStr = get(handles.listbox1,'String');
1036     ResultsStr = {ResultsStr{:}, ...
1037         [],['Largeur corrigée du spectre lissé : (Epeack =' ,sprintf('%2.3f',xdata2(I)),' MeV)'],...
1038         [' 68 % des e- dans ',val2,' % de Epeack'],...
1039         }';
1040    set(handles.listbox1,'String',ResultsStr);
1041%     
1042%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1043    Ipartielle = 0;
1044    j = 1;
1045    i = 1;
1046    dx = xdata2(sizey) - xdata2(sizey - 1);
1047   
1048   
1049    while abs(Ipartielle/Itot) < 0.2
1050       
1051        if yfiltre1(sizey-j+1) < yfiltre1(i+1)
1052            Ipartielle = Ipartielle + yfiltre1(sizey-j)*dx;
1053            j = j+1;
1054        else
1055            Ipartielle = Ipartielle + yfiltre1(i)*dx;
1056            i = i+1;
1057        end
1058       
1059    end
1060   
1061    ifinal = i;
1062    jfinal = j;
1063    Nbpxf = sizey - ifinal - jfinal + 2;
1064    %pasMeVf = xdata2(2) - xdata2(1);
1065    pasMeVf = (max(xdata)-min(xdata))/sizex;
1066    LargeurMeVf = Nbpxf * pasMeVf;
1067    pasmmf = xdata(2) - xdata(1);
1068    Largeurmmf = Nbpxf * pasmmf;
1069   
1070   
1071     [Y,I] = max(yfiltre1);
1072     dpsurp = 100 * LargeurMeVf / xdata2(I);
1073     val1=sprintf('%2.2f',dpsurp);
1074     dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
1075     val2=sprintf('%2.2f',dpsurpcorr);
1076     ResultsStr = get(handles.listbox1,'String');
1077     ResultsStr = {ResultsStr{:}, ...
1078         [' 80 % des e- dans ',val2,' % de Epeack'],...
1079         }';
1080    set(handles.listbox1,'String',ResultsStr);
1081%     
1082%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1083   
1084    Ipartielle = 0;
1085    j = 1;
1086    i = 1;
1087    dx = xdata2(sizey) - xdata2(sizey - 1);
1088   
1089   
1090    while abs(Ipartielle/Itot) < 0.1
1091       
1092        if yfiltre1(sizey-j+1) < yfiltre1(i+1)
1093            Ipartielle = Ipartielle + yfiltre1(sizey-j)*dx;
1094            j = j+1;
1095        else
1096            Ipartielle = Ipartielle + yfiltre1(i)*dx;
1097            i = i+1;
1098        end
1099       
1100    end
1101   
1102    ifinal = i;
1103    jfinal = j;
1104    Nbpxf = sizey - ifinal - jfinal + 2;
1105    %pasMeVf = xdata2(2) - xdata2(1);
1106    pasMeVf = (max(xdata)-min(xdata))/sizex;
1107    LargeurMeVf = Nbpxf * pasMeVf;
1108    pasmmf = xdata(2) - xdata(1);
1109    Largeurmmf = Nbpxf * pasmmf;
1110   
1111   
1112     [Y,I] = max(yfiltre1);
1113     dpsurp = 100 * LargeurMeVf / xdata2(I);
1114     val1=sprintf('%2.2f',dpsurp);
1115     dpsurpcorr = sqrt(dpsurp*dpsurp - 0.5*0.5);
1116     val2=sprintf('%2.2f',dpsurpcorr);
1117     ResultsStr = get(handles.listbox1,'String');
1118     ResultsStr = {ResultsStr{:}, ...
1119         [' 90 % des e- dans ',val2,' % de Epeack'],...
1120         }';
1121    set(handles.listbox1,'String',ResultsStr);
1122%     
1123%     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1124end
1125
1126setappdata(handles.figure1,'yfiltre',yfiltre1);
1127
1128
1129function horodatage_edit1_Callback(hObject, eventdata, handles)
1130% hObject    handle to horodatage_edit1 (see GCBO)
1131% eventdata  reserved - to be defined in a future version of MATLAB
1132% handles    structure with handles and user data (see GUIDATA)
1133
1134% Hints: get(hObject,'String') returns contents of horodatage_edit1 as text
1135%        str2double(get(hObject,'String')) returns contents of horodatage_edit1 as a double
1136
1137
1138% --- Executes during object creation, after setting all properties.
1139function horodatage_edit1_CreateFcn(hObject, eventdata, handles)
1140% hObject    handle to horodatage_edit1 (see GCBO)
1141% eventdata  reserved - to be defined in a future version of MATLAB
1142% handles    empty - handles not created until after all CreateFcns called
1143
1144% Hint: edit controls usually have a white background on Windows.
1145%       See ISPC and COMPUTER.
1146if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1147    set(hObject,'BackgroundColor','white');
1148end
1149
1150
1151
1152function WindowSize_edit2_Callback(hObject, eventdata, handles)
1153% hObject    handle to WindowSize_edit2 (see GCBO)
1154% eventdata  reserved - to be defined in a future version of MATLAB
1155% handles    structure with handles and user data (see GUIDATA)
1156
1157% Hints: get(hObject,'String') returns contents of WindowSize_edit2 as text
1158%        str2double(get(hObject,'String')) returns contents of WindowSize_edit2 as a double
1159
1160
1161% --- Executes during object creation, after setting all properties.
1162function WindowSize_edit2_CreateFcn(hObject, eventdata, handles)
1163% hObject    handle to WindowSize_edit2 (see GCBO)
1164% eventdata  reserved - to be defined in a future version of MATLAB
1165% handles    empty - handles not created until after all CreateFcns called
1166
1167% Hint: edit controls usually have a white background on Windows.
1168%       See ISPC and COMPUTER.
1169if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1170    set(hObject,'BackgroundColor','white');
1171end
1172
1173
1174% --- Executes on button press in sauvegarder_pushbutton6.
1175function sauvegarder_pushbutton6_Callback(hObject, eventdata, handles)
1176% hObject    handle to sauvegarder_pushbutton6 (see GCBO)
1177% eventdata  reserved - to be defined in a future version of MATLAB
1178% handles    structure with handles and user data (see GUIDATA)
1179
1180log1=get(handles.Dipfixe_radiobutton1,'Value');
1181log2=get(handles.Fenfixe_radiobutton2,'Value');
1182log3=get(handles.Gap_radiobutton3,'Value')
1183
1184% Determine file and directory name
1185FileName = '1';
1186
1187%DirectoryName = '/home/PM/nadolski/controlroom/measdata/LT1data/';
1188DirectoryName = getfamilydata('Directory','FAEData');
1189
1190
1191TimeStamp = getappdata(handles.figure1,'Date');
1192
1193% en attendant le time stamp de Florent
1194%TimeStamp = clock;
1195
1196% Append date_Time to FileName
1197FileName = sprintf('%s_%s', datestr(TimeStamp,31), FileName);
1198FileName(11) = '_';
1199FileName(14) = '-';
1200FileName(17) = '-';
1201
1202%FileName = appendtimestamp(FileName, clock);
1203[FileName, DirectoryName] = uiputfile('*','Save Lattice to ...', [DirectoryName FileName]);
1204if FileName == 0
1205    fprintf('   File not saved (getmachineconfig)\n');
1206    return;
1207end
1208
1209% afficher le nom du fichier
1210set(handles.nom_fichier_edit7,'String',FileName);
1211
1212% Save all data in structure to file
1213DirStart = pwd;
1214[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName); 
1215xdata = getappdata(handles.figure1,'xdata');
1216ydata = getappdata(handles.figure1,'ydata');
1217xdata2 = getappdata(handles.figure1,'xdata2');
1218yfiltre = getappdata(handles.figure1,'yfiltre');
1219ydatamc1 = getappdata(handles.figure1,'ydatamc1');
1220ResultsStr = get(handles.listbox1,'String');
1221horodatage = get(handles.horodatage_edit1,'String');
1222mc1_charge =   get(handles.mc1_charge_edit5,'String');
1223mc1_calibre = get(handles.mc1_calibre_edit6,'String');
1224
1225try
1226    % cas du dipï¿œle fixe
1227    if isequal(log1,1)
1228       Dfiltre = getappdata(handles.figure1,'Dfiltre');
1229       ydata2 = getappdata(handles.figure1,'ydata2');
1230       save(FileName, 'xdata', 'ydata','xdata2','ydata2',...
1231            'yfiltre','ydatamc1','Dfiltre','ResultsStr','log1','log2','log3',...
1232            'horodatage',...
1233            'mc1_charge','mc1_calibre')
1234
1235    elseif  isequal(log2,1)
1236       save(FileName, 'xdata', 'ydata','xdata2','yfiltre','ydatamc1',...
1237           'ResultsStr','log1','log2','log3','horodatage','mc1_charge','mc1_calibre')   
1238       
1239    else
1240        ydata2 = getappdata(handles.figure1,'ydata2');
1241        save(FileName, 'xdata', 'ydata','xdata2','ydata2','yfiltre','ydatamc1',...
1242           'ResultsStr','log1','log2','log3','horodatage','mc1_charge','mc1_calibre')
1243    end
1244   
1245catch
1246    cd(DirStart);
1247    return
1248end
1249cd(DirStart);
1250
1251
1252% --- Executes on button press in restaurer_pushbutton7.
1253function restaurer_pushbutton7_Callback(hObject, eventdata, handles)
1254% hObject    handle to restaurer_pushbutton7 (see GCBO)
1255% eventdata  reserved - to be defined in a future version of MATLAB
1256% handles    structure with handles and user data (see GUIDATA)
1257
1258DirectoryName = getfamilydata('Directory','FAEData')
1259DirStart = pwd;
1260[DirectoryName, DirectoryErrorFlag] = gotodirectory(DirectoryName); 
1261[FileName, DirectoryName] = uigetfile('*','Select a file ...');
1262if FileName == 0
1263    fprintf('  no File picked (getmachineconfig)\n');
1264    return;
1265else
1266    load(FileName)
1267end
1268
1269
1270
1271% afficher
1272try
1273    set(handles.listbox1,'String',ResultsStr);
1274    set(handles.horodatage_edit1,'String',horodatage);
1275    set(handles.mc1_charge_edit5,'String',mc1_charge);
1276    set(handles.mc1_calibre_edit6,'String',mc1_calibre);
1277    setappdata(handles.figure1,'ydata',ydata);
1278    setappdata(handles.figure1,'xdata2',xdata2);
1279    setappdata(handles.figure1,'xdata',xdata);
1280    setappdata(handles.figure1,'ydata2',ydata2);
1281    set(handles.nom_fichier_edit7,'String',FileName);
1282    % _____________________________________________________________________
1283    axes(handles.axes1);
1284    cla
1285   
1286
1287    %if isequal(log1,1)
1288    plot(xdata,ydata,'r',...
1289            xdata(1:size(yfiltre,2)),yfiltre(1:size(yfiltre,2)));
1290    %else
1291       % plot(xdata,ydata,'r',...
1292       %     xdata(1:size(yfiltre,2)),yfiltre1(1:size(yfiltre,2)));
1293    %end
1294   
1295    xlim([min(xdata) max(xdata)]);
1296   
1297% %     if isequal(log1,1)
1298% %         xlabel('déplacement du mors en mm');
1299% %         ylabel('charge normalisée');
1300% %         title('intégrale du spectre','FontAngle','italic','FontSize',12,'FontWeight','bold');
1301% %         
1302%     elseif isequal(log2,1)
1303%         xlabel('courant du dipÃŽle en A');
1304%         ylabel('charge normalisée');
1305%         title('spectre brut','FontAngle','italic','FontSize',12,'FontWeight','bold');
1306%     else
1307        xlabel('déplacement du gap en mm');
1308        ylabel('charge normalisée');
1309        title('spectre brut','FontAngle','italic','FontSize',12,'FontWeight','bold');
1310 %%   end
1311    %axis tight
1312   
1313    legend('données brutes',2);
1314    legend('boxoff');
1315    grid on;
1316    drawnow;
1317   
1318    %______________________________________________________________________
1319    axes(handles.axes2);
1320    cla
1321   
1322    sizex = size(xdata2,2);
1323
1324% %     if isequal(log2,1)
1325% %         set(handles.Fenfixe_radiobutton2,'Value',1);
1326% %         setappdata(handles.figure1,'yfiltre',yfiltre);
1327% %         plot(xdata2,ydata,'r',...
1328% %              xdata2(1:size(yfiltre,2)),yfiltre(1:size(yfiltre,2)))
1329% %         
1330% %     elseif isequal(log1,1)
1331% %         set(handles.Dipfixe_radiobutton1,'Value',1);
1332% %         setappdata(handles.figure1,'Dfiltre',Dfiltre);
1333% %         setappdata(handles.figure1,'ydata2',ydata2);
1334% %         plot(xdata2(1:sizex-1),ydata2,'r',...
1335% %             xdata2(1:size(Dfiltre,2)),Dfiltre(1:size(Dfiltre,2)));
1336% %     else
1337       
1338        set(handles.Gap_radiobutton3,'Value',1);
1339        %setappdata(handles.figure1,'yfiltre',yfiltre);
1340        plot(xdata2,ydata2,'r',...
1341             xdata2(1:size(yfiltre,2)),yfiltre(1:size(yfiltre,2)))
1342 %%  end
1343    xlim([min(xdata2) max(xdata2)]);
1344    xlabel('Energie en MeV');
1345    ylabel('charge normalisée');
1346    title('spectre','FontAngle','italic','FontSize',12,'FontWeight','bold');
1347    grid on;
1348    drawnow;
1349   
1350    %______________________________________________________________________
1351    axes(handles.axes3);
1352    cla
1353 
1354    plot(xdata2(1:sizex-1),ydatamc1(1:sizex-1),'b');
1355    xlim([min(xdata2) max(xdata2)]);
1356   
1357    xlabel('Energie en MeV');
1358    ylabel('charge n01');
1359    title('mesureur de charge n°1','FontAngle','italic','FontSize',12,'FontWeight','bold');
1360    grid on;
1361    drawnow;
1362   
1363   
1364catch
1365    cd(DirStart);
1366    return
1367end
1368cd(DirStart);
1369
1370
1371function repositionner_edit3_Callback(hObject, eventdata, handles)
1372% hObject    handle to repositionner_edit3 (see GCBO)
1373% eventdata  reserved - to be defined in a future version of MATLAB
1374% handles    structure with handles and user data (see GUIDATA)
1375
1376% Hints: get(hObject,'String') returns contents of repositionner_edit3 as text
1377%        str2double(get(hObject,'String')) returns contents of repositionner_edit3 as a double
1378
1379
1380% --- Executes during object creation, after setting all properties.
1381function repositionner_edit3_CreateFcn(hObject, eventdata, handles)
1382% hObject    handle to repositionner_edit3 (see GCBO)
1383% eventdata  reserved - to be defined in a future version of MATLAB
1384% handles    empty - handles not created until after all CreateFcns called
1385
1386% Hint: edit controls usually have a white background on Windows.
1387%       See ISPC and COMPUTER.
1388if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1389    set(hObject,'BackgroundColor','white');
1390end
1391
1392
1393% --- Executes on button press in repositionner_pushbutton8.
1394function repositionner_pushbutton8_Callback(hObject, eventdata, handles)
1395% hObject    handle to repositionner_pushbutton8 (see GCBO)
1396% eventdata  reserved - to be defined in a future version of MATLAB
1397% handles    structure with handles and user data (see GUIDATA)
1398
1399
1400% voir si l'on fait un scaling sur les quadrupᅵles aval ᅵ D1, de sorte ᅵ
1401% assurer un transport correct jusqu'ᅵ ARMO
1402
1403% test si un lissage a ᅵtᅵ effectuᅵ. Su oui le max est pris sur la fonction
1404% lissï¿œe sinon sur les donnï¿œes brutes
1405log1=get(handles.Dipfixe_radiobutton1,'Value');
1406log2=get(handles.Fenfixe_radiobutton2,'Value');
1407log3=get(handles.Gap_radiobutton3,'Value');
1408
1409device_name = getappdata(handles.figure1,'device_name');
1410yfiltre = getappdata(handles.figure1,'yfiltre');
1411Dfiltre = getappdata(handles.figure1,'Dfiltre');
1412ydata2 = getappdata(handles.figure1,'ydata2');
1413ydata = getappdata(handles.figure1,'ydata');
1414xdata2 = getappdata(handles.figure1,'xdata2');
1415xdata = getappdata(handles.figure1,'xdata');
1416Imax = 0;
1417
1418if isequal(log1,1)
1419   
1420    if isequal(Dfiltre,[]) & isequal(ydata2,[])
1421        errordlg('vous n''avez pas rentré de données !','Attention');
1422        return
1423    elseif isequal(Dfiltre,[])
1424        [Y,Imax] = max(ydata2);
1425   
1426    else
1427        [Y,Imax] = max(Dfiltre);
1428    end
1429
1430% balayage du dipole on souhaite replacer le dipole sur la valeur donnant
1431% le pic de charge
1432elseif isequal(log2,1)
1433    if isequal(yfiltre,[]) & isequal(ydata,[])
1434        errordlg('vous n''avez pas rentré de données !','Attention');
1435        return
1436    elseif isequal(yfiltre,[])
1437        [Y,Imax] = max(ydata);
1438   
1439    else
1440        [Y,Imax] = max(yfiltre);
1441    end
1442    energie = xdata2(Imax);
1443    set(handles.repositionner_edit3,'String',num2str(energie));
1444    %courant = physics2hw('BEND','Setpoint',energie/1000,[1 1]);
1445    courant = xdata(Imax);
1446    offset = 0.220;
1447    tango_write_attribute(device_name.dipole,'current',courant+offset);
1448
1449% balayage du gap on souhaite replacer le gap à la valeur 0 tout simplement !
1450elseif isequal(log3,1)
1451    if isequal(yfiltre,[]) & isequal(ydata,[])
1452        errordlg('vous n''avez pas rentré de données !','Attention');
1453        return
1454    else
1455        tango_write_attribute(device_name.fente,'Position',0)
1456    end
1457   
1458end
1459
1460
1461% --- Executes on button press in pushbutton9.
1462function pushbutton9_Callback(hObject, eventdata, handles)
1463% hObject    handle to pushbutton9 (see GCBO)
1464% eventdata  reserved - to be defined in a future version of MATLAB
1465% handles    structure with handles and user data (see GUIDATA)
1466
1467
1468
1469%% What to do before closing the application
1470function Closinggui(obj, event, handles, figure1)
1471
1472% Get default command line output from handles structure
1473answer = questdlg('Fermer Mesure de Spectre ?',...
1474    'Mesure de Spectre',...
1475    'Yes','No','Yes');
1476
1477switch answer
1478    case 'Yes'           
1479        delete(handles); %Delete Timer       
1480        delete(figure1); %Close gui
1481    otherwise
1482        disp('Closing aborted')
1483end
1484
1485
1486% --- Executes on button press in zoom1_pushbutton.
1487function zoom1_pushbutton_Callback(hObject, eventdata, handles)
1488% hObject    handle to zoom1_pushbutton (see GCBO)
1489% eventdata  reserved - to be defined in a future version of MATLAB
1490% handles    structure with handles and user data (see GUIDATA)
1491
1492zoom on
1493
1494
1495% --- Executes on button press in zoomoff_pushbutton.
1496function zoomoff_pushbutton_Callback(hObject, eventdata, handles)
1497% hObject    handle to zoomoff_pushbutton (see GCBO)
1498% eventdata  reserved - to be defined in a future version of MATLAB
1499% handles    structure with handles and user data (see GUIDATA)
1500
1501zoom off
1502
1503
1504
1505function mc1_charge_edit5_Callback(hObject, eventdata, handles)
1506% hObject    handle to mc1_charge_edit5 (see GCBO)
1507% eventdata  reserved - to be defined in a future version of MATLAB
1508% handles    structure with handles and user data (see GUIDATA)
1509
1510% Hints: get(hObject,'String') returns contents of mc1_charge_edit5 as text
1511%        str2double(get(hObject,'String')) returns contents of mc1_charge_edit5 as a double
1512
1513
1514% --- Executes during object creation, after setting all properties.
1515function mc1_charge_edit5_CreateFcn(hObject, eventdata, handles)
1516% hObject    handle to mc1_charge_edit5 (see GCBO)
1517% eventdata  reserved - to be defined in a future version of MATLAB
1518% handles    empty - handles not created until after all CreateFcns called
1519
1520% Hint: edit controls usually have a white background on Windows.
1521%       See ISPC and COMPUTER.
1522if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1523    set(hObject,'BackgroundColor','white');
1524end
1525
1526
1527
1528function mc1_calibre_edit6_Callback(hObject, eventdata, handles)
1529% hObject    handle to mc1_calibre_edit6 (see GCBO)
1530% eventdata  reserved - to be defined in a future version of MATLAB
1531% handles    structure with handles and user data (see GUIDATA)
1532
1533% Hints: get(hObject,'String') returns contents of mc1_calibre_edit6 as text
1534%        str2double(get(hObject,'String')) returns contents of mc1_calibre_edit6 as a double
1535
1536
1537% --- Executes during object creation, after setting all properties.
1538function mc1_calibre_edit6_CreateFcn(hObject, eventdata, handles)
1539% hObject    handle to mc1_calibre_edit6 (see GCBO)
1540% eventdata  reserved - to be defined in a future version of MATLAB
1541% handles    empty - handles not created until after all CreateFcns called
1542
1543% Hint: edit controls usually have a white background on Windows.
1544%       See ISPC and COMPUTER.
1545if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1546    set(hObject,'BackgroundColor','white');
1547end
1548
1549
1550
1551function nom_fichier_edit7_Callback(hObject, eventdata, handles)
1552% hObject    handle to nom_fichier_edit7 (see GCBO)
1553% eventdata  reserved - to be defined in a future version of MATLAB
1554% handles    structure with handles and user data (see GUIDATA)
1555
1556% Hints: get(hObject,'String') returns contents of nom_fichier_edit7 as text
1557%        str2double(get(hObject,'String')) returns contents of nom_fichier_edit7 as a double
1558
1559
1560% --- Executes during object creation, after setting all properties.
1561function nom_fichier_edit7_CreateFcn(hObject, eventdata, handles)
1562% hObject    handle to nom_fichier_edit7 (see GCBO)
1563% eventdata  reserved - to be defined in a future version of MATLAB
1564% handles    empty - handles not created until after all CreateFcns called
1565
1566% Hint: edit controls usually have a white background on Windows.
1567%       See ISPC and COMPUTER.
1568if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1569    set(hObject,'BackgroundColor','white');
1570end
1571
1572
Note: See TracBrowser for help on using the repository browser.