next up previous contents index
Next: Batch Mode Up: Plots, Vectors and Expressions Previous: Expression Lists   Contents   Index

Set and Let

Novice WRspice users may be confused by the different interpretations of shell variables and vectors. Any variable can be defined with the set command, and undefined with unset. If defined, the value of the variable is the string, if given. For example, if

set a = 10*2
is entered, the value of a (obtained as $a) is the string ``10*2'' and not the integer 20.

Some internally used variables have boolean values, such as

set unixcom
which if set causes certain modes or functions to be active.

Vectors, however, always have numeric values, and can be created with let and compose, and deleted with unlet. If one enters

let a = 10*2,
or more simply

a = 10*2
the value of the vector a is 20. Note that the ``let'' is generally optional when assigning vectors.

At the risk of adding confusion, it should be noted that in recent WRspice releases, the set command can also be used to assign values to vectors. The syntax

set &vector = value

is equivalent to

let vector = value

Vectors can be set to shell variables, in which case they take on the interpreted numerical values. For example,

set a=10*2
b = $a
would assign the string 10*2 to the shell variable a, but the vector b would contain the value 20.

The inputs to most commands are vectors, however some commands, such as echo, substitute for shell variables. For example,

set a = "foo"
set b = "bar"
echo $a$b
would print ``foobar''.

Shell variables are expanded by echo, and in WRspice input when sourced. If the value of a vector is needed in shell expansion, then the special prefix $& should be added. This tells the shell interpreter that the following symbol is a vector, to be replaced by its value. For example,

let a = 2.0e-2
echo $&a
will print 2.00000e-2. However
let a = 2.0e-2
echo $a
would give an error message (unless a is also a shell variable), and
let a = 2.0e-2
echo a
would print ``a''.

Double quotes will cause multiple tokens to be taken as one, for example

set a = "a string"
will set a accordingly, whereas
set a = a string
will set shell variable a to ``a'' and shell variable string to boolean true.

Single quotes do about the same thing, but suppress shell variable expansion. For example:

set a = foo
set b = bar
echo $a $b
set a = foo
set b = bar
echo "$a $b"
would print ``foo bar'', whereas
set a = foo
set b = bar
echo '$a $b'
would print ``$a $b''.

In the present version, $ can not be nested. For example,

set a = foo
set b = bar
set c = '$a$b'
echo $c
prints ``$a$b'', not ``foobar''. However,
set a = foo
set b = bar
set c = $a$b
echo $c
does print ``foobar'' (the value of c).

Shell variables that are lists are referenced with zero-based index, for example

set a = ( aa bb cc )
echo $a[1]
prints ``bb''.

Actually, what can be in the brackets is [lo-hi], where lo defaults to 0 and hi defaults to the length - 1. If lo > hi, the list is reversed.

If the reference is to a vector, as in

compose a values .1 .2 .3
echo $&a[1]
the index is also zero-based, so ``2.0000e-1'' is printed.

The [] subscripting is interpreted a little differently by the shell and by the vector parser. If a variable starts with $, as in $&value[], the [] is interpreted by the shell parser. In this case, the terms inside [] must be interpreted as shell variables, with the (optional) low-high notation. In a vector expression, i. e. , one using value[], the terms inside [] will be interpreted as vector expressions, with the optional low,high notation. Thus,

if (value[index] = 0)
is perfectly legal for vectors value and index. Also, equivalently,
if ($&value[$&index] = 0)
is also ok, though not as efficient. However
if ($&value1[index] = 0)
is an error, as the shell parser does not know that index is a vector.

Shell variables can be used freely in vector expressions, however one must keep in mind how the variables are interpreted. During parsing, the shell variables are evaluated, and their values put back into the expression as constants. Then the expression is evaluated as a vector expression.

next up previous contents index
Next: Batch Mode Up: Plots, Vectors and Expressions Previous: Expression Lists   Contents   Index
Stephen R. Whiteley 2022-09-18