Physics and Astronomy
Home Our Teaching Resources CDHW Electronics2 Userguide sec5.html

# SPICE 3 User's Manual - Section 5

## 5 INTERACTIVE INTERPRETER

Spice3 consists of a simulator and a front-end for data analysis and plotting. The front-end may be run as a separate "stand-alone" program under the name Nutmeg.

Nutmeg will read in the "raw" data output file created by Spice -r or with the write command in an interactive Spice3 session. Nutmeg or interactive Spice3 can plot data from a simulation on a graphics terminal or a workstation display. Most of the commands available in the interactive Spice3 front end are available in nutmeg; where this is not the case, Spice-only commands have been marked with an asterisk ("*"). Note that the raw output file is different from the data that Spice2 writes to the standard output, which may also be produced by Spice3 with the "-b" command line option.

Spice and Nutmeg use the X Window System for plotting if they find the environment variable DISPLAY. Otherwise, a graphics-terminal independent interface (MFB) is used. If you are using X on a workstation, the DISPLAY variable should already be set; if you want to display graphics on a system different from the one you are running Spice3 or Nutmeg on, DISPLAY should be of the form "machine:0.0". See the appropriate documentation on the X Window System for more details.

Command Synopsis


Spice [ -n ] [ -t term ] [ -r rawfile ] [ -b ] [ -i ] [ inpfile ... ]

nutmeg [ - ] [ -n ] [ -t term ] [ datafile ... ]

Options are:
-
Don't try to load the default data file ("rawSpice.raw") if no other files are given. Nutmeg only.

-n (or -N)
Don't try to source the file ".Spiceinit" upon startup. Normally Spice and Nutmeg try to find the file in the current directory, and if it is not found then in the user's home directory.

-t term (or -T term)
The program is being run on a terminal with mfb name term.

-b (or -B)
Run in batch mode. Spice3 reads the default input source (e.g. keyboard) or reads the given input file and performs the analyses specified; output is either Spice2-like line-printer plots ("ascii plots") or a Spice rawfile. See the following section for details. Note that if the input source is not a terminal (e.g. using the IO redirection notation of "<") Spice3 defaults to batch mode (-i overrides). This option is valid for Spice3 only.

-s (or -S)
Run in server mode. This is like batch mode, except that a temporary rawfile is used and then written to the standard output, preceded by a line with a single "@", after the simulation is done. This mode is used by the Spice daemon. This option is valid for Spice3 only.

-i (or -I)
Run in interactive mode. This is useful if the standard input is not a terminal but interactive mode is desired. Command completion is not available unless the standard input is a terminal, however. This option is valid for Spice3 only.

-r rawfile (or -P rawfile)
Use rawfile as the default file into which the results of the simulation are saved. This option is valid for Spice3 only.

Further arguments to Spice are taken to be Spice3 input files, which are read and saved (if running in batch mode then they are run immediately). Spice3 accepts most Spice2 input file, and output ascii plots, fourier analyses, and node printouts as specified in .PLOT, .FOUR, and .PRINT cards. If an out parameter is given on a .WIDTH card, the effect is the same as set width = .... Since Spice3 ascii plots do not use multiple ranges, however, if vectors together on a .PLOT card have different ranges they are not provide as much information as they would in Spice2. The output of Spice3 is also much less verbose than Spice2, in that the only data printed is that requested by the above cards.

For Nutmeg, further arguments are taken to be data files in binary or ascii format (see sconvert(1)) which are loaded into Nutmeg. If the file is in binary format, it may be only partially completed (useful for examining Spice2 output before the simulation is finished). One file may contain any number of data sets from different analyses.

### 5.1 EXPRESSIONS, FUNCTIONS, AND CONSTANTS

Spice and Nutmeg data is in the form of vectors: time, voltage, etc. Each vector has a type, and vectors can be operated on and combined in algebraic ways consistent with their types. Vectors are normally created when a data file is read in (see the load command below), and when the initial datafile is loaded. They can also be created with the let command.

An expression is an algebraic formula involving vectors and scalars (a scalar is a vector of length 1) and the following operations:

+ - * / ^ %

% is the modulo operator, and the comma operator has two meanings: if it is present in the argument list of a user-definable function, it serves to separate the arguments. Otherwise, the term x,y is synonymous with x+j(y).

Also available are the logical operations & (and), | (or), ! (not), and the relational operations <, >, >=, <=, =, and <> (not equal). If used in an algebraic expression they work like they would in C, producing values of 0 or 1. The relational operators have the following synonyms:

 gt > lt < ge >= le <= ne <> eq = and & or | not !

These are useful when < and > might be confused with IO redirection (which is almost always).

The following functions are available:

 mag(vector) The magnitude of vector. [Note: magnitude() is a synonym for this.] ph(vector) The phase of vector. [Note: phase() is a synonym for this.] j(vector) i (sqrt(-1)) times vector. real(vector) The real component of vector. imag(vector) The imaginary part of vector. db(vector) 20 log10(mag(vector)). log(vector) The logarithm (base 10) of vector. ln(vector) The natural logarithm (base e) of vector. exp(vector) e to the vector power. abs(vector) The absolute value of vector. sqrt(vector) The square root of vector. sin(vector) The sine of vector. cos(vector) The cosine of vector. tan(vector) The tangent of vector. atan(vector) The inverse tangent of vector. norm(vector) The vector normalized to 1 (i.e. the largest magnitude of any component is 1). pos(vector) 1 if the real part of vector is positive, 0 otherwise. [Note: present, but undocumented in Berkeley release.] rnd(vector) A vector with each component a random integer between 0 and the absolute value of the vector's corresponding component. mean(vector) The result is a scalar (a length 1 vector) that is the mean of the elements of vector. unitvec(number) The result is a vector of length number, with elements 1. If number is a vector then just the first element is taken, and if it isn't an integer then the floor of the magnitude is used. [Note: present, but undocumented in Berkeley release.] vector(number) The result is a vector of length number, with elements 0, 1, ... number - 1. If number is a vector then just the first element is taken, and if it isn't an integer then the floor of the magnitude is used. length(vector) The length of vector. interpolate(plot.vector) The result of interpolating the named vector onto the scale of the current plot. This function uses the variable polydegree to determine the degree of interpolation. deriv(vector) Calculates the derivative of the given vector. This uses numeric differentiation by interpolating a polynomial and may not produce satisfactory results (particularly with iterated differentiation). The implementation only calculates the derivative with respect to the real component of that vector's scale.

A vector may be either the name of a vector already defined or a floating-point number (a scalar). A number may be written in any format acceptable to Spice, such as 14.6Meg or -1.231e-4. Note that you can either use scientific notation or one of the abbreviations like MEG or G, but not both. As with Spice, a number may have trailing alphabetic characters after it.

The notation expr[num] denotes the num'th element of expr. For multi-dimensional vectors, a vector of one less dimension is returned. Also for multi-dimensional vectors, the notation expr[m][n] will return the n'th element of the m'th subvector. To get a subrange of a vector, use the form expr[lower,upper].

[Note: The parser is not very sophisticated so it may sometimes be necessary to delimit element names with spaces, e.g. 'foo[ bar ]'. CDHW.]

The notation vector[[lower,upper]] denotes the values in vector corresponding to the range from lower to upper in the scale, so that v(1)[[10, 20]] gives all the values of v(1) for which the TIME value is between 10 and 20. If there is one argument it picks out the values which have that scale value. Multi-dimensionality is ignored here; the result is a 1-dimensional vector.

To reference vectors in a plot that is not the current plot (see the setplot command, below), the notation plotname.vecname can be used.

Either a plotname or a vector name may be replaced by the wildcard all. If the plotname is all, matching vectors from all plots are specified, and if the vector name is all, all vectors in the specified plots are referenced. Note that you may not use binary operations on expressions involving wildcards - it is not obvious what all + all should denote, for instance. Thus some (contrived) examples of expressions are:


cos(TIME) + db(v(3))
sin(cos(log([1 2 3 4 5 6 7 8 9 10])))
TIME * rnd(v(9)) - 15 * cos(vin#branch) ^ [7.9e5 8]
not ((ac3.FREQ[32] & tran1.TIME[10]) gt 3)


[Note: The Berkeley 3f4/5 release code does not correctly parse vectors like [ 1 2 3 ], so the above examples only work in patched distributions. The compose command can be used as a workround in unpatched versions. Conflicts within the standard Spice syntax makes specifying vectors with [] ambiguous so some developers have used other methods. For example the MacSpice defines a semicolon operator to facilitate construction of vectors and n-dimensional matrices. e.g. the commands:

    let foo = ((11;12);(21;22)) creates a 2x2 matrix
let bar = (foo;(31;32))     creates a 3x2 matrix
let baz = (1;(3,4);5)       creates a complex vector with 3 elements


The ()'s protect the semicolon and prevent it being treated as a command separator. CDHW.]

Vector names in Spice may have a name such as @name[param], where name is either the name of a device instance or model. This denotes the value of the param parameter of the device or model. See Appendix B for details of what parameters are available. The value is a vector of length 1. This function is also available with the show command, and is available with variables for convenience for command scripts.

There are a number of pre-defined constants in Nutmeg. They are:

 pi π (3.14159...) e The base of natural logarithms (2.71828...) c The speed of light (299,792,500 m/s) i The square root of -1 kelvin Absolute 0 in Centigrade (-273.15°C) echarge The charge on an electron (1.6021918e-19 C) boltz Boltzman's constant (1.3806226e-23 J/K) planck Planck's constant (h = 6.626200e-34 J/Hz)

These are all in MKS units. If you have another variable with a name that conflicts with one of these then it takes precedence.

### 5.2 COMMAND INTERPRETATION

If a word is typed as a command, and there is no built-in command with that name, the directories in the sourcepath list are searched in order for the file. If it is found, it is read in as a command file (as if it were sourced). Before it is read, however, the variables argc and argv are set to the number of words following the filename on the command line, and a list of those words respectively. After the file is finished, these variables are unset. Note that if a command file calls another, it must save its argv and argc since they are altered. Also, command files may not be re-entrant since there are no local variables. (Of course, the procedures may explicitly manipulate a stack...) This way one can write scripts analogous to shell scripts for Nutmeg and Spice3.

Note that for the script to work with Spice3, it must begin with a blank line (or whatever else, since it is thrown away) and then a line with .CONTROL on it. This is an unfortunate result of the source command being used for both circuit input and command file execution. Note also that this allows the user to merely type the name of a circuit file as a command and it is automatically run. The commands are executed immediately, without running any analyses that may be specified in the circuit (to execute the analyses before the script executes, include a run command in the script).

There are various command scripts installed in /usr/local/lib/Spice/scripts (or whatever the path is on your machine), and the default sourcepath includes this directory, so you can use these command files (almost) like built-in commands.

### 5.3 COMMANDS

#### 5.3.1 Ac*: Perform an AC, small-signal frequency response analysis

General form:
     ac [ dec | oct | lin ] N Fstart Fstop


Do an ac analysis. See the previous sections of this manual for more details.

#### 5.3.2 Alias: Create an alias for a command

General form:
     alias [word] [text ... ]


Causes word to be aliased to text. History substitutions may be used, as in C-shell aliases.

#### 5.3.3 Alter*: Change a device or model parameter

General form [3f4]:
     alter dev = expression
alter dev param = expression
alter @dev[param] = expression

General form [pre 3f4]:
     alter device value
alter device parameter value [ parameter value ]


Alter changes the value for a device or a specified parameter of a device or model. The first form is used by simple devices which have one principal value (resistors, capacitors, etc.) the other forms are for more complex devices (bjt's, etc.). Model parameters can be changed with the second form if the name contains a "#".

For specifying vectors as values, start the vector with "[", followed by the values in the vector, and end with "]". Be sure to place a space between each of the values and before and after the "[" and "]".

#### 5.3.am Altermod*: Change a model parameter

General form:
     altermod mod = expression
altermod mod param = expression
altermod @mod[param] = expression


Altermod is a version of the alter command which operates on models and is used in the same manner. [Note: Code for this command was present but inactive in the original Berkeley release of Spice 3f4. CDHW.]

#### 5.3.4 Asciiplot: Plot values using old-style character plots

General form:
     asciiplot plotargs


Produce a line printer plot of the vectors. The plot is sent to the standard output, so you can put it into a file with asciiplot args ... > file. The set options width, height, and nobreak determine the width and height of the plot, and whether there are page breaks, respectively. Note that you will have problems if you try to asciiplot something with an X-scale that isn't monotonic (i.e, something like sin(TIME)), because asciiplot uses a simple-minded linear interpolation.

#### 5.3.5 ASpice: Asynchronous Spice run

General form:
     aSpice input-file [output-file]


Start a Spice-3 run, and when it is finished load the resulting data. The raw data is kept in a temporary file. If output-file is specified then the diagnostic output is directed into that file, otherwise it is thrown away.

#### 5.3.6 Bug: Mail a bug report

General form:
     bug


Send a bug report. Please include a short summary of the problem, the version number and name of the operating system that you are running, the version of Spice that you are running, and the relevant Spice input file. (If you have defined BUGADDR, the mail is delivered to there.)

#### 5.3.7 Cd: Change directory

General form:
     cd [ directory ]


Change the current working directory to directory, or to the user's home directory if none is given.

#### 5.3.co Compose: Compose a vector

General form:
     compose name values value1 [ value2 ... ]
compose name parm = val [ parm = val ... ]


[Note: This command was not fully implemented in the Berkeley release, however it is a way to create a vector from a list of values, which is lucky because the Berkeley frontend parser rejects expressions like [ 11 22 33 ].]

The first form takes the values and creates a new vector, the values may be arbitrary expressions.

The second form has the following possible parameters:

 start The value at which the vector should start. stop The value at which the vector should end. step The difference between sucessive elements. lin The number of points, linearly spaced. log The number of points, logarithmically spaced. dec The number of points per decade, logarithmically spaced. center Where to center the range of points. span The size of the range of points. unif The number of random points (uniform [0.1) distribution). gauss The number of random points (Gaussian distribution). mean The mean of the Gaussian distribution. sd The standard deviation of the Gaussian distribution.

#### 5.3.cs Cross: Create a vector

General form:
     cross vecname n [ vector1 vector2 ... ]


Create a new vector vecname from the nth elements of the listed vectors. Note: If any input vector is complex then the output vector will be complex, and vector[n] is the first element of vector. If n is a vector only the real part of its first element is used.

#### 5.3.8 Destroy: Delete a data set

General form:
     destroy [ plotnames | all ]

Release the memory holding the data for the specified runs.

#### 5.3.9 Dc*: Perform a DC-sweep analysis

General form:
     dc Source-Name Vstart Vstop Vincr [ Source2 Vstart2 Vstop2 Vincr2 ]

Do a dc transfer curve analysis. See the previous sections of this manual for more details.

#### 5.3.10 Define: Define a function

General form:
     define function(arg1 [ , arg2  ... ]) expression


Define the user-definable function with the name function and arguments arg1, arg2, ... to be expression, which may involve the arguments. When the function is later used, the arguments it is given are substituted for the formal arguments when it is parsed. If expression is not present, any definition for function is printed, and if there are no arguments to define then all currently active definitions are printed. Note that you may have different functions defined with the same name but different arities [i.e. number of arguments.].

Some useful definitions are:


define max(x,y) (x > y) * x + (x <= y) * y
define min(x,y) (x < y) * x + (x >= y) * y


#### 5.3.dt Deftype: Define type of plot or vector

General form:
     deftype v vectype [ units ]
deftype p plottype [ pattern ... ]


Define addtional vector and plot types. The first form refers to vectors, for example:

     Spice3 > deftype v money USD
Spice3 > let cost = 0.15 * vector(10)
Spice3 > settype money cost
Spice3 > plot cost vs vector(10)


This second form of this command seems to have been intended for use in the Command: field of rawfiles. It defines additional plot-types. The short name given to a plot with any of the patterns present in its Name: field will be plottypeN, where N is a distinctive number.

#### 5.3.11 Delete*: Remove a trace or breakpoint

General form:
     delete [ debug-number ... ]


Delete the specified breakpoints, traces and saves. The debug numbers are those shown by the status command (unless you do status > file, in which case the debug numbers are not printed).

#### 5.3.12 Diff: Compare vectors

General form:
     diff plot1 plot2 [ vec ...]


Compare all the vectors in the specified plots, or only the named vectors if any are given. There are different vectors in the two plots, or any values in the vectors differ significantly the difference is reported. The variable diff_abstol, diff_reltol, and diff_vntol are used to determine what is meant by a significant difference.

#### 5.3.13 Display: List known vectors and types

General form:
     display [ varname ...]


Prints a summary of currently defined vectors, or of the names specified. The vectors are sorted by name unless the variable nosort is set. The information given is the name of the vector, the length, the type of the vector, and whether it is real or complex data. Additionally, one vector is labeled [scale]. When a command such as plot is given without a vs argument, this scale is used for the X-axis. It is always the first vector in a rawfile, or the first vector defined in a new plot. If you undefine the scale (i.e., let TIME = []), one of the remaining vectors becomes the new scale (which is undetermined). See also setscale.

#### 5.3.14 Echo: Print text

General form:
     echo [ -n ] [ text ... ]


Echos the given text to the screen. If the first argument is -n the terminating newline is suppressed.

#### 5.3.15 Edit*: Edit the current circuit

General form:
     edit [ file ]


Print the current Spice3 input file into a file, call up the editor on that file and allow the user to modify it, and then read it back in, replacing the original file. If a filename is given, then edit that file and load it, making the circuit the current one.

#### 5.3.16 Fourier: Perform a Fourier transform

General form:
     fourier fundamental [ value ...]


Does a Fourier analysis of each of the given values, using the first 10 multiples of the fundamental frequency (or the first nfreqs, if that variable is set - see below). The output is like that of the .FOUR Spice3 line. The values may be any valid expression. The values are interpolated onto a fixed-space grid with the number of points given by the fourgridsize variable, or 200 if it is not set. The interpolation is of degree polydegree if that variable is set, or 1. If polydegree is 0, then no interpolation is done. This is likely to give erroneous results if the time scale is not monotonic, though.

#### 5.3.17 Hardcopy: Save a plot to a file for printing

General form:
     hardcopy file plotargs


Just like plot, except creates a file called file containing the plot in the format specified by the variable hcopydevtype. The default file format is an image in plot(5) format, and can be printed by either the [unix] plot(1) program or lpr with the -g flag. See also the hcopy variables.

#### 5.3.18 Help: Print summaries of Spice3 commands

General form:
     help [all] [command ...]


Prints help. If the argument all is given, a short description of everything you could possibly type is printed. If commands are given, descriptions of those commands are printed. Otherwise help for only a few major commands is printed.

#### 5.3.19 History: Review previous commands

General form:
     history [ -r ] [number]


Print out the history, or the last number commands typed at the keyboard. Note: in Spice3 version 3a7 and earlier, all commands (including ones read from files) were saved. The -r option reverses the printing order. [See also the page on history substitutions in commands.]

#### 5.3.20 Iplot*: Incremental plot

General form:
     iplot [ node ...]


Incrementally plot the values of the nodes while Spice3 runs. The iplot command can be used with the where command to find trouble spots in a transient simulation; it is essentially a graphical version of trace. Several iplots may be active simulataneously. Iplotting is not applicable for all analyses. The status command displays a list of current iplots, and these can be removed with the delete command.

#### 5.3.21 Jobs: List active asynchronous Spice runs

General form:
     jobs


Report on the asynchronous Spice-3 jobs currently running. Nutmeg checks to see if the jobs are finished every time you execute a command. If it is done then the data is loaded and becomes available.

#### 5.3.22 Let: Assign a value to a vector

General form:
     let name = expr


Assigns the value specified by expr, an expression as described above, to the vector called name which is created in the current plot if it is not found. If expr is [] (a zero-length vector) then the vector becomes undefined [Note: This doesn't work with the Berkeley 3f4/5 release code, try unlet instead.]. Individual elements of a vector may be modified by appending a subscript to name (e.g. name[0]). If there are no arguments, let is the same as display.

[Note: Do not use the form

    Spice3 > myvec = 0.15 * yourvec

to abbreviate
 	Spice3 > let myvec = 0.15 * yourvec

because Spice will perform an unwanted and time-consuming search for commands and/or files matching 'myvec' before using the let command as the default behaviour.]

The command let creates a vector in the current plot, use setplot to create a new plot.

#### 5.3.23 Linearize*: Interpolate to a linear scale

General form:
     linearize [ vec ... ]


Create a new plot with all of the vectors in the current plot, or only those mentioned if arguments are given. The new vectors are interpolated onto a linear time scale, which is determined by the values of tstep, tstart, and tstop in the currently active transient analysis. The currently loaded input file must include a transient analysis (a tran command may be run interactively before the last reset, alternately), and the current plot must be from this transient analysis. This command is needed because Spice3 doesn't output the results from a transient analysis in the same manner that Spice2 did.

#### 5.3.24 Listing*: Print a listing of the current circuit

General form:
     listing [ logical | physical | deck ] [ expand ]


If the logical argument is given, the listing is with all continuation lines collapsed into one line, and if the physical argument is given the lines are printed out as they were found in the file. The default is logical. A deck listing is just like the physical listing, except without the line numbers it recreates the input file verbatim (except that it does not preserve case). If the word expand is present, the circuit is printed with all subcircuits expanded.

General form:
     load [ filename ... ]


Loads either binary or ascii format rawfile data from the files named. The default filename is rawSpice.raw, or the argument to the -r flag if there was one when Spice was invoked.

#### 5.3.ns Noise*: Perform a noise analysis

General form:
     noise v(output [,ref]) src [ dec | lin | oct ] Pts Fstart Fstop [PPS];


Do an noise analysis. See the previous sections of this manual for more details.

#### 5.3.26 Op*: Perform an operating point analysis

General form:
     op


Do an operating point analysis. See the previous sections of this manual for more details.

#### 5.3.27 Plot: Plot values on the display

General form:
     plot exprs [ylimit ylo yhi] [xlimit xlo xhi] [xindices xilo xihi]
[xcompress comp] [xdelta xdel] [ydelta ydel] [xlog] [ylog] [loglog]
[vs xname] [xlabel word] [ylabel word] [title word] [samep]
[keyword ... ]


Plot the given exprs on the screen (if you are on a graphics terminal). The xlimit and ylimit arguments determine the high and low x- and y-limits of the axes, respectively. The xindices arguments determine what range of points are to be plotted - everything between the xiloth point and the xihith point is plotted. The xcompress argument specifies that only one out of every comp points should be plotted. If an xdelta or a ydelta parameter is present, it specifies the spacing between grid lines on the X- and Y-axis. These parameter names may be abbreviated to xl, yl, xind, xcomp, xdel, and ydel respectively.

The xname argument is an expression to use as the scale on the x-axis. If xlog or ylog are present then the X or Y scale, respectively, is logarithmic (loglog is the same as specifying both). The xlabel and ylabel arguments cause the specified labels to be used for the X and Y axes, respectively.

If samep is given, the values of the other parameters (other than xname) from the previous plot, hardcopy, or asciiplot command is used unless re-defined on the command line.

The title argument is used in the place of the plot name at the bottom of the graph.

The following keywords are available in Spice3f:

 linear override a default log-scale plot (as in the output for an AC analysis linplot synonym for linear lingrid override a default log-scale plot without tranforming the data smith Smith plot - data is transformed by the function (x-1)/(x+1) smithgrid polar plot with a Smith grid but without transforming the data. pointplot plot the points without joining them. combplot plot vectors by drawing a vertical line from each point to the X-axis, as opposed to joining the points.

[Note: The Berkeley release version of this command seems to ignore the variables that one would expect to influence this command. CDHW.]

#### 5.3.28 Print: Print values

General form:
     print [col] [line] expr [ expr2 ... ]


Prints the vector described by the expression expr. If the col argument is present, print the vectors named side by side. If line is given, the vectors are printed horizontally. col is the default, unless all the vectors named have a length of one, in which case line is the default. The options width, height, and nobreak are effective for this command (see asciiplot). If the expression is all, all of the vectors available are printed. Thus print col all > file prints everything in the file in Spice2 format. The scale vector (time, frequency) is always in the first column unless the variable noprintscale is true.

#### 5.3.pz PZ: Pole-Zero Analysis

General form:
     pz node1 node2 node3 node4 { cur | vol } { pol | zer | pz }

Performs a pole-zero analysis of the current circuit, as described earlier.

#### 5.3.29 Quit: Leave Spice3 or Nutmeg

General form:
     quit


Quit nutmeg or Spice.

#### 5.3.30 Rehash: Reset internal hash tables

General form:
     rehash


Recalculate the internal hash tables used when looking up UNIX commands, and make all UNIX commands in the user's PATH available for command completion. This is useless unless you have set unixcom first (see below).

#### 5.3.31 Reset*: Reset an analysis

General form:
     reset


Throw out any intermediate data in the circuit (e.g, after a breakpoint or after one or more analyses have been done already), and re-parse the input file. The circuit can then be re-run from its initial state, overriding the affect of any set or alter commands. In Spice-3e and earlier versions this was done automatically by the run command.

#### 5.3.32 Reshape: Alter the dimensionality or dimensions of a vector

General form:
     reshape vector vector ...
or
reshape vector vector ...  [ dimension, dimension, ...  ]
or
reshape vector vector ... [ dimension ][ dimension ] ...


This command changes the dimensions of a vector or a set of vectors. The final dimension may be left off and it will be filled in automatically. If no dimensions are specified, then the dimensions of the first vector are copied to the other vectors. An error message of the form 'dimensions of x were inconsistent' can be ignored.

#### 5.3.33 Resume*: Continue a simulation after a stop

General form:
     resume


Resume a simulation after a stop or interruption (control-C).

#### 5.3.34 RSpice: Remote Spice submission

General form:
     rSpice input file


Runs a Spice-3 remotely taking the input file as a Spice-3 input file, or the current circuit if no argument is given. Nutmeg or Spice3 waits for the job to complete, and passes output from the remote job to the user's standard output. When the job is finished the data is loaded in as with aSpice. If the variable rhost is set, nutmeg connects to this host instead of the default remote Spice3 server machine. This command uses the "rsh" command and thereby requires authentication via a ".rhosts" file or other equivalent method. Note that "rsh" refers to the "remote shell" program, which may be "remsh" on your system; to override the default name of "rsh", set the variable remote_shell. If the variable rprogram is set, then rSpice uses this as the pathname to the program to run on the remote system.

Note: rSpice will not acknowledge elements that have been changed via the alter or altermod commands. [Note: Altermod is absent from many implemetations, use alter instead.]

#### 5.3.35 Run*: Run analysis from the input file

General form:
     run [ rawfile ]


Run the analyses specified in the input file for the current circuit. If there are any of the control lines specified in Section 4.3 present they are executed. The output is put in rawfile if it is given, in addition to being available interactively. In Spice-3e and earlier versions, the input file would be re-read and any affects of the set or alter commands would be reversed. This is no longer the effect.

[Note. Interactive commands specified using the .command/.endc mechanism are not executed by this command.]

#### 5.3.36 Rusage: Resource usage

General form:
     rusage [ resource ...]


Print resource usage statistics. If any resources are given, just print the usage of that resource. Most resources require that a circuit be loaded. Currently valid resources are:

 all Everything below. elapsed The amount of time elapsed since the last rusage elaped call. faults Number of page faults and context switches (BSD only). space Data space used. time CPU time used so far. temp Operating temperature. tnom Temperature at which device parameters were measured. equations Circuit Equations time Total Analysis Time totiter Total iterations accept Accepted timepoints rejected Rejected timepoints loadtime Time spent loading the circuit matrix and RHS. reordertime Matrix reordering time lutime L-U decomposition time solvetime Matrix solve time trantime Transient analysis time tranpoints Transient timepoints traniter Transient iterations trancuriters Transient iterations for the last time point (listed incorrectly as "Transient iterations per point") tranlutime Transient L-U decomposition time transolvetime Transient matrix solve time everything All of the above.

#### 5.3.37 Save*: Save a set of outputs

General form:
      save [ all | output ...]


Save a set of outputs, discarding the rest. If a node has been mentioned in a save command, it appears in the working plot after a run has completed, or in the rawfile if Spice is run in batch mode. If a node is traced or plotted (see below) it is also saved. For backward compatibility, if there are no save commands given, all outputs are saved.

When the keyword "all" appears in the save command, all default values (node voltages and voltage source currents) are saved in addition to any other values listed. See also the status and delete commands.

#### 5.3.38 Sens*: Run a sensitivity analysis

General form:
     sens output
sens output ac [ dec | oct | lin ] N Fstart Fstop


Perform a sensitivity analysis. The variable output is either a node voltage (e.g. "v(1)" or "v(A,out)") or a current through a voltage source (e.g. "i(vtest)"). The first form calculates DC sensitivities, the second form calculates AC sensitivities. The output values are in dimensions of change in output per unit change of input (as opposed to percent change in output or per percent change of input).

#### 5.3.39 Set: Set the value of a variable

General form:
     set [ word ]
set [ word = value ] ...


Set the value of word to be value, if it is present. You can set any word to be any value, numeric or string. If no value is given then the value is the boolean 'true'.

#### 5.4.5 If - Then - Else

General form:
     if condition
statement
...
else
statement
...
end


If the condition is non-zero then the first set of statements are executed, otherwise the second set. The else and the second set of statements may be omitted.

#### 5.4.6 Label

General form:
     label word

If a statement of the form goto word is encountered, control is transferred to this point, otherwise this is a no-op.

#### 5.4.7 Goto

General form:
     goto word

If a statement of the form label word is present in the block or an enclosing block, control is transferred there. Note that if the label is at the top level, it must be before the goto statement (i.e. a forward goto) may occur only within a block).

#### 5.4.8 Continue

     continue


If there is a while, dowhile, or foreach block enclosing this statement, control passes to the test, or in the case of foreach, the next value is taken. Otherwise an error results.

#### 5.4.9 Break

General form:
     break


If there is a while, dowhile, or foreach enclosing this statement, control passes out of the block. Otherwise an error results.

Of course, control structures may be nested. When a block is entered and the input is the terminal, the prompt becomes a number of >'s corresponding to the number of blocks the user has entered. The current control structures may be examined with the debugging command cdump.

### 5.5 VARIABLES

The operation of both Nutmeg and Spice3 may be affected by setting variables with the "set" command. In addition to the variables mentioned below, the set command in Spice3 also affect the behaviour of the simulator via the options previously described under the section on ".OPTIONS".

The variables meaningful to nutmeg which may be altered by the set command are:

 appendwrite Append output to the rawfile, if one already exists, e.g. when a write command is issued. colorN These variables determine the colors used, if X is being run on a color display. N may be between 0 and 15. Color 0 is the background, color 1 is the grid and text color, and colors 2 through 15 are used in order for vectors plotted. The value of the color variables should be names of colors, which may be found in the file /usr/lib/rgb.txt. combplot Plot vectors by drawing a vertical line from each point to the X-axis, as opposed to joining the points. Note that this option is subsumed in the plottype option, below. cpdebug Print cshpar debugging information (must be complied with the -DCPDEBUG flag). Unsupported in the current release. debug If set then a lot of debugging information is printed (must be compiled with the -DFTEDEBUG flag). Unsupported in the current release. device The name (/dev/tty??) of the graphics device. If this variable isn't set then the user's terminal is used. To do plotting on another monitor you probably have to set both the device and term variables. (If device is set to the name of a file, nutmeg dumps the graphics control codes into this file -this is useful for saving plots.) diff_abstol The absolute tolerance used by the diff command. echo Print out each command before it is executed. filetype This can be either ascii or binary, and determines the format used to write rawfile data. The default is ascii. fourgridsize How many points to use for interpolating into when doing Fourier analysis. gridsize If this variable is set to an integer, this number is used as the number of equally spaced points to use for the Yaxis when plotting. Otherwise the current scale is used (which may not have equally spaced points). If this variable is set to an integer, this number is used as the number of equally spaced points to use for the Yaxis when plotting. Otherwise the current scale is used (which may not have equally spaced points). If the current scale isn't strictly monotonic, then this option has no effect. hcopydev If this is set, when the hardcopy command is run the resulting file is automatically printed on the printer named hcopydev with the command lpr -Phcopydev -g file. hcopyfont This variable specifies the font name for hardcopy output plots. The value is device dependent. hcopyfontsize This is a scaling factor for the font used in hardcopy plots. hcopydevtype This variable specifies the type of the printer output to use in the hardcopy command. If hcopydevtype is not set, plot(5) format is assumed. The standard distribution currently recognizes postscript as an alternative output format. When used in conjunction with hcopydev, hcopydevtype should specify a format supported by the printer. height The length of the page for asciiplot and print col. history The number of events to save in the history list. lprplot5 This is a printf(3s) style format string used to specify the command to use for sending plot(5)-style plots to a printer or plotter. The first parameter supplied is the printer name, the second parameter supplied is a file name containing the plot. Both parameters are strings. This is a printf(3s) style format string used to specify the command to use for sending plot(5)-style plots to a printer or plotter. It is trivial to cause Spice3 to abort by supplying a unreasonable format string. lprps This is a printf(3s) style format string used to specify the command to use for sending PostScript plots to a printer or plotter. The first parameter supplied is the printer name, the second parameter supplied is a file name containing the plot. Both parameters are strings. It is trivial to cause Spice3 to abort by supplying an unreasonable format string. nfreqs The number of frequencies to compute in the fourier command. (Defaults to 10.) nobreak Don't have asciiplot and print col break between pages. noasciiplotvalue Don't print the first vector plotted to the left when doing an asciiplot. noclobber Don't overwrite existing files when doing IO redirection. noglob Don't expand the global characters *', ?', [', and ]'. This is the default. nogrid Don't plot a grid when graphing curves (but do label the axes). nomoremode If nomoremode is not set, whenever a large amount of data is being printed to the screen (e.g, the print or asciiplot commands), the output is stopped every screenful and continues when a carriage return is typed. If nomoremode is set then data scrolls off the screen without check. nonomatch If noglob is unset and a global expression cannot be matched, use the global characters literally instead of complaining. nopadding Don't pad vectors with zeros to equalize lengths when writing rawfile output. nosort Don't have display sort the variable names. noprintscale Don't print the scale in the leftmost column when a print col command is given. numdgt The number of digits to print when printing tables of data (fourier, print col). The default precision is 6 digits. On the VAX, approximately 16 decimal digits are available using double precision, so numdgt should not be more than 16. If the number is negative, one fewer digit is printed to ensure constant widths in tables. plottype This should be one of normal, comb, or point:chars. normal, the default, causes points to be plotted as parts of connected lines. comb causes a comb plot to be done (see the description of the combplot variable above). point causes each point to be plotted separately - the chars are a list of characters that are used for each vector plotted. If they are omitted then a default set is used. polydegree The degree of the polynomial that the plot command should fit to the data. If polydegree is N, then nutmeg fits a degree N polynomial to every set of N points and draw 10 intermediate points in between each endpoint. If the points aren't monotonic, then it tries rotating the curve and reducing the degree until a fit is achieved. polysteps The number of points to interpolate between every pair of points available when doing curve fitting. The default is 10. program The name of the current program (argv[0]). prompt The prompt, with the character !' replaced by the current event number. rawfile The default name for rawfiles created. diff_reltol The relative tolerance used by the diff command. remote_shell Overrides the name used for generating rSpice runs (default is "rsh"). rhost The machine to use for remote Spice-3 runs, instead of the default one (see the description of the rSpice command, below). rprogram The name of the remote program to use in the rSpice command. slowplot Stop between each graph plotted and wait for the user to type return before continuing. sourcepath A list of the directories to search when a source command is given. The default is the current directory and the standard Spice library (/usr/local/lib/Spice, or whatever LIBPATH is #defined to in the Spice3 source. Spicepath The program to use for the aSpice command. The default is /cad/bin/Spice. term The mfb name of the current terminal. units If this is degrees, then all the trig functions will use degrees instead of radians. unixcom If a command isn't defined, try to execute it as a UNIX command. Setting this option has the effect of giving a rehash command, above. This is useful for people who want to use nutmeg as a login shell. verbose Be verbose. This is midway between echo and debug / cpdebug. diff_vntol The absolute voltage tolerance used by the diff command. width The width of the page for asciiplot and print col. x11lineararcs Some X11 implementations have poor arc drawing. If you set this option, Spice3 will plot using an approximation to the curve using straight lines. xbrushheight The height of the brush to use if X is being run. xbrushwidth The width of the brush to use if X is being run. xfont The name of the X font to use when plotting data and entering labels. The plot may not look good if this is a variable-width font.

There are several set variables that Spice3 uses but Nutmeg does not. They are:

 editor The editor to use for the edit command. modelcard The name of the model card (normally .MODEL). noaskquit Do not check to make sure that there are no circuits suspended and no plots unsaved. Normally Spice-3 warns the user when he tries to quit if this is the case. nobjthack Assume that BJTs have 4 nodes. noparse Don't attempt to parse input files when they are read in (useful for debugging). Of course, they cannot be run if they are not parsed. nosubckt Don't expand subcircuits renumber Renumber input lines when an input file has .INCLUDE's. subend The card to end subcircuits (normally .ENDS). subinvoke The prefix to invoke subcircuits (normally X). substart The card to begin subcircuits (normally .SUBCKT).

### 5.6 MISCELLANEOUS

If there are subcircuits in the input file, Spice3 expands instances of them. A subcircuit is delimited by the cards .SUBCKT and .ENDS, or whatever the value of the variables substart and subend is, respectively. An instance of a subcircuit is created by specifying a device with type 'x' - the device line is written

     xname node1 node2 ... subcktname

where the nodes are the node names that replace the formal parameters on the .SUBCKT line. All nodes that are not formal parameters are prepended with the name given to the instance and a ':', as are the names of the devices in the subcircuit. If there are several nested subcircuits, node and device names look like subckt1:subckt2:...:name. If the variable subinvoke is set, then it is used as the prefix that specifies instances of subcircuits, instead of 'x'.

Nutmeg occasionally checks to see if it is getting close to running out of space, and warns the user if this is the case. (This is more likely to be useful with the Spice front end.)

C-shell type quoting with "" and '', and backquote substitution may be used. Within single quotes, no further substitution (like history substitution) is done, and within double quotes, the words are kept together but further substitution is done. Any text between backquotes is replaced by the result of executing the text as a command to the shell.

Tenex-style ('set filec' in the 4.3 C-shell) command, filename, and keyword completion is possible: If EOF (control-D) is typed after the first character on the line, a list of the commands or possible arguments is printed (If it is alone on the line it exits nutmeg). If escape is typed, then nutmeg trys to complete what the user has already typed. To get a list of all commands, the user should type <space> ^D.

The values of variables may be used in commands by writing $varname where the value of the variable is to appear. The special variables$$and$< refer to the process ID of the program and a line of input which is read from the terminal when the variable is evaluated, respectively. If a variable has a name of the form $&word, then word is considered a vector (see above), and its value is taken to be the value of the variable. If$foo is a valid variable, and is of type list, then the expression $foo[low-high] represents a range of elements. Either the upper index or the lower may be left out, and the reverse of a list may be obtained with$foo[len-1]. Also, the notation $?foo evaluates to 1 if the variable foo is defined, 0 otherwise, and$#foo evaluates to the number of elements in foo if it is a list, 1 if it is a number or string, and 0 if it is a boolean variable.

History substitutions, similar to C-shell history substitutions, are also available - see the C-shell manual page for all of the details.

The characters ~, {, and } have the same effects as they do in the C-Shell, i.e., home directory and alternative expansion. It is possible to use the wildcard characters *, ?, [, and ] also, but only if you unset noglob first. This makes them rather useless for typing algebraic expressions, so you should set noglob again after you are done with wild-card expansion. Note that the pattern [^abc] matchs all characters except a, b, and c.

IO redirection is available - the symbols >, >>, >&, >>&, and < have the same effects as in the C-shell.

You may type multiple commands on one line, separated by semicolons.

If you want to use a different mfbcap file than the default (usually ~cad/lib/mfbcap), you have to set the environment variable Spice_MFBCAP before you start nutmeg or Spice. The -m option and the mfbcap variable no longer work.

If X is being used, the cursor may be positioned at any point on the screen when the window is up and characters typed at the keyboard are added to the window at that point. The window may then be sent to a printer using the xpr(1) program.

Nutmeg can be run under VAX/VMS, as well as several other operating systems. Some features like command completion, expansion of *, ?, and [], backquote substitution, the shell command, and so forth do not work.

On some systems you have to respond to the -more- prompt during plot with a carriage return instead of any key as you can do on UNIX.

### 5.7 BUGS

The label entry facilities are primitive. You must be careful to type slowly when entering labels -- nutmeg checks for input once every second, and can get confused if characters arrive faster.

If you redefine colors after creating a plot window with X, and then cause the window to be redrawn, it does not redraw in the correct colors.

When defining aliases like

     alias pdb plot db( '!:1' - '!:2' )

you must be careful to quote the argument list substitutions in this manner. If you quote the whole argument it might not work properly.

In a user-defined function, the arguments cannot be part of a name that uses the plot.vec syntax. For example:


define check(v(1)) cos(tran1.v(1))

does not work.

If you type plot all all, or otherwise use a wildcard reference for one plot twice in a command, the effect is unpredictable.

The asciiplot command doesn't deal with log scales or the delta keywords.

Often the names of terminals recognized by MFB are different from those in /etc/termcap. Thus you may have to reset your terminal type with the command


set term = termname

where termname is the name in the mfbcap file.

The hardcopy command is useless on VMS and other systems without the plot command, unless the user has a program that understands plot(5) format.

Spice3 recognizes all the notations used in Spice2 .PLOT cards, and translates vp(1) into ph(v(1)), and so forth. However, if there are spaces in these names it won't work. Hence v(1, 2) and (-.5, .5) aren't recognized.

BJTs can have either 3 or 4 nodes, which makes it difficult for the subcircuit expansion routines to decide what to rename. If the fourth parameter has been declared as a model name, then it is assumed that there are 3 nodes, otherwise it is considered a node. To disable this, you can set the variable "nobjthack" which forces BJTs to have 4 nodes (for the purposes of subcircuit expansion, at least).

The @name[param] notation might not work with trace, iplot`, etc. yet.

The first line of a command file (except for the .Spiceinit file) should be a comment, otherwise Spice may create an empty circuit.

Files specified on the command line are read before .Spiceinit is read.