WRspice data are in the form of vectors: time, voltage, etc. Each vector has a type, and vectors can be operated on and combined algebraically in ways consistent with their types. During a simulation, each of the circuit variables, plus the scale vector, are filled with data from the simulation. For each simulation, the resulting vectors are associated with a ``plot''. The plot is given a name (such as ``tran2''), and stored in a list with other plots. There is one hard coded plot called ``constants'' which contains various length 1 vectors set to constant values.
An analysis will produce a plot consisting of vectors representing simulated output data. The ``current plot'' is usually the last plot produced by an analysis run, or the constants plot if no analyses have been run or rawfiles loaded. Vectors created with the let command are added to the current plot. The current plot can be changed with the setplot command, or with the Plots button in the Tools menu. A vector from any plot can be referenced with the notation
plotname.vecnamewhere plotname is the name of the plot, and vecname is the vector name.
When a rawfile is read into WRspice with the load command, a plot containing vectors is produced, as if the anaylsis had been run. The new plot becomes the current plot.
Vectors can be created with the let and compose commands. Newly-created vectors are added to the current plot, unless a plotname field is specified as part of the vector reference name. For example, entering
let myvec = constants.ewill assign a vector myvec in the current plot the values of the vector e in the constants plot. The let command without arguments will print a listing of vectors in the current plot.
The vectors actually produced depend on the type of analysis, but the most common output is the node voltage. Node voltages are denoted by vectors of the form v(N), where N is a name representing the node. Although the notation looks like a function call, the construct actually refers to a vector, and may be used in expressions whenever a vector is syntactically expected. Another common form is name#branch, which represents the ``branch'' current through voltage sources and inductors. The SPICE algorithm adds a term to the matrix for these elements, which represents the current flowing through the device. As there is a specific matrix element for the current for these devices, the value is available as an output variable. The name is the name of the voltage source or inductor. For compatibility with SPICE2, the construct i(name) is internally mapped to name#branch, and the two notations can be used interchangeably.
Additional mappings familiar from SPICE2 are also recognized in WRspice. In addition to v() and i(), the following are recognized:
vm(), im() Magnitude vp(), ip() Phase vr(), ir() Real part vi(), ii() Imaginary part vdb(), idb() Decibel value ( 20log10())
These are most useful for complex vectors as are produced in ac analysis. The general form for the argument inside the parentheses of the node voltage constructs is (node1 [,node2]), where if both node1 and node2 are given, the vector represents the voltage difference between nodes node1 and node2. If node2 and the corresponding comma are omitted, then the ground node, at zero potential, is implied. In the branch current construct, the single argument is always the name of a ``branch'' device, either a voltage source or inductor.
Most simply, vector names can be any alphanumeric word that starts with an alpha character. Vector names may also be of the form string(something), if the string is not the name of a built-in or user-defined function. In WRspice, a vector name beginning with the `@' symbol is considered a reference to an internal device or model parameter, or a circuit parameter. If the vector name is of the form @name[param], this denotes the parameter param of the device or model named name. Of course, there must be a device or model with that name defined for the current circuit and param must be a valid parameter name for that device or model type. See the documentation or use the show command for a listing of the parameters available. If the vector name is of the form @param, this refers to a parameter of the circuit with the name param. The parameters obtained in this manner are those defined on a .options line in the current circuit, those defined on a .param line in a current circuit, and the keywords of the rusage command, sought in that order. These vectors may be used as arguments to commands and functions which take vector arguments.
Vectors have an indexing that begins with 0, and an index, or range of indices, can be specified in square brackets following the vector name. The notation vec[lower,upper], where lower and upper are numbers, denotes the range of elements from vec between lower and upper. The notation vec[num] denotes the num'th element of vec. If upper is lower than lower, the order of the elements in the vector is reversed.
Using the let command, a vector may be assigned the values of a vector already defined, or a floating-point number (a real scalar), or a comma separated pair of numbers (a complex scalar). A number may be written in any format acceptable to SPICE2, such as 14.6MEG or -1.231e-4. Note that one can use either scientific notation or one of the abbreviations like MEG or G (case insensitive), but not both. As with SPICE2, a number may have trailing alphabetic characters after it, which can indicate the units.
See the description of the let command for more information. The compose command can also be used to assign values to a vector.
Vectors typically have defined units. The units are carried through a computation, and simplified when the result is generated. Presently, the system can not handle fractional powers. The units of a vector can be set with the settype command.
Vectors also posses a dimensionality. A scalar is a vector of the lowest dimensionality. Most vectors are one-dimensional lists of numbers. Certain types of analysis produce multidimensional vectors, which are analogous to arrays. This dimensionality is indicated when the vectors are listed with the display command or the let command without arguments. Plotting a multidimensional vector will produce a family of traces. Elements and sub-dimensional vectors are specified with multiple square brackets, with the bracket on the right having the lowest dimensionality.
For example, one might issue the following command:
.ac dec 10 1Hz 1Mhz dc v1 0 2 .1 v2 4.5 5.5 .25which will perform an ac analysis with the dc sources v1 and v2 stepped through the ranges 0-2 step .1 for v1, 4.5-5.5 step .25 for v2. The resulting output vectors will have dimensions [5,21,61], i.e., 5 values for v2, 21 for v1, and 61 for the ac analysis. Typing ``plot v(1)'' (for example) would plot all 21*5 analyses on the same scale (this would not be too useful). However, one can plot subranges by entering, for example, ``plot v(1)[1]'' which would plot the results for v2 = 4.75, or ``plot v(1)[1][2]'' for v2 = 4.75, v1 = .2, etc. Range specifications also work, for example ``plot v(1)[2][0,2]'' plots the values for v2 = 5, v1 = 0, .1, .2. The memory space required to hold the multidimensional plot data can grow quite large, so one should be reasonable.
An expression is an algebraic combination of already defined vectors, scalars (a scalar is a vector of length 1), constants, operators and functions. Some examples of expressions are:
cos(time) + db(v(3))
sin(cos(log(10)))
TIME*rnd(v(9)) - 15*cos(vin#branch)^7.9e5
not ((ac3.freq[32] & tran1.time[10]) gt 3)
Vectors can be evaluated by the shell parser by adding the prefix $& to the vector's name. This is useful, for example, when the value of a vector needs to be passed to the shell's echo command, or in circuit description files where vectors are to be evaluated by the shell as the file is read. Similar to the shell constructs, $?&word expands to 1 if word is a defined vector, 0 otherwise. Also $#&word expands to the length of word if word is a defined vector, or 0 if not found. Additionally, the notation $&(vector expression) is replaced by the value of the vector expression. A range specification can be added, for example echo $&(a+1)[2] prints the third entry in a+1, or 0 if out of range. If white space exists in the $&(...) construct, it probably should be quoted. Finally, the shell recognizes the construct $&v($something) as a reference to a SPICE node voltage, so that one can index node voltages as echo $&v($&i), for example. A range specification can be added, which can contain shell variables. This is true for both vectors ($& prefix) and variables.
Vector expressions can also contain calls to the built-in ``tran'' functions ordinarily used in voltage/current source specifications in transient analysis. These are the pulse(), pwl(), etc. functions described in 2.12.3. If assigned to a vector, the vector will have a length equal to the current scale (e.g., the time values of the last transient analysis plot), and be filled in with values just as if the analysis was run with the given source specification. For example
(run transient analysis: tran .1n 10n)Vector a will have length 101 and contain the pulse values.
let a = pulse(0 1 1n 1n)
There are three such functions, sin(), exp(), and gauss(), that have the same names as math functions. The math functions always return data of the same length as the argument(s), and take 1 argument for sin, exp and 2 for gauss. When one of these names is encountered in an expression, WRspice counts the arguments. If the number of arguments is 1 for sin/exp or 1 or 2 for gauss, the math function is called, otherwise the tran function is called. It may be necessary to give the gauss function a phony additional argument to force calling the tran function.