0001 function ferrs = atmakefielderrstruct(ring,class,nval,Bval,Aval,radius,rnd)
0002
0003
0004
0005
0006 if isequal(class,'Quadrupole')
0007 elemindex=findcells(ring,'Class','Quadrupole');
0008 Nval=2*ones(length(elemindex),1);
0009 elseif isequal(class,'Sextupole')
0010 elemindex=findcells(ring,'Class','Sextupole');
0011 Nval=3*ones(length(elemindex),1);
0012 else
0013 error('not a valid element class');
0014 end
0015
0016 len=length(elemindex);
0017 if(rnd==1)
0018 for j=1:len
0019 Barray(j)=Bval*randn;
0020 Aarray(j)=Aval*randn;
0021 end
0022 else
0023 Barray=Bval*ones(len,1);
0024 Aarray=Aval*ones(len,1);
0025 end
0026
0027
0028
0029 ferrs=struct('elemindex',elemindex,'Nval',Nval,'nval',nval*ones(len,1),'Bval',Barray,'Aval',Aarray,'radius',radius);