Boolean management

How to manage Scilab’s boolean read and write process using call_scilab and api_scilab

Description

This help describes how boolean and matrix of booleans can be handle through the `Call Scilab API`_ and api Scilab.

There are several functions which can be used to read / write from the memory of Scilab. These functions are described in dedicated pages.

Note: Access to variables is done through api Scilab (named variable).

Examples

/*
 * Write a `matrix`_ of boolean into Scilab
 * B=[F F T F;
 *    F F F T ]
 * Note that it is done column by column
 */
`int`_ B[]={0,0,0,0,1,0,0,1};   /* Declare the `matrix`_ */
`int`_ rowB=2, colB=4; /* Size of the `matrix`_ */
`char`_ variableNameB[] = "B";
SciErr sciErr;

/* Write it into Scilab's memory */
sciErr = createNamedMatrixOfBoolean(pvApiCtx, variableNameB, rowB, colB, B);
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/*
 * Prior to Scilab 5.2:
 * C2F(cwritebmat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
 */

printf("Display from Scilab of B:\n");
SendScilabJob("disp(B);"); /* Display B */
/* Read the previously declared `matrix`_ of boolean B */
`int`_ rowB_ = 0, colB_ = 0, lp_ = 0;
`int`_ i = 0, j = 0;
`int`_ *matrixOfBooleanB = NULL; /* Int instead of `double`_ */

`char`_ variableToBeRetrievedB[] = "B";
SciErr sciErr;
/* First, retrieve the `size`_ of the matrix */
sciErr = readNamedMatrixOfBoolean(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL);
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/*
 * Prior to Scilab 5.2:
 * C2F(cmatbptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB));
 */

/* Alloc the memory */
matrixOfBooleanB=(`int`_*)malloc((rowB_*colB_)*sizeof(`int`_));

/* Load the `matrix`_ */
sciErr = readNamedMatrixOfBoolean(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfBooleanB);
if(sciErr.iErr)
{
    printError(&sciErr, 0);
}

/*
 * Prior to Scilab 5.2:
 * C2F(creadbmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfBooleanB,strlen(variableToBeRetrievedB) );
 */

printf("\n");
printf("Display from B formated (size: %d, %d):\n",rowB_, colB_);
for(j = 0 ; j < rowB_ ; j++)
{
 for(i = 0 ; i < colB_ ; i++)
 {
  /* Display the formated `matrix`_ ... the way the user expects */
  printf("%d ",matrixOfBooleanB[i * rowB_ + j]);
 }
 printf("\n"); /* New row of the `matrix`_ */
}

See Also

Table Of Contents

This Page