0001 function pp = atplotsyn(ax,ring,varargin)
0002
0003
0004
0005
0006 options=struct(varargin{:});
0007 labs=false(size(ring(:)));
0008 if isfield(options,'labels')
0009 if islogical(options.labels)
0010 labs=options.labels(:);
0011 elseif isnumeric(options.labels)
0012 labs(options.labels)=true;
0013 end
0014 end
0015 indx=false(size(ring(:)));
0016 if isfield(options,'index')
0017 if islogical(options.index)
0018 indx=options.index(:);
0019 elseif isnumeric(options.index)
0020 indx(options.index)=true;
0021 end
0022 end
0023 xlim=get(ax,'XLim');
0024 slim=diff(xlim);
0025 tlim=diff(get(ax,'YLim'));
0026 nlines=length(get(ax,'Children'));
0027
0028
0029 sl=findspos(ring(:,1),1:size(ring,1)+1);
0030 ll=diff(sl);
0031 sok=(sl(2:end)>xlim(1)) & (sl(1:end-1)<xlim(2));
0032 sl=sl(sok);
0033 ll=ll(sok);
0034 rok=ring(sok);
0035 labs=labs(sok);
0036 indx=indx(sok);
0037 [dipoles,qpoles,spoles,mpoles,bpms]=cellfun(@eltype,rok);
0038
0039 ampl=0.05*tlim;
0040 [xplot,yplot]=setxpl(sl(dipoles),ll(dipoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
0041
0042 p1=patch(xplot,yplot,[0.5 0.5 1],'DisplayName','Dipoles');
0043
0044
0045 ampl=0.05*tlim;
0046 foc=reshape(0.4*ampl*sign(atgetfieldvalues(rok(qpoles),'PolynomB',{2})),1,[]);
0047 [xplot,yplot]=setxpl(sl(qpoles),ll(qpoles),[0;0;0.5;1;1;0],ampl*[0;1;1;1;0;0]);
0048 yplot(3,:)=yplot(3,:)+foc;
0049
0050
0051 p2=patch(xplot,yplot,[1 0.5 0.5],'DisplayName','Quadrupoles');
0052
0053
0054 ampl=0.04*tlim;
0055 foc=reshape(0.25*ampl*sign(atgetfieldvalues(rok(spoles),'PolynomB',{3})),1,[]);
0056 [xplot,yplot]=setxpl(sl(spoles),ll(spoles),[0;0;0.33;0.66;1;1;0],ampl*[0;1;1;1;1;0;0]);
0057 yplot(3:4,:)=yplot(3:4,:)+foc([1;1],:);
0058
0059
0060 p3=patch(xplot,yplot,[0.5 1 0.5],'DisplayName','Sextupoles');
0061
0062
0063 ampl=0.03*tlim;
0064 [xplot,yplot]=setxpl(sl(mpoles),ll(mpoles),[0;0;1;1;0],ampl*[0;1;1;0;0]);
0065
0066 p4=patch(xplot,yplot,[0 0.5 0]);
0067
0068
0069 ampl=0.015*tlim;
0070 amplx=0.005*slim;
0071 [xplot,yplot]=setxpl(sl(bpms),ones(1,sum(bpms)),[-amplx;0;amplx;0;-amplx],[0;-ampl;0;ampl;0]);
0072 p5=patch(xplot,yplot,[0 0 0],'clipping','off');
0073
0074
0075 if any(labs)
0076 slabs=sl(labs)+0.5*ll(labs);
0077 vlabs=cellfun(@(el) el.FamName,rok(labs),'UniformOutput',false);
0078 args={'Label',text(slabs,-0.03*tlim*ones(size(slabs)),vlabs,'Rotation',90,...
0079 'Interpreter','none','FontUnits','normalized','FontSize',0.025,...
0080 'HorizontalAlignment','right')};
0081 else
0082 args={};
0083 end
0084 if any(indx)
0085 sindex=sl(indx)+0.5*ll(indx);
0086 iiok=1:length(rok);
0087 vlabs=cellfun(@(el) el,num2cell(iiok(indx)),'UniformOutput',false);
0088 args={'Label',text(sindex,-0.05*tlim*ones(size(sindex)),vlabs,'Rotation',90,...
0089 'Interpreter','none','FontUnits','normalized','FontSize',0.02,...
0090 'HorizontalAlignment','right')};
0091 else
0092 args={};
0093 end
0094
0095
0096 set(ax,'Children',circshift(get(ax,'Children'),nlines));
0097
0098 pp=struct('Dipole',p1,'Quadrupole',p2,'Sextupole',p3,'Multipole',p4,...
0099 'BPM',p5,args{:});
0100
0101 function [xpl,ypl]=setxpl(s,l,xmotif,ymotif)
0102 nm=length(xmotif);
0103 xpl=s(ones(nm,1),:)+l(ones(nm,1),:).*xmotif(:,ones(1,length(s)));
0104 ypl=ymotif(:,ones(1,length(s)));
0105 end
0106
0107 function varargout=eltype(elem)
0108 if isfield(elem,'Class')
0109 cls=elem.Class;
0110 else
0111 cls=atguessclass(elem);
0112 end
0113 tst=strcmp(cls,{'Bend','Quadrupole','Sextupole','Multipole','Monitor'});
0114 varargout=num2cell(tst);
0115 end
0116 end