source: PSPA/madxPSPA/doc/usrguide/Introduction/select.html

Last change on this file was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 14.1 KB
Line 
1<head>
2<title>SELECT</title>
3<!-- Changed by: Hans Grote, 16-Jan-2003 -->
4</head>
5
6<body bgcolor="#ffffff">
7
8<center>
9EUROPEAN 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
14The elements, or a range of elements, in a sequence can be selected for
15various purposes. Such selections remain valid until cleared (in difference
16to MAD-8); it is therefore recommended to always start with a
17<pre>
18select,flag=...,clear;
19</pre>
20before setting a new selection.
21<pre>
22SELECT,FLAG=name,RANGE=range,CLASS=class,PATTERN=pattern[,FULL][,CLEAR];
23</pre>
24where the name for FLAG can be one of ERROR, MAKETHIN, SEQEDIT
25or the name of a twiss table which is established for all sequence
26positions in general.
27<p>
28Selected 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>
30criteria.
31<p>
32Any number of SELECT commands can be issued for the same flag and
33are accumulated (logically ORed). In this context note the following:
34<pre>
35SELECT,FLAG=name,FULL;
36</pre>
37selects all positions in the sequence for this flag. This is the
38default for all tables and makethin, whereas for ERROR and SEQEDIT the
39default is "nothing selected".
40<p><a name=save_select></a>SAVE:
41A SELECT,FLAG=SAVE statement causes the selected sequences, elements, and
42variables to be written into the save file. A class (only used for
43element selection), and a pattern can be specified.
44Example:
45<pre>
46select,flag=save,class=variable,pattern="abc.*";
47save,file=mysave;
48</pre>
49will save all variables (and sequences) containing "abc" in their name,
50but not elements with names containing "abc" since the class "variable"
51does not exist (astucieux, non ?).
52<p>SECTORMAP:
53A SELECT,FLAG=SECTORMAP statement causes sectormaps to be written into
54the file "sectormap" like in MAD-8. For the file to be written,
55a flag SECTORMAP must be issued on the TWISS command in addition.
56<p>TWISS:
57A SELECT,FLAG=TWISS statement causes the selected rows and columns
58to be written into
59the Twiss TFS file (former OPTICS command in MAD-8).
60The column selection is done on the same select. See as well example 2.
61
62Example 1:
63<pre>
64TITLE,'Test input for MAD-X';
65
66option,rbarc=false; // use arc length of rbends
67beam; ! sets the default beam for the following sequence
68option,-echo;
69call file=fv9.opt;  ! contains optics parameters
70call file="fv9.seq"; ! contains a small sequence "fivecell"
71OPTION,ECHO;
72SELECT,FLAG=SECTORMAP,clear;
73SELECT,FLAG=SECTORMAP,PATTERN="^m.*";
74SELECT,FLAG=TWISS,clear;
75SELECT,FLAG=TWISS,PATTERN="^m.*",column=name,s,betx,bety;
76USE,PERIOD=FIVECELL;
77twiss,file=optics,sectormap;
78stop;
79</pre>
80This 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>
162Example 2:
163<p>
164Addition 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>
169will write the current value of var1 etc. into the table each time
170a new line is added; values from the same (current) line can be
171accessed by these variables, e.g.
172<pre>
173   var1:= sqrt(beam->ex*table(twiss,betx));
174</pre>
175in the case of table above being "twiss". The plot command accepts
176the new variables.
177<p>
178Remark: this replaces the "string" variables of MAD-8.
179<p>
180<a name=ucreate></a>
181This example demonstrates as well the usage of
182a user defined table.
183<pre>
184beam,ex=1.e-6,ey=1.e-3;
185// element definitions
186mb:rbend, l=14.2, angle:=0,k0:=bang/14.2;
187mq:quadrupole, l:=3.1,apertype=ellipse,aperture={1,2};
188qft:mq, l:=0.31, k1:=kqf,tilt=-pi/4;
189qf.1:mq, l:=3.1, k1:=kqf;
190qf.2:mq, l:=3.1, k1:=kqf;
191qf.3:mq, l:=3.1, k1:=kqf;
192qf.4:mq, l:=3.1, k1:=kqf;
193qf.5:mq, l:=3.1, k1:=kqf;
194qd.1:mq, l:=3.1, k1:=kqd;
195qd.2:mq, l:=3.1, k1:=kqd;
196qd.3:mq, l:=3.1, k1:=kqd;
197qd.4:mq, l:=3.1, k1:=kqd;
198qd.5:mq, l:=3.1, k1:=kqd;
199bph:hmonitor, l:=l.bpm;
200bpv:vmonitor, l:=l.bpm;
201cbh:hkicker;
202cbv:vkicker;
203cbh.1:cbh, kick:=acbh1;
204cbh.2:cbh, kick:=acbh2;
205cbh.3:cbh, kick:=acbh3;
206cbh.4:cbh, kick:=acbh4;
207cbh.5:cbh, kick:=acbh5;
208cbv.1:cbv, kick:=acbv1;
209cbv.2:cbv, kick:=acbv2;
210cbv.3:cbv, kick:=acbv3;
211cbv.4:cbv, kick:=acbv4;
212cbv.5:cbv, kick:=acbv5;
213!mscbh:sextupole, l:=1.1, k2:=ksf;
214mscbh:multipole, knl:={0,0,0,ksf},tilt=-pi/8;
215mscbv:sextupole, l:=1.1, k2:=ksd;
216!mscbv:octupole, l:=1.1, k3:=ksd,tilt=-pi/8;
217
218// sequence declaration
219
220fivecell: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;
292end:marker, at=5.346000e+02;
293endsequence;
294
295// forces and other constants
296
297l.bpm:=.3;
298bang:=.509998807401e-2;
299kqf:=.872651312e-2;
300kqd:=-.872777242e-2;
301ksf:=.0198492943;
302ksd:=-.039621283;
303acbv1:=1.e-4;
304acbh1:=1.e-4;
305!save,sequence=fivecell,file,mad8;
306
307s := table(twiss,bpv[5],betx);
308myvar := sqrt(beam->ex*table(twiss,betx));
309use, period=fivecell;
310select,flag=twiss,column=name,s,myvar,apertype;
311twiss,file;
312n = 0;
313create,table=mytab,column=dp,mq1,mq2;
314mq1:=table(summ,q1);
315mq2:=table(summ,q2);
316while ( n < 11)
317{
318  n = n + 1;
319  dp = 1.e-4*(n-6);
320  twiss,deltap=dp;
321  fill,table=mytab;
322}
323write,table=mytab;
324plot,haxis=s,vaxis=aper_1,aper_2,colour=100,range=#s/cbv.1,notitle;
325stop;
326</pre>
327prints 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>
349and produces a twiss file with the additional column myvar, as well as a plot
350file with the aperture values plotted.
351<p>
352<a name=screate></a>
353
354Example of joing 2 tables with different length into a third table
355making use of the length of either table as given by
356table("your_table_name", tablelength) and adding names by the "_name"
357attribute.
358
359<pre>
360
361title,   "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
390stop;
391</pre>
392
393<address>
394<a href="http://www.cern.ch/Hans.Grote/hansg_sign.html">hansg</a>,
395May 8, 2001
396</address>
397</body>
398
399
400
401
402
Note: See TracBrowser for help on using the repository browser.