Home > lattice > Converters > MADX2AT > buildATLattice.m

buildATLattice

PURPOSE ^

given a list (cell array) of elements with specified field Spos (center of element (madx default)) in a

SYNOPSIS ^

function Lat=buildATLattice(list,s,totL)

DESCRIPTION ^

 given a list (cell array) of elements with specified field Spos (center of element (madx default)) in a
 vector returns a cell array with elements without Spos field and
 appropriate Drifts spaces between. Drifts of the same length have the same name.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Lat=buildATLattice(list,s,totL)
0002 % given a list (cell array) of elements with specified field Spos (center of element (madx default)) in a
0003 % vector returns a cell array with elements without Spos field and
0004 % appropriate Drifts spaces between. Drifts of the same length have the same name.
0005 Lat={};
0006 latind=1;
0007 zero=0;
0008 
0009 [s,indpos]=sort(s);
0010 list=list(indpos);
0011 elemalign='b'; % (c) center (b) begin (e) end
0012 
0013 for i=1:length(list)
0014     L=list{i}.('Length');
0015     
0016  
0017     spos=s(i)-L/2; % refer to element entrance
0018     D=[];% drift name
0019     
0020     switch elemalign
0021         case 'c'
0022             DL=spos-zero-L/2; % drift length
0023         case 'b'
0024             DL=spos-zero; % drift length
0025         case 'e'
0026             DL=spos-zero-L; % drift length
0027         otherwise
0028             DL=spos-zero-L/2; % drift length
0029     end
0030 
0031     
0032     if DL>1e-7
0033         Dnam=['DR_' num2str(DL)]; %['Drift'];
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 % fix roundings
0044       
0045         Lat{latind}=list{i};
0046         Lat{latind-1}.('Length')=Lat{latind-1}.('Length')+DL;
0047     
0048     else
0049       % list{i}
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 % add last dirft to reach lattice length
0076 
0077 Dnam=['DR_' num2str(totL-zero)];%['Drift'];
0078         Dnam(ismember(Dnam,'.'))=[];
0079 D=atdrift(Dnam,totL-zero);
0080        
0081 Lat{latind}=D;
0082 
0083 
0084 Lat=Lat'; % return column
0085 
0086 % clean unusefull drifts
0087 
0088 %
0089 %LD=getcellstruct(Lat,'Length',drifts);
0090 
0091 %Lat(drifts(LD<1e-7))=[];
0092 
0093 
0094 
0095 
0096 
0097

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005