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

/ATF2/FlightSim/trustedApps/bba/bba.m

http://atf2flightsim.googlecode.com/
MATLAB | 1455 lines | 852 code | 198 blank | 405 comment | 125 complexity | 3cf2687740f6d132729cc7e5ea43b6e8 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. function varargout = bba(varargin)
  2. % BBA M-file for bba.fig
  3. % BBA, by itself, creates a new BBA or raises the existing
  4. % singleton*.
  5. %
  6. % H = BBA returns the handle to a new BBA or the handle to
  7. % the existing singleton*.
  8. %
  9. % BBA('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in BBA.M with the given input arguments.
  11. %
  12. % BBA('Property','Value',...) creates a new BBA or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before bba_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to bba_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 bba
  23. % Last Modified by GUIDE v2.5 18-Nov-2009 17:55:15
  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', @bba_OpeningFcn, ...
  29. 'gui_OutputFcn', @bba_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 bba is made visible.
  42. function bba_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 bba (see VARARGIN)
  48. global BEAMLINE INSTR
  49. % Choose default command line output for bba
  50. handles.output = handles;
  51. % Update handles structure
  52. guidata(hObject, handles);
  53. % Info message box
  54. mhan=msgbox('Initialising BBA routine...','BBA');
  55. % Fill BPM popup menu
  56. % Allow BBA for Quad attached EXT and FFS bpms
  57. bpmind=findcells(BEAMLINE,'Name','MQ*');
  58. for ibpm=1:length(bpmind)
  59. pstr{ibpm}=BEAMLINE{bpmind(ibpm)}.Name;
  60. end
  61. set(handles.popupmenu1,'String',pstr);
  62. % Get function parameters and set GUI values
  63. [stat pars]=bbaFn('GetPars');
  64. if stat{1}~=1
  65. errordlg(stat{2},'bbaFn Error')
  66. return
  67. end
  68. % - make sure bbaFn in stopped state
  69. if ~strcmp(pars.status,'stopped')
  70. stat=bbaFn('stop');
  71. if stat{1}~=1
  72. errordlg(stat{2},'bbaFn Error')
  73. return
  74. end
  75. [stat pars]=bbaFn('GetPars');
  76. if stat{1}~=1
  77. errordlg(stat{2},'bbaFn Error')
  78. return
  79. end
  80. end
  81. if ~isempty(pars.thisbpm)
  82. thisbpm=BEAMLINE{INSTR{pars.thisbpm}.Index}.Name;
  83. set(handles.popupmenu1,'Value',find(ismember(pstr,thisbpm)));
  84. else
  85. set(handles.popupmenu1,'Value',1);
  86. end
  87. for ibpm=1:length(bpmind)
  88. bpminstr(ibpm)=findcells(INSTR,'Index',bpmind(ibpm));
  89. end
  90. set(handles.popupmenu1,'UserData',bpminstr);
  91. popupmenu1_Callback(handles.popupmenu1,[],handles);
  92. % Set bbaFn into non-blocking mode
  93. newpars.blocking=false;
  94. stat=bbaFn('SetPars',newpars);
  95. if stat{1}~=1
  96. errordlg(stat{2},'bbaFn Error')
  97. return
  98. end
  99. % Remove info box if still there
  100. if ishandle(mhan); delete(mhan); end;
  101. % --- Outputs from this function are returned to the command line.
  102. function varargout = bba_OutputFcn(hObject, eventdata, handles)
  103. % varargout cell array for returning output args (see VARARGOUT);
  104. % hObject handle to figure
  105. % eventdata reserved - to be defined in a future version of MATLAB
  106. % handles structure with handles and user data (see GUIDATA)
  107. % Get default command line output from handles structure
  108. varargout{1} = handles.output;
  109. % --- Executes on button press in pushbutton1.
  110. function pushbutton1_Callback(hObject, eventdata, handles) %#ok<*INUSD,*DEFNU>
  111. % hObject handle to pushbutton1 (see GCBO)
  112. % eventdata reserved - to be defined in a future version of MATLAB
  113. % handles structure with handles and user data (see GUIDATA)
  114. guiCloseFn('bba',handles);
  115. % N BPM readings to ave
  116. function edit1_Callback(hObject, eventdata, handles)
  117. % hObject handle to edit1 (see GCBO)
  118. % eventdata reserved - to be defined in a future version of MATLAB
  119. % handles structure with handles and user data (see GUIDATA)
  120. bpminstr=get(handles.popupmenu1,'UserData');
  121. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  122. val=str2double(get(hObject,'String'));
  123. [stat pars]=bbaFn('GetPars');
  124. if isnan(val) || val<2
  125. set(hObject,'String',num2str(pars.defnbpm));
  126. return
  127. end
  128. newpars.nbpm=pars.nbpm;
  129. if get(handles.togglebutton2,'Value')
  130. newpars.nbpm(:)=val;
  131. else
  132. if get(handles.togglebutton2,'Value')
  133. newpars.nbpm(:)=val;
  134. else
  135. newpars.nbpm(bpmind)=val;
  136. end
  137. end
  138. bbaFn('SetPars',newpars);
  139. % --- Executes during object creation, after setting all properties.
  140. function edit1_CreateFcn(hObject, eventdata, handles)
  141. % hObject handle to edit1 (see GCBO)
  142. % eventdata reserved - to be defined in a future version of MATLAB
  143. % handles empty - handles not created until after all CreateFcns called
  144. % Hint: edit controls usually have a white background on Windows.
  145. % See ISPC and COMPUTER.
  146. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  147. set(hObject,'BackgroundColor','white');
  148. end
  149. % Q cut
  150. function edit2_Callback(hObject, eventdata, handles)
  151. % hObject handle to edit2 (see GCBO)
  152. % eventdata reserved - to be defined in a future version of MATLAB
  153. % handles structure with handles and user data (see GUIDATA)
  154. bpminstr=get(handles.popupmenu1,'UserData');
  155. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  156. val=str2double(get(hObject,'String'));
  157. [stat pars]=bbaFn('GetPars');
  158. if isnan(val) || val<=0 || val>=1
  159. set(hObject,'String',num2str(pars.defqcut));
  160. return
  161. end
  162. newpars.qcut=pars.qcut;
  163. if get(handles.togglebutton2,'Value')
  164. newpars.qcut(:)=val;
  165. else
  166. newpars.qcut(bpmind)=val;
  167. end
  168. bbaFn('SetPars',newpars);
  169. % --- Executes during object creation, after setting all properties.
  170. function edit2_CreateFcn(hObject, eventdata, handles)
  171. % hObject handle to edit2 (see GCBO)
  172. % eventdata reserved - to be defined in a future version of MATLAB
  173. % handles empty - handles not created until after all CreateFcns called
  174. % Hint: edit controls usually have a white background on Windows.
  175. % See ISPC and COMPUTER.
  176. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  177. set(hObject,'BackgroundColor','white');
  178. end
  179. % --- Start BBA procedure
  180. function pushbutton2_Callback(hObject, eventdata, handles)
  181. % hObject handle to pushbutton2 (see GCBO)
  182. % eventdata reserved - to be defined in a future version of MATLAB
  183. % handles structure with handles and user data (see GUIDATA)
  184. bpminstr=get(handles.popupmenu1,'UserData');
  185. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  186. set(handles.pushbutton9,'String','Starting');
  187. set(handles.pushbutton9,'BackgroundColor','green');
  188. set(handles.text6,'String','Starting BBA measurement process...');
  189. drawnow('expose');
  190. maxiter=str2double(get(handles.edit5,'String'));
  191. [stat pars]=bbaFn('GetPars');
  192. if stat{1}~=1
  193. set(handles.text6,'String',sprintf('Fetch pars error:\n%s',stat{2}))
  194. set(handles.pushbutton9,'String','Error');
  195. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  196. return
  197. end
  198. % Check bba function in stopped state before starting
  199. if ~strcmp(pars.status,'stopped')
  200. set(handles.text6,'String','BBA appears to still be running, reset with status button')
  201. set(handles.pushbutton9,'String','Error');
  202. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  203. return
  204. end
  205. % Start measurement procedure and take first offset measurement
  206. stat = bbaFn('start',bpmind);
  207. if stat{1}<0
  208. set(handles.text6,'String',sprintf('Run error:\n%s',stat{2}))
  209. set(handles.pushbutton9,'String','Error');
  210. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  211. return
  212. end
  213. [stat pars]=bbaFn('GetPars');
  214. if stat{1}~=1
  215. set(handles.text6,'String',sprintf('Fetch pars error:\n%s',stat{2}))
  216. set(handles.pushbutton9,'String','Error');
  217. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  218. return
  219. end
  220. % Continue taking BBA data and moving to offset until requested to stop or
  221. % max iterations reached
  222. lastiter=pars.iterstep;
  223. diagplot('clear');
  224. while ~isempty(pars.iterstep) && pars.iterstep<=maxiter
  225. % Update displays
  226. popupmenu1_Callback(handles.popupmenu1,[],handles);
  227. % check for stop command or stop if using measureonce command or reached
  228. % tolerence value
  229. stcmd=get(hObject,'UserData');
  230. istol=pars.iterstep>0;
  231. if get(handles.radiobutton1,'Value') && abs(pars.thisOffset(1))<pars.tol(bpmind)
  232. istol=false;
  233. end
  234. if get(handles.radiobutton2,'Value') && abs(pars.thisOffset(3))<pars.tol(bpmind)
  235. istol=false;
  236. end
  237. if isequal(stcmd,'stop') || (isequal(stcmd,'measureonce') && pars.iterstep>0) || (istol && ~isequal(stcmd,'measureonce'))
  238. if isequal(stcmd,'measureonce')
  239. diagplot('bpm',pars,handles);
  240. end
  241. stat = bbaFn('Stop');
  242. if stat{1}<0
  243. set(handles.text6,['Stop Command error:\n' stat{2}]);
  244. set(handles.pushbutton9,'String','Error');
  245. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  246. else
  247. if isequal(stcmd,'stop')
  248. set(handles.text6,'String','Stop Request');
  249. else
  250. set(handles.text6,'String','Finished measurement')
  251. end
  252. set(handles.pushbutton9,'String','Stopped');
  253. set(handles.pushbutton9,'BackgroundColor','red');
  254. end
  255. set(hObject,'UserData',[]);
  256. return
  257. end
  258. % Check if stopping or stopped
  259. [stat pars]=bbaFn('GetPars');
  260. if stat{1}==1 && (strcmp(pars.status,'stopping') || strcmp(pars.status,'stopped'))
  261. set(handles.text6,'BBA procedure complete');
  262. set(handles.pushbutton9,'String','Stopped');
  263. set(handles.pushbutton9,'BackgroundColor','red');
  264. return
  265. end
  266. % continue with next step of BBA procedure
  267. stat = bbaFn('continue',bpmind);
  268. if stat{1}<0
  269. set(handles.text6,sprintf('Run error:\n %s',stat{2}))
  270. set(handles.pushbutton9,'String','Error');
  271. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  272. return
  273. end
  274. % Get current status
  275. [stat pars]=bbaFn('GetPars');
  276. if stat{1}~=1
  277. set(handles.text6,['Fetch pars error:\n' stat{2}]);
  278. set(handles.pushbutton9,'String','Error');
  279. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  280. return
  281. end
  282. % Show appropriate diagnostic plots
  283. % & ask accept|reject bpm measurements
  284. if ~isempty(pars.iterstep) && ~isequal(lastiter,pars.iterstep)
  285. lastiter=pars.iterstep;
  286. if ~get(handles.togglebutton1,'Value')
  287. diagplot('bpm',pars,handles);
  288. set(handles.pushbutton9,'String','Paused');
  289. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  290. set(handles.text6,'String','Accept or retake BPM measurements?')
  291. drawnow('expose');
  292. uiwait(handles.figure1);
  293. while ishandle(handles.figure1) && ...
  294. ~(get(handles.figure1,'CurrentObject')==handles.pushbutton10 || get(handles.figure1,'CurrentObject')==handles.pushbutton11)
  295. uiwait(handles.figure1);
  296. end
  297. if ~ishandle(handles.figure1); return; end;
  298. if get(handles.figure1,'CurrentObject')==handles.pushbutton11
  299. newpars.iterstep=newpars.iterstep-1;
  300. bbaFn('SetPars',newpars); pars.iterstep=newpars.iterstep;
  301. end
  302. end
  303. diagplot('offset',pars,handles);
  304. end
  305. set(handles.text6,'String',sprintf('Running...\nIteration step: %d',pars.iterstep));
  306. set(handles.pushbutton9,'String','Running');
  307. set(handles.pushbutton9,'BackgroundColor','green');
  308. drawnow('expose');
  309. pause(0.2)
  310. end
  311. % Make sure bba in stopped state and signal completion
  312. bbaFn('stop');
  313. set(handles.text6,'BBA procedure complete');
  314. set(handles.pushbutton9,'String','Stopped');
  315. set(handles.pushbutton9,'BackgroundColor','red');
  316. % plotting function
  317. function diagplot(cmd,pars,handles)
  318. persistent offdata lastcmd
  319. if isequal(cmd,'clear')
  320. offdata=[];
  321. lastcmd=[];
  322. return
  323. end
  324. if isempty(cmd)
  325. cmd=lastcmd;
  326. else
  327. lastcmd=cmd;
  328. end
  329. %pars.thisBpmData=[find(xbpms); dx(xbpms); dx_err(xbpms); find(ybpms); dy(ybpms); dy_err(ybpms)];
  330. switch cmd
  331. case 'bpm'
  332. % plot x or y measurement bpm estimates of beam offset at magnet
  333. if get(handles.radiobutton3,'Value')
  334. errorbar(pars.thisBpmData{1},pars.thisBpmData{2}*1e6,pars.thisBpmData{3}*1e6)
  335. xlabel('INSTR index');
  336. ylabel('\DeltaX / um');
  337. else
  338. errorbar(pars.thisBpmData{4},pars.thisBpmData{5}*1e6,pars.thisBpmData{6}*1e6)
  339. xlabel('INSTR index');
  340. ylabel('\DeltaY / um');
  341. end
  342. case 'offset'
  343. offdata(pars.iterstep,:)=pars.thisOffset(:);
  344. os=size(offdata);
  345. if get(handles.radiobutton3,'Value')
  346. errorbar(1:os(1),offdata(:,1)*1e6,offdata(:,2)*1e6);
  347. xlabel('Iteration #');
  348. ylabel('Measured Horizontal Beam Offset / um');
  349. else
  350. errorbar(1:os(1),offdata(:,3)*1e6,offdata(:,4)*1e6);
  351. xlabel('Iteration #');
  352. ylabel('Measured Vertical Beam Offset / um');
  353. end
  354. end
  355. % --- Executes on button press in pushbutton3.
  356. function pushbutton3_Callback(hObject, eventdata, handles)
  357. % hObject handle to pushbutton3 (see GCBO)
  358. % eventdata reserved - to be defined in a future version of MATLAB
  359. % handles structure with handles and user data (see GUIDATA)
  360. % --- Executes on button press in pushbutton4.
  361. function pushbutton4_Callback(hObject, eventdata, handles)
  362. % hObject handle to pushbutton4 (see GCBO)
  363. % eventdata reserved - to be defined in a future version of MATLAB
  364. % handles structure with handles and user data (see GUIDATA)
  365. % --- Executes on button press in pushbutton5.
  366. function pushbutton5_Callback(hObject, eventdata, handles)
  367. % hObject handle to pushbutton5 (see GCBO)
  368. % eventdata reserved - to be defined in a future version of MATLAB
  369. % handles structure with handles and user data (see GUIDATA)
  370. % --- Executes on button press in pushbutton6.
  371. function pushbutton6_Callback(hObject, eventdata, handles)
  372. % hObject handle to pushbutton6 (see GCBO)
  373. % eventdata reserved - to be defined in a future version of MATLAB
  374. % handles structure with handles and user data (see GUIDATA)
  375. % --- Status
  376. function pushbutton9_Callback(hObject, eventdata, handles)
  377. % hObject handle to pushbutton9 (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. % Reset error status
  381. if strcmpi(get(hObject,'String'),'error')
  382. newpars.status='stopped';
  383. bbaFn('SetPars',newpars);
  384. set(hObject,'String','Stopped');
  385. set(hObject,'BackgroundColor','red');
  386. set(handles.text6,'String','')
  387. end
  388. % --- Reset x BBA
  389. function pushbutton7_Callback(hObject, eventdata, handles)
  390. % hObject handle to pushbutton7 (see GCBO)
  391. % eventdata reserved - to be defined in a future version of MATLAB
  392. % handles structure with handles and user data (see GUIDATA)
  393. bpminstr=get(handles.popupmenu1,'UserData');
  394. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  395. if ~strcmp(questdlg('Reset horizontal BBA offset to zero (takes immediate effect)?','Reset BBA?'),'Yes')
  396. return
  397. end
  398. stat=bbaFn('CommitBBA',bpmind,'x',0);
  399. if stat{1}~=1
  400. set(handles.text6,['BBA commit error:\n' stat{2}]);
  401. set(handles.pushbutton9,'String','Error');
  402. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  403. return
  404. else
  405. set(handles.text6,'X BBA setting reset to zero');
  406. popupmenu1_Callback(handles.popupmenu1,[],handles);
  407. end
  408. % --- Executes on button press in pushbutton8.
  409. function pushbutton8_Callback(hObject, eventdata, handles)
  410. % hObject handle to pushbutton8 (see GCBO)
  411. % eventdata reserved - to be defined in a future version of MATLAB
  412. % handles structure with handles and user data (see GUIDATA)
  413. % --- BPM list
  414. function popupmenu1_Callback(hObject, eventdata, handles)
  415. % hObject handle to popupmenu1 (see GCBO)
  416. % eventdata reserved - to be defined in a future version of MATLAB
  417. % handles structure with handles and user data (see GUIDATA)
  418. persistent lastval
  419. if ~isempty(lastval) && ~get(hObject,'Value')
  420. set(hObject,'Value',lastval)
  421. end
  422. lastval=get(hObject,'Value');
  423. % Reset message box
  424. set(handles.text6,'String','');
  425. % Get bba function pars
  426. stat=bbaFn('UpdateBBA'); % make sure have fresh BBA values
  427. if stat{1}~=1
  428. errordlg(stat{2},'bbaFn Error')
  429. return
  430. end
  431. [stat pars]=bbaFn('GetPars');
  432. if stat{1}~=1
  433. errordlg(stat{2},'bbaFn Error')
  434. return
  435. end
  436. % BPM index
  437. bpminstr=get(hObject,'UserData');
  438. bpmind=bpminstr(get(hObject,'Value'));
  439. % Set GUI boxes
  440. set(handles.edit4,'String',num2str(pars.tol(bpmind)*1e6,4));
  441. set(handles.edit5,'String',num2str(pars.maxiter(bpmind),4));
  442. set(handles.edit8,'String',num2str(pars.dps(bpmind)*100,4));
  443. set(handles.edit1,'String',num2str(pars.nbpm(bpmind)));
  444. set(handles.edit2,'String',num2str(pars.qcut(bpmind)));
  445. set(handles.edit12,'String',num2str(pars.bpmdev(bpmind)));
  446. set(handles.radiobutton1,'Value',pars.doaxis(1));
  447. set(handles.radiobutton2,'Value',pars.doaxis(2));
  448. if ~isempty(pars.thisOffset)
  449. set(handles.text10,'String',sprintf('%.3g +/- %.3g',pars.thisOffset(1)*1e6,pars.thisOffset(2)*1e6));
  450. set(handles.text14,'String',sprintf('%.3g +/- %.3g',pars.thisOffset(3)*1e6,pars.thisOffset(4)*1e6));
  451. else
  452. set(handles.text10,'String','---');
  453. set(handles.text14,'String','---');
  454. end
  455. if ~isempty(pars.thisBpmMeas)
  456. set(handles.text12,'String',sprintf('%.3g +/- %.3g',pars.thisBpmMeas(1,pars.thisbpm)*1e6,pars.thisBpmMeas(2,pars.thisbpm)*1e6));
  457. set(handles.text15,'String',sprintf('%.3g +/- %.3g',pars.thisBpmMeas(3,pars.thisbpm)*1e6,pars.thisBpmMeas(4,pars.thisbpm)*1e6));
  458. else
  459. set(handles.text12,'String','---');
  460. set(handles.text15,'String','---');
  461. end
  462. set(handles.text4,'String',num2str(pars.bba_x(bpmind)*1e6))
  463. set(handles.text11,'String',datestr(pars.bbats_x(bpmind)))
  464. set(handles.text13,'String',num2str(pars.bba_y(bpmind)*1e6))
  465. set(handles.text17,'String',datestr(pars.bbats_y(bpmind)))
  466. drawnow('expose')
  467. % Get BPM selection
  468. popupmenu3_Callback(handles.popupmenu3,eventdata,handles);
  469. % --- Executes during object creation, after setting all properties.
  470. function popupmenu1_CreateFcn(hObject, eventdata, handles)
  471. % hObject handle to popupmenu1 (see GCBO)
  472. % eventdata reserved - to be defined in a future version of MATLAB
  473. % handles empty - handles not created until after all CreateFcns called
  474. % Hint: popupmenu controls usually have a white background on Windows.
  475. % See ISPC and COMPUTER.
  476. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  477. set(hObject,'BackgroundColor','white');
  478. end
  479. % --- Executes on selection change in popupmenu2.
  480. function popupmenu2_Callback(hObject, eventdata, handles)
  481. % hObject handle to popupmenu2 (see GCBO)
  482. % eventdata reserved - to be defined in a future version of MATLAB
  483. % handles structure with handles and user data (see GUIDATA)
  484. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
  485. % contents{get(hObject,'Value')} returns selected item from popupmenu2
  486. % --- Executes during object creation, after setting all properties.
  487. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  488. % hObject handle to popupmenu2 (see GCBO)
  489. % eventdata reserved - to be defined in a future version of MATLAB
  490. % handles empty - handles not created until after all CreateFcns called
  491. % Hint: popupmenu controls usually have a white background on Windows.
  492. % See ISPC and COMPUTER.
  493. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  494. set(hObject,'BackgroundColor','white');
  495. end
  496. % Max iter
  497. function edit5_Callback(hObject, eventdata, handles)
  498. % hObject handle to edit5 (see GCBO)
  499. % eventdata reserved - to be defined in a future version of MATLAB
  500. % handles structure with handles and user data (see GUIDATA)
  501. bpminstr=get(handles.popupmenu1,'UserData');
  502. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  503. val=floor(str2double(get(hObject,'String')));
  504. [stat pars]=bbaFn('GetPars');
  505. if isnan(val) || val<2
  506. set(hObject,'String',num2str(pars.defmaxiter));
  507. return
  508. end
  509. newpars.maxiter=pars.maxiter;
  510. if get(handles.togglebutton2,'Value')
  511. newpars.maxiter(:)=val;
  512. else
  513. newpars.maxiter(bpmind)=val;
  514. end
  515. bbaFn('SetPars',newpars);
  516. % --- Executes during object creation, after setting all properties.
  517. function edit5_CreateFcn(hObject, eventdata, handles)
  518. % hObject handle to edit5 (see GCBO)
  519. % eventdata reserved - to be defined in a future version of MATLAB
  520. % handles empty - handles not created until after all CreateFcns called
  521. % Hint: edit controls usually have a white background on Windows.
  522. % See ISPC and COMPUTER.
  523. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  524. set(hObject,'BackgroundColor','white');
  525. end
  526. % Stop Tol
  527. function edit4_Callback(hObject, eventdata, handles)
  528. % hObject handle to edit4 (see GCBO)
  529. % eventdata reserved - to be defined in a future version of MATLAB
  530. % handles structure with handles and user data (see GUIDATA)
  531. bpminstr=get(handles.popupmenu1,'UserData');
  532. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  533. val=str2double(get(hObject,'String'))*1e-6;
  534. [stat pars]=bbaFn('GetPars');
  535. if isnan(val) || val<=0
  536. set(hObject,'String',num2str(pars.deftol));
  537. return
  538. end
  539. newpars.tol=pars.tol;
  540. if get(handles.togglebutton2,'Value')
  541. newpars.tol(:)=val;
  542. else
  543. newpars.tol(bpmind)=val;
  544. end
  545. bbaFn('SetPars',newpars);
  546. % --- Executes during object creation, after setting all properties.
  547. function edit4_CreateFcn(hObject, eventdata, handles)
  548. % hObject handle to edit4 (see GCBO)
  549. % eventdata reserved - to be defined in a future version of MATLAB
  550. % handles empty - handles not created until after all CreateFcns called
  551. % Hint: edit controls usually have a white background on Windows.
  552. % See ISPC and COMPUTER.
  553. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  554. set(hObject,'BackgroundColor','white');
  555. end
  556. function edit6_Callback(hObject, eventdata, handles)
  557. % hObject handle to edit6 (see GCBO)
  558. % eventdata reserved - to be defined in a future version of MATLAB
  559. % handles structure with handles and user data (see GUIDATA)
  560. % Hints: get(hObject,'String') returns contents of edit6 as text
  561. % str2double(get(hObject,'String')) returns contents of edit6 as a double
  562. % --- Executes during object creation, after setting all properties.
  563. function edit6_CreateFcn(hObject, eventdata, handles)
  564. % hObject handle to edit6 (see GCBO)
  565. % eventdata reserved - to be defined in a future version of MATLAB
  566. % handles empty - handles not created until after all CreateFcns called
  567. % Hint: edit controls usually have a white background on Windows.
  568. % See ISPC and COMPUTER.
  569. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  570. set(hObject,'BackgroundColor','white');
  571. end
  572. % --- Accept
  573. function pushbutton10_Callback(hObject, eventdata, handles)
  574. % hObject handle to pushbutton10 (see GCBO)
  575. % eventdata reserved - to be defined in a future version of MATLAB
  576. % handles structure with handles and user data (see GUIDATA)
  577. uiresume(handles.figure1);
  578. % --- Reject
  579. function pushbutton11_Callback(hObject, eventdata, handles)
  580. % hObject handle to pushbutton11 (see GCBO)
  581. % eventdata reserved - to be defined in a future version of MATLAB
  582. % handles structure with handles and user data (see GUIDATA)
  583. uiresume(handles.figure1);
  584. % --- Auto Accept
  585. function togglebutton1_Callback(hObject, eventdata, handles)
  586. % hObject handle to togglebutton1 (see GCBO)
  587. % eventdata reserved - to be defined in a future version of MATLAB
  588. % handles structure with handles and user data (see GUIDATA)
  589. if get(hObject,'Value')
  590. set(hObject,'String','Auto Accept On');
  591. set(hObject,'BackgroundColor','green')
  592. else
  593. set(hObject,'String','Auto Accept Off');
  594. set(hObject,'BackgroundColor','red')
  595. end
  596. % --- Measure once
  597. function pushbutton12_Callback(hObject, eventdata, handles)
  598. % hObject handle to pushbutton12 (see GCBO)
  599. % eventdata reserved - to be defined in a future version of MATLAB
  600. % handles structure with handles and user data (see GUIDATA)
  601. set(handles.pushbutton2,'UserData','measureonce');
  602. newpars.measureonce=true;
  603. bbaFn('SetPars',newpars);
  604. pushbutton2_Callback(handles.pushbutton2,[],handles);
  605. newpars.measureonce=false;
  606. bbaFn('SetPars',newpars);
  607. if ~strcmpi(get(handles.pushbutton9,'String'),'error')
  608. popupmenu1_Callback(handles.popupmenu1,'noplot',handles);
  609. set(handles.text6,'String','Single Measurement Completed');
  610. end
  611. % --- Select X axis
  612. function radiobutton1_Callback(hObject, eventdata, handles)
  613. % hObject handle to radiobutton1 (see GCBO)
  614. % eventdata reserved - to be defined in a future version of MATLAB
  615. % handles structure with handles and user data (see GUIDATA)
  616. newpars.doaxis=[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  617. if ~any(newpars.doaxis)
  618. set(hObject,'Value',1);
  619. newpars.doaxis=[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  620. end
  621. bbaFn('SetPars',newpars);
  622. % --- Select Y axis
  623. function radiobutton2_Callback(hObject, eventdata, handles)
  624. % hObject handle to radiobutton2 (see GCBO)
  625. % eventdata reserved - to be defined in a future version of MATLAB
  626. % handles structure with handles and user data (see GUIDATA)
  627. newpars.doaxis=[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  628. if ~any(newpars.doaxis)
  629. set(hObject,'Value',1);
  630. newpars.doaxis=[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  631. end
  632. bbaFn('SetPars',newpars);
  633. % --- Reset y BBA setting
  634. function pushbutton13_Callback(hObject, eventdata, handles)
  635. % hObject handle to pushbutton13 (see GCBO)
  636. % eventdata reserved - to be defined in a future version of MATLAB
  637. % handles structure with handles and user data (see GUIDATA)
  638. bpminstr=get(handles.popupmenu1,'UserData');
  639. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  640. if ~strcmp(questdlg('Reset vertical BBA offset to zero (takes immediate effect)?','Reset BBA?'),'Yes')
  641. return
  642. end
  643. stat=bbaFn('CommitBBA',bpmind,'y',0);
  644. if stat{1}~=1
  645. set(handles.text6,['BBA commit error:\n' stat{2}]);
  646. set(handles.pushbutton9,'String','Error');
  647. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  648. return
  649. else
  650. set(handles.text6,'Y BBA setting reset to zero');
  651. popupmenu1_Callback(handles.popupmenu1,[],handles);
  652. end
  653. % --- Executes on button press in togglebutton2.
  654. function togglebutton2_Callback(hObject, eventdata, handles)
  655. % hObject handle to togglebutton2 (see GCBO)
  656. % eventdata reserved - to be defined in a future version of MATLAB
  657. % handles structure with handles and user data (see GUIDATA)
  658. if get(hObject,'Value')
  659. set(hObject,'String','Apply Settings to all BPMs');
  660. else
  661. set(hObject,'String','Apply Settings to just this BPM')
  662. end
  663. % dPS/PS
  664. function edit8_Callback(hObject, eventdata, handles)
  665. % hObject handle to edit8 (see GCBO)
  666. % eventdata reserved - to be defined in a future version of MATLAB
  667. % handles structure with handles and user data (see GUIDATA)
  668. bpminstr=get(handles.popupmenu1,'UserData');
  669. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  670. val=str2double(get(hObject,'String'));
  671. [stat pars]=bbaFn('GetPars');
  672. if isnan(val) || val<=0 || val >=100
  673. set(hObject,'String',num2str(pars.defdps*100));
  674. return
  675. end
  676. newpars.dps=pars.dps;
  677. if get(handles.togglebutton2,'Value')
  678. newpars.dps(:)=val/100;
  679. else
  680. newpars.dps(bpmind)=val/100;
  681. end
  682. bbaFn('SetPars',newpars);
  683. % --- Executes during object creation, after setting all properties.
  684. function edit8_CreateFcn(hObject, eventdata, handles)
  685. % hObject handle to edit8 (see GCBO)
  686. % eventdata reserved - to be defined in a future version of MATLAB
  687. % handles empty - handles not created until after all CreateFcns called
  688. % Hint: edit controls usually have a white background on Windows.
  689. % See ISPC and COMPUTER.
  690. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  691. set(hObject,'BackgroundColor','white');
  692. end
  693. % --- Commit x
  694. function pushbutton15_Callback(hObject, eventdata, handles)
  695. % hObject handle to pushbutton15 (see GCBO)
  696. % eventdata reserved - to be defined in a future version of MATLAB
  697. % handles structure with handles and user data (see GUIDATA)
  698. bpminstr=get(handles.popupmenu1,'UserData');
  699. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  700. [stat pars]=bbaFn('GetPars');
  701. if stat{1}~=1
  702. errordlg(stat{2},'bbaFn Error')
  703. return
  704. end
  705. % If within desired tolerence, call this zero offset
  706. if abs(pars.thisOffset(1)) < pars.tol(bpmind)
  707. pars.thisOffset(1)=0;
  708. end
  709. bbasetting_x=pars.bba_x(bpmind)+pars.thisOffset(1)-pars.thisBpmMeas(1,bpmind);
  710. if ~strcmp(questdlg(sprintf('Commit New BBA setting to EPICS Database (takes immediate effect)?\n Will submit current BBA + Current Measured Offset - Current Ave BPM = %s',...
  711. [num2str(bbasetting_x*1e6),' um']),'Submit BBA?'),'Yes')
  712. return
  713. end
  714. stat=bbaFn('CommitBBA',bpmind,'x',bbasetting_x);
  715. if stat{1}~=1
  716. set(handles.text6,'String',sprintf('BBA commit error:\n%s',stat{2}));
  717. set(handles.pushbutton9,'String','Error');
  718. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  719. return
  720. else
  721. set(handles.text6,'String','X BBA setting commited to EPICS database');
  722. popupmenu1_Callback(handles.popupmenu1,[],handles);
  723. end
  724. % --- Commit y
  725. function pushbutton16_Callback(hObject, eventdata, handles)
  726. % hObject handle to pushbutton16 (see GCBO)
  727. % eventdata reserved - to be defined in a future version of MATLAB
  728. % handles structure with handles and user data (see GUIDATA)
  729. bpminstr=get(handles.popupmenu1,'UserData');
  730. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  731. [stat pars]=bbaFn('GetPars');
  732. if stat{1}~=1
  733. errordlg(stat{2},'bbaFn Error')
  734. return
  735. end
  736. % If within desired tolerence, call this zero offset
  737. if abs(pars.thisOffset(3)) < pars.tol(bpmind)
  738. pars.thisOffset(3)=0;
  739. end
  740. bbasetting_y=pars.bba_y(bpmind)+pars.thisOffset(3)-pars.thisBpmMeas(3,bpmind);
  741. if ~strcmp(questdlg(sprintf('Commit New BBA setting to EPICS Database (takes immediate effect)?\n Will submit current BBA + Current Measured Offset - Current Ave BPM = %s',...
  742. [num2str(bbasetting_y*1e6),' um']),'Submit BBA?'),'Yes')
  743. return
  744. end
  745. stat=bbaFn('CommitBBA',bpmind,'y',bbasetting_y);
  746. if stat{1}~=1
  747. set(handles.text6,['BBA commit error:\n' stat{2}]);
  748. set(handles.pushbutton9,'String','Error');
  749. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  750. return
  751. else
  752. set(handles.text6,'Y BBA setting commited to EPICS database');
  753. popupmenu1_Callback(handles.popupmenu1,[],handles);
  754. end
  755. % --- Bump to zero offset
  756. function pushbutton17_Callback(hObject, eventdata, handles)
  757. % hObject handle to pushbutton17 (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. set(handles.text6,'String','Commanding bump to beam...');
  761. drawnow('expose');
  762. bpminstr=get(handles.popupmenu1,'UserData');
  763. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  764. [stat pars]=bbaFn('GetPars');
  765. if stat{1}~=1
  766. errordlg(stat{2},'bbaFn Error')
  767. return
  768. end
  769. if isfield(pars.bumpx{bpmind},'Value')
  770. bumpsetting=[pars.bumpx{bpmind}.Value pars.bumpy{bpmind}.Value] + ...
  771. [pars.thisOffset(1) pars.thisOffset(3)].*[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  772. else
  773. bumpsetting=[pars.thisOffset(1) pars.thisOffset(3)].*[get(handles.radiobutton1,'Value') get(handles.radiobutton2,'Value')];
  774. end
  775. stat=bbaFn('SetOffset',bpmind,bumpsetting);
  776. if stat{1}~=1
  777. set(handles.text6,'String',sprintf('BBA commit error:\n%s',stat{2}));
  778. set(handles.pushbutton9,'String','Error');
  779. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  780. return
  781. else
  782. popupmenu1_Callback(handles.popupmenu1,'noplot',handles);
  783. set(handles.text6,'String','Bump commanded to zero measure beam offset in magnet');
  784. end
  785. % --- Get Bump setting information and display
  786. function pushbutton18_Callback(hObject, eventdata, handles)
  787. % hObject handle to pushbutton18 (see GCBO)
  788. % eventdata reserved - to be defined in a future version of MATLAB
  789. % handles structure with handles and user data (see GUIDATA)
  790. % handles structure with handles and user data (see GUIDATA)
  791. global GIRDER PS %#ok<NUSED>
  792. bpminstr=get(handles.popupmenu1,'UserData');
  793. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  794. [stat pars]=bbaFn('GetPars');
  795. if stat{1}~=1
  796. errordlg(stat{2},'bbaFn Error')
  797. return
  798. end
  799. bumpnames=[]; bumpvals=[];
  800. if isempty(pars.bumpx{bpmind})
  801. bumpnames='?';
  802. bumpvals='?';
  803. bumprefvals='?';
  804. elseif isfield(pars.bumpx{bpmind},'gind')
  805. bumpnames=['GIRDER ',num2str(pars.bumpx{bpmind}.gind)];
  806. bumpvals=num2str(GIRDER{pars.bumpx{bpmind}.gind}.MoverSetPt(1)*1e6);
  807. bumprefvals=num2str(pars.bumpx_orig{bpmind}*1e6);
  808. else
  809. for ichan=1:length(pars.bumpx{bpmind}.Channel)
  810. bumpnames=[bumpnames ' ' pars.bumpx{bpmind}.Channel(ichan).Parameter];
  811. evalc(['val=',pars.bumpx{bpmind}.Channel(ichan).Parameter]);
  812. bumpvals=[bumpvals ' ' num2str(val*1e6)];
  813. end
  814. if ~isfield(pars,'bumpx_orig')
  815. set(handles.text6,'String','No bump computations made yet')
  816. return
  817. end
  818. bumprefvals=num2str(pars.bumpx_orig{bpmind}.*1e6);
  819. end
  820. str_x=sprintf('X:\nCurrent Bump Value (um): %g \nBump components: %s\nComponent Current Values: %s\nComponent Reference Values: %s\n',...
  821. pars.bumpx{bpmind}.Value*1e6,bumpnames,bumpvals,bumprefvals);
  822. bumpnames=[]; bumpvals=[];
  823. if isempty(pars.bumpy{bpmind})
  824. bumpnames='?';
  825. bumpvals='?';
  826. bumprefvals='?';
  827. elseif isfield(pars.bumpy{bpmind},'gind')
  828. bumpnames=['GIRDER ',num2str(pars.bumpy{bpmind}.gind)];
  829. bumpvals=num2str(GIRDER{pars.bumpy{bpmind}.gind}.MoverSetPt(1)*1e6);
  830. bumprefvals=num2str(pars.bumpy_orig{bpmind}*1e6);
  831. else
  832. for ichan=1:length(pars.bumpy{bpmind}.Channel)
  833. bumpnames=[bumpnames ' ' pars.bumpy{bpmind}.Channel(ichan).Parameter];
  834. evalc(['val=',pars.bumpy{bpmind}.Channel(ichan).Parameter]);
  835. bumpvals=[bumpvals ' ' num2str(val*1e6)];
  836. end
  837. bumprefvals=num2str(pars.bumpy_orig{bpmind}.*1e6);
  838. end
  839. str_y=sprintf('Y:\nCurrent Bump Value (um): %g \nBump components: %s\nComponent Current Values: %s\nComponent Reference Values: %s\n',...
  840. pars.bumpy{bpmind}.Value*1e6,bumpnames,bumpvals,bumprefvals);
  841. set(handles.text6,'String',[str_x str_y]);
  842. % --- Restore bump
  843. function pushbutton19_Callback(hObject, eventdata, handles)
  844. % hObject handle to pushbutton19 (see GCBO)
  845. % eventdata reserved - to be defined in a future version of MATLAB
  846. % handles structure with handles and user data (see GUIDATA)
  847. bpminstr=get(handles.popupmenu1,'UserData');
  848. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  849. stat=bbafn('restorebumps',bpmind);
  850. if stat{1}~=1
  851. set(handles.text6,'String',sprintf('Error returning bump to default value\n%s',stat{2}));
  852. set(handles.pushbutton9,'String','Error');
  853. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  854. else
  855. set(handles.text6,'String','Bump restored to default value');
  856. end
  857. % --- Executes on button press in pushbutton21.
  858. function pushbutton21_Callback(hObject, eventdata, handles)
  859. % hObject handle to pushbutton21 (see GCBO)
  860. % eventdata reserved - to be defined in a future version of MATLAB
  861. % handles structure with handles and user data (see GUIDATA)
  862. % --- Executes on button press in pushbutton22.
  863. function pushbutton22_Callback(hObject, eventdata, handles)
  864. % hObject handle to pushbutton22 (see GCBO)
  865. % eventdata reserved - to be defined in a future version of MATLAB
  866. % handles structure with handles and user data (see GUIDATA)
  867. function edit9_Callback(hObject, eventdata, handles)
  868. % hObject handle to edit9 (see GCBO)
  869. % eventdata reserved - to be defined in a future version of MATLAB
  870. % handles structure with handles and user data (see GUIDATA)
  871. val=str2double(get(hObject,'String'));
  872. if isnan(val) || val<0
  873. set(hObject,'String','0')
  874. end
  875. % --- Executes during object creation, after setting all properties.
  876. function edit9_CreateFcn(hObject, eventdata, handles)
  877. % hObject handle to edit9 (see GCBO)
  878. % eventdata reserved - to be defined in a future version of MATLAB
  879. % handles empty - handles not created until after all CreateFcns called
  880. % Hint: edit controls usually have a white background on Windows.
  881. % See ISPC and COMPUTER.
  882. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  883. set(hObject,'BackgroundColor','white');
  884. end
  885. function edit10_Callback(hObject, eventdata, handles)
  886. % hObject handle to edit10 (see GCBO)
  887. % eventdata reserved - to be defined in a future version of MATLAB
  888. % handles structure with handles and user data (see GUIDATA)
  889. % Hints: get(hObject,'String') returns contents of edit10 as text
  890. % str2double(get(hObject,'String')) returns contents of edit10 as a double
  891. % --- Executes during object creation, after setting all properties.
  892. function edit10_CreateFcn(hObject, eventdata, handles)
  893. % hObject handle to edit10 (see GCBO)
  894. % eventdata reserved - to be defined in a future version of MATLAB
  895. % handles empty - handles not created until after all CreateFcns called
  896. % Hint: edit controls usually have a white background on Windows.
  897. % See ISPC and COMPUTER.
  898. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  899. set(hObject,'BackgroundColor','white');
  900. end
  901. % --- Executes on button press in pushbutton20.
  902. function pushbutton20_Callback(hObject, eventdata, handles)
  903. % hObject handle to pushbutton20 (see GCBO)
  904. % eventdata reserved - to be defined in a future version of MATLAB
  905. % handles structure with handles and user data (see GUIDATA)
  906. function edit11_Callback(hObject, eventdata, handles)
  907. % hObject handle to edit11 (see GCBO)
  908. % eventdata reserved - to be defined in a future version of MATLAB
  909. % handles structure with handles and user data (see GUIDATA)
  910. val=str2double(get(hObject,'String'));
  911. if isnan(val) || val<0
  912. set(hObject,'String','0')
  913. end
  914. % --- Executes during object creation, after setting all properties.
  915. function edit11_CreateFcn(hObject, eventdata, handles)
  916. % hObject handle to edit11 (see GCBO)
  917. % eventdata reserved - to be defined in a future version of MATLAB
  918. % handles empty - handles not created until after all CreateFcns called
  919. % Hint: edit controls usually have a white background on Windows.
  920. % See ISPC and COMPUTER.
  921. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  922. set(hObject,'BackgroundColor','white');
  923. end
  924. % --- Increment bump
  925. function pushbutton23_Callback(hObject, eventdata, handles)
  926. % hObject handle to pushbutton23 (see GCBO)
  927. % eventdata reserved - to be defined in a future version of MATLAB
  928. % handles structure with handles and user data (see GUIDATA)
  929. bpminstr=get(handles.popupmenu1,'UserData');
  930. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  931. [stat pars]=bbaFn('GetPars');
  932. if stat{1}~=1
  933. errordlg(stat{2},'bbaFn Error')
  934. return
  935. end
  936. if ~isfield(pars.bumpx{bpmind},'Value')
  937. pars.bumpx{bpmind}.Value=0;
  938. end
  939. if ~isfield(pars.bumpy{bpmind},'Value')
  940. pars.bumpy{bpmind}.Value=0;
  941. end
  942. newval(1)=str2double(get(handles.edit9,'String')).*1e-6;
  943. newval(2)=str2double(get(handles.edit11,'String')).*1e-6;
  944. stat=bbaFn('setoffset',bpmind,...
  945. [pars.bumpx{bpmind}.Value pars.bumpy{bpmind}.Value]+newval);
  946. if stat{1}~=1
  947. set(handles.text6,'String',sprintf('Error setting new bump value\n%s',stat{2}));
  948. set(handles.pushbutton9,'String','Error');
  949. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  950. else
  951. set(handles.text6,'String','Bump setting completed');
  952. end
  953. % --- Reset Bump
  954. function pushbutton24_Callback(hObject, eventdata, handles)
  955. % hObject handle to pushbutton24 (see GCBO)
  956. % eventdata reserved - to be defined in a future version of MATLAB
  957. % handles structure with handles and user data (see GUIDATA)
  958. bpminstr=get(handles.popupmenu1,'UserData');
  959. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  960. stat=bbaFn('resetbumps',bpmind);
  961. if stat{1}~=1
  962. set(handles.text6,['Error resetting bunp reference\n',stat{2}]);
  963. set(handles.pushbutton9,'String','Error');
  964. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  965. else
  966. set(handles.text6,'Bump reference point reset to current location.');
  967. end
  968. % --- Executes on selection change in listbox1.
  969. function listbox1_Callback(hObject, eventdata, handles)
  970. % hObject handle to listbox1 (see GCBO)
  971. % eventdata reserved - to be defined in a future version of MATLAB
  972. % handles structure with handles and user data (see GUIDATA)
  973. % Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
  974. % contents{get(hObject,'Value')} returns selected item from listbox1
  975. % --- Executes during object creation, after setting all properties.
  976. function listbox1_CreateFcn(hObject, eventdata, handles)
  977. % hObject handle to listbox1 (see GCBO)
  978. % eventdata reserved - to be defined in a future version of MATLAB
  979. % handles empty - handles not created until after all CreateFcns called
  980. % Hint: listbox controls usually have a white background on Windows.
  981. % See ISPC and COMPUTER.
  982. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  983. set(hObject,'BackgroundColor','white');
  984. end
  985. % --- add to allowed list
  986. function pushbutton25_Callback(hObject, eventdata, handles)
  987. % hObject handle to pushbutton25 (see GCBO)
  988. % eventdata reserved - to be defined in a future version of MATLAB
  989. % handles structure with handles and user data (see GUIDATA)
  990. bpminstr=get(handles.popupmenu1,'UserData');
  991. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  992. axis=get(handles.popupmenu3,'Value');
  993. [stat pars]=bbaFn('GetPars');
  994. if stat{1}~=1
  995. errordlg(stat{2},'bbaFn Error')
  996. return
  997. end
  998. % Get INSTR ind of selected bpms
  999. bpmlist=get(handles.listbox2,'String');
  1000. bpmsel=get(handles.listbox2,'Value');
  1001. bpminst=arrayfun(@(x) str2double(regexp(bpmlist{x},'\d+','match','once')),bpmsel);
  1002. pars.ignorebpm{axis,bpmind}(bpminst(~isnan(bpminst)))=false;
  1003. newpars.ignorebpm=pars.ignorebpm;
  1004. stat=bbaFn('SetPars',newpars);
  1005. if stat{1}~=1
  1006. errordlg(stat{2},'bbaFn Error')
  1007. return
  1008. end
  1009. % Update displays
  1010. popupmenu3_Callback(handles.popupmenu3,eventdata,handles);
  1011. % BPM selection cut criteria
  1012. function edit12_Callback(hObject, eventdata, handles)
  1013. % hObject handle to edit12 (see GCBO)
  1014. % eventdata reserved - to be defined in a future version of MATLAB
  1015. % handles structure with handles and user data (see GUIDATA)
  1016. bpminstr=get(handles.popupmenu1,'UserData');
  1017. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  1018. [stat pars]=bbaFn('GetPars');
  1019. if stat{1}~=1
  1020. errordlg(stat{2},'bbaFn Error')
  1021. return
  1022. end
  1023. val=str2double(get(hObject,'String'));
  1024. if isnan(val) || val<=0
  1025. set(hObject,'String',num2str(pars.defbpmdev))
  1026. return
  1027. end
  1028. newpars.bpmdev=pars.bpmdev;
  1029. if get(handles.togglebutton2,'Value')
  1030. newpars.bpmdev(:)=val;
  1031. else
  1032. newpars.bpmdev(bpmind)=val;
  1033. end
  1034. stat=bbaFn('SetPars',newpars);
  1035. if stat{1}~=1
  1036. errordlg(stat{2},'bbaFn Error')
  1037. return
  1038. end
  1039. popupmenu3_Callback(handles.popupmenu3,[],handles);
  1040. % --- Executes during object creation, after setting all properties.
  1041. function edit12_CreateFcn(hObject, eventdata, handles)
  1042. % hObject handle to edit12 (see GCBO)
  1043. % eventdata reserved - to be defined in a future version of MATLAB
  1044. % handles empty - handles not created until after all CreateFcns called
  1045. % Hint: edit controls usually have a white background on Windows.
  1046. % See ISPC and COMPUTER.
  1047. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1048. set(hObject,'BackgroundColor','white');
  1049. end
  1050. % --- Apply BPM selection cut
  1051. function pushbutton26_Callback(hObject, eventdata, handles)
  1052. % hObject handle to pushbutton26 (see GCBO)
  1053. % eventdata reserved - to be defined in a future version of MATLAB
  1054. % handles structure with handles and user data (see GUIDATA)
  1055. %Just need to re-show BPM selections
  1056. popupmenu3_Callback(handles.popupmenu3,eventdata,handles);
  1057. % --- Select axis for displaying BPM selections
  1058. function popupmenu3_Callback(hObject, eventdata, handles)
  1059. % hObject handle to popupmenu3 (see GCBO)
  1060. % eventdata reserved - to be defined in a future version of MATLAB
  1061. % handles structure with handles and user data (see GUIDATA)
  1062. global BEAMLINE INSTR
  1063. persistent lastval
  1064. set(handles.text6,'String','')
  1065. % BPM index
  1066. if ~isempty(lastval) && ~get(hObject,'Value')
  1067. set(hObject,'Value',lastval);
  1068. end
  1069. lastval=get(hObject,'Value');
  1070. bpminstr=get(handles.popupmenu1,'UserData');
  1071. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  1072. % get bpm data
  1073. [stat bpms expsig]=bbaFn('BpmSel',bpmind);
  1074. if stat{1}~=1
  1075. errordlg(stat{2},'bbaFn Error')
  1076. return
  1077. end
  1078. axis=get(hObject,'Value');
  1079. % Check if any BPMs pass the cuts
  1080. if ~any(bpms(axis,:))
  1081. set(handles.text6,'String','No BPMs pass the selection cuts!');
  1082. set(handles.pushbutton9,'String','Error');
  1083. set(handles.pushbutton9,'BackgroundColor',[1 0.5 0]);
  1084. drawnow('expose');
  1085. return
  1086. end
  1087. % Form used bpm string
  1088. str={};
  1089. for ibpm=find(bpms(axis,:))
  1090. str{end+1}=sprintf('%4d: %13s | %9.4f | %6.2f',ibpm,BEAMLINE{INSTR{ibpm}.Index}.Name,...
  1091. INSTR{ibpm}.Res*1e6,expsig(axis,ibpm)*1e6);
  1092. end
  1093. set(handles.listbox1,'Value',1);
  1094. set(handles.listbox1,'String',str);
  1095. [stat pars]=bbaFn('GetPars');
  1096. % Form disused bpm string
  1097. str={};
  1098. badbpms=find(~bpms(axis,:));
  1099. for ibpm=badbpms(ismember(badbpms,pars.allowedbpms)&badbpms>bpmind)
  1100. str{end+1}=sprintf('%4d: %13s | %9.4f | %6.2f',ibpm,BEAMLINE{INSTR{ibpm}.Index}.Name,...
  1101. INSTR{ibpm}.Res*1e6,expsig(axis,ibpm)*1e6);
  1102. end
  1103. set(handles.listbox2,'Value',1);
  1104. set(handles.listbox2,'String',str);
  1105. if ~isequal(eventdata,'noplot')
  1106. plot(handles.axes1,find(bpms(axis,:)),expsig(axis,find(bpms(axis,:))).*1e6,'*','linewidth',4) %#ok<FNDSB>
  1107. xlabel(handles.axes1,'INSTR ID')
  1108. ylabel(handles.axes1,'Expected BPM signal / um')
  1109. grid(handles.axes1,'on')
  1110. end
  1111. if axis==1
  1112. set(handles.radiobutton3,'Value',1)
  1113. set(handles.radiobutton4,'Value',0)
  1114. else
  1115. set(handles.radiobutton3,'Value',0)
  1116. set(handles.radiobutton4,'Value',1)
  1117. end
  1118. %%
  1119. % --- Executes during object creation, after setting all properties.
  1120. function popupmenu3_CreateFcn(hObject, eventdata, handles)
  1121. % hObject handle to popupmenu3 (see GCBO)
  1122. % eventdata reserved - to be defined in a future version of MATLAB
  1123. % handles empty - handles not created until after all CreateFcns called
  1124. % Hint: popupmenu controls usually have a white background on Windows.
  1125. % See ISPC and COMPUTER.
  1126. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1127. set(hObject,'BackgroundColor','white');
  1128. end
  1129. % --- Executes on selection change in listbox2.
  1130. function listbox2_Callback(hObject, eventdata, handles)
  1131. % hObject handle to listbox2 (see GCBO)
  1132. % eventdata reserved - to be defined in a future version of MATLAB
  1133. % handles structure with handles and user data (see GUIDATA)
  1134. % Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array
  1135. % contents{get(hObject,'Value')} returns selected item from listbox2
  1136. % --- Executes during object creation, after setting all properties.
  1137. function listbox2_CreateFcn(hObject, eventdata, handles)
  1138. % hObject handle to listbox2 (see GCBO)
  1139. % eventdata reserved - to be defined in a future version of MATLAB
  1140. % handles empty - handles not created until after all CreateFcns called
  1141. % Hint: listbox controls usually have a white background on Windows.
  1142. % See ISPC and COMPUTER.
  1143. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1144. set(hObject,'BackgroundColor','white');
  1145. end
  1146. % --- Disable bpm
  1147. function pushbutton27_Callback(hObject, eventdata, handles)
  1148. % hObject handle to pushbutton27 (see GCBO)
  1149. % eventdata reserved - to be defined in a future version of MATLAB
  1150. % handles structure with handles and user data (see GUIDATA)
  1151. bpminstr=get(handles.popupmenu1,'UserData');
  1152. bpmind=bpminstr(get(handles.popupmenu1,'Value'));
  1153. axis=get(handles.popupmenu3,'Value');
  1154. [stat pars]=bbaFn('GetPars');
  1155. if stat{1}~=1
  1156. errordlg(stat{2},'bbaFn Error')
  1157. return
  1158. end
  1159. % Get INSTR ind of selected bpms
  1160. bpmlist=get(handles.listbox1,'String');
  1161. bpmsel=get(handles.listbox1,'Value');
  1162. bpminst=arrayfun(@(x) str2double(regexp(bpmlist{x},'\d+','match','once')),bpmsel);
  1163. pars.ignorebpm{axis,bpmind}(bpminst(~isnan(bpminst)))=true;
  1164. newpars.ignorebpm=pars.ignorebpm;
  1165. stat=bbaFn('SetPars',newpars);
  1166. if stat{1}~=1
  1167. errordlg(stat{2},'bbaFn Error')
  1168. return
  1169. end
  1170. % Update displays
  1171. popupmenu3_Callback(handles.popupmenu3,eventdata,handles);
  1172. % --- Executes on selection change in popupmenu4.
  1173. function popupmenu4_Callback(hObject, eventdata, handles)
  1174. % hObject handle to popupmenu4 (see GCBO)
  1175. % eventdata reserved - to be defined in a future version of MATLAB
  1176. % handles structure with handles and user data (see GUIDATA)
  1177. % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
  1178. % contents{get(hObject,'Value')} returns selected item from popupmenu4
  1179. % --- Executes during object creation, after setting all properties.
  1180. function popupmenu4_CreateFcn(hObject, eventdata, handles)
  1181. % hObject handle to popupmenu4 (see GCBO)
  1182. % eventdata reserved - to be defined in a future version of MATLAB
  1183. % handles empty - handles not created until after all CreateFcns called
  1184. % Hint: popupmenu controls usually have a white background on Windows.
  1185. % See ISPC and COMPUTER.
  1186. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1187. set(hObject,'BackgroundColor','white');
  1188. end
  1189. % --- Executes on button press in pushbutton28.
  1190. function pushbutton28_Callback(hObject, eventdata, handles)
  1191. % hObject handle to pushbutton28 (see GCBO)
  1192. % eventdata reserved - to be defined in a future version of MATLAB
  1193. % handles structure with handles and user data (see GUIDATA)
  1194. % --- Executes on button press in pushbutton29.
  1195. function

Large files files are truncated, but you can click here to view the full file