next up previous contents index
Next: .check, .checkall, .monte, and Up: Control Script Execution Previous: Control Script Execution   Contents   Index


.exec, .control, and .endc Lines

WRspice includes a script parsing and execution facility, which uses a syntax similar to that of the UNIX C-shell and will be described in 3.12. Statements which are interpreted and executed by this facility can be included in circuit files through use of the .exec and .control tokens. These statements are enclosed in a block beginning with .exec or .control and ending with .endc. The .exec, .control, and .endc lines contain only the keyword.
General Form:
.exec
shell_command
...
.endc
Example:
.exec
set vmin = 2.5
.endc
General Form:
.control
shell_command
...
.endc
Example:
.control
let maxv = v(2)*v(19)
print maxv
.endc
The shell_commands are any commands which can be interpreted by the WRspice shell. The difference between .exec and .control is that for .exec, the commands are executed before the circuit is parsed, and for .control, the commands are executed after the circuit is parsed.

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 $rvalue
r32 12 35 $rvalue
etc. and elsewhere in the file one would have
.exec
set rvalue = 50
.endc
The 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.

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=50
and, as the .options lines are expanded after the .exec lines are executed, one could have the following contrived example:
.exec
set rtmp=50
.endc
.options rvalue = $rtmp
The 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.

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 = 50
Obviously, 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.


next up previous contents index
Next: .check, .checkall, .monte, and Up: Control Script Execution Previous: Control Script Execution   Contents   Index
Stephen R. Whiteley 2006-10-23