Next: Program Flow Control
Up: The MAD Program
Previous: Multipoles
Subsections
The format for variables (parameters) and constants has been unified,
and a data types have been introduced:
REAL P=<logical expression>; // a logical variable
BOOL B=<real expression>; // a real variable
REAL CONST C=<constant expression>; // a real constant
REAL VECTOR V=<vector expression>; // a real vector
STRING S=<string expression>; // a string constant
The word REAL is optional.
For backward compatibility, a variable parameter can still be entered with
P:=<expression>
A variable or vector also can be redefined by the above syntax.
To assigne a constant value to one of them, use
P=<expression>;
V=<vector-expression>;
Logical Expressions
A logical expression has the same format as a logical expression in C.
It is built from operators and operands.
Operands may include functions:
<relation> ::=
true | false |
<real expression> <relational operator> <real expression>
<relational operator> ::= "==" | "!=" |
"<" | ">" | ">=" | "<="
<and expression> ::= <relation> |
<and expression> "&&" <relation>
<logical expression> ::= <and expression> |
<logical> "||" <and expression>
Real Expressions
A real expression is built from operators operators and
operands. Operands may include
functions:
<primary> ::= <literal constant> |
<symbolic constant> |
<real variable> |
<real vector>"["<index>"]" |
<function name>"("<arguments>")" |
(<real expression>)
<factor> ::= <primary> |
<factor> "^" <primary>
<term> ::= <factor> |
<term> "*" <factor> |
<term> "/" <factor>
<real expression> ::= <term> |
"+" <term> |
"-" <term> |
<real expression> "+" <term> |
<real expression> "-" <term> |
Vector Expressions
A <vector-expression> can have one of the following formats:
<real expression>
{<real expression>, <real expression>, ... , <real expression>}
TABLE(<max>, <real expression>)
TABLE(<min>:<max>, <real expression>)
TABLE(<min>:<max>:<step>, <real expression>)
It can be entered as a single scalar value,
giving a vector of length one,
as a table of scalar values with an unlimited number of values,
or as a TABLE generator/
In the TABLE generator the <count> specifies how
many components are wanted,
and the <real expression> may contain the special value
#.
It allws to generate arbitrary tables.
The generator fills the vector with zeros from 1 ... <max>
,
and the generates the expressions for all values <min> ... <max>
with steps <step>
.
Thus
TABLE(4, #*A+B)
generates the vector
{1*A+B, 2*A+B, 3*A+B, 4*A+B},
and
TABLE(1,9,4, V[#+1])
returns the components 2, 6, 10
of the vector V and
stores them in components 1, 5, 9
.
A vector component is referred to by the syntax
<vector>[<index>]
where the index must have a positive non-zero value not
exceeding the length of the vector.
This may be combined with the attribute notation like
MULTIPOLE->KNORMAL[1]
which denotes the normal quadrupole component of multipole.
String Expressions
All string values, including object names,
but not attribute keywords,
can be written using string concatenation:
<simple string> :: " <litteral> " | <label> |
STRING(<numeric expression>)
<string expression> ::= <simple string> |
<string expression> "&" <simple string>
The '&' is the concatenation operator.
QF & STRING(I): QUADRUPOLE, L=1.6, K1=KF & STRING(I);
An operand of the form
STRING(<numeric expression>)
generates a string representation of the <numeric expression>.
All arithmetic is done in floating-point.
When an integer is required, the last operation consists in rounding
to the nearest integer.
A different behaviour can be requested by use of one of the functions
ROUND(X), TRUNC(X), FLOOR(X), CEIL(X)
All available operators are listed in operators,
all available functions are listed in functions,
The complete list of available operators in expressions is now:
Table 1:
Operators available in MAD-9 Expressions
Operator |
Meaning |
result type |
operand type |
Operators with one operand |
+ X |
unary plus, returns X |
real |
real |
- X |
unary minus, returns the negative of X |
real |
real |
Operators with two operands |
X + Y |
add X to Y |
real |
real,real |
X - Y |
subtract Y from X |
real |
real,real |
X * Y |
multiply X by Y |
real |
real,real |
X / Y |
divide X by Y |
real |
real,real |
X ^ Y |
power, return X raised to the power Y > 0 |
real |
real,real |
X & Y |
concatenate the strings X and Y |
string |
string,string |
X < Y |
true, if X is less than Y |
logical |
real,real |
X <= Y |
true, if X is not greater than Y |
logical |
real,real |
X > Y |
true, if X is greater than Y |
logical |
real,real |
X >= Y |
true, if X is not less than Y |
logical |
real,real |
X == Y |
true, if X is equal to Y |
logical |
real,real |
X != Y |
true, if X is not equal to Y |
logical |
real,real |
X && Y |
true, if both X and Y are true |
logical |
logical,logical |
X || Y |
true, if at least one of X and Y is true |
logical |
logical,logical |
|
Table 2:
Functions Available in MAD-9 Expressions
Function |
Meaning |
result type |
operand type |
Functions with no arguments |
RANF() |
random number, uniform distribution in [0,1) |
real |
|
GAUSS() |
random number, Gaussian distribution with =1 |
real |
|
USER0() |
random number, user-defined distribution |
real |
|
SI() |
arc length from start of ring to the entry of the current element |
real |
|
SC() |
arc length from start of ring to the centre of the current element |
real |
|
SO() |
arc length from start of ring to the exit of current the element |
real |
|
Functions with one argument |
TRUNC(X) |
truncate X towards zero (discard fractional part) |
real |
real |
ROUND(X) |
round X to nearest integer |
real |
real |
FLOOR(X) |
return largest integer not greater than X |
real |
real |
CEIL(X) |
return smallest integer not less than X |
real |
real |
SIGN(X) |
return sign of X
(+1 for X positive, -1 for X negative,
0 for X zero) |
real |
real |
SQRT(X) |
return square root of X |
real |
real |
LOG(X) |
return natural logartithm of X |
real |
real |
EXP(X) |
return exponential to the base of X |
real |
real |
SIN(X) |
return trigonometric sine of X |
real |
real |
COS(X) |
return trigonometric cosine of X |
real |
real |
ABS(X) |
return absolute value of X |
real |
real |
TAN(X) |
return trigonometric tangent of X |
real |
real |
ASIN(X) |
return inverse trigonometric sine of X |
real |
real |
ACOS(X) |
return inverse trigonometric cosine of X |
real |
real |
ATAN(X) |
return inverse trigonometric tangent of X |
real |
real |
TGAUSS(X) |
random number, Gaussian distribution with =1,
truncated at X |
real |
real |
USER1(X) |
random number, user-defined distribution with one parameter |
real |
real |
STRING(X) |
return string representation of the value<br>
of the numeric expression X |
string |
real |
Functions with two arguments |
ATAN2(X,Y) |
return inverse trigonometric tangent of Y/X |
real |
real,real |
MAX(X,Y) |
return the larger of X, Y |
real |
real,real |
MIN(X,Y) |
return the smaller of X, Y |
real |
real,real |
MOD(X,Y) |
return the largest value less than Y
which differs from X by a multiple of Y |
real |
real,real |
USER2(X,Y) |
random number, user-defined distribution with two parameters |
real |
real,real |
|
Next: Program Flow Control
Up: The MAD Program
Previous: Multipoles
chris.iselin@cern.ch