Scicos Editor
fr - eng
Context - Using symbolic parameters, context and masking in Scicos

### Modules

- Scicos

### Introduction

In most cases, double clicking on a Scicos block leads to the opening of a dialog box used to set the values of block parameters. These parameters, which we refer to as GUI parameters, are not necessarily the exact duplicate of the block parameters used in the computational function of the block used during simulation. For example the GUI parameters of a linear system block can be the numerator and the denominator of its transfer function, whereas the parameters used during the simulation are the A, B, C and D matrices associated with the time domain specification of this transfer function. It is the role of the interfacing function of the block to examine the GUI parameters given by the user, generate error messages if needed, and convert them into simulation parameters.

In specifying the GUI parameters, the user can enter numerical expressions in the dialog box, for example `23` or `[1,4;0,2]`, but he can also enter Scilab expressions such as: `exp(.4*3)+sin(.3)` or `ones(5,5)+diag([1:5])`. But more importantly, the user can enter expressions using Scilab variables: `A`, `cos(theta)/2`. These variables, which we call symbolic parameters of the block, must have been previously defined; in most cases this is done in a context.

Using symbolic parameters in specifying GUI parameters allows the user to easily change a system parameter affecting multiple blocks (otherwise the GUI parameter of each block has to be individually changed). To make an analogy with standard programming languages such as C, it would be like setting `double mass=0.3;` and using `mass` everywhere in the program instead of `0.3`. Symbolic parameters can also be used to construct parameterized models, for example it is possible to build the model of a fully generic linear-system-Kalman-filter system in which even the size of the blocks' states and input/outputs are not determined in advance and vary depending on the value of the parameters. Indeed, the sizes of the symbolic parameters can also be changed if it does not create inconsistencies in the diagram.

### Diagram context

Each Scicos diagram (the main diagram as well as the Super Blocks) has a context associated with it. The context is a Scilab script; it can be edited interactively using the ``Diagram/Context'' menu of the diagram. To use a symbolic parameter, say the matrix `A`, to be used in defining the GUI parameter of a block, `A` can be defined in the context of the diagram. But all the symbolic parameters of all the blocks in a diagram are not necessarily defined in the context of that same diagram.

### Scope of a context variable

A Scilab variable defined in the context of a diagram is accessible not only to the blocks of that diagram, but also to the contexts and the blocks of all sub-diagrams below it. For example if `A` is defined in the context of Diagram D1, and Diagram D2 is a sub-diagram of D1 (is the content of a super block of D1), then `A` is available to the context of D2 and can be used in the definition of the GUI parameters of its blocks. The context of D2 can for example contain the following instruction: `B=A+2`.

If the variable `A` is redefined in the context of Dn, one of the sub-diagrams of D1, then it is the new value that is available in the blocks of Dn, and the context and the blocks of the sub-diagrams below it. So in general, to find the definition of a symbolic parameter used in a block, first the context of the diagram containing the block must be examined. If the parameter is not defined there, the context of the diagram containing the first diagram must be examined and so on until the definition of the parameter is found.

This hierarchical treatment of parameter definition using multiple contexts as opposed to a single workspace has many advantages. The most important advantage is that a Super Block can be placed inside a diagram without any risk of conflict, even if symbolic parameters with similar names are used in both. Another advantage is its natural usage in the masking operation that we shall see later.

### Evaluation of the context

As previously stated, a context is nothing but a list of Scilab instructions: a Scilab script. The context of a diagram must be evaluated (script executed) in order to compute the symbolic parameters that are used in the definition of the GUI parameters of its blocks. The contexts are evaluated only when necessary, in particular when the content of a context is modified. In that case, all the GUI parameters of all the blocks in the diagram in which the context has been modified are re-evaluated, and so are the context and the blocks' GUI parameters of all the sub-diagrams below it. The reason for re-evaluating the sub-diagrams below it has to do with the scope of the parameters defined in the context of the first diagram. Indeed any change in this context can affect GUI parameters of all the blocks within sub-diagrams below this first diagram.

When a diagram is opened, its context is also evaluated so that symbolic parameters are made available in the environment. The GUI parameters of the blocks are however not re-evaluated. The reason is that it is assumed that two evaluation of the same identical contexts leads necessary to the same values of symbolic parameters. So, since the content of the context of the diagram has not changed since it has last been saved, the blocks GUI parameters must be up to date. This assumption holds in most cases, but not if functions such as `rand` or `date` are used in the context. Another instruction that can invalidate the assumption is the execution of an external script, for example `exec('myprog.sce')`. Clearly if the file `myprog.sce` is modified, the re-evaluation of the context can lead to different values for the symbolic parameters. Scicos attempts to identify the presence of such commands inside the text of the context and issues a full re-evaluation if it finds it necessary when a diagram is opened. But this identification is not full proof and a manual ``Evaluate'' button is provided to force a full re-evaluation if the user finds it necessary.

The ``Evaluate'' button is particularly useful when the context contains an `exec` command since Scicos does not know if the executed file is edited. In such a case, it is up to the user to force an evaluation.

Finally it should be noted that all the variables defined in a context, except for functions, are available as symbolic parameters. So it is recommended that intermediate variables used in the context be cleared at the end of the context to avoid overloading the list of symbolic parameters.

### Masking operation

The masking operation consists of modifying a Super Block in such a way that it resembles a regular block. Double clicking on a masked block, opens a GUI, just as in the case of a regular block (double clicking on a Super Block opens up the diagram contained in the Super Block). The GUI parameters of a masked block are the symbolic parameters needed to evaluate its content. These parameters are identified automatically when the ``Create Mask'' operation is applied to a Super Block.

By choosing to define or not to define in the context various symbolic parameters needed in a Super Block, user can specify the GUI parameters of the block obtained after the masking operation. This is an easy way of constructing custom blocks. The dialog box associated with the block can also be customized using the ``Customize Mask'' operation. Finally, the mask can be removed by the ``Remove Mask'' operation.

### Authors

Ramine Nikoukhah INRIA