Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - 日本語 -
Справка Scilab >> API Scilab > API boolean functions

API boolean functions

This page lists all the functions to manipulate Scilab native objects containing booleans

scilabVar scilab_createBooleanMatrix( scilabEnv env, int dim, const int* dims)

Create a boolean matrix with dim dimensions (dims[0], dims[1], ..., dims[dim-1]).

scilabVar scilab_createBooleanMatrix2d( scilabEnv env, int row, int col)

Create an boolean matrix with 2 dimensions (row, col).

scilabVar scilab_createBoolean( scilabEnv env, int val)

Create a scalar boolean.

scilabStatus scilab_getBooleanArray( scilabEnv env, scilabVar var, int** vals)

Get pointer on internal array of boolean of var.

scilabStatus scilab_getBoolean( scilabEnv env, scilabVar var, int* val)

Get boolean value from an scalar boolean variable.

scilabStatus scilab_setBooleanArray( scilabEnv env, scilabVar var, const int* vals)

Set values of boolean variable var.

scilabStatus scilab_setBoolean( scilabEnv env, scilabVar var, int val)

Set value of a scalar boolean variable var.

Examples

#include "api_scilab.h"
#include "Scierror.h"
#include "localization.h"
#include "sciprint.h"
#include "sci_malloc.h"

const char fname[] = "boolean_test";

int sci_boolean_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
{
    int i = 0;
    int inr1 = 0;
    int inc1 = 0;
    int size1 = 0;
    int* in1 = NULL;

    int in2 = 0;

    int* out1 = NULL;

    int* out2dims = NULL;
    int* out2 = NULL;

    int out3 = 0;

    if (nin != 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
        return API_ERROR;
    }

    if (nout != 3)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 3);
        return API_ERROR;
    }

    //in[0] : matrix 2d of boolean
    if (scilab_isBoolean(env, in[0]) == 0 || scilab_isMatrix(env, in[0]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A boolean matrix expected.\n"), fname, 1);
        return API_ERROR;
    }

    size1 = scilab_getDim2d(env, in[0], &inr1, &inc1);
    scilab_getBooleanArray(env, in[0], &in1);

    //in[1] : bool
    if (scilab_isBoolean(env, in[1]) == 0 || scilab_isScalar(env, in[1]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
        return API_ERROR;
    }

    scilab_getBoolean(env, in[1], &in2);

    //out1 : matrix 2d of boolean with same size of in[0]
    out[0] = scilab_createBooleanMatrix2d(env, inr1, inc1);
    if (scilab_getBooleanArray(env, out[0], &out1) != <link linkend="api_types_scilabStatus"><command>scilabStatus</command></link>::API_OK)
    {
        Scierror(999, "blabla\n");
        return 1;
    }

    for (i = 0; i < size1; ++i)
    {
        out1[i] = in1[i] == 1 ? 0 : 1;
    }

    //out2 : 3d matrix of boolean
    out2dims = (int*)MALLOC(3 * sizeof(int));
    out2dims[0] = inr1;
    out2dims[1] = inc1;
    out2dims[2] = 2;

    out[1] = scilab_createBooleanMatrix(env, 3, out2dims);
    scilab_getBooleanArray(env, out[1], &out2);

    for (i = 0; i < size1; ++i)
    {
        out2[i] = in1[i];
        out2[i + size1] = in1[i] ? 0 : 1;
    }

    //out3 : bool
    out[2] = scilab_createBoolean(env, in2 ? 0 : 1);
    return API_OK;
}

Scilab test script

mkdir(pathconvert(TMPDIR+"/api_c/"));
cd(pathconvert(TMPDIR+"/api_c/"));
copyfile(SCI+"/modules/api_scilab/tests/unit_tests/api_c/boolean_test.c",pathconvert(TMPDIR+"/api_c/boolean_test.c",%F));

ilib_build("libboolean",["boolean_test","sci_boolean_test", "csci6"],"boolean_test.c",[],"","","");
exec("loader.sce");

in1 = rand(3,4) > 0.5;
in2 = rand() > 0.5;

[out1, out2, out3] = boolean_test(in1, in2);

assert_checkequal(out1, ~in1);
ref(:,:, 1) = in1;
ref(:,:, 2) = out1;
assert_checkequal(out2, ref);
assert_checkequal(out3, ~in2);
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 14 15:13:38 CET 2017