0001 function [ring2,radelemIndex,cavitiesIndex]=atradoff(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 [cavipass,bendpass,quadpass]=parseargs({'IdentityPass','auto',''},varargin);
0028
0029 ring2=ring1;
0030
0031 if ~isempty(cavipass)
0032 cavitiesIndex=atgetcells(ring2,'Frequency');
0033 if ~any(cavitiesIndex)
0034 warning('AT:atradon:NoCavity', 'No cavity found in the structure');
0035 end
0036 ring2(cavitiesIndex)=changepass(ring2(cavitiesIndex),cavipass);
0037 else
0038 cavitiesIndex=false(size(ring2));
0039 end
0040
0041 if ~isempty(bendpass)
0042 isdipole=@(elem,bangle) bangle~=0;
0043 dipoles=atgetcells(ring2,'BendingAngle',isdipole);
0044 if sum(dipoles) <= 0
0045 warning('AT:atradon:NoBend', 'No dipole in the structure');
0046 end
0047 ring2(dipoles)=changepass(ring2(dipoles),bendpass);
0048 else
0049 dipoles=false(size(ring2));
0050 end
0051
0052 if ~isempty(quadpass)
0053 isquadrupole=@(elem,polyb) length(polyb) >= 2 && polyb(2)~=0;
0054 quadrupoles=atgetcells(ring2,'PolynomB',isquadrupole) & ~dipoles;
0055 if sum(quadrupoles) <= 0
0056 warning('AT:atradon:NoQuad', 'No quadrupole in the structure');
0057 end
0058 ring2(quadrupoles)=changepass(ring2(quadrupoles),quadpass);
0059 else
0060 quadrupoles=false(size(ring2));
0061 end
0062
0063 radelemIndex=dipoles|quadrupoles;
0064
0065 disp(['Cavities located at position ' num2str(find(cavitiesIndex)')]);
0066 disp([num2str(sum(radelemIndex)) ' elements with radiation switched off']);
0067
0068 function newline=changepass(line,newpass)
0069 if strcmp(newpass,'auto')
0070 passlist=strrep(atgetfieldvalues(line,'PassMethod'),'RadPass','Pass');
0071 else
0072 passlist=repmat({newpass},size(line));
0073 end
0074 newline=cellfun(@newelem,line,passlist,'UniformOutput',false);
0075
0076 function elem=newelem(elem,newpass)
0077 elem.PassMethod=newpass;
0078
0079 end
0080 end
0081
0082 end