PageRenderTime 31ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/FlightSim/testApps/trajectory_correction/trajectory_correction.m

http://atf2flightsim.googlecode.com/
MATLAB | 1528 lines | 1038 code | 245 blank | 245 comment | 42 complexity | b9f6982268b664952b2a430871b53682 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 = trajectory_correction(varargin)
  2. % trajectory_correction M-file for trajectory_correction.fig
  3. % trajectory_correction, by itself, creates a new trajectory_correction or raises the existing
  4. % singleton*.
  5. %
  6. % H = trajectory_correction returns the handle to a new trajectory_correction or the handle to
  7. % the existing singleton*.
  8. %
  9. % trajectory_correction('CALLBACK',hObject,eventData,handles,...) calls the local
  10. % function named CALLBACK in trajectory_correction.M with the given input arguments.
  11. %
  12. % trajectory_correction('Property','Value',...) creates a new trajectory_correction or raises the
  13. % existing singleton*. Starting from the left, property value pairs are
  14. % applied to the GUI before trajectory_correction_OpeningFcn gets called. An
  15. % unrecognized property name or invalid value makes property application
  16. % stop. All inputs are passed to trajectory_correction_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 trajectory_correction
  23. % Last Modified by GUIDE v2.5 10-Mar-2011 21:12:13
  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', @trajectory_correction_OpeningFcn, ...
  29. 'gui_OutputFcn', @trajectory_correction_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. end
  42. % --- Executes just before trajectory_correction is made visible.
  43. function trajectory_correction_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 trajectory_correction (see VARARGIN)
  49. % Choose default command line output for trajectory_correction
  50. handles.output = hObject;
  51. handles.out='';
  52. handles=output(handles,'loading ...');
  53. disable_all(handles);
  54. handles=init(handles);
  55. % Update handles structure
  56. guidata(hObject, handles);
  57. % UIWAIT makes trajectory_correction wait for user response (see UIRESUME)
  58. % uiwait(handles.trajectory_correction);
  59. end
  60. function handles=init(handles)
  61. global BEAMLINE;
  62. handles.choice='plot_bpm';
  63. handles.xlegend=false;
  64. handles.ylegend=false;
  65. handles.xbpm_range_default=[-5e-3 5e-3];
  66. handles.ybpm_range_default=[-5e-3 5e-3];
  67. handles.xIP_range_default=[-5e-3 5e-3];
  68. handles.yIP_range_default=[-5e-3 5e-3];
  69. handles.xcor_range_default=[-2e-3 2e-3];
  70. handles.ycor_range_default=[-2e-3 2e-3];
  71. handles.xmov_range_default=[-2e-3 2e-3];
  72. handles.ymov_range_default=[-2e-3 2e-3];
  73. handles.srange_default=[0 95];
  74. handles.sIPrange_default=[87.5 92];
  75. IEX=findcells(BEAMLINE, 'Name','IEX');
  76. BS1XA=findcells(BEAMLINE, 'Name','BS1XA');
  77. handles.sub_ref_orbit=true;
  78. handles.naverage=5;
  79. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  80. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  81. range=find(bpm0>=IEX);
  82. handles.bpm=bpm0(range);
  83. handles.nbpm=getcolumn(size(handles.bpm),2);
  84. handles.bpm_read=bpm_read0(range,1:2);
  85. handles.bpm_resol=bpm_resol0(range,1:2);
  86. handles.bpm_S=bpm_S0(range);
  87. handles.bpm_name=bpm_name0(range,:);
  88. handles.bpm_range=1:handles.nbpm;
  89. handles.bpm_ref=zeros(handles.nbpm,2);
  90. handles.weight=ones(handles.nbpm,2);
  91. FlHwUpdate;
  92. ipdata = getIPData;
  93. handles.IP_read=[ipdata.x;ipdata.xp;ipdata.y;ipdata.yp];
  94. handles.IP_ref=zeros(4,1);
  95. handles=plot_choice(handles);
  96. xcor=sort([findcells(BEAMLINE, 'Name','ZX*X') findcells(BEAMLINE, 'Name','ZH*X') findcells(BEAMLINE, 'Name','ZH*FF')]);
  97. handles.xcor_name='';
  98. nxcor=length(xcor);
  99. handles.xcor=[];
  100. for i=1:nxcor
  101. if (strcmp(BEAMLINE{xcor(i)}.Class, 'XCOR') && xcor(i)>BS1XA)
  102. handles.xcor(end+1)=xcor(i);
  103. end
  104. end
  105. handles.nxcor=length(handles.xcor);
  106. handles.xcor_range=1:handles.nxcor;
  107. for i=1:handles.nxcor
  108. handles.xcor_name=strvcat(handles.xcor_name,BEAMLINE{handles.xcor(i)}.Name);
  109. handles.xcor_S(i)=BEAMLINE{handles.xcor(i)}.S-BEAMLINE{IEX}.S;
  110. end
  111. ycor=[findcells(BEAMLINE, 'Name','ZV*X') findcells(BEAMLINE, 'Name','ZV*FF')];
  112. handles.ycor_name='';
  113. nycor=length(ycor);
  114. handles.ycor=[];
  115. for i=1:nycor
  116. if (strcmp(BEAMLINE{ycor(i)}.Class, 'YCOR') && ycor(i)>BS1XA)
  117. handles.ycor(end+1)=ycor(i);
  118. end
  119. end
  120. handles.nycor=length(handles.ycor);
  121. handles.ycor_range=1:handles.nycor;
  122. for i=1:handles.nycor
  123. handles.ycor_name=strvcat(handles.ycor_name,BEAMLINE{handles.ycor(i)}.Name);
  124. handles.ycor_S(i)=BEAMLINE{handles.ycor(i)}.S-BEAMLINE{IEX}.S;
  125. end
  126. handles.mover=28:49;
  127. handles.nmover=length(handles.mover);
  128. handles.mover_name='';
  129. for i=1:handles.nmover
  130. elems=findcells(BEAMLINE,'Girder',handles.mover(i));
  131. if(strcmp(BEAMLINE{elems(1)}.Class,'MONI'))
  132. elems(1)=[];
  133. end
  134. handles.mover_S(i)=BEAMLINE{elems(1)}.S-BEAMLINE{IEX}.S;
  135. mult=findstr(BEAMLINE{elems(1)}.Name,'MULT');
  136. if(isempty(mult))
  137. handles.mover_name=strvcat(handles.mover_name,BEAMLINE{elems(1)}.Name);
  138. else
  139. handles.mover_name=strvcat(handles.mover_name,BEAMLINE{elems(1)}.Name(1:mult-1));
  140. end
  141. end
  142. handles.mover_range=1:22;
  143. %handles.xmover_pos=getcolumn(get_mover(handles.mover),1).';
  144. %handles.ymover_pos=getcolumn(get_mover(handles.mover),2).';
  145. handles.oldread_date='';
  146. handles.mover_oldread={};
  147. handles.mover_old={};
  148. handles.ps_oldread={};
  149. handles.ps_oldps={};
  150. handles.bpm_read_old={};
  151. handles.bpm_read_expected_old={};
  152. handles.IP_read_old={};
  153. handles.IP_read_expected_old={};
  154. handles=output(handles,'done');
  155. enable_all(handles);
  156. end
  157. % --- Outputs from this function are returned to the command line.
  158. function varargout = trajectory_correction_OutputFcn(hObject, eventdata, handles)
  159. % varargout cell array for returning output args (see VARARGOUT);
  160. % hObject handle to figure
  161. % eventdata reserved - to be defined in a future version of MATLAB
  162. % handles structure with handles and user data (see GUIDATA)
  163. % Get default command line output from handles structure
  164. varargout{1} = handles.output;
  165. end
  166. % --- Executes on button press in select_bpm.
  167. function select_bpm_Callback(hObject, eventdata, handles)
  168. % hObject handle to select_bpm (see GCBO)
  169. % eventdata reserved - to be defined in a future version of MATLAB
  170. % handles structure with handles and user data (see GUIDATA)
  171. global BEAMLINE
  172. if(~isfield(handles,'bpm_name'))
  173. end
  174. [selection,ok]=listdlg('PromptString',{'Select bpms :' '' '(Shift+clik = continuous selection)' '(Crtl+clik = uncontinuous selection)'},...
  175. 'ListString',handles.bpm_name,'ListSize',[250 min(handles.nbpm*15,500)],...
  176. 'InitialValue',handles.bpm_range,'Name','Select BPM');
  177. if(ok)
  178. handles.bpm_range=selection;
  179. end
  180. guidata(hObject,handles);
  181. end
  182. % --- Executes on button press in select_xcorrector.
  183. function select_xcorrector_Callback(hObject, eventdata, handles)
  184. % hObject handle to select_xcorrector (see GCBO)
  185. % eventdata reserved - to be defined in a future version of MATLAB
  186. % handles structure with handles and user data (see GUIDATA)
  187. global BEAMLINE;
  188. [selection,ok]=listdlg('PromptString',{'Select X correctors :' '' '(Shift+clik = continuous selection)' '(Crtl+clik = uncontinuous selection)'},...
  189. 'ListString',handles.xcor_name,'ListSize',[250 min(handles.nxcor*15,500)],...
  190. 'InitialValue',handles.xcor_range,'Name','Select X cor');
  191. if(ok)
  192. handles.xcor_range=selection;
  193. end
  194. guidata(hObject,handles);
  195. end
  196. % --- Executes on button press in select_xcorrector.
  197. function select_ycorrector_Callback(hObject, eventdata, handles)
  198. % hObject handle to select_xcorrector (see GCBO)
  199. % eventdata reserved - to be defined in a future version of MATLAB
  200. % handles structure with handles and user data (see GUIDATA)
  201. global BEAMLINE;
  202. [selection,ok]=listdlg('PromptString',{'Select Y correctors :' '' '(Shift+clik = continuous selection)' '(Crtl+clik = uncontinuous selection)'},...
  203. 'ListString',handles.ycor_name,'ListSize',[250 min(handles.nycor*15,500)],...
  204. 'InitialValue',handles.ycor_range,'Name','Select Y cor');
  205. if(ok)
  206. handles.ycor_range=selection;
  207. end
  208. guidata(hObject,handles);
  209. end
  210. function nave_Callback(hObject, eventdata, handles)
  211. % hObject handle to nave (see GCBO)
  212. % eventdata reserved - to be defined in a future version of MATLAB
  213. % handles structure with handles and user data (see GUIDATA)
  214. nave=str2double(get(hObject, 'String'));
  215. if(nave<2)
  216. set(hObject, 'String','2');
  217. nave=2;
  218. end
  219. handles.naverage =nave;
  220. guidata(hObject,handles);
  221. % Hints: get(hObject,'String') returns contents of nave as text
  222. % str2double(get(hObject,'String')) returns contents of nave as a double
  223. end
  224. % --- Executes during object creation, after setting all properties.
  225. function nave_CreateFcn(hObject, eventdata, handles)
  226. % hObject handle to nave (see GCBO)
  227. % eventdata reserved - to be defined in a future version of MATLAB
  228. % handles empty - handles not created until after all CreateFcns called
  229. % Hint: edit controls usually have a white background on Windows.
  230. % See ISPC and COMPUTER.
  231. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  232. set(hObject,'BackgroundColor','white');
  233. end
  234. handles.naverage = str2double(get(hObject, 'String'));
  235. guidata(hObject,handles);
  236. end
  237. % --- Executes on button press in measure_orbit.
  238. function measure_orbit_Callback(hObject, eventdata, handles)
  239. % hObject handle to measure_orbit (see GCBO)
  240. % eventdata reserved - to be defined in a future version of MATLAB
  241. % handles structure with handles and user data (see GUIDATA)
  242. global BEAMLINE
  243. disable_all(handles);
  244. handles=output(handles,'measurement of the orbit ...');
  245. IEX=findcells(BEAMLINE, 'Name','IEX');
  246. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  247. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  248. range=find(bpm0>=IEX );
  249. handles.bpm=bpm0(range);
  250. handles.nbpm=getcolumn(size(handles.bpm),2);
  251. handles.bpm_read=bpm_read0(range,1:2);
  252. handles.bpm_resol=bpm_resol0(range,1:2);
  253. handles.bpm_S=bpm_S0(range);
  254. handles.bpm_name=bpm_name0(range,:);
  255. FlHwUpdate;
  256. ipdata = getIPData;
  257. handles.IP_read=[ipdata.x;ipdata.xp;ipdata.y;ipdata.yp];
  258. if(isfield(handles,'IP_read_expected'))
  259. handles=rmfield(handles,'IP_read_expected');
  260. end
  261. if(isfield(handles,'IP_read_before'))
  262. handles=rmfield(handles,'IP_read_before');
  263. end
  264. if(isfield(handles,'bpm_read_expected'))
  265. handles=rmfield(handles,'bpm_read_expected');
  266. end
  267. if(isfield(handles,'bpm_read_before'))
  268. handles=rmfield(handles,'bpm_read_before');
  269. end
  270. if(isfield(handles,'xcor_ps_newvalue'))
  271. handles=rmfield(handles,'xcor_ps_newvalue');
  272. end
  273. if(isfield(handles,'ycor_ps_newvalue'))
  274. handles=rmfield(handles,'ycor_ps_newvalue');
  275. end
  276. if(isfield(handles,'xmover_pos'))
  277. handles=rmfield(handles,'xmover_pos');
  278. end
  279. if(isfield(handles,'ymover_pos'))
  280. handles=rmfield(handles,'ymover_pos');
  281. end
  282. handles=output(handles,'done');
  283. handles=plot_choice(handles);
  284. enable_all(handles);
  285. guidata(hObject,handles);
  286. end
  287. % --- Executes on button press in compute_ext.
  288. function compute_ext_Callback(hObject, eventdata, handles)
  289. % hObject handle to compute_ext (see GCBO)
  290. % eventdata reserved - to be defined in a future version of MATLAB
  291. % handles structure with handles and user data (see GUIDATA)
  292. global BEAMLINE;
  293. handles=output(handles,'compute EXT correction...');
  294. disable_all(handles);
  295. FlHwUpdate();
  296. IP=findcells(BEAMLINE,'Name','IP');
  297. invalid=isnan(handles.bpm_read(handles.bpm_range,1)) | isnan(handles.bpm_read(handles.bpm_range,2));
  298. if any(invalid)
  299. handles=output(handles,'NaN values BPMS disabled :');
  300. handles=output(handles,handles.bpm_name(handles.bpm_range(invalid),:));
  301. handles.bpm_range=handles.bpm_range(~invalid);
  302. end
  303. handles=output(handles,'compute EXT transfert matrices...');
  304. handles.xmatrix_EXT=get_transfert_matrix(handles.xcor(handles.xcor_range),handles.bpm,1,2);
  305. handles.ymatrix_EXT=get_transfert_matrix(handles.ycor(handles.ycor_range),handles.bpm,3,4);
  306. handles=output(handles,'compute IP transfert matrices...');
  307. handles.xmatrix_EXT_IP=get_transfert_matrix_IP(handles.xcor(handles.xcor_range),IP,1:4,2);
  308. handles.ymatrix_EXT_IP=get_transfert_matrix_IP(handles.ycor(handles.ycor_range),IP,1:4,4);
  309. handles=output(handles,'compute correction...');
  310. [handles.xcor_ps,handles.xcor_ps_newvalue,handles.ycor_ps,handles.ycor_ps_newvalue]=compute_steering_EXT(handles.bpm_read(handles.bpm_range,:)*diag([handles.xgain_val handles.ygain_val]),handles.weight(handles.bpm_range,:),handles.bpm_ref(handles.bpm_range,:),handles.xcor(handles.xcor_range),handles.ycor(handles.ycor_range),handles.xmatrix_EXT(handles.bpm_range,:),handles.ymatrix_EXT(handles.bpm_range,:));
  311. handles.xcor_ps_read=get_ps(handles.xcor_ps);
  312. handles.ycor_ps_read=get_ps(handles.ycor_ps);
  313. handles=output(handles,'correctors change :');
  314. for i=1:length(handles.xcor_range)
  315. handles=output(handles,sprintf('%s %g', handles.xcor_name(handles.xcor_range(i),:), handles.xcor_ps_newvalue(i)-handles.xcor_ps_read(i)));
  316. end
  317. for i=1:length(handles.ycor_range)
  318. handles=output(handles,sprintf('%s %g', handles.ycor_name(handles.ycor_range(i),:), handles.ycor_ps_newvalue(i)-handles.ycor_ps_read(i)));
  319. end
  320. handles.bpm_read_expected(:,1)=handles.xmatrix_EXT*(handles.xcor_ps_newvalue-handles.xcor_ps_read).'+handles.bpm_read(:,1);
  321. handles.bpm_read_expected(:,2)=handles.ymatrix_EXT*(handles.ycor_ps_newvalue-handles.ycor_ps_read).'+handles.bpm_read(:,2);
  322. handles.IP_read_expected= handles.xmatrix_EXT_IP*(handles.xcor_ps_newvalue-handles.xcor_ps_read).'+...
  323. handles.ymatrix_EXT_IP*(handles.ycor_ps_newvalue-handles.ycor_ps_read).'+...
  324. handles.IP_read;
  325. if(isfield(handles,'bpm_read_before'))
  326. handles=rmfield(handles,'bpm_read_before');
  327. end
  328. if(isfield(handles,'IP_read_before'))
  329. handles=rmfield(handles,'IP_read_before');
  330. end
  331. if(isfield(handles,'xmover_pos'))
  332. handles=rmfield(handles,'xmover_pos');
  333. end
  334. if(isfield(handles,'ymover_pos'))
  335. handles=rmfield(handles,'ymover_pos');
  336. end
  337. handles=plot_choice(handles);
  338. if(get(handles.autoapply_ext,'Value')==true)
  339. handles=apply_correction_EXT_Callback(handles.apply_correction_EXT, eventdata, handles);
  340. end
  341. enable_all(handles);
  342. guidata(hObject,handles);
  343. end
  344. % --- Executes on button press in autoapply_ext.
  345. function autoapply_ext_Callback(hObject, eventdata, handles)
  346. % hObject handle to autoapply_ext (see GCBO)
  347. % eventdata reserved - to be defined in a future version of MATLAB
  348. % handles structure with handles and user data (see GUIDATA)
  349. % Hint: get(hObject,'Value') returns toggle state of autoapply_ext
  350. % set(handles.autoapply_ext,'Value',true);
  351. guidata(hObject,handles);
  352. end
  353. % --- Executes on button press in apply_correction_EXT.
  354. function handles=apply_correction_EXT_Callback(hObject, eventdata, handles)
  355. % hObject handle to apply_correction_EXT (see GCBO)
  356. % eventdata reserved - to be defined in a future version of MATLAB
  357. % handles structure with handles and user data (see GUIDATA)
  358. global BEAMLINE PS GIRDER INSTR FS;
  359. handles=output(handles,'apply EXT correction...');
  360. disable_all(handles);
  361. %need mover info for cancelletion
  362. mover_pos0=get_mover(handles.mover);
  363. [ps_oldread]=set_ps([handles.xcor_ps handles.ycor_ps],[handles.xcor_ps_newvalue handles.ycor_ps_newvalue]);
  364. handles.oldread_date=strvcat(handles.oldread_date,[datestr(now,31) ' EXT cor']);
  365. handles.ps_oldread{end+1}=ps_oldread;
  366. handles.ps_oldps{end+1}=[handles.xcor_ps handles.ycor_ps];
  367. handles.mover_oldread{end+1}=mover_pos0;
  368. handles.mover_old{end+1}=handles.mover;
  369. handles.bpm_read_old{end+1}=handles.bpm_read;
  370. handles.IP_read_old{end+1}=handles.bpm_read;
  371. handles.bpm_read_expected_old{end+1}=handles.bpm_read_expected;
  372. handles.IP_read_expected_old{end+1}=handles.bpm_read_expected;
  373. handles.bpm_read_before=handles.bpm_read;
  374. handles.IP_read_before=handles.IP_read;
  375. IEX=findcells(BEAMLINE, 'Name','IEX');
  376. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  377. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  378. range=find(bpm0>=IEX );
  379. handles.bpm=bpm0(range);
  380. handles.nbpm=getcolumn(size(handles.bpm),2);
  381. handles.bpm_read=bpm_read0(range,1:2);
  382. handles.bpm_resol=bpm_resol0(range,1:2);
  383. handles.bpm_S=bpm_S0(range);
  384. handles.bpm_name=bpm_name0(range,:);
  385. FlHwUpdate;
  386. ipdata = getIPData;
  387. handles.IP_read=[ipdata.x;ipdata.xp;ipdata.y;ipdata.yp];
  388. filename = {['testApps/trajectory_correction/data/' datestr(now,30) '.mat']};
  389. save(filename{1},'handles','GIRDER','PS','BEAMLINE','INSTR','FS');
  390. handles=plot_choice(handles);
  391. disable_all(handles);
  392. handles=output(handles,'EXT correction applied');
  393. guidata(hObject,handles);
  394. end
  395. % --- Executes on button press in EXIT.
  396. function EXIT_Callback(hObject, eventdata, handles)
  397. % hObject handle to EXIT (see GCBO)
  398. % eventdata reserved - to be defined in a future version of MATLAB
  399. % handles structure with handles and user data (see GUIDATA)
  400. delete(handles.orbit_steering_fig)
  401. end
  402. function xgain_Callback(hObject, eventdata, handles)
  403. % hObject handle to xgain (see GCBO)
  404. % eventdata reserved - to be defined in a future version of MATLAB
  405. % handles structure with handles and user data (see GUIDATA)
  406. if(str2double(get(hObject, 'String'))~=handles.xgain_val)
  407. handles=output(handles,'xgain changed, compute correction again !');
  408. end
  409. handles.xgain_val = str2double(get(hObject, 'String'));
  410. guidata(hObject,handles);
  411. % Hints: get(hObject,'String') returns contents of xgain as text
  412. % str2double(get(hObject,'String')) returns contents of xgain as a double
  413. end
  414. % --- Executes during object creation, after setting all properties.
  415. function xgain_CreateFcn(hObject, eventdata, handles)
  416. % hObject handle to xgain (see GCBO)
  417. % eventdata reserved - to be defined in a future version of MATLAB
  418. % handles empty - handles not created until after all CreateFcns called
  419. % Hint: edit controls usually have a white background on Windows.
  420. % See ISPC and COMPUTER.
  421. handles.xgain_val = str2double(get(hObject, 'String'));
  422. guidata(hObject,handles);
  423. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  424. set(hObject,'BackgroundColor','white');
  425. end
  426. end
  427. function ygain_Callback(hObject, eventdata, handles)
  428. % hObject handle to ygain (see GCBO)
  429. % eventdata reserved - to be defined in a future version of MATLAB
  430. % handles structure with handles and user data (see GUIDATA)
  431. if(str2double(get(hObject, 'String'))~=handles.ygain_val)
  432. handles=output(handles,'ygain changed, compute correction again !');
  433. end
  434. handles.ygain_val = str2double(get(hObject, 'String'));
  435. guidata(hObject,handles);
  436. % Hints: get(hObject,'String') returns contents of ygain as text
  437. % str2double(get(hObject,'String')) returns contents of ygain as a double
  438. end
  439. % --- Executes during object creation, after setting all properties.
  440. function ygain_CreateFcn(hObject, eventdata, handles)
  441. % hObject handle to ygain (see GCBO)
  442. % eventdata reserved - to be defined in a future version of MATLAB
  443. % handles empty - handles not created until after all CreateFcns called
  444. % Hint: edit controls usually have a white background on Windows.
  445. % See ISPC and COMPUTER.
  446. handles.ygain_val = str2double(get(hObject, 'String'));
  447. guidata(hObject,handles);
  448. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  449. set(hObject,'BackgroundColor','white');
  450. end
  451. end
  452. % --- Executes on button press in compute_ff.
  453. function compute_ff_Callback(hObject, eventdata, handles)
  454. % hObject handle to compute_ff (see GCBO)
  455. % eventdata reserved - to be defined in a future version of MATLAB
  456. % handles structure with handles and user data (see GUIDATA)
  457. global BEAMLINE;
  458. handles=output(handles,'compute FF correction...');
  459. disable_all(handles);
  460. FlHwUpdate();
  461. invalid=isnan(handles.bpm_read(handles.bpm_range,1)) | isnan(handles.bpm_read(handles.bpm_range,2));
  462. if any(invalid)
  463. handles=output(handles,'NaN values BPMS disabled :');
  464. handles=output(handles,handles.bpm_name(handles.bpm_range(invalid),:));
  465. handles.bpm_range=handles.bpm_range(~invalid);
  466. end
  467. invalid=isnan(handles.bpm_ref(handles.bpm_range,1)) | isnan(handles.bpm_ref(handles.bpm_range,2));
  468. if any(invalid)
  469. handles=output(handles,'NaN values BPMS disabled :');
  470. handles=output(handles,handles.bpm_name(handles.bpm_range(invalid),:));
  471. handles.bpm_range=handles.bpm_range(~invalid);
  472. end
  473. [handles.xmatrix_FF,handles.ymatrix_FF]=get_mover_matrix(handles.bpm,handles.mover(handles.mover_range),handles.mover(handles.mover_range));
  474. [handles.xmatrix_IP,handles.ymatrix_IP]=get_mover_matrix_IP(handles.mover(handles.mover_range),handles.mover(handles.mover_range));
  475. [handles.xmover_pos,handles.ymover_pos]=compute_steering_FF(handles.bpm_read(handles.bpm_range,:)*diag([handles.xgain_val handles.ygain_val]),handles.weight(handles.bpm_range,:),handles.bpm_ref(handles.bpm_range,:),handles.mover(handles.mover_range),handles.mover(handles.mover_range),handles.xmatrix_FF(handles.bpm_range,:),handles.ymatrix_FF(handles.bpm_range,:));
  476. handles.xmover_read=getcolumn(get_mover(handles.mover),1).';
  477. handles.ymover_read=getcolumn(get_mover(handles.mover),2).';
  478. handles=output(handles,'mover changes :');
  479. for i=1:length(handles.mover_range)
  480. handles=output(handles,sprintf('%s %g %g', handles.mover_name(handles.mover_range(i),:), handles.xmover_pos(i)-handles.xmover_read(i), handles.ymover_pos(i)-handles.ymover_read(i)));
  481. end
  482. handles.nmover=length(handles.mover);
  483. handles.bpm_read_expected(:,1)=handles.xmatrix_FF*(handles.xmover_pos-handles.xmover_read(handles.mover_range)).'+handles.bpm_read(:,1);
  484. handles.bpm_read_expected(:,2)=handles.ymatrix_FF*(handles.ymover_pos-handles.ymover_read(handles.mover_range)).'+handles.bpm_read(:,2);
  485. handles.IP_read_expected= handles.xmatrix_IP*(handles.xmover_pos-handles.xmover_read(handles.mover_range)).'+...
  486. handles.ymatrix_IP*(handles.ymover_pos-handles.ymover_read(handles.mover_range)).'+...
  487. handles.IP_read;
  488. if(isfield(handles,'bpm_read_before'))
  489. handles=rmfield(handles,'bpm_read_before');
  490. end
  491. if(isfield(handles,'IP_read_before'))
  492. handles=rmfield(handles,'IP_read_before');
  493. end
  494. if(isfield(handles,'xcor_ps_newvalue'))
  495. handles=rmfield(handles,'xcor_ps_newvalue');
  496. end
  497. if(isfield(handles,'ycor_ps_newvalue'))
  498. handles=rmfield(handles,'ycor_ps_newvalue');
  499. end
  500. handles=plot_choice(handles);
  501. if(get(handles.autoapply_ff,'Value')==true)
  502. handles=apply_ff_Callback(handles.apply_ff, eventdata, handles);
  503. end
  504. enable_all(handles);
  505. guidata(hObject,handles);
  506. end
  507. % --- Executes on button press in autoapply_ff.
  508. function autoapply_ff_Callback(hObject, eventdata, handles)
  509. % hObject handle to autoapply_ff (see GCBO)
  510. % eventdata reserved - to be defined in a future version of MATLAB
  511. % handles structure with handles and user data (see GUIDATA)
  512. % Hint: get(hObject,'Value') returns toggle state of autoapply_ff
  513. % set(handles.autoapply_ff,'Value',true);
  514. end
  515. % --- Executes on button press in apply_ff.
  516. function handles=apply_ff_Callback(hObject, eventdata, handles)
  517. % hObject handle to apply_ff (see GCBO)
  518. % eventdata reserved - to be defined in a future version of MATLAB
  519. % handles structure with handles and user data (see GUIDATA)
  520. global BEAMLINE PS GIRDER INSTR FS;
  521. handles=output(handles,'apply FF correction...');
  522. disable_all(handles);
  523. %need ps for cancellation
  524. [nxcor,handles.xcor_ps,handles.xcor_ps_read]=get_corrector(handles.xcor);
  525. [nycor,handles.ycor_ps,handles.ycor_ps_read]=get_corrector(handles.ycor);
  526. mover_pos0=get_mover(handles.mover);
  527. set_mover(handles.mover(handles.mover_range),[handles.xmover_pos.' handles.ymover_pos.' mover_pos0(handles.mover_range,3)]);
  528. handles.oldread_date=strvcat(handles.oldread_date,[datestr(now,31) ' FF cor']);
  529. handles.mover_oldread{end+1}=mover_pos0;
  530. handles.mover_old{end+1}=handles.mover;
  531. handles.ps_oldread{end+1}=[handles.xcor_ps_read handles.ycor_ps_read];
  532. handles.ps_oldps{end+1}=[handles.xcor_ps handles.ycor_ps];
  533. handles.bpm_read_old{end+1}=handles.bpm_read;
  534. handles.IP_read_old{end+1}=handles.bpm_read;
  535. handles.bpm_read_expected_old{end+1}=handles.bpm_read_expected;
  536. handles.IP_read_expected_old{end+1}=handles.bpm_read_expected;
  537. handles.bpm_read_before=handles.bpm_read;
  538. handles.IP_read_before=handles.IP_read;
  539. IEX=findcells(BEAMLINE, 'Name','IEX');
  540. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  541. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  542. range=find(bpm0>=IEX );
  543. handles.bpm=bpm0(range);
  544. handles.nbpm=getcolumn(size(handles.bpm),2);
  545. handles.bpm_read=bpm_read0(range,1:2);
  546. handles.bpm_resol=bpm_resol0(range,1:2);
  547. handles.bpm_S=bpm_S0(range);
  548. handles.bpm_name=bpm_name0(range,:);
  549. FlHwUpdate;
  550. ipdata = getIPData;
  551. handles.IP_read=[ipdata.x;ipdata.xp;ipdata.y;ipdata.yp];
  552. filename = {['testApps/trajectory_correction/data/' datestr(now,30) '.mat']};
  553. save(filename{1},'handles','GIRDER','PS','BEAMLINE','INSTR','FS');
  554. handles=plot_choice(handles);
  555. enable_all(handles);
  556. handles=output(handles,'FF correction applied');
  557. guidata(hObject,handles);
  558. end
  559. % --- Executes on button press in compute_ip.
  560. function compute_ip_Callback(hObject, eventdata, handles)
  561. % hObject handle to compute_ip (see GCBO)
  562. % eventdata reserved - to be defined in a future version of MATLAB
  563. % handles structure with handles and user data (see GUIDATA)
  564. global BEAMLINE;
  565. handles=output(handles,'compute IP correction...');
  566. disable_all(handles);
  567. FlHwUpdate();
  568. [handles.xmatrix_FF,handles.ymatrix_FF]=get_mover_matrix(handles.bpm,handles.mover(handles.mover_range),handles.mover(handles.mover_range));
  569. [handles.xmatrix_IP,handles.ymatrix_IP]=get_mover_matrix_IP(handles.mover(handles.mover_range),handles.mover(handles.mover_range));
  570. [handles.xmover_pos,handles.ymover_pos]=compute_steering_IP(handles.IP_read.*[handles.xgain_val;handles.xgain_val;handles.ygain_val;handles.ygain_val],handles.IP_ref,handles.mover(handles.mover_range),handles.mover(handles.mover_range),handles.xmatrix_IP,handles.ymatrix_IP);
  571. handles.xmover_read=getcolumn(get_mover(handles.mover),1).';
  572. handles.ymover_read=getcolumn(get_mover(handles.mover),2).';
  573. handles=output(handles,'mover changes :');
  574. for i=1:length(handles.mover_range)
  575. handles=output(handles,sprintf('%s %g %g', handles.mover_name(handles.mover_range(i),:), handles.xmover_pos(i)-handles.xmover_read(i), handles.ymover_pos(i)-handles.ymover_read(i)));
  576. end
  577. handles.nmover=length(handles.mover);
  578. handles.bpm_read_expected(:,1)=handles.xmatrix_FF*(handles.xmover_pos-handles.xmover_read(handles.mover_range)).'+handles.bpm_read(:,1);
  579. handles.bpm_read_expected(:,2)=handles.ymatrix_FF*(handles.ymover_pos-handles.ymover_read(handles.mover_range)).'+handles.bpm_read(:,2);
  580. handles.IP_read_expected= handles.xmatrix_IP*(handles.xmover_pos-handles.xmover_read(handles.mover_range)).'+...
  581. handles.ymatrix_IP*(handles.ymover_pos-handles.ymover_read(handles.mover_range)).'+...
  582. handles.IP_read;
  583. if(isfield(handles,'bpm_read_before'))
  584. handles=rmfield(handles,'bpm_read_before');
  585. end
  586. if(isfield(handles,'IP_read_before'))
  587. handles=rmfield(handles,'IP_read_before');
  588. end
  589. if(isfield(handles,'xcor_ps_newvalue'))
  590. handles=rmfield(handles,'xcor_ps_newvalue');
  591. end
  592. if(isfield(handles,'ycor_ps_newvalue'))
  593. handles=rmfield(handles,'ycor_ps_newvalue');
  594. end
  595. handles=plot_choice(handles);
  596. if(get(handles.autoapply_ip,'Value')==true)
  597. handles=apply_ip_Callback(handles.apply_ip, eventdata, handles);
  598. end
  599. enable_all(handles);
  600. guidata(hObject,handles);
  601. end
  602. % --- Executes on button press in autoapply_ip.
  603. function autoapply_ip_Callback(hObject, eventdata, handles)
  604. % hObject handle to autoapply_ip (see GCBO)
  605. % eventdata reserved - to be defined in a future version of MATLAB
  606. % handles structure with handles and user data (see GUIDATA)
  607. % Hint: get(hObject,'Value') returns toggle state of autoapply_ip
  608. end
  609. % --- Executes on button press in apply_ip.
  610. function handles=apply_ip_Callback(hObject, eventdata, handles)
  611. % hObject handle to apply_ip (see GCBO)
  612. % eventdata reserved - to be defined in a future version of MATLAB
  613. % handles structure with handles and user data (see GUIDATA)
  614. global BEAMLINE PS GIRDER INSTR FS;
  615. handles=output(handles,'apply IP correction...');
  616. disable_all(handles);
  617. %need ps for cancellation
  618. [nxcor,handles.xcor_ps,handles.xcor_ps_read]=get_corrector(handles.xcor);
  619. [nycor,handles.ycor_ps,handles.ycor_ps_read]=get_corrector(handles.ycor);
  620. mover_pos0=get_mover(handles.mover);
  621. set_mover(handles.mover(handles.mover_range),[handles.xmover_pos.' handles.ymover_pos.' mover_pos0(handles.mover_range,3)]);
  622. handles.oldread_date=strvcat(handles.oldread_date,[datestr(now,31) ' IP cor']);
  623. handles.mover_oldread{end+1}=mover_pos0;
  624. handles.mover_old{end+1}=handles.mover;
  625. handles.ps_oldread{end+1}=[handles.xcor_ps_read handles.ycor_ps_read];
  626. handles.ps_oldps{end+1}=[handles.xcor_ps handles.ycor_ps];
  627. handles.bpm_read_old{end+1}=handles.bpm_read;
  628. handles.IP_read_old{end+1}=handles.bpm_read;
  629. handles.bpm_read_expected_old{end+1}=handles.bpm_read_expected;
  630. handles.IP_read_expected_old{end+1}=handles.bpm_read_expected;
  631. handles.bpm_read_before=handles.bpm_read;
  632. handles.IP_read_before=handles.IP_read;
  633. IEX=findcells(BEAMLINE, 'Name','IEX');
  634. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  635. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  636. range=find(bpm0>=IEX );
  637. handles.bpm=bpm0(range);
  638. handles.nbpm=getcolumn(size(handles.bpm),2);
  639. handles.bpm_read=bpm_read0(range,1:2);
  640. handles.bpm_resol=bpm_resol0(range,1:2);
  641. handles.bpm_S=bpm_S0(range);
  642. handles.bpm_name=bpm_name0(range,:);
  643. FlHwUpdate;
  644. ipdata = getIPData;
  645. handles.IP_read=[ipdata.x;ipdata.xp;ipdata.y;ipdata.yp];
  646. filename = {['testApps/trajectory_correction/data/' datestr(now,30) '.mat']};
  647. save(filename{1},'handles','GIRDER','PS','BEAMLINE','INSTR','FS');
  648. handles=plot_choice(handles);
  649. enable_all(handles);
  650. handles=output(handles,'IP correction applied');
  651. guidata(hObject,handles);
  652. end
  653. % --- Executes on button press in select_mover.
  654. function select_mover_Callback(hObject, eventdata, handles)
  655. % hObject handle to select_mover (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. global BEAMLINE;
  659. [selection,ok]=listdlg('PromptString',{'Select movers :' '' '(Shift+clik = continuous selection)' '(Crtl+clik = uncontinuous selection)'},...
  660. 'ListString',handles.mover_name,'ListSize',[250 min(handles.nmover*15,500)],...
  661. 'InitialValue',handles.mover_range,'Name','Select Mover');
  662. if(ok)
  663. handles.mover_range=selection;
  664. end
  665. guidata(hObject,handles);
  666. end
  667. % --- Executes on button press in cancel_correction.
  668. function cancel_correction_Callback(hObject, eventdata, handles)
  669. % hObject handle to cancel_correction (see GCBO)
  670. % eventdata reserved - to be defined in a future version of MATLAB
  671. % handles structure with handles and user data (see GUIDATA)
  672. global BEAMLINE
  673. if(~isfield(handles,'oldread_date'))
  674. handles=output(handles,'No action to cancel !');
  675. return
  676. end
  677. ndate=getcolumn(size(handles.oldread_date),1);
  678. ex = get(0,'defaultuicontrolfontsize')*1.7;
  679. listsize=[250 min((ndate+1)*ex,500)];
  680. ylimit{1}=[min(handles.bpm_read(:,1)) max(handles.bpm_read(:,1))];
  681. for i=1:ndate;
  682. ylimit{1}=[min([handles.bpm_read_old{i}(:,1);ylimit{1}(1)]) max([handles.bpm_read_old{i}(:,1);ylimit{1}(2)])];
  683. end
  684. ylimit{2}=[min(handles.bpm_read(:,2)) max(handles.bpm_read(:,2))];
  685. for i=1:ndate;
  686. ylimit{2}=[min([handles.bpm_read_old{i}(:,2);ylimit{2}(1)]) max([handles.bpm_read_old{i}(:,2);ylimit{2}(2)])];
  687. end
  688. [selection,ok]=list_plot_dlg('PromptString','Select the date of the setting you want come back :',...
  689. 'ListString',strvcat(handles.oldread_date,'Now'),...
  690. 'SelectionMode','single',...
  691. 'ListSize',listsize,...
  692. 'InitialValue',ndate+1,...
  693. 'Name','Cancel Correction',...
  694. 'NPlot',2,...
  695. 'PlotSize',[500,100],...
  696. 'XData',handles.bpm_S',...
  697. 'YData',[handles.bpm_read_old {handles.bpm_read}],...
  698. 'ylim',ylimit);
  699. if(ok && selection~=ndate+1)
  700. handles=output(handles,'Cancel correction...');
  701. [ps_oldread]=set_ps(handles.ps_oldps{selection},handles.ps_oldread{selection});
  702. mover_pos0=get_mover(handles.mover_old{selection});
  703. set_mover(handles.mover_old{selection},handles.mover_oldread{selection});
  704. handles.oldread_date=strvcat(handles.oldread_date,[datestr(now,31) ' Cancel.']);
  705. handles.ps_oldread{end+1}=ps_oldread;
  706. handles.ps_oldps{end+1}=handles.ps_oldps{selection};
  707. handles.mover_oldread{end+1}=mover_pos0;
  708. handles.mover_old{end+1}=handles.mover_old{selection};
  709. handles.bpm_read_old{end+1}=handles.bpm_read;
  710. handles.IP_read_old{end+1}=handles.bpm_read;
  711. IEX=findcells(BEAMLINE, 'Name','IEX');
  712. [bpm0,nbpm0,bpm_read0,bpm_resol0,bpm_S0,bpm_name0]=get_bpm_yves(handles.naverage);
  713. %range=find( ~isnan(bpm_read0(:,1).') & bpm0>=IEX );
  714. range=find(bpm0>=IEX );
  715. handles.bpm=bpm0(range);
  716. handles.nbpm=getcolumn(size(handles.bpm),2);
  717. handles.bpm_read=bpm_read0(range,1:2);
  718. handles.bpm_resol=bpm_resol0(range,1:2);
  719. handles.bpm_S=bpm_S0(range);
  720. handles.bpm_name=bpm_name0(range,:);
  721. if(isfield(handles,'bpm_read_expected'))
  722. handles=rmfield(handles,'bpm_read_expected');
  723. end
  724. if(isfield(handles,'bpm_read_before'))
  725. handles=rmfield(handles,'bpm_read_before');
  726. end
  727. if(isfield(handles,'xcor_ps_newvalue'))
  728. handles=rmfield(handles,'xcor_ps_newvalue');
  729. end
  730. if(isfield(handles,'ycor_ps_newvalue'))
  731. handles=rmfield(handles,'ycor_ps_newvalue');
  732. end
  733. if(isfield(handles,'xmover_pos'))
  734. handles=rmfield(handles,'xmover_pos');
  735. end
  736. if(isfield(handles,'ymover_pos'))
  737. handles=rmfield(handles,'ymover_pos');
  738. end
  739. handles=plot_choice(handles);
  740. handles=output(handles,'Correction cancelled');
  741. end
  742. guidata(hObject,handles);
  743. end
  744. % --- Executes when selected object is changed in plot_choice.
  745. function plot_choice_SelectionChangeFcn(hObject, eventdata, handles)
  746. % hObject handle to the selected object in plot_choice
  747. % eventdata structure with the following fields (see UIBUTTONGROUP)
  748. % EventName: string 'SelectionChanged' (read only)
  749. % OldValue: handle of the previously selected object or empty if none was selected
  750. % NewValue: handle of the currently selected object
  751. % handles structure with handles and user data (see GUIDATA)
  752. handles.choice=get(hObject,'Tag');
  753. disable_all(handles);
  754. handles=plot_choice(handles);
  755. enable_all(handles);
  756. guidata(hObject,handles);
  757. end
  758. % --- Executes on button press in Ref_table.
  759. function Ref_table_Callback(hObject, eventdata, handles)
  760. % hObject handle to Ref_table (see GCBO)
  761. % eventdata reserved - to be defined in a future version of MATLAB
  762. % handles structure with handles and user data (see GUIDATA)
  763. % handles.bpm_ref=handles.bpm_read;
  764. % handles=plot_choice(handles);
  765. f=figure('Position',[1 1 700 800]);
  766. dat = [handles.bpm_ref(:,1) handles.bpm_read(:,1) handles.weight(:,1) ...
  767. handles.bpm_ref(:,2) handles.bpm_read(:,2) handles.weight(:,2);...
  768. handles.IP_ref(1) handles.IP_read(1) NaN ...
  769. handles.IP_ref(3) handles.IP_read(3) NaN;
  770. handles.IP_ref(2) handles.IP_read(2) NaN ...
  771. handles.IP_ref(4) handles.IP_read(4) NaN;];
  772. columnname = {'X reference', 'X Reading', 'X Weight', 'Y reference', 'Y Reading', 'Y Weight'};
  773. columnformat = {'short e', 'short e', 'short e', 'short e', 'short e', 'short e'};
  774. columneditable = [true false true true false true];
  775. columnwidth ={100 100 100 100 100 100};
  776. rowname = strvcat(handles.bpm_name,['IP pos';'IP ang']);
  777. t = uitable('Units','normalized',...
  778. 'Position', [0 0 1 1], ...
  779. 'Data', dat,...
  780. 'Parent',f,...
  781. 'RowStriping','on',...
  782. 'ColumnName', columnname,...
  783. 'ColumnFormat', columnformat,...
  784. 'ColumnEditable', columneditable,...
  785. 'ColumnWidth',columnwidth,...
  786. 'RowName',rowname,...
  787. 'DeleteFcn','dat = get(gcbo,''Data'');save -v7 tmp.mat dat;');
  788. waitfor(t);
  789. load('tmp.mat');
  790. eval('!rm tmp.mat')
  791. handles.bpm_ref=dat(1:end-2,[1 4]);
  792. handles.weight=dat(1:end-2,[3 6]);
  793. handles.IP_ref=[dat(end-1,1); dat(end,1); dat(end-1,4); dat(end,4)];
  794. handles=plot_choice(handles);
  795. guidata(hObject,handles);
  796. end
  797. % --- Executes on button press in save_ref_orbit.
  798. function save_ref_orbit_Callback(hObject, eventdata, handles)
  799. % hObject handle to save_ref_orbit (see GCBO)
  800. % eventdata reserved - to be defined in a future version of MATLAB
  801. % handles structure with handles and user data (see GUIDATA)
  802. prompt = {'Enter file name:'};
  803. dlg_title = 'Save Ref Orbit';
  804. num_lines = 1;
  805. def = {[datestr(now,30) '.mat']};
  806. filename = inputdlg(prompt,dlg_title,num_lines,def);
  807. save(filename{1});
  808. end
  809. % --- Executes on button press in load_ref_orbit.
  810. function load_ref_orbit_Callback(hObject, eventdata, handles)
  811. % hObject handle to load_ref_orbit (see GCBO)
  812. % eventdata reserved - to be defined in a future version of MATLAB
  813. % handles structure with handles and user data (see GUIDATA)
  814. d = dir;
  815. str = {d.name};
  816. [selection,ok]=listdlg('PromptString',{'Select the file to load :'},...
  817. 'ListString',str,'ListSize',[250 min(length(str)*15,500)],...
  818. 'InitialValue',1,'Name','Load Ref Orbit',...
  819. 'SelectionMode','single');
  820. if(ok)
  821. load_handle=load(str{selection});
  822. size_bpm_ref=size(handles.bpm_ref);
  823. size_load_bpm_ref=size(load_handle.handles.bpm_ref);
  824. if(size_load_bpm_ref~=size_bpm_ref)
  825. handles=output(handles,'Size of reference and current orbit does not match : load canceled.');
  826. guidata(hObject,handles);
  827. return
  828. end
  829. handles.bpm_ref=load_handle.handles.bpm_ref;
  830. handles=output(handles,handles.bpm_ref);
  831. end
  832. disable_all(handles);
  833. handles=plot_choice(handles);
  834. enable_all(handles);
  835. guidata(hObject,handles);
  836. end
  837. % --- Executes on button press in subst_ref_orbit.
  838. function subst_ref_orbit_Callback(hObject, eventdata, handles)
  839. % hObject handle to subst_ref_orbit (see GCBO)
  840. % eventdata reserved - to be defined in a future version of MATLAB
  841. % handles structure with handles and user data (see GUIDATA)
  842. % Hint: get(hObject,'Value') returns toggle state of subst_ref_orbit
  843. handles.sub_ref_orbit=get(hObject,'Value');
  844. if strcmp(handles.choice,'plot_bpm')
  845. disable_all(handles);
  846. handles=plot_choice(handles);
  847. enable_all(handles);
  848. end
  849. guidata(hObject,handles);
  850. end
  851. function sbpm_range_Callback(hObject, eventdata, handles)
  852. % hObject handle to sbpm_range (see GCBO)
  853. % eventdata reserved - to be defined in a future version of MATLAB
  854. % handles structure with handles and user data (see GUIDATA)
  855. % Hints: get(hObject,'String') returns contents of sbpm_range as text
  856. % str2double(get(hObject,'String')) returns contents of sbpm_range
  857. % as a double
  858. switch handles.choice % Get Tag of selected object
  859. case 'plot_bpm'
  860. handles.srange_default = eval(get(hObject, 'String'));
  861. case 'plot_cor'
  862. handles.srange_default = eval(get(hObject, 'String'));
  863. case 'plot_mover'
  864. handles.srange_default = eval(get(hObject, 'String'));
  865. case 'plot_IP'
  866. handles.sIPrange_default = eval(get(hObject, 'String'));
  867. otherwise
  868. handles=output(handles,['ERROR : ' handles.choice ' plot is unknow !']);
  869. end
  870. handles=plot_choice(handles);
  871. guidata(hObject,handles);
  872. end
  873. % --- Executes during object creation, after setting all properties.
  874. function sbpm_range_CreateFcn(hObject, eventdata, handles)
  875. % hObject handle to sbpm_range (see GCBO)
  876. % eventdata reserved - to be defined in a future version of MATLAB
  877. % handles empty - handles not created until after all CreateFcns called
  878. % Hint: edit controls usually have a white background on Windows.
  879. % See ISPC and COMPUTER.
  880. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  881. set(hObject,'BackgroundColor','white');
  882. end
  883. end
  884. function xbpm_range_Callback(hObject, eventdata, handles)
  885. % hObject handle to xbpm_range (see GCBO)
  886. % eventdata reserved - to be defined in a future version of MATLAB
  887. % handles structure with handles and user data (see GUIDATA)
  888. % Hints: get(hObject,'String') returns contents of xbpm_range as text
  889. % str2double(get(hObject,'String')) returns contents of xbpm_range as a double
  890. switch handles.choice % Get Tag of selected object
  891. case 'plot_bpm'
  892. handles.xbpm_range_default = eval(get(hObject, 'String'));
  893. case 'plot_cor'
  894. handles.xcor_range_default = eval(get(hObject, 'String'));
  895. case 'plot_mover'
  896. handles.xmov_range_default = eval(get(hObject, 'String'));
  897. case 'plot_IP'
  898. handles.xIP_range_default = eval(get(hObject, 'String'));
  899. otherwise
  900. handles=output(handles,['ERROR : ' handles.choice ' plot is unknow !']);
  901. end
  902. handles=plot_choice(handles);
  903. guidata(hObject,handles);
  904. end
  905. % --- Executes during object creation, after setting all properties.
  906. function xbpm_range_CreateFcn(hObject, eventdata, handles)
  907. % hObject handle to xbpm_range (see GCBO)
  908. % eventdata reserved - to be defined in a future version of MATLAB
  909. % handles empty - handles not created until after all CreateFcns called
  910. % Hint: edit controls usually have a white background on Windows.
  911. % See ISPC and COMPUTER.
  912. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  913. set(hObject,'BackgroundColor','white');
  914. end
  915. end
  916. function ybpm_range_Callback(hObject, eventdata, handles)
  917. % hObject handle to ybpm_range (see GCBO)
  918. % eventdata reserved - to be defined in a future version of MATLAB
  919. % handles structure with handles and user data (see GUIDATA)
  920. % Hints: get(hObject,'String') returns contents of ybpm_range as text
  921. % str2double(get(hObject,'String')) returns contents of ybpm_range as a
  922. % double
  923. switch handles.choice % Get Tag of selected object
  924. case 'plot_bpm'
  925. handles.ybpm_range_default = eval(get(hObject, 'String'));
  926. case 'plot_cor'
  927. handles.ycor_range_default = eval(get(hObject, 'String'));
  928. case 'plot_mover'
  929. handles.ymov_range_default = eval(get(hObject, 'String'));
  930. case 'plot_IP'
  931. handles.yIP_range_default = eval(get(hObject, 'String'));
  932. otherwise
  933. handles=output(handles,['ERROR : ' handles.choice ' plot is unknow !']);
  934. end
  935. handles=plot_choice(handles);
  936. guidata(hObject,handles);
  937. end
  938. % --- Executes during object creation, after setting all properties.
  939. function ybpm_range_CreateFcn(hObject, eventdata, handles)
  940. % hObject handle to ybpm_range (see GCBO)
  941. % eventdata reserved - to be defined in a future version of MATLAB
  942. % handles empty - handles not created until after all CreateFcns called
  943. % Hint: edit controls usually have a white background on Windows.
  944. % See ISPC and COMPUTER.
  945. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  946. set(hObject,'BackgroundColor','white');
  947. end
  948. end
  949. % --------------------------------------------------------------------
  950. function xbpm_legend_Callback(hObject, eventdata, handles)
  951. % hObject handle to ybpm_legend (see GCBO)
  952. % eventdata reserved - to be defined in a future version of MATLAB
  953. % handles structure with handles and user data (see GUIDATA)
  954. if(handles.xlegend)
  955. handles.xlegend=false;
  956. else
  957. handles.xlegend=true;
  958. end
  959. handles=plot_choice(handles);
  960. guidata(hObject,handles);
  961. end
  962. % --------------------------------------------------------------------
  963. function xbpm_context_menu_Callback(hObject, eventdata, handles)
  964. % hObject handle to xbpm_context_menu (see GCBO)
  965. % eventdata reserved - to be defined in a future version of MATLAB
  966. % handles structure with handles and user data (see GUIDATA)
  967. end
  968. % --------------------------------------------------------------------
  969. function ybpm_legend_Callback(hObject, eventdata, handles)
  970. % hObject handle to ybpm_legend (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. if(handles.ylegend)
  974. handles.ylegend=false;
  975. else
  976. handles.ylegend=true;
  977. end
  978. handles=plot_choice(handles);
  979. guidata(hObject,handles);
  980. end
  981. % --------------------------------------------------------------------
  982. function ybpm_context_menu_Callback(hObject, eventdata, handles)
  983. % hObject handle to ybpm_context_menu (see GCBO)
  984. % eventdata reserved - to be defined in a future version of MATLAB
  985. % handles structure with handles and user data (see GUIDATA)
  986. end
  987. % --- Executes during object creation, after setting all properties.
  988. function xbpm_CreateFcn(hObject, eventdata, handles)
  989. % hObject handle to xbpm (see GCBO)
  990. % eventdata reserved - to be defined in a future version of MATLAB
  991. % handles empty - handles not created until after all CreateFcns called
  992. % Hint: place code in OpeningFcn to populate xbpm
  993. end
  994. function output_txt_Callback(hObject, eventdata, handles)
  995. % hObject handle to output_txt (see GCBO)
  996. % eventdata reserved - to be defined in a future version of MATLAB
  997. % handles structure with handles and user data (see GUIDATA)
  998. % Hints: get(hObject,'String') returns contents of output_txt as text
  999. % str2double(get(hObject,'String')) returns contents of output_txt as a double
  1000. end
  1001. % --- Executes during object creation, after setting all properties.
  1002. function output_txt_CreateFcn(hObject, eventdata, handles)
  1003. % hObject handle to output_txt (see GCBO)
  1004. % eventdata reserved - to be defined in a future version of MATLAB
  1005. % handles empty - handles not created until after all CreateFcns called
  1006. % Hint: edit controls usually have a white background on Windows.
  1007. % See ISPC and COMPUTER.
  1008. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1009. set(hObject,'BackgroundColor','white');
  1010. end
  1011. end
  1012. function handles=plot_choice(handles)
  1013. global BEAMLINE
  1014. IEX=getcolumn(findcells(BEAMLINE, 'Name','IEX'),1);
  1015. switch handles.choice % Get Tag of selected object
  1016. case 'plot_bpm'
  1017. plot_magnets_external(BEAMLINE(IEX:end),handles.beamline,BEAMLINE{IEX}.S+handles.srange_default(1),BEAMLINE{IEX}.S+handles.srange_default(2),1,0);
  1018. set(handles.sbpm_range,'String',sprintf('[%g %g]',handles.srange_default(1), handles.srange_default(2)));
  1019. set(handles.xbpm_range,'String',sprintf('[%g %g]',handles.xbpm_range_default(1), handles.xbpm_range_default(2)));
  1020. set(handles.ybpm_range,'String',sprintf('[%g %g]',handles.ybpm_range_default(1), handles.ybp

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