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


.exec, .control, .postrun, and .endc Lines

General Form:
.exec [blockname]
shell commands ...
.endc

.control [blockname]
shell commands ...
.endc

.postrun [blockname]
shell commands ...
.endc

Example:
.exec
set vmin = 2.5
.endc

.control
let maxv = v(2)*v(19)
.endc

The shell commands are any commands which can be interpreted by the WRspice shell.

If a blockname is given, the script lines are parsed, and the executable object saved as a codeblock under blockname. The block can be executed by invoking the blockname from the command line or in a script or codeblock.

In this usage, there is no difference between the .exec, .control, and .postrun keywords, and there is no connection of the block to any other content in tne same file. One file can be used to load any number of named codeblocks. Blocks with an existing name will replace the existing content.

If the block is unnamed, 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, assuming that the file also contains a circuit description. If not, there is again no real distinction, but unlike for named blocks, unnamed blocks will be executed when read.

Commands in a .postrun block are executed after every simulation that completes normally (i.e., without errors or interrupts). This can be used to dump circuit data to a file, for example, without having to explicitly give commands or write a script.

When the circuit is parsed, shell variable substitution (see 3.15.9) 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 prevents substitution and is usually taken as a comment start. 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 plot structure is created to hold any vectors defined in the .exec block while the circuit is parsed. 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. Similar to variables, vectors can be used to pass values to the curcuit, through use of the substitution form ``$&vecname''.

In releases 4.2.4 and earlier, this plot was temporary, and was destroyed once the circuit lines were processed. In present releases, this plot is retained, if it contains any vectors.


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