An expression is built from a combination of operator and operand, and it may contain random generators.
Beware:
There is a second option of this function with 3 entries
Note that "N_row" has to be a number and not a variable. However, the Macro facility in MAD-X allows one to use a variable instead.
A typical example could look like this, in fact the square root of betx (user defined variable myvar) is added to the twiss table:
myvar := sqrt(table(twiss,betx));
select,flag=twiss,column=name,s,myvar,betx;
twiss,file;
Or another arbitrary test case of adding k1l taken from the Twiss table:
Define macro:
mycrap(xx,yy,zz): macro = {myval = table(xx,yy,zz);};
Use macro in loop:
i = 0;
incval = 0;
while (i < 100) {
value,i;
exec,mycrap(twiss,k1l,$i);
incval = incval + myval;
value,i,myval,incval;
i = i + 1;
}
FILL,TABLE=t,ROW=n;
fill a table row with the present variable values. If ROW is negative or missing a new row is created. If ROW is greater than the number of rows, the last row is selected without creating a new row.
set variables according to the column names of the given table and the values of the given row. if ROW is negative, missing or greater than the number of rows, the last row is selected.
Examples:
1, 10.35, 5E3, 314.1592E-2
Additional symbolic constants may be defined to simplify their repeated use in statements and expressions.
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:
const in = 0.0254;
mad name | symbol | value used | unit |
pi | pi | 4 * atan(1) | 1 |
twopi | 2 pi | 2 * pi | 1 |
degrad | 180/pi | 180 / pi | deg/rad |
raddeg | pi/180 | 180 / pi | rad/deg |
e | e | exp(1) | 1 |
emass | m_e | .510998902*10(-3) | GeV |
pmass | m_p | .938271998 | GeV |
mumass | m_mu | .1056583568 | GeV |
clight | c | 2.99792458*10**8 | m/s |
qelect | elem. charge | 1.602176462e-19 | As |
x = a;x is set to the current value of a and not changed, even if a changes. This makes assignments such as
x = x + 1;perfectly valid (this replaces the old SET instruction). The definition of the deferred expression
x := a;assign the current value of a to x every time x is used, i.e. it is re-evaluated using the latest value of a; therefore,
x := x + 1;results in an infinite loop (!) when x is used (error abort). Of course, the following definitions are equivalent:
x = 0.1; x := 0.1;
When such a parameter is used in an expression, MAD uses the current value of the parameter if the expression is deferred:
Example:
x:=1.0; d1: drift,l = x; d2: drift,l := 2.0 - x;When the value of X is changed, the length of the drift d1 remains unchanged, that of d2 is recalculated.
element-name->attribute-name command-name->attribute-nameValues are assigned to attributes in element definitions or commands.
Example:
D1: DRIFT,L=1.0; D2: DRIFT,L=2.0-D1->L;D1->L refers to the length L of the drift space D1.
Example:
a := 3*ranf();Every time a is used, it gets a random value assigned from a uniform distribution between 0 and 3.
error: ealign,range,dx:=sigma*gauss();All elements in range are assigned independent random displacements sampled from a Gaussian distribution with standard deviation sigma.
hansg, May 8, 2001