next up previous contents
Next: 6.9 Working with files Up: 6. FORTRAN style interpreter Previous: 6.7 Filenames

   
6.8 Macros

Any list of valid KUPLOT commands can be written to an ASCII file and executed indirectly by the command '@<filename>'. The commands must start in the left most column of the file and are otherwise executed as typed. Macro files can be written by any editor on your system or be generated by the 'learn' command. 'learn' starts to remember all the commands that follow and saves them into the file given on the 'learn' command. The learn sequence is terminated by the 'lend' command. The default extension of the macro file is '.mac'. Macro files can be nested and even reference themselves directly or indirectly. This referencing of macro files is, however, just a nesting of the corresponding text of each macro, not a call to a function. All variable retain their values. If an error occurs while executing a macro, KUPLOT immediately stops execution of all macros and returns to the interactive prompt. If the macro switched to a sublevel, and the error occurred inside of this sublevel, KUPLOT will remain within this sublevel the interactive prompt corresponding to this sublevel is returned.

On the command line of the macro command '@', optional parameters can be supplied. Within the macro these have to be referenced as '$1', '$2' etc. Upon execution of the macro the formal parameters '$n' are replaced by the character string of the actual values from the command line. As any other command parameters, these parameters must be separated by comma. If a formal parameter is referenced inside a macro without a corresponding parameter on the command line, an error message is given. An example is given below:

     # Adds two numbers supplied as command line parameters.
     # The value is stored in variable defined by parameter three
     #
     $3 = $1 + $2

If this macro is called with the following line, @add 1,2,i[4], the result is stored in variable i[4] which now has the integer value 3.


next up previous contents
Next: 6.9 Working with files Up: 6. FORTRAN style interpreter Previous: 6.7 Filenames
Thomas Proffen {Billinge}
1999-06-26