[430] | 1 | <head> |
---|
| 2 | <title>Parameters</title> |
---|
| 3 | <!-- Changed by: Hans Grote, 17-Jun-2002 --> |
---|
| 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>Parameter Statements</h2> |
---|
| 12 | </center> |
---|
| 13 | |
---|
| 14 | <h2><a name=relation>Relations between Variable Parameters</a></h2> |
---|
| 15 | A relation is established between variables by the statement |
---|
| 16 | <pre> |
---|
| 17 | parameter-name = expression; |
---|
| 18 | </pre> |
---|
| 19 | or |
---|
| 20 | <pre> |
---|
| 21 | parameter-name := expression; |
---|
| 22 | </pre> |
---|
| 23 | The first form evaluates the expression at the right immediately |
---|
| 24 | and assigns its value to the parameter. The second form assigns the value |
---|
| 25 | by evaluating the expression at right every time the parameter is |
---|
| 26 | actually used. |
---|
| 27 | This holds as well for element parameters - beware ! If you want to modify |
---|
| 28 | e.g. the strength of a quadrupole later (e.g. in a match, |
---|
| 29 | or by entering a new value for a parameter on which it depends) |
---|
| 30 | then the defition has to be |
---|
| 31 | <pre> |
---|
| 32 | qd:quadrupole,k1:= ak1; |
---|
| 33 | </pre> |
---|
| 34 | and not |
---|
| 35 | <pre> |
---|
| 36 | qd:quadrupole,k1 = ak1; |
---|
| 37 | </pre> |
---|
| 38 | In the latter case, k1 will be set to the current value of ak1, and will |
---|
| 39 | not change when ak1 changes. |
---|
| 40 | <p> |
---|
| 41 | Parameters not yet defined have the value zero. |
---|
| 42 | <p> |
---|
| 43 | Example: |
---|
| 44 | <pre> |
---|
| 45 | gev = 100; |
---|
| 46 | beam,energy=gev; |
---|
| 47 | </pre> |
---|
| 48 | the parameter on the left may appear on the right as well: |
---|
| 49 | <pre> |
---|
| 50 | x = x+1; |
---|
| 51 | </pre> |
---|
| 52 | Increases the value of x by 1. As a result, the SET statement of MAD-8 |
---|
| 53 | is no longer necessary and is not implemented. |
---|
| 54 | <pre> |
---|
| 55 | Circular definitions are allowed in the first form: |
---|
| 56 | <pre> |
---|
| 57 | a = b + 2; |
---|
| 58 | b = a * b; |
---|
| 59 | </pre> |
---|
| 60 | However, circular definitions in the second form are forbidden: |
---|
| 61 | <pre> |
---|
| 62 | a := b + 2; |
---|
| 63 | b := a * b; |
---|
| 64 | </pre> |
---|
| 65 | will result in an error. |
---|
| 66 | <h2><a name=par_output>VALUE: Output of Parameters</a></h2> |
---|
| 67 | The VALUE statement |
---|
| 68 | <pre>VALUE = expression;</pre> |
---|
| 69 | or |
---|
| 70 | <pre>VALUE = expression1, expression2, ...;</pre> |
---|
| 71 | evaluates the current value of "expression" resp. "expression1" etc. and |
---|
| 72 | prints the result on the standard output file. |
---|
| 73 | <p> |
---|
| 74 | Example: |
---|
| 75 | <pre> |
---|
| 76 | p1 = 5; |
---|
| 77 | p2 = 7; |
---|
| 78 | value,p1*p2-3; |
---|
| 79 | </pre> |
---|
| 80 | After echoing the command, this prints: |
---|
| 81 | <pre> |
---|
| 82 | p1*p2-3 = 32 ; |
---|
| 83 | </pre> |
---|
| 84 | Another example: |
---|
| 85 | <pre> |
---|
| 86 | option,-warn; |
---|
| 87 | while (x < 100) {x = x + 1;} |
---|
| 88 | value,x,x^2,log10(x); |
---|
| 89 | </pre> |
---|
| 90 | After echoing the command, this prints: |
---|
| 91 | <pre> |
---|
| 92 | x = 100 ; |
---|
| 93 | x^2 = 10000 ; |
---|
| 94 | log10(x) = 2 ; |
---|
| 95 | </pre> |
---|
| 96 | <p> |
---|
| 97 | <address> |
---|
| 98 | <a href="http://www.cern.ch/Hans.Grote/hansg_sign.html">hansg</a> |
---|
| 99 | 11.9.2000 |
---|
| 100 | </address> |
---|
| 101 | |
---|
| 102 | </body> |
---|