source: MML/trunk/machine/SOLEIL/LT1/fae/fae_v5_old_fevrier09.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

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