[4] | 1 | function corgui(action, varargin) |
---|
| 2 | % CORGUI - controls corrector manipulation and plotting for orbit program |
---|
| 3 | %varargout = corgui(action, varargin) |
---|
| 4 | %============================================================= |
---|
| 5 | % |
---|
| 6 | % INPUT |
---|
| 7 | %1. action among: |
---|
| 8 | % PlotCor_Init |
---|
| 9 | % Fract |
---|
| 10 | % ApplyCorrection |
---|
| 11 | % RemoveCorrection |
---|
| 12 | % ApplyFit |
---|
| 13 | % UpdateCors |
---|
| 14 | % GetAct |
---|
| 15 | % UpdateAct |
---|
| 16 | % PlotAct |
---|
| 17 | % PlotFit |
---|
| 18 | % ClearFit |
---|
| 19 | % ClearPlots |
---|
| 20 | % ShowPlots |
---|
| 21 | % HidePlots |
---|
| 22 | % RePlot |
---|
| 23 | % ylimits |
---|
| 24 | % CorSelect |
---|
| 25 | % CorDown |
---|
| 26 | % ProcessCor |
---|
| 27 | % CorBar |
---|
| 28 | % UpdateCorBox |
---|
| 29 | % CorBox |
---|
| 30 | % Up |
---|
| 31 | % CORmove |
---|
| 32 | % SelectAll |
---|
| 33 | % SelectNone |
---|
| 34 | % ToggleCor |
---|
| 35 | % ShowResp |
---|
| 36 | % ShowEig |
---|
| 37 | % SaveCors |
---|
| 38 | % RestoreCors |
---|
| 39 | % CorEdit |
---|
| 40 | % ShowCORState |
---|
| 41 | % |
---|
| 42 | |
---|
| 43 | % |
---|
| 44 | % Written by William J. Corbett |
---|
| 45 | % Adapted by Laurent S. Nadolski |
---|
| 46 | |
---|
| 47 | %globals |
---|
| 48 | global COR RSP SYS |
---|
| 49 | |
---|
| 50 | % HCORFamily = 'HCOR'; |
---|
| 51 | % VCORFamily = 'VCOR'; |
---|
| 52 | % BPMxFamily = 'BPMx'; |
---|
| 53 | % BPMzFamily = 'BPMz'; |
---|
| 54 | |
---|
| 55 | orbfig = findobj(0,'tag','orbfig'); |
---|
| 56 | plane = SYS.plane; |
---|
| 57 | |
---|
| 58 | switch action |
---|
| 59 | |
---|
| 60 | %========================================================== |
---|
| 61 | case 'PlotCor_Init' % *** PlotCor_Init *** |
---|
| 62 | %============Replot============================================== |
---|
| 63 | %draw patches to create a "bar" plot for the correctors. |
---|
| 64 | set(SYS.ahcor,'Xlim',[0 SYS.xlimax]); |
---|
| 65 | |
---|
| 66 | %======================================== |
---|
| 67 | %initialize for plane that IS NOT default |
---|
| 68 | %======================================== |
---|
| 69 | plane = 1 + mod(plane,2); |
---|
| 70 | SYS.plane = plane; |
---|
| 71 | |
---|
| 72 | xd = orbgui('GetAbscissa',SYS,'COR'); %horizontal coordinates for plotting |
---|
| 73 | |
---|
| 74 | COR(plane).id = 1; %first corrector selected as default |
---|
| 75 | |
---|
| 76 | for ii = 1:size(COR(plane).name,1) |
---|
| 77 | c = xd(ii); %horizontal coordinate |
---|
| 78 | color = 'k'; %default black if not in status vector |
---|
| 79 | if ~isempty(find(COR(plane).status==ii,1)), color='y'; end %yellow for available |
---|
| 80 | if ~isempty(find(COR(plane).ifit==ii,1)), color='g'; end %green for fit |
---|
| 81 | |
---|
| 82 | %actual corrector strength (green) |
---|
| 83 | COR(plane).hact(ii,1) = line('parent',SYS.ahcor,'XData', ... |
---|
| 84 | c,'YData',0,'Marker','diamond',... |
---|
| 85 | 'MarkerFaceColor',color,'MarkerSize',6,... |
---|
| 86 | 'tag', ['c' num2str(plane) '_' num2str(ii)],... %c for corrector |
---|
| 87 | 'ButtonDownFcn','corgui(''CorSelect'')'); |
---|
| 88 | %vertical bar to icon |
---|
| 89 | COR(plane).hact(ii,2) = line('parent',SYS.ahcor,'XData', ... |
---|
| 90 | [c c],'YData',[0 0],'Color','b'); |
---|
| 91 | |
---|
| 92 | %actual+fitted strength (red) |
---|
| 93 | COR(plane).hfit(ii,1) = line('parent',SYS.ahcor,'XData', ... |
---|
| 94 | c,'YData',0,'Marker','o',... |
---|
| 95 | 'MarkerFaceColor','r','MarkerSize',4,... |
---|
| 96 | 'tag', ['f' num2str(plane) '_' num2str(ii)],... %f for fit |
---|
| 97 | 'ButtonDownFcn','corgui(''CorSelect'')'); |
---|
| 98 | %vertical bar to icon |
---|
| 99 | COR(plane).hfit(ii,2)=line('parent',SYS.ahcor,'XData', ... |
---|
| 100 | [c c],'YData',[0 0],'Color','b'); |
---|
| 101 | |
---|
| 102 | if strcmp(color,'k') %if status bad make single black dot |
---|
| 103 | set(COR(plane).hact(ii,1),'MarkerSize',4,'Marker','o'); |
---|
| 104 | set(COR(plane).hfit(ii,1),'MarkerFaceColor','k'); |
---|
| 105 | end |
---|
| 106 | |
---|
| 107 | end |
---|
| 108 | %======================================== |
---|
| 109 | %initialize for plane that IS default |
---|
| 110 | %======================================== |
---|
| 111 | plane = 1+mod(plane,2); %return to default plane |
---|
| 112 | SYS.plane = plane; |
---|
| 113 | |
---|
| 114 | COR(plane).id = 1; |
---|
| 115 | |
---|
| 116 | xd = orbgui('GetAbscissa',SYS,'COR'); %horizontal coordinates for plotting |
---|
| 117 | |
---|
| 118 | for ii = 1:size(COR(plane).name,1) |
---|
| 119 | c = xd(ii); |
---|
| 120 | color = 'k'; %black if not in status vector |
---|
| 121 | if ~isempty(find(COR(plane).status==ii,1)), color='y'; end %yellow for for available |
---|
| 122 | if ~isempty(find(COR(plane).ifit==ii,1)), color='g'; end %green for fit |
---|
| 123 | |
---|
| 124 | %actual corrector strength (green) |
---|
| 125 | COR(plane).hact(ii,1)=line('parent',SYS.ahcor,'XData', ... |
---|
| 126 | c,'YData',0,'Marker','diamond',... |
---|
| 127 | 'MarkerFaceColor',color,'MarkerSize',6,... |
---|
| 128 | 'tag', ['c' num2str(plane) '_' num2str(ii)],... |
---|
| 129 | 'ButtonDownFcn','corgui(''CorSelect'')'); |
---|
| 130 | %vertical bar to icon |
---|
| 131 | COR(plane).hact(ii,2)=line('parent',SYS.ahcor,'XData', ... |
---|
| 132 | [c c],'YData',[0 0]); |
---|
| 133 | |
---|
| 134 | %actual+fitted strength (red) |
---|
| 135 | COR(plane).hfit(ii,1)=line('parent',SYS.ahcor,'XData', ... |
---|
| 136 | c,'YData',0,'Marker','o',... |
---|
| 137 | 'MarkerFaceColor','r','MarkerSize',4,... |
---|
| 138 | 'tag', ['f' num2str(plane) '_' num2str(ii)],... |
---|
| 139 | 'ButtonDownFcn','corgui(''CorSelect'')'); |
---|
| 140 | %vertical bar to icon |
---|
| 141 | COR(plane).hfit(ii,2)=line('parent',SYS.ahcor,'XData', ... |
---|
| 142 | [c c],'YData',[0 0]); |
---|
| 143 | |
---|
| 144 | if strcmp(color,'k') %if status bad make single black dot |
---|
| 145 | set(COR(plane).hact(ii,1),'MarkerSize',4,'Marker','o'); |
---|
| 146 | set(COR(plane).hfit(ii,1),'MarkerFaceColor','k'); |
---|
| 147 | end |
---|
| 148 | end |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | %set limits on corrector plot |
---|
| 152 | ylim = get(SYS.ahcor,'YLim'); |
---|
| 153 | |
---|
| 154 | %vertical bar on selected corrector |
---|
| 155 | SYS.lhcid = line('parent',SYS.ahcor,... |
---|
| 156 | 'XData',[xd(COR(plane).id),xd(COR(plane).id)+0.001],... |
---|
| 157 | 'YData',[ylim(1),ylim(2)],'Color','k'); |
---|
| 158 | set(SYS.lhcid,'ButtonDownFcn','corgui(''CorSelect'')'); |
---|
| 159 | |
---|
| 160 | corgui('ylimits'); |
---|
| 161 | |
---|
| 162 | %=========================================================== |
---|
| 163 | case 'Fract' %*** Fract *** |
---|
| 164 | %=========================================================== |
---|
| 165 | %callback of the text box used to set fraction |
---|
| 166 | h1 = SYS.fract; |
---|
| 167 | fract = str2double(get(h1,'String')); |
---|
| 168 | |
---|
| 169 | if isnan(fract) || ~isnumeric(fract) || ~length(fract) == 1 |
---|
| 170 | % flush the bad string out of the edit; replace with current value: |
---|
| 171 | set(h1,'String',num2str(COR(plane).fract)); |
---|
| 172 | disp('Warning: Invalid fraction entry.'); |
---|
| 173 | orbgui('LBox','Warning: Invalid fraction entry'); |
---|
| 174 | return; |
---|
| 175 | else |
---|
| 176 | COR(plane).fract = fract; |
---|
| 177 | %NOTE: fraction scalar only used at time of corrector application |
---|
| 178 | % respgui('UpdateFit'); |
---|
| 179 | % orbgui('RefreshOrbGUI'); |
---|
| 180 | end |
---|
| 181 | |
---|
| 182 | %=========================================================== |
---|
| 183 | case 'ApplyCorrection' %*** ApplyCorrection *** |
---|
| 184 | %=========================================================== |
---|
| 185 | %Apply orbit correction |
---|
| 186 | if ~isempty(COR(plane).ifit) || RSP(plane).rfflag |
---|
| 187 | orbgui('LBox',' Apply Correction for current plane'); |
---|
| 188 | corgui('ApplyFit'); |
---|
| 189 | else |
---|
| 190 | orbgui('LBox',' Correction not valid for current plane'); |
---|
| 191 | end |
---|
| 192 | |
---|
| 193 | %=========================================================== |
---|
| 194 | case 'RemoveCorrection' %*** RemoveCorrection *** |
---|
| 195 | %=========================================================== |
---|
| 196 | %restore to corrector pattern prior to 'ApplyFit' |
---|
| 197 | |
---|
| 198 | if ~isempty(COR(plane).ifit) || RSP(plane).rfflag |
---|
| 199 | orbgui('LBox',' Removing Correction'); |
---|
| 200 | |
---|
| 201 | if COR(plane).ifit % Corrector magnet part |
---|
| 202 | %NOTE: corrector pattern (.act) measured at time of fit in RefreshOrbGUI |
---|
| 203 | |
---|
| 204 | % Select good status correctors |
---|
| 205 | status = COR(plane).status; |
---|
| 206 | val = COR(plane).rst(status); |
---|
| 207 | %restore values |
---|
| 208 | setsp(COR(plane).AOFamily,val,status,SYS.mode); |
---|
| 209 | end |
---|
| 210 | |
---|
| 211 | if RSP(plane).rfflag % RF part |
---|
| 212 | stepsp('RF', -SYS.drfrst, SYS.mode); |
---|
| 213 | end |
---|
| 214 | |
---|
| 215 | % Update gui |
---|
| 216 | bpmgui('GetAct'); |
---|
| 217 | corgui('GetAct'); |
---|
| 218 | orbgui('RefreshOrbGUI'); |
---|
| 219 | else |
---|
| 220 | orbgui('LBox',' Correction not valid for current plane'); |
---|
| 221 | end |
---|
| 222 | |
---|
| 223 | %=========================================================== |
---|
| 224 | case 'ApplyFit' %*** ApplyFit *** |
---|
| 225 | %=========================================================== |
---|
| 226 | %apply corrector fit pattern scaled by fract |
---|
| 227 | %NOTE: corrector pattern (.act) measured at time of fit in RefreshOrbGUI |
---|
| 228 | |
---|
| 229 | if ~isempty(COR(plane).ifit) % corrector magnet part |
---|
| 230 | % Actual value + fitted value |
---|
| 231 | val = COR(plane).act(COR(plane).ifit) + ... |
---|
| 232 | COR(plane).fract*COR(plane).fit; |
---|
| 233 | |
---|
| 234 | % Test if saturation |
---|
| 235 | istoobig = (abs(val) > COR(plane).lim(COR(plane).ifit)); |
---|
| 236 | if sum(istoobig) ~= 0 |
---|
| 237 | orbgui('LBox',' Warning: cannot apply correction strength too large'); |
---|
| 238 | return; |
---|
| 239 | end |
---|
| 240 | |
---|
| 241 | %load restore field to enable corrector pattern removal |
---|
| 242 | COR(plane).rst = COR(plane).act; |
---|
| 243 | |
---|
| 244 | % Set new current values |
---|
| 245 | setsp(COR(plane).AOFamily,val,COR(plane).ifit,SYS.mode); |
---|
| 246 | pause(2); % pause for letting correctors reach their final value % (should be a special flag in setsp) |
---|
| 247 | end |
---|
| 248 | |
---|
| 249 | if RSP(plane).rfflag % Apply RF correction |
---|
| 250 | stepsp('RF',COR(plane).fract*SYS.drf, SYS.mode); |
---|
| 251 | %load restore field to enable corrector pattern removal |
---|
| 252 | SYS.drfrst = COR(plane).fract*SYS.drf; |
---|
| 253 | end |
---|
| 254 | |
---|
| 255 | setappdata(0,'SYS',SYS); |
---|
| 256 | bpmgui('GetAct'); |
---|
| 257 | corgui('GetAct'); |
---|
| 258 | orbgui('RefreshOrbGUI'); |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | %========================================================== |
---|
| 262 | case 'UpdateCorrs' % *** UpdateCorrs *** |
---|
| 263 | %========================================================== |
---|
| 264 | %callback of the 'refresh corrector' button |
---|
| 265 | %acquire corrector readbacks, plot, re-calculate fit |
---|
| 266 | corgui('UpdateAct'); |
---|
| 267 | orbgui('RefreshOrbGUI'); |
---|
| 268 | |
---|
| 269 | %========================================================== |
---|
| 270 | case 'GetAct' % *** GetAct *** |
---|
| 271 | %========================================================== |
---|
| 272 | %get readback corrector values from database |
---|
| 273 | %load values into full length array slots with valid status |
---|
| 274 | |
---|
| 275 | % H-correctors |
---|
| 276 | status = COR(1).status; |
---|
| 277 | COR(1).act(status) = getam(COR(1).AOFamily,[],SYS.mode); |
---|
| 278 | % V-correctors |
---|
| 279 | status = COR(2).status; |
---|
| 280 | COR(2).act(status) = getam(COR(2).AOFamily,[],SYS.mode); |
---|
| 281 | |
---|
| 282 | setappdata(0,'COR',COR); |
---|
| 283 | |
---|
| 284 | %========================================================== |
---|
| 285 | case 'UpdateAct' % *** UpdateAct *** |
---|
| 286 | %========================================================== |
---|
| 287 | %callback of the 'refresh corrector' button |
---|
| 288 | %acquire corrector readbacks and plot |
---|
| 289 | |
---|
| 290 | corgui('GetAct'); |
---|
| 291 | corgui('PlotAct'); |
---|
| 292 | corgui('UpdateCorBox'); |
---|
| 293 | orbgui('LBox',' Refresh Corrector Setpoints'); |
---|
| 294 | |
---|
| 295 | %========================================================== |
---|
| 296 | case 'PlotAct' % *** PlotAct *** |
---|
| 297 | %========================================================== |
---|
| 298 | %draw stem plot for the actual corrector values. |
---|
| 299 | %act contains real values |
---|
| 300 | |
---|
| 301 | %scale start patch |
---|
| 302 | ah = get(SYS.ahcor); |
---|
| 303 | set(orbfig,'currentaxes',SYS.ahcor) |
---|
| 304 | |
---|
| 305 | xd = orbgui('GetAbscissa',SYS,'COR'); |
---|
| 306 | |
---|
| 307 | nstat = length(COR(plane).act); |
---|
| 308 | kk = (1:nstat)'; |
---|
| 309 | colorcell = repmat({'g'},nstat,1); %green for fit |
---|
| 310 | colorcell(setdiff(kk,COR(plane).ifit)) = {'y'}; %yellow for no fit |
---|
| 311 | colorcell(setdiff(kk,COR(plane).status)) = {'k'}; %black for not available |
---|
| 312 | |
---|
| 313 | if strcmpi(COR(plane).units,'Physics') == 1 |
---|
| 314 | fact = COR(plane).hw2physics; |
---|
| 315 | else |
---|
| 316 | fact = 1; |
---|
| 317 | end |
---|
| 318 | |
---|
| 319 | yd = zeros(nstat,1); |
---|
| 320 | idx = intersect(kk,COR(plane).status); |
---|
| 321 | yd(idx) = COR(plane).act(idx); |
---|
| 322 | yd = yd*fact; |
---|
| 323 | |
---|
| 324 | set(COR(plane).hact(:,1),{'XData'},num2cell(xd),{'YData'}, ... |
---|
| 325 | num2cell(yd),{'MarkerFaceColor'},colorcell); |
---|
| 326 | set(COR(plane).hact(:,2),{'XData'},num2cell([xd xd],2), ... |
---|
| 327 | {'YData'},num2cell([0*yd yd],2)); |
---|
| 328 | |
---|
| 329 | % for kk = 1:size(COR(plane).name,1) |
---|
| 330 | % yd = 0.0; %default corrector value |
---|
| 331 | % color = 'k'; %default black if not in status vector |
---|
| 332 | % if ~isempty(find(COR(plane).status == kk)) |
---|
| 333 | % color = 'y'; %yellow for available |
---|
| 334 | % yd = COR(plane).act(kk); |
---|
| 335 | % end |
---|
| 336 | % |
---|
| 337 | % if ~isempty(COR(plane).ifit); |
---|
| 338 | % if ~isempty(find(COR(plane).ifit == kk)) |
---|
| 339 | % color = 'g'; |
---|
| 340 | % end |
---|
| 341 | % end |
---|
| 342 | % |
---|
| 343 | % if strcmpi(COR(plane).units,'Physics') == 1 |
---|
| 344 | % fact = COR(plane).hw2physics; |
---|
| 345 | % else |
---|
| 346 | % fact = 1; |
---|
| 347 | % end |
---|
| 348 | % |
---|
| 349 | % set(COR(plane).hact(kk,1),'XData',xd(kk),'YData', ... |
---|
| 350 | % yd*fact,'MarkerFaceColor',color); |
---|
| 351 | % set(COR(plane).hact(kk,2),'XData',[xd(kk) xd(kk)], ... |
---|
| 352 | % 'YData',[0 yd*fact]); |
---|
| 353 | % end %end loop over all correctors |
---|
| 354 | |
---|
| 355 | corgui('ylimits'); |
---|
| 356 | |
---|
| 357 | %========================================================== |
---|
| 358 | case 'PlotFit' % *** PlotFit *** |
---|
| 359 | %========================================================== |
---|
| 360 | %draw stem plot for the total predicted corrector values after fitting |
---|
| 361 | %note:COR(plane).fit is compressed |
---|
| 362 | |
---|
| 363 | if isempty(COR(plane).fit) |
---|
| 364 | return |
---|
| 365 | end |
---|
| 366 | |
---|
| 367 | xd = orbgui('GetAbscissa',SYS,'COR'); |
---|
| 368 | |
---|
| 369 | len = length(COR(plane).ifit); |
---|
| 370 | idx = COR(plane).ifit(1:len); %get indices |
---|
| 371 | xd = xd(idx); |
---|
| 372 | yd = COR(plane).act(idx) + COR(plane).fit(1:len); % new value |
---|
| 373 | |
---|
| 374 | if strcmpi(COR(plane).units,'Physics') == 1 |
---|
| 375 | fact = COR(plane).hw2physics; |
---|
| 376 | else |
---|
| 377 | fact = 1; |
---|
| 378 | end |
---|
| 379 | yd = yd *fact; |
---|
| 380 | |
---|
| 381 | set(COR(plane).hfit(idx,1),{'Xdata'}, num2cell(xd), ... |
---|
| 382 | {'YData'}, num2cell(yd)); |
---|
| 383 | set(COR(plane).hfit(idx,2),{'Xdata'},num2cell([xd xd],2), ... |
---|
| 384 | {'YData'}, num2cell([0*yd yd],2)); |
---|
| 385 | |
---|
| 386 | % for kk = 1:length(COR(plane).ifit) |
---|
| 387 | % k = COR(plane).ifit(kk); |
---|
| 388 | % yd = COR(plane).act(k) + COR(plane).fit(kk); |
---|
| 389 | % |
---|
| 390 | % if strcmpi(COR(plane).units,'Physics') ==1 |
---|
| 391 | % fact = COR(plane).hw2physics; |
---|
| 392 | % else |
---|
| 393 | % fact = 1; |
---|
| 394 | % end |
---|
| 395 | % |
---|
| 396 | % set(COR(plane).hfit(k,1),'Xdata', xd(k),'YData', yd*fact); |
---|
| 397 | % set(COR(plane).hfit(k,2),'Xdata',[xd(k) xd(k)],'YData',[0 yd*fact]); |
---|
| 398 | % end |
---|
| 399 | % corgui('ylimits'); |
---|
| 400 | |
---|
| 401 | %========================================================== |
---|
| 402 | case 'ClearFit' % *** ClearFit *** |
---|
| 403 | %========================================================== |
---|
| 404 | |
---|
| 405 | %clear horizontal fit |
---|
| 406 | set(COR(1).hfit(:,1),'YData',0); |
---|
| 407 | set(COR(1).hfit(:,2),'YData',[0 0]); |
---|
| 408 | |
---|
| 409 | %clear vertical fit |
---|
| 410 | set(COR(2).hfit(:,1),'YData',0); |
---|
| 411 | set(COR(2).hfit(:,2),'YData',[0 0]); |
---|
| 412 | |
---|
| 413 | %========================================================== |
---|
| 414 | case 'ClearPlots' % *** Clearplots *** |
---|
| 415 | %========================================================== |
---|
| 416 | corgui('ClearFit'); |
---|
| 417 | |
---|
| 418 | %clear horizontal actuals |
---|
| 419 | set(COR(1).hact(:,1),'YData',0); |
---|
| 420 | set(COR(1).hact(:,2),'YData',[0 0]); |
---|
| 421 | %clear vertical actuals |
---|
| 422 | set(COR(2).hact(:,1),'YData',0); |
---|
| 423 | set(COR(2).hact(:,2),'YData',[0 0]); |
---|
| 424 | |
---|
| 425 | %========================================================== |
---|
| 426 | case 'ShowPlots' % *** Showplots *** |
---|
| 427 | %========================================================== |
---|
| 428 | %hide stem plots for current plane |
---|
| 429 | set(COR(plane).hact,'Visible','On'); |
---|
| 430 | set(COR(plane).hfit,'Visible','On'); |
---|
| 431 | |
---|
| 432 | %========================================================== |
---|
| 433 | case 'HidePlots' % *** Hideplots *** |
---|
| 434 | %========================================================== |
---|
| 435 | %hide stem plots for current plane |
---|
| 436 | set(COR(plane).hact,'Visible','Off'); |
---|
| 437 | set(COR(plane).hfit,'Visible','Off'); |
---|
| 438 | |
---|
| 439 | %============================================================= |
---|
| 440 | case 'RePlot' % *** RePlot *** |
---|
| 441 | %============================================================= |
---|
| 442 | corgui('ClearPlots'); |
---|
| 443 | set(orbfig,'currentaxes',SYS.ahcor) |
---|
| 444 | corgui('PlotAct'); %plot actual correctors |
---|
| 445 | corgui('PlotFit'); %plot fitted correctors |
---|
| 446 | corgui('ylimits'); |
---|
| 447 | corgui('CorBar'); |
---|
| 448 | |
---|
| 449 | %============================================================= |
---|
| 450 | case 'ylimits' % *** ylimits *** |
---|
| 451 | %============================================================= |
---|
| 452 | %compute vertical axes limits for corrector plot |
---|
| 453 | |
---|
| 454 | if COR(plane).scalemode == 0 |
---|
| 455 | return; %manual mode |
---|
| 456 | end |
---|
| 457 | |
---|
| 458 | orbgui('AutoScaleCorrAxis'); |
---|
| 459 | % mxfit = 0; |
---|
| 460 | % if ~isempty(COR(plane).ifit) |
---|
| 461 | % mxfit = max(abs(COR(plane).fit(:) + COR(plane).act(COR(plane).ifit))); |
---|
| 462 | % end |
---|
| 463 | % |
---|
| 464 | % mxact = max(abs(COR(plane).act(COR(plane).status))); |
---|
| 465 | % |
---|
| 466 | % ylim = max(mxfit, mxact)*1.1; |
---|
| 467 | % |
---|
| 468 | % if strcmpi(COR(plane).units,'Physics') == 1 |
---|
| 469 | % fact = COR(plane).hw2physics; |
---|
| 470 | % else |
---|
| 471 | % fact = 1; |
---|
| 472 | % end |
---|
| 473 | % |
---|
| 474 | % ylim = ylim*fact; |
---|
| 475 | % |
---|
| 476 | % %% Saturation @ 10 um |
---|
| 477 | % if ylim < 0.01 |
---|
| 478 | % ylim = 0.01; |
---|
| 479 | % end |
---|
| 480 | % |
---|
| 481 | % set(SYS.ahcor,'YLim',ylim*[-1, 1]); |
---|
| 482 | |
---|
| 483 | %============================================================= |
---|
| 484 | case 'CorSelect' % *** CorSelect *** |
---|
| 485 | %============================================================= |
---|
| 486 | %used if mouse clicks anywhere in COR window |
---|
| 487 | cpa = get(SYS.ahcor,'CurrentPoint'); |
---|
| 488 | pos = cpa(1); % current position |
---|
| 489 | |
---|
| 490 | switch SYS.xscale |
---|
| 491 | case 'meter' |
---|
| 492 | id = find(min(abs(COR(plane).s-pos)) == abs(COR(plane).s-pos)); |
---|
| 493 | case 'phase' |
---|
| 494 | id = find(min(abs(COR(plane).phi-pos)) == abs(COR(plane).phi-pos)); |
---|
| 495 | end |
---|
| 496 | |
---|
| 497 | COR(plane).id = id; |
---|
| 498 | |
---|
| 499 | setappdata(0,'COR',COR); |
---|
| 500 | |
---|
| 501 | c = COR(plane).hact(id,1); %...get handle |
---|
| 502 | |
---|
| 503 | corgui('ProcessCor',id,c); |
---|
| 504 | corgui('CorBar'); |
---|
| 505 | |
---|
| 506 | %============================================================= |
---|
| 507 | case 'CorDown' % *** CorDown *** |
---|
| 508 | %============================================================= |
---|
| 509 | c = gcbo; |
---|
| 510 | ctag = get(c,'tag'); |
---|
| 511 | id = str2double(ctag(4:length(ctag))); %strip off 'c/plane_' to get the cor index |
---|
| 512 | corgui('ProcessCor',id,c); |
---|
| 513 | |
---|
| 514 | %============================================================= |
---|
| 515 | case 'ProcessCor' % *** ProcessCor *** |
---|
| 516 | %============================================================= |
---|
| 517 | %This function is activated whenever the left mouse button is pressed inside a BPM patch. |
---|
| 518 | %It sets up corfig to interpret movement of the mouse and also puts data about the |
---|
| 519 | %particular cor into the text fields. |
---|
| 520 | |
---|
| 521 | %identify COR handle and number |
---|
| 522 | id = varargin{1}; %corrector index 'id' comes through varargin |
---|
| 523 | c = varargin{2}; %bpm handle 'c' comes through varargin |
---|
| 524 | %c = gcbo; |
---|
| 525 | %cortag = get(c,'tag'); |
---|
| 526 | %id = str2num(cortag(2:length(cortag))); %strip off 'c' to get the cor index |
---|
| 527 | |
---|
| 528 | if COR(plane).mode == 1 %Correctors in toggle mode |
---|
| 529 | first = 0; |
---|
| 530 | if isempty(COR(plane).ifit) %no CORs chosen |
---|
| 531 | COR(plane).ifit(1) = id; |
---|
| 532 | set(c,'MarkerFaceColor','g'); %add to fit list |
---|
| 533 | first = 1; |
---|
| 534 | setappdata(0,'COR',COR); |
---|
| 535 | end |
---|
| 536 | |
---|
| 537 | if ~isempty(find(COR(plane).ifit == id,1)) && first == 0 %presently selected for fit |
---|
| 538 | set(c,'MarkerFaceColor','y'); |
---|
| 539 | COR(plane).ifit(find(COR(plane).ifit == id)) = 0; %set fit vector to zero |
---|
| 540 | COR(plane).ifit = COR(plane).ifit(find(COR(plane).ifit)); % compress data |
---|
| 541 | % nfit = length(COR(plane).ifit); %compute vector length used ??? |
---|
| 542 | setappdata(0,'COR',COR); |
---|
| 543 | |
---|
| 544 | elseif isempty(find(COR(plane).ifit == id,1)) && ... |
---|
| 545 | ~isempty(find(COR(plane).avail == id, 1)) |
---|
| 546 | %Corrector added to OK for fit |
---|
| 547 | %elseif ~isempty(find(COR(plane).avail==id)) %corrector is available |
---|
| 548 | set(c,'MarkerFaceColor','g'); |
---|
| 549 | t = COR(plane).ifit; |
---|
| 550 | t = t(find(t)); % number 1 to 56 out of 120 for instance |
---|
| 551 | t = sort([t; id]); % add to fit list |
---|
| 552 | COR(plane).ifit = t; % updated corrector list for fit |
---|
| 553 | % nfit = length(COR(plane).ifit); % used ??? |
---|
| 554 | setappdata(0,'COR',COR); |
---|
| 555 | end |
---|
| 556 | |
---|
| 557 | orbgui('RefreshOrbGUI'); |
---|
| 558 | else |
---|
| 559 | corgui('UpdateCorBox'); |
---|
| 560 | end %end toggle mode condition |
---|
| 561 | |
---|
| 562 | set(orbfig,'WindowButtonUpFcn','corgui(''Up'')'); |
---|
| 563 | |
---|
| 564 | %update response matrix column plot |
---|
| 565 | if strcmpi(RSP(plane).disp(1:3), 'off') %Response display mode |
---|
| 566 | set(SYS.lhrsp,'XData',[],'YData',[]); |
---|
| 567 | else |
---|
| 568 | bpmgui('PlotResp'); %plot matrix column vector |
---|
| 569 | end |
---|
| 570 | |
---|
| 571 | %============================================================= |
---|
| 572 | case 'CorBar' % *** CorBar *** |
---|
| 573 | %============================================================= |
---|
| 574 | %move black line in window to indicate selection |
---|
| 575 | id = COR(plane).id; |
---|
| 576 | ylim = get(SYS.ahcor,'YLim'); |
---|
| 577 | |
---|
| 578 | |
---|
| 579 | if isempty(find(COR(plane).status == id, 1)) |
---|
| 580 | yd = ylim/4; |
---|
| 581 | else |
---|
| 582 | yd = COR(plane).act(id) + ylim/4; |
---|
| 583 | end |
---|
| 584 | |
---|
| 585 | |
---|
| 586 | xd = orbgui('GetAbscissa',SYS,'COR'); %horizontal coordinates for plotting |
---|
| 587 | xd = [xd(id) xd(id) + 0.001]; |
---|
| 588 | |
---|
| 589 | set(SYS.lhcid,'XData',xd,'YData',yd); |
---|
| 590 | |
---|
| 591 | %============================================================= |
---|
| 592 | case 'UpdateCorBox' % *** UpdateCorBox *** |
---|
| 593 | %============================================================= |
---|
| 594 | %update UpdateCorBox |
---|
| 595 | %called from orbgui(RefreshOrbGUI), corgui(UpdateCorrs), |
---|
| 596 | id = COR(plane).id; |
---|
| 597 | %put fit value in offset box and in request box |
---|
| 598 | fitindx = []; |
---|
| 599 | if ~isempty(COR(plane).ifit) |
---|
| 600 | fitindx = find(COR(plane).ifit == id); |
---|
| 601 | end |
---|
| 602 | |
---|
| 603 | if ~isempty(fitindx) |
---|
| 604 | offset = COR(plane).fit(fitindx); |
---|
| 605 | request = COR(plane).act(id)+offset; |
---|
| 606 | else |
---|
| 607 | offset = 0.0; |
---|
| 608 | request = COR(plane).act(id); |
---|
| 609 | end |
---|
| 610 | |
---|
| 611 | % mean val |
---|
| 612 | meanV = mean(COR(plane).act(COR(plane).status)); |
---|
| 613 | % rms val |
---|
| 614 | sigma = std(COR(plane).act(COR(plane).status)); |
---|
| 615 | |
---|
| 616 | corgui('CorBox',COR(plane).name(id,:),COR(plane).act(id),... |
---|
| 617 | COR(plane).save(id),offset,request,... |
---|
| 618 | meanV,sigma,id); |
---|
| 619 | |
---|
| 620 | %============================================================= |
---|
| 621 | case 'CorBox' % *** CorBox *** |
---|
| 622 | %============================================================= |
---|
| 623 | %called from |
---|
| 624 | %corgui('CorBox',COR(plane).name(id,:),COR(plane).act(id),... |
---|
| 625 | % COR(plane).ref(id),id); |
---|
| 626 | corname = SYS.corname; |
---|
| 627 | actual = SYS.coract; |
---|
| 628 | reference = SYS.corref; |
---|
| 629 | offset = SYS.coroffset; |
---|
| 630 | request = SYS.correq; |
---|
| 631 | rmsval = SYS.cormean; |
---|
| 632 | meanval = SYS.corrms; |
---|
| 633 | |
---|
| 634 | name = varargin{1}; |
---|
| 635 | act = varargin{2}; |
---|
| 636 | ref = varargin{3}; |
---|
| 637 | off = varargin{4}; |
---|
| 638 | req = varargin{5}; |
---|
| 639 | rms = varargin{6}; |
---|
| 640 | meanV= varargin{7}; |
---|
| 641 | id = varargin{8}; |
---|
| 642 | |
---|
| 643 | if strcmpi(COR(plane).units,'Physics') == 1 |
---|
| 644 | fact = COR(plane).hw2physics; |
---|
| 645 | else |
---|
| 646 | fact = 1; |
---|
| 647 | end |
---|
| 648 | |
---|
| 649 | % conversion in device list |
---|
| 650 | dev = elem2dev(COR(plane).AOFamily,id); |
---|
| 651 | |
---|
| 652 | set(corname, 'String',[name ' [',num2str(dev(1)),' ', ... |
---|
| 653 | num2str(dev(2)),']']); |
---|
| 654 | set(actual, 'String',num2str(act*fact, '%6.3f')); |
---|
| 655 | set(reference,'String',num2str(ref*fact, '%6.3f')); |
---|
| 656 | set(offset, 'String',num2str(off*fact, '%6.3f')); |
---|
| 657 | set(meanval, 'String',num2str(meanV*fact, '%6.3f')); |
---|
| 658 | set(rmsval, 'String',num2str(rms*fact, '%6.3f')); |
---|
| 659 | set(request, 'String',num2str(req*fact, '%6.3f')); |
---|
| 660 | |
---|
| 661 | %============================================================= |
---|
| 662 | case 'Up' % *** Up *** |
---|
| 663 | %============================================================= |
---|
| 664 | %once the mouse button is let up, don't respond to motion any more. |
---|
| 665 | |
---|
| 666 | set(orbfig,'WindowButtonMotionFcn','','WindowButtonUpFcn',''); |
---|
| 667 | |
---|
| 668 | %============================================================= |
---|
| 669 | case 'CORmove' % *** CORmove *** |
---|
| 670 | %============================================================= |
---|
| 671 | %empty for now: can't drag correctors |
---|
| 672 | return; |
---|
| 673 | |
---|
| 674 | %============================================================= |
---|
| 675 | case 'SelectAll' % *** SelectAll *** |
---|
| 676 | %============================================================ |
---|
| 677 | %load all available correctors into ifit field |
---|
| 678 | COR(plane).ifit = []; |
---|
| 679 | |
---|
| 680 | set(COR(plane).hact(COR(plane).avail,1),'MarkerFaceColor','g'); |
---|
| 681 | vavail = 1:length(COR(plane).avail); |
---|
| 682 | COR(plane).ifit(vavail) = COR(plane).avail; |
---|
| 683 | |
---|
| 684 | % for kk = 1:length(COR(plane).avail) |
---|
| 685 | % k = COR(plane).avail(kk); |
---|
| 686 | % h1 = COR(plane).hact(k,1); %k,1 is the icon |
---|
| 687 | % set(h1,'MarkerFaceColor','g'); |
---|
| 688 | % COR(plane).ifit(kk)=k; |
---|
| 689 | % end |
---|
| 690 | |
---|
| 691 | COR(plane).ifit = COR(plane).ifit(:); |
---|
| 692 | setappdata(0,'COR',COR); |
---|
| 693 | |
---|
| 694 | corgui('ClearFit'); %be sure to remove residual red corrector bars |
---|
| 695 | orbgui('RefreshOrbGUI'); |
---|
| 696 | |
---|
| 697 | %============================================================= |
---|
| 698 | case 'SelectNone' % *** SelectNone *** |
---|
| 699 | %============================================================= |
---|
| 700 | COR(plane).ifit = []; |
---|
| 701 | COR(plane).fit = []; |
---|
| 702 | |
---|
| 703 | set(COR(plane).hact(COR(plane).avail,1),'MarkerFaceColor','y'); |
---|
| 704 | |
---|
| 705 | % for kk = 1:length(COR(plane).avail) |
---|
| 706 | % k = COR(plane).avail(kk); |
---|
| 707 | % h1 = COR(plane).hact(k,1); %k,1 is the icon |
---|
| 708 | % set(h1,'MarkerFaceColor','y'); |
---|
| 709 | % end |
---|
| 710 | |
---|
| 711 | setappdata(0,'COR',COR); |
---|
| 712 | |
---|
| 713 | RSP(plane).nsvd = 1; |
---|
| 714 | RSP(plane).nsvdmax = 1; |
---|
| 715 | setappdata(0,'RSP',RSP); |
---|
| 716 | |
---|
| 717 | orbgui('RefreshOrbGUI'); |
---|
| 718 | %respgui('FitOff',num2str(plane)); |
---|
| 719 | |
---|
| 720 | %========================================================== |
---|
| 721 | case 'ToggleCor' % ToggleCor |
---|
| 722 | %========================================================== |
---|
| 723 | h1 = SYS.togglecor; |
---|
| 724 | val = get(h1,'Value'); |
---|
| 725 | if val == 0 %radio was on, push turned off |
---|
| 726 | COR(plane).mode = 0; %'0' for display |
---|
| 727 | elseif val == 1 %radio was off, push turned on |
---|
| 728 | COR(plane).mode = 1; %'1' for toggle |
---|
| 729 | end |
---|
| 730 | setappdata(0,'COR',COR); |
---|
| 731 | |
---|
| 732 | %========================================================== |
---|
| 733 | case 'ShowResp' % ShowResp |
---|
| 734 | %========================================================== |
---|
| 735 | %toggle the 'showresp' flag to display columns of response matrix |
---|
| 736 | %plotting in bpmgui('PlotResp') |
---|
| 737 | |
---|
| 738 | %first make sure eigenvector display is off |
---|
| 739 | val = get(SYS.showeig,'Checked'); |
---|
| 740 | if strcmpi(val,'On') %radio on, turn off |
---|
| 741 | % RSP(plane).eig = 'off'; |
---|
| 742 | setappdata(0,'RSP',RSP); |
---|
| 743 | set(SYS.lheig,'XData',[],'YData',[]); |
---|
| 744 | set(SYS.showeig,'Checked','Off'); |
---|
| 745 | end |
---|
| 746 | |
---|
| 747 | val = get(SYS.showresp,'Checked'); |
---|
| 748 | %RSP=getappdata(0,'RSP'); |
---|
| 749 | if strcmpi(val,'on') %radio was on, push turned off |
---|
| 750 | % RSP(plane).disp = 'off'; |
---|
| 751 | set(SYS.lhrsp,'XData',[],'YData',[]); |
---|
| 752 | set(SYS.showresp,'Checked','Off'); |
---|
| 753 | elseif strcmpi(val,'off') %radio was off, push turned on |
---|
| 754 | % RSP(plane).disp = 'on'; |
---|
| 755 | setappdata(0,'RSP',RSP); |
---|
| 756 | bpmgui('PlotResp'); |
---|
| 757 | set(SYS.showresp,'Checked','On'); |
---|
| 758 | end |
---|
| 759 | |
---|
| 760 | %========================================================== |
---|
| 761 | case 'ShowEig' % ShowEig |
---|
| 762 | %========================================================== |
---|
| 763 | %toggle state to show eigenvectors |
---|
| 764 | %first make sure response matrix display is off |
---|
| 765 | |
---|
| 766 | val = get(SYS.showresp,'Checked'); |
---|
| 767 | if strcmpi(val, 'On') %radio on, turn off |
---|
| 768 | RSP(plane).disp = 'off'; |
---|
| 769 | set(SYS.lhrsp,'XData',[],'YData',[]); |
---|
| 770 | set(SYS.showresp,'Checked','Off'); |
---|
| 771 | end |
---|
| 772 | |
---|
| 773 | val = get(SYS.showeig,'Checked'); |
---|
| 774 | if strcmpi(val, 'On') %radio was on, push turned off |
---|
| 775 | % RSP(plane).eig = 'off'; |
---|
| 776 | set(SYS.lheig,'XData',[],'YData',[]); |
---|
| 777 | set(SYS.showeig,'Checked','Off'); |
---|
| 778 | elseif strcmpi(val, 'Off') %radio was off, push turned on |
---|
| 779 | % RSP(plane).eig = 'on'; |
---|
| 780 | bpmgui('PlotEig'); |
---|
| 781 | set(SYS.showeig,'Checked','On'); |
---|
| 782 | end |
---|
| 783 | |
---|
| 784 | %=========================================================== |
---|
| 785 | case 'SaveCors' %*** SaveCors *** |
---|
| 786 | %=========================================================== |
---|
| 787 | %Save Corrector Readbacks for RESET button |
---|
| 788 | plane = varargin{1}; |
---|
| 789 | |
---|
| 790 | % Corrector magnet part |
---|
| 791 | |
---|
| 792 | % Read true values for want all correctors |
---|
| 793 | val = getsp(COR(plane).AOFamily, SYS.mode); |
---|
| 794 | status = COR(plane).status; |
---|
| 795 | COR(plane).save(status) = val; |
---|
| 796 | |
---|
| 797 | % Set corrector save flag |
---|
| 798 | COR(plane).saveflag = 1; |
---|
| 799 | |
---|
| 800 | setappdata(0,'COR',COR); |
---|
| 801 | |
---|
| 802 | % RF part |
---|
| 803 | SYS.rfsave = getrf(SYS.mode); |
---|
| 804 | SYS.rfsaveflag = 1; |
---|
| 805 | |
---|
| 806 | setappdata(0,'SYS',SYS); |
---|
| 807 | |
---|
| 808 | %update corrector display |
---|
| 809 | corgui('UpdateCorBox'); |
---|
| 810 | |
---|
| 811 | orbgui('LBox',[' Corrector and RF saved for plane: ' num2str(plane)]); |
---|
| 812 | |
---|
| 813 | %=========================================================== |
---|
| 814 | case 'RestoreCors' %*** RestoreCors *** |
---|
| 815 | %=========================================================== |
---|
| 816 | %restore correctors to saved values |
---|
| 817 | if ~COR(plane).saveflag || ~SYS.rfsaveflag |
---|
| 818 | orbgui('LBox',[' Corrector pattern not saved for plane: ' ... |
---|
| 819 | num2str(plane)]); |
---|
| 820 | return |
---|
| 821 | end |
---|
| 822 | |
---|
| 823 | if COR(plane).saveflag % Corrector magnet |
---|
| 824 | %Get saved corrector values |
---|
| 825 | val = COR(plane).save; |
---|
| 826 | status = COR(plane).status; |
---|
| 827 | |
---|
| 828 | % set back coorector values |
---|
| 829 | setsp(COR(plane).AOFamily, val(status), status, SYS.mode); |
---|
| 830 | |
---|
| 831 | orbgui('LBox',[' Corrector pattern restored for plane: ' num2str(plane)]); |
---|
| 832 | end |
---|
| 833 | |
---|
| 834 | if SYS.rfsaveflag % RF part |
---|
| 835 | setrf(SYS.rfsave, SYS.mode); |
---|
| 836 | orbgui('LBox','RF frequency restored '); |
---|
| 837 | end |
---|
| 838 | |
---|
| 839 | %% Update gui |
---|
| 840 | bpmgui('GetAct'); |
---|
| 841 | corgui('GetAct'); |
---|
| 842 | orbgui('RefreshOrbGUI'); |
---|
| 843 | |
---|
| 844 | % %============================================================== |
---|
| 845 | % case 'MakeOrbitSlider' % MakeOrbitSlider |
---|
| 846 | % %============================================================== |
---|
| 847 | % %figure to create bump sliders and/or write files |
---|
| 848 | % |
---|
| 849 | % [screen_wide, screen_high]=screensizecm; |
---|
| 850 | % fig_start = [0.4*screen_wide 0.5*screen_high]; |
---|
| 851 | % fig_size = [0.4*screen_wide 0.25*screen_high]; |
---|
| 852 | % |
---|
| 853 | % h = findobj(0,'tag','makeorbitslider'); |
---|
| 854 | % if ~isempty(h) |
---|
| 855 | % delete(h); |
---|
| 856 | % end |
---|
| 857 | % |
---|
| 858 | % if SYS.plane==1 |
---|
| 859 | % planestr = 'Horizontal '; |
---|
| 860 | % else |
---|
| 861 | % planestr = 'Vertical'; |
---|
| 862 | % end |
---|
| 863 | % |
---|
| 864 | % figh = figure('units','centimeters',... %...Figure |
---|
| 865 | % 'Position',[fig_start fig_size],'tag','makeorbitslider',... |
---|
| 866 | % 'NumberTitle','off','Doublebuffer','on','Visible','On','Name',[planestr 'corrector bump panel'],... |
---|
| 867 | % 'PaperPositionMode','Auto','MenuBar','None'); |
---|
| 868 | % %------------------------------------------------------------------ |
---|
| 869 | % path = getfamilydata('Directory','BumpData'); |
---|
| 870 | % filename = appendtimestamp('bump', clock); |
---|
| 871 | % |
---|
| 872 | % uicontrol('Style','Text',... %...Header |
---|
| 873 | % 'units', 'normalize', ... |
---|
| 874 | % 'Position', [.02 .8 .12 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 875 | % 'String','Header:','ToolTipString','Name of slider in gui display',... |
---|
| 876 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 877 | % |
---|
| 878 | % SYS.bumpheader=uicontrol('Style','Edit',... %...Header |
---|
| 879 | % 'units', 'normalize', ... |
---|
| 880 | % 'Position', [.2 .8 .4 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 881 | % 'String','Bump','ToolTipString','Name of slider in gui display',... |
---|
| 882 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 883 | % |
---|
| 884 | % uicontrol('Style','Text',... %...File Name |
---|
| 885 | % 'units', 'normalize', ... |
---|
| 886 | % 'Position', [.02 .7 .12 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 887 | % 'String','File Name:','ToolTipString','Name of file written to disk',... |
---|
| 888 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 889 | % |
---|
| 890 | % SYS.bumpfile=uicontrol('Style','Edit',... %...File Name |
---|
| 891 | % 'units', 'normalize', ... |
---|
| 892 | % 'Position', [.2 .7 .5 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 893 | % 'String',filename,'ToolTipString','Name of file written to disk',... |
---|
| 894 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 895 | % |
---|
| 896 | % uicontrol('Style','Text',... %...Save Directory |
---|
| 897 | % 'units', 'normalize', ... |
---|
| 898 | % 'Position', [.02 .6 .12 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 899 | % 'String','File Path','ToolTipString','Path of file written to disk',... |
---|
| 900 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 901 | % |
---|
| 902 | % SYS.bumppath=uicontrol('Style','Edit',... %...Save Directory |
---|
| 903 | % 'units', 'normalize', ... |
---|
| 904 | % 'Position', [.2 .6 .8 .08],'ForeGroundColor','k','HorizontalAlignment','Left',... |
---|
| 905 | % 'String',path,'ToolTipString','Path of file written to disk',... |
---|
| 906 | % 'FontSize',8,'FontWeight','demi'); |
---|
| 907 | % |
---|
| 908 | % uicontrol('Style','pushbutton',... %...Save Command |
---|
| 909 | % 'units', 'normalize', ... |
---|
| 910 | % 'Position', [.2 .3 .3 .1],'ForeGroundColor','k',... |
---|
| 911 | % 'String','Save file','ToolTipString','Write bump file to disk (do not launch slider)',... |
---|
| 912 | % 'FontSize',8,'FontWeight','demi','Callback',['corgui(''WriteBumpFile'');', 'close(''gcf'')']); |
---|
| 913 | % |
---|
| 914 | % uicontrol('Style','pushbutton',... %...Save & Launch Command |
---|
| 915 | % 'units', 'normalize', ... |
---|
| 916 | % 'Position', [.6 .3 .3 .1],'ForeGroundColor','k',... |
---|
| 917 | % 'String','Save file/Launch Slider','ToolTipString','Write bump file to disk and launch slider',... |
---|
| 918 | % 'FontSize',8,'FontWeight','demi','Callback','corgui(''LaunchBumpSlider'')'); |
---|
| 919 | % |
---|
| 920 | % uicontrol('Style','pushbutton',... %...cancel |
---|
| 921 | % 'units', 'normalize','Position', [.8 .08 .1 .1],'ForeGroundColor','k','String','cancel',... |
---|
| 922 | % 'Callback','delete(gcf)','FontSize',8,'FontWeight','demi'); |
---|
| 923 | % |
---|
| 924 | % %========================================================== |
---|
| 925 | % case 'WriteBumpFile' % *** WriteBumpFile *** |
---|
| 926 | % %========================================================== |
---|
| 927 | % %call of MakeOrbitSlider |
---|
| 928 | % %call function WriteBumpFile with corrector strengths |
---|
| 929 | % |
---|
| 930 | % if plane == 1 |
---|
| 931 | % Family = HCORFamily; |
---|
| 932 | % elseif plane == 2 |
---|
| 933 | % Family = VCORFamily; |
---|
| 934 | % end |
---|
| 935 | % |
---|
| 936 | % pv = common2tango(COR(plane).name(COR(plane).ifit,:),'Setpoint',Family); |
---|
| 937 | % delta = zeros(length(COR(plane).ifit),1); |
---|
| 938 | % for ii = 1:length(COR(plane).ifit) |
---|
| 939 | % jj = COR(plane).ifit(ii); |
---|
| 940 | % delta(ii,1) = COR(plane).fit(ii)-COR(plane).act(jj); |
---|
| 941 | % end |
---|
| 942 | % |
---|
| 943 | % header = get(SYS.bumpheader,'String'); |
---|
| 944 | % path = get(SYS.bumppath,'String'); |
---|
| 945 | % filename = get(SYS.bumpfile,'String'); |
---|
| 946 | % |
---|
| 947 | % if isempty(header) header = 'slider'; end |
---|
| 948 | % if isempty(path) path = getfamilydata('Directory','BumpFiles'); end |
---|
| 949 | % |
---|
| 950 | % set(SYS.bumppath,'String',path); %update so launchbumpslider has correct path |
---|
| 951 | % |
---|
| 952 | % if isempty(filename) filename = appendtimestamp('bump', clock); |
---|
| 953 | % if isempty(findstr(filename,'.m')) filename = [filename '.m']; end |
---|
| 954 | % set(SYS.bumpfile,'String',filename); %update so launchbumpslider has correct filename |
---|
| 955 | % end |
---|
| 956 | % |
---|
| 957 | % writebumpfile(pv,delta,header,path,filename); |
---|
| 958 | % orbgui('LBox',[' Bump File Created: ', filename]); |
---|
| 959 | % |
---|
| 960 | % %========================================================== |
---|
| 961 | % case 'LaunchBumpSlider' % *** LaunchBumpSlider *** |
---|
| 962 | % %========================================================== |
---|
| 963 | % %call of MakeOrbitSlider 'Save and Launch |
---|
| 964 | % %call function SingleSlider with corrector strengths |
---|
| 965 | % |
---|
| 966 | % corgui('WriteBumpFile'); %first write file |
---|
| 967 | % |
---|
| 968 | % header= get(SYS.bumpheader,'String'); |
---|
| 969 | % path= get(SYS.bumppath,'String'); |
---|
| 970 | % filename=get(SYS.bumpfile,'String'); |
---|
| 971 | % |
---|
| 972 | % if isempty(header) header='slider'; end |
---|
| 973 | % if isempty(path) path=getfamilydata('Directory','BumpFiles'); end |
---|
| 974 | % if isempty(filename) filename=appendtimestamp('bump', clock); end |
---|
| 975 | % |
---|
| 976 | % setappdata(0,'SliderIndex',1); |
---|
| 977 | % setappdata(0,'SliderFigHandle',gcf); |
---|
| 978 | % |
---|
| 979 | % singleslider(path,filename); |
---|
| 980 | |
---|
| 981 | |
---|
| 982 | %========================================================== |
---|
| 983 | case 'CorEdit' %...CorEdit |
---|
| 984 | %========================================================== |
---|
| 985 | %The callback of the single corrector edit box (not implemented) |
---|
| 986 | % |
---|
| 987 | h1 = SYS.corname; |
---|
| 988 | if ~isempty(get(h1,'String')) |
---|
| 989 | set(SYS.coredit,'String',num2str(0.0)); |
---|
| 990 | return |
---|
| 991 | |
---|
| 992 | end |
---|
| 993 | |
---|
| 994 | %=========================================================== |
---|
| 995 | case 'ShowCORState' %*** ShowCORState *** |
---|
| 996 | %=========================================================== |
---|
| 997 | |
---|
| 998 | % Show =corrector settings |
---|
| 999 | |
---|
| 1000 | len = size(COR(plane).name,1); |
---|
| 1001 | tavail = zeros(len,1); |
---|
| 1002 | tfit = zeros(len,1); |
---|
| 1003 | tifit = zeros(len,1); |
---|
| 1004 | tstatus = zeros(len,1); |
---|
| 1005 | |
---|
| 1006 | idx = intersect(COR(plane).avail,1:len); |
---|
| 1007 | tavail(idx) = idx; |
---|
| 1008 | idx = intersect(COR(plane).ifit,1:len); |
---|
| 1009 | tifit(idx) = idx; |
---|
| 1010 | tfit(idx) = COR(plane).fit; |
---|
| 1011 | idx = intersect(COR(plane).status,1:len); |
---|
| 1012 | tstatus(idx) = idx; |
---|
| 1013 | |
---|
| 1014 | % findx=1; |
---|
| 1015 | % for ind=1:length(COR(plane).name) |
---|
| 1016 | % if ~isempty(find(COR(plane).avail==ind)) tavail(ind)=ind; end |
---|
| 1017 | % if ~isempty(find(COR(plane).ifit==ind)) |
---|
| 1018 | % tifit(ind)=ind; |
---|
| 1019 | % tfit(ind)=COR(plane).fit(findx); |
---|
| 1020 | % findx=findx+1; |
---|
| 1021 | % end |
---|
| 1022 | % if ~isempty(find(COR(plane).status==ind)) tstatus(ind)=ind; end |
---|
| 1023 | % end |
---|
| 1024 | |
---|
| 1025 | %%% BUILD UP CELL TO DISPLAY |
---|
| 1026 | ivec = (1:len)'; |
---|
| 1027 | Strcell = cell(8,len); |
---|
| 1028 | Strcell(1,:) = num2cell(ivec); |
---|
| 1029 | Strcell(2,:) = cellstr(COR(plane).name(ivec,:))'; |
---|
| 1030 | Strcell(3:end,:) = num2cell([tstatus(ivec),tavail(ivec),tifit(ivec), ... |
---|
| 1031 | COR(plane).act(ivec),tfit(ivec),COR(plane).wt(ivec) ])'; |
---|
| 1032 | |
---|
| 1033 | %% Speed issue |
---|
| 1034 | % see bpmgui('ShowBPMState') for more details |
---|
| 1035 | |
---|
| 1036 | filename = [SYS.localdata 'cordata.txt']; |
---|
| 1037 | fid = fopen(filename,'w'); |
---|
| 1038 | fprintf(fid,'%s\n','index name stat avail ifit act fit weight'); |
---|
| 1039 | fprintf(fid,'%3d %10s %5d %5d %5d %10.3f %10.3f %10.3f\n', Strcell{:}); |
---|
| 1040 | fclose(fid) |
---|
| 1041 | % edit 'cordata.txt' |
---|
| 1042 | system(['nedit ', filename, ' &']); %much faster |
---|
| 1043 | |
---|
| 1044 | % fprintf('%s\n','index name stat avail ifit act fit weight'); |
---|
| 1045 | % for ind=1:length(COR(plane).name) |
---|
| 1046 | % fprintf('%3d %10s %5d %5d %5d %10.3f %10.3f %10.3f\n',... |
---|
| 1047 | % ind, COR(plane).name(ind,:),... |
---|
| 1048 | % tstatus(ind),tavail(ind),tifit(ind),COR(plane).act(ind),tfit(ind),COR(plane).wt(ind)); |
---|
| 1049 | % end |
---|
| 1050 | |
---|
| 1051 | % %========================================================== |
---|
| 1052 | % case 'MeasureXResp' % *** MeasureXResp *** |
---|
| 1053 | % %========================================================== |
---|
| 1054 | % %callback of the 'Measure X-Response' menu selection |
---|
| 1055 | % |
---|
| 1056 | % orbitfiginvisible; |
---|
| 1057 | % |
---|
| 1058 | % disp('Orbit gui visibility turned off while response matrix measurement in progress'); |
---|
| 1059 | % disp(['To re-activate, issue command : ', 'OrbitFigVisible']); |
---|
| 1060 | % |
---|
| 1061 | % % acquire initial orbit |
---|
| 1062 | % disp(' Acquiring initial orbit') |
---|
| 1063 | % Xorb = getx('struct'); |
---|
| 1064 | % Xorb.DataDescriptor = 'ResponseMatrixReference'; |
---|
| 1065 | % Zorb = getz('struct'); |
---|
| 1066 | % Zorb.DataDescriptor = 'ResponseMatrixReference'; |
---|
| 1067 | % |
---|
| 1068 | % %acquire machine configuration |
---|
| 1069 | % disp(' Acquiring machine configuration') |
---|
| 1070 | % machineconfig = getmachineconfig; |
---|
| 1071 | % |
---|
| 1072 | % ad = getad; |
---|
| 1073 | % |
---|
| 1074 | % xbpms = BPM(1).status; |
---|
| 1075 | % ybpms = BPM(2).status; |
---|
| 1076 | % |
---|
| 1077 | % xcors = COR(1).status; |
---|
| 1078 | % xkick = COR(1).ebpm(xcors); |
---|
| 1079 | % |
---|
| 1080 | % WaitFlag = ad.BPMDelay; |
---|
| 1081 | % ExtraDelay = 0; |
---|
| 1082 | % |
---|
| 1083 | % disp(' *** Begin measuring horizontal response matrix ***'); |
---|
| 1084 | % mat = measrespmat({BPMxFamily,BPMzFamily},{xbpms,ybpms},HCORFamily, ... |
---|
| 1085 | % xcors,xkick,'bipolar',WaitFlag,ExtraDelay,'struct'); |
---|
| 1086 | % |
---|
| 1087 | % % Make a response matrix array |
---|
| 1088 | % Rmat(1,1) = mat{1}; % xx |
---|
| 1089 | % Rmat(2,1) = mat{2}; % zx |
---|
| 1090 | % |
---|
| 1091 | % %load xx data |
---|
| 1092 | % Rmat(1,1).NaNData = zeros(size(getlist(BPMxFamily,0),1), ... |
---|
| 1093 | % size(getlist(HCORFamily,0),1)); |
---|
| 1094 | % Rmat(1,1).NaNData(:) = deal(NaN); |
---|
| 1095 | % Rmat(1,1).NaNData(xbpms,xcors) = mat{1}.Data; %Kick x, look x |
---|
| 1096 | % % |
---|
| 1097 | % %load zx data |
---|
| 1098 | % Rmat(2,1).NaNData = zeros(size(getlist(BPMzFamily,0),1), ... |
---|
| 1099 | % size(getlist(HCORFamily,0),1)); |
---|
| 1100 | % Rmat(2,1).NaNData(:) = deal(NaN); |
---|
| 1101 | % Rmat(2,1).NaNData(ybpms,xcors) = mat{2}.Data; %Kick x, look z |
---|
| 1102 | % |
---|
| 1103 | % for ii = 1:2 |
---|
| 1104 | % Rmat(ii,1).X = Xorb; |
---|
| 1105 | % Rmat(ii,1).Y = Zorb; |
---|
| 1106 | % Rmat(ii,1).MachineConfig = machineconfig; |
---|
| 1107 | % end |
---|
| 1108 | % Rmat(1,1).Monitor.DataDescriptor = 'Horizontal Orbit'; |
---|
| 1109 | % Rmat(1,1).Actuator.DataDescriptor = 'Horizontal Correctors'; |
---|
| 1110 | % Rmat(2,1).Monitor.DataDescriptor = 'Vertical Orbit'; |
---|
| 1111 | % Rmat(2,1).Actuator.DataDescriptor = 'Horizontal Correctors'; |
---|
| 1112 | % |
---|
| 1113 | % RSP(1) = response2rsp(Rmat(1,1),RSP(1),1); |
---|
| 1114 | % |
---|
| 1115 | % orbitfigvisible; |
---|
| 1116 | % |
---|
| 1117 | % BPM = SortBPMs(BPM,RSP); |
---|
| 1118 | % COR = SortCORs(COR,RSP); |
---|
| 1119 | % orbgui('RefreshOrbGUI'); |
---|
| 1120 | % |
---|
| 1121 | % orbgui('LBox',' Finished measuring horizontal eBPM response matrix'); |
---|
| 1122 | % |
---|
| 1123 | % %========================================================== |
---|
| 1124 | % case 'MeasureZResp' % *** MeasureZResp *** |
---|
| 1125 | % %========================================================== |
---|
| 1126 | % |
---|
| 1127 | % %callback of the 'Measure Z-Response' menu selection |
---|
| 1128 | % |
---|
| 1129 | % orbitfiginvisible; |
---|
| 1130 | % |
---|
| 1131 | % disp('Orbit gui visibility turned off while response matrix measurement in progress'); |
---|
| 1132 | % disp(['To re-activate, issue command : ', 'OrbitFigVisible']); |
---|
| 1133 | % |
---|
| 1134 | % % acquire initial orbit |
---|
| 1135 | % disp(' Acquiring initial orbit') |
---|
| 1136 | % Xorb = getx('struct'); |
---|
| 1137 | % Xorb.DataDescriptor = 'ResponseMatrixReference'; |
---|
| 1138 | % Zorb = getz('struct'); |
---|
| 1139 | % Zorb.DataDescriptor = 'ResponseMatrixReference'; |
---|
| 1140 | % |
---|
| 1141 | % %acquire machine configuration |
---|
| 1142 | % disp(' Acquiring machine configuration') |
---|
| 1143 | % machineconfig=getmachineconfig; |
---|
| 1144 | % |
---|
| 1145 | % ad = getad; |
---|
| 1146 | % |
---|
| 1147 | % xbpms = BPM(1).status; |
---|
| 1148 | % ybpms = BPM(2).status; |
---|
| 1149 | % |
---|
| 1150 | % ycors = COR(2).status; |
---|
| 1151 | % ykick = COR(2).ebpm(ycors); |
---|
| 1152 | % |
---|
| 1153 | % WaitFlag = 0; |
---|
| 1154 | % ExtraDelay = ad.BPMDelay; |
---|
| 1155 | % |
---|
| 1156 | % disp(' *** Begin measuring vertical response matrix ***'); |
---|
| 1157 | % mat = measrespmat({BPMxFamily,BPMzFamily},{xbpms,ybpms}, ... |
---|
| 1158 | % VCORFamily,ycors,ykick,'bipolar',WaitFlag,ExtraDelay,'struct'); |
---|
| 1159 | % |
---|
| 1160 | % % Make a response matrix array |
---|
| 1161 | % Rmat(1,2) = mat{1}; % zx |
---|
| 1162 | % Rmat(2,2) = mat{2}; % zz |
---|
| 1163 | % |
---|
| 1164 | % %load x-y data |
---|
| 1165 | % Rmat(1,2).NaNData = zeros(size(getlist(BPMzFamily,0),1), ... |
---|
| 1166 | % size(getlist(VCORFamily,0),1)); |
---|
| 1167 | % Rmat(1,2).NaNData(:) = deal(NaN); |
---|
| 1168 | % Rmat(1,2).NaNData(xbpms,ycors) = mat{1}.Data; %Kick x, look z |
---|
| 1169 | % |
---|
| 1170 | % %load y-y data |
---|
| 1171 | % Rmat(2,2).NaNData = zeros(size(getlist(BPMxFamily,0),1), ... |
---|
| 1172 | % size(getlist(VCORFamily,0),1)); |
---|
| 1173 | % Rmat(2,2).NaNData(:) = deal(NaN); |
---|
| 1174 | % Rmat(2,2).NaNData(xbpms,ycors) = mat{2}.Data; %Kick z, look z |
---|
| 1175 | % % |
---|
| 1176 | % for ii = 1:2 |
---|
| 1177 | % Rmat(ii,2).X = Xorb; |
---|
| 1178 | % Rmat(ii,2).Y = Zorb; |
---|
| 1179 | % Rmat(ii,2).MachineConfig = machineconfig; |
---|
| 1180 | % end |
---|
| 1181 | % |
---|
| 1182 | % Rmat(1,2).Monitor.DataDescriptor = 'Horizontal Orbit'; |
---|
| 1183 | % Rmat(1,2).Actuator.DataDescriptor = 'Vertical Correctors'; |
---|
| 1184 | % Rmat(2,2).Monitor.DataDescriptor = 'Vertical Orbit'; |
---|
| 1185 | % Rmat(2,2).Actuator.DataDescriptor = 'Vertical Correctors'; |
---|
| 1186 | % |
---|
| 1187 | % RSP(2) = response2rsp(Rmat(2,2),RSP(2),2); |
---|
| 1188 | % |
---|
| 1189 | % orbitfigvisible; |
---|
| 1190 | % |
---|
| 1191 | % BPM = SortBPMs(BPM,RSP); |
---|
| 1192 | % COR = SortCORs(COR,RSP); |
---|
| 1193 | % orbgui('RefreshOrbGUI'); |
---|
| 1194 | % |
---|
| 1195 | % orbgui('LBox',' Finished measuring vertical eBPM response matrix'); |
---|
| 1196 | |
---|
| 1197 | %========================================================== |
---|
| 1198 | otherwise |
---|
| 1199 | disp(['Warning: no CASE found in corgui: ' action]); |
---|
| 1200 | |
---|
| 1201 | end %end switchyard |
---|