forked from MethodicalAcceleratorDesign/MAD-X-User-Manual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.tex
811 lines (665 loc) · 27.7 KB
/
format.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
%%\title{Command Format}
% Changed by: Chris ISELIN, 24-Jan-1997
% Changed by: Hans Grote, 25-Sep-2002
% Changed by: Ghislain ROY, 27-Jan-2014
\chapter{Command Format}
\section{Input Statements}
Input for \madx follows in broad lines the
\href{http://cern.ch/mad9}{\madnine}\index{MAD-9} format, \textsl{i.e.}
free format with commas (,) as separators, although blanks may be used as
separators outside \{...\} enclosures.
Blank input lines do not affect program execution.
The input is not case sensitive except for strings enclosed in double
quotes (" ").
The input file consists of a sequence of statements.
A statement may occupy any number of input lines.
Several statements may be placed on the same line.
A statement must be terminated by a semicolon (;).
Several statements may be grouped into a block enclosed inside a \{...\}
enclosure. In this case the terminating semmicolon can be omitted.
\madxmp{if (a $<$ 3) \{ a=b*b; b=2*b+4; \};}
or
\madxmp{if (a $<$ 3) \{ a=b*b; b=2*b+4; \}}
are both valid.
\section{Comments}
When an exclamation mark (\texttt{!}) or double forward slash (\texttt{//}) is
found in the input line, the remaining characters until the end of the
line are treated as a comment and are skipped.
A comment spreading over multiple lines starts with a string \texttt{/*}
and ends with a string \texttt{*/}.
\section{Commands}
The general format for a command is
\madbox{
label: keyword \{,attribute\} ;
}
where the \texttt{\{ \}} are not part of the command and the items
enclosed in \texttt{\{ \}} can be omitted or repeated any number of times.
A command contains three parts:
\begin{madlist}
\ttitem{label}\index{label}
A label is required for a definition statement.
A label gives a name to the stored command.
\ttitem{keyword}\index{keyword}
A keyword identifies the action desired.
\ttitem{attributes}\index{attribute}
The attributes are normally entered in the
form \madxmp{attribute-name = attribute-value}
and serve to define data for the command, where:
\begin{madlist}
\ttitem{attribute-name} selects the attribute, and
\ttitem{attribute-value} provides its value.
\end{madlist}
\end{madlist}
If a value is to be assigned to an attribute, the \texttt{attribute-name} is
mandatory.
Whenever an attribute is not explicitly given a value, the default
\texttt{attribute-value} specified in the command dictionary is assumed.
%% In the case of attributes taking logical values, it is sufficient to
%% enter the \texttt{attribute-name} only; the attribute is then given the
%% default \texttt{attribute-value} specified in the command dictionary.
\section{Keywords}
\label{subsec:keyword}
A keyword begins with a letter and consists of letters and digits.
The \madx keywords are protected; attempting to use a protected
keyword as a label results in a fatal error.
The keyword \texttt{VERSION} has been introduced since version 5.02.07.
It contains the version number of the \madx release quoted as a decimal.
For example:
\madxmp{
X:> value VERSION;\\
version = 50207 ;
}
This allows testing of the version number of the running \madx process.
Note that any version prior to version 5.02.07 reports the value
\texttt{version = 0;}
\section{Attribute Types}
The command attributes can have one of the following types:
\begin{itemize}
\item String attribute,
\item Logical attribute,
\item Integer attribute,
\item Real attribute,
\item Expression,
\item Range selection,
\end{itemize}
Any integer or real attribute can be replaced by a real expression;
expressions are normally deferred\index{deferred} (see
\hyperref[sec:defer]{deferred expression}), except in the
definition of constants where they are evaluated immediately.
When a command has a \hyperref[sec:label]{label}, \madx keeps this
command in memory. This allows repeated execution of the same command by
simply entering \texttt{EXEC label;}. This construct may be nested.
%For an exhaustive list of valid declarations of constants or variables
%see \href{declarations.html}{declarations}.
\section{Variable Declarations}
\label{subsec:var_declarations}
In the following, "=" means that the variable on the left receives the
current value of the expression on the right, but does not depend on it
any further, whereas ":=" makes the variable on the left depend on the
expression on the right, \textsl{i.e.} every time the expression
changes, the variable is re-evaluated, except for "const" variables.
\madxmp{
var = expression; \\
var := expression; \\
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\= \kill
real var = expression; \>// identical \\
real var := expression; \>// to above \\
int var = expression; \>// truncated if expression is real \\
int var := expression; \\
const var = expression; \\
const var := expression; \\
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\= \kill
const real var = expression; \>// identical \\
const real var := expression; \>// to above \\
const int var = expression; \>// truncated if expression is real \\
const int var := expression;
}
\section{Identifiers or Labels}
\label{sec:label}
A label begins with a letter, followed by up to fifteen letters, digits,
decimal points (.), or underscores (\_). Characters beyond the sixteenth
are dropped, but should be avoided, and the resulting sequence must be
unique.
A label may refer to a keyword, an element, a beam-line, a sequence,
etc.
The \madx keywords are protected; using one of them as a label
results in a fatal error.
%\input{Introduction/attribute}
\section{Command Attributes}
\label{sec:attribute}
\begin{itemize}
\item A name or string attribute refers to an object, or a string.
\item A logical attribute selects or deselects an option.
\item An integer attribute defines a value stored as integer data.
\item A real attribute defines a value stored as double precision data.
\item A real expression defines a datum for a command, it may be
varied in matching. An expression is built of a combination of
operator and operand.
\item A constraint specifies a matching constraint.
\item A variable name selects a variable to be matched.
\end{itemize}
%\input{Introduction/name}
\section{Name or String Attributes}
\label{sec:name}\label{sec:string}
A name or string attribute often selects one of a set of options:
\madxmp{
xxxxxxxxxxxxxxxxxxxx\= \kill
USE, PERIOD=lhc; \>// expand the LHC sequence
}
It may also refer to a user-defined object:
\madxmp{
xxxxxxxxxxxxxxxxxxxxxxx\= \kill
TWISS, FILE=optics; \>// specifies the name of the OPTICS output file
}
It may also define a string:
\madxmp{
TITLE, "LHC version 6.2";
}
The case of letters is only significant if a string is enclosed in
quotes, otherwise all characters are converted to lowercase at
reading.
On the other hand, strings that do not contain blanks do not
need to be enclosed in quotes.
Example:
\madxmp{
CALL, FILE = "my.file"; \\
CALL, FILE = my.file; \\
CALL, FILE = MY.FILE; \\
CALL, FILE = "MY.FILE"; \\
CALL, FILE = 'MY.FILE';
}
In the first three cases, \madx will try to read a file named my.file, in the
last two it will try to read the file named MY.FILE.
%\section{String Attributes}
A string attribute makes alphanumeric information available, e.g. a
title or a file name. It can contain any characters, enclosed in single
(') or double (") quotes, except for quotes of the type used as its
delimiter.
Examples:
\madxmp{
TITLE, 'This is a title for the program run "test"'; \\
\\
SYSTEM, "ln -fns some-lengthy-directory-name local-link";
}
\section{Logical Attributes}
\label{sec:logical}
Many commands in \madx require the setting of logical values (flags) to
represent the on/off state of an option. A logical value "flag" can be
set in two ways:
\madxmp{flag | flag = true}
It can be reset by:
\madxmp{-flag | flag = false}
Example:
\madxmp{
OPTION, -ECHO; // switch off copying the input to the standard output
}
The default for a logical flag is normally \texttt{false}, but can be found e.g. for options by the command
\madxmp{HELP, option;}
\section{Integer Attributes}
\label{sec:integer}
An integer attribute usually denotes a count. Example:
\madxmp{myline: LINE = ( -3 * (a,b,c) );}
In this case, a litteral integer is requested; however, in the following
\madxmp{rfc: RFCAVITY, HARMON = 12345;}
or
\madxmp{rfc: RFCAVITY, HARMON = num;}
"num" may be an integer variable, a real variable, or an expression. In
the two latter cases, the value is truncated.
\section{Real Attributes}
\label{sec:real}
Most attributes are of type REAL and are treated internally as double
precision values. They may be set by integer values, real values, or
expressions.
Example:
\madxmp{
xxxxxxx\= \kill
ddd: \>drift, l = 1.2345; \\
dddd: \>drift, l = ddd-\textgreater l-0.3;
}
%\input{Introduction/expression}
% Changed by: Ghislain Roy, 12-Dec-2013: updated physicial constants
% to PDG2012 values; very old values were pre PDG2010.
\section{Real Expressions}
\label{sec:expression}
To facilitate the definition of interdependent quantities, any real
value and integer value can be entered as an arithmetic expression. When
a value used in an expression is redefined by the user or changed in a
matching process, the expression is reevaluated. Expression definitions
may be entered in any order. \madx evaluates them in the correct order
before it performs any computation. At evaluation time all operands used
must have values assigned.
An expression is built from a combination of
\hyperref[subsec:operator]{operator} and \hyperref[subsec:operand]{operand}, and it
may contain \hyperref[subsubsec:random]{random generators}.
\subsection{Operators in Arithmetic Expressions}
\label{subsec:operator}
An expression can be formed using the following operators:
\subsubsection{Arithmetic operators}
\begin{madlist}
\ttitem{+} Addition,
\ttitem{-} Subtraction,
\ttitem{*} Multiplication,
\ttitem{/} Division,
\ttitem{\^\ } Exponentiation.
\end{madlist}
\subsubsection{Ordinary Functions}
\label{subsubsec:function}
\begin{madlist}
\ttitem{SQRT(x)} square root,
\ttitem{LOG(x)} natural logarithm,
\ttitem{LOG10(x)} logarithm base 10,
\ttitem{EXP(x)} exponential,
\ttitem{SIN(x)} trigonometric sine,
\ttitem{COS(x)} trigonometric cosine,
\ttitem{TAN(x)} trigonometric tangent,
\ttitem{ASIN(x)} arc sine,
\ttitem{ACOS(x)} arc cosine,
\ttitem{ATAN(x)} arc tangent,
\ttitem{SINH(x)} hyperbolic sine,
\ttitem{COSH(x)} hyperbolic cosine,
\ttitem{TANH(x)} hyperbolic tangent,
\ttitem{SINC(x)} cardinal sine function,
\ttitem{ABS(x)} absolute value,
\ttitem{ERF(x)} Gauss error,
\ttitem{ERFC(x)} complementary error,
\ttitem{FLOOR(x)} floor, largest previous integer,
\ttitem{CEIL(x)} ceiling, smallest next integer,
\ttitem{ROUND(x)} round, closest integer;
\ttitem{FRAC(x)} fractional part of number;
\end{madlist}
\subsubsection{Random Number Generators}
\label{subsubsec:random}
\begin{madlist}
\ttitem{RANF()} random number, uniformly distributed in [0,1],
\ttitem{GAUSS()} random number, gaussian distribution with unit
standard deviation,
\ttitem{TGAUSS(x)} random number, gaussian distribution with unit
standard deviation, truncated at x standard deviations;
\end{madlist}
in the above cases, "x" can be any expression, i.e. contain other
functions, variable or constant expressions. To initialize the \madx
random generator use the \hyperref[sec:eoption]{\texttt{EOPTION}} or \hyperref[sec:coption]{\texttt{COPTION}} commands. Note that the command \hyperref[sec:track]{\texttt{TRACK}} with \texttt{QUANTUM} attribute set to true may set or reset the seed too.
The command \hyperref[sec:option]{\texttt{OPTION}} has two attributes to control the new random generator of MAD-X. The attribute \texttt{RAND} can take the value \texttt{default} (for backward compatibility) or \texttt{best} for the new generator. The latter supports 10 multiple independent generators numbered from 1 to 10, and can be selected with the attribute \texttt{RANDID=id} in combination to \texttt{RAND}. If \texttt{RANDID} is not specified and \texttt{RAND=best}, then the last \texttt{id} set is used (init: 1). The user can switch between the 10 independent generators at will to use different streams for the next generated random numbers. When a new seed is set through to command \hyperref[sec:eoption]{\texttt{EOPTION}}, \hyperref[sec:coption]{\texttt{COPTION}} or \hyperref[sec:track]{\texttt{TRACK}}, it will only affect the currently selected stream. The special initial seed for the \texttt{best} generator can be restored by using the value zero instead of the commands default 123456789.
The following example displays the first 10 random numbers of the 10 streams of the \texttt{best} generator, using the default initial seed.
\begin{verbatim}
option, -info;
i = 1;
while (i <= 10) {
option, rand=best, randid=i;
j = 1;
while(j <= 10) {
value, i, j, ranf();
j = j+1;
}
i = i+1;
}
\end{verbatim}
\subsubsection{Table Access Functions}
\label{subsubsec:table}
\begin{madlist}
\ttitem{TABLE(x,z)} identical to TABLE(x,z,1); example: table(summ,q1) returns the hor. tune of
the Twiss summary table "summ".
\ttitem{TABLE(x,y,z)} accesses value of the named table column "z"
for element "y" (first table row with that name) of table "x";
example: table(twiss,mb.12,betx) returns the beta\_x at
element mb.12 from the Twiss table "twiss". When the element
is called with its proper name, as in the example above, the
value is returned at the first occurrence of the element of
this name. If the value is needed at an occurrence number: NNN,
then "[NNN]" has to be appended to the name, e.g. in the above
example one obtains the betx of the 23th occurrence of the
element "mb.12" by changing the example to:
"table(twiss,mb.12[23],betx)". Mind you that the old, but
little known, form: "table(twiss,mb.12-\textgreater 23,betx)"
continues to work. Lastly, if NNN exceeds the maximum
occurrence number the return value is arbitrarily small.
\ttitem{TABLE(x,z,N\_row)} accesses the value of the named table
column "z" at the "N\_row" number of rows of table "x" (row
numbers start at 1); example: table(twiss,betx,370) returns
the beta\_x at row number "370" of the Twiss table
"twiss". The return value is zero if "N\_row" is outside of
the allowed range.
\ttitem{TABINDEX(x,z,key)} identical to TABINDEX(x,z,1,key).
\ttitem{TABINDEX(x,z,N\_row,key)} returns the index of the first occurrence of a string starting by "key" in table column "z" (must be a column of strings) starting at the "N\_row" number of rows of table "x"; example: tabindex(survey,name,102,bpm) returns the row number of the first element found starting from row 102 with a "name" beginning by "bpm" in the table "survey".
\ttitem{TABSTRING(x,z,N\_row)} accesses value of the named table
column "z" (must be a column of strings) at the "N\_row" number of rows of table "x";
example: tabstring(survey,name,10) returns the name of
the 10th element of the survey table "survey". Row count starts at 1. The
function can be used in any context where a string appears; in case
there is no match, it returns "\_void\_".
\end{madlist}
Note that "N\_row" has to be a number and not a variable. However, the
\hyperref[sec:macro]{Macro} facility in \madx allows
the use of a variable instead.
\begin{verbatim}
gettab(tblname, colname, rowidx) : macro = {
gettab.val = table(tblname, colname, rowidx) ;
}
getidx(tblname, colname, rowidx, keyname) : macro = {
getidx.val = tabindex(tblname, colname, rowidx, keyname) ;
}
row = 10 ;
exec, gettab(twiss,betx,$row) ;
exec, getidx(twiss,name,$row,qf) ;
value, gettab.val, getidx.val ;
\end{verbatim}
Beware:
\begin{itemize}
\item Unnamed Drifts are not included in the table name
database, so as to speed up the search for "real"
elements. Therefore, those unnamed drifts cannot be
found. However, named drifts can be searched for.
\item Due to the importance of finding elements in the table
for a proper functioning of the \madx runs, the programs
throws a "fatal\_error" if an element cannot be found in the
table.
\end{itemize}
A typical example could look like this, in fact the square root of betx
(user defined variable myvar) is added to the twiss table:
\begin{verbatim}
myvar := sqrt(table(twiss,betx));
select, flag=twiss, column=name, s, myvar, betx;
twiss, file;
\end{verbatim}
Or another arbitrary test case of adding k1l taken from the Twiss table:
Define macro:
\begin{verbatim}
mymacro(xx,yy,zz): macro = {myval = table(xx,yy,zz);};
\end{verbatim}
Use macro in loop:
\begin{verbatim}
i = 0;
incval = 0;
while (i < 100) {
value, i;
exec, mymacro(twiss,k1l,$i);
incval = incval + myval;
value, i, myval, incval;
i = i + 1;
}
\end{verbatim}
\subsection{Operands in Arithmetic Expressions}
\label{subsec:operand}
An expression may contain the following operands:
\subsubsection{Literal Constants}
Numerical values are entered like FORTRAN constants. Real values are
accepted in INTEGER or REAL format. The use of a decimal exponent,
marked by the letter D or E, is permitted.
Examples:
\madxmp{
1, 10.35, 5E3, 314.1592E-2
}
\subsubsection{Symbolic constants}
\label{subsubsec:symbolic_const}
\madx recognizes some \hyperref[tab-constants]{mathematical and physical
constants}. Their names must not be used for user-defined labels.
Additional symbolic constants may be defined to simplify their repeated
use in statements and expressions.
\madbox{
CONST name=constant-expression;
}
defines a real constant with the name given. An existing symbolic
constant can be redefined, but it cannot change in a matching procedure.
Example:
\madxmp{CONST IN = 0.0254;}
A number of predefined symbolic constants exist in \madx and can be used
in expressions. The values of physical constants are regularly updated
to reflect the values published by the Particle Data Group \cite{PDG2014}
The values published in 2014 (\cite{PDG2014}) have not changed with respect to
the values published in 2012 (\cite{PDG2012}).
\begin{table}[ht]
\caption{Predefined Symbolic Constants in \madx}
\label{tab-constants}
\vspace{1ex}
\centering
\begin{tabular}{|l|c|c|c|}
\hline
\textbf{\madx name} & \textbf{symbol} & \textbf{value} & \textbf{unit} \\
\hline
PI & $\pi$ & 4 * atan(1) & 1 \\
TWOPI & $2\pi$ & 2 * PI & 1 \\
DEGRAD & $180/\pi$ & 180 / PI & deg/rad \\
RADDEG & $\pi/180$ & PI / 180 & rad/deg \\
E & e & exp(1) & 1 \\
EMASS & $m_e$ & $0.510998928\times 10^{-3}$& GeV \\
PMASS & $m_p$ & 0.938272046 & GeV \\
NMASS & $u$ & 0.931494061 & GeV \\
MUMASS & $m_\mu$ & 0.1056583715 & GeV \\
CLIGHT & $c$ & $2.99792458\times 10^{8}$ & m/s \\
QELECT & $e$ & $1.602176565\times 10^{-19}$ & A.s \\
HBAR & $\hbar$ & $6.58211928\times 10^{-25}$ & MeV.s\\
ERAD & $r_e$ & $2.8179403267\times 10^{-15}$ & m\\
PRAD & $r_e (m_e / m_p)$ & ERAD*EMASS/PMASS & m \\
\hline
\end{tabular}
\end{table}
Note that the \texttt{NMASS} constant in \madx is the unified atomic mass unit and
not the neutron mass.
\subsubsection{Parameter labels}
Often a set of numerical values depends on a common variable
parameter. Such a parameter must be defined as a global parameter. A
global parameter always has a current value; however, this value may be
re-evaluated or not, depending on the parameter definition:
\begin{verbatim}
x = a;
\end{verbatim}
\texttt{x} is set to the current value of \texttt{a} and not changed,
even if \texttt{a} changes. This makes assignments such as
\begin{verbatim}
x = x + 1;
\end{verbatim}
perfectly valid (this replaces the deprecated \texttt{SET} instruction).
The definition of the deferred expression
\begin{verbatim}
x := a;
\end{verbatim}
assign the current value of \texttt{a} to \texttt{x} every time
\texttt{x} is used, \textsl{i.e.} it is re-evaluated using the latest
value of \texttt{a}; therefore,
\begin{verbatim}
x := x + 1;
\end{verbatim}
results in an infinite loop (!) when \texttt{x} is used, which results
in abnormnal termination of \madx.
Of course, the following definitions are equivalent:
\begin{verbatim}
x = 0.1;
x := 0.1;
\end{verbatim}
When such a parameter is used in an expression, \madx uses the current
value of the parameter if the expression is deferred:
Example:
\madxmp{
x := 1.0; \\
d1: drift, l = x; \\
d2: drift, l := 2.0 - x; \\
}
When the value of \texttt{x} is changed, the length of the drift
\texttt{d1} remains unchanged, while the length of the drift \texttt{d2}
is recalculated.
\subsubsection{Element or Command Attributes}
In arithmetic expressions the attributes of physical elements or
commands can occur as operands. They are named respectively by
\madbox{
element-name->attribute-name\\
command-name->attribute-name
}
Values are assigned to attributes in element definitions or commands.
Example:
\madxmp{
xxxxxxxx\= \kill
D1: \>DRIFT, L= 1.0; \\
D2: \>DRIFT, L= 2.0 - D1->L;
}
\texttt{D1-\textgreater L} refers to the length \texttt{L} of the drift
space \texttt{D1}.
\subsection{Expressions and Random Values}
\label{subsec:expr_rnd}
The definition of random machine imperfections requires evaluation of
expressions containing random functions. These are evaluated like any
other expression when the expression is used, i.e. only once if a "="
assignment refers to it, or every time if the assignment is ":="; this
latter case is used by the error generation routines.
Example:
\madxmp{
a := 3*ranf();
}
Every time \texttt{a} is used, it gets a random value assigned from a uniform
distribution between 0 and 3.
\madxmp{
error: ealign, range, dx:=sigma*gauss();
}
All elements in range are assigned independent random displacements
sampled from a Gaussian distribution with standard deviation sigma.
%\input{Introduction/constraint}
%\section{Constraints}
%\label{sec:constraints}
\section{Logical Expressions}
\label{sec:logicalexpr}
In matching it is desired to specify equality constraints, as well as
lower and upper limits for a quantity. \madx accepts the following forms
of constraints:
%% \begin{verbatim}
%% ! equality constraint:
%% name = expression
%% ! upper limit:
%% name < expression
%% ! lower limit:
%% name > expression
%% ! both upper and lower limit for the same name:
%% name < expression, name > expression
%% \end{verbatim}
\madbox{
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\= \kill
name = expression \>! equality constraint \\
name < expression \>! upper limit \\
name > expression \>! lower limit \\
name < expression, name > expression \>! both upper and lower limit \\
\>! for the same name
}
%\input{Introduction/variable}
\section{Variable Names}
\label{sec:variable}
A variable name can have one of the formats:
\madbox{
parameter-name \\
element-name->attribute-name \\
command-name->attribute-name \\
beam\%sequence-name->attribute-name \\
table(table-name,..,..)
}
The first format refers to the value of the global parameter
\texttt{parameter-name}.
The second and third formats refer to the real attribute
\texttt{attribute-name} of the element \texttt{element-name}, or the
command \texttt{command-name}.
The fourth format is specific
to beams belonging to a particular sequence (for details see
\hyperref[chap:sequence]{sequences} and \hyperref[chap:beam]{beams}).
The fifth format allows extraction of variables from existing tables, as specified in
\hyperref[chap:tables]{table access}.
%\input{Introduction/wildcard}
\section{Regular Expressions}
\label{sec:regex}
Some commands allow selection of items via "regular expression"
strings. Such a pattern string \textbf{must} be enclosed in single or
double quotes. \madx follows regexp (Unix regular expression patterns)
for matching. The following features are implemented:
A "search string" below is the string containing the pattern, a "target
string" is the string being searched for a possible match with the
pattern.
\begin{madlist}
\ttitem{"\textasciicircum"} at the start of the search string: Match
following search string at the start of the target string;
otherwise the search string can start anywhere in the target
string. To search for a genuine "\textasciicircum" anywhere, use
"$\backslash$\textasciicircum".
\ttitem{"\$"} at the end of the search string: Match preceding search
string at the end of the target string; otherwise the search string
can end anywhere in the target string. To search for a genuine
"\$" anywhere, use "$\backslash$\$".
\ttitem{"."} stands for an arbitrary character; to search for a genuine
".", use "$\backslash$."
\ttitem{"[xyz]"} stands for one character belonging to the string
contained in brackets (example: "[abc]" means one of a, b, c).
\ttitem{"[a-ex-z]"} stands for ranges of characters (example:
"[a-zA-Z]" means any letter).
\ttitem{"[\textasciicircum xyz]"} (i.e. a "\textasciicircum" as first
character in a square bracket) stands for exclusion of all
characters in the list, i.e. "[\textasciicircum a-z]" means "any
character but a lower case letter".
\ttitem{"*"} allows zero or more repetitions of the preceding
character, either specified directly, or from a list. (examples:
"a*" means zero or more occurrences of "a", "[A-Z]*" means zero or
more upper-case letters).
\ttitem{"$\backslash$c"} (e.g. "$\backslash$.") removes the special
meaning of character c.
\end{madlist}
All other characters stand for themselves.
Example:
\madxmp{
SELECT, FLAG=twiss, PATTERN="\textasciicircum d..\$" ; \\
SELECT, FLAG=twiss, PATTERN="\textasciicircum k.*qd.*$\backslash$.r1\$" ;
}
The first command selects all elements whose names have exactly three
characters and begin with the letter "D". The second command selects
elements beginning with the letter "K", containing the string "QD", and
ending with the string ".R1". The two occurrences of ".*" each stand for
an arbitrary number (including zero) of any character, and the
occurrence "$\backslash$." stands for a literal period.
%%\title{Parameters}
% Changed by: Hans Grote, 17-Jun-2002
%\chapter{Parameter Statements}
%\label{chap:parameter}
\section{Relations between Variable Parameters}
\label{sec:relations}\label{sec:defer}
A relation is established between variables by one of two statements
\madbox{
xxxxxxxxxxxxxxxx\= \kill
parameter-name \>= expression; \\
parameter-name :\>= expression;
}
The first form evaluates the expression on the right immediately and
assigns its value to the parameter. It is an immediate assignment.
The second form assigns the value by evaluating the expression on the
right every time the parameter is actually used. It is a deferred
assignment.
This mechanism holds as well for element parameters that can be defined
with either immediate or deferred assignments.
Attention! If you want
to modify e.g. the strength of a quadrupole later (e.g. in a match, or
by entering a new value for a parameter on which it depends) then the
defition has to be
\madxmp{QD: QUADRUPOLE, K1 := ak1;}
and not
\madxmp{QD: QUADRUPOLE, K1 = ak1;}
In the latter case, K1 will be set to the current value of ak1 at the
time of declaration, and will not change when ak1 later changes.
Parameters that have not yet been defined at time of evaluation have a
zero value.
Example:
\madxmp{
gev = 100; \\
BEAM, ENERGY=gev;
}
The parameter on the left may appear on the right as well in the
computer science form of assignments:
\madxmp{x = x+1;}
increases the value of x by 1. \\
%As a result, the SET statement of \madeight is no longer necessary and
%is not implemented in \madx.
Successive definitions are allowed in the first form of relations or
immediate assignments:
\madxmp{
a = b + 2; \\
b = a * b;
}
But circular definitions in the second form of relations, or
deferred assignments, are forbidden:
\madxmp{
a := b + 2; \\
b := a * b;
}
results in an error.
%\href{http://www.cern.ch/Hans.Grote/hansg_sign.html}{hansg} 11.9.2000
%% EOF