1 | <head> |
---|
2 | <title>SELECT</title> |
---|
3 | <!-- Changed by: Hans Grote, 16-Jan-2003 --> |
---|
4 | </head> |
---|
5 | |
---|
6 | <body bgcolor="#ffffff"> |
---|
7 | |
---|
8 | <center> |
---|
9 | EUROPEAN ORGANIZATION FOR NUCLEAR RESEARCH |
---|
10 | <IMG SRC="http://cern.ch/madx/icons/mx7_25.gif" align=right> |
---|
11 | <h2>Selection Statements</h2> |
---|
12 | </center> |
---|
13 | |
---|
14 | The elements, or a range of elements, in a sequence can be selected for |
---|
15 | various purposes. Such selections remain valid until cleared (in difference |
---|
16 | to MAD-8); it is therefore recommended to always start with a |
---|
17 | <pre> |
---|
18 | select,flag=...,clear; |
---|
19 | </pre> |
---|
20 | before setting a new selection. |
---|
21 | <pre> |
---|
22 | SELECT,FLAG=name,RANGE=range,CLASS=class,PATTERN=pattern[,FULL][,CLEAR]; |
---|
23 | </pre> |
---|
24 | where the name for FLAG can be one of ERROR, MAKETHIN, SEQEDIT |
---|
25 | or the name of a twiss table which is established for all sequence |
---|
26 | positions in general. |
---|
27 | <p> |
---|
28 | Selected elements have to fulfill the <a href="ranges.html#range">RANGE</a>, |
---|
29 | <a href="ranges.html#class">CLASS</a>, and <a href="wildcard.html">PATTERN</a> |
---|
30 | criteria. |
---|
31 | <p> |
---|
32 | Any number of SELECT commands can be issued for the same flag and |
---|
33 | are accumulated (logically ORed). In this context note the following: |
---|
34 | <pre> |
---|
35 | SELECT,FLAG=name,FULL; |
---|
36 | </pre> |
---|
37 | selects all positions in the sequence for this flag. This is the |
---|
38 | default for all tables and makethin, whereas for ERROR and SEQEDIT the |
---|
39 | default is "nothing selected". |
---|
40 | <p><a name=save_select></a>SAVE: |
---|
41 | A SELECT,FLAG=SAVE statement causes the selected sequences, elements, and |
---|
42 | variables to be written into the save file. A class (only used for |
---|
43 | element selection), and a pattern can be specified. |
---|
44 | Example: |
---|
45 | <pre> |
---|
46 | select,flag=save,class=variable,pattern="abc.*"; |
---|
47 | save,file=mysave; |
---|
48 | </pre> |
---|
49 | will save all variables (and sequences) containing "abc" in their name, |
---|
50 | but not elements with names containing "abc" since the class "variable" |
---|
51 | does not exist (astucieux, non ?). |
---|
52 | <p>SECTORMAP: |
---|
53 | A SELECT,FLAG=SECTORMAP statement causes sectormaps to be written into |
---|
54 | the file "sectormap" like in MAD-8. For the file to be written, |
---|
55 | a flag SECTORMAP must be issued on the TWISS command in addition. |
---|
56 | <p>TWISS: |
---|
57 | A SELECT,FLAG=TWISS statement causes the selected rows and columns |
---|
58 | to be written into |
---|
59 | the Twiss TFS file (former OPTICS command in MAD-8). |
---|
60 | The column selection is done on the same select. See as well example 2. |
---|
61 | |
---|
62 | Example 1: |
---|
63 | <pre> |
---|
64 | TITLE,'Test input for MAD-X'; |
---|
65 | |
---|
66 | option,rbarc=false; // use arc length of rbends |
---|
67 | beam; ! sets the default beam for the following sequence |
---|
68 | option,-echo; |
---|
69 | call file=fv9.opt; ! contains optics parameters |
---|
70 | call file="fv9.seq"; ! contains a small sequence "fivecell" |
---|
71 | OPTION,ECHO; |
---|
72 | SELECT,FLAG=SECTORMAP,clear; |
---|
73 | SELECT,FLAG=SECTORMAP,PATTERN="^m.*"; |
---|
74 | SELECT,FLAG=TWISS,clear; |
---|
75 | SELECT,FLAG=TWISS,PATTERN="^m.*",column=name,s,betx,bety; |
---|
76 | USE,PERIOD=FIVECELL; |
---|
77 | twiss,file=optics,sectormap; |
---|
78 | stop; |
---|
79 | </pre> |
---|
80 | This produces a file <a href="sectormap.html">sectormap</a>, and a |
---|
81 | <a name=tfs></a>twiss output file (name = optics): |
---|
82 | <pre> |
---|
83 | @ TYPE %05s "TWISS" |
---|
84 | @ PARTICLE %08s "POSITRON" |
---|
85 | @ MASS %le 0.000510998902 |
---|
86 | @ CHARGE %le 1 |
---|
87 | @ E0 %le 1 |
---|
88 | @ PC %le 0.99999986944 |
---|
89 | @ GAMMA %le 1956.95136738 |
---|
90 | @ KBUNCH %le 1 |
---|
91 | @ NPART %le 0 |
---|
92 | @ EX %le 1 |
---|
93 | @ EY %le 1 |
---|
94 | @ ET %le 0 |
---|
95 | @ LENGTH %le 534.6 |
---|
96 | @ ALFA %le 0.00044339992938 |
---|
97 | @ ORBIT5 %le -0 |
---|
98 | @ GAMMATR %le 47.4900022541 |
---|
99 | @ Q1 %le 1.25413071556 |
---|
100 | @ Q2 %le 1.25485338377 |
---|
101 | @ DQ1 %le 1.05329608302 |
---|
102 | @ DQ2 %le 1.04837000224 |
---|
103 | @ DXMAX %le 2.17763211131 |
---|
104 | @ DYMAX %le 0 |
---|
105 | @ XCOMAX %le 0 |
---|
106 | @ YCOMAX %le 0 |
---|
107 | @ BETXMAX %le 177.70993499 |
---|
108 | @ BETYMAX %le 177.671582415 |
---|
109 | @ XCORMS %le 0 |
---|
110 | @ YCORMS %le 0 |
---|
111 | @ DXRMS %le 1.66004270906 |
---|
112 | @ DYRMS %le 0 |
---|
113 | @ DELTAP %le 0 |
---|
114 | @ TITLE %20s "Test input for MAD-X" |
---|
115 | @ ORIGIN %16s "MAD-X 0.20 Linux" |
---|
116 | @ DATE %08s "07/06/02" |
---|
117 | @ TIME %08s "14.25.51" |
---|
118 | * NAME S BETX BETY |
---|
119 | $ %s %le %le %le |
---|
120 | "MSCBH" 4.365 171.6688159 33.31817319 |
---|
121 | "MB" 19.72 108.1309095 58.58680717 |
---|
122 | "MB" 35.38 61.96499987 102.9962313 |
---|
123 | "MB" 51.04 34.61640793 166.2227523 |
---|
124 | "MSCBV.1" 57.825 33.34442808 171.6309057 |
---|
125 | "MB" 73.18 58.61984637 108.0956006 |
---|
126 | "MB" 88.84 103.0313887 61.93159422 |
---|
127 | "MB" 104.5 166.2602486 34.58939635 |
---|
128 | "MSCBH" 111.285 171.6688159 33.31817319 |
---|
129 | "MB" 126.64 108.1309095 58.58680717 |
---|
130 | "MB" 142.3 61.96499987 102.9962313 |
---|
131 | "MB" 157.96 34.61640793 166.2227523 |
---|
132 | "MSCBV" 164.745 33.34442808 171.6309057 |
---|
133 | "MB" 180.1 58.61984637 108.0956006 |
---|
134 | "MB" 195.76 103.0313887 61.93159422 |
---|
135 | "MB" 211.42 166.2602486 34.58939635 |
---|
136 | "MSCBH" 218.205 171.6688159 33.31817319 |
---|
137 | "MB" 233.56 108.1309095 58.58680717 |
---|
138 | "MB" 249.22 61.96499987 102.9962313 |
---|
139 | "MB" 264.88 34.61640793 166.2227523 |
---|
140 | "MSCBV" 271.665 33.34442808 171.6309057 |
---|
141 | "MB" 287.02 58.61984637 108.0956006 |
---|
142 | "MB" 302.68 103.0313887 61.93159422 |
---|
143 | "MB" 318.34 166.2602486 34.58939635 |
---|
144 | "MSCBH" 325.125 171.6688159 33.31817319 |
---|
145 | "MB" 340.48 108.1309095 58.58680717 |
---|
146 | "MB" 356.14 61.96499987 102.9962313 |
---|
147 | "MB" 371.8 34.61640793 166.2227523 |
---|
148 | "MSCBV" 378.585 33.34442808 171.6309057 |
---|
149 | "MB" 393.94 58.61984637 108.0956006 |
---|
150 | "MB" 409.6 103.0313887 61.93159422 |
---|
151 | "MB" 425.26 166.2602486 34.58939635 |
---|
152 | "MSCBH" 432.045 171.6688159 33.31817319 |
---|
153 | "MB" 447.4 108.1309095 58.58680717 |
---|
154 | "MB" 463.06 61.96499987 102.9962313 |
---|
155 | "MB" 478.72 34.61640793 166.2227523 |
---|
156 | "MSCBV" 485.505 33.34442808 171.6309057 |
---|
157 | "MB" 500.86 58.61984637 108.0956006 |
---|
158 | "MB" 516.52 103.0313887 61.93159422 |
---|
159 | "MB" 532.18 166.2602486 34.58939635 |
---|
160 | </pre> |
---|
161 | <p> |
---|
162 | Example 2: |
---|
163 | <p> |
---|
164 | Addition of variables to (any internal) table: |
---|
165 | <pre> |
---|
166 | select,flag=table,column=name,s,betx,...,var1,var2,...; or |
---|
167 | select,flag=table,full,column=var1,var2,...; ! default col.s + new |
---|
168 | </pre> |
---|
169 | will write the current value of var1 etc. into the table each time |
---|
170 | a new line is added; values from the same (current) line can be |
---|
171 | accessed by these variables, e.g. |
---|
172 | <pre> |
---|
173 | var1:= sqrt(beam->ex*table(twiss,betx)); |
---|
174 | </pre> |
---|
175 | in the case of table above being "twiss". The plot command accepts |
---|
176 | the new variables. |
---|
177 | <p> |
---|
178 | Remark: this replaces the "string" variables of MAD-8. |
---|
179 | <p> |
---|
180 | <a name=ucreate></a> |
---|
181 | This example demonstrates as well the usage of |
---|
182 | a user defined table. |
---|
183 | <pre> |
---|
184 | beam,ex=1.e-6,ey=1.e-3; |
---|
185 | // element definitions |
---|
186 | mb:rbend, l=14.2, angle:=0,k0:=bang/14.2; |
---|
187 | mq:quadrupole, l:=3.1,apertype=ellipse,aperture={1,2}; |
---|
188 | qft:mq, l:=0.31, k1:=kqf,tilt=-pi/4; |
---|
189 | qf.1:mq, l:=3.1, k1:=kqf; |
---|
190 | qf.2:mq, l:=3.1, k1:=kqf; |
---|
191 | qf.3:mq, l:=3.1, k1:=kqf; |
---|
192 | qf.4:mq, l:=3.1, k1:=kqf; |
---|
193 | qf.5:mq, l:=3.1, k1:=kqf; |
---|
194 | qd.1:mq, l:=3.1, k1:=kqd; |
---|
195 | qd.2:mq, l:=3.1, k1:=kqd; |
---|
196 | qd.3:mq, l:=3.1, k1:=kqd; |
---|
197 | qd.4:mq, l:=3.1, k1:=kqd; |
---|
198 | qd.5:mq, l:=3.1, k1:=kqd; |
---|
199 | bph:hmonitor, l:=l.bpm; |
---|
200 | bpv:vmonitor, l:=l.bpm; |
---|
201 | cbh:hkicker; |
---|
202 | cbv:vkicker; |
---|
203 | cbh.1:cbh, kick:=acbh1; |
---|
204 | cbh.2:cbh, kick:=acbh2; |
---|
205 | cbh.3:cbh, kick:=acbh3; |
---|
206 | cbh.4:cbh, kick:=acbh4; |
---|
207 | cbh.5:cbh, kick:=acbh5; |
---|
208 | cbv.1:cbv, kick:=acbv1; |
---|
209 | cbv.2:cbv, kick:=acbv2; |
---|
210 | cbv.3:cbv, kick:=acbv3; |
---|
211 | cbv.4:cbv, kick:=acbv4; |
---|
212 | cbv.5:cbv, kick:=acbv5; |
---|
213 | !mscbh:sextupole, l:=1.1, k2:=ksf; |
---|
214 | mscbh:multipole, knl:={0,0,0,ksf},tilt=-pi/8; |
---|
215 | mscbv:sextupole, l:=1.1, k2:=ksd; |
---|
216 | !mscbv:octupole, l:=1.1, k3:=ksd,tilt=-pi/8; |
---|
217 | |
---|
218 | // sequence declaration |
---|
219 | |
---|
220 | fivecell:sequence, refer=centre, l=534.6; |
---|
221 | qf.1:qf.1, at=1.550000e+00; |
---|
222 | qft:qft, at=3.815000e+00; |
---|
223 | ! mscbh:mscbh, at=3.815000e+00; |
---|
224 | cbh.1:cbh.1, at=4.365000e+00; |
---|
225 | mb:mb, at=1.262000e+01; |
---|
226 | mb:mb, at=2.828000e+01; |
---|
227 | mb:mb, at=4.394000e+01; |
---|
228 | bpv:bpv, at=5.246000e+01; |
---|
229 | qd.1:qd.1, at=5.501000e+01; |
---|
230 | mscbv:mscbv, at=5.727500e+01; |
---|
231 | cbv.1:cbv.1, at=5.782500e+01; |
---|
232 | mb:mb, at=6.608000e+01; |
---|
233 | mb:mb, at=8.174000e+01; |
---|
234 | mb:mb, at=9.740000e+01; |
---|
235 | bph:bph, at=1.059200e+02; |
---|
236 | qf.2:qf.2, at=1.084700e+02; |
---|
237 | mscbh:mscbh, at=1.107350e+02; |
---|
238 | cbh.2:cbh.2, at=1.112850e+02; |
---|
239 | mb:mb, at=1.195400e+02; |
---|
240 | mb:mb, at=1.352000e+02; |
---|
241 | mb:mb, at=1.508600e+02; |
---|
242 | bpv:bpv, at=1.593800e+02; |
---|
243 | qd.2:qd.2, at=1.619300e+02; |
---|
244 | mscbv:mscbv, at=1.641950e+02; |
---|
245 | cbv.2:cbv.2, at=1.647450e+02; |
---|
246 | mb:mb, at=1.730000e+02; |
---|
247 | mb:mb, at=1.886600e+02; |
---|
248 | mb:mb, at=2.043200e+02; |
---|
249 | bph:bph, at=2.128400e+02; |
---|
250 | qf.3:qf.3, at=2.153900e+02; |
---|
251 | mscbh:mscbh, at=2.176550e+02; |
---|
252 | cbh.3:cbh.3, at=2.182050e+02; |
---|
253 | mb:mb, at=2.264600e+02; |
---|
254 | mb:mb, at=2.421200e+02; |
---|
255 | mb:mb, at=2.577800e+02; |
---|
256 | bpv:bpv, at=2.663000e+02; |
---|
257 | qd.3:qd.3, at=2.688500e+02; |
---|
258 | mscbv:mscbv, at=2.711150e+02; |
---|
259 | cbv.3:cbv.3, at=2.716650e+02; |
---|
260 | mb:mb, at=2.799200e+02; |
---|
261 | mb:mb, at=2.955800e+02; |
---|
262 | mb:mb, at=3.112400e+02; |
---|
263 | bph:bph, at=3.197600e+02; |
---|
264 | qf.4:qf.4, at=3.223100e+02; |
---|
265 | mscbh:mscbh, at=3.245750e+02; |
---|
266 | cbh.4:cbh.4, at=3.251250e+02; |
---|
267 | mb:mb, at=3.333800e+02; |
---|
268 | mb:mb, at=3.490400e+02; |
---|
269 | mb:mb, at=3.647000e+02; |
---|
270 | bpv:bpv, at=3.732200e+02; |
---|
271 | qd.4:qd.4, at=3.757700e+02; |
---|
272 | mscbv:mscbv, at=3.780350e+02; |
---|
273 | cbv.4:cbv.4, at=3.785850e+02; |
---|
274 | mb:mb, at=3.868400e+02; |
---|
275 | mb:mb, at=4.025000e+02; |
---|
276 | mb:mb, at=4.181600e+02; |
---|
277 | bph:bph, at=4.266800e+02; |
---|
278 | qf.5:qf.5, at=4.292300e+02; |
---|
279 | mscbh:mscbh, at=4.314950e+02; |
---|
280 | cbh.5:cbh.5, at=4.320450e+02; |
---|
281 | mb:mb, at=4.403000e+02; |
---|
282 | mb:mb, at=4.559600e+02; |
---|
283 | mb:mb, at=4.716200e+02; |
---|
284 | bpv:bpv, at=4.801400e+02; |
---|
285 | qd.5:qd.5, at=4.826900e+02; |
---|
286 | mscbv:mscbv, at=4.849550e+02; |
---|
287 | cbv.5:cbv.5, at=4.855050e+02; |
---|
288 | mb:mb, at=4.937600e+02; |
---|
289 | mb:mb, at=5.094200e+02; |
---|
290 | mb:mb, at=5.250800e+02; |
---|
291 | bph:bph, at=5.336000e+02; |
---|
292 | end:marker, at=5.346000e+02; |
---|
293 | endsequence; |
---|
294 | |
---|
295 | // forces and other constants |
---|
296 | |
---|
297 | l.bpm:=.3; |
---|
298 | bang:=.509998807401e-2; |
---|
299 | kqf:=.872651312e-2; |
---|
300 | kqd:=-.872777242e-2; |
---|
301 | ksf:=.0198492943; |
---|
302 | ksd:=-.039621283; |
---|
303 | acbv1:=1.e-4; |
---|
304 | acbh1:=1.e-4; |
---|
305 | !save,sequence=fivecell,file,mad8; |
---|
306 | |
---|
307 | s := table(twiss,bpv[5],betx); |
---|
308 | myvar := sqrt(beam->ex*table(twiss,betx)); |
---|
309 | use, period=fivecell; |
---|
310 | select,flag=twiss,column=name,s,myvar,apertype; |
---|
311 | twiss,file; |
---|
312 | n = 0; |
---|
313 | create,table=mytab,column=dp,mq1,mq2; |
---|
314 | mq1:=table(summ,q1); |
---|
315 | mq2:=table(summ,q2); |
---|
316 | while ( n < 11) |
---|
317 | { |
---|
318 | n = n + 1; |
---|
319 | dp = 1.e-4*(n-6); |
---|
320 | twiss,deltap=dp; |
---|
321 | fill,table=mytab; |
---|
322 | } |
---|
323 | write,table=mytab; |
---|
324 | plot,haxis=s,vaxis=aper_1,aper_2,colour=100,range=#s/cbv.1,notitle; |
---|
325 | stop; |
---|
326 | </pre> |
---|
327 | prints the following user table on output: |
---|
328 | <pre> |
---|
329 | @ NAME %05s "MYTAB" |
---|
330 | @ TYPE %04s "USER" |
---|
331 | @ TITLE %08s "no-title" |
---|
332 | @ ORIGIN %16s "MAD-X 1.09 Linux" |
---|
333 | @ DATE %08s "10/12/02" |
---|
334 | @ TIME %08s "10.45.25" |
---|
335 | * DP MQ1 MQ2 |
---|
336 | $ %le %le %le |
---|
337 | -0.0005 1.242535951 1.270211135 |
---|
338 | -0.0004 1.242495534 1.270197018 |
---|
339 | -0.0003 1.242452432 1.270185673 |
---|
340 | -0.0002 1.242406653 1.270177093 |
---|
341 | -0.0001 1.242358206 1.270171269 |
---|
342 | 0 1.242307102 1.27016819 |
---|
343 | 0.0001 1.242253353 1.270167843 |
---|
344 | 0.0002 1.242196974 1.270170214 |
---|
345 | 0.0003 1.24213798 1.270175288 |
---|
346 | 0.0004 1.242076387 1.270183048 |
---|
347 | 0.0005 1.242012214 1.270193477 |
---|
348 | </pre> |
---|
349 | and produces a twiss file with the additional column myvar, as well as a plot |
---|
350 | file with the aperture values plotted. |
---|
351 | <p> |
---|
352 | <a name=screate></a> |
---|
353 | |
---|
354 | Example of joing 2 tables with different length into a third table |
---|
355 | making use of the length of either table as given by |
---|
356 | table("your_table_name", tablelength) and adding names by the "_name" |
---|
357 | attribute. |
---|
358 | |
---|
359 | <pre> |
---|
360 | |
---|
361 | title, "summing of offset and alignment tables"; |
---|
362 | set, format="13.6f"; |
---|
363 | |
---|
364 | readtable, table=align, file="align.ip2.b1.tfs"; // mesured alignment |
---|
365 | readtable, table=offset, file="offset.ip2.b1.tfs"; // nominal offsets |
---|
366 | |
---|
367 | n_elem = table(offset, tablelength); |
---|
368 | |
---|
369 | create, table=align_offset, column=_name,s_ip,x_off,dx_off,ddx_off,y_off,dy_off,ddy_off; |
---|
370 | |
---|
371 | calcul(elem_name) : macro = { |
---|
372 | x_off = table(align, elem_name, x_ali) + x_off; |
---|
373 | y_off = table(align, elem_name, y_ali) + y_off; |
---|
374 | } |
---|
375 | |
---|
376 | |
---|
377 | one_elem(j_elem) : macro = { |
---|
378 | setvars, table=offset, row=j_elem; |
---|
379 | exec, calcul(tabstring(offset, name, j_elem)); |
---|
380 | fill, table=align_offset; |
---|
381 | } |
---|
382 | |
---|
383 | |
---|
384 | i_elem = 0; |
---|
385 | while (i_elem < n_elem) { i_elem = i_elem + 1; exec, one_elem($i_elem); } |
---|
386 | |
---|
387 | write, table=align_offset, file="align_offset.tfs"; |
---|
388 | |
---|
389 | |
---|
390 | stop; |
---|
391 | </pre> |
---|
392 | |
---|
393 | <address> |
---|
394 | <a href="http://www.cern.ch/Hans.Grote/hansg_sign.html">hansg</a>, |
---|
395 | May 8, 2001 |
---|
396 | </address> |
---|
397 | </body> |
---|
398 | |
---|
399 | |
---|
400 | |
---|
401 | |
---|
402 | |
---|