1 <?xml version="1.0" encoding="UTF-8"?>
5 * Copyright (C) INRIA - METALAU Project <scicos@inria.fr> (HTML version)
6 * Copyright (C) DIGITEO - Scilab Consortium (XML Docbook version)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * See the file ./license.txt
24 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="C_struct">
26 <refname>C_struct</refname>
27 <refpurpose>C Block structure of a computational function</refpurpose>
30 <title>Description</title>
33 <refsection id="Contents_C_struct">
34 <title>Contents</title>
38 <link linkend="C_struct">C_struct - C Block structure of a computational function</link>
45 <xref linkend="Module_C_struct">Module</xref>
50 <xref linkend="Description_C_struct">Description</xref>
55 <xref linkend="Inputsoutputs_C_struct">Inputs/outputs</xref>
60 <xref linkend="Events_C_struct">Events</xref>
65 <xref linkend="Parameters_C_struct">Parameters</xref>
70 <xref linkend="Statesandwork_C_struct">States and work</xref>
75 <xref linkend="Zerocrossingsurfacesandmodes_C_struct">Zero crossing surfaces and modes</xref>
80 <xref linkend="Miscallaneous_C_struct">Miscallaneous</xref>
87 <refsection id="Module_C_struct">
92 <link linkend="xcos">xcos</link>
97 <refsection id="Description_C_struct">
98 <title>Description</title>
100 The C structure of a Scicos block defines all the fields to handle data provided by the simulator
101 such inputs/outputs, parameters, states, ...
104 That structure of type <literal>scicos_block</literal> is defined in the file scicos_block4.h, and user must include that header in each computational functions in the form :
110 The fields, that can be either C pointers or directly data, are then accessible via the <literal>*block</literal>
117 This access is a approach and most of users should prefer the approach for facilities purpose.
120 In the current version of Scicos, the <literal>scicos->block</literal> structure is defined :
129 <refsection id="Inputsoutputs_C_struct">
130 <title>Inputs/outputs</title>
137 <emphasis role="bold">block->nin :</emphasis> Integer that gives the number of regular input ports of the block.
139 <para> One can't override the index when reading sizes of input ports in the array and the index when reading data in the array with a C computational function.</para>
140 <para> The number of regular input ports can also be got by the use of the C macros . </para>
144 <emphasis role="bold">block->insz :</emphasis> An array of integers of size that respectively gives the first dimensions, the second dimensions and the type of data driven by regular input ports.
146 <para> Note that this array of size differs from the array and to provide full compatibility with blocks that only use a single dimension.</para>
147 <para> Suppose that you have a block with three inputs : the first is an int32 matrix of size 3,2, the second a single complex number (matrix of size 1,1) and the last a real matrix of size 4,1.</para>
149 In the<link linkend="scicos_model">scicos_model</link> of such a block, the inputs will be defined :
151 <programlisting role="code"><![CDATA[ model.in = [3;1;4]
155 model.intyp = [2;1;3]
159 and the corresponding
161 <programlisting role="code"><![CDATA[block->insz]]></programlisting>
162 <para> field at C computational function level will be
168 Do the difference here in the type numbers defined at the <emphasis role="bold">Scilab level</emphasis> (2,1,3)
169 and the type numbers defined at the <emphasis role="bold">C level</emphasis> (84,11,10). The following table gives
170 the correspondance for all Scicos type:
173 <informaltable border="1" cellpadding="3">
176 <emphasis role="bold">Scilab Type</emphasis>
179 <emphasis role="bold">Scilab Number</emphasis>
182 <emphasis role="bold">C Type</emphasis>
185 <emphasis role="bold">C Number</emphasis>
189 <td align="left">real</td>
190 <td align="left">1</td>
191 <td align="left">double</td>
192 <td align="left">10</td>
195 <td align="left">complex</td>
196 <td align="left">2</td>
197 <td align="left">double</td>
198 <td align="left">11</td>
201 <td align="left">int32</td>
202 <td align="left">3</td>
203 <td align="left">long</td>
204 <td align="left">84</td>
207 <td align="left">int16</td>
208 <td align="left">4</td>
209 <td align="left">short</td>
210 <td align="left">82</td>
213 <td align="left">int8</td>
214 <td align="left">5</td>
215 <td align="left">char</td>
216 <td align="left">81</td>
219 <td align="left">uint32</td>
220 <td align="left">6</td>
221 <td align="left">unsigned long</td>
222 <td align="left">814</td>
225 <td align="left">uint16</td>
226 <td align="left">7</td>
227 <td align="left">unsigned short</td>
228 <td align="left">812</td>
231 <td align="left">uint8</td>
232 <td align="left">8</td>
233 <td align="left">unsigned char</td>
234 <td align="left">811</td>
240 <emphasis role="bold">block->inptr :</emphasis> An array of pointers of size nin,1 that allow to directly acces to the data contained in the regular input matrices.
242 <para> Suppose the previous example (block with three inputs : an int32 matrix of size [3,2], a complex scalar and a real matrix of size [4,1]).</para>
243 <para> contains three pointers, and should be viewed as arrays contained the data for the int32, the real and the complex matrices :
247 For i.e., to directly access to the data, the user can use theses instructions :
250 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
255 SCSCOMPLEX_COP *ptr_dc;
261 SCSINT32_COP cumsum_i=0;
266 void mycomputfunc(scicos_block *block,int flag)
269 /*get the ptrs of the first int32 regular input port*/
271 ptr_i = (SCSINT32_COP *) block->inptr[0];
272 /*get the ptrs of the second complex regular input port*/
274 ptr_dc = (SCSCOMPLEX_COP *) block->inptr[1];
275 /*get the ptrs of the third real regular input port*/
277 ptr_d = (SCSREAL_COP *) block->inptr[2];
279 /*get the dimension of the first int32 regular input port*/
285 /*compute the cumsum of the input int32 matrix*/
287 for(i=0;i<n1*m1;i++) {
289 cumsum_i += ptr_i[i];
296 One can also use the set of C macros :
299 <programlisting role="code"><![CDATA[GetInPortPtrs(blk,x)]]></programlisting>
301 <programlisting role="code"><![CDATA[GetRealInPortPtrs(block,x)]]></programlisting>
305 <programlisting role="code"><![CDATA[GetImagInPortPtrs(block,x)]]></programlisting>
307 <programlisting role="code"><![CDATA[Getint8InPortPtrs(block,x)]]></programlisting>
311 <programlisting role="code"><![CDATA[Getint16InPortPtrs(block,x)]]></programlisting>
313 <programlisting role="code"><![CDATA[Getint32InPortPtrs(block,x)]]></programlisting>
317 <programlisting role="code"><![CDATA[Getuint8InPortPtrs(block,x)]]></programlisting>
319 <programlisting role="code"><![CDATA[Getuint16InPortPtrs(block,x)]]></programlisting>
323 <programlisting role="code"><![CDATA[Getuint32InPortPtrs(block,x)]]></programlisting>
327 to have the appropriate pointer of the data to handle and
330 <programlisting role="code"><![CDATA[GetNin(block)]]></programlisting>
332 <programlisting role="code"><![CDATA[GetInPortRows(block,x)]]></programlisting>
336 <programlisting role="code"><![CDATA[GetInPortCols(block,x)]]></programlisting>
338 <programlisting role="code"><![CDATA[GetInPortSize(block,x,y)]]></programlisting>
342 <programlisting role="code"><![CDATA[GetInType(block,x)]]></programlisting>
344 <programlisting role="code"><![CDATA[GetSizeOfIn(block,x)]]></programlisting>
348 to handle number, dimensions and type of regular input ports.
349 (<emphasis role="bold">x is numbered from 1 to nin and y numbered from 1 to 2</emphasis>).
352 For the previous example that gives :
355 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
360 SCSCOMPLEX_COP *ptr_dc;
366 SCSINT32_COP cumsum_i=0;
371 void mycomputfunc(scicos_block *block,int flag)
374 /*get the ptrs of the first int32 regular input port*/
376 ptr_i = Getint32InPortPtrs(block,1);
377 /*get the ptrs of the second complex regular input port*/
379 ptr_dc = GetRealInPortPtrs(block,2);
380 /*get the ptrs of the third real regular input port*/
382 ptr_d = GetRealInPortPtrs(block,3);
384 /*get the dimension of the first int32 regular input port*/
386 n1=GetInPortRows(block,1);
388 m1=GetInPortCols(block,1);
394 Finally note that the regular input port registers are only accessible for reading.
399 <emphasis role="bold">block->nout :</emphasis> Integer that gives the number of regular output ports of the block.
401 <para> One can't override the index when reading sizes of output ports in the array and the index when reading data in the array with a C computational function.</para>
402 <para> The number of regular output ports can also be got by the use of the C macros . </para>
406 <emphasis role="bold">block->outsz :</emphasis> An array of integers of size that respectively gives the first dimensions, the second dimensions and the type of data driven by regular output ports.
408 <para> Note that this array of size differs from the array and to provide full compatibility with blocks that only use a single dimension.</para>
409 <para> Suppose that you have a block with two outputs : the first is an int32 matrix of size 3,2, the second a single complex number (matrix of size 1,1) and the last a real matrix of size 4,1.</para>
411 In the<link linkend="scicos_model">scicos_model</link> of such a block, the outputs will be defined :
413 <programlisting role="code"><![CDATA[ model.out = [3;1;4]
417 model.outtyp = [2;1;3]
421 and the corresponding
423 <programlisting role="code"><![CDATA[block->outsz]]></programlisting>
424 <para> field at C computational function level will be
430 Do the difference here in the type numbers defined at the <emphasis role="bold">Scilab level</emphasis> (2,1,3)
431 and the type numbers defined at the <emphasis role="bold">C level</emphasis> (84,11,10) and please report to the
432 previous table to have the correspondence for all Scicos type.
437 <emphasis role="bold">block->outptr :</emphasis> An array of pointers of size nout,1 that allow to directly acces to the data contained in the regular output matrices.
439 <para> Suppose the previous example (block with three outputs : an int32 matrix of size [3,2], a complex scalar and a real matrix of size [4,1]).</para>
440 <para> contains three pointers, and should be viewed as arrays contained the data for the int32, the real and the complex matrices :
444 For i.e., to directly access to the data, the user can use theses instructions :
447 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
452 SCSCOMPLEX_COP *ptr_dc;
458 SCSINT32_COP cumsum_i=0;
463 void mycomputfunc(scicos_block *block,int flag)
465 /*get the ptrs of the first int32 regular output port*/
467 ptr_i = (SCSINT32_COP *) block->outptr[0];
468 /*get the ptrs of the second complex regular output port*/
470 ptr_dc = (SCSCOMPLEX_COP *) block->outptr[1];
471 /*get the ptrs of the third real regular output port*/
473 ptr_d = (SCSREAL_COP *) block->outptr[2];
475 /*get the dimension of the first int32 regular output port*/
481 /*compute the cumsum of the output int32 matrix*/
483 for(i=0;i<n1*m1;i++) {
485 cumsum_i += ptr_i[i];
492 One can also use the set of C macros :
495 <programlisting role="code"><![CDATA[GetOutPortPtrs(block,x)]]></programlisting>
497 <programlisting role="code"><![CDATA[GetRealOutPortPtrs(block,x)]]></programlisting>
501 <programlisting role="code"><![CDATA[GetImagOutPortPtrs(block,x)]]></programlisting>
503 <programlisting role="code"><![CDATA[Getint8OutPortPtrs(block,x)]]></programlisting>
507 <programlisting role="code"><![CDATA[Getint16OutPortPtrs(block,x)]]></programlisting>
509 <programlisting role="code"><![CDATA[Getint32OutPortPtrs(block,x)]]></programlisting>
513 <programlisting role="code"><![CDATA[Getuint8OutPortPtrs(block,x)]]></programlisting>
515 <programlisting role="code"><![CDATA[Getuint16OutPortPtrs(block,x)]]></programlisting>
519 <programlisting role="code"><![CDATA[Getuint32OutPortPtrs(block,x)]]></programlisting>
523 to have the appropriate pointer of the data to handle and
526 <programlisting role="code"><![CDATA[GetNout(block)]]></programlisting>
528 <programlisting role="code"><![CDATA[GetOutPortRows(block,x)]]></programlisting>
532 <programlisting role="code"><![CDATA[GetOutPortCols(block,x)]]></programlisting>
534 <programlisting role="code"><![CDATA[GetOutPortSize(block,x,y)]]></programlisting>
538 <programlisting role="code"><![CDATA[GetOutType(block,x)]]></programlisting>
540 <programlisting role="code"><![CDATA[GetSizeOfOut(block,x)]]></programlisting>
544 to handle number, dimensions and type of regular output ports.
545 (<emphasis role="bold">x is numbered from 1 to nout and y is numbered from 1 to 2</emphasis>).
547 For the previous example that gives :
550 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
555 SCSCOMPLEX_COP *ptr_dc;
561 SCSINT32_COP cumsum_i=0;
566 void mycomputfunc(scicos_block *block,int flag)
569 /*get the ptrs of the first int32 regular output port*/
571 ptr_i = GetOutPortPtrs(block,1);
572 /*get the ptrs of the second complex regular output port*/
574 ptr_dc = GetRealOutPortPtrs(block,2);
575 /*get the ptrs of the third real regular output port*/
577 ptr_d = GetRealOutPortPtrs(block,3);
579 /*get the dimension of the first int32 regular output port*/
581 n1=GetOutPortRows(block,1);
583 m1=GetOutPortCols(block,1);
589 Finally note that the regular output port registers must be only written for
591 <programlisting role="code"><![CDATA[flag]]></programlisting>
599 <refsection id="Events_C_struct">
600 <title>Events</title>
607 <emphasis role="bold">block->nevprt :</emphasis> Integer that gives the event input port number by which the block has been activated. This number is a binary coding. For i.e, if block has two event inputs ports, can take the value 1 if the block has been called by its first event input port, the value 2 if it has been called by the second event input port and 3 if it is called by the same event on both input port 1 and 2.
609 <para> Note that can be -1 if the block is internally called.</para>
610 <para> One can also retrieve this number by using the C macros . </para>
614 <emphasis role="bold">block->nevout :</emphasis> Integer that gives the number of event output ports of the block (also called the length of the output event register).
616 <para> One can't override the index when setting value of events in the output event register .</para>
617 <para> The number of event output ports can also be got by the use of the C macro . </para>
621 <emphasis role="bold">block->evout :</emphasis> Array of double of size nevout,1 corresponding to the output event register. That register is used to program date of events during the simulation.
623 <para> When setting values in that array, you must understand that you give a delay relative to the current time of simulator :</para>
628 <imagedata fileref="../../../images/C_struct_img6_eng.gif" align="center" valign="middle"/>
631 is the date of the programmed event,
634 <imagedata fileref="../../../images/C_struct_img7_eng.gif" align="center" valign="middle"/>
637 is the current time in the simulator and
640 <imagedata fileref="../../../images/C_struct_img8_eng.gif" align="center" valign="middle"/>
643 the value that must be informed in the output event register.
644 For i.e, suppose that you want generate an event with the first event output port, 1ms after
645 each calls of the block, then you'll use :
648 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
651 void mycomputfunc(scicos_block *block,int flag)
657 block->evout[0]=0.001;
665 Note that every events generated from output event register will be asynchronous with event
666 coming from event input port (even if you set
668 <programlisting role="code"><![CDATA[block->evout[x]=0]]></programlisting>
672 The event output register must be only written for
674 <programlisting role="code"><![CDATA[flag]]></programlisting>
682 <refsection id="Parameters_C_struct">
683 <title>Arguments</title>
690 <emphasis role="bold">block->nrpar :</emphasis> Integer that gives the length of the real parameter register.
692 <para> One can't override the index when reading value of real parameters in the register .</para>
693 <para> The total number of real parameters can also be got by the use of the C macro . </para>
697 <emphasis role="bold">block->rpar :</emphasis> Array of double of size nrpar,1 corresponding to the real parameter register. That register is used to pass real parameters coming from the scilab/scicos environment to your block model.
699 <para> The C type of that array is (or C scicos type ).</para>
701 Suppose that you have defined the following real parameters in the<link linkend="scicos_model">scicos_model</link> of a block :
703 <programlisting role="code"><![CDATA[ model.rpar = [%pi;%pi/2;%pi/4]
707 you can retrieve the previous data in the C computational function with :
710 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
720 void mycomputfunc(scicos_block *block,int flag)
723 /*get the first value of the real param register*/
726 /*get the second value of the real param register*/
728 PI_2 = block->rpar[1];
729 /*get the third value of the real param register*/
731 PI_4 = block->rpar[2];
737 You can also use the C macro
739 <programlisting role="code"><![CDATA[GetRparPtrs(block)]]></programlisting>
740 <para> to get the pointer of the
741 real parameter register. For i.e., if we define the following
742 <link linkend="scicos_model">scicos_model</link>
743 in an interfacing function of a
747 <programlisting role="code"><![CDATA[ A = [1.3 ; 4.5 ; 7.9 ; 9.8];
755 in the corresponding C computational function of that block, we'll use :
758 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
768 void mycomputfunc(scicos_block *block,int flag)
771 /*get ptrs of the real param register*/
773 rpar = GetRparPtrs(block);
774 /*get the A ptrs array*/
777 /*get the B ptrs array*/
786 Note that real parameters register is only accessible for reading.
791 <emphasis role="bold">block->nipar :</emphasis> Integer that gives the length of the integer parameter register.
793 <para> One can't override the index when reading value of integer parameters in the register .</para>
794 <para> The total number of integer parameters can also be got by the use of the C macro . </para>
798 <emphasis role="bold">block->ipar :</emphasis> Array of int of size nipar,1 corresponding to the integer parameter register. That register is used to pass integer parameters coming from the scilab/scicos environment to your block model.
800 <para> The C type of that array is (or C scicos type ).</para>
802 Suppose that you have defined the following integer parameters in the<link linkend="scicos_model">scicos_model</link> of a block :
804 <programlisting role="code"><![CDATA[ model.ipar = [(1:3)';5]
808 you can retrieve the previous data in the C computational function with :
811 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
823 void mycomputfunc(scicos_block *block,int flag)
826 /*get the first value of the integer param register*/
828 one = block->ipar[0];
829 /*get the second value of the integer param register*/
831 two = block->ipar[1];
832 /*get the third value of the integer param register*/
834 three = block->ipar[2];
835 /*get the fourth value of the integer param register*/
837 five = block->ipar[3];
843 You can also use the C macro
845 <programlisting role="code"><![CDATA[GetIparPtrs(block)]]></programlisting>
846 <para> to get the pointer of the
847 real parameter register.
850 Most of time in the scicos C block libraries, the integer register is used to
851 parametrize the length of real parameters. For i.e. if you define the following
852 <link linkend="scicos_model">scicos_model</link>
856 <programlisting role="code"><![CDATA[ // set a random size for the first real parameters
858 A_sz = int(rand(10)*10);
859 // set a random size for the second real parameters
861 B_sz = int(rand(10)*10);
862 // set the first real parameters
864 A = rand(A_sz,1,``uniform'');
865 // set the second real parameters
867 B = rand(B_sz,1,``normal'');
870 model.ipar = [A_sz;B_sz]
871 // set rpar (length of A_sz+B_sz)
877 the array of real parameters (parametrized by ipar) can be retrieved in the
878 correspondig C computational function with :
881 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
899 void mycomputfunc(scicos_block *block,int flag)
902 /*get ptrs of the real param register*/
904 rpar = GetRparPtrs(block);
905 /*get size of the first real param register*/
907 A_sz = block->ipar[0];
908 /*get size of the second real param register*/
910 B_sz = block->ipar[1];
911 /*get the A ptrs array*/
914 /*get the B ptrs array*/
918 /*compute the cumsum of the first real parameter array*/
922 for(i=0;i<A_sz;i++) {
927 /*compute the cumsum of the second real parameter array*/
931 for(i=0;i<B_sz;i++) {
938 Note that integer parameters register is only accessible for reading.
943 <emphasis role="bold">block->nopar :</emphasis> Integer that gives the number of the object parameters.
945 <para> One can't override the index when accessing data in the arrays , and in a C computational function.</para>
946 <para> This value is also accessible via the C macro . </para>
950 <emphasis role="bold">block->oparsz :</emphasis> An array of integer of size nopar,2 that contains the dimensions of matrices of object parameters.
952 <para> The first column is for the first dimension and the second for the second dimension. For i.e. if we want the dimensions of the last object parameters, we'll use the instructions :
954 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
962 void mycomputfunc(scicos_block *block,int flag)
965 /*get the number of object parameter*/
969 /*get number of row of the last object parameter*/
971 n=block>oparsz[nopar-1];
972 /*get number of column of the last object parameter*/
974 m=block>oparsz[2*nopar-1];
980 The dimensions of object parameters can be get with the following C macro :
983 <programlisting role="code"><![CDATA[ GetOparSize(block,x,1); /*get first dimension of opar*/
985 GetOparSize(block,x,2); /*get second dimension of opar*/
991 <programlisting role="code"><![CDATA[x]]></programlisting>
993 an integer that gives the index of the object parameter, <emphasis role="bold">numbered
1001 <emphasis role="bold">block->opartyp :</emphasis> An array of integer of size nopar,1 that contains the type of matrices of object parameters.
1003 <para> The following table gives the correspondence for scicos type expressed in Scilab number, in C number and also corresponding C pointers and C macros used for :
1005 The type of object parameter can also be got by the use of the C macro
1007 <programlisting role="code"><![CDATA[GetOparType(block,x)]]></programlisting>
1008 <para>. For i.e, if we want the C number type of the first
1009 object parameter, we'll use the following C instructions:
1012 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1018 void mycomputfunc(scicos_block *block,int flag)
1021 /*get the number type of the first object parameter*/
1023 opartyp_1 = GetOparType(block,1);
1026 ]]></programlisting>
1032 <emphasis role="bold">block->oparptr :</emphasis> An array of pointers of size nopar,1 that allow to directly acces to the data contained in the object parameter.
1035 Suppose that you have defined in the editor a block with the following<emphasis role="bold">opar</emphasis> field in<link linkend="scicos_model">scicos_model</link> :
1037 <programlisting role="code"><![CDATA[model.opar=list(int32([1,2;3,4]),[1+%i %i 0.5]);]]></programlisting>
1040 Then we have two object parameters, one is an 32-bit integer matrix with two rows and two
1041 columns and the second is a vector of complex numbers that can be understand as a matrix
1045 At the C computational function level, the instructions
1047 <programlisting role="code"><![CDATA[block->oparsz[0]]]></programlisting>
1050 <programlisting role="code"><![CDATA[block->oparsz[1]]]></programlisting>
1052 <programlisting role="code"><![CDATA[block->oparsz[2]]]></programlisting>
1054 <programlisting role="code"><![CDATA[block->oparsz[3]]]></programlisting>
1055 <para> will respectively return the
1056 values 2,1,2,3 and the instructions </para>
1057 <programlisting role="code"><![CDATA[block->opartyp[0]]]></programlisting>
1059 <programlisting role="code"><![CDATA[block->opartyp[1]]]></programlisting>
1060 <para> the values 11 and
1064 <programlisting role="code"><![CDATA[block->oparptr]]></programlisting>
1065 <para> will contain then two pointers, and should be viewed as arrays contained data of
1066 object parameter as shown in the following figure :
1071 For i.e., to directly access to the data, the user can use theses instructions :
1074 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1077 SCSINT32_COP *ptr_i;
1079 SCSINT32_COP cumsum_i;
1081 SCSCOMPLEX_COP *ptr_d;
1083 SCSREAL_COP cumsum_d;
1086 void mycomputfunc(scicos_block *block,int flag)
1089 /*get the ptrs of an int32 object parameter*/
1091 ptr_i = (SCSINT32_COP *) block->oparptr[0];
1092 /*get the ptrs of a double object parameter*/
1094 ptr_d = (SCSCOMPLEX_COP *) block->oparptr[1];
1096 /*compute the cumsum of the int32 matrix*/
1098 cumsum_i = ptr_i[0]+ptr_i[1]+ptr_i[2]+ptr_i[3];
1100 /*compute the cumsum of the real part of the complex matrix*/
1102 cumsum_d = ptr_d[0]+ptr_d[1]+ptr_d[2];
1105 ]]></programlisting>
1108 One can also use the set of C macros :
1111 <programlisting role="code"><![CDATA[GetRealOparPtrs(block,x)]]></programlisting>
1113 <programlisting role="code"><![CDATA[GetImagOparPtrs(block,x)]]></programlisting>
1117 <programlisting role="code"><![CDATA[Getint8OparPtrs(block,x)]]></programlisting>
1119 <programlisting role="code"><![CDATA[Getint16OparPtrs(block,x)]]></programlisting>
1123 <programlisting role="code"><![CDATA[Getint32OparPtrs(block,x)]]></programlisting>
1125 <programlisting role="code"><![CDATA[Getuint8OparPtrs(block,x)]]></programlisting>
1129 <programlisting role="code"><![CDATA[Getuint16OparPtrs(block,x)]]></programlisting>
1131 <programlisting role="code"><![CDATA[Getuint32OparPtrs(block,x)]]></programlisting>
1135 to have the appropriate pointer of the data to handle (<emphasis role="bold">x is numbered from 1 to nopar</emphasis>).
1138 For the previous example that gives :
1141 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1144 SCSINT32_COP *ptr_i;
1146 SCSREAL_COP *ptr_dr;
1148 SCSREAL_COP *ptr_di;
1151 void mycomputfunc(scicos_block *block,int flag)
1154 /*get the ptrs of an int32 object parameter*/
1156 ptr_i = Getint32OparPtrs(block,1);
1157 /*get the ptrs of a double object parameter*/
1159 ptr_dr = GetRealOparPtrs(block,2);
1161 ptr_di = GetImagOparPtrs(block,2);
1164 ]]></programlisting>
1167 Note that object parameters register is only accessible for reading.
1175 <refsection id="Statesandwork_C_struct">
1176 <title>States and work</title>
1183 <emphasis role="bold">block->nx :</emphasis> Integer that gives the length of the continus state register.
1185 <para> One can't override the index when reading or writing data in the array , or with a C computational function. </para>
1189 <emphasis role="bold">block->x :</emphasis> Array of double of size nx,1 corresponding to the continuous state register.
1191 <para> That gives the result of the computation of the state derivative.</para>
1192 <para> A value of a continuous state is readable (for i.e the first state) with the C instructions :
1194 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1200 void mycomputfunc(scicos_block *block,int flag)
1207 ]]></programlisting>
1212 <programlisting role="code"><![CDATA[flag]]></programlisting>
1213 <para>=4, user can write some initial conditions in that register.
1216 The pointer of that array can also be retrieve via the C macro
1218 <programlisting role="code"><![CDATA[GetState(block)]]></programlisting>
1224 <emphasis role="bold">block->xd :</emphasis> Array of double of size nx,1 corresponding to the derivative of the continuous state register.
1226 <para> When systems are explicitly given in terms of Ordinary Differential Equations (ODE), it can be explicitly expressed or implicitly used in the residual vector when systems are expressed in terms of Differantial Algebraic Equations (DAE).</para>
1227 <para> Both systems must be programmed with .</para>
1228 <para> For i.e the Lorentz attractor written as an ODE system with three state variables, of the form :
1233 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1236 double *x = block->x;
1238 double *xd = block->xd;
1240 /* define parameters */
1249 void mycomputfunc(scicos_block *block,int flag)
1255 xd[0] = a*(x[1]-x[0]);
1257 xd[1] = x[1]*(b-x[2])-x[1];
1259 xd[2] = x[0]*x[1]-c*x[2];
1263 ]]></programlisting>
1269 <emphasis role="bold">block->res :</emphasis> Array of double of size nx,1 corresponding to Differential Algebraic Equation (DAE) residual.
1271 <para> It is used to write the vector of systems that have the following form :</para>
1272 <para> For i.e the Lorentz attractor written as a DAE system with three state variables, will be defined :
1274 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1277 double *x = block->x;
1279 double *xd = block->xd;
1281 double *res = block->res;
1283 /* define parameters */
1292 void mycomputfunc(scicos_block *block,int flag)
1298 res[0] = - xd[0] + (a*(x[1]-x[0]));
1300 res[1] = - xd[1] + (x[0]*(b-x[2])-x[1]);
1302 res[2] = - xd[2] + (x[0]*x[1]-c*x[2]);
1306 ]]></programlisting>
1312 <emphasis role="bold">block->nz :</emphasis> Integer that gives the length of the discrete state register.
1314 <para> One can't override the index when reading data in the array with a C computational function.</para>
1315 <para> This value is also accessible via the C macros . </para>
1319 <emphasis role="bold">block->z :</emphasis> Array of double of size nz,1 corresponding to the discrete state register.
1321 <para> A value of a discrete state is directly readable (for i.e the second state) with the C instructions :
1323 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1329 void mycomputfunc(scicos_block *block,int flag)
1336 ]]></programlisting>
1339 Note that the state register should be only written for
1341 <programlisting role="code"><![CDATA[flag]]></programlisting>
1342 <para>=4 and </para>
1343 <programlisting role="code"><![CDATA[flag]]></programlisting>
1347 The pointer of that array can also be retrieve via the C macro
1349 <programlisting role="code"><![CDATA[GetDstate(block)]]></programlisting>
1355 <emphasis role="bold">block->noz :</emphasis> Integer that gives the number of the discrete object states.
1357 <para> One can't override the index when accessing data in the arrays , and in a C computational function.</para>
1358 <para> This value is also accessible via the C macro . </para>
1362 <emphasis role="bold">block->ozsz :</emphasis> An array of integer of size noz,2 that contains the dimensions of matrices of discrete object states.
1364 <para> The first column is for the first dimension and the second for the second dimension. For i.e. if we want the dimensions of the last object state, we'll use the instructions :
1366 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1373 /*get the number of object state*/
1378 void mycomputfunc(scicos_block *block,int flag)
1381 /*get number of row of the last object state*/
1383 n=block>ozsz[noz-1];
1384 /*get number of column of the last object state*/
1386 m=block>ozsz[2*noz-1];
1389 ]]></programlisting>
1392 The dimensions of object discrete states can be get with the following C macro :
1395 <programlisting role="code"><![CDATA[ GetOzSize(block,x,1); /*get first dimension of oz*/
1397 GetOzSize(block,x,2); /*get second dimension of oz*/
1398 ]]></programlisting>
1403 <programlisting role="code"><![CDATA[x]]></programlisting>
1405 an integer that gives the index of the discrete object state, <emphasis role="bold">numbered
1413 <emphasis role="bold">block->oztyp :</emphasis> An array of integer of size noz,1 that contains the type of matrices of discrete object states.
1415 <para> The following table gives the correspondence table for scicos type expressed in Scilab number, in C number and also corresponding C pointers and C macros used for :
1417 The type of discrete object state can also be got by the use of the C macro
1419 <programlisting role="code"><![CDATA[GetOzType(block,x)]]></programlisting>
1420 <para>. For i.e, if we want the C number type of the first
1421 discrete object state, we'll use the following C instructions:
1424 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1430 void mycomputfunc(scicos_block *block,int flag)
1433 /*get the number type of the first object state*/
1435 oztyp_1 = GetOzType(block,1);
1438 ]]></programlisting>
1444 <emphasis role="bold">block->ozptr :</emphasis> An array of pointers of size noz,1 that allow to directly acces to the data contained in the discrete object state.
1447 Suppose that you have defined in the editor a block with the following<emphasis role="bold">odstate</emphasis> field in <link linkend="scicos_model">scicos_model</link> :
1449 <programlisting role="code"><![CDATA[model.odstate=list(int32([1,2;3,4]),[1+%i %i 0.5]);]]></programlisting>
1452 Then we have two discrete object states, one is an 32-bit integer matrix with two rows and two
1453 columns and the second is a vector of complex numbers that can be understand as a matrix
1457 At the C computational function level, the instructions
1459 <programlisting role="code"><![CDATA[block->ozsz[0]]]></programlisting>
1462 <programlisting role="code"><![CDATA[block->ozsz[1]]]></programlisting>
1464 <programlisting role="code"><![CDATA[block->ozsz[2]]]></programlisting>
1466 <programlisting role="code"><![CDATA[block->ozsz[3]]]></programlisting>
1467 <para> will respectively return the
1468 values 2,1,2,3 and the instructions </para>
1469 <programlisting role="code"><![CDATA[block->oztyp[0]]]></programlisting>
1471 <programlisting role="code"><![CDATA[block->oztyp[1]]]></programlisting>
1472 <para> the values 11 and
1476 <programlisting role="code"><![CDATA[block->ozptr]]></programlisting>
1477 <para> will contain then two pointers, and should be viewed as arrays contained data of
1478 discrete object state as shown in the following figure :
1483 For i.e., to directly access to the data, the user can use theses instructions :
1486 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1489 SCSINT32_COP *ptr_i;
1491 SCSINT32_COP cumsum_i;
1493 SCSCOMPLEX_COP *ptr_d;
1495 SCSREAL_COP cumsum_d;
1498 void mycomputfunc(scicos_block *block,int flag)
1501 /*get the ptrs of an int32 discrete object state*/
1503 ptr_i = (SCSINT32_COP *) block->ozptr[0];
1504 /*get the ptrs of a double discrete object state*/
1506 ptr_d = (SCSCOMPLEX_COP *) block->ozptr[1];
1508 /*compute the cumsum of the int32 matrix*/
1510 cumsum_i = ptr_i[0]+ptr_i[1]+ptr_i[2]+ptr_i[3];
1512 /*compute the cumsum of the real part of the complex matrix*/
1514 cumsum_d = ptr_d[0]+ptr_d[1]+ptr_d[2];
1517 ]]></programlisting>
1520 One can also use the set of C macros :
1523 <programlisting role="code"><![CDATA[GetRealOzPtrs(block,x)]]></programlisting>
1525 <programlisting role="code"><![CDATA[GetImagOzPtrs(block,x)]]></programlisting>
1529 <programlisting role="code"><![CDATA[Getint8OzPtrs(block,x)]]></programlisting>
1531 <programlisting role="code"><![CDATA[Getint16OzPtrs(block,x)]]></programlisting>
1535 <programlisting role="code"><![CDATA[Getint32OzPtrs(block,x)]]></programlisting>
1537 <programlisting role="code"><![CDATA[Getuint8OzPtrs(block,x)]]></programlisting>
1541 <programlisting role="code"><![CDATA[Getuint16OzPtrs(block,x)]]></programlisting>
1543 <programlisting role="code"><![CDATA[Getuint32OzPtrs(block,x)]]></programlisting>
1547 to have the appropriate pointer of the data to handle (<emphasis role="bold">x is numbered from 1 to noz</emphasis>).
1550 For the previous example that gives :
1553 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1556 SCSINT32_COP *ptr_i;
1558 SCSREAL_COP *ptr_dr;
1560 SCSREAL_COP *ptr_di;
1563 void mycomputfunc(scicos_block *block,int flag)
1566 /*get the ptrs of an int32 discrete object state*/
1568 ptr_i = Getint32OzPtrs(block,1);
1569 /*get the ptrs of a double discrete object state*/
1571 ptr_dr = GetRealOzPtrs(block,2);
1573 ptr_di = GetImagOzPtrs(block,2);
1576 ]]></programlisting>
1579 Finally note that the discrete objects state should be only written for
1581 <programlisting role="code"><![CDATA[flag]]></programlisting>
1582 <para>=4 and </para>
1583 <programlisting role="code"><![CDATA[flag]]></programlisting>
1589 <emphasis role="bold">block->work :</emphasis> A free pointer to set a working array for the block.
1591 <para> The work pointer must be firstly allocated when = 4 and finally be free in the = 5.</para>
1592 <para> Then a basic life cyle of that pointer in a C computational function should be :
1594 <programlisting role="code"><![CDATA[ #include "scicos_block4.h"
1597 void** work=block->work;
1600 void mycomputfunc(scicos_block *block,int flag)
1606 /*allocation of work*/
1608 if (*work=scicos_malloc(sizeof(double))==NULL) {
1610 set_block_error(-16);
1617 /*other flag treatment*/
1627 ]]></programlisting>
1630 Note that if a block use a
1632 <programlisting role="code"><![CDATA[work]]></programlisting>
1633 <para> pointer, it will be called with </para>
1634 <programlisting role="code"><![CDATA[flag]]></programlisting>
1636 the block do not use discrete states.
1639 The pointer of that array can also be retrieve via the C macro
1641 <programlisting role="code"><![CDATA[GetWorkPtrs(block)]]></programlisting>
1649 <refsection id="Zerocrossingsurfacesandmodes_C_struct">
1650 <title>Zero crossing surfaces and modes</title>
1657 <emphasis role="bold">block->ng :</emphasis> Integer that gives the number of zero crossing surface of the block.
1659 <para> One can't override the index when reading/writing data in the array with a C computational function.</para>
1660 <para> The number of zero crossing surface can also be got by the use of the C macro . </para>
1664 <emphasis role="bold">block->g :</emphasis> Array of double of size ng,1 corresponding to the zero crossing surface register.
1666 <para> That register is used to detect zero crossing of state variable during time domain integration.</para>
1667 <para> Note that it is accessible for writing for = 9.</para>
1668 <para> The pointer of that array can also be retrieve via the C macro . </para>
1672 <emphasis role="bold">block->nmode :</emphasis> Integer that gives the number of mode of the block.
1674 <para> One can't override the index when reading/writing data in the array with a C computational function.</para>
1675 <para> The number of mode can also be got by the use of the C macro . </para>
1679 <emphasis role="bold">block->mode :</emphasis> Array of integer of size nmode,1 corresponding to the mode register.
1681 <para> That register is used to set the mode of state variable during time domain integration.</para>
1682 <para> It is typically accessible for writing for = 9.</para>
1683 <para> The pointer of that array can also be retrieve via the C macro . </para>
1690 <refsection id="Miscallaneous_C_struct">
1691 <title>Miscallaneous</title>
1699 <emphasis role="bold">block->type :</emphasis> Integer that gives the type of the computational function. For C blocks, this number is equal to 4.
1704 <emphasis role="bold">block->label :</emphasis> Strings array that allows to retrieve the label of the block.