Skip to content

Commit 268994f

Browse files
authored
Fix atplot for single-element lattices (#854)
* fix atplot for single element lattices * ring splitting when length(ring)==1
1 parent a929804 commit 268994f

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

atmat/atplot/atplotsyn.m

+36-45
Original file line numberDiff line numberDiff line change
@@ -36,60 +36,54 @@
3636
indx=indx(sok);
3737
[dipoles,qpoles,spoles,mpoles,bpms]=cellfun(@eltype,rok);
3838

39-
ampl=0.05*tlim; % Dipoles
40-
[xplot,yplot]=setxpl(sl(dipoles),ll(dipoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
41-
%[xplot,yplot]=setxpl(sl(dipoles),ll(dipoles),[0;0;1;1;0],ampl*[-1;1;1;-1;-1]);
42-
if (~isempty(xplot) && ~isempty(yplot))
43-
p1=patch(xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
44-
%p1=patch(ax,xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
39+
sld=sl(dipoles);
40+
if isempty(sld)
41+
p1={};
4542
else
46-
p1={};
43+
ampl=0.05*tlim; % Dipoles
44+
[xplot,yplot]=setxpl(sld,ll(dipoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
45+
p1=patch(xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
4746
end
4847

49-
ampl=0.05*tlim; % Quadrupoles
50-
foc=reshape(0.4*ampl*sign(atgetfieldvalues(rok(qpoles),'PolynomB',{2})),1,[]);
51-
[xplot,yplot]=setxpl(sl(qpoles),ll(qpoles),[0;0;0.5;1;1;0],ampl*[0;1;1;1;0;0]);
52-
yplot(3,:)=yplot(3,:)+foc;
53-
%[xplot,yplot]=setxpl(sl(qpoles),ll(qpoles),[0;0;0.5;1;1;0.5;0],ampl*[-1;1;1;1;-1;-1;-1]);
54-
%yplot(6,:)=yplot(6,:)-foc;
55-
if (~isempty(xplot) && ~isempty(yplot))
56-
p2=patch(xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
57-
%p2=patch(ax,xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
48+
slq=sl(qpoles);
49+
if isempty(slq)
50+
p2={};
5851
else
59-
p2={};
52+
ampl=0.05*tlim; % Quadrupoles
53+
foc=reshape(0.4*ampl*sign(atgetfieldvalues(rok(qpoles),'PolynomB',{2})),1,[]);
54+
[xplot,yplot]=setxpl(slq,ll(qpoles),[0;0;0.5;1;1;0],ampl*[0;1;1;1;0;0]);
55+
yplot(3,:)=yplot(3,:)+foc;
56+
p2=patch(xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
6057
end
6158

62-
ampl=0.04*tlim; % Sextupoles
63-
foc=reshape(0.25*ampl*sign(atgetfieldvalues(rok(spoles),'PolynomB',{3})),1,[]);
64-
[xplot,yplot]=setxpl(sl(spoles),ll(spoles),[0;0;0.33;0.66;1;1;0],ampl*[0;1;1;1;1;0;0]);
65-
yplot(3:4,:)=yplot(3:4,:)+foc([1;1],:);
66-
%[xplot,yplot]=setxpl(sl(spoles),ll(spoles),[0;0;0.33;0.66;1;1;0.66;0.33;0],ampl*[-1;1;1;1;1;-1;-1;-1;-1]);
67-
%yplot(7:8,:)=yplot(7:8,:)-foc([1;1],:);
68-
if (~isempty(xplot) && ~isempty(yplot))
69-
p3=patch(xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
70-
%p3=patch(ax,xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
59+
sls=sl(spoles);
60+
if isempty(sls)
61+
p3={};
7162
else
72-
p3={};
63+
ampl=0.04*tlim; % Sextupoles
64+
foc=reshape(0.25*ampl*sign(atgetfieldvalues(rok(spoles),'PolynomB',{3})),1,[]);
65+
[xplot,yplot]=setxpl(sls,ll(spoles),[0;0;0.33;0.66;1;1;0],ampl*[0;1;1;1;1;0;0]);
66+
yplot(3:4,:)=yplot(3:4,:)+foc([1;1],:);
67+
p3=patch(xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
7368
end
7469

75-
ampl=0.03*tlim; % Other multipoles
76-
[xplot,yplot]=setxpl(sl(mpoles),ll(mpoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
77-
%[xplot,yplot]=setxpl(sl(mpoles),ll(mpoles),[0;0;1;1;0],ampl*[-1;1;1;-1;-1]);
78-
if (~isempty(xplot) && ~isempty(yplot))
79-
p4=patch(xplot,yplot,[0 0.5 0]);
80-
%p4=patch(ax,xplot,yplot,[0 0.5 0]);
70+
slm=sl(mpoles);
71+
if isempty(slm)
72+
p4={};
8173
else
82-
p4={};
74+
ampl=0.03*tlim; % Other multipoles
75+
[xplot,yplot]=setxpl(slm,ll(mpoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
76+
p4=patch(xplot,yplot,[0 0.5 0]);
8377
end
8478

85-
ampl=0.015*tlim; % BPMs
86-
amplx=0.005*slim;
87-
[xplot,yplot]=setxpl(sl(bpms),ones(1,sum(bpms)),[-amplx;0;amplx;0;-amplx],[0;-ampl;0;ampl;0]);
88-
if (~isempty(xplot) && ~isempty(yplot))
89-
p5=patch(xplot,yplot,[0 0.5 0],'DisplayName','BPM');
90-
%p5=patch(ax,xplot,yplot,[0 0 0],'clipping','off');
79+
slb=sl(bpms);
80+
if isempty(slb)
81+
p5={};
9182
else
92-
p5={};
83+
ampl=0.015*tlim; % BPMs
84+
amplx=0.005*slim;
85+
[xplot,yplot]=setxpl(slb,ones(1,sum(bpms)),[-amplx;0;amplx;0;-amplx],[0;-ampl;0;ampl;0]);
86+
p5=patch(xplot,yplot,[0 0.5 0],'DisplayName','BPM');
9387
end
9488

9589
if any(labs)
@@ -98,10 +92,7 @@
9892
args={'Label',text(slabs,-0.03*tlim*ones(size(slabs)),vlabs,'Rotation',90,...
9993
'Interpreter','none','FontUnits','normalized','FontSize',0.025,...
10094
'HorizontalAlignment','right')};
101-
else
102-
args={};
103-
end
104-
if any(indx)
95+
elseif any(indx)
10596
sindex=sl(indx)+0.5*ll(indx);
10697
iiok=1:length(rok);
10798
vlabs=cellfun(@(el) el,num2cell(iiok(indx)),'UniformOutput',false);

atmat/atplot/xplot.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
% Split the ring
4141
elmlength=findspos(ring(el1:el2-1),el2-el1+1)/npts;
4242
r2=cellfun(@splitelem,ring(el1:el2-1),'UniformOutput',false);
43-
splitring=cat(1,ring(1:el1-1),r2{:},ring(el2:elt0));
43+
splitring=cat(1,ring(1:el1-1,1),r2{:},ring(el2:elt0,1));
4444
plrange=el1:el2+length(splitring)-elt0;
4545

4646
[s,outp]=plotfun(splitring,curve.dpp,plotargs{:},dpargs{:});
@@ -53,7 +53,7 @@
5353
ylabel(ax2(1),outp(1).axislabel);
5454
ylabel(ax2(2),outp(2).axislabel);
5555
linkaxes([ax2(1) ax2(2)],'x');% allows zoom on both right and left plots
56-
elseif numel(outp) == 1
56+
elseif isscalar(outp)
5757
curve.left=plot(ax,s(plrange),outp(1).values(plrange,:));
5858
curve.right=[];
5959
ylabel(ax,outp(1).axislabel);

0 commit comments

Comments
 (0)