Numbers in macro variables


The macro variables are character strings. They don't require any declaration and are created the first time they are filled. Example:

     A = Hello
 
creates the variable A which contains the character string Hello.

To access the content of a variable, the operator [] should be used. For example in a macro the command:

     MESSAGE [A]
 
gives the output:
     Hello
 

Variables can be concatenate in the following way:

     A = Hello
     B = world
     C = [A] [B]
     MESSAGE [C]
     C = [A]+[B]
     MESSAGE [C]
 
This macro gives the output:
     Hello world
     Hello+world
 

If the expression on the right side can be evaluated as an arithmetic expression PAW does it. Example:

     A = 1
     B = 2
     C = [A] [B]
     MESSAGE [C]
     C = [A]+[B]
     MESSAGE [C]
 
gives the output:
     1 2
     3
 
Note that the evaluation of an expression can be forced using the system function $EVAL. In some cases this ensure that the variable really contains a number. The following case show a such example where using $EVAL is safer than the automatic evaluation.
     V/CREATE V2(2) R 10 20
     L = 2
     A = $EVAL(V[L](1))
     MESSAGE [A]
 
gives the output:
      10
 

Variables can be used in commands parameters. Example:

     A = 1
     FUN/PLOT X+[A] 0 1
 
plots the function X+1.

But be careful that A may contains any character string and you may get any expression. For example the following commands

     A = -1
     FUN/PLOT X+[A] 0 1
 
are equivalent to execute the command:
     FUN/PLOT X+-1 0 1
 
which is not valid for the FORTRAN like expression evaluator of FUN/PLOT and PAW will give an error like:
  CS-TR-ERR: routine _002, line    0
  FUNCTION _002(X,Y,Z) _002=X+ ^ -1#
   syntax error
 
A way to bypass this is to do:
     A = -1
     FUN/PLOT X+([A]) 1 0 1
 
which is equivalent to:
     FUN/PLOT X+(-1) 0 1
 


Release NotesKnown bugsFAQsContributionsTutorialReference manualDown loadMiscellaneous

Paw.Support@cern.ch