Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - Русский

Change language to:
English - Français - 日本語 - Português -

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Справка Scilab >> API Scilab > API double functions

API double functions

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

scilabVar scilab_createEmptyMatrix( scilabEnv env)

Create an empty matrix.

scilabVar scilab_createDoubleMatrix( scilabEnv env, int dim, const int* dims, int complex)

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

complex: 0 to real matrix or 1 to complex matrix

scilabVar scilab_createDoubleMatrix2d( scilabEnv env, int row, int col, int complex)

Create a double matrix with 2 dimensions (row, col).

complex: 0 to real matrix or 1 to complex matrix

scilabVar scilab_createDouble( scilabEnv env, double real)

Create a scalar double.

scilabVar scilab_createDoubleComplex( scilabEnv env, double real, double img)

Create a scalar complex double.

scilabStatus scilab_getDoubleArray( scilabEnv env, scilabVar var, double** real)

Get pointer on internal array of double of var.

scilabStatus scilab_getDoubleComplexArray( scilabEnv env, scilabVar var, double** real, double** img)

Get pointers on internal arrays of double of var.

scilabStatus scilab_getDouble( scilabEnv env, scilabVar var, double* real)

Get double value from an scalar double variable.

scilabStatus scilab_getDoubleComplex( scilabEnv env, scilabVar var, double* real, double* img)

Get double values from an scalar double variable.

scilabStatus scilab_setDoubleArray( scilabEnv env, scilabVar var, const double* real)

Set values of double variable var.

scilabStatus scilab_setDoubleComplexArray( scilabEnv env, scilabVar var, const double* real, const double* img)

Set values of complex double variable var.

scilabStatus scilab_setDouble( scilabEnv env, scilabVar var, double real)

Set value of a scalar double variable var.

scilabStatus scilab_setDoubleComplex( scilabEnv env, scilabVar var, double real, double img)

Set values of a scalar complex double variable var.

Examples

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

const char fname[] = "double_test";

int sci_double_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;
    double* in1 = NULL;

    double in2 = 0;

    double* out1 = NULL;

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

    double out3 = 0;

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

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

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

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

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

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

    //out1 : matrix 2d of double with same size of in[0]
    out[0] = scilab_createDoubleMatrix2d(env, inr1, inc1, 0);
    scilab_getDoubleArray(env, out[0], &out1);

    for (i = 0; i < size1; ++i)
    {
        out1[i] = in1[i] * 10;
    }

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

    out[1] = scilab_createDoubleMatrix(env, 3, out2dims, 0);
    scilab_getDoubleArray(env, out[1], &out2);

    for (i = 0; i < size1; ++i)
    {
        out2[i] = in1[i] * 10;
        out2[i + size1] = in1[i] * 100;
    }

    //out3 : double
    out[2] = scilab_createDouble(env, in2 * 1000);
    return SCILAB_OK;
}

Scilab test script

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

ilib_build("libdouble", ["double_test","sci_double_test", "csci6"],"double_test.c",[],"","","");
exec("loader.sce");

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

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

assert_checkequal(out1, in1 * 10);
ref(:,:, 1) = in1 * 10;
ref(:,:, 2) = in1 * 100;
assert_checkequal(out2, ref);
assert_checkequal(out3, in2 * 1000);
disp("OK");
Report an issue
<< Getting started with API_Scilab API Scilab API common functions >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:40:13 CET 2022