source: MML/trunk/machine/SOLEIL/StorageRing/plot_synchrotron_tune_scan.m @ 4

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

Initial import--MML version from SOLEIL@2013

File size: 17.8 KB
Line 
1function varargout = plot_synchrotron_tune_scan(varargin)
2% PLOT_SYNCHROTRON_TUNE_SCAN M-file for plot_synchrotron_tune_scan.fig
3%      PLOT_SYNCHROTRON_TUNE_SCAN, by itself, creates a new PLOT_SYNCHROTRON_TUNE_SCAN or raises the existing
4%      singleton*.
5%
6%      H = PLOT_SYNCHROTRON_TUNE_SCAN returns the handle to a new PLOT_SYNCHROTRON_TUNE_SCAN or the handle to
7%      the existing singleton*.
8%
9%      PLOT_SYNCHROTRON_TUNE_SCAN('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in PLOT_SYNCHROTRON_TUNE_SCAN.M with the given input arguments.
11%
12%      PLOT_SYNCHROTRON_TUNE_SCAN('Property','Value',...) creates a new PLOT_SYNCHROTRON_TUNE_SCAN or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before plot_synchrotron_tune_scan_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to plot_synchrotron_tune_scan_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% Edit the above text to modify the response to help plot_synchrotron_tune_scan
24
25% Last Modified by GUIDE v2.5 08-Dec-2008 15:03:31
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @plot_synchrotron_tune_scan_OpeningFcn, ...
32                   'gui_OutputFcn',  @plot_synchrotron_tune_scan_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46
47% --- Executes just before plot_synchrotron_tune_scan is made visible.
48function plot_synchrotron_tune_scan_OpeningFcn(hObject, eventdata, handles, varargin)
49% This function has no output args, see OutputFcn.
50% hObject    handle to figure
51% eventdata  reserved - to be defined in a future version of MATLAB
52% handles    structure with handles and user data (see GUIDATA)
53% varargin   command line arguments to plot_synchrotron_tune_scan (see VARARGIN)
54
55% Choose default command line output for plot_synchrotron_tune_scan
56handles.output = hObject;
57
58BPM='ANS-C09/DG/BPM.NOD';
59
60
61% get BPM value
62rep = tango_read_attribute2(BPM,'DDBufferSize');pro=rep.value(1);
63set(handles.edit_profondeur,'String',num2str(pro))
64rep = tango_read_attribute2(BPM,'DDDecimationFactor');dec=rep.value(1);
65set(handles.edit_decimation,'String',num2str(dec))
66rep = tango_read_attribute2('ANS-C13/SY/LOCAL.DG.1', 'dcctEvent');adr=rep.value(1);
67set(handles.edit_adress,'String',num2str(adr))
68
69temp=tango_read_attribute2('ANS/RF/MasterClock','phaseFrequency');freq=temp.value(1);
70set(handles.edit_freq,'String',num2str(freq))
71temp=tango_read_attribute2('ANS/RF/MasterClock','phaseVariation');amp=temp.value(1);
72set(handles.edit_amp,'String',num2str(amp))
73   
74handles.bpm=BPM;
75setappdata(handles.figure1, 'amp_scan', []);
76
77% Update handles structure
78guidata(hObject, handles);
79
80% UIWAIT makes plot_synchrotron_tune_scan wait for user response (see UIRESUME)
81% uiwait(handles.figure1);
82
83
84% --- Outputs from this function are returned to the command line.
85function varargout = plot_synchrotron_tune_scan_OutputFcn(hObject, eventdata, handles)
86% varargout  cell array for returning output args (see VARARGOUT);
87% hObject    handle to figure
88% eventdata  reserved - to be defined in a future version of MATLAB
89% handles    structure with handles and user data (see GUIDATA)
90
91% Get default command line output from handles structure
92varargout{1} = handles.output;
93
94
95% --- Executes on button press in pushbutton_plot.
96function pushbutton_plot_Callback(hObject, eventdata, handles)
97% hObject    handle to pushbutton_plot (see GCBO)
98% eventdata  reserved - to be defined in a future version of MATLAB
99% handles    structure with handles and user data (see GUIDATA)
100
101% Hint: get(hObject,'Value') returns toggle state of pushbutton_plot
102BPM=handles.bpm;
103rep = tango_read_attribute2(BPM,'DDDecimationFactor');dec=rep.value(1);
104rep = tango_read_attribute2(BPM,'XPosDD');
105N = length(rep.value);
106
107minfreq=str2double(get(handles.edit_minfreq,'String'));
108maxfreq=str2double(get(handles.edit_maxfreq,'String'));
109
110
111Xvalue = zeros(1,N);
112for ik =1:3, % averaging
113    rep = tango_read_attribute2(BPM,'XPosDD');
114    Xvalue = Xvalue + rep.value;
115    pause(0.3)
116end
117
118Xvalue = Xvalue/3;
119Amp=abs(fft(Xvalue));
120
121frev = getrf/416;
122freq =(1:N)/N*frev*1e6/double(dec);
123len=length(freq);
124
125plot(freq(1:len/2)/1000,Amp(1:len/2))
126xaxis([minfreq maxfreq]);
127grid on
128xlabel('Frequency kHz')
129
130% get max on window
131minf=floor(minfreq*1000*N/frev/1e6*double(dec));
132maxf=floor(maxfreq*1000*N/frev/1e6*double(dec));
133max_amp= max(Amp(minf:maxf));
134
135amp_scan= getappdata(handles.figure1, 'amp_scan');
136amp_scan=[amp_scan max_amp];
137setappdata(handles.figure1, 'amp_scan', amp_scan);
138
139
140
141
142function edit_profondeur_Callback(hObject, eventdata, handles)
143% hObject    handle to edit_profondeur (see GCBO)
144% eventdata  reserved - to be defined in a future version of MATLAB
145% handles    structure with handles and user data (see GUIDATA)
146
147% Hints: get(hObject,'String') returns contents of edit_profondeur as text
148%        str2double(get(hObject,'String')) returns contents of edit_profondeur as a double
149
150
151% --- Executes during object creation, after setting all properties.
152function edit_profondeur_CreateFcn(hObject, eventdata, handles)
153% hObject    handle to edit_profondeur (see GCBO)
154% eventdata  reserved - to be defined in a future version of MATLAB
155% handles    empty - handles not created until after all CreateFcns called
156
157% Hint: edit controls usually have a white background on Windows.
158%       See ISPC and COMPUTER.
159if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
160    set(hObject,'BackgroundColor','white');
161end
162
163
164
165function edit_decimation_Callback(hObject, eventdata, handles)
166% hObject    handle to edit_decimation (see GCBO)
167% eventdata  reserved - to be defined in a future version of MATLAB
168% handles    structure with handles and user data (see GUIDATA)
169
170% Hints: get(hObject,'String') returns contents of edit_decimation as text
171%        str2double(get(hObject,'String')) returns contents of edit_decimation as a double
172
173
174% --- Executes during object creation, after setting all properties.
175function edit_decimation_CreateFcn(hObject, eventdata, handles)
176% hObject    handle to edit_decimation (see GCBO)
177% eventdata  reserved - to be defined in a future version of MATLAB
178% handles    empty - handles not created until after all CreateFcns called
179
180% Hint: edit controls usually have a white background on Windows.
181%       See ISPC and COMPUTER.
182if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
183    set(hObject,'BackgroundColor','white');
184end
185
186
187
188function edit_adress_Callback(hObject, eventdata, handles)
189% hObject    handle to edit_adress (see GCBO)
190% eventdata  reserved - to be defined in a future version of MATLAB
191% handles    structure with handles and user data (see GUIDATA)
192
193% Hints: get(hObject,'String') returns contents of edit_adress as text
194%        str2double(get(hObject,'String')) returns contents of edit_adress as a double
195
196
197% --- Executes during object creation, after setting all properties.
198function edit_adress_CreateFcn(hObject, eventdata, handles)
199% hObject    handle to edit_adress (see GCBO)
200% eventdata  reserved - to be defined in a future version of MATLAB
201% handles    empty - handles not created until after all CreateFcns called
202
203% Hint: edit controls usually have a white background on Windows.
204%       See ISPC and COMPUTER.
205if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
206    set(hObject,'BackgroundColor','white');
207end
208
209guidata(hObject, handles);
210
211function edit_minfreq_Callback(hObject, eventdata, handles)
212% hObject    handle to edit_minfreq (see GCBO)
213% eventdata  reserved - to be defined in a future version of MATLAB
214% handles    structure with handles and user data (see GUIDATA)
215
216% Hints: get(hObject,'String') returns contents of edit_minfreq as text
217%        str2double(get(hObject,'String')) returns contents of edit_minfreq as a double
218
219
220% --- Executes during object creation, after setting all properties.
221function edit_minfreq_CreateFcn(hObject, eventdata, handles)
222% hObject    handle to edit_minfreq (see GCBO)
223% eventdata  reserved - to be defined in a future version of MATLAB
224% handles    empty - handles not created until after all CreateFcns called
225
226% Hint: edit controls usually have a white background on Windows.
227%       See ISPC and COMPUTER.
228if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
229    set(hObject,'BackgroundColor','white');
230end
231
232
233
234function edit_maxfreq_Callback(hObject, eventdata, handles)
235% hObject    handle to edit_maxfreq (see GCBO)
236% eventdata  reserved - to be defined in a future version of MATLAB
237% handles    structure with handles and user data (see GUIDATA)
238
239% Hints: get(hObject,'String') returns contents of edit_maxfreq as text
240%        str2double(get(hObject,'String')) returns contents of edit_maxfreq as a double
241
242
243% --- Executes during object creation, after setting all properties.
244function edit_maxfreq_CreateFcn(hObject, eventdata, handles)
245% hObject    handle to edit_maxfreq (see GCBO)
246% eventdata  reserved - to be defined in a future version of MATLAB
247% handles    empty - handles not created until after all CreateFcns called
248
249% Hint: edit controls usually have a white background on Windows.
250%       See ISPC and COMPUTER.
251if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
252    set(hObject,'BackgroundColor','white');
253end
254
255
256% --- Executes on button press in pushbutton_scan.
257function pushbutton_scan_Callback(hObject, eventdata, handles)
258% hObject    handle to pushbutton_scan (see GCBO)
259% eventdata  reserved - to be defined in a future version of MATLAB
260% handles    structure with handles and user data (see GUIDATA)
261
262%amp  =0.0002;
263freq0=str2double(get(handles.edit_freq_min_scan,'String'));
264freqm=str2double(get(handles.edit_freq_max_scan,'String'));
265df   =str2double(get(handles.edit_step_scan,'String'));
266
267ff   = [freq0 :df:freqm];
268
269
270freq_scan=ff;
271setappdata(handles.figure1, 'amp_scan',[]);
272
273tango_write_attribute2('ANS/RF/MasterClock','phaseFrequency',freq0);pause(2)
274
275for fs=ff
276   
277    tango_write_attribute2('ANS/RF/MasterClock','phaseFrequency',fs*1000);
278   
279    pause(2)
280    temp=tango_read_attribute2('ANS/RF/MasterClock','phaseFrequency');freq=temp.value(1);
281    set(handles.edit_freq,'String',num2str(freq))
282    temp=tango_read_attribute2('ANS/RF/MasterClock','phaseVariation');amp=temp.value(1);
283    set(handles.edit_amp,'String',num2str(amp))
284   
285    pushbutton_plot_Callback(hObject, eventdata, handles);
286   
287end
288
289amp_scan= getappdata(handles.figure1, 'amp_scan');
290minfreq=str2double(get(handles.edit_minfreq,'String'));
291maxfreq=str2double(get(handles.edit_maxfreq,'String'));
292
293plot(freq_scan,amp_scan,'-ob')
294%xaxis([minfreq maxfreq]);
295grid on
296xlabel('Frequency Hz')
297
298[amps,ind]=max(amp_scan);
299tunes=freq_scan(ind);
300set(handles.edit_tune,'String',num2str(tunes))
301
302
303
304% Update handles structure
305guidata(handles.pushbutton_scan, handles);
306
307function edit_freq_min_scan_Callback(hObject, eventdata, handles)
308% hObject    handle to edit_freq_min_scan (see GCBO)
309% eventdata  reserved - to be defined in a future version of MATLAB
310% handles    structure with handles and user data (see GUIDATA)
311
312% Hints: get(hObject,'String') returns contents of edit_freq_min_scan as text
313%        str2double(get(hObject,'String')) returns contents of edit_freq_min_scan as a double
314
315
316% --- Executes during object creation, after setting all properties.
317function edit_freq_min_scan_CreateFcn(hObject, eventdata, handles)
318% hObject    handle to edit_freq_min_scan (see GCBO)
319% eventdata  reserved - to be defined in a future version of MATLAB
320% handles    empty - handles not created until after all CreateFcns called
321
322% Hint: edit controls usually have a white background on Windows.
323%       See ISPC and COMPUTER.
324if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
325    set(hObject,'BackgroundColor','white');
326end
327
328
329
330function edit_freq_max_scan_Callback(hObject, eventdata, handles)
331% hObject    handle to edit_freq_max_scan (see GCBO)
332% eventdata  reserved - to be defined in a future version of MATLAB
333% handles    structure with handles and user data (see GUIDATA)
334
335% Hints: get(hObject,'String') returns contents of edit_freq_max_scan as text
336%        str2double(get(hObject,'String')) returns contents of edit_freq_max_scan as a double
337
338
339% --- Executes during object creation, after setting all properties.
340function edit_freq_max_scan_CreateFcn(hObject, eventdata, handles)
341% hObject    handle to edit_freq_max_scan (see GCBO)
342% eventdata  reserved - to be defined in a future version of MATLAB
343% handles    empty - handles not created until after all CreateFcns called
344
345% Hint: edit controls usually have a white background on Windows.
346%       See ISPC and COMPUTER.
347if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
348    set(hObject,'BackgroundColor','white');
349end
350
351
352
353function edit_step_scan_Callback(hObject, eventdata, handles)
354% hObject    handle to edit_step_scan (see GCBO)
355% eventdata  reserved - to be defined in a future version of MATLAB
356% handles    structure with handles and user data (see GUIDATA)
357
358% Hints: get(hObject,'String') returns contents of edit_step_scan as text
359%        str2double(get(hObject,'String')) returns contents of edit_step_scan as a double
360
361
362% --- Executes during object creation, after setting all properties.
363function edit_step_scan_CreateFcn(hObject, eventdata, handles)
364% hObject    handle to edit_step_scan (see GCBO)
365% eventdata  reserved - to be defined in a future version of MATLAB
366% handles    empty - handles not created until after all CreateFcns called
367
368% Hint: edit controls usually have a white background on Windows.
369%       See ISPC and COMPUTER.
370if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
371    set(hObject,'BackgroundColor','white');
372end
373
374
375% --- Executes on button press in pushbutton_modulationON.
376function pushbutton_modulationON_Callback(hObject, eventdata, handles)
377% hObject    handle to pushbutton_modulationON (see GCBO)
378% eventdata  reserved - to be defined in a future version of MATLAB
379% handles    structure with handles and user data (see GUIDATA)
380
381
382tango_command_inout2('ANS/RF/MasterClock','PhaseModulationON');
383
384% --- Executes on button press in pushbutton_modulationOFF.
385function pushbutton_modulationOFF_Callback(hObject, eventdata, handles)
386% hObject    handle to pushbutton_modulationOFF (see GCBO)
387% eventdata  reserved - to be defined in a future version of MATLAB
388% handles    structure with handles and user data (see GUIDATA)
389
390tango_command_inout2('ANS/RF/MasterClock','PhaseModulationOFF');
391
392
393
394function edit_amp_Callback(hObject, eventdata, handles)
395% hObject    handle to edit_amp (see GCBO)
396% eventdata  reserved - to be defined in a future version of MATLAB
397% handles    structure with handles and user data (see GUIDATA)
398
399% Hints: get(hObject,'String') returns contents of edit_amp as text
400%        str2double(get(hObject,'String')) returns contents of edit_amp as a double
401
402
403% --- Executes during object creation, after setting all properties.
404function edit_amp_CreateFcn(hObject, eventdata, handles)
405% hObject    handle to edit_amp (see GCBO)
406% eventdata  reserved - to be defined in a future version of MATLAB
407% handles    empty - handles not created until after all CreateFcns called
408
409% Hint: edit controls usually have a white background on Windows.
410%       See ISPC and COMPUTER.
411if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
412    set(hObject,'BackgroundColor','white');
413end
414
415
416
417function edit_freq_Callback(hObject, eventdata, handles)
418% hObject    handle to edit_freq (see GCBO)
419% eventdata  reserved - to be defined in a future version of MATLAB
420% handles    structure with handles and user data (see GUIDATA)
421
422% Hints: get(hObject,'String') returns contents of edit_freq as text
423%        str2double(get(hObject,'String')) returns contents of edit_freq as a double
424
425
426% --- Executes during object creation, after setting all properties.
427function edit_freq_CreateFcn(hObject, eventdata, handles)
428% hObject    handle to edit_freq (see GCBO)
429% eventdata  reserved - to be defined in a future version of MATLAB
430% handles    empty - handles not created until after all CreateFcns called
431
432% Hint: edit controls usually have a white background on Windows.
433%       See ISPC and COMPUTER.
434if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
435    set(hObject,'BackgroundColor','white');
436end
437
438
439
440function edit_tune_Callback(hObject, eventdata, handles)
441% hObject    handle to edit_tune (see GCBO)
442% eventdata  reserved - to be defined in a future version of MATLAB
443% handles    structure with handles and user data (see GUIDATA)
444
445% Hints: get(hObject,'String') returns contents of edit_tune as text
446%        str2double(get(hObject,'String')) returns contents of edit_tune as a double
447
448
449% --- Executes during object creation, after setting all properties.
450function edit_tune_CreateFcn(hObject, eventdata, handles)
451% hObject    handle to edit_tune (see GCBO)
452% eventdata  reserved - to be defined in a future version of MATLAB
453% handles    empty - handles not created until after all CreateFcns called
454
455% Hint: edit controls usually have a white background on Windows.
456%       See ISPC and COMPUTER.
457if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
458    set(hObject,'BackgroundColor','white');
459end
460
461
Note: See TracBrowser for help on using the repository browser.