When the circuit is parsed, variable substitution is performed. Shell variable references begin with ``$'', and are replaced with the text to which the shell variable has been set, unless the character before the `$' is a backslash ( \), which indicates a comment. The variable can be set from the shell with the set command, and a variable is also set if it is given in a .options line. Any text in a circuit description can reference a shell variable, and this offers a powerful capability for manipulating the circuit under the control of the shell. As the variables must be set before the circuit is parsed, the set commands which perform this action can be included in the .exec block of the circuit file itself, or in the .options line. For example, suppose one has a circuit with a large number of resistors, each the same value, but it is desired to run the circuit for several different values. The resistor lines could be specified as
r31 11 36 $rvalueetc. and elsewhere in the file one would have
r32 12 35 $rvalue
.execThe 50 can be changed to any value, avoiding the need to change the many resistor lines between simulation runs. Note that the .exec block must be used, if .control was used instead, the variables would not be set until after the circuit is read, which means that they will not be properly defined when the expansion is performed. The .control block is useful for initiating analysis and post-processing.
set rvalue = 50
.endc
Note that there is an alternative method of parameterization using the .param line.
The same effect could have been obtained from the use of the .options line as
.options rvalue=50and, as the .options lines are expanded after the .exec lines are executed, one could have the following contrived example:
.execThe shell variables set in .exec and control blocks remain set until explicitly unset, however variables set in .options lines are active only when the circuit is the current circuit, and cannot be unset (with the unset command) from the shell. A variable set in the .options line will be superseded by the same variable set from the shell, .exec or .control lines.
set rtmp=50
.endc
.options rvalue = $rtmp
Commands can also be included using a different mechanism, which might be useful if the circuit file is to be used with other simulators. This mechanism uses comment lines to include shell commands. If a comment begins with the characters ``*@'', the remainder of the line is taken as a shell command just as if it had been enclosed in .exec and .endc. If a comment line begins with the characters ``*#'', the remainder of the line is treated as if it had been enclosed in .control and .endc. Thus, in the example above, the .exec block could be replaced with the line
*@ set rvalue = 50Obviously, this facility allows the possibility that a real comment can be misconstrued as a shell command. The user is suggested to leave space after the ``*'' in intended comments, as a general rule.
If a circuit contains an .exec block, a temporary plot structure is created to hold any vectors defined in the .exec block while the circuit is parsed, after which the plot is deleted. Thus, if the circuit references vectors defined in the .exec block, the reference will be satisfied, and the variables will have initial values as defined in the .exec block.