0001 function Lat=buildATLattice(list,s,totL)
0002
0003
0004
0005 Lat={};
0006 latind=1;
0007 zero=0;
0008
0009 [s,indpos]=sort(s);
0010 list=list(indpos);
0011 elemalign='b';
0012
0013 for i=1:length(list)
0014 L=list{i}.('Length');
0015
0016
0017 spos=s(i)-L/2;
0018 D=[];
0019
0020 switch elemalign
0021 case 'c'
0022 DL=spos-zero-L/2;
0023 case 'b'
0024 DL=spos-zero;
0025 case 'e'
0026 DL=spos-zero-L;
0027 otherwise
0028 DL=spos-zero-L/2;
0029 end
0030
0031
0032 if DL>1e-7
0033 Dnam=['DR_' num2str(DL)];
0034 Dnam(ismember(Dnam,'.'))=[];
0035 D=atdrift(Dnam,DL);
0036 Lat{latind}=D;
0037 Lat{latind+1}=list{i};
0038 latind=latind+1;
0039
0040 elseif (DL>=0 && DL<1e-7)
0041 Lat{latind}=list{i};
0042
0043 elseif DL>-1e-5
0044
0045 Lat{latind}=list{i};
0046 Lat{latind-1}.('Length')=Lat{latind-1}.('Length')+DL;
0047
0048 else
0049
0050 disp([ 'negative drift: ' num2str(DL)])
0051 end
0052
0053
0054
0055
0056 latind=latind+1;
0057
0058 switch elemalign
0059 case 'c'
0060 zero=spos+L/2;
0061 case 'b'
0062 zero=spos+L;
0063 case 'e'
0064 zero=spos;
0065 otherwise
0066 zero=spos+L/2;
0067 end
0068
0069
0070
0071
0072 end
0073
0074
0075
0076
0077 Dnam=['DR_' num2str(totL-zero)];
0078 Dnam(ismember(Dnam,'.'))=[];
0079 D=atdrift(Dnam,totL-zero);
0080
0081 Lat{latind}=D;
0082
0083
0084 Lat=Lat';
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097