next up previous contents
Next: Macro 'InnerPlunger' Up: Modelling a Plunger Previous: Modelling a Plunger   Contents

Using macros to model two plungers

Since we have to model two plungers, we could edit our inputfile to contain the description of the other plunger as well. But this is a good opportunity to use a macro.

Anywhere in an inputfile we can define macros. A macro is enclosed between two lines: The first line contains the keyword macro followed by the name of the macro. All lines until a line with only the keyword endmacro are considered the body of the macro. When gd1 or gd1.pp find such a macro, they read it and store the body of the macro in an internal buffer.
Example

   #
   # This defines a macro with name 'foo'
   #
   macro foo
      echo I am foo, my first argument is @arg1
      echo The total number of arguments supplied is @nargs
   endmacro
When gd1 or gd1.pp find a call of the macro, the number of the supplied arguments is assigned to the variable @nargs, and the variables @arg1, @arg2, .. are assigned the values of the supplied parameters of the call. The values of the arguments are strings. Of course it is possible to have a string eg. '1e-4' which happens to be interpreted in the right context as a real number.
Example
   #
   # this calls 'foo' with the arguments 'hi', 'there'
   #
   call foo(hi, there)
Macro calls may be nested. The body of a macro may call another macro.

Subsections
next up previous contents
Next: Macro 'InnerPlunger' Up: Modelling a Plunger Previous: Modelling a Plunger   Contents