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

/ATF2/FlightSim/testApps/lattice_check/lattice_check.m

http://atf2flightsim.googlecode.com/
MATLAB | 1621 lines | 1122 code | 255 blank | 244 comment | 206 complexity | d849df3be1e5bfbee8036ff382b5cec3 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 = lattice_check(varargin)
  2. % LATTICE_CHECK M-file for lattice_check.fig
  3. % LATTICE_CHECK, by itself, creates a new LATTICE_CHECK or raises the existing
  4. % singleton*.
  5. %
  6. % H = LATTICE_CHECK returns the handle to a new LATTICE_CHECK or the handle to
  7. % the existing singleton*.
  8. %
  9. % LATTICE_CHECK('CALLBACK',hObject,eventData,handles,...) calls the
  10. % local
  11. % function named CALLBACK in LATTICE_CHECK.M with the given input arguments.
  12. %
  13. % LATTICE_CHECK('Property','Value',...) creates a new LATTICE_CHECK or raises the
  14. % existing singleton*. Starting from the left, property value pairs are
  15. % applied to the GUI before lattice_check_OpeningFcn gets called. An
  16. % unrecognized property name or invalid value makes property application
  17. % stop. All inputs are passed to lattice_check_OpeningFcn via varargin.
  18. %
  19. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  20. % instance to run (singleton)".
  21. %
  22. % See also: GUIDE, GUIDATA, GUIHANDLES
  23. % Edit the above text to modify the response to help lattice_check
  24. % Last Modified by GUIDE v2.5 09-Dec-2008 09:31:29
  25. % Begin initialization code - DO NOT EDIT
  26. gui_Singleton = 1;
  27. gui_State = struct('gui_Name', mfilename, ...
  28. 'gui_Singleton', gui_Singleton, ...
  29. 'gui_OpeningFcn', @lattice_check_OpeningFcn, ...
  30. 'gui_OutputFcn', @lattice_check_OutputFcn, ...
  31. 'gui_LayoutFcn', [] , ...
  32. 'gui_Callback', []);
  33. if nargin && ischar(varargin{1})
  34. gui_State.gui_Callback = str2func(varargin{1});
  35. end
  36. if nargout
  37. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  38. else
  39. gui_mainfcn(gui_State, varargin{:});
  40. end
  41. % End initialization code - DO NOT EDIT
  42. % --- Executes just before lattice_check is made visible.
  43. function lattice_check_OpeningFcn(hObject, eventdata, handles, varargin)
  44. % This function has no output args, see OutputFcn.
  45. % hObject handle to figure
  46. % eventdata reserved - to be defined in a future version of MATLAB
  47. % handles structure with handles and user data (see GUIDATA)
  48. % varargin command line arguments to lattice_check (see VARARGIN)
  49. % Choose default command line output for lattice_check
  50. handles.output = hObject;
  51. % Update handles structure
  52. guidata(hObject, handles);
  53. % UIWAIT makes lattice_check wait for user response (see UIRESUME)
  54. % uiwait(handles.figure1);
  55. global LC_GUIDATA BEAMLINE INSTR GIRDER
  56. % Detects the user pressing the cancel button
  57. LC_GUIDATA.iscancelled = false;
  58. % Fill the "region" list -- ext, ff, all, etc.
  59. list = get(handles.region_menu,'String');
  60. select = get(handles.region_menu,'Value');
  61. LC_GUIDATA.region = list{select};
  62. % Fills the "magnet selection" list -- which magnets to scan
  63. list = get(handles.magselect_menu,'String');
  64. select = get(handles.magselect_menu,'Value');
  65. LC_GUIDATA.magselect = list{select};
  66. % Default kick size
  67. LC_GUIDATA.kicksize = str2double(get(handles.kicksize_edit,'String'));
  68. LC_GUIDATA.moversize = 0.5;
  69. % Number of averages to do
  70. LC_GUIDATA.ave_edit = str2double(get(handles.ave_edit,'String'));
  71. % Find the start and end of each of the regions and a list of the
  72. % correctors in those regions
  73. LC_GUIDATA.ringend = findcells(BEAMLINE,'Name','IEX');
  74. LC_GUIDATA.ringend = LC_GUIDATA.ringend(end);
  75. LC_GUIDATA.extff = findcells(BEAMLINE,'Name','BEGFF');
  76. LC_GUIDATA.xcorinds = findcells(BEAMLINE,'Class','XCOR');
  77. LC_GUIDATA.xcorinds = ...
  78. LC_GUIDATA.xcorinds(LC_GUIDATA.xcorinds>LC_GUIDATA.ringend);
  79. LC_GUIDATA.ycorinds = findcells(BEAMLINE,'Class','YCOR');
  80. LC_GUIDATA.ycorinds = ...
  81. LC_GUIDATA.ycorinds(LC_GUIDATA.ycorinds>LC_GUIDATA.ringend);
  82. % Find all girders on a mover
  83. xmover_ind = [];
  84. ymover_ind = [];
  85. xmover_S = [];
  86. ymover_S = [];
  87. for gnum = 1:length(GIRDER)
  88. if ~isfield(GIRDER{gnum},'Mover')
  89. continue
  90. end
  91. for dof = GIRDER{gnum}.Mover
  92. if dof == 1
  93. xmover_ind = [xmover_ind gnum]; %#ok<AGROW>
  94. xmover_S = [xmover_S GIRDER{gnum}.S(1)]; %#ok<AGROW>
  95. elseif dof == 3
  96. ymover_ind = [ymover_ind gnum]; %#ok<AGROW>
  97. ymover_S = [ymover_S GIRDER{gnum}.S(1)]; %#ok<AGROW>
  98. end
  99. end
  100. end
  101. % Set the names of these girders by the quad/sext name
  102. count = 0;
  103. for mnum=xmover_ind
  104. for elenum = GIRDER{mnum}.Element
  105. if strcmpi(BEAMLINE{elenum}.Class,'QUAD')
  106. count = count + 1;
  107. LC_GUIDATA.xmover_name{count} = [BEAMLINE{elenum}.Name '_x'];
  108. LC_GUIDATA.xmover_ind{count} = mnum;
  109. LC_GUIDATA.xmover_S{count} = GIRDER{mnum}.S;
  110. break
  111. end
  112. end
  113. end
  114. count = 0;
  115. for mnum=ymover_ind
  116. for elenum = GIRDER{mnum}.Element
  117. if strcmpi(BEAMLINE{elenum}.Class,'QUAD')
  118. count = count + 1;
  119. LC_GUIDATA.ymover_name{count} = [BEAMLINE{elenum}.Name '_y'];
  120. LC_GUIDATA.ymover_ind{count} = mnum;
  121. LC_GUIDATA.ymover_S{count} = GIRDER{mnum}.S;
  122. break
  123. end
  124. end
  125. end
  126. % First bpm in the extraction line
  127. bpminds = findcells(BEAMLINE,'Class','MONI');
  128. bpminds = bpminds(bpminds>LC_GUIDATA.ringend);
  129. LC_GUIDATA.firstbpm = findcells(INSTR,'Index',bpminds(1));
  130. % --- Outputs from this function are returned to the command line.
  131. function varargout = lattice_check_OutputFcn(hObject, eventdata, handles)
  132. % varargout cell array for returning output args (see VARARGOUT);
  133. % hObject handle to figure
  134. % eventdata reserved - to be defined in a future version of MATLAB
  135. % handles structure with handles and user data (see GUIDATA)
  136. % Get default command line output from handles structure
  137. varargout{1} = handles;
  138. varargout{2} = hObject;
  139. % --- Executes on button press in start_button.
  140. function start_button_Callback(hObject, eventdata, handles)
  141. % hObject handle to start_button (see GCBO)
  142. % eventdata reserved - to be defined in a future version of MATLAB
  143. % handles structure with handles and user data (see GUIDATA)
  144. global LC_GUIDATA BEAMLINE PS FL GIRDER
  145. % Set the start button colour and message
  146. set(hObject,'BackgroundColor',[1 0 0])
  147. set(hObject,'String','RUNNING!')
  148. % Disable other front panel buttons to avoid confusion
  149. set(hObject,'Enable','inactive')
  150. set(handles.plot_pushbutton,'Enable','inactive')
  151. set(handles.save_button,'Enable','inactive')
  152. set(handles.load_button,'Enable','inactive')
  153. set(handles.region_menu,'Enable','inactive')
  154. set(handles.magselect_menu,'Enable','inactive')
  155. set(handles.devicetype_menu,'Enable','inactive')
  156. set(handles.ave_edit,'Enable','inactive')
  157. set(handles.kicksize_edit,'Enable','inactive')
  158. % Enable the cancel button and change its colour
  159. set(handles.cancel_button,'Enable','on')
  160. set(handles.cancel_button,'BackgroundColor',[1 0 0])
  161. % Cors or movers
  162. devtype_contents = get(handles.devicetype_menu,'String');
  163. devtype_choice = devtype_contents{get(handles.devicetype_menu,'Value')};
  164. if strcmpi(devtype_choice,'Movers')
  165. movers = true;
  166. else
  167. movers = false;
  168. end
  169. % Single particle beam
  170. beamin = FL.SimBeam{2};
  171. % May be calculating bumps, so add this routine to the path
  172. if ~isdeployed
  173. addpath testApps/bumpgui;
  174. end
  175. % Scale the kick from m.rad to rad.
  176. mradkick = str2double(get(handles.kicksize_edit,'String'))/1e3;
  177. % Get the list of correctors from the input box
  178. corlist = get(handles.maglistbox,'String');
  179. % Convert this to a cell array if necessary
  180. if ~iscell(corlist)
  181. temp{1} = corlist;
  182. clear corlist
  183. corlist = temp;
  184. end
  185. % If this cell array is empty, then we have an error. Reset the front
  186. % panel buttons and exit.
  187. if (strcmpi(corlist{1},'Empty ...') || strcmpi(corlist{1},'none'))
  188. errordlg('No magnets selected.','No magnets')
  189. set(hObject,'BackgroundColor',[0 1 0])
  190. set(hObject,'String','START!')
  191. set(hObject,'Enable','on')
  192. set(handles.plot_pushbutton,'Enable','on')
  193. set(handles.save_button,'Enable','on')
  194. set(handles.load_button,'Enable','on')
  195. set(handles.region_menu,'Enable','on')
  196. set(handles.magselect_menu,'Enable','on')
  197. set(handles.devicetype_menu,'Enable','on')
  198. set(handles.ave_edit,'Enable','on')
  199. set(handles.kicksize_edit,'Enable','on')
  200. set(handles.cancel_button,'Enable','off')
  201. set(handles.cancel_button,'BackgroundColor',[0.502 0.502 0.502])
  202. return
  203. end
  204. % Get the name of the region we're investigating
  205. region_contents = get(handles.region_menu,'String');
  206. region_choice = region_contents{get(handles.region_menu,'Value')};
  207. % Get the contents of the magnet select drop down menu
  208. mag_contents = get(handles.magselect_menu,'String');
  209. mag_choice = mag_contents{get(handles.magselect_menu,'Value')};
  210. % Figure out if we'll be closing bumps, and, if so, which correctors we'll
  211. % be using to do that. This is all based on the region and correctors
  212. % selection.
  213. if ~movers
  214. if strcmpi(region_choice,'Extraction Line')
  215. close_bumps = true;
  216. final_xcors = [findcells(BEAMLINE,'Name','ZH10X') ...
  217. findcells(BEAMLINE,'Name','ZH1FF')];
  218. final_ycors = [findcells(BEAMLINE,'Name','ZV11X') ...
  219. findcells(BEAMLINE,'Name','ZV1FF')];
  220. if strncmpi(mag_choice,'All',3)
  221. elseif ( sum(strcmpi(corlist,'ZH9X')) || sum(strcmpi(corlist,'ZH10X')) || ...
  222. sum(strcmpi(corlist,'ZV10X')) || sum(strcmpi(corlist,'ZV11X')) )
  223. close_bumps = false;
  224. end
  225. elseif strcmpi(region_choice,'Final Focus')
  226. close_bumps = false;
  227. elseif strcmpi(region_choice,'All')
  228. close_bumps = true;
  229. final_xcors = [findcells(BEAMLINE,'Name','ZH10X') ...
  230. findcells(BEAMLINE,'Name','ZH1FF')];
  231. final_ycors = [findcells(BEAMLINE,'Name','ZV11X') ...
  232. findcells(BEAMLINE,'Name','ZV1FF')];
  233. else
  234. error('Something''s gone terribly wrong :S')
  235. end
  236. end
  237. % Find the PSs/GIRDERs used to control our devices
  238. if movers
  239. cor_ps = zeros(1,length(corlist));
  240. mover_girder = zeros(1,length(corlist));
  241. mover_plane = cell(1,length(corlist));
  242. for movernum = 1:length(corlist)
  243. l = length(corlist{movernum});
  244. magname = corlist{movernum}(1:(l-2));
  245. eleind = findcells(BEAMLINE,'Name',magname);
  246. mover_girder(movernum) = BEAMLINE{eleind(1)}.Girder;
  247. mover_plane{movernum} = corlist{movernum}(end);
  248. end
  249. else
  250. cor_ps = zeros(1,length(corlist));
  251. for cornum=1:length(corlist)
  252. corind(cornum) = findcells(BEAMLINE,'Name',corlist{cornum}); %#ok<AGROW>
  253. cor_ps(cornum) = BEAMLINE{corind(cornum)}.PS;
  254. end
  255. end
  256. % Clear the current plots
  257. for plotnum=1:4
  258. plothand = subplot(2,2,plotnum,'Parent',handles.measdata_panel);
  259. cla(plothand)
  260. plothand = subplot(2,2,plotnum,'Parent',handles.preddata_panel);
  261. cla(plothand)
  262. end
  263. plothand = subplot(1,1,1,'Parent',handles.diffdx_panel);
  264. cla(plothand)
  265. plothand = subplot(1,1,1,'Parent',handles.diffdy_panel);
  266. cla(plothand)
  267. % MAIN LOOP!
  268. % Loop around our correctors and do what we need to do
  269. for cornum=1:length(cor_ps)
  270. if (strcmpi(corlist{cornum},'ZX2X') || ...
  271. strcmpi(corlist{cornum},'ZX3X') )
  272. continue
  273. end
  274. % Report the status in the start button string
  275. set(hObject,'String',[corlist{cornum} ' baseline data'])
  276. disp(corlist{cornum}) % Also report to the cli
  277. % Request access for the correctors we need (closing bumps or not)
  278. if movers
  279. stat = AccessRequest({mover_girder(cornum),[],[]});
  280. if stat{1}~=1; error(stat{2}); end
  281. else
  282. if close_bumps
  283. if strcmpi(BEAMLINE{corind(cornum)}.Class,'XCOR')
  284. knob = bumpgui(2,3,corind(cornum),[corind(cornum) final_xcors]);
  285. stat = AccessRequest({[],...
  286. [knob.Channel(1).Unit ...
  287. knob.Channel(2).Unit ...
  288. knob.Channel(3).Unit],...
  289. []});
  290. if stat{1}~=1; error(stat{2}); end
  291. elseif strcmpi(BEAMLINE{corind(cornum)}.Class,'YCOR')
  292. knob = bumpgui(4,3,corind(cornum),[corind(cornum) final_ycors]);
  293. stat = AccessRequest({[],...
  294. [knob.Channel(1).Unit ...
  295. knob.Channel(2).Unit ...
  296. knob.Channel(3).Unit],...
  297. []});
  298. if stat{1}~=1; error(stat{2}); end
  299. else
  300. error('Something''s not right :(')
  301. end
  302. else
  303. stat = AccessRequest({[],cor_ps(cornum),[]});
  304. if stat{1}~=1; error(stat{2}); end
  305. end
  306. end
  307. % Call FlHwUpdate to synch with the server, then grab the data for the
  308. % un-kicked (nominal position) beam.
  309. FlHwUpdate;
  310. [stat output] = FlHwUpdate('bpmave',LC_GUIDATA.ave_edit);
  311. if stat{1}~=1; error(stat{2}); end
  312. [stat instdata] = FlTrackThru(1,length(BEAMLINE),output);
  313. if stat{1}~=1; error(stat{2}); end
  314. % Sort the data into seperate arrays
  315. orig_x = [instdata{1}.x]; orig_x = orig_x(LC_GUIDATA.firstbpm:end);
  316. orig_y = [instdata{1}.y]; orig_y = orig_y(LC_GUIDATA.firstbpm:end);
  317. orig_S = [instdata{1}.S]; orig_S = orig_S(LC_GUIDATA.firstbpm:end);
  318. % Set the bpmS field of LC_GUIDATA
  319. LC_GUIDATA.bpmS = orig_S;
  320. % Looping over the number of averages, calculate the predicted position
  321. % of the beam. It shouldn't be necessary to average, but the finite
  322. % BPM resolution in BEAMLINE forces this. This needs to be fixed.
  323. for pulsenum=1:LC_GUIDATA.ave_edit
  324. [stat beamout instdata] = TrackThru(1,length(BEAMLINE),beamin,1,1);
  325. inds = [instdata{1}.Index];
  326. inds = find(inds>LC_GUIDATA.ringend);
  327. if pulsenum==1
  328. pred_orig_x = [instdata{1}.x];
  329. pred_orig_y = [instdata{1}.y];
  330. end
  331. pred_orig_x = pred_orig_x + [instdata{1}.x];
  332. pred_orig_y = pred_orig_y + [instdata{1}.y];
  333. end
  334. pred_orig_x = pred_orig_x(inds) / LC_GUIDATA.ave_edit;
  335. pred_orig_y = pred_orig_y(inds) / LC_GUIDATA.ave_edit;
  336. pred_orig_S = [instdata{1}.S];
  337. % Set aside some memory for the pred-meas matrix
  338. if ~exist('xdiff_mat','var')
  339. xdiff_mat = zeros(length(cor_ps),length(orig_x));
  340. ydiff_mat = zeros(length(cor_ps),length(orig_x));
  341. xdiff_pred_mat = zeros(length(cor_ps),length(orig_x));
  342. ydiff_pred_mat = zeros(length(cor_ps),length(orig_x));
  343. end
  344. % Plot the data!
  345. plothand = subplot(2,2,1,'Parent',handles.measdata_panel);
  346. plot(plothand,orig_S,orig_x*1e3,'bx')
  347. xlim(plothand,[orig_S(1) orig_S(end)])
  348. title(plothand,[strrep(corlist{cornum},'_','\_') ' x'])
  349. ylabel(plothand,'x / mm')
  350. xlabel(plothand,'S / m')
  351. hold(plothand,'on')
  352. plothand = subplot(2,2,2,'Parent',handles.measdata_panel);
  353. plot(plothand,orig_S,orig_y*1e3,'bx')
  354. xlim(plothand,[orig_S(1) orig_S(end)])
  355. title(plothand,[strrep(corlist{cornum},'_','\_') ' y'])
  356. ylabel(plothand,'y / mm')
  357. xlabel(plothand,'S / m')
  358. hold(plothand,'on')
  359. plothand = subplot(2,2,1,'Parent',handles.preddata_panel);
  360. plot(plothand,orig_S,pred_orig_x*1e3,'bx')
  361. xlim(plothand,[orig_S(1) orig_S(end)])
  362. title(plothand,[strrep(corlist{cornum},'_','\_') ' x'])
  363. ylabel(plothand,'x / mm')
  364. xlabel(plothand,'S / m')
  365. hold(plothand,'on')
  366. plothand = subplot(2,2,2,'Parent',handles.preddata_panel);
  367. plot(plothand,orig_S,pred_orig_y*1e3,'bx')
  368. xlim(plothand,[orig_S(1) orig_S(end)])
  369. title(plothand,[strrep(corlist{cornum},'_','\_') ' y'])
  370. ylabel(plothand,'y / mm')
  371. xlabel(plothand,'S / m')
  372. hold(plothand,'on')
  373. % Report the status in the start button string
  374. set(hObject,'String',[strrep(corlist{cornum},'_','\_') ' kicked data'])
  375. % Kick the beam
  376. if movers
  377. if strcmpi(mover_plane{cornum},'x')
  378. plane = 1;
  379. elseif strcmpi(mover_plane{cornum},'y')
  380. plane = 3;
  381. else
  382. error('Something''s really not right :(')
  383. end
  384. for loop=1:length(GIRDER{mover_girder(cornum)}.Mover)
  385. if GIRDER{mover_girder(cornum)}.Mover(loop) == plane;
  386. ind = loop;
  387. break
  388. end
  389. end
  390. curr_moverpos = GIRDER{mover_girder(cornum)}.MoverSetPt(ind);
  391. GIRDER{mover_girder(cornum)}.MoverSetPt(ind) = curr_moverpos + mradkick;
  392. stat = MoverTrim(mover_girder(cornum), true);
  393. if stat{1}~=1; error(stat{2}); end
  394. else
  395. if close_bumps && ...
  396. ~(strcmp(corlist{cornum},'ZV11X') || strcmp(corlist{cornum},'ZV1FF') || ...
  397. strcmp(corlist{cornum},'ZH10X') || strcmp(corlist{cornum},'ZH1FF'))
  398. stat = SetMultiKnob('knob',mradkick,true);
  399. if stat{1}~=1; error(stat{2}); end
  400. else
  401. curr_psval = PS(cor_ps(cornum)).SetPt;
  402. PS(cor_ps(cornum)).SetPt = curr_psval + mradkick;
  403. PSTrim(cor_ps(cornum), true);
  404. end
  405. end
  406. % Synch with the server
  407. FlHwUpdate;
  408. % Determine the pulse number of the most recent reading
  409. [stat output] = FlHwUpdate('readbuffer',1);
  410. if stat{1}~=1; error(stat{2}); end
  411. lastpulse = output(end,1);
  412. % Pause for enough time for the number of requested averages to occur
  413. pause(LC_GUIDATA.ave_edit/1.56)
  414. % Keep looping until we're sure that we will only be averaging pulses
  415. % from *after* the kick
  416. [stat output] = FlHwUpdate('readbuffer',1);
  417. currpulse = output(end,1);
  418. while currpulse-lastpulse < LC_GUIDATA.ave_edit
  419. pause(1)
  420. [stat output] = FlHwUpdate('readbuffer',1);
  421. if stat{1}~=1; error(stat{2}); end
  422. currpulse = output(end,1);
  423. end
  424. % Grab the data
  425. [stat output] = FlHwUpdate('bpmave',LC_GUIDATA.ave_edit);
  426. if stat{1}~=1; error(stat{2}); end
  427. [stat instdata] = FlTrackThru(1,length(BEAMLINE),output);
  428. if stat{1}~=1; error(stat{2}); end
  429. % Sort into arrays
  430. new_x = [instdata{1}.x]; new_x = new_x(LC_GUIDATA.firstbpm:end);
  431. new_y = [instdata{1}.y]; new_y = new_y(LC_GUIDATA.firstbpm:end);
  432. new_S = [instdata{1}.S]; new_S = new_S(LC_GUIDATA.firstbpm:end);
  433. % Synch with the server
  434. FlHwUpdate;
  435. % Calculate the predicted data
  436. for pulsenum=1:LC_GUIDATA.ave_edit
  437. [stat beamout instdata] = TrackThru(1,length(BEAMLINE),beamin,1,1);
  438. inds = [instdata{1}.Index];
  439. inds = find(inds>LC_GUIDATA.ringend);
  440. if pulsenum==1
  441. pred_new_x = [instdata{1}.x];
  442. pred_new_y = [instdata{1}.y];
  443. end
  444. pred_new_x = pred_new_x + [instdata{1}.x];
  445. pred_new_y = pred_new_y + [instdata{1}.y];
  446. end
  447. pred_new_x = pred_new_x(inds)/LC_GUIDATA.ave_edit;
  448. pred_new_y = pred_new_y(inds)/LC_GUIDATA.ave_edit;
  449. % Un-kick the beam
  450. if movers
  451. GIRDER{mover_girder(cornum)}.MoverSetPt(ind) = curr_moverpos;
  452. stat = MoverTrim(mover_girder(cornum), true);
  453. if stat{1}~=1; error(stat{2}); end
  454. else
  455. if close_bumps && ...
  456. ~(strcmp(corlist{cornum},'ZV11X') || strcmp(corlist{cornum},'ZV1FF') || ...
  457. strcmp(corlist{cornum},'ZH10X') || strcmp(corlist{cornum},'ZH1FF'))
  458. stat = SetMultiKnob('knob',0,true);
  459. if stat{1}~=1; error(stat{2}); end
  460. else
  461. PS(cor_ps(cornum)).SetPt = curr_psval;
  462. PSTrim(cor_ps(cornum), true);
  463. end
  464. end
  465. % Synch with the server
  466. FlHwUpdate;
  467. % Plot it!
  468. plothand = subplot(2,2,1,'Parent',handles.measdata_panel);
  469. plot(plothand,new_S,new_x*1e3,'rx')
  470. hold(plothand,'off')
  471. plothand = subplot(2,2,2,'Parent',handles.measdata_panel);
  472. plot(plothand,new_S,new_y*1e3,'rx')
  473. hold(plothand,'off')
  474. plothand = subplot(2,2,1,'Parent',handles.preddata_panel);
  475. plot(plothand,new_S,pred_new_x*1e3,'rx')
  476. hold(plothand,'off')
  477. plothand = subplot(2,2,2,'Parent',handles.preddata_panel);
  478. plot(plothand,new_S,pred_new_y*1e3,'rx')
  479. hold(plothand,'off')
  480. xdiff_mat(cornum,:) = new_x - orig_x;
  481. ydiff_mat(cornum,:) = new_y - orig_y;
  482. xdiff_pred_mat(cornum,:) = pred_new_x - pred_orig_x;
  483. ydiff_pred_mat(cornum,:) = pred_new_y - pred_orig_y;
  484. plothand = subplot(2,2,3,'Parent',handles.measdata_panel);
  485. if length(corlist)>1
  486. surf(plothand,new_S,1:length(corlist),xdiff_mat*1e3)
  487. zlabel(plothand,'x / mm')
  488. ylabel(plothand,'Corr num')
  489. xlabel(plothand,'S / m')
  490. view(plothand,-37.5,30)
  491. axis(plothand,'tight')
  492. else
  493. stem(plothand,new_S,xdiff_mat*1e3,'x')
  494. xlabel(plothand,'S / m')
  495. ylabel(plothand,'x / mm')
  496. xlim(plothand,[new_S(1) new_S(end)])
  497. end
  498. title('Diff x')
  499. hold(plothand,'off')
  500. plothand = subplot(2,2,4,'Parent',handles.measdata_panel);
  501. if length(corlist)>1
  502. surf(plothand,new_S,1:length(corlist),ydiff_mat*1e3)
  503. view(-37.5,30)
  504. zlabel('y / mm')
  505. ylabel('Corr num')
  506. xlabel('S / m')
  507. axis(plothand,'tight')
  508. else
  509. stem(plothand,new_S,ydiff_mat*1e3,'x')
  510. xlabel('S / m')
  511. ylabel('y / mm')
  512. xlim([new_S(1) new_S(end)])
  513. end
  514. title('Diff y')
  515. hold(plothand,'off')
  516. plothand = subplot(2,2,3,'Parent',handles.preddata_panel);
  517. if length(corlist)>1
  518. surf(plothand,new_S,1:length(corlist),xdiff_pred_mat*1e3)
  519. view(-37.5,30)
  520. zlabel('x / mm')
  521. ylabel('Corr num')
  522. xlabel('S / m')
  523. axis(plothand,'tight')
  524. else
  525. stem(plothand,new_S,xdiff_pred_mat*1e3,'x')
  526. xlabel('S / m')
  527. ylabel('y / mm')
  528. xlim([new_S(1) new_S(end)])
  529. end
  530. title('Diff x')
  531. hold(plothand,'off')
  532. plothand = subplot(2,2,4,'Parent',handles.preddata_panel);
  533. if length(corlist)>1
  534. surf(plothand,new_S,1:length(corlist),ydiff_pred_mat*1e3)
  535. view(-37.5,30)
  536. zlabel('y / mm')
  537. ylabel('Corr num')
  538. xlabel('S / m')
  539. axis(plothand,'tight')
  540. else
  541. stem(plothand,new_S,ydiff_pred_mat*1e3,'x')
  542. xlabel('S / m')
  543. ylabel('y / mm')
  544. xlim([new_S(1) new_S(end)])
  545. end
  546. title('Diff y')
  547. hold(plothand,'off')
  548. plothand = subplot(1,1,1,'Parent',handles.diffdx_panel);
  549. if length(corlist)>1
  550. surf(plothand,new_S,1:length(corlist),(xdiff_pred_mat-xdiff_mat)*1e3)
  551. view(-37.5,30)
  552. zlabel('x / mm')
  553. ylabel('Corr num')
  554. xlabel('S / m')
  555. axis(plothand,'tight')
  556. else
  557. stem(plothand,new_S,(xdiff_pred_mat-xdiff_mat)*1e3,'x')
  558. xlabel('S / m')
  559. ylabel('x / mm')
  560. xlim([new_S(1) new_S(end)])
  561. end
  562. hold(plothand,'off')
  563. plothand = subplot(1,1,1,'Parent',handles.diffdy_panel);
  564. if length(corlist)>1
  565. surf(plothand,new_S,1:length(corlist),(ydiff_pred_mat-ydiff_mat)*1e3)
  566. view(-37.5,30)
  567. zlabel('y / mm')
  568. ylabel('Corr num')
  569. xlabel('S / m')
  570. axis(plothand,'tight')
  571. else
  572. stem(plothand,new_S,(ydiff_pred_mat-ydiff_mat)*1e3,'x')
  573. xlabel('S / m')
  574. ylabel('y / mm')
  575. xlim([new_S(1) new_S(end)])
  576. end
  577. hold(plothand,'off')
  578. % Note status in start button strin
  579. set(hObject,'String','Removing kick...')
  580. % Start the loop again to make sure the next iteration of the loop only
  581. % sees unkicked beam
  582. [stat output] = FlHwUpdate('readbuffer',1);
  583. if stat{1}~=1; error(stat{2}); end
  584. lastpulse = output(end,1);
  585. pause(LC_GUIDATA.ave_edit/1.56)
  586. currpulse = lastpulse;
  587. while currpulse-lastpulse < LC_GUIDATA.ave_edit
  588. pause(1)
  589. [stat output] = FlHwUpdate('readbuffer',1);
  590. if stat{1}~=1; error(stat{2}); end
  591. currpulse = output(end,1);
  592. end
  593. % Release the corrector access request
  594. AccessRequest('release');
  595. % Test for user cancellation during this run. If so, then deactivate
  596. % the cancel button, and exit the main loop
  597. if LC_GUIDATA.iscancelled
  598. LC_GUIDATA.iscancelled = false;
  599. set(handles.cancel_button,'Enable','off')
  600. set(handles.cancel_button,'BackgroundColor',[0.502 0.502 0.502])
  601. break
  602. end
  603. % Create a "save" field in the global in case the user wants to save
  604. % the data. Fill it full of data, but make sure to reorder it in S
  605. % order first.
  606. eval(['LC_GUIDATA.save.' corlist{cornum} '.orig_x = orig_x;']);
  607. eval(['LC_GUIDATA.save.' corlist{cornum} '.orig_y = orig_y;']);
  608. eval(['LC_GUIDATA.save.' corlist{cornum} '.orig_S = orig_S;']);
  609. eval(['LC_GUIDATA.save.' corlist{cornum} '.new_x = new_x;']);
  610. eval(['LC_GUIDATA.save.' corlist{cornum} '.new_y = new_y;']);
  611. eval(['LC_GUIDATA.save.' corlist{cornum} '.pred_orig_x = pred_orig_x;']);
  612. eval(['LC_GUIDATA.save.' corlist{cornum} '.pred_orig_y = pred_orig_y;']);
  613. eval(['LC_GUIDATA.save.' corlist{cornum} '.pred_orig_S = pred_orig_S;']);
  614. eval(['LC_GUIDATA.save.' corlist{cornum} '.pred_new_x = pred_new_x;']);
  615. eval(['LC_GUIDATA.save.' corlist{cornum} '.pred_new_y = pred_new_y;']);
  616. eval(['LC_GUIDATA.save.' corlist{cornum} '.xdiff = xdiff_mat(cornum,:);']);
  617. eval(['LC_GUIDATA.save.' corlist{cornum} '.ydiff = ydiff_mat(cornum,:);']);
  618. eval(['LC_GUIDATA.save.' corlist{cornum} '.xdiff_pred = xdiff_pred_mat(cornum,:);']);
  619. eval(['LC_GUIDATA.save.' corlist{cornum} '.ydiff_pred = ydiff_pred_mat(cornum,:);']);
  620. eval(['LC_GUIDATA.save.' corlist{cornum} '.kick = mradkick;']);
  621. eval(['LC_GUIDATA.save.' corlist{cornum} '.movers = movers;']);
  622. eval(['LC_GUIDATA.save.' corlist{cornum} '.close_bumps = close_bumps;']);
  623. end
  624. % Put the data into the main global variable
  625. LC_GUIDATA.diffdx = xdiff_pred_mat-xdiff_mat;
  626. LC_GUIDATA.diffdy = ydiff_pred_mat-ydiff_mat;
  627. LC_GUIDATA.corlist = corlist;
  628. % Reset the start button
  629. set(hObject,'BackgroundColor',[0 1 0])
  630. set(hObject,'String','START!')
  631. % Switch on all the front panel buttons
  632. set(hObject,'Enable','on')
  633. set(handles.plot_pushbutton,'Enable','on')
  634. set(handles.save_button,'Enable','on')
  635. set(handles.load_button,'Enable','on')
  636. set(handles.region_menu,'Enable','on')
  637. set(handles.magselect_menu,'Enable','on')
  638. set(handles.devicetype_menu,'Enable','on')
  639. set(handles.ave_edit,'Enable','on')
  640. set(handles.kicksize_edit,'Enable','on')
  641. % Disable the cancel button
  642. set(handles.cancel_button,'Enable','off')
  643. set(handles.cancel_button,'BackgroundColor',[0.502 0.502 0.502])
  644. % --- Executes on selection change in region_menu.
  645. function region_menu_Callback(hObject, eventdata, handles) %#ok<*INUSL>
  646. % hObject handle to region_menu (see GCBO)
  647. % eventdata reserved - to be defined in a future version of MATLAB
  648. % handles structure with handles and user data (see GUIDATA)
  649. % Hints: contents = get(hObject,'String') returns region_menu contents as cell array
  650. % contents{get(hObject,'Value')} returns selected item from region_menu
  651. global BEAMLINE LC_GUIDATA
  652. % Get the contents of the magselect list
  653. mag_contents = get(handles.magselect_menu,'String');
  654. mag_choice = mag_contents{get(handles.magselect_menu,'Value')};
  655. % Get the contents of the device-type list
  656. devtype_contents = get(handles.devicetype_menu,'String');
  657. devtype_choice = devtype_contents{get(handles.devicetype_menu,'Value')};
  658. % Get a list of the xcors and remove a few from this list
  659. xcors_temp = LC_GUIDATA.xcorinds;
  660. xcors = [];
  661. for counter=1:length(xcors_temp)
  662. if ~(xcors_temp(counter)==1257 || ...
  663. xcors_temp(counter)==1261 || ...
  664. xcors_temp(counter)==1267)
  665. xcors = [xcors xcors_temp(counter)]; %#ok<AGROW>
  666. end
  667. end
  668. % Get a list of the ycors
  669. ycors = LC_GUIDATA.ycorinds;
  670. % Get the user selection for the region list
  671. region_contents = get(handles.region_menu,'String');
  672. region_choice = region_contents{get(handles.region_menu,'Value')};
  673. % Determine the corrector/mover list based on this selection
  674. if strcmpi(region_choice,'Extraction Line')
  675. begin = LC_GUIDATA.ringend;
  676. finish = LC_GUIDATA.extff;
  677. elseif strcmpi(region_choice,'Final Focus')
  678. begin = LC_GUIDATA.extff;
  679. finish = length(BEAMLINE);
  680. elseif strcmpi(region_choice,'All')
  681. begin = LC_GUIDATA.ringend;
  682. finish = length(BEAMLINE);
  683. else
  684. error('Something''s gone terribly wrong :S')
  685. end
  686. xcors = xcors(xcors>begin & xcors<finish);
  687. ycors = ycors(ycors>begin & ycors<finish);
  688. % Grab the lists of mover names
  689. count = 0;
  690. for mover_num=1:length(LC_GUIDATA.xmover_S)
  691. if (LC_GUIDATA.xmover_S{mover_num}>BEAMLINE{begin}.S && ...
  692. LC_GUIDATA.xmover_S{mover_num}<BEAMLINE{finish}.S)
  693. count = count + 1;
  694. xmovername{count} = LC_GUIDATA.xmover_name{mover_num}; %#ok<AGROW>
  695. end
  696. end
  697. count = 0;
  698. for mover_num=1:length(LC_GUIDATA.ymover_S)
  699. if (LC_GUIDATA.ymover_S{mover_num}>BEAMLINE{begin}.S && ...
  700. LC_GUIDATA.ymover_S{mover_num}<BEAMLINE{finish}.S)
  701. count = count + 1;
  702. ymovername{count} = LC_GUIDATA.ymover_name{mover_num}; %#ok<AGROW>
  703. end
  704. end
  705. % Generate a list of xcor and ycor names from their indices
  706. xcorname = cell(1,length(xcors));
  707. ycorname = cell(1,length(ycors));
  708. for cornum=1:length(xcors)
  709. xcorname{cornum} = BEAMLINE{xcors(cornum)}.Name;
  710. end
  711. for cornum=1:length(ycors)
  712. ycorname{cornum} = BEAMLINE{ycors(cornum)}.Name;
  713. end
  714. % Set the contents of the corrector list based on the user's selection.
  715. % Ask for further input in the case of "user choice"
  716. if strcmpi(devtype_choice,'correctors')
  717. if strcmpi(mag_choice,'User choice (single)')
  718. magnets = [xcorname ycorname];
  719. [selection ok] = listdlg('ListString',magnets,...
  720. 'SelectionMode','single','Name','Corrector',...
  721. 'PromptString','Choose a corrector to scan');
  722. if ok==0
  723. return
  724. end
  725. set(handles.maglistbox,'String',magnets{selection})
  726. elseif strcmpi(mag_choice,'User choice (multiple)')
  727. magnets = [xcorname ycorname];
  728. [selection ok] = listdlg('ListString',magnets,...
  729. 'SelectionMode','multiple','Name','Corrector',...
  730. 'PromptString','Choose a corrector to scan');
  731. if ok==0
  732. return
  733. end
  734. for count=1:length(selection)
  735. maglist{count} = magnets{selection(count)}; %#ok<AGROW>
  736. end
  737. set(handles.maglistbox,'String',maglist)
  738. elseif strcmpi(mag_choice,'All')
  739. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  740. maglist = [xcorname(1:end-1) ycorname(1:end-1)];
  741. else
  742. maglist = [xcorname(1:end-2) ycorname(1:end-2)];
  743. end
  744. set(handles.maglistbox,'String',maglist)
  745. elseif strcmpi(mag_choice,'All (x)')
  746. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  747. maglist = xcorname(1:end-1);
  748. else
  749. maglist = xcorname(1:end-2);
  750. end
  751. set(handles.maglistbox,'String',maglist)
  752. elseif strcmpi(mag_choice,'All (y)')
  753. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  754. maglist = ycorname(1:end-1);
  755. else
  756. maglist = ycorname(1:end-2);
  757. end
  758. set(handles.maglistbox,'String',maglist)
  759. else
  760. error('Something''s gone terribly wrong :S')
  761. end
  762. elseif strcmpi(devtype_choice,'movers')
  763. if strcmpi(mag_choice,'User choice (single)')
  764. magnets = [xmovername ymovername];
  765. [selection ok] = listdlg('ListString',magnets,...
  766. 'SelectionMode','single','Name','Mover',...
  767. 'PromptString','Choose a mover to scan');
  768. if ok==0
  769. return
  770. end
  771. set(handles.maglistbox,'String',magnets{selection})
  772. elseif strcmpi(mag_choice,'User choice (multiple)')
  773. magnets = [xmovername ymovername];
  774. [selection ok] = listdlg('ListString',magnets,...
  775. 'SelectionMode','multiple','Name','Mover',...
  776. 'PromptString','Choose a mover to scan');
  777. if ok==0
  778. return
  779. end
  780. for count=1:length(selection)
  781. maglist{count} = magnets{selection(count)}; %#ok<AGROW>
  782. end
  783. set(handles.maglistbox,'String',maglist)
  784. elseif strcmpi(mag_choice,'All')
  785. if ~exist('xmovername','var') || ~exist('ymovername','var')
  786. maglist{1} = 'None';
  787. elseif ~exist('xmovername','var')
  788. maglist = ymovername;
  789. elseif ~exist('xmovername','var')
  790. maglist = xmovername;
  791. else
  792. maglist = [xmovername ymovername];
  793. end
  794. set(handles.maglistbox,'String',maglist)
  795. elseif strcmpi(mag_choice,'All (x)')
  796. if ~exist('xmovername','var')
  797. set(handles.maglistbox,'String','None')
  798. else
  799. set(handles.maglistbox,'String',xmovername)
  800. end
  801. elseif strcmpi(mag_choice,'All (y)')
  802. if ~exist('ymovername','var')
  803. set(handles.maglistbox,'String','None')
  804. else
  805. set(handles.maglistbox,'String',ymovername)
  806. end
  807. else
  808. error('Something''s gone terribly wrong :S')
  809. end
  810. else
  811. error('Something''s gone terribly wrong :S')
  812. end
  813. % --- Executes during object creation, after setting all properties.
  814. function region_menu_CreateFcn(hObject, eventdata, handles)
  815. % hObject handle to region_menu (see GCBO)
  816. % eventdata reserved - to be defined in a future version of MATLAB
  817. % handles empty - handles not created until after all CreateFcns called
  818. % Hint: popupmenu controls usually have a white background on Windows.
  819. % See ISPC and COMPUTER.
  820. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  821. set(hObject,'BackgroundColor','white');
  822. end
  823. % --- Executes on selection change in magselect_menu.
  824. function magselect_menu_Callback(hObject, eventdata, handles)
  825. % hObject handle to magselect_menu (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. % Hints: contents = get(hObject,'String') returns magselect_menu contents as cell array
  829. % contents{get(hObject,'Value')} returns selected item from magselect_menu
  830. global BEAMLINE LC_GUIDATA
  831. % Get the contents of the magselect list
  832. mag_contents = get(handles.magselect_menu,'String');
  833. mag_choice = mag_contents{get(handles.magselect_menu,'Value')};
  834. % Get the contents of the device-type list
  835. devtype_contents = get(handles.devicetype_menu,'String');
  836. devtype_choice = devtype_contents{get(handles.devicetype_menu,'Value')};
  837. % Get a list of the xcors and remove a few from this list
  838. xcors_temp = LC_GUIDATA.xcorinds;
  839. xcors = [];
  840. for counter=1:length(xcors_temp)
  841. if ~(xcors_temp(counter)==1257 || ...
  842. xcors_temp(counter)==1261 || ...
  843. xcors_temp(counter)==1267)
  844. xcors = [xcors xcors_temp(counter)]; %#ok<AGROW>
  845. end
  846. end
  847. % Get a list of the ycors
  848. ycors = LC_GUIDATA.ycorinds;
  849. % Get the user selection for the region list
  850. region_contents = get(handles.region_menu,'String');
  851. region_choice = region_contents{get(handles.region_menu,'Value')};
  852. % Determine the corrector/mover list based on this selection
  853. if strcmpi(region_choice,'Extraction Line')
  854. begin = LC_GUIDATA.ringend;
  855. finish = LC_GUIDATA.extff;
  856. elseif strcmpi(region_choice,'Final Focus')
  857. begin = LC_GUIDATA.extff;
  858. finish = length(BEAMLINE);
  859. elseif strcmpi(region_choice,'All')
  860. begin = LC_GUIDATA.ringend;
  861. finish = length(BEAMLINE);
  862. else
  863. error('Something''s gone terribly wrong :S')
  864. end
  865. xcors = xcors(xcors>begin & xcors<finish);
  866. ycors = ycors(ycors>begin & ycors<finish);
  867. % Grab the lists of mover names
  868. count = 0;
  869. for mover_num=1:length(LC_GUIDATA.xmover_S)
  870. if (LC_GUIDATA.xmover_S{mover_num}>BEAMLINE{begin}.S && ...
  871. LC_GUIDATA.xmover_S{mover_num}<BEAMLINE{finish}.S)
  872. count = count + 1;
  873. xmovername{count} = LC_GUIDATA.xmover_name{mover_num}; %#ok<AGROW>
  874. end
  875. end
  876. count = 0;
  877. for mover_num=1:length(LC_GUIDATA.ymover_S)
  878. if (LC_GUIDATA.ymover_S{mover_num}>BEAMLINE{begin}.S && ...
  879. LC_GUIDATA.ymover_S{mover_num}<BEAMLINE{finish}.S)
  880. count = count + 1;
  881. ymovername{count} = LC_GUIDATA.ymover_name{mover_num}; %#ok<AGROW>
  882. end
  883. end
  884. % Generate a list of xcor and ycor names from their indices
  885. xcorname = cell(1,length(xcors));
  886. ycorname = cell(1,length(ycors));
  887. for cornum=1:length(xcors)
  888. xcorname{cornum} = BEAMLINE{xcors(cornum)}.Name;
  889. end
  890. for cornum=1:length(ycors)
  891. ycorname{cornum} = BEAMLINE{ycors(cornum)}.Name;
  892. end
  893. % Set the contents of the corrector list based on the user's selection.
  894. % Ask for further input in the case of "user choice"
  895. if strcmpi(devtype_choice,'correctors')
  896. if strcmpi(mag_choice,'User choice (single)')
  897. magnets = [xcorname ycorname];
  898. [selection ok] = listdlg('ListString',magnets,...
  899. 'SelectionMode','single','Name','Corrector',...
  900. 'PromptString','Choose a corrector to scan');
  901. if ok==0
  902. return
  903. end
  904. set(handles.maglistbox,'String',magnets{selection})
  905. elseif strcmpi(mag_choice,'User choice (multiple)')
  906. magnets = [xcorname ycorname];
  907. [selection ok] = listdlg('ListString',magnets,...
  908. 'SelectionMode','multiple','Name','Corrector',...
  909. 'PromptString','Choose a corrector to scan');
  910. if ok==0
  911. return
  912. end
  913. for count=1:length(selection)
  914. maglist{count} = magnets{selection(count)}; %#ok<AGROW>
  915. end
  916. set(handles.maglistbox,'String',maglist)
  917. elseif strcmpi(mag_choice,'All')
  918. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  919. maglist = [xcorname(1:end-1) ycorname(1:end-1)];
  920. else
  921. maglist = [xcorname(1:end-2) ycorname(1:end-2)];
  922. end
  923. set(handles.maglistbox,'String',maglist)
  924. elseif strcmpi(mag_choice,'All (x)')
  925. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  926. maglist = xcorname(1:end-1);
  927. else
  928. maglist = xcorname(1:end-2);
  929. end
  930. set(handles.maglistbox,'String',maglist)
  931. elseif strcmpi(mag_choice,'All (y)')
  932. if strcmpi(region_choice,'Extraction line') || strcmpi(region_choice,'Final Focus')
  933. maglist = ycorname(1:end-1);
  934. else
  935. maglist = ycorname(1:end-2);
  936. end
  937. set(handles.maglistbox,'String',maglist)
  938. else
  939. error('Something''s gone terribly wrong :S')
  940. end
  941. elseif strcmpi(devtype_choice,'movers')
  942. if strcmpi(mag_choice,'User choice (single)')
  943. magnets = [xmovername ymovername];
  944. [selection ok] = listdlg('ListString',magnets,...
  945. 'SelectionMode','single','Name','Mover',...
  946. 'PromptString','Choose a mover to scan');
  947. if ok==0
  948. return
  949. end
  950. set(handles.maglistbox,'String',magnets{selection})
  951. elseif strcmpi(mag_choice,'User choice (multiple)')
  952. magnets = [xmovername ymovername];
  953. [selection ok] = listdlg('ListString',magnets,...
  954. 'SelectionMode','multiple','Name','Mover',...
  955. 'PromptString','Choose a mover to scan');
  956. if ok==0
  957. return
  958. end
  959. for count=1:length(selection)
  960. maglist{count} = magnets{selection(count)}; %#ok<AGROW>
  961. end
  962. set(handles.maglistbox,'String',maglist)
  963. elseif strcmpi(mag_choice,'All')
  964. if ~exist('xmovername','var') || ~exist('ymovername','var')
  965. maglist{1} = 'None';
  966. elseif ~exist('xmovername','var')
  967. maglist = ymovername;
  968. elseif ~exist('xmovername','var')
  969. maglist = xmovername;
  970. else
  971. maglist = [xmovername ymovername];
  972. end
  973. set(handles.maglistbox,'String',maglist)
  974. elseif strcmpi(mag_choice,'All (x)')
  975. if ~exist('xmovername','var')
  976. set(handles.maglistbox,'String','None')
  977. else
  978. set(handles.maglistbox,'String',xmovername)
  979. end
  980. elseif strcmpi(mag_choice,'All (y)')
  981. if ~exist('ymovername','var')
  982. set(handles.maglistbox,'String','None')
  983. else
  984. set(handles.maglistbox,'String',ymovername)
  985. end
  986. else
  987. error('Something''s gone terribly wrong :S')
  988. end
  989. else
  990. error('Something''s gone terribly wrong :S')
  991. end
  992. % --- Executes during object creation, after setting all properties.
  993. function magselect_menu_CreateFcn(hObject, eventdata, handles) %#ok<*INUSD>
  994. % hObject handle to magselect_menu (see GCBO)
  995. % eventdata reserved - to be defined in a future version of MATLAB
  996. % handles empty - handles not created until after all CreateFcns called
  997. % Hint: popupmenu controls usually have a white background on Windows.
  998. % See ISPC and COMPUTER.
  999. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1000. set(hObject,'BackgroundColor','white');
  1001. end
  1002. function kicksize_edit_Callback(hObject, eventdata, handles)
  1003. % hObject handle to kicksize_edit (see GCBO)
  1004. % eventdata reserved - to be defined in a future version of MATLAB
  1005. % handles structure with handles and user data (see GUIDATA)
  1006. % Hints: get(hObject,'String') returns contents of kicksize_edit as text
  1007. % str2double(get(hObject,'String')) returns contents of kicksize_edit as a double
  1008. global LC_GUIDATA
  1009. % Check that the input is acceptable, and, if so, set the global
  1010. if ~isnan(str2double(get(hObject,'String')))
  1011. input = str2double(get(hObject,'String'));
  1012. devtype_contents = get(handles.devicetype_menu,'String');
  1013. devtype_choice = devtype_contents{get(handles.devicetype_menu,'Value')};
  1014. if strcmpi(devtype_choice,'movers')
  1015. LC_GUIDATA.moversize = input;
  1016. elseif strcmpi(devtype_choice,'correctors')
  1017. LC_GUIDATA.kicksize = input;
  1018. end
  1019. end
  1020. % --- Executes during object creation, after setting all properties.
  1021. function kicksize_edit_CreateFcn(hObject, eventdata, handles)
  1022. % hObject handle to kicksize_edit (see GCBO)
  1023. % eventdata reserved - to be defined in a future version of MATLAB
  1024. % handles empty - handles not created until after all CreateFcns called
  1025. % Hint: edit controls usually have a white background on Windows.
  1026. % See ISPC and COMPUTER.
  1027. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1028. set(hObject,'BackgroundColor','white');
  1029. end
  1030. % --- Executes on selection change in maglistbox.
  1031. function maglistbox_Callback(hObject, eventdata, handles)
  1032. % hObject handle to maglistbox (see GCBO)
  1033. % eventdata reserved - to be defined in a future version of MATLAB
  1034. % handles structure with handles and user data (see GUIDATA)
  1035. % Hints: contents = get(hObject,'String') returns maglistbox contents as cell array
  1036. % contents{get(hObject,'Value')} returns selected item from maglistbox
  1037. % --- Executes during object creation, after setting all properties.
  1038. function maglistbox_CreateFcn(hObject, eventdata, handles)
  1039. % hObject handle to maglistbox (see GCBO)
  1040. % eventdata reserved - to be defined in a future version of MATLAB
  1041. % handles empty - handles not created until after all CreateFcns called
  1042. % Hint: listbox controls usually have a white background on Windows.
  1043. % See ISPC and COMPUTER.
  1044. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1045. set(hObject,'BackgroundColor','white');
  1046. end
  1047. function ave_edit_Callback(hObject, eventdata, handles)
  1048. % hObject handle to ave_edit (see GCBO)
  1049. % eventdata reserved - to be defined in a future version of MATLAB
  1050. % handles structure with handles and user data (see GUIDATA)
  1051. % Hints: get(hObject,'String') returns contents of ave_edit as text
  1052. % str2double(get(hObject,'String')) returns contents of ave_edit as a double
  1053. global LC_GUIDATA
  1054. % Check to see if the input is acceptable, and, if so, set the global
  1055. if ~isnan(str2double(get(hObject,'String')))
  1056. LC_GUIDATA.ave_edit = str2double(get(hObject,'String'));
  1057. else
  1058. set(hObject,'String',num2str(LC_GUIDATA.ave_edit))
  1059. end
  1060. % --- Executes during object creation, after setting all properties.
  1061. function ave_edit_CreateFcn(hObject, eventdata, handles)
  1062. % hObject handle to ave_edit (see GCBO)
  1063. % eventdata reserved - to be defined in a future version of MATLAB
  1064. % handles empty - handles not created until after all CreateFcns called
  1065. % Hint: edit controls usually have a white background on Windows.
  1066. % See ISPC and COMPUTER.
  1067. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1068. set(hObject,'BackgroundColor','white');
  1069. end
  1070. % --- Executes during object deletion, before destroying properties.
  1071. function figure1_DeleteFcn(hObject, eventdata, handles) %#ok<*DEFNU>
  1072. % hObject handle to figure1 (see GCBO)
  1073. % eventdata reserved - to be defined in a future version of MATLAB
  1074. % handles structure with handles and user data (see GUIDATA)
  1075. clear global LC_GUIDATA
  1076. % --- Executes on button press in plot_pushbutton.
  1077. function plot_pushbutton_Callback(hObject, eventdata, handles)
  1078. % hObject handle to plot_pushbutton (see GCBO)
  1079. % eventdata reserved - to be defined in a future version of MATLAB
  1080. % handles structure with handles and user data (see GUIDATA)
  1081. global LC_GUIDATA
  1082. % Check to see if data has been collected, if so, generate a figure and
  1083. % plot the data
  1084. if isfield(LC_GUIDATA,'diffdx')
  1085. figure
  1086. if length(LC_GUIDATA.corlist)>1
  1087. surf(LC_GUIDATA.bpmS,1:length(LC_GUIDATA.corlist),LC_GUIDATA.diffdx*1e3)
  1088. zlabel('x / mm')
  1089. ylabel('Corr num')
  1090. xlabel('S / m')
  1091. title('Pred - Meas (x)')
  1092. else
  1093. stem(LC_GUIDATA.bpmS,LC_GUIDATA.diffdx*1e3,'x')
  1094. xlabel('S / m')
  1095. ylabel('x / mm')
  1096. title(['Pred - Meas (x) (' LC_GUIDATA.corlist{1} ')'])
  1097. end
  1098. end
  1099. % Check to see if data has been collected, if so, generate a figure and
  1100. % plot the data
  1101. if isfield(LC_GUIDATA,'diffdy')
  1102. figure
  1103. if length(LC_GUIDATA.corlist)>1
  1104. surf(LC_GUIDATA.bpmS,1:length(LC_GUIDATA.corlist),LC_GUIDATA.diffdy*1e3)
  1105. zlabel('y / mm')
  1106. ylabel('Corr num')
  1107. xlabel('S / m')
  1108. title('Pred - Meas (y)')
  1109. else
  1110. stem(LC_GUIDATA.bpmS,LC_GUIDATA.diffdy*1e3,'x')
  1111. xlabel('S / m')
  1112. ylabel('y / mm')
  1113. title(['Pred - Meas (y) (' LC_GUIDATA.corlist{1} ')'])
  1114. end
  1115. end
  1116. % --- Executes on button press in cancel_button.
  1117. function cancel_button_Callback(hObject, eventdata, handles)
  1118. % hObject handle to cancel_button (see GCBO)
  1119. % eventdata reserved - to be defined in a future version of MATLAB
  1120. % handles structure with handles and user data (see GUIDATA)
  1121. global LC_GUIDATA
  1122. % If the user hits the cancel button, set the global for the start_button
  1123. % callback to see.
  1124. LC_GUIDATA.iscancelled = true;
  1125. % It won't cancel immediately since it has to clear up after itself, so let
  1126. % the user know that their request has been acknowledged.
  1127. msgbox('Will attempt to terminate this run after this corrector measurement has completed',...
  1128. 'Canceling the run','warn')
  1129. % --- Executes on selection change in devicetype_menu.
  1130. function devicetype_menu_Callback(hObject, eventdata, handles)
  1131. % hObject handle to devicetype_menu (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 = get(hObject,'String') returns devicetype_menu contents as cell array
  1135. % contents{get(hObject,'Value')} returns selected item from
  1136. % devicetype_menu
  1137. global BEAMLINE LC_GUIDATA
  1138. % Get the contents of the magselect list
  1139. mag_contents = get(handles.magselect_menu,'String');
  1140. mag_choice = mag_contents{get(handles.magselect_menu,'Value')};
  1141. % Get the contents of the device-type list
  1142. devtype_contents = get(handles.devicetype_menu,'String');
  1143. devtype_choice = devtype_contents{get(handles.devicetype_menu,'Value')};
  1144. % Get a list of the xcors and remove a few from this list
  1145. xcors_temp = LC_GUIDATA.xcorinds;
  1146. xcors = [];
  1147. for counter=1:length(xcors_temp)
  1148. if ~(xcors_temp(counter)==1257 || ...
  1149. xcors_temp(counter)==1261 || ...
  1150. xcors_temp(counter)==1267)
  1151. xcors = [xcors xcors_temp(counter)]; %#ok<AGROW>
  1152. end
  1153. end
  1154. % Get a list of the ycors
  1155. ycors = LC_GUIDATA.ycorinds;
  1156. % Get the user selection for the region list
  1157. region_contents = get(handles.region_menu,'String');
  1158. region_choice = region_contents{get(handles.region_menu,'Value')};
  1159. % Determine the corrector/mover list based on this selection
  1160. if strcmpi(region_choice,'Extraction Line')
  1161. begin = LC_GUIDATA.ringend;
  1162. finish = LC_GUIDATA.extff;
  1163. elseif strcmpi(region_choice,'Final Focus')
  1164. begin = LC_GUIDATA.extff;
  1165. finish = length(BEAMLINE);
  1166. elseif strcmpi(region_choice,'All')
  1167. begin = LC_GUIDATA.ringend;
  1168. finish = length(BEAMLINE);
  1169. else
  1170. error('Something''s gone terribly wrong :S')
  1171. end
  1172. xcors = xcors(xcors>begin & xcors<finish);
  1173. ycors = ycors(ycors>begin & ycors<finish);
  1174. % Grab the lists of mover names
  1175. count = 0;
  1176. for mover_num=1:length(LC_GUIDATA.xmover_S)
  1177. if (LC_GUIDATA.xmover_S{mover_num}>BEAMLINE{begin}.S && ...
  1178. LC_GUIDATA.xmover_S{mover_num}<BEAMLINE{finish}.S)
  1179. count = count + 1;
  1180. xmovername{count} = LC_GUIDATA.xmover_name{mover_num}; %#ok<AGROW>
  1181. end
  1182. end
  1183. count = 0;
  1184. for mover_num=1:length(LC_GUIDATA.ymover_S)
  1185. if (LC_GUIDATA.ymover_S{mover_num}>BEAMLINE{begin}.S && ...
  1186. LC_GUIDATA.ymover_S{mover_num}<BEAMLINE{finish}.S)
  1187. count = count + 1;
  1188. ymovername{count} = LC_GUIDATA.ymover_name{mover_num}; %#ok<AGROW>
  1189. end
  1190. end
  1191. % Generate a list of xco

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