source: MML/trunk/machine/SOLEIL/LT1/fae/fae_v2.m @ 17

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

To have a stable version on the server.

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