1 | function varargout = plotBPMturns(varargin) |
---|
2 | % PLOTBPMTURNS M-file for plotBPMturns.fig |
---|
3 | % PLOTBPMTURNS, by itself, creates a new PLOTBPMTURNS or raises the existing |
---|
4 | % singleton*. |
---|
5 | % |
---|
6 | % H = PLOTBPMTURNS returns the handle to a new PLOTBPMTURNS or the handle to |
---|
7 | % the existing singleton*. |
---|
8 | % |
---|
9 | % PLOTBPMTURNS('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
10 | % function named CALLBACK in PLOTBPMTURNS.M with the given input arguments. |
---|
11 | % |
---|
12 | % PLOTBPMTURNS('Property','Value',...) creates a new PLOTBPMTURNS or raises the |
---|
13 | % existing singleton*. Starting from the left, property value pairs are |
---|
14 | % applied to the GUI before plotBPMturns_OpeningFunction gets called. An |
---|
15 | % unrecognized property name or invalid value makes property application |
---|
16 | % stop. All inputs are passed to plotBPMturns_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 plotBPMturns |
---|
24 | |
---|
25 | % Last Modified by GUIDE v2.5 08-Aug-2006 14:29:40 |
---|
26 | |
---|
27 | % Begin initialization code - DO NOT EDIT |
---|
28 | gui_Singleton = 0; |
---|
29 | gui_State = struct('gui_Name', mfilename, ... |
---|
30 | 'gui_Singleton', gui_Singleton, ... |
---|
31 | 'gui_OpeningFcn', @plotBPMturns_OpeningFcn, ... |
---|
32 | 'gui_OutputFcn', @plotBPMturns_OutputFcn, ... |
---|
33 | 'gui_LayoutFcn', [] , ... |
---|
34 | 'gui_Callback', []); |
---|
35 | if nargin && ischar(varargin{1}) |
---|
36 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
37 | end |
---|
38 | |
---|
39 | if nargout |
---|
40 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
41 | else |
---|
42 | gui_mainfcn(gui_State, varargin{:}); |
---|
43 | end |
---|
44 | % End initialization code - DO NOT EDIT |
---|
45 | |
---|
46 | |
---|
47 | % --- Executes just before plotBPMturns is made visible. |
---|
48 | function plotBPMturns_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 plotBPMturns (see VARARGIN) |
---|
54 | |
---|
55 | % fprintf('%6.2f\n',hObject); |
---|
56 | |
---|
57 | datacursormode on; |
---|
58 | |
---|
59 | % Choose default command line output for plotBPMturns |
---|
60 | handles.output = hObject; |
---|
61 | |
---|
62 | % Update handles structure |
---|
63 | guidata(hObject, handles); |
---|
64 | |
---|
65 | % Make figure resizable |
---|
66 | set(hObject,'Resize','off'); |
---|
67 | |
---|
68 | % Set default values for the various fields. |
---|
69 | set(handles.turns_input,'String','[1:100]'); |
---|
70 | set(handles.FFTturns_input,'String','[1:100]'); |
---|
71 | set(handles.fftxaxis,'String','[0 0.5 0 0.2 0.1 0.4]'); |
---|
72 | set(handles.fftyaxis,'String','[0 0.5 0 0.1 0.1 0.4]'); |
---|
73 | set(handles.FFTturns_input,'String','[1:512]'); |
---|
74 | set(handles.BPMdev_input,'String','[1 1]'); |
---|
75 | set(handles.sumplot_max,'String','15e5'); |
---|
76 | set(handles.sumplot_min,'String','0'); |
---|
77 | set(handles.xyplot_max,'String','10'); |
---|
78 | set(handles.xyplot_min,'String','-10'); |
---|
79 | set(handles.tuneplot_max,'String','0.5'); |
---|
80 | set(handles.tuneplot_min,'String','0'); |
---|
81 | |
---|
82 | % User data structure to store data |
---|
83 | data.maxturns = 6663; |
---|
84 | data.maxtunesamples = 20; |
---|
85 | data.turnsstr = '[1:100]'; |
---|
86 | data.turns = 1:100; |
---|
87 | data.BPMdev = [1 1]; |
---|
88 | data.sumplotaxis = [0 15e5]; |
---|
89 | data.xyplotaxis = [-10 10]; |
---|
90 | data.tuneplotaxis = [0 0.5]; |
---|
91 | data.fftturnsstr = '[1:512]'; |
---|
92 | data.fftturns = 1:512; |
---|
93 | % The last 2 numbers define the window over which to detect the tune. |
---|
94 | data.fftxaxis = [0 0.5 0 0.2 0.1 0.4]; |
---|
95 | data.fftyaxis = [0 0.5 0 0.1 0.1 0.4]; |
---|
96 | data.fftaverage = 10; |
---|
97 | data.Pxx = []; % store power spectrum for averaging |
---|
98 | data.Pyy = []; % store power spectrum for averaging |
---|
99 | |
---|
100 | % for liftime calculations |
---|
101 | data.prev_sum = NaN; |
---|
102 | data.prev_time = NaN; |
---|
103 | data.lifetime = NaN; |
---|
104 | %data.lifetime_pv = 'CR01:GENERAL_ANALOG_01_MONITOR'; |
---|
105 | data.lifetime_handle = getlifetime; |
---|
106 | data.currsumarray = NaN; |
---|
107 | data.currsumarray2 = NaN; |
---|
108 | |
---|
109 | data.tuneind = 1; |
---|
110 | |
---|
111 | data.sum = zeros(data.maxturns,1); |
---|
112 | data.x = zeros(data.maxturns,1); |
---|
113 | data.y = zeros(data.maxturns,1)+1; |
---|
114 | data.xtune = zeros(data.maxtunesamples,1); data.xtune(:) = NaN; |
---|
115 | data.ytune = zeros(data.maxtunesamples,1); data.ytune(:) = NaN; |
---|
116 | |
---|
117 | % Initialise plots |
---|
118 | axes(handles.sum_plot); |
---|
119 | plot(data.sum,'LineWidth',2); |
---|
120 | set(gca,'XLim',[data.turns(1) data.turns(end)]); |
---|
121 | set(gca,'YLim',data.sumplotaxis); |
---|
122 | |
---|
123 | axes(handles.xy_plot); |
---|
124 | plot(data.x,'LineWidth',2,'Color','k','Tag','Horizontal'); |
---|
125 | hold on; |
---|
126 | plot(data.y,'LineWidth',2,'Color','b','LineStyle','--','Tag','Vertical'); |
---|
127 | hold off; |
---|
128 | set(gca,'XLim',[data.turns(1) data.turns(end)]); |
---|
129 | set(gca,'YLim',data.xyplotaxis); |
---|
130 | |
---|
131 | % Tunes only plot 20 samples/updates worth of tunes |
---|
132 | axes(handles.tune_plot); |
---|
133 | plot(data.xtune,'LineWidth',2,'Color','k','Tag','Htune','Marker','.'); |
---|
134 | hold on; |
---|
135 | plot(data.ytune,'LineWidth',2,'Color','b','Tag','Vtune','Marker','.','LineStyle','--'); |
---|
136 | hold off; |
---|
137 | set(gca,'XLim',[1 data.maxtunesamples]); |
---|
138 | set(gca,'YLim',data.tuneplotaxis); |
---|
139 | |
---|
140 | % Plots for the FFT. With more points than would be needed. |
---|
141 | axes(handles.fft_x); |
---|
142 | plot(zeros(1,length(data.maxturns/2)),'LineWidth',1,'Color','k','Tag','fftx'); |
---|
143 | hold on; |
---|
144 | % Plot the tune window over which to detect the tune |
---|
145 | plot([data.fftxaxis(5) data.fftxaxis(5)],data.fftxaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','fftx_lower'); |
---|
146 | plot([data.fftxaxis(6) data.fftxaxis(6)],data.fftxaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','fftx_upper'); |
---|
147 | hold off; |
---|
148 | axis(data.fftxaxis(1:4)); |
---|
149 | |
---|
150 | axes(handles.fft_y); |
---|
151 | plot(zeros(1,length(data.maxturns/2)),'LineWidth',1,'Color','k','Tag','ffty'); |
---|
152 | hold on; |
---|
153 | % Plot the tune window over which to detect the tune |
---|
154 | plot([data.fftyaxis(5) data.fftyaxis(5)],data.fftyaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','ffty_lower'); |
---|
155 | plot([data.fftyaxis(6) data.fftyaxis(6)],data.fftyaxis(3:4),'--','Color',[1.0 0.7 0.7],'Tag','ffty_upper'); |
---|
156 | hold off; |
---|
157 | axis(data.fftyaxis(1:4)); |
---|
158 | |
---|
159 | |
---|
160 | set(handles.main,'UserData',data); |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | % --- Outputs from this function are returned to the command line. |
---|
165 | function varargout = plotBPMturns_OutputFcn(hObject, eventdata, handles) |
---|
166 | % varargout cell array for returning output args (see VARARGOUT); |
---|
167 | % hObject handle to figure |
---|
168 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
169 | % handles structure with handles and user data (see GUIDATA) |
---|
170 | |
---|
171 | % Get default command line output from handles structure |
---|
172 | varargout{1} = handles.output; |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | function turns_input_Callback(hObject, eventdata, handles) |
---|
177 | % hObject handle to turns_input (see GCBO) |
---|
178 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
179 | % handles structure with handles and user data (see GUIDATA) |
---|
180 | |
---|
181 | % Hints: get(hObject,'String') returns contents of turns_input as text |
---|
182 | % str2double(get(hObject,'String')) returns contents of turns_input as a double |
---|
183 | |
---|
184 | data = get(handles.main,'UserData'); |
---|
185 | |
---|
186 | turnsstr = get(hObject,'String'); |
---|
187 | turns = eval(turnsstr); |
---|
188 | if isnumeric(turns) && turns(end) < data.maxturns |
---|
189 | data.turnsstr = turnsstr; |
---|
190 | data.turns = turns; |
---|
191 | else |
---|
192 | msgbox(sprintf('Invalid turns input. Max turns is < %d',data.maxturns)); |
---|
193 | set(hObject,'String',data.turnsstr); |
---|
194 | end |
---|
195 | |
---|
196 | set(handles.main,'UserData',data); |
---|
197 | |
---|
198 | |
---|
199 | % --- Executes during object creation, after setting all properties. |
---|
200 | function turns_input_CreateFcn(hObject, eventdata, handles) |
---|
201 | % hObject handle to turns_input (see GCBO) |
---|
202 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
203 | % handles empty - handles not created until after all CreateFcns called |
---|
204 | |
---|
205 | % Hint: edit controls usually have a white background on Windows. |
---|
206 | % See ISPC and COMPUTER. |
---|
207 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
208 | set(hObject,'BackgroundColor','white'); |
---|
209 | end |
---|
210 | |
---|
211 | function BPMdev_input_Callback(hObject, eventdata, handles) |
---|
212 | % hObject handle to BPMdev_input (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 BPMdev_input as text |
---|
217 | % str2double(get(hObject,'String')) returns contents of BPMdev_input as a double |
---|
218 | |
---|
219 | data = get(handles.main,'UserData'); |
---|
220 | |
---|
221 | BPMdev = eval(get(hObject,'String')); |
---|
222 | BPMdevlist = family2dev('BPMx',1); |
---|
223 | |
---|
224 | ind = findrowindex(BPMdevlist,BPMdev); |
---|
225 | if isempty(ind) |
---|
226 | msgbox('Invalid BPM device index'); |
---|
227 | set(hObject,'String',sprintf('[%d %d]',data.BPMdev(1), data.BPMdev(2))); |
---|
228 | else |
---|
229 | data.BPMdev = BPMdev; |
---|
230 | end |
---|
231 | |
---|
232 | set(handles.main,'UserData',data); |
---|
233 | |
---|
234 | |
---|
235 | % --- Executes during object creation, after setting all properties. |
---|
236 | function BPMdev_input_CreateFcn(hObject, eventdata, handles) |
---|
237 | % hObject handle to BPMdev_input (see GCBO) |
---|
238 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
239 | % handles empty - handles not created until after all CreateFcns called |
---|
240 | |
---|
241 | % Hint: edit controls usually have a white background on Windows. |
---|
242 | % See ISPC and COMPUTER. |
---|
243 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
244 | set(hObject,'BackgroundColor','white'); |
---|
245 | end |
---|
246 | |
---|
247 | |
---|
248 | % --- Executes on button press in start_stop. |
---|
249 | function start_stop_Callback(hObject, eventdata, handles) |
---|
250 | % hObject handle to start_stop (see GCBO) |
---|
251 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
252 | % handles structure with handles and user data (see GUIDATA) |
---|
253 | |
---|
254 | % Hint: get(hObject,'Value') returns toggle state of start_stop |
---|
255 | |
---|
256 | OnFlag = get(handles.start_stop,'Value'); |
---|
257 | |
---|
258 | if OnFlag |
---|
259 | % Turn on updates |
---|
260 | set(handles.start_stop, 'String', 'Running'); |
---|
261 | |
---|
262 | % Turn lattice menu back off |
---|
263 | %set(handles.('LatticeMenu'),'enable','off'); |
---|
264 | |
---|
265 | % Setup timer |
---|
266 | UpdatePeriod = 0.5; |
---|
267 | t = timer; |
---|
268 | set(t,'StartDelay',0); |
---|
269 | set(t,'Period', UpdatePeriod); |
---|
270 | tagstr = sprintf('PlotBPMTimer_%6.2f',handles.main); |
---|
271 | set(t,'Tag', tagstr); |
---|
272 | timerstr = sprintf('plotBPMturns(''single_shot_Callback'', getfield(get(timerfind(''Tag'',''%s''),''Userdata''),''main''), [], get(timerfind(''Tag'',''%s''),''Userdata'')); drawnow;',... |
---|
273 | tagstr,tagstr); |
---|
274 | set(t,'TimerFcn', timerstr); |
---|
275 | set(t,'UserData', handles); |
---|
276 | |
---|
277 | set(t,'BusyMode','drop'); %'queue' |
---|
278 | set(t,'TasksToExecute', 10000000); |
---|
279 | set(t,'ExecutionMode','FixedRate'); |
---|
280 | start(t); |
---|
281 | |
---|
282 | else |
---|
283 | % Turn off updating by deleting timer handle |
---|
284 | tagstr = sprintf('PlotBPMTimer_%6.2f',handles.main); |
---|
285 | h = timerfind('Tag',tagstr); |
---|
286 | for i = 1:length(h) |
---|
287 | stop(h(i)); |
---|
288 | delete(h(i)); |
---|
289 | end |
---|
290 | |
---|
291 | % Change OnOff label string |
---|
292 | set(handles.start_stop, 'String', 'Continuous'); |
---|
293 | end |
---|
294 | |
---|
295 | |
---|
296 | |
---|
297 | |
---|
298 | function sumplot_max_Callback(hObject, eventdata, handles) |
---|
299 | % hObject handle to sumplot_max (see GCBO) |
---|
300 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
301 | % handles structure with handles and user data (see GUIDATA) |
---|
302 | |
---|
303 | % Hints: get(hObject,'String') returns contents of sumplot_max as text |
---|
304 | % str2double(get(hObject,'String')) returns contents of sumplot_max as a double |
---|
305 | data = get(handles.main,'UserData'); |
---|
306 | |
---|
307 | val = str2double(get(hObject,'String')); |
---|
308 | if ~isnan(val) |
---|
309 | data.sumplotaxis(2) = val; |
---|
310 | else |
---|
311 | msgbox('Invalid number'); |
---|
312 | set(hObject,'String',num2str(data.sumplotaxis(2))); |
---|
313 | end |
---|
314 | |
---|
315 | set(handles.main,'UserData',data); |
---|
316 | |
---|
317 | |
---|
318 | % --- Executes during object creation, after setting all properties. |
---|
319 | function sumplot_max_CreateFcn(hObject, eventdata, handles) |
---|
320 | % hObject handle to sumplot_max (see GCBO) |
---|
321 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
322 | % handles empty - handles not created until after all CreateFcns called |
---|
323 | |
---|
324 | % Hint: edit controls usually have a white background on Windows. |
---|
325 | % See ISPC and COMPUTER. |
---|
326 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
327 | set(hObject,'BackgroundColor','white'); |
---|
328 | end |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | function sumplot_min_Callback(hObject, eventdata, handles) |
---|
333 | % hObject handle to sumplot_min (see GCBO) |
---|
334 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
335 | % handles structure with handles and user data (see GUIDATA) |
---|
336 | |
---|
337 | % Hints: get(hObject,'String') returns contents of sumplot_min as text |
---|
338 | % str2double(get(hObject,'String')) returns contents of sumplot_min as a double |
---|
339 | |
---|
340 | data = get(handles.main,'UserData'); |
---|
341 | |
---|
342 | val = str2double(get(hObject,'String')); |
---|
343 | if ~isnan(val) |
---|
344 | data.sumplotaxis(1) = val; |
---|
345 | else |
---|
346 | msgbox('Invalid number'); |
---|
347 | set(hObject,'String',num2str(data.sumplotaxis(1))); |
---|
348 | end |
---|
349 | |
---|
350 | set(handles.main,'UserData',data); |
---|
351 | |
---|
352 | % --- Executes during object creation, after setting all properties. |
---|
353 | function sumplot_min_CreateFcn(hObject, eventdata, handles) |
---|
354 | % hObject handle to sumplot_min (see GCBO) |
---|
355 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
356 | % handles empty - handles not created until after all CreateFcns called |
---|
357 | |
---|
358 | % Hint: edit controls usually have a white background on Windows. |
---|
359 | % See ISPC and COMPUTER. |
---|
360 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
361 | set(hObject,'BackgroundColor','white'); |
---|
362 | end |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | function xyplot_max_Callback(hObject, eventdata, handles) |
---|
367 | % hObject handle to xyplot_max (see GCBO) |
---|
368 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
369 | % handles structure with handles and user data (see GUIDATA) |
---|
370 | |
---|
371 | % Hints: get(hObject,'String') returns contents of xyplot_max as text |
---|
372 | % str2double(get(hObject,'String')) returns contents of xyplot_max as a double |
---|
373 | |
---|
374 | data = get(handles.main,'UserData'); |
---|
375 | |
---|
376 | val = str2double(get(hObject,'String')); |
---|
377 | if ~isnan(val) |
---|
378 | data.xyplotaxis(2) = val; |
---|
379 | else |
---|
380 | msgbox('Invalid number'); |
---|
381 | set(hObject,'String',num2str(data.xyplotaxis(2))); |
---|
382 | end |
---|
383 | |
---|
384 | set(handles.main,'UserData',data); |
---|
385 | |
---|
386 | |
---|
387 | % --- Executes during object creation, after setting all properties. |
---|
388 | function xyplot_max_CreateFcn(hObject, eventdata, handles) |
---|
389 | % hObject handle to xyplot_max (see GCBO) |
---|
390 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
391 | % handles empty - handles not created until after all CreateFcns called |
---|
392 | |
---|
393 | % Hint: edit controls usually have a white background on Windows. |
---|
394 | % See ISPC and COMPUTER. |
---|
395 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
396 | set(hObject,'BackgroundColor','white'); |
---|
397 | end |
---|
398 | |
---|
399 | |
---|
400 | |
---|
401 | function xyplot_min_Callback(hObject, eventdata, handles) |
---|
402 | % hObject handle to xyplot_min (see GCBO) |
---|
403 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
404 | % handles structure with handles and user data (see GUIDATA) |
---|
405 | |
---|
406 | % Hints: get(hObject,'String') returns contents of xyplot_min as text |
---|
407 | % str2double(get(hObject,'String')) returns contents of xyplot_min as a double |
---|
408 | |
---|
409 | data = get(handles.main,'UserData'); |
---|
410 | |
---|
411 | val = str2double(get(hObject,'String')); |
---|
412 | if ~isnan(val) |
---|
413 | data.xyplotaxis(1) = val; |
---|
414 | else |
---|
415 | msgbox('Invalid number'); |
---|
416 | set(hObject,'String',num2str(data.xyplotaxis(1))); |
---|
417 | end |
---|
418 | |
---|
419 | set(handles.main,'UserData',data); |
---|
420 | |
---|
421 | % --- Executes during object creation, after setting all properties. |
---|
422 | function xyplot_min_CreateFcn(hObject, eventdata, handles) |
---|
423 | % hObject handle to xyplot_min (see GCBO) |
---|
424 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
425 | % handles empty - handles not created until after all CreateFcns called |
---|
426 | |
---|
427 | % Hint: edit controls usually have a white background on Windows. |
---|
428 | % See ISPC and COMPUTER. |
---|
429 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
430 | set(hObject,'BackgroundColor','white'); |
---|
431 | end |
---|
432 | |
---|
433 | |
---|
434 | |
---|
435 | function tuneplot_max_Callback(hObject, eventdata, handles) |
---|
436 | % hObject handle to tuneplot_max (see GCBO) |
---|
437 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
438 | % handles structure with handles and user data (see GUIDATA) |
---|
439 | |
---|
440 | % Hints: get(hObject,'String') returns contents of tuneplot_max as text |
---|
441 | % str2double(get(hObject,'String')) returns contents of tuneplot_max as a double |
---|
442 | |
---|
443 | data = get(handles.main,'UserData'); |
---|
444 | |
---|
445 | val = str2double(get(hObject,'String')); |
---|
446 | if ~isnan(val) |
---|
447 | data.tuneplotaxis(2) = val; |
---|
448 | else |
---|
449 | msgbox('Invalid number'); |
---|
450 | set(hObject,'String',num2str(data.tuneplotaxis(2))); |
---|
451 | end |
---|
452 | |
---|
453 | set(handles.main,'UserData',data); |
---|
454 | |
---|
455 | % --- Executes during object creation, after setting all properties. |
---|
456 | function tuneplot_max_CreateFcn(hObject, eventdata, handles) |
---|
457 | % hObject handle to tuneplot_max (see GCBO) |
---|
458 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
459 | % handles empty - handles not created until after all CreateFcns called |
---|
460 | |
---|
461 | % Hint: edit controls usually have a white background on Windows. |
---|
462 | % See ISPC and COMPUTER. |
---|
463 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
464 | set(hObject,'BackgroundColor','white'); |
---|
465 | end |
---|
466 | |
---|
467 | |
---|
468 | |
---|
469 | function tuneplot_min_Callback(hObject, eventdata, handles) |
---|
470 | % hObject handle to tuneplot_min (see GCBO) |
---|
471 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
472 | % handles structure with handles and user data (see GUIDATA) |
---|
473 | |
---|
474 | % Hints: get(hObject,'String') returns contents of tuneplot_min as text |
---|
475 | % str2double(get(hObject,'String')) returns contents of tuneplot_min as a double |
---|
476 | |
---|
477 | data = get(handles.main,'UserData'); |
---|
478 | |
---|
479 | val = str2double(get(hObject,'String')); |
---|
480 | if ~isnan(val) |
---|
481 | data.tuneplotaxis(1) = val; |
---|
482 | else |
---|
483 | msgbox('Invalid number'); |
---|
484 | set(hObject,'String',num2str(data.tuneplotaxis(1))); |
---|
485 | end |
---|
486 | |
---|
487 | set(handles.main,'UserData',data); |
---|
488 | |
---|
489 | % --- Executes during object creation, after setting all properties. |
---|
490 | function tuneplot_min_CreateFcn(hObject, eventdata, handles) |
---|
491 | % hObject handle to tuneplot_min (see GCBO) |
---|
492 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
493 | % handles empty - handles not created until after all CreateFcns called |
---|
494 | |
---|
495 | % Hint: edit controls usually have a white background on Windows. |
---|
496 | % See ISPC and COMPUTER. |
---|
497 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
498 | set(hObject,'BackgroundColor','white'); |
---|
499 | end |
---|
500 | |
---|
501 | |
---|
502 | % --- Executes on button press in single_shot. |
---|
503 | function single_shot_Callback(hObject, eventdata, handles) |
---|
504 | % hObject handle to single_shot (see GCBO) |
---|
505 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
506 | % handles structure with handles and user data (see GUIDATA) |
---|
507 | |
---|
508 | data = get(handles.main,'UserData'); |
---|
509 | |
---|
510 | setlibera('TT_READY_STATUS',0,data.BPMdev); |
---|
511 | setlibera('TT_ARM_CMD',1,data.BPMdev); |
---|
512 | |
---|
513 | ii = 0; |
---|
514 | while ~getlibera('TT_READY_STATUS',data.BPMdev); |
---|
515 | pause(0.3); |
---|
516 | ii = ii + 1; |
---|
517 | if ii > 20 |
---|
518 | msgbox('Problem with this bpm. Maybe not triggering properly. Try another BPM'); |
---|
519 | return |
---|
520 | end |
---|
521 | end |
---|
522 | |
---|
523 | [data.sum temp datatime] = getlibera('TT_WF_S_MONITOR',data.BPMdev); |
---|
524 | data.x = getlibera('TT_WF_HPOS_MONITOR',data.BPMdev)/1e6; % convert into mm |
---|
525 | data.y = getlibera('TT_WF_VPOS_MONITOR',data.BPMdev)/1e6; % convert into mm |
---|
526 | |
---|
527 | % FFT |
---|
528 | npoints = 2^(floor(log2(length(data.fftturns)))); |
---|
529 | |
---|
530 | % FFT horizontal. Data stack is cleared everytime number of fft_turns is |
---|
531 | % changed |
---|
532 | XX = fft(data.x(data.fftturns) - mean(data.x(data.fftturns))); |
---|
533 | f = [0:npoints/2]/npoints; |
---|
534 | if size(data.Pxx,2) >= data.fftaverage |
---|
535 | % First In First Out, push data on stack |
---|
536 | data.Pxx(:,1:end-1) = data.Pxx(:,2:end); |
---|
537 | data.Pxx(:,end) = XX.*conj(XX)/npoints; |
---|
538 | else |
---|
539 | data.Pxx(:,end+1) = XX.*conj(XX)/npoints; |
---|
540 | end |
---|
541 | Pxx_mean = mean(data.Pxx(1:npoints/2+1,:),2); |
---|
542 | |
---|
543 | linehandle = get(handles.fft_x,'Children'); |
---|
544 | for i=1:length(linehandle) |
---|
545 | switch get(linehandle(i),'Tag') |
---|
546 | case 'fftx' |
---|
547 | set(linehandle(i),'XData',f,'YData',Pxx_mean); |
---|
548 | set(handles.fft_x,'YLim',data.fftxaxis(3:4),'XLim',data.fftxaxis(1:2)); |
---|
549 | case 'fftx_lower' |
---|
550 | set(linehandle(i),'XData',[data.fftxaxis(5) data.fftxaxis(5)],'YData',data.fftxaxis(3:4)); |
---|
551 | case 'fftx_upper' |
---|
552 | set(linehandle(i),'XData',[data.fftxaxis(6) data.fftxaxis(6)],'YData',data.fftxaxis(3:4)); |
---|
553 | end |
---|
554 | end |
---|
555 | |
---|
556 | % Detect peak within window |
---|
557 | indices = find(f > data.fftxaxis(5) & f < data.fftxaxis(6)); |
---|
558 | [temp xtuneind] = max(Pxx_mean(indices)); |
---|
559 | xtuneind = xtuneind + 3; |
---|
560 | if data.tuneind == data.maxtunesamples + 1 |
---|
561 | data.xtune(1:data.maxtunesamples-1) = data.xtune(2:data.maxtunesamples); |
---|
562 | data.xtune(data.maxtunesamples) = f(xtuneind+indices(1)); |
---|
563 | else |
---|
564 | data.xtune(data.tuneind) = f(xtuneind+indices(1)); |
---|
565 | end |
---|
566 | |
---|
567 | |
---|
568 | % FFT vertical. Data stack is cleared everytime number of fft_turns is |
---|
569 | % changed |
---|
570 | YY = fft(data.y(data.fftturns) - mean(data.y(data.fftturns))); |
---|
571 | f = [0:npoints/2]/npoints; |
---|
572 | if size(data.Pyy,2) >= data.fftaverage |
---|
573 | % First In First Out, push data on stack |
---|
574 | data.Pyy(:,1:end-1) = data.Pyy(:,2:end); |
---|
575 | data.Pyy(:,end) = YY.*conj(YY)/npoints; |
---|
576 | else |
---|
577 | data.Pyy(:,end+1) = YY.*conj(YY)/npoints; |
---|
578 | end |
---|
579 | Pyy_mean = mean(data.Pyy(1:npoints/2+1,:),2); |
---|
580 | |
---|
581 | |
---|
582 | linehandle = get(handles.fft_y,'Children'); |
---|
583 | for i=1:length(linehandle) |
---|
584 | switch get(linehandle(i),'Tag') |
---|
585 | case 'ffty' |
---|
586 | set(linehandle(i),'XData',f,'YData',Pyy_mean); |
---|
587 | set(handles.fft_y,'YLim',data.fftyaxis(3:4),'XLim',data.fftyaxis(1:2)); |
---|
588 | case 'ffty_lower' |
---|
589 | set(linehandle(i),'XData',[data.fftyaxis(5) data.fftyaxis(5)],'YData',data.fftyaxis(3:4)); |
---|
590 | case 'ffty_upper' |
---|
591 | set(linehandle(i),'XData',[data.fftyaxis(6) data.fftyaxis(6)],'YData',data.fftyaxis(3:4)); |
---|
592 | end |
---|
593 | end |
---|
594 | |
---|
595 | % Detect peak within window |
---|
596 | indices = find(f > data.fftyaxis(5) & f < data.fftyaxis(6)); |
---|
597 | [temp ytuneind] = max(Pyy_mean(indices)); |
---|
598 | ytuneind = ytuneind + 3; |
---|
599 | if data.tuneind == data.maxtunesamples + 1 |
---|
600 | data.ytune(1:data.maxtunesamples-1) = data.ytune(2:data.maxtunesamples); |
---|
601 | data.ytune(data.maxtunesamples) = f(ytuneind+indices(1)); |
---|
602 | else |
---|
603 | data.ytune(data.tuneind) = f(ytuneind+indices(1)); |
---|
604 | data.tuneind = data.tuneind + 1; |
---|
605 | end |
---|
606 | |
---|
607 | |
---|
608 | |
---|
609 | |
---|
610 | linehandle = get(handles.sum_plot,'Children'); |
---|
611 | set(linehandle,'YData',data.sum); |
---|
612 | set(handles.sum_plot,'XLim',[data.turns(1) data.turns(end)]); |
---|
613 | set(handles.sum_plot,'YLim',data.sumplotaxis); |
---|
614 | |
---|
615 | linehandle = get(handles.xy_plot,'Children'); |
---|
616 | for i=1:length(linehandle) |
---|
617 | switch get(linehandle(i),'Tag') |
---|
618 | case 'Horizontal' |
---|
619 | % only set the axis limits once since it should cycle through |
---|
620 | % both horizontal and vertical |
---|
621 | set(linehandle(i),'YData',data.x); |
---|
622 | set(handles.xy_plot,'XLim',[data.turns(1) data.turns(end)]); |
---|
623 | set(handles.xy_plot,'YLim',data.xyplotaxis); |
---|
624 | case 'Vertical' |
---|
625 | set(linehandle(i),'YData',data.y); |
---|
626 | end |
---|
627 | end |
---|
628 | |
---|
629 | linehandle = get(handles.tune_plot,'Children'); |
---|
630 | for i=1:length(linehandle) |
---|
631 | switch get(linehandle(i),'Tag') |
---|
632 | case 'Htune' |
---|
633 | set(linehandle(i),'YData',data.xtune); |
---|
634 | set(handles.tune_plot,'XLim',[1 data.maxtunesamples]); |
---|
635 | set(handles.tune_plot,'YLim',data.tuneplotaxis); |
---|
636 | case 'Vtune' |
---|
637 | set(linehandle(i),'YData',data.ytune); |
---|
638 | end |
---|
639 | end |
---|
640 | |
---|
641 | % Calculate Lifetime |
---|
642 | sumindex = 1000:1002; |
---|
643 | %sumindex2 = 5000:6000; |
---|
644 | currsum = mean(data.sum(sumindex)); |
---|
645 | %currsum2 = mean(data.sum(sumindex2)); |
---|
646 | data.currsumarray = [data.currsumarray currsum]; |
---|
647 | %data.currsumarray2 = [data.currsumarray2 currsum2]; |
---|
648 | %figure(10); |
---|
649 | %plot(data.currsumarray,'x-'); |
---|
650 | %hold on |
---|
651 | %plot(data.currsumarray2,'ro-'); |
---|
652 | %axis([1 length(data.currsumarray) 1.525e6 1.535e6]); |
---|
653 | %hold off; |
---|
654 | |
---|
655 | if isnan(data.prev_sum) |
---|
656 | data.lifetime = NaN; |
---|
657 | else |
---|
658 | data.lifetime = - currsum/(currsum-data.prev_sum)*(datatime - data.prev_time)*1e5/60; |
---|
659 | %data.lifetime = - currsum/(currsum-data.prev_sum)*1/60; |
---|
660 | end |
---|
661 | data.prev_sum = currsum; |
---|
662 | data.prev_time = datatime; |
---|
663 | if data.lifetime_handle ~= 0 |
---|
664 | mcaput(data.lifetime_handle,data.lifetime); |
---|
665 | end |
---|
666 | |
---|
667 | set(handles.lifetime_text,'String',sprintf('%+06.3f',data.lifetime)); |
---|
668 | |
---|
669 | |
---|
670 | set(handles.main,'UserData',data); |
---|
671 | |
---|
672 | |
---|
673 | |
---|
674 | function FFTturns_input_Callback(hObject, eventdata, handles) |
---|
675 | % hObject handle to FFTturns_input (see GCBO) |
---|
676 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
677 | % handles structure with handles and user data (see GUIDATA) |
---|
678 | |
---|
679 | % Hints: get(hObject,'String') returns contents of FFTturns_input as text |
---|
680 | % str2double(get(hObject,'String')) returns contents of FFTturns_input as a double |
---|
681 | data = get(handles.main,'UserData'); |
---|
682 | |
---|
683 | fftturnsstr = get(hObject,'String'); |
---|
684 | fftturns = eval(fftturnsstr); |
---|
685 | if isnumeric(fftturns) && fftturns(end) < data.maxturns |
---|
686 | data.fftturnsstr = fftturnsstr; |
---|
687 | data.fftturns = fftturns; |
---|
688 | % If changing fft turns then must reset FFT data structure due to |
---|
689 | % averaging. |
---|
690 | data.Pxx = []; |
---|
691 | data.Pyy = []; |
---|
692 | else |
---|
693 | msgbox(sprintf('Invalid FFT turns input. Max turns is < %d',data.maxturns)); |
---|
694 | set(hObject,'String',data.fftturnsstr); |
---|
695 | end |
---|
696 | |
---|
697 | set(handles.main,'UserData',data); |
---|
698 | |
---|
699 | |
---|
700 | % --- Executes during object creation, after setting all properties. |
---|
701 | function FFTturns_input_CreateFcn(hObject, eventdata, handles) |
---|
702 | % hObject handle to FFTturns_input (see GCBO) |
---|
703 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
704 | % handles empty - handles not created until after all CreateFcns called |
---|
705 | |
---|
706 | % Hint: edit controls usually have a white background on Windows. |
---|
707 | % See ISPC and COMPUTER. |
---|
708 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
709 | set(hObject,'BackgroundColor','white'); |
---|
710 | end |
---|
711 | |
---|
712 | |
---|
713 | |
---|
714 | |
---|
715 | % --- Executes when main is resized. |
---|
716 | function main_ResizeFcn(hObject, eventdata, handles) |
---|
717 | % hObject handle to main (see GCBO) |
---|
718 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
719 | % handles structure with handles and user data (see GUIDATA) |
---|
720 | |
---|
721 | |
---|
722 | |
---|
723 | function fftyaxis_Callback(hObject, eventdata, handles) |
---|
724 | % hObject handle to fftyaxis (see GCBO) |
---|
725 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
726 | % handles structure with handles and user data (see GUIDATA) |
---|
727 | |
---|
728 | % Hints: get(hObject,'String') returns contents of fftyaxis as text |
---|
729 | % str2double(get(hObject,'String')) returns contents of fftyaxis as a double |
---|
730 | data = get(handles.main,'UserData'); |
---|
731 | |
---|
732 | fftystr = get(hObject,'String'); |
---|
733 | data.fftyaxis = eval(fftystr); |
---|
734 | |
---|
735 | set(handles.main,'UserData',data); |
---|
736 | |
---|
737 | % --- Executes during object creation, after setting all properties. |
---|
738 | function fftyaxis_CreateFcn(hObject, eventdata, handles) |
---|
739 | % hObject handle to fftyaxis (see GCBO) |
---|
740 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
741 | % handles empty - handles not created until after all CreateFcns called |
---|
742 | |
---|
743 | % Hint: edit controls usually have a white background on Windows. |
---|
744 | % See ISPC and COMPUTER. |
---|
745 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
746 | set(hObject,'BackgroundColor','white'); |
---|
747 | end |
---|
748 | |
---|
749 | |
---|
750 | |
---|
751 | function fftxaxis_Callback(hObject, eventdata, handles) |
---|
752 | % hObject handle to fftxaxis (see GCBO) |
---|
753 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
754 | % handles structure with handles and user data (see GUIDATA) |
---|
755 | |
---|
756 | % Hints: get(hObject,'String') returns contents of fftxaxis as text |
---|
757 | % str2double(get(hObject,'String')) returns contents of fftxaxis as a double |
---|
758 | data = get(handles.main,'UserData'); |
---|
759 | |
---|
760 | fftxstr = get(hObject,'String'); |
---|
761 | data.fftxaxis = eval(fftxstr); |
---|
762 | |
---|
763 | set(handles.main,'UserData',data); |
---|
764 | |
---|
765 | % --- Executes during object creation, after setting all properties. |
---|
766 | function fftxaxis_CreateFcn(hObject, eventdata, handles) |
---|
767 | % hObject handle to fftxaxis (see GCBO) |
---|
768 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
769 | % handles empty - handles not created until after all CreateFcns called |
---|
770 | |
---|
771 | % Hint: edit controls usually have a white background on Windows. |
---|
772 | % See ISPC and COMPUTER. |
---|
773 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) |
---|
774 | set(hObject,'BackgroundColor','white'); |
---|
775 | end |
---|
776 | |
---|
777 | |
---|
778 | |
---|
779 | |
---|
780 | % --- Executes when user attempts to close main. |
---|
781 | function main_CloseRequestFcn(hObject, eventdata, handles) |
---|
782 | % hObject handle to main (see GCBO) |
---|
783 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
784 | % handles structure with handles and user data (see GUIDATA) |
---|
785 | |
---|
786 | % Hint: delete(hObject) closes the figure |
---|
787 | |
---|
788 | % If the continuous update still running, then turn off before closing |
---|
789 | % window. Else it will loop and keep creating new figure, new application. |
---|
790 | if get(handles.start_stop,'Value') |
---|
791 | set(handles.start_stop,'Value',0); |
---|
792 | start_stop_Callback(handles.start_stop, eventdata, handles) |
---|
793 | end |
---|
794 | |
---|
795 | % Close handle for the PV holding the lifetime values. |
---|
796 | data = get(handles.main,'UserData'); |
---|
797 | |
---|
798 | delete(hObject); |
---|
799 | |
---|
800 | |
---|
801 | |
---|
802 | |
---|