PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/testApps/bpmgui/bpmgui.m

http://atf2flightsim.googlecode.com/
MATLAB | 470 lines | 243 code | 74 blank | 153 comment | 34 complexity | 6b2967e3772f71cd0e405b595f97a1a3 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = bpmgui(varargin)
  2. % BPMGUI M-file for bpmgui.fig
  3. % BPMGUI, by itself, creates a new BPMGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = BPMGUI returns the handle to a new BPMGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % BPMGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in BPMGUI.M with the given input arguments.
  11. %
  12. % BPMGUI('Property','Value',...) creates a new BPMGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before bpmgui_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to bpmgui_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. % Edit the above text to modify the response to help bpmgui
  23. % Last Modified by GUIDE v2.5 07-Apr-2009 16:39:37
  24. % Begin initialization code - DO NOT EDIT
  25. gui_Singleton = 1;
  26. gui_State = struct('gui_Name', mfilename, ...
  27. 'gui_Singleton', gui_Singleton, ...
  28. 'gui_OpeningFcn', @bpmgui_OpeningFcn, ...
  29. 'gui_OutputFcn', @bpmgui_OutputFcn, ...
  30. 'gui_LayoutFcn', [] , ...
  31. 'gui_Callback', []);
  32. if nargin && ischar(varargin{1})
  33. gui_State.gui_Callback = str2func(varargin{1});
  34. end
  35. if nargout
  36. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  37. else
  38. gui_mainfcn(gui_State, varargin{:});
  39. end
  40. % End initialization code - DO NOT EDIT
  41. % --- Executes just before bpmgui is made visible.
  42. function bpmgui_OpeningFcn(hObject, eventdata, handles, varargin) %#ok<*INUSL>
  43. % This function has no output args, see OutputFcn.
  44. % hObject handle to figure
  45. % eventdata reserved - to be defined in a future version of MATLAB
  46. % handles structure with handles and user data (see GUIDATA)
  47. % varargin command line arguments to bpmgui (see VARARGIN)
  48. % Choose default command line output for bpmgui
  49. handles.output = hObject;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % UIWAIT makes bpmgui wait for user response (see UIRESUME)
  53. % uiwait(handles.figure1);
  54. set(handles.uipanel1,'Title','Paused')
  55. set(handles.uipanel1,'ForegroundColor',[1 0 0])
  56. global GUI_DATA %grabdata_t
  57. % grabdata_t = timer('TimerFcn',{@grabdata,handles},'Period',0.64,...
  58. % 'ExecutionMode','fixedSpacing');
  59. % start(grabdata_t);
  60. % drawnow
  61. GUI_DATA.ave = 0;
  62. GUI_DATA.avval = 10;
  63. GUI_DATA.plotrms = 0;
  64. GUI_DATA.type = 'abs';
  65. GUI_DATA.counter = 0;
  66. GUI_DATA.fsimmode = true;
  67. % --- Outputs from this function are returned to the command line.
  68. function varargout = bpmgui_OutputFcn(hObject, eventdata, handles)
  69. % varargout cell array for returning output args (see VARARGOUT);
  70. % hObject handle to figure
  71. % eventdata reserved - to be defined in a future version of MATLAB
  72. % handles structure with handles and user data (see GUIDATA)
  73. % Get default command line output from handles structure
  74. varargout{1} = handles.output;
  75. % --- Executes on selection change in popupmenu1.
  76. function popupmenu1_Callback(hObject, eventdata, handles)
  77. % hObject handle to popupmenu1 (see GCBO)
  78. % eventdata reserved - to be defined in a future version of MATLAB
  79. % handles structure with handles and user data (see GUIDATA)
  80. %
  81. % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
  82. % contents{get(hObject,'Value')} returns selected item from popupmenu1
  83. % --- Executes during object creation, after setting all properties.
  84. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  85. % hObject handle to popupmenu1 (see GCBO)
  86. % eventdata reserved - to be defined in a future version of MATLAB
  87. % handles empty - handles not created until after all CreateFcns called
  88. % Hint: popupmenu controls usually have a white background on Windows.
  89. % See ISPC and COMPUTER.
  90. if ispc && isequal(get(hObject,'BackgroundColor'), ...
  91. get(0,'defaultUicontrolBackgroundColor'))
  92. set(hObject,'BackgroundColor','white');
  93. end
  94. % --- Executes on button press in togglebutton1.
  95. function togglebutton1_Callback(hObject, eventdata, handles)
  96. % hObject handle to togglebutton1 (see GCBO)
  97. % eventdata reserved - to be defined in a future version of MATLAB
  98. % handles structure with handles and user data (see GUIDATA)
  99. %
  100. % Hint: get(hObject,'Value') returns toggle state of togglebutton1
  101. global BEAM_DATA GUI_DATA BEAMLINE INSTR %grabdata_t
  102. if isempty(BEAM_DATA)
  103. BEAM_DATA.x = nan;
  104. BEAM_DATA.y = nan;
  105. end
  106. buttonval = get(hObject,'Value');
  107. if buttonval
  108. set(hObject,'String','CLICK TO PAUSE')
  109. set(handles.uipanel1,'Title','Running')
  110. set(handles.uipanel1,'ForegroundColor',[0 1 0])
  111. set(hObject,'BackgroundColor',[1 0 0])
  112. else
  113. set(hObject,'String','CLICK TO RUN')
  114. set(handles.uipanel1,'Title','Paused')
  115. set(handles.uipanel1,'ForegroundColor',[1 0 0])
  116. set(hObject,'BackgroundColor',[0 1 0])
  117. end
  118. [stat GUI_DATA.counter] = FlHwUpdate('getpulsenum');
  119. while buttonval
  120. [stat newnum] = FlHwUpdate('getpulsenum');
  121. while GUI_DATA.counter == newnum
  122. pause(0.2)
  123. [stat newnum] = FlHwUpdate('getpulsenum');
  124. end
  125. GUI_DATA.counter = newnum;
  126. try
  127. axes1as = get(handles.radiobutton3,'Value');
  128. axes1man = get(handles.radiobutton4,'Value');
  129. axes1minval = str2double(get(handles.edit1,'String'));
  130. axes1maxval = str2double(get(handles.edit2,'String'));
  131. axes1currval = ylim(handles.axes1);
  132. axes2as = get(handles.radiobutton7,'Value');
  133. axes2man = get(handles.radiobutton8,'Value');
  134. axes2minval = str2double(get(handles.edit5,'String'));
  135. axes2maxval = str2double(get(handles.edit6,'String'));
  136. axes2currval = ylim(handles.axes2);
  137. axes3as = get(handles.radiobutton9,'Value');
  138. axes3man = get(handles.radiobutton10,'Value');
  139. axes3minval = str2double(get(handles.edit7,'String'));
  140. axes3maxval = str2double(get(handles.edit8,'String'));
  141. axes3currval = ylim(handles.axes3);
  142. catch %#ok<*CTCH>
  143. close all
  144. buttonval = 0; %#ok<*NASGU>
  145. continue
  146. end
  147. if axes1minval >= axes1maxval
  148. axes1minval = axes1currval(1);
  149. axes1maxval = axes1currval(2);
  150. end
  151. if axes2minval >= axes2maxval
  152. axes2minval = axes2currval(1);
  153. axes2maxval = axes2currval(2);
  154. end
  155. if axes3minval >= axes3maxval
  156. axes3minval = axes3currval(1);
  157. axes3maxval = axes3currval(2);
  158. end
  159. if buttonval == 0; break; end
  160. if GUI_DATA.ave
  161. [stat output] = FlHwUpdate('bpmave',GUI_DATA.avval);
  162. BEAM_DATA.x = output{1}(1,:);
  163. BEAM_DATA.y = output{1}(2,:);
  164. BEAM_DATA.rmsx = output{1}(4,:);
  165. BEAM_DATA.rmsy = output{1}(5,:);
  166. BEAM_DATA.q = cellfun(@(x) x.Data(3),INSTR);
  167. BEAM_DATA.s = zeros(1,length(INSTR));
  168. for bpmnum=1:length(INSTR)
  169. BEAM_DATA.s(bpmnum) = BEAMLINE{INSTR{bpmnum}.Index}.S;
  170. end
  171. else
  172. FlHwUpdate;
  173. BEAM_DATA.x = cellfun(@(x) x.Data(1),INSTR);
  174. BEAM_DATA.rmsx = zeros(size(BEAM_DATA.x));
  175. BEAM_DATA.y = cellfun(@(x) x.Data(2),INSTR);
  176. BEAM_DATA.rmsy = zeros(size(BEAM_DATA.y));
  177. BEAM_DATA.q = cellfun(@(x) x.Data(3),INSTR);
  178. BEAM_DATA.s = zeros(1,length(INSTR));
  179. for bpmnum=1:length(INSTR)
  180. BEAM_DATA.s(bpmnum) = BEAMLINE{INSTR{bpmnum}.Index}.S;
  181. end
  182. end
  183. set(handles.pushbutton1,'Enable','on');
  184. if strcmp(GUI_DATA.type,'abs')
  185. x = BEAM_DATA.x;
  186. y = BEAM_DATA.y;
  187. s = BEAM_DATA.s;
  188. q = BEAM_DATA.q;
  189. elseif strcmp(GUI_DATA.type,'dif')
  190. x = BEAM_DATA.x - GUI_DATA.reference(1,:);
  191. y = BEAM_DATA.y - GUI_DATA.reference(2,:);
  192. s = BEAM_DATA.s;
  193. q = BEAM_DATA.q;
  194. end
  195. % order with s
  196. [s,sortI]=sort(s);
  197. x=x(sortI); y=y(sortI); q=q(sortI);
  198. if GUI_DATA.ave && GUI_DATA.plotrms
  199. hold(handles.axes1,'off')
  200. plot(handles.axes1,s,x*1e3,'bx')
  201. xlim(handles.axes1,[0 s(end)])
  202. hold(handles.axes1,'on')
  203. plot(handles.axes1,s,x*1e3+BEAM_DATA.rmsx*1e3,'xr')
  204. plot(handles.axes1,s,x*1e3-BEAM_DATA.rmsx*1e3,'xr')
  205. else
  206. hold(handles.axes1,'off')
  207. plot(handles.axes1,s,x*1e3,'bx')
  208. xlim(handles.axes1,[0 s(end)])
  209. end
  210. ylabel(handles.axes1,'x / mm')
  211. if axes1as
  212. ylim(handles.axes1,'auto')
  213. elseif axes1man
  214. % ylim('manual')
  215. minval = axes1minval;
  216. maxval = axes1maxval;
  217. if isnan(minval)
  218. temp = ylim;
  219. minval = temp(1);
  220. end
  221. if isnan(maxval)
  222. temp = ylim;
  223. maxval = temp(2);
  224. end
  225. ylim(handles.axes1,[minval maxval])
  226. end
  227. if GUI_DATA.ave && GUI_DATA.plotrms
  228. hold(handles.axes2,'off')
  229. plot(handles.axes2,s,y*1e3,'bx')
  230. xlim(handles.axes2,[0 BEAM_DATA.s(end)])
  231. hold(handles.axes2,'on')
  232. plot(handles.axes2,s,y*1e3+BEAM_DATA.rmsy*1e3,'xr')
  233. plot(handles.axes2,s,y*1e3-BEAM_DATA.rmsy*1e3,'xr')
  234. else
  235. hold(handles.axes2,'off')
  236. plot(handles.axes2,s,y*1e3,'bx')
  237. xlim(handles.axes2,[0 BEAM_DATA.s(end)])
  238. end
  239. ylabel(handles.axes2,'y / mm')
  240. if axes2as
  241. ylim(handles.axes2,'auto')
  242. elseif axes2man
  243. % ylim('manual')
  244. minval = axes2minval;
  245. maxval = axes2maxval;
  246. if isnan(minval)
  247. temp = ylim;
  248. minval = temp(1);
  249. end
  250. if isnan(maxval)
  251. temp = ylim;
  252. maxval = temp(2);
  253. end
  254. ylim(handles.axes2,[minval maxval])
  255. end
  256. [s_plot i_plot]=unique(s);
  257. bar(handles.axes3,s_plot,q(i_plot))
  258. xlim(handles.axes3,[0 BEAM_DATA.s(end)])
  259. ylabel(handles.axes3,'# of e-')
  260. if axes3as
  261. ylim(handles.axes3,'auto')
  262. elseif axes3man
  263. % ylim('manual')
  264. minval = axes3minval;
  265. maxval = axes3maxval;
  266. if isnan(minval)
  267. temp = ylim;
  268. minval = temp(1);
  269. end
  270. if isnan(maxval)
  271. temp = ylim;
  272. maxval = temp(2);
  273. end
  274. ylim(handles.axes3,[minval maxval])
  275. end
  276. try
  277. buttonval = get(hObject,'Value');
  278. catch
  279. close all
  280. buttonval=0;
  281. continue
  282. end
  283. end
  284. % --- Executes on button press in pushbutton1.
  285. function pushbutton1_Callback(hObject, eventdata, handles) %#ok<*DEFNU,*INUSD>
  286. % hObject handle to pushbutton1 (see GCBO)
  287. % eventdata reserved - to be defined in a future version of MATLAB
  288. % handles structure with handles and user data (see GUIDATA)
  289. % This function switches off the timer (if it's on), calculates a reference
  290. % waveform, and switches it back on (if it was on originally).
  291. %
  292. % Need to acquire a reference. Stop the GUI updating (if necessary), then
  293. % grab the ref from FlHwUpdate('bpmave'), and restart (if it was running
  294. % originally).
  295. % global GUI_DATA INSTR %grabdata_t
  296. %
  297. % tdata = get(grabdata_t);
  298. %
  299. % if strcmp(tdata.Running,'off')
  300. % if GUI_DATA.ave
  301. % [stat output] = FlHwUpdate('bpmave',GUI_DATA.avval);
  302. % GUI_DATA.reference(1,:) = output{1}(1,:);
  303. % GUI_DATA.reference(2,:) = output{1}(2,:);
  304. % else
  305. % FlHwUpdate;
  306. % GUI_DATA.reference(1,:) = cellfun(@(x) x.Data(1),INSTR);
  307. % GUI_DATA.reference(2,:) = cellfun(@(x) x.Data(2),INSTR);
  308. % end
  309. %
  310. % else
  311. % if GUI_DATA.ave
  312. % stop(grabdata_t)
  313. % while strcmp(tdata.Running,'on')
  314. % pause(0.1)
  315. % tdata = get(grabdata_t);
  316. % end
  317. % [stat output] = FlHwUpdate('bpmave',GUI_DATA.avval);
  318. % GUI_DATA.reference(1,:) = output{1}(1,:);
  319. % GUI_DATA.reference(2,:) = output{1}(2,:);
  320. % start(grabdata_t)
  321. % else
  322. % stop(grabdata_t)
  323. % while strcmp(tdata.Running,'on')
  324. % pause(0.1)
  325. % tdata = get(grabdata_t);
  326. % end
  327. % FlHwUpdate;
  328. % GUI_DATA.reference(1,:) = cellfun(@(x) x.Data(1),INSTR);
  329. % GUI_DATA.reference(2,:) = cellfun(@(x) x.Data(2),INSTR);
  330. % start(grabdata_t)
  331. % end
  332. % end
  333. global GUI_DATA BEAM_DATA
  334. GUI_DATA.reference(1,:) = BEAM_DATA.x;
  335. GUI_DATA.reference(2,:) = BEAM_DATA.y;
  336. % --- Executes on button press in checkbox1.
  337. function checkbox1_Callback(hObject, eventdata, handles)
  338. % hObject handle to checkbox1 (see GCBO)
  339. % eventdata reserved - to be defined in a future version of MATLAB
  340. % handles structure with handles and user data (see GUIDATA)
  341. %
  342. % Hint: get(hObject,'Value') returns toggle state of checkbox1
  343. global GUI_DATA
  344. GUI_DATA.plotrms = get(hObject,'Value');
  345. % --- Executes during object deletion, before destroying properties.
  346. function figure1_DeleteFcn(hObject, eventdata, handles)
  347. % hObject handle to figure1 (see GCBO)
  348. % eventdata reserved - to be defined in a future version of MATLAB
  349. % handles structure with handles and user data (see GUIDATA)
  350. %
  351. % global grabdata_t
  352. %
  353. % state = get(handles.togglebutton1,'Value');
  354. % if state
  355. % togglebutton1_Callback(hObject, eventdata, handles)
  356. % pause(0.5)
  357. % end
  358. clear global GUI_DATA BEAM_DATA
  359. % --- Executes on button press in radiobutton12.
  360. function radiobutton12_Callback(hObject, eventdata, handles)
  361. % hObject handle to radiobutton12 (see GCBO)
  362. % eventdata reserved - to be defined in a future version of MATLAB
  363. % handles structure with handles and user data (see GUIDATA)
  364. % Hint: get(hObject,'Value') returns toggle state of radiobutton12
  365. global GUI_DATA
  366. GUI_DATA.ave = get(hObject,'Value');
  367. % --- Executes on button press in radiobutton11.
  368. function radiobutton11_Callback(hObject, eventdata, handles)
  369. % hObject handle to radiobutton11 (see GCBO)
  370. % eventdata reserved - to be defined in a future version of MATLAB
  371. % handles structure with handles and user data (see GUIDATA)
  372. % Hint: get(hObject,'Value') returns toggle state of radiobutton11
  373. global GUI_DATA
  374. GUI_DATA.ave = ~get(hObject,'Value');
  375. % --- Executes on button press in radiobutton1.
  376. function radiobutton1_Callback(hObject, eventdata, handles)
  377. % hObject handle to radiobutton1 (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. % Hint: get(hObject,'Value') returns toggle state of radiobutton1
  381. global GUI_DATA
  382. GUI_DATA.type = 'abs';
  383. % --- Executes on button press in radiobutton2.
  384. function radiobutton2_Callback(hObject, eventdata, handles)
  385. % hObject handle to radiobutton2 (see GCBO)
  386. % eventdata reserved - to be defined in a future version of MATLAB
  387. % handles structure with handles and user data (see GUIDATA)
  388. % Hint: get(hObject,'Value') returns toggle state of radiobutton2
  389. global GUI_DATA
  390. GUI_DATA.type = 'dif';
  391. if ~isfield(GUI_DATA,'reference')
  392. GUI_DATA.reference = zeros(2,numbpms);
  393. end
  394. if ~isnumeric(GUI_DATA.reference) && ~ndims(GUI_DATA.reference)==2
  395. GUI_DATA.reference = zeros(2,numbpms);
  396. end