source: MML/trunk/machine/SOLEIL/StorageRing/TuneMovePanel/TuneMovePanel.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 14.6 KB
Line 
1function varargout = TuneMovePanel(varargin)
2% TUNEMOVEPANEL M-file for TuneMovePanel.fig
3%      TUNEMOVEPANEL, by itself, creates a new TUNEMOVEPANEL or raises the existing
4%      singleton*.
5%
6%      H = TUNEMOVEPANEL returns the handle to a new TUNEMOVEPANEL or the handle to
7%      the existing singleton*.
8%
9%      TUNEMOVEPANEL('CALLBACK',hObject,eventData,handles,...) calls the local
10%      function named CALLBACK in TUNEMOVEPANEL.M with the given input arguments.
11%
12%      TUNEMOVEPANEL('Property','Value',...) creates a new TUNEMOVEPANEL or raises the
13%      existing singleton*.  Starting from the left, property value pairs are
14%      applied to the GUI before TuneMovePanel_OpeningFunction gets called.  An
15%      unrecognized property name or invalid value makes property application
16%      stop.  All inputs are passed to TuneMovePanel_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
23% Edit the above text to modify the response to help TuneMovePanel
24
25% Last Modified by GUIDE v2.5 05-Aug-2005 17:18:44
26
27% Begin initialization code - DO NOT EDIT
28gui_Singleton = 1;
29gui_State = struct('gui_Name',       mfilename, ...
30                   'gui_Singleton',  gui_Singleton, ...
31                   'gui_OpeningFcn', @TuneMovePanel_OpeningFcn, ...
32                   'gui_OutputFcn',  @TuneMovePanel_OutputFcn, ...
33                   'gui_LayoutFcn',  [] , ...
34                   'gui_Callback',   []);
35if nargin && ischar(varargin{1})
36    gui_State.gui_Callback = str2func(varargin{1});
37end
38
39if nargout
40    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41else
42    gui_mainfcn(gui_State, varargin{:});
43end
44% End initialization code - DO NOT EDIT
45
46% --- Executes just before TuneMovePanel is made visible.
47function TuneMovePanel_OpeningFcn(hObject, eventdata, handles, varargin)
48% This function has no output args, see OutputFcn.
49% hObject    handle to figure
50% eventdata  reserved - to be defined in a future version of MATLAB
51% handles    structure with handles and user data (see GUIDATA)
52% varargin   command line arguments to TuneMovePanel (see VARARGIN)
53
54% Choose default command line output for TuneMovePanel
55handles.output = hObject;
56
57% Update handles structure
58display('Launching Tune Move Panel ....');
59
60theReset(hObject, eventdata, handles)
61
62%tunespaceplot([18 18.5] , [8 8.5], 8, 4, handles.webAxe);
63
64% UIWAIT makes TuneMovePanel wait for user response (see UIRESUME)
65% uiwait(handles.figure1);
66
67
68% --- Outputs from this function are returned to the command line.
69function varargout = TuneMovePanel_OutputFcn(hObject, eventdata, handles)
70% varargout  cell array for returning output args (see VARARGOUT);
71% hObject    handle to figure
72% eventdata  reserved - to be defined in a future version of MATLAB
73% handles    structure with handles and user data (see GUIDATA)
74
75% Get default command line output from handles structure
76varargout{1} = handles.output;
77
78
79
80function dqField_Callback(hObject, eventdata, handles)
81% hObject    handle to dqField (see GCBO)
82% eventdata  reserved - to be defined in a future version of MATLAB
83% handles    structure with handles and user data (see GUIDATA)
84
85% Hints: get(hObject,'String') returns contents of dqField as text
86%        str2double(get(hObject,'String')) returns contents of dqField as a double
87
88
89% --- Executes during object creation, after setting all properties.
90function dqField_CreateFcn(hObject, eventdata, handles)
91% hObject    handle to dqField (see GCBO)
92% eventdata  reserved - to be defined in a future version of MATLAB
93% handles    empty - handles not created until after all CreateFcns called
94
95% Hint: edit controls usually have a white background on Windows.
96%       See ISPC and COMPUTER.
97if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
98    set(hObject,'BackgroundColor','white');
99end
100
101% --- Executes on button press in qyUpButton.
102function qyUpButton_Callback(hObject, eventdata, handles)
103% hObject    handle to qyUpButton (see GCBO)
104% eventdata  reserved - to be defined in a future version of MATLAB
105% handles    structure with handles and user data (see GUIDATA)
106dQx=0;
107dQy=str2double(get(handles.dqField,'string'));
108thesteptune(dQx,dQy);
109UpdatePlot(hObject, handles);
110% --- Executes on button press in qyDownButton.
111function qyDownButton_Callback(hObject, eventdata, handles)
112% hObject    handle to qyDownButton (see GCBO)
113% eventdata  reserved - to be defined in a future version of MATLAB
114% handles    structure with handles and user data (see GUIDATA)
115dQx=0;
116dQy=str2double(get(handles.dqField,'string'));
117thesteptune(dQx,-dQy);
118UpdatePlot(hObject, handles);
119% --- Executes on button press in qxUpButton.
120function qxUpButton_Callback(hObject, eventdata, handles)
121% hObject    handle to qxUpButton (see GCBO)
122% eventdata  reserved - to be defined in a future version of MATLAB
123% handles    structure with handles and user data (see GUIDATA)
124dQx=str2double(get(handles.dqField,'string'));
125dQy=0;
126thesteptune(dQx,dQy);
127UpdatePlot(hObject, handles);
128
129% --- Executes on button press in qxDownButton.
130function qxDownButton_Callback(hObject, eventdata, handles)
131% hObject    handle to qxDownButton (see GCBO)
132% eventdata  reserved - to be defined in a future version of MATLAB
133% handles    structure with handles and user data (see GUIDATA)
134dQx=str2double(get(handles.dqField,'string'));
135dQy=0;
136thesteptune(-dQx,dQy);
137UpdatePlot(hObject, handles);
138
139%% Update the Plots
140
141function UpdatePlot(hObject, handles)
142
143global THERING;
144handles.THERING = THERING;
145[TD, tune, chrom] = twissring(handles.THERING,0,1:handles.L+1,'chrom', 1e-8);
146BETA = cat(1,TD.beta);
147S    = cat(1,TD.SPos);
148Disp =cat(2,TD.Dispersion);
149
150
151set(handles.betax,'YData',BETA(:,1));
152set(handles.qxText,'String',num2str(tune(1)));
153
154set(handles.betay,'YData',BETA(:,2));
155set(handles.qyText,'String',num2str(tune(2)));
156
157set(handles.dx, 'YData', 10*Disp(1,:)');
158
159delete(handles.QDot);
160
161handles.Qx = tune(1);
162handles.Qy = tune(2);
163handles.QDot = line('parent',handles.webAxe,'XData',handles.Qx,'YData',handles.Qy,'Marker','+','MarkerSize',12.0);
164
165[name, val] = quad_getsetpoint;
166
167%handles.figure1;
168quad_table('title', name, val, [0.1 0.45 0.2 0.325]);
169set(handles.cxText,'String',num2str(chrom(1)));
170set(handles.cyText,'String',num2str(chrom(2)));
171if handles.emitCalc
172    e=getemit(TD);
173    set(handles.emitText,'String',num2str(e(1)));
174else
175    set(handles.emitText,'String','No Calc');
176end
177guidata(hObject,handles);
178
179
180% --- Executes on button press in summaryButton.
181function summaryButton_Callback(hObject, eventdata, handles)
182% hObject    handle to summaryButton (see GCBO)
183% eventdata  reserved - to be defined in a future version of MATLAB
184% handles    structure with handles and user data (see GUIDATA)
185
186
187% --- Executes on button press in emitCheckBox.
188function emitCheckBox_Callback(hObject, eventdata, handles)
189% hObject    handle to emitCheckBox (see GCBO)
190% eventdata  reserved - to be defined in a future version of MATLAB
191% handles    structure with handles and user data (see GUIDATA)
192
193% Hint: get(hObject,'Value') returns toggle state of emitCheckBox
194if (get(hObject,'Value') == get(hObject,'Max'))
195    % then checkbox is checked-take approriate action
196    handles.emitCalc=true;
197else
198    % checkbox is not checked-take approriate action
199    handles.emitCalc=false;
200end
201guidata(hObject,handles);
202
203function thesteptune(dqx, dqy)
204%ALBAsteptune(dqx, dqy);
205% original was
206steptune([dqx dqy],'Model'); % Laurent
207
208
209% --------------------------------------------------------------------
210function optionsMeno_Callback(hObject, eventdata, handles)
211% hObject    handle to optionsMeno (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
215
216% --------------------------------------------------------------------
217function panelResetMenu_Callback(hObject, eventdata, handles)
218% hObject    handle to panelResetMenu (see GCBO)
219% eventdata  reserved - to be defined in a future version of MATLAB
220% handles    structure with handles and user data (see GUIDATA)
221delete(handles.QDot);
222delete(handles.betax);
223delete(handles.betay);
224delete(handles.dx);
225theReset (hObject, eventdata, handles)
226
227% Local reset function
228function theReset(hObject, eventdata, handles)
229global THERING
230
231handles.L    = length(THERING);
232[TD, tune]   = twissring(THERING,0,1:handles.L+1);
233handles.spos = findspos(THERING,1:handles.L+1);
234handles.THERING = THERING;
235handles.betax   =       line('parent',handles.betaAxe,'XData',handles.spos,'YData',0*handles.spos,'Color','r');
236handles.betay   =       line('parent',handles.betaAxe,'XData',handles.spos,'YData',0.*handles.spos,'Color','b');
237handles.dx      =       line('parent',handles.betaAxe,'XData',handles.spos,'YData',0.*handles.spos,'Color','g');
238
239guidata(hObject,handles);
240
241drawlattice_local(handles, -1, 1);
242
243xlabel(handles.betaAxe,'s - position [m]');
244ylabel(handles.betaAxe,'\beta [m]');
245xaxis([0 handles.spos(handles.L+1)/4], handles.betaAxe);
246
247
248handles.Qx = tune(1);
249handles.Qy = tune(2);
250handles.emitCalc = true;
251handles.QDot = line('parent',handles.webAxe,'XData',handles.Qx,'YData',handles.Qy,'Marker','+');
252UpdatePlot(hObject, handles);
253
254
255% resonance diagramme
256handles.webAxe;
257max_order= 5;
258per = 4;
259
260window = [tune(1)-0.255 tune(1)+0.255 tune(2)-0.255 tune(2)+0.255];
261
262for i = max_order:-1:1,
263    [k, tab] = reson(i,per,window);
264end
265
266axis(window);
267
268handles.betaAxe;
269set(handles.emitCheckBox, 'Value',1);
270
271
272function drawlattice_local(hParent, Offset, Scaling)
273%DRAWLATTICE - Draws the AT lattice to a figure
274%  drawlattice(Offset, Scaling)
275%
276
277if nargin < 2
278    Offset = 0;
279end
280Offset = Offset(1);
281if nargin < 3
282    Scaling = 1;
283end
284Scaling = Scaling(1);
285
286global THERING
287
288SPositions = findspos(THERING, 1:length(THERING)+1);
289L = SPositions(end);
290line('parent',hParent.betaAxe,'XData',[0 L],'YData',[0 0]+Offset,'Color','k');
291
292% Remember the hold state then turn hold on
293HoldState = ishold;
294hold on;
295
296% Make default icons for elements of different physical types
297for i = 1:length(THERING)
298    SPos = SPositions(i);
299    if isfield(THERING{i},'BendingAngle') & THERING{i}.BendingAngle
300        % make icons for bending magnets
301        IconHeight = .3;
302        IconColor = [1 1 0];
303        IconWidth = THERING{i}.Length;
304        if IconWidth < .15 % meters
305            IconWidth = .15;
306            SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
307        end
308        vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
309        vy = [IconHeight IconHeight -IconHeight -IconHeight];
310        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-','parent',hParent.betaAxe);
311        %if IconWidth < .1 % meters
312        %    set(h, 'EdgeColor', IconColor);
313        %end
314
315    elseif isfield(THERING{i},'K') & THERING{i}.K
316        % Quadrupole
317        if THERING{i}.K > 0
318            % Focusing quadrupole
319            IconHeight = .6;
320            IconColor = [1 0 0];
321            IconWidth = THERING{i}.Length;
322            if IconWidth < .15 % meters
323                IconWidth = .15;
324                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
325            end
326            vx = [SPos SPos+IconWidth/2  SPos+IconWidth SPos+IconWidth/2 SPos];
327            vy = [0          IconHeight               0      -IconHeight    0];
328        else
329            % Defocusing quadrupole
330            IconHeight = .6;
331            IconColor = [0 0 1];
332            IconWidth = THERING{i}.Length;
333            if IconWidth < .15 % meters
334                IconWidth = .15;
335                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
336            end
337            vx = [SPos+.4*IconWidth    SPos    SPos+IconWidth  SPos+.6*IconWidth  SPos+IconWidth    SPos      SPos+.4*IconWidth];
338            vy = [     0            IconHeight   IconHeight          0              -IconHeight  -IconHeight    0];
339        end
340        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-','Parent',hParent.betaAxe);
341        %if IconWidth < .1 % meters
342        %    set(h, 'EdgeColor', IconColor);
343        %end
344
345    elseif isfield(THERING{i},'PolynomB') & length(THERING{i}.PolynomB)>2 & THERING{i}.PolynomB(3)
346        % Sextupole
347        if THERING{i}.PolynomB(3)>0
348            % Focusing sextupole
349            IconHeight = .5;
350            IconColor = [1 0 1];
351            IconWidth = THERING{i}.Length;
352            if IconWidth < .1 % meters
353                IconWidth = .1;
354                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
355            end
356            vx = [SPos          SPos+.33*IconWidth  SPos+.66*IconWidth  SPos+IconWidth   SPos+IconWidth   SPos+.66*IconWidth  SPos+.33*IconWidth      SPos          SPos];
357            vy = [IconHeight/3      IconHeight          IconHeight        IconHeight/3    -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
358        else
359            % Defocusing sextupole
360            IconHeight = .5;
361            IconColor = [0 1 0];
362            IconWidth = THERING{i}.Length;
363            if IconWidth < .1 % meters
364                IconWidth = .1;
365                SPos = SPos - IconWidth/2 + THERING{i}.Length/2;
366            end
367            vx = [SPos          SPos+.33*IconWidth  SPos+.66*IconWidth  SPos+IconWidth   SPos+IconWidth   SPos+.66*IconWidth  SPos+.33*IconWidth      SPos          SPos];
368            vy = [IconHeight/3      IconHeight          IconHeight        IconHeight/3    -IconHeight/3      -IconHeight          -IconHeight     -IconHeight/3  IconHeight/3];
369        end
370        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle','-');
371        %if IconWidth < .1 % meters
372        %    set(h, 'EdgeColor', IconColor);
373        %end
374
375    elseif isfield(THERING{i},'Frequency') & isfield(THERING{i},'Voltage')
376        % RF cavity
377        IconColor = [1 0.5 0];
378        plot(SPos, 0+Offset, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 4)
379
380    elseif strcmpi(THERING{i}.FamName,'BPM')
381        % BPM
382        IconColor = 'k';
383        plot(SPos, 0+Offset, '.-', 'Color', IconColor)
384        %plot(SPos, 0, 'o', 'MarkerFaceColor', IconColor, 'Color', IconColor, 'MarkerSize', 1.5)
385
386    elseif any(strcmpi(THERING{i}.FamName,{'COR','XCOR','YCOR','HCOR','VCOR'})) | isfield(THERING{i},'KickAngle')
387        % Corrector
388        IconHeight = .8;
389        IconColor = [0 0 0];
390        vx = [SPos   SPos];
391        vy = [-IconHeight IconHeight];
392        %plot(vx, Scaling*vy+Offset, 'Color', IconColor);
393        IconWidth = THERING{i}.Length;
394        vx = [SPos SPos+IconWidth SPos+IconWidth SPos];
395        vy = [IconHeight IconHeight -IconHeight -IconHeight];
396        h = patch(vx, Scaling*vy+Offset, IconColor,'LineStyle', '-','parent',hParent.betaAxe);
397        if IconWidth < .1 % meters
398            set(h, 'EdgeColor', IconColor);
399        end
400    end
401end
402
403
404% Leave the hold state as it was at the start
405if ~HoldState
406    hold off
407end
408%yaxis([-3 3]);
Note: See TracBrowser for help on using the repository browser.