0001 function AT_2_OPA(AT_ring,linename)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 outfile=['' linename '_lattice.opa'];
0014
0015
0016
0017
0018
0019 [families,ind_first_oc_ring]=...
0020 unique(getcellstruct(AT_ring,'FamName',1:length(AT_ring)),'first');
0021
0022
0023
0024 elelat=['Energy = ' num2str(AT_ring{1}.Energy*1e-9) ';\n\n'];
0025
0026 format='%8.10f';
0027
0028
0029 for i=1:length(families)
0030 el= AT_ring{ind_first_oc_ring(i)};
0031 if isfield(el,'BetaCode')
0032 type=el.BetaCode;
0033 elseif isfield(el,'Class')
0034 type=el.Class;
0035 else
0036 type='Marker';
0037 end
0038
0039 switch type
0040 case {'DI','Dipole','Bend'}
0041 di=[' ' el.('FamName') ': '...
0042 ' Combined, L = ' num2str(el.('Length'),format) ', '...
0043 'T = ' num2str(180/pi*el.('BendingAngle'),format) ', '...
0044 'K = ' num2str(el.('PolynomB')(2),format) ', '...
0045 'T1 = ' num2str(180/pi*el.('EntranceAngle'),format) ', '...
0046 'T2 = ' num2str(180/pi*el.('ExitAngle'),format) ', '...
0047 'K1in = ' num2str(0,format) ', '...
0048 'k1ex = ' num2str(0,format) ', '...
0049 'k2in = ' num2str(0,format) ', '...
0050 'k2ex = ' num2str(0,format) ', '...
0051 'gap = ' num2str(0,format) ', '...
0052 'ax = ' num2str(32,format) ', '...
0053 'ay = ' num2str(20,format) '; '...
0054 ];
0055
0056 elelat=[elelat di '\n\n'];
0057 case {'QP','Quadrupole'}
0058
0059 if el.('MaxOrder')==3
0060 if el.('PolynomB')(4)==0
0061 qp=[' ' el.('FamName') ': '...
0062 ' quadrupole, L = ' num2str(el.('Length'),format) ', '...
0063 ...
0064 'K = ' num2str(el.('PolynomB')(2),format) ', '...
0065 'ax = ' num2str(32,format) ', '...
0066 'ay = ' num2str(20,format) '; '...
0067 ];
0068 else
0069
0070 qp=[' ' el.('FamName') '_sl: '...
0071 ' quadrupole, L = ' num2str(el.('Length')/4,format) ', '...
0072 'K = ' num2str(el.('PolynomB')(2),format) ', '...
0073 'ax = ' num2str(32,format) ', '...
0074 'ay = ' num2str(20,format) '; '...
0075 '\n'...
0076 ];
0077 qp=[qp ' ' el.('FamName') '_oc:Multipole,'...
0078 ' N= ' num2str(4,format) ','...
0079 ...
0080 ' K= ' num2str(el.('PolynomB')(4)*el.('Length')/2,format) ','...
0081 'ax = ' num2str(32,format) ', '...
0082 'ay = ' num2str(20,format) '; '...
0083 '\n'...
0084 ];
0085 qp=[qp el.('FamName') ':'...
0086 el.('FamName') '_sl,'...
0087 el.('FamName') '_oc,'...
0088 el.('FamName') '_sl,'...
0089 el.('FamName') '_sl,'...
0090 el.('FamName') '_oc,'...
0091 el.('FamName') '_sl,'...
0092 '\n'...
0093 ];
0094 qp(end-2:end)=[];
0095 qp=[qp ';\n'];
0096 end
0097 else
0098 qp=[' ' el.('FamName') ': '...
0099 ' quadrupole, L = ' num2str(el.('Length'),format) ', '...
0100 'K = ' num2str(el.('PolynomB')(2),format) ', '...
0101 'ax = ' num2str(32,format) ', '...
0102 'ay = ' num2str(20,format) '; '...
0103 ];
0104
0105 end
0106
0107
0108 elelat=[elelat qp '\n\n'];
0109 case {'SX','Sextupole'}
0110 sx=[' ' el.('FamName') ': '...
0111 ' sextupole, L = ' num2str(el.('Length'),format) ', '...
0112 ...
0113 ' K = ' num2str(el.('PolynomB')(3),format) ', n = 6 , '...
0114 'ax = ' num2str(32,format) ', '...
0115 'ay = ' num2str(20,format) '; '...
0116 ];
0117 elelat=[elelat sx '\n\n'];
0118 case {'OC','Octupole'}
0119 sx=[];
0120 nslice=2;
0121 sx=[sx ' ' el.('FamName') '_dr: drift, L= ' num2str(el.('Length')/2/nslice,format) ';' '\n'];
0122 sx=[sx ' ' el.('FamName') '_sl:Multipole,'...
0123 ' N= ' num2str(el.('MaxOrder')+1,format) ','...
0124 ...
0125 ' K= ' num2str(el.('PolynomB')(el.('MaxOrder')+1)*el.('Length')/nslice,format) ','...
0126 'ax = ' num2str(32,format) ', '...
0127 'ay = ' num2str(20,format) '; '...
0128 '\n'...
0129 ];
0130 sx=[sx el.('FamName') ':'];
0131 for islice=1:nslice
0132 sx=[sx el.('FamName') '_dr, ' el.('FamName') '_sl, ' el.('FamName') '_dr, '];
0133 end
0134 sx(end-1:end)=[];
0135 sx=[sx ';\n'];
0136
0137 elelat=[elelat sx '\n\n'];
0138 case {'MP','Multipole'}
0139 mp=[' ' el.('FamName') ':Multipole,'...
0140 ' N= ' num2str(el.('MaxOrder')+1,format) ','...
0141 ...
0142 ' K= ' num2str(el.('PolynomB')(el.('MaxOrder')+1),format) ','...
0143 ' ax = ' num2str(32,format) ', '...
0144 'ay = ' num2str(20,format) '; '...
0145 ];
0146 elelat=[elelat mp '\n\n'];
0147 case {'ThinMultipole'}
0148 warning('still to be defined!')
0149 case {'PU','Monitor'}
0150 pu=[' ' el.('FamName') ': monitor' ', '...
0151 'ax = ' num2str(32,format) ', '...
0152 'ay = ' num2str(20,format) '; '...
0153 ];
0154 elelat=[elelat pu '\n\n'];
0155 case {'MRK','Marker'}
0156 mrk=[' ' el.('FamName') ': marker' '; '...
0157 ];
0158 elelat=[elelat mrk '\n\n'];
0159 case {'KI','Corrector'}
0160 ki=[' ' el.('FamName') ': marker' '; '...
0161 ];
0162
0163 elelat=[elelat ki '\n\n'];
0164 case {'SD','DR','Drift'}
0165
0166 dr=[' ' el.('FamName') ': drift, L = ' num2str(el.('Length'),format) ', '...
0167 'ax = ' num2str(32,format) ', '...
0168 'ay = ' num2str(20,format) '; '...
0169 ];
0170
0171 elelat=[elelat dr '\n\n'];
0172
0173 case {'CAV','RFCavity'}
0174
0175
0176
0177 rfc=[' ' el.('FamName') ':marker;'];
0178 elelat=[elelat rfc '\n\n'];
0179
0180 otherwise
0181 warning(['Element: ' el.('FamName') ' was not converted, since it does not match any Class.'])
0182 mrk=[' ' el.('FamName') ': marker' '; '...
0183 ];
0184 elelat=[elelat mrk '\n\n'];
0185 end
0186
0187 end
0188
0189
0190
0191
0192 elelat=[elelat linename ':'];
0193
0194
0195
0196 for i=1:length(AT_ring)
0197 if i~=1
0198 elelat=[elelat ',' AT_ring{i}.('FamName') '\n'];
0199 else
0200 elelat=[elelat '' AT_ring{i}.('FamName') '\n'];
0201 end
0202 end
0203
0204 elelat=[elelat ';'];
0205
0206 elelat=strrep(elelat,'RFC','RFCav');
0207
0208
0209 of=fopen(outfile,'w');
0210 fprintf(of,elelat);
0211
0212 fclose('all');
0213
0214
0215
0216
0217 return