Exemplo n.º 1
0
/*--------------------------------------------------------------------------*/
int sci_typename_no_rhs(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int numberOfTypes = 0;
    int *TypesNumbers = NULL;

    int m_out1 = 0, n_out1 = 0;

    TypesNumbers = getAllTypesNumber(&numberOfTypes);
    m_out1 = numberOfTypes;
    n_out1 = 1;

    sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 1, m_out1, n_out1, TypesNumbers);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 0;
    }

    if (TypesNumbers)
    {
        FREE(TypesNumbers);
        TypesNumbers = NULL;
    }
    LhsVar(1) = Rhs + 1;

    if (Lhs > 1)
    {
        int m_out2 = 0, n_out2 = 0;
        char **TypesNames = NULL;

        TypesNames = getAllTypesName(&numberOfTypes);
        m_out2 = numberOfTypes;
        n_out2 = 1;

        sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, m_out2, n_out2,
                                      (const char *const *)TypesNames);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }

        if (TypesNames)
        {
            freeArrayOfString(TypesNames, numberOfTypes);
        }
        LhsVar(2) = Rhs + 2;
    }
    PutLhsVar();

    return 0;
}
Exemplo n.º 2
0
int returnIntegerMatrixToScilab(int itemPos, int rows, int cols, int *dest)
{
	SciErr sciErr;
	//same steps as above
	sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + itemPos, rows, cols, dest);
	if (sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 1;
	}

	AssignOutputVariable(pvApiCtx, itemPos) = nbInputArgument(pvApiCtx)+itemPos;

	return 0;
}
Exemplo n.º 3
0
int ScilabGateway::getEnvId(char * fname, const int envId, void * pvApiCtx)
{
    SciErr sciErr;

    CheckInputArgument(pvApiCtx, 0, 0);
    CheckOutputArgument(pvApiCtx, 1, 1);

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
    ScilabGatewayOptions & options = env.getGatewayOptions();
    OptionsHelper::setCopyOccurred(false);
    ScilabObjects::initialization(env, pvApiCtx);
    options.setIsNew(false);

    sciErr = createMatrixOfInteger32(pvApiCtx, 1, 1, 1, &envId);
    if (sciErr.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot create the identifier"));
    }

    LhsVar(1) = 1;
    PutLhsVar();

    return 0;
}
int read_integer(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    //output variable info
    int iRows8					= 0;
    int iCols8					= 0;
    int iRows16					= 0;
    int iCols16					= 0;
    int iRows32					= 0;
    int iCols32					= 0;
    int iRowsu8					= 0;
    int iColsu8					= 0;
    int iRowsu16				= 0;
    int iColsu16				= 0;
    int iRowsu32				= 0;
    int iColsu32				= 0;
    int iPrec					= 0;
    int* piAddr8				= NULL;
    int* piAddr16				= NULL;
    int* piAddr32				= NULL;
    int* piAddru8				= NULL;
    int* piAddru16				= NULL;
    int* piAddru32				= NULL;
    char* pcData				= NULL;
    short* psData				= NULL;
    int* piData					= NULL;
    unsigned char* pucData		= NULL;
    unsigned short* pusData		= NULL;
    unsigned int* puiData		= NULL;
    char* pcDataOut				= NULL;
    short* psDataOut			= NULL;
    int* piDataOut				= NULL;
    unsigned char* pucDataOut	= NULL;
    unsigned short* pusDataOut	= NULL;
    unsigned int* puiDataOut	= NULL;

    //check input/output arguments count
    CheckInputArgument(pvApiCtx, 6, 6);
    CheckOutputArgument(pvApiCtx, 6, 6);

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr8);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddru8);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr16);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddru16);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr32);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddru32);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr8, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT8)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru8, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT8)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr16, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT16)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru16, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT16)
    {
        printError(&sciErr, 0);
        return 0;
    }
    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr32, &iPrec);
    if (sciErr.iErr || iPrec != SCI_INT32)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //check variable precision
    sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddru32, &iPrec);
    if (sciErr.iErr || iPrec != SCI_UINT32)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, piAddru8, &iRowsu8, &iColsu8, &pucData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger16(pvApiCtx, piAddr16, &iRows16, &iCols16, &psData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, piAddru16, &iRowsu16, &iColsu16, &pusData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfInteger32(pvApiCtx, piAddr32, &iRows32, &iCols32, &piData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //retrieve dimensions and data
    sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, piAddru32, &iRowsu32, &iColsu32, &puiData);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //alloc and fill new variable
    pcDataOut   = (char*)create_output(2, 1, iRows8, iCols8, (void*)pcData);
    pucDataOut  = (unsigned char*)create_output(4, 1, iRowsu8, iColsu8, (void*)pucData);
    psDataOut   = (short*)create_output(8, 2, iRows16, iCols16, (void*)psData);
    pusDataOut  = (unsigned short*)create_output(16, 2, iRowsu16, iColsu16, (void*)pusData);
    piDataOut   = (int*)create_output(32, 4, iRows32, iCols32, (void*)piData);
    puiDataOut  = (unsigned int*)create_output(64, 4, iRowsu32, iColsu32, (void*)puiData);

    //create new variable
    sciErr = createMatrixOfInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows8, iCols8, pcDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 2, iRowsu8, iColsu8, pucDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 3, iRows16, iCols16, psDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 4, iRowsu16, iColsu16, pusDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 5, iRows32, iCols32, piDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    //create new variable
    sciErr = createMatrixOfUnsignedInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 6, iRowsu32, iColsu32, puiDataOut);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    FREE(pcDataOut);
    FREE(pucDataOut);
    FREE(psDataOut);
    FREE(pusDataOut);
    FREE(piDataOut);
    FREE(puiDataOut);


    //assign allocated variables to Lhs position
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
    AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
    AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
    AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
    return 0;
}
int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *matVariable, int * parent, int item_position)
{
    int nbRow, nbCol, i;
    SciErr sciErr;
    char * tmp_int8 = NULL;
    short * tmp_int16 = NULL;
    int * tmp_int32 = NULL;
    int *piDims = NULL;
    unsigned char * tmp_uint8 = NULL;
    unsigned short * tmp_uint16 = NULL;
    unsigned int * tmp_uint32 = NULL;
#ifdef __SCILAB_INT64__
    long long * tmp_int64 = NULL;
    unsigned long long * tmp_uint64 = NULL;
#endif
    int iSize = 0;

    // Matrix dimensions
    nbRow = (int)matVariable->dims[0];
    nbCol = (int)matVariable->dims[1];
    iSize = nbRow * nbCol;

    if (iSize == 0)
    {
        double dblReal = 0;
        SciErr sciErr = createMatrixOfDouble(pvApiCtx, iVar, 0, 0, &dblReal);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), "CreateIntegerVariable");
            return FALSE;
        }

        return TRUE;
    }

    if (matVariable->rank == 2) /* 2-D array */
    {
        switch (integerType)
        {
            case SCI_INT8:
            {
                tmp_int8 = (char *)MALLOC(iSize * sizeof(char));

                if (tmp_int8 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_int8[i] = ((char *)matVariable->data)[i];
                }

                if (parent == NULL)
                {
                    sciErr = createMatrixOfInteger8(pvApiCtx, iVar, nbRow, nbCol, tmp_int8);
                }
                else
                {
                    sciErr = createMatrixOfInteger8InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_int8);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }

                FREE(tmp_int8);
            }
            break;
            case SCI_INT16:
            {

                tmp_int16 = (short *)MALLOC(iSize * sizeof(short));
                if (tmp_int16 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }

                for (i = 0; i < iSize; i++)
                {
                    tmp_int16[i] = ((short *)matVariable->data)[i];
                }


                if (parent == NULL)
                {
                    sciErr = createMatrixOfInteger16(pvApiCtx, iVar, nbRow, nbCol, tmp_int16);
                }
                else
                {
                    sciErr = createMatrixOfInteger16InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_int16);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }


                FREE(tmp_int16);
            }
            break;
            case SCI_INT32:
            {
                tmp_int32 = (int *)MALLOC(iSize * sizeof(int));

                if (tmp_int32 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }

                for (i = 0; i < iSize; i++)
                {
                    tmp_int32[i] = ((int *)matVariable->data)[i];
                }


                if (parent == NULL)
                {
                    sciErr = createMatrixOfInteger32(pvApiCtx, iVar, nbRow, nbCol, tmp_int32);
                }
                else
                {
                    sciErr = createMatrixOfInteger32InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_int32);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }


                FREE(tmp_int32);
            }
            break;
#ifdef __SCILAB_INT64__
            case SCI_INT64:
            {
                tmp_int64 = (long long *)MALLOC(iSize * sizeof(long long));
                if (tmp_int64 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_int64[i] = ((long long *)matVariable->data)[i];
                }


                if (parent == NULL)
                {
                    sciErr = createMatrixOfInteger64(pvApiCtx, iVar, nbRow, nbCol, tmp_int64);
                }
                else
                {
                    sciErr = createMatrixOfInteger64InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_int64);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }


                FREE(tmp_int64);
            }
            break;
#endif
            case SCI_UINT8:
            {
                tmp_uint8 = (unsigned char *)MALLOC(iSize * sizeof(unsigned char));
                if (tmp_uint8 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_uint8[i] = ((unsigned char *)matVariable->data)[i];
                }


                if (parent == NULL)
                {
                    sciErr = createMatrixOfUnsignedInteger8(pvApiCtx, iVar, nbRow, nbCol, tmp_uint8);
                }
                else
                {
                    sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_uint8);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }


                FREE(tmp_uint8);
            }
            break;
            case SCI_UINT16:
            {
                tmp_uint16 = (unsigned short *)MALLOC(iSize * sizeof(unsigned short));
                if (tmp_uint16 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_uint16[i] = ((unsigned short *)matVariable->data)[i];
                }

                if (parent == NULL)
                {
                    sciErr = createMatrixOfUnsignedInteger16(pvApiCtx, iVar, nbRow, nbCol, tmp_uint16);
                }
                else
                {
                    sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_uint16);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }

                FREE(tmp_uint16);
            }
            break;
            case SCI_UINT32:
            {
                tmp_uint32 = (unsigned int *)MALLOC(iSize * sizeof(unsigned int));
                if (tmp_uint32 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_uint32[i] = ((unsigned int *)matVariable->data)[i];
                }


                if (parent == NULL)
                {
                    sciErr = createMatrixOfUnsignedInteger32(pvApiCtx, iVar, nbRow, nbCol, tmp_uint32);
                }
                else
                {
                    sciErr = createMatrixOfUnsignedInteger32InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_uint32);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }

                FREE(tmp_uint32);
            }
            break;
#ifdef __SCILAB_INT64__
            case SCI_UINT64:
            {
                tmp_uint64 = (unsigned long long *)MALLOC(iSize * sizeof(unsigned long long));
                if (tmp_uint64 == NULL)
                {
                    Scierror(999, _("%s: No more memory.\n"), "CreateIntegerVariable");
                    return FALSE;
                }
                for (i = 0; i < iSize; i++)
                {
                    tmp_uint64[i] = ((unsigned long long *)matVariable->data)[i];
                }

                if (parent == NULL)
                {
                    sciErr = createMatrixOfUnsignedInteger64(pvApiCtx, iVar, nbRow, nbCol, tmp_uint64);
                }
                else
                {
                    sciErr = createMatrixOfUnsignedInteger64InList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, tmp_uint64);
                }

                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 0;
                }


                FREE(tmp_uint64);
            }
            break;
#endif
        }
    }
    else /* Multi-dimension array -> Scilab HyperMatrix */
    {
        piDims = (int*) MALLOC(matVariable->rank * sizeof(int));
        if (piDims == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "CreateBooleanVariable");
            return FALSE;
        }
        for (i = 0; i < matVariable->rank; i++)
        {
            piDims[i] = (int)matVariable->dims[i];
        }

        CreateHyperMatrixVariable(pvApiCtx, iVar, matVariable->class_type, &integerType, &matVariable->rank,
                                  piDims, matVariable , parent, item_position);

        FREE(piDims);
    }

    return TRUE;
}