Command files are files containing circuit descriptions and/or shell commands. The first line of a command file is ignored, so must be blank or a comment. This is a result of the source command being used for both circuit input and command file execution.
A pure script file, i.e., one which does not include a circuit description, consists of an unread ``title'' line, followed by a control block. The control block begins with a ``.control'' line, continues with one or more executable statements, and terminates with a ``.endc'' line. In WRspice, an ``.exec'' line can be used rather than the .control line, though for backward compatibility with SPICE3, it is recommended that the traditional .control be used. The executable statements are any statements understandable to the WRspice shell. Typically, such statements appear just as they would be entered on the command line if given as text input. Scripts can call other scripts to any depth.
Before a script is read, the variables argc and argv are set to the number of words on the command line, and a list of those words respectively. Their previous values (if any) are pushed onto a stack, and popped back in place when the script terminates. Thus, within a command script, these predefined variables are available for use in the script. Otherwise, command files may not be reentrant since there are no local variables, however, the procedures may explicitly manipulate a stack.
There may be various command scripts installed in the default scripts directory, and the default sourcepath includes this directory, so one can use these command files (almost) like built-in commands. In addition to scripts, there is an executable data structure called a ``codeblock''. Codeblocks are derived from scripts, but store the command text internally, so are somewhat more efficient. A codeblock has the same name (in general) as the script file from which it was derived. See the description of the codeblock command (in 4.4.1) for more information.
When a line of input is given to WRspice, the first word on the line determines how the line is processed. The following logic is used to make this determination.
If the variable unixcom is set and the operating system is supportive, commands which are not built-ins are considered shell commands and executed as if the program were a shell. However, using this option increases the start-up time of the program. Probably WRspice should not be used as a login shell.
WRspice can be used as the ``shell'' in UNIX shell scripts. In these scripts, the wrspice executable should be called, using the convention applicable to the user's UNIX shell. This generally requires that the first line of the script begin with the characters ``#!'' and be followed by a space-separated program invocation string. The remainder of the file should consist of standard WRspice command file lines, the first line of which (second line of the file) will be ignored.
For example, below is a script that can be saved in a file, which should be made executable (using the UNIX command ``chmod +x filename''). From the UNIX shell, typing the name of the file will run WRspice on the example file mosamp2.cir and display the plot.
#! wrspice -J
#
.exec
source /usr/local/lib/xictools/wrspice/examples/mosamp2.cir
run
plot v(20) v(66)
set noaskquit
pause
quit
.endc
Typing the name of the file is the same as executing ``wrspice -J file''. WRspice ignores the #!... line, so that the next line is the ``title'' line and is also ignored. The -J (JSPICE3 compatibility) means to not bring up the Tool Control window.