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

/ATF2/FlightSim/trustedApps/magStandardise/magStandardise.m

http://atf2flightsim.googlecode.com/
MATLAB | 518 lines | 244 code | 92 blank | 182 comment | 49 complexity | de08c1060f5fa23a30e71f1b8e7bdfc5 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. function varargout = magStandardise(varargin)
  2. % MAGSTANDARDISE M-file for magStandardise.fig
  3. % MAGSTANDARDISE, by itself, creates a new MAGSTANDARDISE or raises the existing
  4. % singleton*.
  5. %
  6. % H = MAGSTANDARDISE returns the handle to a new MAGSTANDARDISE or the handle to
  7. % the existing singleton*.
  8. %
  9. % MAGSTANDARDISE('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in MAGSTANDARDISE.M with the given input arguments.
  11. %
  12. % MAGSTANDARDISE('Property','Value',...) creates a new MAGSTANDARDISE or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before magStandardise_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to magStandardise_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 magStandardise
  23. % Last Modified by GUIDE v2.5 11-Dec-2011 22:22:00
  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', @magStandardise_OpeningFcn, ...
  29. 'gui_OutputFcn', @magStandardise_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 magStandardise is made visible.
  42. function magStandardise_OpeningFcn(hObject, eventdata, handles, varargin)
  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 magStandardise (see VARARGIN)
  48. % Choose default command line output for magStandardise
  49. handles.output = handles;
  50. % Update handles structure
  51. guidata(hObject, handles);
  52. % UIWAIT makes magStandardise wait for user response (see UIRESUME)
  53. % uiwait(handles.figure1);
  54. % --- Outputs from this function are returned to the command line.
  55. function varargout = magStandardise_OutputFcn(hObject, eventdata, handles)
  56. % varargout cell array for returning output args (see VARARGOUT);
  57. % hObject handle to figure
  58. % eventdata reserved - to be defined in a future version of MATLAB
  59. % handles structure with handles and user data (see GUIDATA)
  60. % Get default command line output from handles structure
  61. varargout{1} = handles.output;
  62. % --- Exit function
  63. function pushbutton1_Callback(hObject, eventdata, handles)
  64. % hObject handle to pushbutton1 (see GCBO)
  65. % eventdata reserved - to be defined in a future version of MATLAB
  66. % handles structure with handles and user data (see GUIDATA)
  67. guiCloseFn('magStandardise',handles);
  68. % --- Execute Standardisation Procedure
  69. function pushbutton5_Callback(hObject, eventdata, handles)
  70. % hObject handle to pushbutton5 (see GCBO)
  71. % eventdata reserved - to be defined in a future version of MATLAB
  72. % handles structure with handles and user data (see GUIDATA)
  73. if ~strcmp(questdlg('Start Standardisation Procedure?','Standardise','Yes','No','No'),'Yes')
  74. return
  75. end
  76. % Split magnet names by ; separator
  77. magData=regexp(get(handles.edit1,'String'),';','split');
  78. magData={magData{cellfun(@(x) ~isempty(x),magData)}};
  79. set(handles.text7,'ForegroundColor','black');
  80. set(handles.text7,'String','Starting Standardisation Procedure...');
  81. stat=magStandardise_run(magData);
  82. if stat{1}==1
  83. if isempty(regexp(get(handles.text7,'String'),'^Standardise Aborted','once'))
  84. set(handles.text7,'String','Standardisation Complete');
  85. end
  86. else
  87. set(handles.text7,'ForegroundColor','red');
  88. set(handles.text7,'String',['Error in standardisation procedure: ',stat{2}]);
  89. end
  90. function edit2_Callback(hObject, eventdata, handles)
  91. % hObject handle to edit2 (see GCBO)
  92. % eventdata reserved - to be defined in a future version of MATLAB
  93. % handles structure with handles and user data (see GUIDATA)
  94. % Hints: get(hObject,'String') returns contents of edit2 as text
  95. % str2double(get(hObject,'String')) returns contents of edit2 as a double
  96. % --- Executes during object creation, after setting all properties.
  97. function edit2_CreateFcn(hObject, eventdata, handles)
  98. % hObject handle to edit2 (see GCBO)
  99. % eventdata reserved - to be defined in a future version of MATLAB
  100. % handles empty - handles not created until after all CreateFcns called
  101. % Hint: edit controls usually have a white background on Windows.
  102. % See ISPC and COMPUTER.
  103. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  104. set(hObject,'BackgroundColor','white');
  105. end
  106. function edit3_Callback(hObject, eventdata, handles)
  107. % hObject handle to edit3 (see GCBO)
  108. % eventdata reserved - to be defined in a future version of MATLAB
  109. % handles structure with handles and user data (see GUIDATA)
  110. % Hints: get(hObject,'String') returns contents of edit3 as text
  111. % str2double(get(hObject,'String')) returns contents of edit3 as a double
  112. % --- Executes during object creation, after setting all properties.
  113. function edit3_CreateFcn(hObject, eventdata, handles)
  114. % hObject handle to edit3 (see GCBO)
  115. % eventdata reserved - to be defined in a future version of MATLAB
  116. % handles empty - handles not created until after all CreateFcns called
  117. % Hint: edit controls usually have a white background on Windows.
  118. % See ISPC and COMPUTER.
  119. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  120. set(hObject,'BackgroundColor','white');
  121. end
  122. function edit4_Callback(hObject, eventdata, handles)
  123. % hObject handle to edit4 (see GCBO)
  124. % eventdata reserved - to be defined in a future version of MATLAB
  125. % handles structure with handles and user data (see GUIDATA)
  126. % Hints: get(hObject,'String') returns contents of edit4 as text
  127. % str2double(get(hObject,'String')) returns contents of edit4 as a double
  128. % --- Executes during object creation, after setting all properties.
  129. function edit4_CreateFcn(hObject, eventdata, handles)
  130. % hObject handle to edit4 (see GCBO)
  131. % eventdata reserved - to be defined in a future version of MATLAB
  132. % handles empty - handles not created until after all CreateFcns called
  133. % Hint: edit controls usually have a white background on Windows.
  134. % See ISPC and COMPUTER.
  135. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  136. set(hObject,'BackgroundColor','white');
  137. end
  138. function edit5_Callback(hObject, eventdata, handles)
  139. % hObject handle to edit5 (see GCBO)
  140. % eventdata reserved - to be defined in a future version of MATLAB
  141. % handles structure with handles and user data (see GUIDATA)
  142. % Hints: get(hObject,'String') returns contents of edit5 as text
  143. % str2double(get(hObject,'String')) returns contents of edit5 as a double
  144. % --- Executes during object creation, after setting all properties.
  145. function edit5_CreateFcn(hObject, eventdata, handles)
  146. % hObject handle to edit5 (see GCBO)
  147. % eventdata reserved - to be defined in a future version of MATLAB
  148. % handles empty - handles not created until after all CreateFcns called
  149. % Hint: edit controls usually have a white background on Windows.
  150. % See ISPC and COMPUTER.
  151. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  152. set(hObject,'BackgroundColor','white');
  153. end
  154. function edit6_Callback(hObject, eventdata, handles)
  155. % hObject handle to edit6 (see GCBO)
  156. % eventdata reserved - to be defined in a future version of MATLAB
  157. % handles structure with handles and user data (see GUIDATA)
  158. % Hints: get(hObject,'String') returns contents of edit6 as text
  159. % str2double(get(hObject,'String')) returns contents of edit6 as a double
  160. % --- Executes during object creation, after setting all properties.
  161. function edit6_CreateFcn(hObject, eventdata, handles)
  162. % hObject handle to edit6 (see GCBO)
  163. % eventdata reserved - to be defined in a future version of MATLAB
  164. % handles empty - handles not created until after all CreateFcns called
  165. % Hint: edit controls usually have a white background on Windows.
  166. % See ISPC and COMPUTER.
  167. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  168. set(hObject,'BackgroundColor','white');
  169. end
  170. function edit1_Callback(hObject, eventdata, handles)
  171. % hObject handle to edit1 (see GCBO)
  172. % eventdata reserved - to be defined in a future version of MATLAB
  173. % handles structure with handles and user data (see GUIDATA)
  174. % Hints: get(hObject,'String') returns contents of edit1 as text
  175. % str2double(get(hObject,'String')) returns contents of edit1 as a double
  176. % --- Executes during object creation, after setting all properties.
  177. function edit1_CreateFcn(hObject, eventdata, handles)
  178. % hObject handle to edit1 (see GCBO)
  179. % eventdata reserved - to be defined in a future version of MATLAB
  180. % handles empty - handles not created until after all CreateFcns called
  181. % Hint: edit controls usually have a white background on Windows.
  182. % See ISPC and COMPUTER.
  183. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  184. set(hObject,'BackgroundColor','white');
  185. end
  186. % --- Launch Beamlineviewer
  187. function pushbutton2_Callback(hObject, eventdata, handles)
  188. % hObject handle to pushbutton2 (see GCBO)
  189. % eventdata reserved - to be defined in a future version of MATLAB
  190. % handles structure with handles and user data (see GUIDATA)
  191. global FL
  192. FL.Gui.BeamlineViewer = BeamlineViewer;
  193. % --- Select magnets from choices in BeamlineViewer
  194. function pushbutton3_Callback(hObject, eventdata, handles)
  195. % hObject handle to pushbutton3 (see GCBO)
  196. % eventdata reserved - to be defined in a future version of MATLAB
  197. % handles structure with handles and user data (see GUIDATA)
  198. global FL
  199. if isfield(FL,'Gui') && isfield(FL.Gui,'BeamlineViewer')
  200. han=FL.Gui.BeamlineViewer;
  201. maglist=get(han.listbox1,'String');
  202. magsel=get(han.listbox1,'Value');
  203. magstr='';
  204. if ~isempty(magsel)
  205. for imag=1:length(magsel)
  206. magstr=[magstr regexprep(maglist{magsel(imag)},'\S+\s+\S+\s+\S+\s+(\S+)$','$1;')];
  207. end
  208. set(handles.edit1,'String',magstr);
  209. end
  210. end
  211. % --- Clear magnet setting edit window
  212. function pushbutton4_Callback(hObject, eventdata, handles)
  213. % hObject handle to pushbutton4 (see GCBO)
  214. % eventdata reserved - to be defined in a future version of MATLAB
  215. % handles structure with handles and user data (see GUIDATA)
  216. set(handles.edit1,'String',[]);
  217. % --- Executes when user attempts to close figure1.
  218. function figure1_CloseRequestFcn(hObject, eventdata, handles)
  219. % hObject handle to figure1 (see GCBO)
  220. % eventdata reserved - to be defined in a future version of MATLAB
  221. % handles structure with handles and user data (see GUIDATA)
  222. % Hint: delete(hObject) closes the figure
  223. guiCloseFn('magStandardise',handles);
  224. % --- Get standardisation settings
  225. function pushbutton6_Callback(hObject, eventdata, handles)
  226. % hObject handle to pushbutton6 (see GCBO)
  227. % eventdata reserved - to be defined in a future version of MATLAB
  228. % handles structure with handles and user data (see GUIDATA)
  229. global FL BEAMLINE
  230. try
  231. magData=regexp(get(handles.edit1,'String'),';','split');
  232. magData={magData{cellfun(@(x) ~isempty(x),magData)}};
  233. if length(magData)==1
  234. b_ind=findcells(BEAMLINE,'Name',magData{1});
  235. if isempty(b_ind); error('unknown magnet name: %s',magData{1}); end;
  236. if ~isfield(BEAMLINE{b_ind(1)},'PS'); error('No PS element for magnet name: %s',magData{1}); end;
  237. ps_ind=BEAMLINE{b_ind(1)}.PS;
  238. % get pv names for standardisation parameters
  239. if ~isfield(FL.HwInfo.PS(ps_ind),'standardise'); error('No standardisation entries for PS: %d',ps_ind); end;
  240. set(handles.edit4,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.nCycles)));
  241. set(handles.edit2,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.iLow)));
  242. set(handles.edit3,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.iHigh)));
  243. set(handles.edit5,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.waitLow)));
  244. set(handles.edit6,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.waitHigh)));
  245. set(handles.edit7,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.rate)));
  246. set(handles.edit8,'String',num2str(lcaGet(FL.HwInfo.PS(ps_ind).standardise.settingRate)));
  247. set(handles.text7,'ForegroundColor','black');
  248. set(handles.text7,'String','Data retrieved from EPICS database');
  249. else
  250. error('Enter name of single magnet')
  251. end
  252. catch
  253. set(handles.text7,'ForegroundColor','red');
  254. set(handles.text7,'String',['Error getting standardisation settings: ',lasterr]);
  255. set(handles.edit2,'String','?');
  256. set(handles.edit3,'String','?');
  257. set(handles.edit4,'String','?');
  258. set(handles.edit5,'String','?');
  259. set(handles.edit6,'String','?');
  260. set(handles.edit7,'String','?');
  261. set(handles.edit8,'String','?');
  262. end
  263. % --- Commit standardisation settings
  264. function pushbutton7_Callback(hObject, eventdata, handles)
  265. % hObject handle to pushbutton7 (see GCBO)
  266. % eventdata reserved - to be defined in a future version of MATLAB
  267. % handles structure with handles and user data (see GUIDATA)
  268. global FL BEAMLINE
  269. try
  270. magData=regexp(get(handles.edit1,'String'),';','split');
  271. magData={magData{cellfun(@(x) ~isempty(x),magData)}};
  272. if length(magData)==1
  273. b_ind=findcells(BEAMLINE,'Name',magData{1});
  274. if isempty(b_ind); error('unknown magnet name: %s',magData{1}); end;
  275. if ~isfield(BEAMLINE{b_ind(1)},'PS'); error('No PS element for magnet name: %s',magData{1}); end;
  276. ps_ind=BEAMLINE{b_ind(1)}.PS;
  277. % get pv names for standardisation parameters
  278. if ~isfield(FL.HwInfo.PS(ps_ind),'standardise'); error('No standardisation entries for PS: %d',ps_ind); end;
  279. if ~isnan(str2double(get(handles.edit4,'String')))
  280. lcaPut(FL.HwInfo.PS(ps_ind).standardise.nCycles,str2double(get(handles.edit4,'String')));
  281. else
  282. error('Incorrect format for nCycles')
  283. end
  284. if ~isnan(str2double(get(handles.edit2,'String')))
  285. lcaPut(FL.HwInfo.PS(ps_ind).standardise.iLow,str2double(get(handles.edit2,'String')));
  286. else
  287. error('Incorrect format for iLow')
  288. end
  289. if ~isnan(str2double(get(handles.edit3,'String')))
  290. lcaPut(FL.HwInfo.PS(ps_ind).standardise.iHigh,str2double(get(handles.edit3,'String')));
  291. else
  292. error('Incorrect format for iHigh')
  293. end
  294. if ~isnan(str2double(get(handles.edit5,'String')))
  295. lcaPut(FL.HwInfo.PS(ps_ind).standardise.waitLow,str2double(get(handles.edit5,'String')));
  296. else
  297. error('Incorrect format for waitLow')
  298. end
  299. if ~isnan(str2double(get(handles.edit6,'String')))
  300. lcaPut(FL.HwInfo.PS(ps_ind).standardise.waitHigh,str2double(get(handles.edit6,'String')));
  301. else
  302. error('Incorrect format for waitHigh')
  303. end
  304. if ~isnan(str2double(get(handles.edit7,'String')))
  305. lcaPut(FL.HwInfo.PS(ps_ind).standardise.rate,str2double(get(handles.edit7,'String')));
  306. else
  307. error('Incorrect format for standardisation ramp rate')
  308. end
  309. if ~isnan(str2double(get(handles.edit8,'String')))
  310. lcaPut(FL.HwInfo.PS(ps_ind).standardise.settingRate,str2double(get(handles.edit8,'String')));
  311. else
  312. error('Incorrect format for setting ramp rate')
  313. end
  314. else
  315. error('Enter name of single magnet')
  316. end
  317. set(handles.text7,'ForegroundColor','black');
  318. set(handles.text7,'String','Data committed to EPICS database');
  319. catch
  320. set(handles.text7,'ForegroundColor','red');
  321. set(handles.text7,'String',['Error committing standardisation settings: ',lasterr]);
  322. end
  323. % --- Select magnet list
  324. function popupmenu2_Callback(hObject, eventdata, handles)
  325. % hObject handle to popupmenu2 (see GCBO)
  326. % eventdata reserved - to be defined in a future version of MATLAB
  327. % handles structure with handles and user data (see GUIDATA)
  328. % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
  329. % contents{get(hObject,'Value')} returns selected item from popupmenu2
  330. global FL BEAMLINE PS
  331. sel=get(hObject,'Value');
  332. ps_ind=[];
  333. % HAPS PS's
  334. mags=[];
  335. for ips=1:length(FL.HwInfo.PS)
  336. if ~isempty(FL.HwInfo.PS(ips).pvname) && ~isempty(regexp(FL.HwInfo.PS(ips).pvname{1}{1},'^PS','once'))
  337. mags(end+1)=ips;
  338. end
  339. end
  340. switch sel
  341. case 2
  342. for ips=mags
  343. if strcmp(BEAMLINE{PS(ips).Element(1)}.Class,'QUAD')
  344. ps_ind(end+1)=ips;
  345. end
  346. end
  347. case 3
  348. for ips=mags
  349. if strcmp(BEAMLINE{PS(ips).Element(1)}.Class,'SEXT')
  350. ps_ind(end+1)=ips;
  351. end
  352. end
  353. case 4
  354. for ips=mags
  355. if strcmp(BEAMLINE{PS(ips).Element(1)}.Class,'SBEN')
  356. ps_ind(end+1)=ips;
  357. end
  358. end
  359. case 5
  360. ps_ind=mags;
  361. end
  362. if ~isempty(ps_ind)
  363. names=[];
  364. for ips=1:length(ps_ind)
  365. names=[names BEAMLINE{PS(ps_ind(ips)).Element(1)}.Name ';'];
  366. end
  367. set(handles.edit1,'String',names);
  368. else
  369. set(handles.edit1,'String',[]);
  370. errordlg('No magnets set!','Magnet Standardise');
  371. end
  372. % --- Executes during object creation, after setting all properties.
  373. function popupmenu2_CreateFcn(hObject, eventdata, handles)
  374. % hObject handle to popupmenu2 (see GCBO)
  375. % eventdata reserved - to be defined in a future version of MATLAB
  376. % handles empty - handles not created until after all CreateFcns called
  377. % Hint: popupmenu controls usually have a white background on Windows.
  378. % See ISPC and COMPUTER.
  379. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  380. set(hObject,'BackgroundColor','white');
  381. end
  382. function edit7_Callback(hObject, eventdata, handles)
  383. % hObject handle to edit7 (see GCBO)
  384. % eventdata reserved - to be defined in a future version of MATLAB
  385. % handles structure with handles and user data (see GUIDATA)
  386. % Hints: get(hObject,'String') returns contents of edit7 as text
  387. % str2double(get(hObject,'String')) returns contents of edit7 as a double
  388. % --- Executes during object creation, after setting all properties.
  389. function edit7_CreateFcn(hObject, eventdata, handles)
  390. % hObject handle to edit7 (see GCBO)
  391. % eventdata reserved - to be defined in a future version of MATLAB
  392. % handles empty - handles not created until after all CreateFcns called
  393. % Hint: edit controls usually have a white background on Windows.
  394. % See ISPC and COMPUTER.
  395. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  396. set(hObject,'BackgroundColor','white');
  397. end
  398. function edit8_Callback(hObject, eventdata, handles)
  399. % hObject handle to edit8 (see GCBO)
  400. % eventdata reserved - to be defined in a future version of MATLAB
  401. % handles structure with handles and user data (see GUIDATA)
  402. % Hints: get(hObject,'String') returns contents of edit8 as text
  403. % str2double(get(hObject,'String')) returns contents of edit8 as a double
  404. % --- Executes during object creation, after setting all properties.
  405. function edit8_CreateFcn(hObject, eventdata, handles)
  406. % hObject handle to edit8 (see GCBO)
  407. % eventdata reserved - to be defined in a future version of MATLAB
  408. % handles empty - handles not created until after all CreateFcns called
  409. % Hint: edit controls usually have a white background on Windows.
  410. % See ISPC and COMPUTER.
  411. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  412. set(hObject,'BackgroundColor','white');
  413. end
  414. % --- Executes on button press in pushbutton8.
  415. function pushbutton8_Callback(hObject, eventdata, handles)
  416. % hObject handle to pushbutton8 (see GCBO)
  417. % eventdata reserved - to be defined in a future version of MATLAB
  418. % handles structure with handles and user data (see GUIDATA)
  419. global FL
  420. if ~strcmp(questdlg('Abort Standardisation Procedure?','Standardise','Yes','No','No'),'Yes')
  421. return
  422. end
  423. FL.abortcmd=true;
  424. set(handles.text7,'String','Abort requested...')
  425. % set(FL.Gui.magStandardise.edit1,'String','ABORT')
  426. drawnow('expose')