PageRenderTime 60ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/watchdogApps/apertures/aperturesGui.m

http://atf2flightsim.googlecode.com/
MATLAB | 1347 lines | 800 code | 178 blank | 369 comment | 133 complexity | 74d4f49d0da3770be07b30a96edd6910 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = aperturesGui(varargin)
  2. % APERTURESGUI M-file for aperturesGui.fig
  3. % APERTURESGUI, by itself, creates a new APERTURESGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = APERTURESGUI returns the handle to a new APERTURESGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % APERTURESGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in APERTURESGUI.M with the given input arguments.
  11. %
  12. % APERTURESGUI('Property','Value',...) creates a new APERTURESGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before aperturesGui_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to aperturesGui_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 aperturesGui
  23. % Last Modified by GUIDE v2.5 23-Oct-2009 18:15:48
  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', @aperturesGui_OpeningFcn, ...
  29. 'gui_OutputFcn', @aperturesGui_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 aperturesGui is made visible.
  42. function aperturesGui_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 aperturesGui (see VARARGIN)
  48. global INSTR
  49. % Choose default command line output for aperturesGui
  50. handles.output = handles;
  51. % Update handles structure
  52. guidata(hObject, handles);
  53. % UIWAIT makes aperturesGui wait for user response (see UIRESUME)
  54. % uiwait(handles.figure1);
  55. % Get alarm status
  56. [stat alarm]=apertures('IsAlarm');
  57. setAlarm(handles,alarm);
  58. % Check a reference orbit exists
  59. if ~isfield(INSTR{1},'ref')
  60. errordlg('No reference orbit in INSTR array, aborting startup','Apertures GUI Error')
  61. delete(handles.figure1)
  62. return
  63. end
  64. % Setup aperture list
  65. [stat data]=apertures('GetData'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  66. setApList(handles,data);
  67. % Set GUI fields from pars
  68. [stat pars]=apertures('GetPars'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  69. setPars(handles,pars);
  70. % Plot data
  71. apPlot(handles);
  72. % Tell apertures gui is active
  73. newpars.guiActive=true;
  74. apertures('SetPars',newpars);
  75. % --- Outputs from this function are returned to the command line.
  76. function varargout = aperturesGui_OutputFcn(hObject, eventdata, handles)
  77. % varargout cell array for returning output args (see VARARGOUT);
  78. % hObject handle to figure
  79. % eventdata reserved - to be defined in a future version of MATLAB
  80. % handles structure with handles and user data (see GUIDATA)
  81. % Get default command line output from handles structure
  82. varargout{1} = handles.output;
  83. % --- EXIT button
  84. function pushbutton1_Callback(hObject, eventdata, handles) %#ok<*DEFNU>
  85. % hObject handle to pushbutton1 (see GCBO)
  86. % eventdata reserved - to be defined in a future version of MATLAB
  87. % handles structure with handles and user data (see GUIDATA)
  88. apertures('save');
  89. newpars.guiActive=false;
  90. apertures('SetPars',newpars);
  91. guiCloseFn('aperturesGui',handles);
  92. % --- BPM Orbit Plots figure
  93. function pushbutton2_Callback(hObject, eventdata, handles) %#ok<*INUSD>
  94. % hObject handle to pushbutton2 (see GCBO)
  95. % eventdata reserved - to be defined in a future version of MATLAB
  96. % handles structure with handles and user data (see GUIDATA)
  97. global FL
  98. FL.Gui.aperturesGui_plot1=figure;
  99. apPlot(handles);
  100. % --- Aperture List
  101. function popupmenu1_Callback(hObject, eventdata, handles)
  102. % hObject handle to popupmenu1 (see GCBO)
  103. % eventdata reserved - to be defined in a future version of MATLAB
  104. % handles structure with handles and user data (see GUIDATA)
  105. % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
  106. % contents{get(hObject,'Value')} returns selected item from popupmenu1
  107. [stat pars]=apertures('GetPars'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  108. setPars(handles,pars)
  109. pushbutton9_Callback(handles.pushbutton9,[],handles);
  110. % --- Executes during object creation, after setting all properties.
  111. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  112. % hObject handle to popupmenu1 (see GCBO)
  113. % eventdata reserved - to be defined in a future version of MATLAB
  114. % handles empty - handles not created until after all CreateFcns called
  115. % Hint: popupmenu controls usually have a white background on Windows.
  116. % See ISPC and COMPUTER.
  117. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  118. set(hObject,'BackgroundColor','white');
  119. end
  120. % aperture x/y offset
  121. function edit1_Callback(hObject, eventdata, handles)
  122. % hObject handle to edit1 (see GCBO)
  123. % eventdata reserved - to be defined in a future version of MATLAB
  124. % handles structure with handles and user data (see GUIDATA)
  125. % Hints: get(hObject,'String') returns contents of edit1 as text
  126. % str2double(get(hObject,'String')) returns contents of edit1 as a double
  127. % Get ap name
  128. aplist=get(handles.popupmenu1,'String');
  129. aname=aplist{get(handles.popupmenu1,'Value')};
  130. [stat pars]=apertures('GetPars');
  131. if stat{1}~=1
  132. errordlg(stat{2},'GetPars error')
  133. return
  134. end
  135. if get(handles.radiobutton1,'Value')
  136. fn='xoff';
  137. else
  138. fn='yoff';
  139. end
  140. newpars.(aname).(fn)=str2double(get(hObject,'String'))*1e-3;
  141. if isnan(newpars.(aname).(fn))
  142. set(hObject,'String',num2str(pars.(aname).(fn)))
  143. return
  144. end
  145. smin=get(handles.slider3,'Min'); smax=get(handles.slider3,'Max');
  146. if newpars.(aname).(fn)<smin || newpars.(aname).(fn)>smax
  147. errordlg([fn,' Value out of slider range'],'Aperture set error')
  148. return
  149. end
  150. set(handles.slider3,'Value',newpars.(aname).(fn))
  151. stat=apertures('SetPars',newpars);
  152. if stat{1}~=1
  153. errordlg(stat{2},'SetPars error')
  154. set(hObject,'String',num2str(pars.(aname).(fn)))
  155. return
  156. end
  157. pushbutton9_Callback(handles.pushbutton9,[],handles);
  158. % --- Executes during object creation, after setting all properties.
  159. function edit1_CreateFcn(hObject, eventdata, handles)
  160. % hObject handle to edit1 (see GCBO)
  161. % eventdata reserved - to be defined in a future version of MATLAB
  162. % handles empty - handles not created until after all CreateFcns called
  163. % Hint: edit controls usually have a white background on Windows.
  164. % See ISPC and COMPUTER.
  165. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  166. set(hObject,'BackgroundColor','white');
  167. end
  168. % --- xp/yp offset
  169. function edit2_Callback(hObject, eventdata, handles)
  170. % hObject handle to edit2 (see GCBO)
  171. % eventdata reserved - to be defined in a future version of MATLAB
  172. % handles structure with handles and user data (see GUIDATA)
  173. % Hints: get(hObject,'String') returns contents of edit2 as text
  174. % str2double(get(hObject,'String')) returns contents of edit2 as a double
  175. aplist=get(handles.popupmenu1,'String');
  176. aname=aplist{get(handles.popupmenu1,'Value')};
  177. [stat pars]=apertures('GetPars');
  178. if stat{1}~=1
  179. errordlg(stat{2},'GetPars error')
  180. return
  181. end
  182. if get(handles.radiobutton1,'Value')
  183. fn='xpoff';
  184. else
  185. fn='ypoff';
  186. end
  187. newpars.(aname).(fn)=str2double(get(hObject,'String'))*1e-3;
  188. if isnan(newpars.(aname).(fn))
  189. set(hObject,'String',num2str(pars.(aname).(fn)))
  190. return
  191. end
  192. smin=get(handles.slider4,'Min'); smax=get(handles.slider4,'Max');
  193. if newpars.(aname).(fn)<smin || newpars.(aname).(fn)>smax
  194. errordlg([fn,' Value out of slider range'],'Aperture set error')
  195. return
  196. end
  197. set(handles.slider4,'Value',newpars.(aname).(fn))
  198. stat=apertures('SetPars',newpars);
  199. if stat{1}~=1
  200. errordlg(stat{2},'SetPars error')
  201. set(hObject,'String',num2str(pars.(aname).(fn)))
  202. return
  203. end
  204. pushbutton9_Callback(handles.pushbutton9,[],handles);
  205. % --- Executes during object creation, after setting all properties.
  206. function edit2_CreateFcn(hObject, eventdata, handles)
  207. % hObject handle to edit2 (see GCBO)
  208. % eventdata reserved - to be defined in a future version of MATLAB
  209. % handles empty - handles not created until after all CreateFcns called
  210. % Hint: edit controls usually have a white background on Windows.
  211. % See ISPC and COMPUTER.
  212. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  213. set(hObject,'BackgroundColor','white');
  214. end
  215. % --- aperture rotation
  216. function edit3_Callback(hObject, eventdata, handles)
  217. % hObject handle to edit3 (see GCBO)
  218. % eventdata reserved - to be defined in a future version of MATLAB
  219. % handles structure with handles and user data (see GUIDATA)
  220. % Hints: get(hObject,'String') returns contents of edit3 as text
  221. % str2double(get(hObject,'String')) returns contents of edit3 as a double
  222. aplist=get(handles.popupmenu1,'String');
  223. aname=aplist{get(handles.popupmenu1,'Value')};
  224. [stat pars]=apertures('GetPars');
  225. if stat{1}~=1
  226. errordlg(stat{2},'GetPars error')
  227. return
  228. end
  229. if get(handles.radiobutton1,'Value')
  230. fn='xrot';
  231. else
  232. fn='yrot';
  233. end
  234. newpars.(aname).(fn)=str2double(get(hObject,'String'));
  235. if isnan(newpars.(aname).(fn))
  236. set(hObject,'String',num2str(pars.(aname).(fn)))
  237. return
  238. end
  239. smin=get(handles.slider5,'Min'); smax=get(handles.slider5,'Max');
  240. if newpars.(aname).(fn)<smin || newpars.(aname).(fn)>smax
  241. errordlg([fn,' Value out of slider range'],'Aperture set error')
  242. return
  243. end
  244. set(handles.slider5,'Value',newpars.(aname).(fn))
  245. stat=apertures('SetPars',newpars);
  246. if stat{1}~=1
  247. errordlg(stat{2},'SetPars error')
  248. set(hObject,'String',num2str(pars.(aname).(fn)))
  249. return
  250. end
  251. % --- Executes during object creation, after setting all properties.
  252. function edit3_CreateFcn(hObject, eventdata, handles)
  253. % hObject handle to edit3 (see GCBO)
  254. % eventdata reserved - to be defined in a future version of MATLAB
  255. % handles empty - handles not created until after all CreateFcns called
  256. % Hint: edit controls usually have a white background on Windows.
  257. % See ISPC and COMPUTER.
  258. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  259. set(hObject,'BackgroundColor','white');
  260. end
  261. % --- aperture width
  262. function edit4_Callback(hObject, eventdata, handles)
  263. % hObject handle to edit4 (see GCBO)
  264. % eventdata reserved - to be defined in a future version of MATLAB
  265. % handles structure with handles and user data (see GUIDATA)
  266. % Hints: get(hObject,'String') returns contents of edit4 as text
  267. % str2double(get(hObject,'String')) returns contents of edit4 as a double
  268. aplist=get(handles.popupmenu1,'String');
  269. aname=aplist{get(handles.popupmenu1,'Value')};
  270. [stat pars]=apertures('GetPars');
  271. if stat{1}~=1
  272. errordlg(stat{2},'GetPars error')
  273. return
  274. end
  275. if get(handles.radiobutton1,'Value')
  276. fn='xwid';
  277. else
  278. fn='ywid';
  279. end
  280. newpars.(aname).(fn)=str2double(get(hObject,'String'))*1e-3;
  281. if isnan(newpars.(aname).(fn))
  282. set(hObject,'String',num2str(pars.(aname).(fn)))
  283. return
  284. end
  285. smin=get(handles.slider1,'Min'); smax=get(handles.slider1,'Max');
  286. if newpars.(aname).(fn)<smin || newpars.(aname).(fn)>smax
  287. errordlg([fn,' Value out of slider range'],'Aperture set error')
  288. return
  289. end
  290. set(handles.slider1,'Value',newpars.(aname).(fn))
  291. stat=apertures('SetPars',newpars);
  292. if stat{1}~=1
  293. errordlg(stat{2},'SetPars error')
  294. set(hObject,'String',num2str(pars.(aname).(fn)))
  295. return
  296. end
  297. % --- Executes during object creation, after setting all properties.
  298. function edit4_CreateFcn(hObject, eventdata, handles)
  299. % hObject handle to edit4 (see GCBO)
  300. % eventdata reserved - to be defined in a future version of MATLAB
  301. % handles empty - handles not created until after all CreateFcns called
  302. % Hint: edit controls usually have a white background on Windows.
  303. % See ISPC and COMPUTER.
  304. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  305. set(hObject,'BackgroundColor','white');
  306. end
  307. % --- Aperture height
  308. function edit5_Callback(hObject, eventdata, handles)
  309. % hObject handle to edit5 (see GCBO)
  310. % eventdata reserved - to be defined in a future version of MATLAB
  311. % handles structure with handles and user data (see GUIDATA)
  312. % Hints: get(hObject,'String') returns contents of edit5 as text
  313. % str2double(get(hObject,'String')) returns contents of edit5 as a double
  314. aplist=get(handles.popupmenu1,'String');
  315. aname=aplist{get(handles.popupmenu1,'Value')};
  316. [stat pars]=apertures('GetPars');
  317. if stat{1}~=1
  318. errordlg(stat{2},'GetPars error')
  319. return
  320. end
  321. if get(handles.radiobutton1,'Value')
  322. fn='xpwid';
  323. else
  324. fn='ypwid';
  325. end
  326. newpars.(aname).(fn)=str2double(get(hObject,'String'))*1e-3;
  327. if isnan(newpars.(aname).(fn))
  328. set(hObject,'String',num2str(pars.(aname).(fn)))
  329. return
  330. end
  331. smin=get(handles.slider2,'Min'); smax=get(handles.slider2,'Max');
  332. if newpars.(aname).(fn)<smin || newpars.(aname).(fn)>smax
  333. errordlg([fn,' Value out of slider range'],'Aperture set error')
  334. return
  335. end
  336. set(handles.slider2,'Value',newpars.(aname).(fn))
  337. stat=apertures('SetPars',newpars);
  338. if stat{1}~=1
  339. errordlg(stat{2},'SetPars error')
  340. set(hObject,'String',num2str(pars.(aname).(fn)))
  341. return
  342. end
  343. % --- Executes during object creation, after setting all properties.
  344. function edit5_CreateFcn(hObject, eventdata, handles)
  345. % hObject handle to edit5 (see GCBO)
  346. % eventdata reserved - to be defined in a future version of MATLAB
  347. % handles empty - handles not created until after all CreateFcns called
  348. % Hint: edit controls usually have a white background on Windows.
  349. % See ISPC and COMPUTER.
  350. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  351. set(hObject,'BackgroundColor','white');
  352. end
  353. % --- Executes on button press in pushbutton3.
  354. function pushbutton3_Callback(hObject, eventdata, handles)
  355. % hObject handle to pushbutton3 (see GCBO)
  356. % eventdata reserved - to be defined in a future version of MATLAB
  357. % handles structure with handles and user data (see GUIDATA)
  358. % --- Make new
  359. function pushbutton4_Callback(hObject, eventdata, handles)
  360. % hObject handle to pushbutton4 (see GCBO)
  361. % eventdata reserved - to be defined in a future version of MATLAB
  362. % handles structure with handles and user data (see GUIDATA)
  363. aperturesGui_makeNew;
  364. % Setup aperture list
  365. [stat data]=apertures('GetData'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  366. setApList(handles,data);
  367. function edit7_Callback(hObject, eventdata, handles)
  368. % hObject handle to edit7 (see GCBO)
  369. % eventdata reserved - to be defined in a future version of MATLAB
  370. % handles structure with handles and user data (see GUIDATA)
  371. % Hints: get(hObject,'String') returns contents of edit7 as text
  372. % str2double(get(hObject,'String')) returns contents of edit7 as a double
  373. [stat pars]=apertures('GetPars');
  374. if stat{1}~=1
  375. errordlg(stat{2},'GetPars error')
  376. return
  377. end
  378. newpars.nbpm=str2double(get(hObject,'String'));
  379. if isnan(newpars.nbpm)
  380. set(hObject,'String',num2str(pars.nbpm))
  381. return
  382. end
  383. stat=apertures('SetPars',newpars);
  384. if stat{1}~=1
  385. errordlg(stat{2},'SetPars error')
  386. set(hObject,'String',num2str(pars.nbpm))
  387. return
  388. end
  389. pars.nbpm=newpars.nbpm;
  390. setBpmList(handles,pars)
  391. % --- Executes during object creation, after setting all properties.
  392. function edit7_CreateFcn(hObject, eventdata, handles)
  393. % hObject handle to edit7 (see GCBO)
  394. % eventdata reserved - to be defined in a future version of MATLAB
  395. % handles empty - handles not created until after all CreateFcns called
  396. % Hint: edit controls usually have a white background on Windows.
  397. % See ISPC and COMPUTER.
  398. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  399. set(hObject,'BackgroundColor','white');
  400. end
  401. % --- width slider
  402. function slider1_Callback(hObject, eventdata, handles)
  403. % hObject handle to slider1 (see GCBO)
  404. % eventdata reserved - to be defined in a future version of MATLAB
  405. % handles structure with handles and user data (see GUIDATA)
  406. % Hints: get(hObject,'Value') returns position of slider
  407. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  408. set(handles.edit4,'String',num2str(get(hObject,'Value')*1e3))
  409. edit4_Callback(handles.edit4,[],handles)
  410. % --- Executes during object creation, after setting all properties.
  411. function slider1_CreateFcn(hObject, eventdata, handles)
  412. % hObject handle to slider1 (see GCBO)
  413. % eventdata reserved - to be defined in a future version of MATLAB
  414. % handles empty - handles not created until after all CreateFcns called
  415. % Hint: slider controls usually have a light gray background.
  416. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  417. set(hObject,'BackgroundColor',[.9 .9 .9]);
  418. end
  419. % --- height slider
  420. function slider2_Callback(hObject, eventdata, handles)
  421. % hObject handle to slider2 (see GCBO)
  422. % eventdata reserved - to be defined in a future version of MATLAB
  423. % handles structure with handles and user data (see GUIDATA)
  424. % Hints: get(hObject,'Value') returns position of slider
  425. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  426. set(handles.edit5,'String',num2str(get(hObject,'Value')*1e3))
  427. edit5_Callback(handles.edit5,[],handles)
  428. % --- Executes during object creation, after setting all properties.
  429. function slider2_CreateFcn(hObject, eventdata, handles)
  430. % hObject handle to slider2 (see GCBO)
  431. % eventdata reserved - to be defined in a future version of MATLAB
  432. % handles empty - handles not created until after all CreateFcns called
  433. % Hint: slider controls usually have a light gray background.
  434. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  435. set(hObject,'BackgroundColor',[.9 .9 .9]);
  436. end
  437. % --- Aperture x/y offset slider
  438. function slider3_Callback(hObject, eventdata, handles)
  439. % hObject handle to slider3 (see GCBO)
  440. % eventdata reserved - to be defined in a future version of MATLAB
  441. % handles structure with handles and user data (see GUIDATA)
  442. % Hints: get(hObject,'Value') returns position of slider
  443. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  444. set(handles.edit1,'String',num2str(get(hObject,'Value')*1e3))
  445. edit1_Callback(handles.edit1,[],handles)
  446. % --- Executes during object creation, after setting all properties.
  447. function slider3_CreateFcn(hObject, eventdata, handles)
  448. % hObject handle to slider3 (see GCBO)
  449. % eventdata reserved - to be defined in a future version of MATLAB
  450. % handles empty - handles not created until after all CreateFcns called
  451. % Hint: slider controls usually have a light gray background.
  452. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  453. set(hObject,'BackgroundColor',[.9 .9 .9]);
  454. end
  455. % --- x'/y' offset slider
  456. function slider4_Callback(hObject, eventdata, handles)
  457. % hObject handle to slider4 (see GCBO)
  458. % eventdata reserved - to be defined in a future version of MATLAB
  459. % handles structure with handles and user data (see GUIDATA)
  460. % Hints: get(hObject,'Value') returns position of slider
  461. % get(hObject,'Min') and get(hObject,'Max') to determine range of
  462. % slider
  463. set(handles.edit2,'String',num2str(get(hObject,'Value')*1e3))
  464. edit2_Callback(handles.edit2,[],handles)
  465. % --- Executes during object creation, after setting all properties.
  466. function slider4_CreateFcn(hObject, eventdata, handles)
  467. % hObject handle to slider4 (see GCBO)
  468. % eventdata reserved - to be defined in a future version of MATLAB
  469. % handles empty - handles not created until after all CreateFcns called
  470. % Hint: slider controls usually have a light gray background.
  471. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  472. set(hObject,'BackgroundColor',[.9 .9 .9]);
  473. end
  474. % --- rotation slider
  475. function slider5_Callback(hObject, eventdata, handles)
  476. % hObject handle to slider5 (see GCBO)
  477. % eventdata reserved - to be defined in a future version of MATLAB
  478. % handles structure with handles and user data (see GUIDATA)
  479. % Hints: get(hObject,'Value') returns position of slider
  480. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  481. set(handles.edit3,'String',num2str(get(hObject,'Value')))
  482. edit3_Callback(handles.edit3,[],handles)
  483. % --- Executes during object creation, after setting all properties.
  484. function slider5_CreateFcn(hObject, eventdata, handles)
  485. % hObject handle to slider5 (see GCBO)
  486. % eventdata reserved - to be defined in a future version of MATLAB
  487. % handles empty - handles not created until after all CreateFcns called
  488. % Hint: slider controls usually have a light gray background.
  489. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  490. set(hObject,'BackgroundColor',[.9 .9 .9]);
  491. end
  492. % --- alarm update rate
  493. function edit6_Callback(hObject, eventdata, handles)
  494. % hObject handle to edit6 (see GCBO)
  495. % eventdata reserved - to be defined in a future version of MATLAB
  496. % handles structure with handles and user data (see GUIDATA)
  497. % Hints: get(hObject,'String') returns contents of edit6 as text
  498. % str2double(get(hObject,'String')) returns contents of edit6 as a double
  499. [stat pars]=apertures('GetPars');
  500. if stat{1}~=1
  501. errordlg(stat{2},'GetPars error')
  502. return
  503. end
  504. newpars.updateRate=str2double(get(hObject,'String'));
  505. if isnan(newpars.updateRate)
  506. set(hObject,'String',num2str(pars.updateRate))
  507. return
  508. end
  509. stat=apertures('SetPars',newpars);
  510. if stat{1}~=1
  511. errordlg(stat{2},'SetPars error')
  512. set(hObject,'String',num2str(pars.updateRate))
  513. return
  514. end
  515. % --- Executes during object creation, after setting all properties.
  516. function edit6_CreateFcn(hObject, eventdata, handles)
  517. % hObject handle to edit6 (see GCBO)
  518. % eventdata reserved - to be defined in a future version of MATLAB
  519. % handles empty - handles not created until after all CreateFcns called
  520. % Hint: edit controls usually have a white background on Windows.
  521. % See ISPC and COMPUTER.
  522. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  523. set(hObject,'BackgroundColor','white');
  524. end
  525. % --- Executes on selection change in listbox1.
  526. function listbox1_Callback(hObject, eventdata, handles)
  527. % hObject handle to listbox1 (see GCBO)
  528. % eventdata reserved - to be defined in a future version of MATLAB
  529. % handles structure with handles and user data (see GUIDATA)
  530. % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
  531. % contents{get(hObject,'Value')} returns selected item from listbox1
  532. % --- Executes during object creation, after setting all properties.
  533. function listbox1_CreateFcn(hObject, eventdata, handles)
  534. % hObject handle to listbox1 (see GCBO)
  535. % eventdata reserved - to be defined in a future version of MATLAB
  536. % handles empty - handles not created until after all CreateFcns called
  537. % Hint: listbox controls usually have a white background on Windows.
  538. % See ISPC and COMPUTER.
  539. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  540. set(hObject,'BackgroundColor','white');
  541. end
  542. % --- Get reference orbit from saved set point file
  543. function pushbutton5_Callback(hObject, eventdata, handles)
  544. % hObject handle to pushbutton5 (see GCBO)
  545. % eventdata reserved - to be defined in a future version of MATLAB
  546. % handles structure with handles and user data (see GUIDATA)
  547. [filename pathname]=uigetfile('*.mat','Select FS Save File','latticeFiles/archive');
  548. if ~isequal(filename,0) && ~isequal(pathname,0)
  549. ld=load(fullfile(pathname,filename),'INSTR');
  550. if ~isfield(ld,'INSTR') || isempty(ld.INSTR) || ~isfield(ld.INSTR{1},'ref') || ~isfield(ld.INSTR{1},'referr')
  551. errordlg('No INSTR reference orbit data found in this file!','Ref Load Error')
  552. return
  553. end
  554. for i_ind=1:2
  555. newpars.reforbit(:,i_ind)=arrayfun(@(x) ld.INSTR{x}.ref(i_ind),1:length(ld.INSTR))';
  556. newpars.reforbit(:,i_ind+3)=arrayfun(@(x) ld.INSTR{x}.referr(i_ind),1:length(ld.INSTR))';
  557. end
  558. set(handles.text9,'String',filename)
  559. end
  560. % --- Alarm active
  561. function checkbox1_Callback(hObject, eventdata, handles)
  562. % hObject handle to checkbox1 (see GCBO)
  563. % eventdata reserved - to be defined in a future version of MATLAB
  564. % handles structure with handles and user data (see GUIDATA)
  565. % Hint: get(hObject,'Value') returns toggle state of checkbox1
  566. aplist=get(handles.popupmenu1,'String');
  567. aname=aplist{get(handles.popupmenu1,'Value')};
  568. newpars.(aname).active=get(hObject,'Value');
  569. stat=apertures('SetPars',newpars);
  570. if stat{1}~=1
  571. errordlg(stat{2},'SetPars Error')
  572. end
  573. % --- Alarm status
  574. function pushbutton6_Callback(hObject, eventdata, handles)
  575. % hObject handle to pushbutton6 (see GCBO)
  576. % eventdata reserved - to be defined in a future version of MATLAB
  577. % handles structure with handles and user data (see GUIDATA)
  578. % Get alarm status
  579. [stat alarm]=apertures('IsAlarm'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  580. setAlarm(handles,alarm);
  581. % Go to first alarmed aperture if alarm and list alarmed aperture
  582. if alarm
  583. [stat data]=apertures('GetData'); if stat{1}~=1; errordlg(stat{2},'apertures error'); end;
  584. setApList(handles,data);
  585. end
  586. % --- # bpm ave
  587. function edit8_Callback(hObject, eventdata, handles)
  588. % hObject handle to edit8 (see GCBO)
  589. % eventdata reserved - to be defined in a future version of MATLAB
  590. % handles structure with handles and user data (see GUIDATA)
  591. % Hints: get(hObject,'String') returns contents of edit8 as text
  592. % str2double(get(hObject,'String')) returns contents of edit8 as a double
  593. [stat pars]=apertures('GetPars');
  594. if stat{1}~=1
  595. errordlg(stat{2},'GetPars error')
  596. return
  597. end
  598. newpars.bpmave=str2double(get(hObject,'String'));
  599. if isnan(newpars.bpmave)
  600. set(hObject,'String',num2str(pars.bpmave))
  601. return
  602. end
  603. stat=apertures('SetPars',newpars);
  604. if stat{1}~=1
  605. errordlg(stat{2},'SetPars error')
  606. set(hObject,'String',num2str(pars.bpmave))
  607. return
  608. end
  609. % --- Executes during object creation, after setting all properties.
  610. function edit8_CreateFcn(hObject, eventdata, handles)
  611. % hObject handle to edit8 (see GCBO)
  612. % eventdata reserved - to be defined in a future version of MATLAB
  613. % handles empty - handles not created until after all CreateFcns called
  614. % Hint: edit controls usually have a white background on Windows.
  615. % See ISPC and COMPUTER.
  616. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  617. set(hObject,'BackgroundColor','white');
  618. end
  619. % --- Set Max rms cut
  620. function edit9_Callback(hObject, eventdata, handles)
  621. % hObject handle to edit9 (see GCBO)
  622. % eventdata reserved - to be defined in a future version of MATLAB
  623. % handles structure with handles and user data (see GUIDATA)
  624. [stat pars]=apertures('GetPars');
  625. if stat{1}~=1
  626. errordlg(stat{2},'GetPars error')
  627. return
  628. end
  629. newpars.maxrms=str2double(get(hObject,'String'));
  630. if isnan(newpars.maxrms)
  631. set(hObject,'String',num2str(pars.maxrms))
  632. return
  633. end
  634. stat=apertures('SetPars',newpars);
  635. if stat{1}~=1
  636. errordlg(stat{2},'SetPars error')
  637. set(hObject,'String',num2str(pars.minq))
  638. return
  639. end
  640. % --- Executes during object creation, after setting all properties.
  641. function edit9_CreateFcn(hObject, eventdata, handles)
  642. % hObject handle to edit9 (see GCBO)
  643. % eventdata reserved - to be defined in a future version of MATLAB
  644. % handles empty - handles not created until after all CreateFcns called
  645. % Hint: edit controls usually have a white background on Windows.
  646. % See ISPC and COMPUTER.
  647. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  648. set(hObject,'BackgroundColor','white');
  649. end
  650. % --- Min Q
  651. function edit10_Callback(hObject, eventdata, handles)
  652. % hObject handle to edit10 (see GCBO)
  653. % eventdata reserved - to be defined in a future version of MATLAB
  654. % handles structure with handles and user data (see GUIDATA)
  655. % Hints: get(hObject,'String') returns contents of edit10 as text
  656. % str2double(get(hObject,'String')) returns contents of edit10 as a double
  657. [stat pars]=apertures('GetPars');
  658. if stat{1}~=1
  659. errordlg(stat{2},'GetPars error')
  660. return
  661. end
  662. newpars.minq=str2double(get(hObject,'String'));
  663. if isnan(newpars.minq)
  664. set(hObject,'String',num2str(pars.minq))
  665. return
  666. end
  667. stat=apertures('SetPars',newpars);
  668. if stat{1}~=1
  669. errordlg(stat{2},'SetPars error')
  670. set(hObject,'String',num2str(pars.minq))
  671. return
  672. end
  673. % --- Executes during object creation, after setting all properties.
  674. function edit10_CreateFcn(hObject, eventdata, handles)
  675. % hObject handle to edit10 (see GCBO)
  676. % eventdata reserved - to be defined in a future version of MATLAB
  677. % handles empty - handles not created until after all CreateFcns called
  678. % Hint: edit controls usually have a white background on Windows.
  679. % See ISPC and COMPUTER.
  680. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  681. set(hObject,'BackgroundColor','white');
  682. end
  683. % --- Executes when user attempts to close figure1.
  684. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  685. % hObject handle to figure1 (see GCBO)
  686. % eventdata reserved - to be defined in a future version of MATLAB
  687. % handles structure with handles and user data (see GUIDATA)
  688. apertures('save');
  689. newpars.guiActive=false;
  690. apertures('SetPars',newpars);
  691. guiCloseFn('aperturesGui',handles);
  692. % --- Executes on button press in radiobutton5.
  693. function radiobutton5_Callback(hObject, eventdata, handles)
  694. % hObject handle to radiobutton5 (see GCBO)
  695. % eventdata reserved - to be defined in a future version of MATLAB
  696. % handles structure with handles and user data (see GUIDATA)
  697. % Hint: get(hObject,'Value') returns toggle state of radiobutton5
  698. % --- fwd propagate
  699. function radiobutton6_Callback(hObject, eventdata, handles)
  700. % hObject handle to radiobutton6 (see GCBO)
  701. % eventdata reserved - to be defined in a future version of MATLAB
  702. % handles structure with handles and user data (see GUIDATA)
  703. [stat, pars]=apertures('GetPars');
  704. if stat{1}~=1
  705. warning('Lucretia:aperturesGui:apPlot',stat{2});
  706. return
  707. end
  708. setBpmList(handles,pars);
  709. pushbutton9_Callback(handles.pushbutton9, eventdata, handles)
  710. % --- Use default reference orbit
  711. function pushbutton7_Callback(hObject, eventdata, handles)
  712. % hObject handle to pushbutton7 (see GCBO)
  713. % eventdata reserved - to be defined in a future version of MATLAB
  714. % handles structure with handles and user data (see GUIDATA)
  715. % --- Check want to do this
  716. resp=questdlg('Set New Reference Orbit for this Aperture?','Default Ref Orbit');
  717. if ~strcmp(resp,'Yes'); return; end;
  718. aplist=get(handles.popupmenu1,'String');
  719. aname=aplist{get(handles.popupmenu1,'Value')};
  720. newpars.(aname).reforbit='default';
  721. stat=apertures('SetPars',newpars);
  722. if stat{1}~=1
  723. errordlg(stat{2},'Set Pars Error')
  724. return
  725. end
  726. set(handles.text9,'String','Use Default')
  727. % --- Remove BPM(s)
  728. function pushbutton8_Callback(hObject, eventdata, handles)
  729. % hObject handle to pushbutton8 (see GCBO)
  730. % eventdata reserved - to be defined in a future version of MATLAB
  731. % handles structure with handles and user data (see GUIDATA)
  732. [stat, pars]=apertures('GetPars');
  733. if stat{1}~=1
  734. warning('Lucretia:aperturesGui:apPlot',stat{2});
  735. return
  736. end
  737. bpms=get(handles.listbox1,'Value');
  738. bpmList=get(handles.listbox1,'String');
  739. bpmList={bpmList{~ismember(1:length(bpmList),bpms)}};
  740. set(handles.listbox1,'String',bpmList)
  741. setBpmList(handles,pars);
  742. % --- Update gui
  743. function pushbutton9_Callback(hObject, eventdata, handles)
  744. % hObject handle to pushbutton9 (see GCBO)
  745. % eventdata reserved - to be defined in a future version of MATLAB
  746. % handles structure with handles and user data (see GUIDATA)
  747. Update(hObject, eventdata, handles)
  748. function Update(hObject, eventdata, handles)
  749. stat=apertures('update');
  750. if stat{1}~=1
  751. errordlg(stat{2},'update error')
  752. return
  753. end
  754. apPlot(handles);
  755. % --- Reset BPM list
  756. function pushbutton10_Callback(hObject, eventdata, handles)
  757. % hObject handle to pushbutton10 (see GCBO)
  758. % eventdata reserved - to be defined in a future version of MATLAB
  759. % handles structure with handles and user data (see GUIDATA)
  760. [stat, pars]=apertures('GetPars');
  761. if stat{1}~=1
  762. warning('Lucretia:aperturesGui:apPlot',stat{2});
  763. return
  764. end
  765. set(handles.listbox1,'String',{'none'})
  766. setBpmList(handles,pars);
  767. % --- Aperture shape - ellipse
  768. function radiobutton3_Callback(hObject, eventdata, handles)
  769. % hObject handle to radiobutton3 (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. if get(hObject,'Value')
  773. set(handles.radiobutton4,'Value',0)
  774. alist=get(handles.popupmenu1,'String'); apName=alist{get(handles.popupmenu1,'Value')};
  775. newpars.(apName).shape=get(hObject,'String');
  776. stat = apertures('SetPars',newpars);
  777. if stat{1}~=1
  778. errordlg(stat{2},'SetPars Error')
  779. return
  780. end
  781. [stat pars]=apertures('GetPars');
  782. if stat{1}~=1
  783. errordlg(stat{2},'GetPars Error')
  784. return
  785. end
  786. setPars(handles,pars);
  787. end
  788. % --- Aperture shape - rectangle
  789. function radiobutton4_Callback(hObject, eventdata, handles)
  790. % hObject handle to radiobutton4 (see GCBO)
  791. % eventdata reserved - to be defined in a future version of MATLAB
  792. % handles structure with handles and user data (see GUIDATA)
  793. if get(hObject,'Value')
  794. set(handles.radiobutton3,'Value',0)
  795. alist=get(handles.popupmenu1,'String'); apName=alist{get(handles.popupmenu1,'Value')};
  796. newpars.(apName).shape=get(hObject,'String');
  797. stat = apertures('SetPars',newpars);
  798. if stat{1}~=1
  799. errordlg(stat{2},'SetPars Error')
  800. return
  801. end
  802. [stat pars]=apertures('GetPars');
  803. if stat{1}~=1
  804. errordlg(stat{2},'GetPars Error')
  805. return
  806. end
  807. setPars(handles,pars);
  808. end
  809. % --- select plane
  810. function radiobutton1_Callback(hObject, eventdata, handles)
  811. % hObject handle to radiobutton1 (see GCBO)
  812. % eventdata reserved - to be defined in a future version of MATLAB
  813. % handles structure with handles and user data (see GUIDATA)
  814. [stat pars]=apertures('GetPars');
  815. if stat{1}~=1
  816. errordlg(stat{2},'GetPars Error')
  817. return
  818. elseif isequal(stat{1},'Citation X')
  819. errordlg(stat{2},'Good choice but sadly not available')
  820. return
  821. end
  822. setPars(handles,pars);
  823. % --- select plane
  824. function radiobutton2_Callback(hObject, eventdata, handles)
  825. % hObject handle to radiobutton2 (see GCBO)
  826. % eventdata reserved - to be defined in a future version of MATLAB
  827. % handles structure with handles and user data (see GUIDATA)
  828. [stat pars]=apertures('GetPars');
  829. if stat{1}~=1
  830. errordlg(stat{2},'GetPars Error')
  831. return
  832. elseif isequal(stat{1},'Citation X')
  833. errordlg(stat{2},'Good choice but sadly not available')
  834. return
  835. end
  836. setPars(handles,pars);
  837. % --- use ICTDUMP
  838. function radiobutton7_Callback(hObject, eventdata, handles)
  839. % hObject handle to radiobutton7 (see GCBO)
  840. % eventdata reserved - to be defined in a future version of MATLAB
  841. % handles structure with handles and user data (see GUIDATA)
  842. if get(hObject,'Value')
  843. set(handles.radiobutton8,'Value',0)
  844. newpars.whichICT=get(hObject,'String');
  845. stat = apertures('SetPars',newpars);
  846. if stat{1}~=1
  847. errordlg(stat{2},'SetPars Error')
  848. return
  849. end
  850. end
  851. % --- use ICT1X
  852. function radiobutton8_Callback(hObject, eventdata, handles)
  853. % hObject handle to radiobutton8 (see GCBO)
  854. % eventdata reserved - to be defined in a future version of MATLAB
  855. % handles structure with handles and user data (see GUIDATA)
  856. if get(hObject,'Value')
  857. set(handles.radiobutton7,'Value',0)
  858. newpars.whichICT=get(hObject,'String');
  859. stat = apertures('SetPars',newpars);
  860. if stat{1}~=1
  861. errordlg(stat{2},'SetPars Error')
  862. return
  863. end
  864. end
  865. % --- Alarm handling
  866. function setAlarm(handles,alarm)
  867. if alarm==1
  868. set(handles.pushbutton6,'BackgroundColor','yellow')
  869. set(handles.pushbutton6,'String','Minor Alarm')
  870. elseif alarm==2
  871. set(handles.pushbutton6,'BackgroundColor','red')
  872. set(handles.pushbutton6,'String','Major Alarm')
  873. else
  874. set(handles.pushbutton6,'BackgroundColor','green')
  875. set(handles.pushbutton6,'String','OK')
  876. end
  877. drawnow('expose')
  878. % --- Setup Aperture list in pulldown menu
  879. function setApList(handles,data)
  880. persistent lastaplist
  881. df=fieldnames(data);
  882. apnames={}; isalarm=[];
  883. for idf=1:length(df)
  884. if ~strcmp(df{idf},'alarm')
  885. apnames{end+1}=df{idf};
  886. isalarm(end+1)=data.(df{idf}).alarm;
  887. end
  888. end
  889. set(handles.popupmenu1,'String',apnames);
  890. if data.alarm
  891. set(handles.popupmenu1,'Value',find(isalarm,1))
  892. elseif ~isempty(lastaplist) && ~isequal(lastaplist,apnames)
  893. % select new entry
  894. inew=find(~ismember(apnames,lastaplist));
  895. if ~isempty(inew)
  896. set(handles.popupmenu1,'Value',inew(1))
  897. else
  898. set(handles.popupmenu1,'Value',1)
  899. end
  900. else
  901. set(handles.popupmenu1,'Value',1)
  902. end
  903. lastaplist=apnames;
  904. % --- Setup BPM selection list
  905. function setBpmList(handles,pars)
  906. global BEAMLINE
  907. persistent allbi
  908. % Get indicies of current BPM list
  909. guiList=get(handles.listbox1,'String');
  910. if ~iscell(guiList); guiList={guiList}; end;
  911. guiListInd=[];
  912. for iList=1:length(guiList)
  913. ib=findcells(BEAMLINE,'Name',guiList{iList});
  914. if ~isempty(ib)
  915. guiListInd(end+1)=ib(1);
  916. end
  917. end
  918. aplist=get(handles.popupmenu1,'String');
  919. aname=aplist{get(handles.popupmenu1,'Value')};
  920. % bi=pars.(aname).bpmind;
  921. bi=[];
  922. ti=pars.(aname).targetInd;
  923. % remove any upstream bpms if fwd prop button false
  924. if ~get(handles.radiobutton6,'Value') && any(find(bi<ti))
  925. bi(bi<ti)=[];
  926. end
  927. % try and make it so selected number of bpms existing
  928. if isempty(allbi); allbi=findcells(BEAMLINE,'Class','MONI'); end;
  929. % downstream bpms
  930. [stat bcheck]=apertures('bpmCheck',bi);
  931. bi=bcheck(1,:);
  932. numbpm=sum(bi>ti);
  933. nbpmsearch=pars.nbpm;
  934. % Trim excess
  935. if numbpm>pars.nbpm
  936. ntrim=numbpm-pars.nbpm;
  937. bi(find(bi>ti,ntrim,'last'))=[];
  938. end
  939. bi1=bi(bi<ti);
  940. while numbpm<pars.nbpm && sum(allbi>ti)>=nbpmsearch
  941. bi=[allbi(find(allbi>ti,nbpmsearch,'first')) bi1];
  942. [stat bcheck]=apertures('bpmCheck',bi);
  943. bi=bcheck(1,:);
  944. nbpmsearch=nbpmsearch+1;
  945. numbpm=sum(bi>ti);
  946. end
  947. if numbpm<pars.nbpm
  948. errordlg('Insufficient (downstream) BPMs for requested number, only those shown available','BPM allocation error')
  949. end
  950. if get(handles.radiobutton6,'Value') % upstream bpms
  951. numbpm=sum(bi<ti);
  952. nbpmsearch=pars.nbpm;
  953. % Trim excess
  954. if numbpm>pars.nbpm
  955. ntrim=numbpm-pars.nbpm;
  956. bi(find(bi<ti,ntrim,'first'))=[];
  957. end
  958. bi1=bi(bi>ti);
  959. while numbpm<pars.nbpm && sum(allbi<ti)>=nbpmsearch
  960. bi=[bi1 allbi(find(allbi<ti,nbpmsearch,'last'))];
  961. [stat bcheck]=apertures('bpmCheck',bi);
  962. bi=bcheck(1,:);
  963. nbpmsearch=nbpmsearch+1;
  964. numbpm=sum(bi<ti);
  965. end
  966. if numbpm<pars.nbpm
  967. errordlg('Insufficient (upstream) BPMs for requested number, only those shown available','BPM allocation error')
  968. end
  969. end
  970. % fill listbox with bpm names and set apertures pars
  971. set(handles.listbox1,'String',arrayfun(@(x) BEAMLINE{x}.Name,bi,'UniformOutput',false))
  972. if isempty(get(handles.listbox1,'String'))
  973. set(handles.listbox1,'String',{'none'})
  974. else
  975. newpars.(aname).bpmind=bi;
  976. stat=apertures('SetPars',newpars);
  977. if stat{1}~=1
  978. errordlg(stat{2},'SetPars Error')
  979. set(handles.listbox1,'String',guiList)
  980. end
  981. end
  982. set(handles.listbox1,'Value',1)
  983. % --- Aperture Plotting
  984. function apPlot(handles)
  985. global FL BEAMLINE
  986. [stat data]=apertures('GetData');data.alarm;
  987. setAlarm(handles,data.alarm);
  988. drawnow('expose')
  989. % Get data for plotting
  990. if ~exist('handles','var')
  991. handles=FL.Gui.aperturesGui;
  992. end
  993. [stat, data]=evalin('base','apertures(''GetData'')');
  994. if stat{1}~=1
  995. warning('Lucretia:aperturesGui:apPlot',stat{2});
  996. return
  997. end
  998. [stat, pars]=apertures('GetPars');
  999. if stat{1}~=1
  1000. warning('Lucretia:aperturesGui:apPlot',stat{2});
  1001. return
  1002. end
  1003. % Get ap name
  1004. aplist=get(handles.popupmenu1,'String');
  1005. aname=aplist{get(handles.popupmenu1,'Value')};
  1006. % Are using upstream data and fwd prop?
  1007. isusdata=get(handles.radiobutton6,'Value');
  1008. % get ds derived data and plot
  1009. xax=handles.axes1; yax=handles.axes2;
  1010. if ~isfield(data.(aname),'pos')
  1011. return
  1012. end
  1013. pos=data.(aname).pos.*1e3;
  1014. err=data.(aname).error.*1e3;
  1015. ap_x=pars.(aname).aper_x.*1e3; ap_xp=pars.(aname).aper_xp.*1e3;
  1016. ap_y=pars.(aname).aper_y.*1e3; ap_yp=pars.(aname).aper_yp.*1e3;
  1017. hold off
  1018. plot(xax,pos(1),pos(2),'ko')
  1019. hold on
  1020. patch(ap_x,ap_xp,'green','EdgeColor','green','Parent',xax)
  1021. line([pos(1)-err(1) pos(1)+err(1)],[pos(2) pos(2)],'color','black','Parent',xax)
  1022. line([pos(1) pos(1)],[pos(2)-err(2) pos(2)+err(2)],'color','black','Parent',xax)
  1023. xlabel(xax,'x / mm','FontSize',12); ylabel(xax,'x'' / mrad','FontSize',12);
  1024. hold off
  1025. plot(yax,pos(3),pos(4),'ko')
  1026. patch(ap_y,ap_yp,'green','EdgeColor','green','Parent',yax)
  1027. hold on
  1028. line([pos(3)-err(3) pos(3)+err(3)],[pos(4) pos(4)],'color','black','Parent',yax)
  1029. line([pos(3) pos(3)],[pos(4)-err(4) pos(4)+err(4)],'color','black','Parent',yax)
  1030. xlabel(yax,'y / mm','FontSize',12); ylabel(yax,'y'' / mrad','FontSize',12);
  1031. hold off
  1032. % Set Aperture title text
  1033. txt=sprintf('x = %.2g +/- %.2g mm x'' = %.2g +/- %.2g mrad\n y = %.2g +/- %.2g mm y'' = %.2g +/- %.2g mrad',pos(1),err(1),pos(2),err(2),pos(3),err(3),pos(4),err(4));
  1034. set(handles.text8,'String',txt);
  1035. if data.(aname).alarm
  1036. set(handles.text8,'ForegroundColor','red')
  1037. else
  1038. set(handles.text8,'ForegroundColor','black')
  1039. end
  1040. % get us derived data and plot
  1041. if isusdata
  1042. pos=data.(aname).pos_us.*1e3;
  1043. err=data.(aname).error_us.*1e3;
  1044. hold(xax,'on')
  1045. plot(xax,pos(1),pos(2),'ko')
  1046. line([pos(1)-err(1) pos(1)+err(1)],[pos(2) pos(2)],'color','blue','Parent',xax)
  1047. line([pos(1) pos(1)],[pos(2)-err(2) pos(2)+err(2)],'color','blue','Parent',xax)
  1048. hold(xax,'off')
  1049. hold(yax,'on')
  1050. plot(yax,pos(3),pos(4),'ko')
  1051. line([pos(3)-err(3) pos(3)+err(3)],[pos(4) pos(4)],'color','blue','Parent',yax)
  1052. line([pos(3) pos(3)],[pos(4)-err(4) pos(4)+err(4)],'color','blue','Parent',yax)
  1053. hold(yax,'off')
  1054. end
  1055. % Plot bpm orbits
  1056. S=arrayfun(@(x) BEAMLINE{x}.S,pars.(aname).bpmind);
  1057. S_target=BEAMLINE{pars.(aname).targetInd}.S;
  1058. subplot(2,1,1,'Parent',handles.uipanel13), errorbar(S(end-length(data.(aname).bpm(:,1))+1:end),data.(aname).bpm(:,1).*1e3,data.(aname).bpm_error(:,1).*1e3,'k')
  1059. hold on
  1060. subplot(2,1,1,'Parent',handles.uipanel13), errorbar(S_target,data.(aname).pos(1).*1e3,data.(aname).error(1).*1e3,'kx','MarkerSize',20,'LineWidth',2)
  1061. if isusdata
  1062. subplot(2,1,1,'Parent',handles.uipanel13), errorbar(S(1:length(data.(aname).bpm_us(:,1))),data.(aname).bpm_us(:,1).*1e3,data.(aname).bpm_error_us(:,1).*1e3,'b')
  1063. subplot(2,1,1,'Parent',handles.uipanel13), errorbar(S_target,data.(aname).pos_us(1).*1e3,data.(aname).error_us(1).*1e3,'bx','MarkerSize',20,'LineWidth',2)
  1064. end
  1065. hold off
  1066. xlabel('S / m','FontSize',12)
  1067. ylabel('\Deltax / mm','FontSize',12)
  1068. subplot(2,1,2,'Parent',handles.uipanel13), errorbar(S(end-length(data.(aname).bpm(:,1))+1:end),data.(aname).bpm(:,2).*1e3,data.(aname).bpm_error(:,2).*1e3,'k')
  1069. hold on
  1070. subplot(2,1,2,'Parent',handles.uipanel13), errorbar(S_target,data.(aname).pos(3).*1e3,data.(aname).error(3).*1e3,'kx','MarkerSize',20,'LineWidth',2)
  1071. if isusdata
  1072. subplot(2,1,2,'Parent',handles.uipanel13), errorbar(S(1:length(data.(aname).bpm_us(:,1))),data.(aname).bpm_us(:,2).*1e3,data.(aname).bpm_error_us(:,2).*1e3,'b')
  1073. subplot(2,1,2,'Parent',handles.uipanel13), errorbar(S_target,data.(aname).pos_us(3).*1e3,data.(aname).error_us(3).*1e3,'bx','MarkerSize',20,'LineWidth',2)
  1074. end
  1075. hold off
  1076. xlabel('S / m','FontSize',12)
  1077. ylabel('\Deltay / mm','FontSize',12)
  1078. drawnow('expose')
  1079. % --- Set parameters into GUI fields
  1080. function setPars(handles,pars)
  1081. % Set Title
  1082. alist=get(handles.popupmenu1,'String'); apName=alist{get(handles.popupmenu1,'Value')};
  1083. set(handles.text1,'String',sprintf('Aperture Watchdog - %s',apName))
  1084. % ICT choice
  1085. if strcmp(pars.whichICT,'ICTDUMP')
  1086. set(handles.radiobutton8,'Value',0)
  1087. set(handles.radiobutton7,'Value',1)
  1088. elseif strcmp(pars.whichICT,'ICT1X')
  1089. set(handles.radiobutton7,'Value',0)
  1090. set(handles.radiobutton8,'Value',1)
  1091. end
  1092. set(handles.edit9,'String',num2str(pars.maxrms))
  1093. set(handles.edit10,'String',num2str(pars.minq))
  1094. set(handles.edit6,'String',num2str(pars.updateRate))
  1095. set(handles.edit7,'String',num2str(pars.nbpm))
  1096. set(handles.edit8,'String',num2str(pars.bpmave))
  1097. if get(handles.radiobutton1,'Value'); p='x'; else p='y'; end;
  1098. set(handles.edit1,'String',num2str(pars.(apName).([p,'off'])*1e3))
  1099. set(handles.slider3,'Value',pars.(apName).([p,'off']))
  1100. set(handles.edit2,'String',num2str(pars.(apName).([p,'poff'])*1e3))
  1101. set(handles.slider4,'Value',pars.(apName).([p,'poff']))
  1102. set(handles.edit3,'String',num2str(pars.(apName).([p,'rot'])))
  1103. set(handles.slider5,'Value',pars.(apName).([p,'rot']))
  1104. set(handles.edit4,'String',num2str(pars.(apName).([p,'wid'])*1e3))
  1105. set(handles.slider1,'Value',pars.(apName).([p,'wid']))
  1106. set(handles.edit5,'String',num2str(pars.(apName).([p,'pwid'])*1e3))
  1107. set(handles.slider2,'Value',pars.(apName).([p,'pwid']))
  1108. if strcmp(pars.(apName).shape,'ellipse')
  1109. set(handles.radiobutton4,'Value',0)
  1110. set(handles.radiobutton3,'Value',1)
  1111. elseif strcmp(pars.(apName).shape,'rectangle')
  1112. set(handles.radiobutton3,'Value',0)
  1113. set(handles.radiobutton4,'Value',1)
  1114. else
  1115. errordlg('Unknown aperture shape','apertures error')
  1116. end
  1117. set(handles.checkbox1,'Value',pars.(apName).active)
  1118. setBpmList(handles,pars);
  1119. % ref orbit
  1120. if strcmp(pars.(apName).reforbit,'default')
  1121. set(handles.text9,'String','Use Default')
  1122. else
  1123. set(handles.text9,'String','User Defined')
  1124. end
  1125. % --- Set new reference orbit
  1126. function pushbutton11_Callback(hObject, eventdata, handles)
  1127. % hObject handle to pushbutton11 (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. % --- Check want to do this
  1131. resp=questdlg('Set New Reference Orbit for this Aperture?','New Ref Orbit');
  1132. if ~strcmp(resp,'Yes'); return; end;
  1133. [stat pars]=apertures('GetPars');
  1134. if stat{1}~=1
  1135. errordlg(stat{2},'GetPars Error')
  1136. return
  1137. end
  1138. % --- Get reference orbit
  1139. % Check there is enough bpm data
  1140. [stat bsize]=FlHwUpdate('buffersize');
  1141. if stat{1}~=1 || bsize<pars.bpmave
  1142. errordlg('Not enough buffered bpm data or not available','bpm ave error')
  1143. return
  1144. end
  1145. % Get aperture selected
  1146. alist=get(handles.popupmenu1,'String'); apName=alist{get(handles.popupmenu1,'Value')};
  1147. % Get averaged bpm readings and set reference orbit
  1148. % Check there is enough bpm data
  1149. [stat bsize]=FlHwUpdate('buffersize');
  1150. if stat{1}~=1 || bsize<pars.bpmave
  1151. errordlg('Not enough buffered bpm data or not available','bpmave error')
  1152. return
  1153. end
  1154. [stat bpmdata]=FlHwUpdate('bpmave',pars.bpmave,[pars.minq,pars.maxrms,isequal(pars.whichICT,'ICT1X'),0]); if stat{1}~=1; return; end;
  1155. for i_ind=1:6
  1156. newpars.(apName).reforbit(:,i_ind)=bpmdata{1}(:,i_ind);
  1157. end
  1158. stat=apertures('SetPars',newpars);
  1159. if stat{1}~=1
  1160. errordlg(stat{2},'Set Pars Error')
  1161. return
  1162. end
  1163. set(handles.text9,'String',datestr(now))
  1164. % --- Executes on button press in checkbox2.
  1165. function checkbox2_Callback(hObject, eventdata, handles)
  1166. % hObject handle to checkbox2 (see GCBO)
  1167. % eventdata reserved - to be defined in a future version of MATLAB
  1168. % handles structure with handles and user data (see GUIDATA)
  1169. % Hint: get(hObject,'Value') returns toggle state of checkbox2