Expressions

NSLS provides two basic methods, set and get, to access NSLM attribute variables. Set

Objects can be assigned data values using the set command, analogous to the assignment operator in NSLM.

To assign data, nsl set object-name value where object-name is the name of an existing object and value corresponds to a matching attribute type value.

For example, to set the value of "1" to a scalar object found in model.objl.objll would be use:

nsl set model.obj1.obj11 1

In general, the number of elements typed in value will correspond to the dimension defined for the object. The exception is to set all of the values in an object to a unique value corresponding to a single element. According to the object type and corresponding dimension NSL uses the following format:

For NslTjpeO corresponding to single elements, for example, we set a scalar as nsl set tu 1.0 assigning 1.0 to a zero dimension tu object.

For NslTjpel corresponding to a list or vector, for example, we set a 9-element vector as nsl set s { 0 0 0 0 1 0 2 0 0 }

The expression assigns the nine integer values to a one dimension s object: 1 to s[4] and 2 to s[6], and the rest 0. (Remember that indices start with 0 and spaces must be left between brackets and other characters.) Objects can be assigned single element values by using parenthesis around element indices. For example:

nsl

set

s

0

nsl

set

s

4)

1

nsl

set

s

6)

2

is equivalent to the initial example.

is equivalent to the initial example.

For NslType2 corresponding to a two-dimensional list or matrix, we set the values of a 2x9 matrix using:

nsl set s {{ 0 0 0 0 1 0 2 0 0 } { 3 0 0 0 0 0 0 0 0 }}

The expression assigns integer values to a two dimensional s object: 1 to s(0,4) 2 to s(0,6), 3 to s(0,1) and the rest 0. We can also type the above all on one line. (Notice that if an interactively specified command is incomplete then the ">" prompt will appear. When the command is complete the prompt will change back to "nsls%".)

Matrices can be assigned single element values by using parenthesis around element indices. For example

nsl

set

s

0

nsl

set

s(

0

4)

1

nsl

set

s(

0

6)

2

nsl

set

s(

1

0)

3

is equivalent to the initial example.

is equivalent to the initial example.

For NslType3 corresponding to a three-dimensional list or vector of matrices, we set the values of a 2x2x9 array using:

nsl set s {{{ 0 0 0 0 1 0 2 0 0 } { 3 0 0 0 0 0 0 0 0 }} {{ 0 0 0 0 4 0 5 0 0 } { 6 0 0 0 0 0 0 0 0 }}}

The expression assigns integer values to a three dimension s object: 1 to s(0,0,4) 2 to s(0,0,6), 3 to s(0,0,1), 4 to s(1,0,4) 5 to s(1,0,6), 6 to s(1,0,1) and the rest 0. Again we can assign single element values by using parenthesis around element indices. For example nsl set s 0

and so forth.

For NslType4 corresponding to a four-dimensional list or a vector of three-dimensional matrices, for example, we set a 2x2x2x9 array as nsl set s {{{{ 0 0 0 0 1 0 2 0 0 }{ 3 0 0 0 0 0 0 0 0 }} {{ 0 0 0 0 4 0 5 0 0 }{ 6 0 0 0 0 0 0 0 0 }}} {{{ 0 0 0 0 7 0 8 0 0 }{ 9 0 0 0 0 0 0 0 0 }} {{ 0 0 0 0 10 0 11 0 0 }{ 12 0 0 0 0 0 0 0 0 }}}}

The expression assigns integer values to a four dimensional s object: 1 to s(0,0,0,4) 2 to s(0,0,0,6), 3 to s(0,0,0,1) and so forth. Again we can assign single element values by using parenthesis around element indices. For example nsl set s 0

and so forth.

The get command is somewhat similar to the set command. The main difference lies in that it retrieves the value instead of setting it. Since NSLS does not let the user create new NSLM variables, the result from a get command must be stored into a TCL variable. We use the following TCL substitution format to retrieve values with the NSLS get command into a TCL variable command (notice the brackets below):

set tclvar [nsl get object-name]

where tclvar is the name of the TCL variable storing the resulting value, object-name is the name of an existing object. For example, set s [nsl get model.objl.objll]

Since TCL expressions always return a string, the "[nsl get object-name]" will return a string as well, setting the value of s to the corresponding return value. For example, if "model.objLobjU" was a two dimensional 2x2 matrix containing integer values, then "model.objLobjU" might return the string "{{ 9 5 }{7 4 }}".

If the user tries the "nsl get object-name" command without assigning the returning string to a variable, a TCL script error will occur. TCL would not know how to interpret the resultant string and would print an "invalid command name" message.

According to the object type and corresponding dimension NSL uses the following format:

For NslType0 corresponding to single elements, for example, we get a scalar as nsl get tu would return the value stored in tu, for example 1.0.

For NslType1 corresponding to a list or vector, for example, we get a 9-element vector as nsl get s

The expression returns a one dimension vector, for example { 0 0 0 0 1 0 2 0 0 }. Using parenthesis around element indices can retrieve single values. For example nsl get s(4)

would return 1.

For NslType2 corresponding to a two-dimensional list or matrix, for example, we get a 2x9 matrix as nsl get s

The expression returns a two dimension matrix, for example {{ 0 0 0 0 1 0 2 0 0 }{ 3 0 0 0 0 0 0 0 0 }}. Using parenthesis around element indices can retrieve single values. For example nsl get s(0,4)

would return 1.

For NslType3 corresponding to a three-dimensional list or array of matrices, for example, we get a 2x2x9 array as nsl get s

The expression returns a three dimension array, for example {{{ 0 0 0 0 1 0 2 0 0 }{ 3 0 0 0 0 0 0 0 0 }}{{ 0 0 0 0 4 0 5 0 0 }{ 6 0 0 0 0 0 0 0 0 }}}. Using parenthesis around element indices can retrieve single values. For example nsl get s(0,0,4) would return 1.

For Nsl7jpe4 corresponding to a four-dimensional list or two-dimensional array of matrices, for example, we get a 2x2x2x9 array as nsl get s

The expression returns a four dimensional array, for example {{{{ 0 0 0 0 1 0 2 0 0 }{ 3 0 0 0 0 0 0 0 0 }}{{ 0 0 0 0 4 0 5 0 0 }{ 6 0 0 0 0 0 0 0 0 }}}{{ 0 0 0 0 7 0 8 0 0 }{ 9 0 0 0 0 0 0 0 0 }}}{{ 0 0 0 0 10 0 11 0 0 }{ 12 0 0 0 0 0 0 0 0 }}}}. Using parenthesis around element indices can retrieve single values. For example nsl get s(0,0,0,4) would return 1.

Another useful function is the -dim option. We can use -dim to get the sizes of the dimensions from a NSL type object:

nsl get s -dim returns {2 2 2 9} for the four dimensional array mentioned above.

Was this article helpful?

0 0

Post a comment