0001 function [ring,radelemIndex,cavitiesIndex,energy]=atradon(ring1,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 [cavipass,bendpass,quadpass]=parseargs({'CavityPass','auto',''},varargin);
0034
0035 ring=ring1;
0036
0037 energy=atenergy(ring);
0038 if ~isempty(cavipass)
0039 cavitiesIndex=atgetcells(ring,'Frequency');
0040 if any(cavitiesIndex)
0041 ring(cavitiesIndex)=changepass(ring(cavitiesIndex),cavipass,energy);
0042 end
0043 else
0044 cavitiesIndex=false(size(ring));
0045 end
0046
0047 if ~isempty(bendpass)
0048 isdipole=@(elem,bangle) bangle~=0;
0049 dipoles=atgetcells(ring,'BendingAngle',isdipole);
0050 if any(dipoles) > 0
0051 ring(dipoles)=changepass(ring(dipoles),bendpass,energy);
0052 end
0053 else
0054 dipoles=false(size(ring));
0055 end
0056
0057 if ~isempty(quadpass)
0058 isquadrupole=@(elem,polyb) length(polyb) >= 2 && polyb(2)~=0;
0059 quadrupoles=atgetcells(ring,'PolynomB',isquadrupole) & ~dipoles;
0060 if any(quadrupoles) > 0
0061 ring(quadrupoles)=changepass(ring(quadrupoles),quadpass,energy);
0062 end
0063 else
0064 quadrupoles=false(size(ring));
0065 end
0066
0067 radelemIndex=dipoles|quadrupoles;
0068
0069 if any(cavitiesIndex)
0070 atdisplay(1,['Cavities located at position ' num2str(find(cavitiesIndex)')]);
0071 else
0072 atdisplay(1,'No cavity');
0073 end
0074 atdisplay(1,[num2str(sum(radelemIndex)) ' elements switched to include radiation']);
0075
0076 function newline=changepass(line,newpass,nrj)
0077 if strcmp(newpass,'auto')
0078 passlist=atgetfieldvalues(line,'PassMethod');
0079 ok=cellfun(@(psm) isempty(strfind(psm,'RadPass')),passlist);
0080 passlist(ok)=strrep(passlist(ok),'Pass','RadPass');
0081 else
0082 passlist=repmat({newpass},size(line));
0083 end
0084 newline=cellfun(@newelem,line,passlist,'UniformOutput',false);
0085
0086 function elem=newelem(elem,newpass)
0087 elem.PassMethod=newpass;
0088 elem.Energy=nrj;
0089 end
0090 end
0091
0092 end