Session 8: Defining new Scicos blocks

To define a new block, two functions are required. The first one is the Interfacing function (or GUI function) which determines the graphical properties, parameters, ..., and the name of the computational function. And the computational function which performs the computations required during simulation. The Interfacing function must be a Scilab function, the computational function can be in C, fortran or Scilab language.

How these functions can be defined is discussed in  Inside Scicos. Here we look at a couple of ways of defining new blocks on-line. In these cases, a canonincal Interfacing function is used.

We have seen one way of defining new blocks: compiling a Super Block. If the block is just an immediate funcition (it does not have any state) and has no input or output activation ports, then it can be realized using C or Fortran block in Others palette. These blocks allow for online definition of the computational function respectively in C and fortran language.



Copy Fortran block from the Others palette

Fortran block allow online definition of computational function
In order to use this block, you must have a fortran compiler or an f2c. On MS Windows, you need Visual C++, f2c is included in   the Scilab package.

Click on the block after selecting Open/Set in Object menu
     You can now specify input-output port sizes, block parameters and the name of the fortran function to be used for computational function. 
This block will have 3 scalar inputs and 1 scalar output. forty will be the name of computational function

Scicos now generates the synopsis of forty (calling sequence and the declarations)
The above is automatically generated

The function can now be defined by typing any number of fortran expressions in the above Dialog Panel.


Modify the text as follows

The complete fortran computational function

After clicking on the OK button, forty is compiled and linked automatically, and we are back to Scicos' main window.

Click on OK to get back to the diagram
    The block has now the correct number of input and output  ports. It can be used to in the construction of the diagram.  
The block is now ready to be used

Saving the diagram that contains this block saves the source of the fortran function. When this diagram is loaded later in Scicos, the compilation and incremental linking is done automatically if needed. The icon of the block can of course be changed using Icon in Object menu.

Original Icon
New Icon


The C block works exactly the same way except that the C language is used instead of fortran. As for Scifunc block, same thing except that Scilab expressions are used. In the case of Scifunc, the block can even have discrete and continuous states. 

Ready to go on?
 Yes, I am ready for Session 9
 No, I want to go back 

For more information about Scicos, send an e-mail to Doctor Scilab: Scilab@inria.fr

 
 
For suggestions about this Web server, send an e-mail to Scilab@inria.fr