PageRenderTime 38ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/ATF2/FlightSim/coreApps/FlBeamModelGUI.m

http://atf2flightsim.googlecode.com/
MATLAB | 713 lines | 360 code | 129 blank | 224 comment | 57 complexity | 6abbe4a8d170c14fe32ddbd52eae348e MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = FlBeamModelGUI(varargin)
  2. % FLBEAMMODELGUI MATLAB code for FlBeamModelGUI.fig
  3. % FLBEAMMODELGUI, by itself, creates a new FLBEAMMODELGUI or raises the existing
  4. % singleton*.
  5. %
  6. % H = FLBEAMMODELGUI returns the handle to a new FLBEAMMODELGUI or the handle to
  7. % the existing singleton*.
  8. %
  9. % FLBEAMMODELGUI('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in FLBEAMMODELGUI.M with the given input arguments.
  11. %
  12. % FLBEAMMODELGUI('Property','Value',...) creates a new FLBEAMMODELGUI or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before FlBeamModelGUI_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to FlBeamModelGUI_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 FlBeamModelGUI
  23. % Last Modified by GUIDE v2.5 04-Apr-2011 11:16:32
  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', @FlBeamModelGUI_OpeningFcn, ...
  29. 'gui_OutputFcn', @FlBeamModelGUI_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 FlBeamModelGUI is made visible.
  42. function FlBeamModelGUI_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 FlBeamModelGUI (see VARARGIN)
  48. % Choose default command line output for FlBeamModelGUI
  49. handles.output = handles;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % Reset FlBeamModel
  53. FlBeamModel('clear');
  54. % Fill data fields from FlBeamModel routine
  55. [~, data]=FlBeamModel('GetData');
  56. [~, l]=FlBeamModel('GetLocal');
  57. set(handles.edit1,'String',num2str(data.nbpmave));
  58. set(handles.edit2,'String',num2str(data.lookbackTime));
  59. if any(l.drBpms)
  60. set(handles.togglebutton8,'Value',any(data.useBpms & l.drBpms))
  61. end
  62. set(handles.togglebutton9,'Value',any(data.useBpms & l.extBpms))
  63. set(handles.togglebutton10,'Value',any(data.useBpms & l.ffsBpms))
  64. set(handles.radiobutton4,'Value',0)
  65. set(handles.radiobutton5,'Value',0)
  66. set(handles.radiobutton6,'Value',0)
  67. if data.useEmitData==0
  68. set(handles.radiobutton4,'Value',1)
  69. elseif data.useEmitData==1
  70. set(handles.radiobutton5,'Value',1)
  71. else
  72. set(handles.radiobutton6,'Value',1)
  73. end
  74. set(handles.edit5,'String',num2str(l.optimParam.MaxIter))
  75. % Update bpm and magnet lists
  76. bpmsel('get',handles);
  77. magsel('get',handles);
  78. % GUI timer (keep data age up to date)
  79. t=timer('TimerFcn',@(x,y) guiTimer({handles,'edit2'}),'StartDelay',1,'ExecutionMode','fixedSpacing','BusyMode','drop','Period',1);
  80. set(handles.figure1,'UserData',t);
  81. start(t);
  82. % --- Outputs from this function are returned to the command line.
  83. function varargout = FlBeamModelGUI_OutputFcn(hObject, eventdata, handles)
  84. % varargout cell array for returning output args (see VARARGOUT);
  85. % hObject handle to figure
  86. % eventdata reserved - to be defined in a future version of MATLAB
  87. % handles structure with handles and user data (see GUIDATA)
  88. % Get default command line output from handles structure
  89. varargout{1} = handles.output;
  90. % --- Executes on button press in checkbox1.
  91. function checkbox1_Callback(hObject, eventdata, handles) %#ok<*INUSD,*DEFNU>
  92. % hObject handle to checkbox1 (see GCBO)
  93. % eventdata reserved - to be defined in a future version of MATLAB
  94. % handles structure with handles and user data (see GUIDATA)
  95. % Hint: get(hObject,'Value') returns toggle state of checkbox1
  96. % --- Executes on button press in checkbox2.
  97. function checkbox2_Callback(hObject, eventdata, handles)
  98. % hObject handle to checkbox2 (see GCBO)
  99. % eventdata reserved - to be defined in a future version of MATLAB
  100. % handles structure with handles and user data (see GUIDATA)
  101. if get(hObject,'Value')
  102. set(handles.checkbox3,'Value',0)
  103. set(handles.checkbox4,'Value',0)
  104. else
  105. set(hObject,'Value',1)
  106. end
  107. % --- Executes on button press in checkbox3.
  108. function checkbox3_Callback(hObject, eventdata, handles)
  109. % hObject handle to checkbox3 (see GCBO)
  110. % eventdata reserved - to be defined in a future version of MATLAB
  111. % handles structure with handles and user data (see GUIDATA)
  112. if get(hObject,'Value')
  113. set(handles.checkbox2,'Value',0)
  114. set(handles.checkbox4,'Value',0)
  115. else
  116. set(hObject,'Value',1)
  117. end
  118. % --- Executes on button press in checkbox4.
  119. function checkbox4_Callback(hObject, eventdata, handles)
  120. % hObject handle to checkbox4 (see GCBO)
  121. % eventdata reserved - to be defined in a future version of MATLAB
  122. % handles structure with handles and user data (see GUIDATA)
  123. if get(hObject,'Value')
  124. set(handles.checkbox2,'Value',0)
  125. set(handles.checkbox3,'Value',0)
  126. else
  127. set(hObject,'Value',1)
  128. end
  129. % --- Executes on button press in pushbutton1.
  130. function pushbutton1_Callback(hObject, eventdata, handles)
  131. % hObject handle to pushbutton1 (see GCBO)
  132. % eventdata reserved - to be defined in a future version of MATLAB
  133. % handles structure with handles and user data (see GUIDATA)
  134. stat = FlBeamModel('DoDispFit');
  135. if stat{1}~=1
  136. errordlg(stat{2},'Dispersion Fit Error')
  137. return
  138. end
  139. doplot(handles);
  140. % --- Executes on button press in pushbutton2.
  141. function pushbutton2_Callback(hObject, eventdata, handles)
  142. % hObject handle to pushbutton2 (see GCBO)
  143. % eventdata reserved - to be defined in a future version of MATLAB
  144. % handles structure with handles and user data (see GUIDATA)
  145. stat = FlBeamModel('DoMagOffsetFit');
  146. if stat{1}~=1
  147. errordlg(stat{2},'Mag Offset Fit Error')
  148. return
  149. end
  150. doplot(handles);
  151. % --- Perform orbit fit
  152. function pushbutton3_Callback(hObject, eventdata, handles)
  153. % hObject handle to pushbutton3 (see GCBO)
  154. % eventdata reserved - to be defined in a future version of MATLAB
  155. % handles structure with handles and user data (see GUIDATA)
  156. % Setup progress bar
  157. global FL
  158. gui_active(1);
  159. pbh=progressbar([],0,'Orbit Fit Progress');
  160. drawnow('expose')
  161. [~, l]=FlBeamModel('GetLocal');
  162. FL.optimMonitor.pbh=pbh;
  163. FL.optimMonitor.maxIter=l.optimParam.MaxIter;
  164. stat = FlBeamModel('DoOrbitFit',pbh);
  165. FL=rmfield(FL,'optimMonitor');
  166. if ~isempty(pbh)
  167. progressbar(pbh,-1);
  168. end
  169. if stat{1}~=1
  170. if strfind(stat{2},'undefined values')
  171. errordlg('Probable error with beam tracking, lattice too badly mismatched to get an initial beam through','Orbit Fit Error')
  172. else
  173. errordlg(stat{2},'Orbit Fit Error')
  174. end
  175. return
  176. end
  177. doplot(handles);
  178. % --- Executes on button press in pushbutton4.
  179. function pushbutton4_Callback(hObject, eventdata, handles)
  180. % hObject handle to pushbutton4 (see GCBO)
  181. % eventdata reserved - to be defined in a future version of MATLAB
  182. % handles structure with handles and user data (see GUIDATA)
  183. % --- Executes on button press in radiobutton4.
  184. function radiobutton4_Callback(hObject, eventdata, handles)
  185. % hObject handle to radiobutton4 (see GCBO)
  186. % eventdata reserved - to be defined in a future version of MATLAB
  187. % handles structure with handles and user data (see GUIDATA)
  188. if get(hObject,'Value')
  189. FlBeamModel('UseEmitData',0);
  190. set(handles.radiobutton5,'Value',0)
  191. set(handles.radiobutton6,'Value',0)
  192. else
  193. set(hObject,'Value',1)
  194. end
  195. % --- Executes on button press in radiobutton5.
  196. function radiobutton5_Callback(hObject, eventdata, handles)
  197. % hObject handle to radiobutton5 (see GCBO)
  198. % eventdata reserved - to be defined in a future version of MATLAB
  199. % handles structure with handles and user data (see GUIDATA)
  200. if get(hObject,'Value')
  201. FlBeamModel('UseEmitData',1)
  202. set(handles.radiobutton4,'Value',0)
  203. set(handles.radiobutton6,'Value',0)
  204. else
  205. set(hObject,'Value',1)
  206. end
  207. % --- Executes on button press in radiobutton6.
  208. function radiobutton6_Callback(hObject, eventdata, handles)
  209. % hObject handle to radiobutton6 (see GCBO)
  210. % eventdata reserved - to be defined in a future version of MATLAB
  211. % handles structure with handles and user data (see GUIDATA)
  212. if get(hObject,'Value')
  213. FlBeamModel('UseEmitData',2)
  214. set(handles.radiobutton4,'Value',0)
  215. set(handles.radiobutton5,'Value',0)
  216. else
  217. set(hObject,'Value',1)
  218. end
  219. % --- Executes on button press in togglebutton4.
  220. function togglebutton4_Callback(hObject, eventdata, handles)
  221. % hObject handle to togglebutton4 (see GCBO)
  222. % eventdata reserved - to be defined in a future version of MATLAB
  223. % handles structure with handles and user data (see GUIDATA)
  224. % Hint: get(hObject,'Value') returns toggle state of togglebutton4
  225. % --- Executes on button press in togglebutton5.
  226. function togglebutton5_Callback(hObject, eventdata, handles)
  227. % hObject handle to togglebutton5 (see GCBO)
  228. % eventdata reserved - to be defined in a future version of MATLAB
  229. % handles structure with handles and user data (see GUIDATA)
  230. % Hint: get(hObject,'Value') returns toggle state of togglebutton5
  231. % --- Executes on button press in togglebutton6.
  232. function togglebutton6_Callback(hObject, eventdata, handles)
  233. % hObject handle to togglebutton6 (see GCBO)
  234. % eventdata reserved - to be defined in a future version of MATLAB
  235. % handles structure with handles and user data (see GUIDATA)
  236. % Hint: get(hObject,'Value') returns toggle state of togglebutton6
  237. % --- Executes on selection change in listbox2.
  238. function listbox2_Callback(hObject, eventdata, handles)
  239. % hObject handle to listbox2 (see GCBO)
  240. % eventdata reserved - to be defined in a future version of MATLAB
  241. % handles structure with handles and user data (see GUIDATA)
  242. % Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array
  243. % contents{get(hObject,'Value')} returns selected item from listbox2
  244. % --- Executes during object creation, after setting all properties.
  245. function listbox2_CreateFcn(hObject, eventdata, handles)
  246. % hObject handle to listbox2 (see GCBO)
  247. % eventdata reserved - to be defined in a future version of MATLAB
  248. % handles empty - handles not created until after all CreateFcns called
  249. % Hint: listbox controls usually have a white background on Windows.
  250. % See ISPC and COMPUTER.
  251. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  252. set(hObject,'BackgroundColor','white');
  253. end
  254. function edit2_Callback(hObject, eventdata, handles)
  255. % hObject handle to edit2 (see GCBO)
  256. % eventdata reserved - to be defined in a future version of MATLAB
  257. % handles structure with handles and user data (see GUIDATA)
  258. persistent lastStr
  259. if isempty(lastStr) || ~isequal(lastStr,get(hObject,'String'))
  260. FlBeamModel('SetLookbackTime',str2double(get(hObject,'String')));
  261. lastStr=get(hObject,'String');
  262. end
  263. setlastmeas(handles);
  264. % --- Executes during object creation, after setting all properties.
  265. function edit2_CreateFcn(hObject, eventdata, handles)
  266. % hObject handle to edit2 (see GCBO)
  267. % eventdata reserved - to be defined in a future version of MATLAB
  268. % handles empty - handles not created until after all CreateFcns called
  269. % Hint: edit controls usually have a white background on Windows.
  270. % See ISPC and COMPUTER.
  271. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  272. set(hObject,'BackgroundColor','white');
  273. end
  274. % --- Executes on button press in radiobutton2.
  275. function radiobutton2_Callback(hObject, eventdata, handles)
  276. % hObject handle to radiobutton2 (see GCBO)
  277. % eventdata reserved - to be defined in a future version of MATLAB
  278. % handles structure with handles and user data (see GUIDATA)
  279. if get(hObject,'Value')
  280. set(handles.radiobutton3,'Value',0)
  281. bpmsel('get',handles);
  282. else
  283. set(hObject,'Value',1)
  284. end
  285. % --- Executes on button press in radiobutton3.
  286. function radiobutton3_Callback(hObject, eventdata, handles)
  287. % hObject handle to radiobutton3 (see GCBO)
  288. % eventdata reserved - to be defined in a future version of MATLAB
  289. % handles structure with handles and user data (see GUIDATA)
  290. if (get(hObject,'Value'))
  291. set(handles.radiobutton2,'Value',0)
  292. bpmsel('get',handles);
  293. else
  294. set(hObject,'Value',1)
  295. end
  296. % --- Executes on button press in togglebutton1.
  297. function togglebutton1_Callback(hObject, eventdata, handles)
  298. % hObject handle to togglebutton1 (see GCBO)
  299. % eventdata reserved - to be defined in a future version of MATLAB
  300. % handles structure with handles and user data (see GUIDATA)
  301. % Hint: get(hObject,'Value') returns toggle state of togglebutton1
  302. % --- Executes on button press in togglebutton2.
  303. function togglebutton2_Callback(hObject, eventdata, handles)
  304. % hObject handle to togglebutton2 (see GCBO)
  305. % eventdata reserved - to be defined in a future version of MATLAB
  306. % handles structure with handles and user data (see GUIDATA)
  307. % Hint: get(hObject,'Value') returns toggle state of togglebutton2
  308. % --- Executes on button press in togglebutton3.
  309. function togglebutton3_Callback(hObject, eventdata, handles)
  310. % hObject handle to togglebutton3 (see GCBO)
  311. % eventdata reserved - to be defined in a future version of MATLAB
  312. % handles structure with handles and user data (see GUIDATA)
  313. % Hint: get(hObject,'Value') returns toggle state of togglebutton3
  314. % --- Executes on selection change in listbox1.
  315. function listbox1_Callback(hObject, eventdata, handles)
  316. % hObject handle to listbox1 (see GCBO)
  317. % eventdata reserved - to be defined in a future version of MATLAB
  318. % handles structure with handles and user data (see GUIDATA)
  319. bpmsel('set',handles);
  320. % --- Executes during object creation, after setting all properties.
  321. function listbox1_CreateFcn(hObject, eventdata, handles)
  322. % hObject handle to listbox1 (see GCBO)
  323. % eventdata reserved - to be defined in a future version of MATLAB
  324. % handles empty - handles not created until after all CreateFcns called
  325. % Hint: listbox controls usually have a white background on Windows.
  326. % See ISPC and COMPUTER.
  327. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  328. set(hObject,'BackgroundColor','white');
  329. end
  330. % # bpm pulses to use
  331. function edit1_Callback(hObject, eventdata, handles)
  332. % hObject handle to edit1 (see GCBO)
  333. % eventdata reserved - to be defined in a future version of MATLAB
  334. % handles structure with handles and user data (see GUIDATA)
  335. FlBeamModel('SetNBPMAve',str2double(get(hObject,'String')))
  336. % --- Executes during object creation, after setting all properties.
  337. function edit1_CreateFcn(hObject, eventdata, handles)
  338. % hObject handle to edit1 (see GCBO)
  339. % eventdata reserved - to be defined in a future version of MATLAB
  340. % handles empty - handles not created until after all CreateFcns called
  341. % Hint: edit controls usually have a white background on Windows.
  342. % See ISPC and COMPUTER.
  343. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  344. set(hObject,'BackgroundColor','white');
  345. end
  346. % --- Executes on button press in togglebutton7.
  347. function togglebutton7_Callback(hObject, eventdata, handles)
  348. % hObject handle to togglebutton7 (see GCBO)
  349. % eventdata reserved - to be defined in a future version of MATLAB
  350. % handles structure with handles and user data (see GUIDATA)
  351. bpmsel('get',handles);
  352. function edit3_Callback(hObject, eventdata, handles)
  353. % hObject handle to edit3 (see GCBO)
  354. % eventdata reserved - to be defined in a future version of MATLAB
  355. % handles structure with handles and user data (see GUIDATA)
  356. [~, data]=FlBeamModel('GetData');
  357. if data.donefit
  358. doplot(handles)
  359. end
  360. % --- Executes during object creation, after setting all properties.
  361. function edit3_CreateFcn(hObject, eventdata, handles)
  362. % hObject handle to edit3 (see GCBO)
  363. % eventdata reserved - to be defined in a future version of MATLAB
  364. % handles empty - handles not created until after all CreateFcns called
  365. % Hint: edit controls usually have a white background on Windows.
  366. % See ISPC and COMPUTER.
  367. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  368. set(hObject,'BackgroundColor','white');
  369. end
  370. function stat=bpmsel(cmd,handles)
  371. [stat l]=FlBeamModel('GetLocal'); if stat{1}~=1; return; end;
  372. [stat data]=FlBeamModel('GetData'); if stat{1}~=1; return; end;
  373. switch cmd
  374. case 'get'
  375. bpmList=true(1,length(l.allBpms));
  376. if any(l.drBpms)
  377. bpmList(l.drBpms)=get(handles.togglebutton8,'Value');
  378. end
  379. bpmList(l.extBpms)=get(handles.togglebutton9,'Value');
  380. bpmList(l.ffsBpms)=get(handles.togglebutton10,'Value');
  381. set(handles.listbox1,'String',l.allBpmNames(bpmList))
  382. set(handles.listbox1,'UserData',bpmList)
  383. if get(handles.radiobutton2,'Value')
  384. set(handles.listbox1,'Value',find(data.useBpms(bpmList)))
  385. elseif get(handles.radiobutton3,'Value')
  386. set(handles.listbox1,'Value',find(data.useDispData(bpmList)))
  387. end
  388. case 'set'
  389. useBpms=false(1,length(l.allBpms));
  390. bpmList=get(handles.listbox1,'UserData');
  391. bpmsel=false(1,length(find(bpmList))); bpmsel(get(handles.listbox1,'Value'))=true;
  392. useBpms(bpmList)=bpmsel;
  393. if get(handles.radiobutton2,'Value') || get(handles.togglebutton7,'Value')
  394. stat = FlBeamModel('UseBpms',useBpms); if stat{1}~=1; return; end;
  395. end
  396. if get(handles.radiobutton3,'Value') || get(handles.togglebutton7,'Value')
  397. stat = FlBeamModel('UseDispData',useBpms); if stat{1}~=1; return; end;
  398. end
  399. otherwise
  400. error('No such command in bpmsel')
  401. end
  402. function stat=magsel(cmd,handles)
  403. [stat l]=FlBeamModel('GetLocal'); if stat{1}~=1; return; end;
  404. [stat data]=FlBeamModel('GetData'); if stat{1}~=1; return; end;
  405. switch cmd
  406. case 'get'
  407. magList=true(1,length(l.clName));
  408. magList(l.drcl)=get(handles.togglebutton8,'Value');
  409. magList(l.extcl)=get(handles.togglebutton9,'Value');
  410. magList(l.ffscl)=get(handles.togglebutton10,'Value');
  411. set(handles.listbox2,'String',l.clName(magList))
  412. set(handles.listbox2,'UserData',magList)
  413. set(handles.listbox2,'Value',find(data.useMagOffsets(magList)))
  414. case 'set'
  415. useMag=false(1,length(l.clName));
  416. magList=get(handles.listbox2,'UserData');
  417. magsel=false(1,length(find(magList))); magsel(get(handles.listbox2,'Value'))=true;
  418. useMag(magList)=magsel;
  419. stat = FlBeamModel('UseMagOffsets',useMag); if stat{1}~=1; return; end;
  420. otherwise
  421. error('No such command in bpmsel')
  422. end
  423. % --- Executes on button press in togglebutton8.
  424. function togglebutton8_Callback(hObject, eventdata, handles)
  425. % hObject handle to togglebutton8 (see GCBO)
  426. % eventdata reserved - to be defined in a future version of MATLAB
  427. % handles structure with handles and user data (see GUIDATA)
  428. [~, l]=FlBeamModel('GetLocal');
  429. if ~any(l.drBpms)
  430. errordlg('No DR BPM INSTRs available','No DR BPMs');
  431. set(hObject,'Value',0)
  432. return
  433. end
  434. FlBeamModel('SelectDR',get(hObject,'Value'));
  435. bpmsel('get',handles);
  436. magsel('get',handles);
  437. % --- Executes on button press in togglebutton9.
  438. function togglebutton9_Callback(hObject, eventdata, handles)
  439. % hObject handle to togglebutton9 (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. FlBeamModel('SelectEXT',get(hObject,'Value'));
  443. bpmsel('get',handles);
  444. magsel('get',handles);
  445. % --- Executes on button press in togglebutton10.
  446. function togglebutton10_Callback(hObject, eventdata, handles)
  447. % hObject handle to togglebutton10 (see GCBO)
  448. % eventdata reserved - to be defined in a future version of MATLAB
  449. % handles structure with handles and user data (see GUIDATA)
  450. FlBeamModel('SelectFFS',get(hObject,'Value'));
  451. bpmsel('get',handles);
  452. magsel('get',handles);
  453. % --- Plotting function
  454. function doplot(handles)
  455. global BEAMLINE
  456. % Get data structure
  457. [~, data]=FlBeamModel('GetData');
  458. % Get tracked positions at every BEAMLINE element
  459. [stat xtrack ytrack strack] = FlBeamModel('EleTrack');
  460. if stat{1}~=1; errordlg(stat{2},'EleTrack Error'); end
  461. % Display orbit fit at point request?
  462. sreq=[];
  463. if ~strcmp(get(handles.edit3,'String'),'---')
  464. ind=findcells(BEAMLINE,'Name',get(handles.edit3,'String'));
  465. if ~isempty(ind)
  466. ireq=ismember(strack,BEAMLINE{ind}.S);
  467. if any(ireq)
  468. ireq=find(ireq,1);
  469. sreq=strack(ireq);
  470. xreq=xtrack(ireq);
  471. yreq=ytrack(ireq);
  472. set(handles.text1,'String',num2str(xreq*1e6))
  473. set(handles.text2,'String',num2str(yreq*1e6))
  474. end
  475. end
  476. end
  477. % Orbit plotting
  478. if get(handles.checkbox2,'Value')
  479. % Plot BPM measurements
  480. errorbar(handles.axes1,data.bpmdata.s,data.bpmdata.x.*1e6,data.bpmdata.dx.*1e6,'r*');
  481. hold(handles.axes1,'on')
  482. errorbar(handles.axes1,data.bpmdata.s,data.bpmdata.y.*1e6,data.bpmdata.dy.*1e6,'b*');
  483. % Plot tracked orbit
  484. plot(strack,xtrack.*1e6,'r')
  485. plot(strack,ytrack.*1e6,'b')
  486. xlabel(handles.axes1,'S / m')
  487. ylabel(handles.axes1,'x/y orbit / um')
  488. grid(handles.axes1,'on')
  489. if ~isempty(sreq)
  490. plot(sreq,xreq*1e6,'ro','MarkerSize',12,'LineWidth',2)
  491. plot(sreq,xreq*1e6,'r+','MarkerSize',12,'LineWidth',2)
  492. plot(sreq,yreq*1e6,'bo','MarkerSize',12,'LineWidth',2)
  493. plot(sreq,yreq*1e6,'b+','MarkerSize',12,'LineWidth',2)
  494. end
  495. hold(handles.axes1,'off')
  496. elseif get(handles.checkbox3,'Value')
  497. end
  498. function setlastmeas(handles)
  499. global FL
  500. if ~isfield(FL,'lastDispMeas') || isempty(FL.lastDispMeas)
  501. FL.lastDispMeas=datevec('1/1/1970');
  502. end
  503. set(handles.text5,'String',sprintf('%s (%d hrs)',datestr(FL.lastDispMeas),etime(clock,FL.lastDispMeas)/3600))
  504. if (etime(clock,FL.lastDispMeas)/3600) > str2double(get(handles.edit2,'String'))
  505. set(handles.text5,'ForegroundColor','red')
  506. set(handles.radiobutton8,'Value',1)
  507. radiobutton8_Callback(handles.radiobutton4,[],handles);
  508. set(handles.radiobutton7,'Enable','off')
  509. else
  510. set(handles.text5,'ForegroundColor','black')
  511. set(handles.radiobutton8,'Enable','on')
  512. end
  513. [~, ts]=FlCA('lcaGet','mOTR:procData:projemitx');
  514. if isnan(ts); ts=0; end;
  515. elapsedTime=now*24-epicsts2mat(ts)*24;
  516. set(handles.text6,'String',sprintf('%s (%d hrs)',datestr(epicsts2mat(ts)),elapsedTime))
  517. if elapsedTime>str2double(get(handles.edit2,'String'))
  518. set(handles.text6,'ForegroundColor','red')
  519. set(handles.radiobutton4,'Value',1)
  520. radiobutton4_Callback(handles.radiobutton4,[],handles);
  521. set(handles.radiobutton5,'Enable','off')
  522. set(handles.radiobutton6,'Enable','off')
  523. else
  524. set(handles.text6,'ForegroundColor','black')
  525. set(handles.radiobutton5,'Enable','on')
  526. set(handles.radiobutton6,'Enable','on')
  527. end
  528. % --- Executes on button press in radiobutton7.
  529. function radiobutton7_Callback(hObject, eventdata, handles)
  530. % hObject handle to radiobutton7 (see GCBO)
  531. % eventdata reserved - to be defined in a future version of MATLAB
  532. % handles structure with handles and user data (see GUIDATA)
  533. if get(hObject,'Value')
  534. set(handles.radiobutton8,'Value',0)
  535. else
  536. set(hObject,'Value',1)
  537. end
  538. FlBeamModel('DispSelect',2);
  539. % --- Executes on button press in radiobutton8.
  540. function radiobutton8_Callback(hObject, eventdata, handles)
  541. % hObject handle to radiobutton8 (see GCBO)
  542. % eventdata reserved - to be defined in a future version of MATLAB
  543. % handles structure with handles and user data (see GUIDATA)
  544. if get(hObject,'Value')
  545. set(handles.radiobutton7,'Value',0)
  546. else
  547. set(hObject,'Value',1)
  548. end
  549. FlBeamModel('DispSelect',1);
  550. % --- Executes when user attempts to close figure1.
  551. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  552. % hObject handle to figure1 (see GCBO)
  553. % eventdata reserved - to be defined in a future version of MATLAB
  554. % handles structure with handles and user data (see GUIDATA)
  555. t=get(handles.figure1,'UserData');
  556. stop(t);
  557. guiCloseFn('FlBeamModelGui',handles);
  558. function edit5_Callback(hObject, eventdata, handles)
  559. % hObject handle to edit5 (see GCBO)
  560. % eventdata reserved - to be defined in a future version of MATLAB
  561. % handles structure with handles and user data (see GUIDATA)
  562. val=str2double(get(hObject,'String'));
  563. if ~isnan(val) && val>0 && val <10000
  564. FlBeamModel('SetMaxIter',val);
  565. else
  566. [~, l]=FlBeamModel('GetLocal');
  567. set(hObject,'String',num2str(l.optimParam.MaxIter));
  568. end
  569. % --- Executes during object creation, after setting all properties.
  570. function edit5_CreateFcn(hObject, eventdata, handles)
  571. % hObject handle to edit5 (see GCBO)
  572. % eventdata reserved - to be defined in a future version of MATLAB
  573. % handles empty - handles not created until after all CreateFcns called
  574. % Hint: edit controls usually have a white background on Windows.
  575. % See ISPC and COMPUTER.
  576. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  577. set(hObject,'BackgroundColor','white');
  578. end
  579. % --- Executes on button press in pushbutton5.
  580. function pushbutton5_Callback(hObject, eventdata, handles)
  581. % hObject handle to pushbutton5 (see GCBO)
  582. % eventdata reserved - to be defined in a future version of MATLAB
  583. % handles structure with handles and user data (see GUIDATA)
  584. FlBeamModel('ResetInitial');