Home > lattice > Converters > AT2Elegant > AT_2_Elegant.m

AT_2_Elegant

PURPOSE ^

this functions converts the AT lattice AT_ring in elegant form.

SYNOPSIS ^

function AT_2_Elegant(AT_ring,linename)

DESCRIPTION ^

 this functions converts the AT lattice AT_ring in elegant form.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function AT_2_Elegant(AT_ring,linename)
0002 % this functions converts the AT lattice AT_ring in elegant form.
0003 
0004 
0005 outfile='elegantconvertedlattice.lte';
0006 elelat=['!!\n!!  Elegant lattice: ' linename '\n!!  Created: ' datestr(now) '\n!!\n!!\n\n'];
0007 nkickperL=40; % kicks per meter
0008 
0009 %% get family names for definitions
0010 [families,ind_first_oc_ring]=...
0011     unique(getcellstruct(AT_ring,'FamName',1:length(AT_ring)),'first');
0012 
0013 elelat=[elelat '! DEFINITIONS \n\n'];
0014 
0015 form='%8.16f';
0016 
0017 %% loop families for definitions
0018 for i=1:length(families)
0019    el= AT_ring{ind_first_oc_ring(i)};
0020     switch el.('Class')
0021         case 'Bend' % dipole
0022             di=[el.('FamName')   ': &\n'...
0023                 ' CSBEND,L=' num2str(el.('Length'),form) ', &\n'...
0024 ...   %             ' CSBEND,L=' num2str((el.('Length')/2)*el.('BendingAngle')/(sin(el.('BendingAngle')/2)),form) ', &\n'...
0025                 ' ANGLE = ' num2str(el.('BendingAngle'),form) ', &\n'...
0026                 ' K1 = ' num2str(el.('PolynomB')(2),form) ', &\n'...
0027                 ' E1= ' num2str(el.('EntranceAngle'),form) ', &\n'...
0028                 ' E2= ' num2str(el.('ExitAngle'),form) ', &\n' ];
0029 ... %                ' N_KICKS= ' num2str(ceil(el.('Length')*nkickperL),'%d') ' \n'...
0030                 if(isfield(el,'T1'))
0031                     di= [ di ' DX= ' num2str(-1*el.('T1')(1),form) ', &\n'...
0032                     ' DY= ' num2str(-1*el.('T1')(3),form) ', &\n' ] ;
0033                 end
0034                    di= [di ...
0035                  ' N_KICKS= 40 \n'...
0036                ];
0037              elelat=[elelat di '\n']; %#ok<*AGROW>
0038              
0039         case 'Corrector' % Hor Corr
0040              hc= [el.('FamName') ' : KICKER \n'];
0041              elelat=[elelat hc '\n']; 
0042            
0043         case 'Quadrupole' % quadrupole
0044             
0045             qp=[el.('FamName')   ': &\n'...
0046                 ' KQUAD,  L= ' num2str(el.('Length'),form)  ', &\n'...
0047                 ' K1= ' num2str(el.('PolynomB')(2),form) ', &\n'];
0048 ... %                 ' N_KICKS= ' num2str(ceil(el.('Length')*nkickperL),'%d') ' \n'...
0049                 if(isfield(el,'Tilt'))
0050                     qp= [qp ' TILT= ' num2str(el.('Tilt')) ' & \n'] ;
0051                 end
0052                           
0053                 if(isfield(el,'T1'))
0054                     qp = [ qp ' DX= ' num2str(-1*el.('T1')(1),form) ', &\n'...
0055                     ' DY= ' num2str(-1*el.('T1')(3),form) ', &\n' ] ;
0056                 end
0057                    qp= [qp ...
0058                  ' N_KICKS= 40 \n'...
0059                ];
0060             
0061             elelat=[elelat qp '\n'];
0062         case 'Sextupole' % sextupole
0063             sx=[el.('FamName')   ': &\n'...
0064                 ' KSEXT,  L= ' num2str(el.('Length'),form)  ', &\n'...
0065 ...%                ' K2= ' num2str(el.('PolynomB')(3),form) ', &\n'...
0066                 ' K2= ' num2str(2*el.('PolynomB')(3),form) ', &\n'];
0067 ... %                ' N_KICKS= ' num2str(ceil(el.('Length')*nkickperL),'%d') ' \n'...
0068                 if(isfield(el,'T1'))
0069                     sx=[sx ' DX= ' num2str(-1*el.('T1')(1),form) ', &\n'...
0070                     ' DY= ' num2str(-1*el.('T1')(3),form) ', &\n'];
0071                 end
0072                 if(isfield(el,'Tilt'))
0073                     sx = [ sx ' TILT= ' num2str(el.('Tilt')) ', &\n' ];
0074                 end
0075                 sx = [ sx ' N_KICKS= 40 \n'];
0076                 
0077             elelat=[elelat sx '\n'];
0078         case 'Octupole' % octupole
0079             sx=[el.('FamName')   ': &\n'...
0080                 ' KOCT,  L= ' num2str(el.('Length'),form)  ', &\n'...
0081 ...%                ' K2= ' num2str(el.('PolynomB')(3),form) ', &\n'...
0082                 ' K3= ' num2str(6*el.('PolynomB')(4),form) ', &\n'];
0083             if(isfield(el,'T1'))
0084                     sx=[sx ' DX= ' num2str(-1*el.('T1')(1),form) ', &\n'...
0085                     ' DY= ' num2str(-1*el.('T1')(3),form) ', &\n'];
0086                 end
0087                 if(isfield(el,'Tilt'))
0088                     sx = [ sx ' TILT= ' num2str(el.('Tilt')) ', &\n' ];
0089                 end
0090                 sx = [ sx ' N_KICKS= 40 \n'];
0091 
0092             elelat=[elelat sx '\n'];
0093         case 'Multipole' 
0094             % el.('PolynomB')
0095             ord=find(el.('PolynomB'));
0096             if isempty(ord)
0097                 ord=length(el.('PolynomB'));
0098             end
0099                 mp=[el.('FamName')   ': &\n'...
0100                     ' MULT,  L= ' num2str(el.('Length'),form)  ', &\n'...
0101                     'ORDER= ' num2str(ord(1)-1) ', &\n' ... 
0102                    'KNL= ' num2str(factorial(ord-1)*el.('PolynomB')(ord(1)),form) ', \n'];
0103  ...%                   'KNL= ' num2str(factorial(ord(1)-1)*el.('PolynomB')(ord(1)),form) ', \n'...
0104                 if(isfield(el,'T1'))
0105                     mp=[mp ' DX= ' num2str(-1*el.('T1')(1),form) ', &\n'...
0106                     ' DY= ' num2str(-1*el.('T1')(3),form) ', &\n'];
0107                 end
0108                 if(isfield(el,'Tilt'))
0109                     mp = [ mp ' TILT= ' num2str(el.('Tilt')) ', &\n' ];
0110                 end
0111                 mp = [ mp ' N_KICKS= 40 \n'];
0112  
0113             elelat=[elelat mp '\n'];
0114         case 'Monitor' % bpm
0115             pu=[el.('FamName') ' : MONI, L= ' num2str(el.('Length'),form) ' \n'];
0116             elelat=[elelat pu '\n'];
0117         case 'Marker'% marker
0118             mrk=[el.('FamName') ' :MARK' ' \n'...
0119                 ];
0120             elelat=[elelat mrk '\n'];
0121         case 'Kicker' % kicker
0122             ki=[el.('FamName') ' :KICKER' ' \n'...
0123                 ];
0124             
0125             elelat=[elelat ki '\n'];
0126         case 'Drift' % drift
0127             dr=[el.('FamName') ' : EDRIFT, L= ' num2str(el.('Length'),form) ' \n'];
0128             elelat=[elelat dr '\n'];     
0129          case 'RFCavity' % drift
0130             rfc=[el.('FamName') ' : RFCA, L=' num2str(el.('Length'),form)...
0131                 ',VOLT='  num2str(el.('Voltage'),form) ' &\n'...
0132                 ',phase="180 2.278145 4 / dasin -",' ' &\n'...
0133                 ' freq="c_mks 844.8112 / ' num2str(el.('HarmNumber'),form) ' *" ' ' \n'];
0134       
0135             elelat=[elelat rfc '\n'];
0136            
0137               otherwise
0138     end
0139      
0140 end
0141 
0142 otherlines=['!Malign and watch \n'...
0143 'M1: MALIGN,on_pass=0\n'...
0144 'W1: watch, filename="%%s.w1", mode ="centroid"\n\n'...
0145 '!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!  \n'...
0146 '!    full 32-cell ring(line):            ! \n'...
0147 '!                                         ! \n'...
0148 '!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~! \n\n'
0149 ];
0150 elelat=[elelat otherlines '\n'];
0151 
0152 
0153 elelat=[elelat '! LINE \n\n'];
0154 
0155 elelat=[elelat linename ' : LINE = (M1,W1,' ' &\n'];
0156 
0157 %% define lattice line
0158 % loop all elements
0159 for i=1:(length(AT_ring)-1)
0160     
0161  elelat=[elelat AT_ring{i}.('FamName') ', '];
0162     if (floor(i/8)==ceil(i/8))
0163      elelat = [elelat '&\n'];
0164      end
0165 end
0166 
0167 elelat=[elelat AT_ring{length(AT_ring)}.('FamName')  ') \n\n'];
0168 
0169 
0170 %% print to file
0171 
0172 of=fopen(outfile,'w');
0173 fprintf(of,elelat);
0174 
0175 fclose('all');
0176 
0177 
0178 
0179 
0180 return

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