Exemplo n.º 1
0
matvar_t *GetIntegerVariable(void *pvApiCtx, int iVar, const char *name, int * parent, int item_position)
{
    int rank = 0;
    size_t *pszDims = NULL;
    int *piDims = NULL;
    matvar_t *createdVar = NULL;
    int * var_addr = NULL;
    int i;
    int var_type;
    int integerType;
    SciErr sciErr;
    char * tmp_int8 = NULL;
    short * tmp_int16 = NULL;
    int * tmp_int32 = NULL;
    int * item_addr = 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

    if (parent == NULL)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &var_addr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
        sciErr = getVarType(pvApiCtx, var_addr, &var_type);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
    }
    else
    {
        sciErr = getListItemAddress(pvApiCtx, parent, item_position, &item_addr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
        sciErr = getVarType(pvApiCtx, item_addr, &var_type);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
    }

    if (var_type == sci_ints) /* 2-D array */
    {
        rank = 2;
        if ((pszDims = (size_t*)MALLOC(sizeof(size_t) * rank)) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "GetIntegerVariable");
            return NULL;
        }
        if ((piDims = (int*)MALLOC(sizeof(int) * rank)) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "GetIntegerVariable");
            return NULL;
        }

        if (parent == NULL)
        {
            sciErr = getMatrixOfIntegerPrecision(pvApiCtx, var_addr, &integerType);
        }
        else
        {
            sciErr = getMatrixOfIntegerPrecision(pvApiCtx, item_addr, &integerType);
        }

        switch (integerType)
        {
            case SCI_INT8: /* INT8 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfInteger8(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int8);
                }
                else
                {
                    sciErr = getMatrixOfInteger8InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int8);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_INT8, MAT_T_INT8, rank, pszDims, tmp_int8, 0);
                break;
            case SCI_INT16: /* INT16 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfInteger16(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int16);
                }
                else
                {
                    sciErr = getMatrixOfInteger16InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int16);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_INT16, MAT_T_INT16, rank, pszDims, tmp_int16, 0);
                break;
            case SCI_INT32: /* INT32 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfInteger32(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_int32);
                }
                else
                {
                    sciErr = getMatrixOfInteger32InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_int32);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_INT32, MAT_T_INT32, rank, pszDims, tmp_int32, 0);
                break;
            case SCI_UINT8: /* UINT8 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint8);
                }
                else
                {
                    sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint8);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_UINT8, MAT_T_UINT8, rank, pszDims, tmp_uint8, 0);
                break;
            case SCI_UINT16: /* UINT16 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint16);
                }
                else
                {
                    sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint16);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_UINT16, MAT_T_UINT16, rank, pszDims, tmp_uint16, 0);
                break;
            case SCI_UINT32: /* UINT32 */
                if (parent == NULL)
                {
                    sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, var_addr, &piDims[0], &piDims[1], &tmp_uint32);
                }
                else
                {
                    sciErr = getMatrixOfUnsignedInteger32InList(pvApiCtx, parent, item_position, &piDims[0], &piDims[1], &tmp_uint32);
                }

                for (i = 0; i < rank; i++)
                {
                    pszDims[i] = piDims[i];
                }

                createdVar = Mat_VarCreate(name, MAT_C_UINT32, MAT_T_UINT32, rank, pszDims, tmp_uint32, 0);
                break;
            default:
                createdVar = NULL;
                break;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for first input argument: Integer matrix expected.\n"), "GetIntegerVariable");
    }

    FREE(pszDims);
    FREE(piDims);

    return createdVar;
}
Exemplo n.º 2
0
static int serialize_int(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
{
    SciErr sciErr;
    int iPrecision = 0;
    int iRows = 0;
    int iCols = 0;
    int iItemSize = 0;
    void *p = NULL;
    void *pvData = NULL;

    int *piOut = NULL;
    int iOutLen = 0;

    sciErr = getVarDimension(_pvCtx, _piAddr, &iRows, &iCols);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    sciErr = getMatrixOfIntegerPrecision(_pvCtx, _piAddr, &iPrecision);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (iPrecision == SCI_INT8 || iPrecision == SCI_UINT8)
    {
        iItemSize = sizeof(char);
    }
    else if (iPrecision == SCI_INT16 || iPrecision == SCI_UINT16)
    {
        iItemSize = sizeof(short);
    }
    else if (iPrecision == SCI_INT32 || iPrecision == SCI_UINT32)
    {
        iItemSize = sizeof(int);
    }
    /*
        else if(iPrecision == SCI_INT64 || iPrecision == SCI_UINT64)
        {
            iItemSize = sizeof(long long);
        }
    */
    //check and adjust alignement on integer
    iOutLen = iRows * iCols;
    if ((iOutLen * iItemSize) % sizeof(int))
    {
        iOutLen = (iOutLen * iItemSize) / sizeof(int) + 1;
    }
    else
    {
        iOutLen = (iOutLen * iItemSize) / (sizeof(int));
    }

    iOutLen += 4;
    piOut = (int *)MALLOC(iOutLen * sizeof(int *));
    if (piOut == NULL)
    {
        return 1;
    }

    piOut[0] = sci_ints;
    piOut[1] = iRows;
    piOut[2] = iCols;
    piOut[3] = iPrecision;      //precision

    switch (iPrecision)
    {
        case SCI_INT8:
        {
            sciErr = getMatrixOfInteger8(_pvCtx, _piAddr, &iRows, &iCols, (char **)&pvData);
            break;
        }
        case SCI_UINT8:
        {
            sciErr = getMatrixOfUnsignedInteger8(_pvCtx, _piAddr, &iRows, &iCols, (unsigned char **)&pvData);
            break;
        }
        case SCI_INT16:
        {
            sciErr = getMatrixOfInteger16(_pvCtx, _piAddr, &iRows, &iCols, (short **)&pvData);
            break;
        }
        case SCI_UINT16:
        {
            sciErr = getMatrixOfUnsignedInteger16(_pvCtx, _piAddr, &iRows, &iCols, (unsigned short **)&pvData);
            break;
        }
        case SCI_INT32:
        {
            sciErr = getMatrixOfInteger32(_pvCtx, _piAddr, &iRows, &iCols, (int **)&pvData);
            break;
        }
        case SCI_UINT32:
        {
            sciErr = getMatrixOfUnsignedInteger32(_pvCtx, _piAddr, &iRows, &iCols, (unsigned int **)&pvData);
            break;
        }
        /*
            case SCI_INT64 :
            {
                sciErr = getMatrixOfInteger64(_pvCtx, _piAddr, &iRows, &iCols, (long long**)&pvData);
                break;
            }
            case SCI_UINT64 :
            {
                sciErr = getMatrixOfUnsignedInteger64(_pvCtx, _piAddr, &iRows, &iCols, (unsigned long long**)&pvData);
                break;
                }
        */ default:
            FREE(piOut);
            return 1;
    }

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

    p = piOut + 4;
    memcpy(p, pvData, iRows * iCols * iItemSize);
    *_piBuffer = piOut;
    *_piBufferSize = iOutLen;
    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;
}
Exemplo n.º 4
0
/*--------------------------------------------------------------------------*/
SciErr getDimFromVar(void *_pvCtx, int *_piAddress, int *_piVal)
{
    SciErr sciErr;
    sciErr.iErr = 0;
    sciErr.iMsgCount = 0;
    int iType = 0;
    int iRows = 0;
    int iCols = 0;
    double *pdblReal = NULL;

    sciErr = getVarType(_pvCtx, _piAddress, &iType);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument type"), "getDimFromVar");
        return sciErr;
    }

    if (iType == sci_matrix)
    {
        if (isVarComplex(_pvCtx, _piAddress))
        {
            addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Wrong type for argument %d: Real matrix expected.\n"), "getDimFromVar",
                            getRhsFromAddress(_pvCtx, _piAddress));
            return sciErr;
        }

        sciErr = getMatrixOfDouble(_pvCtx, _piAddress, &iRows, &iCols, &pdblReal);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
            return sciErr;
        }

        *_piVal = (int)Max(pdblReal[0], 0);
    }
    else if (iType == sci_ints)
    {
        int iPrec = 0;

        sciErr = getVarDimension(_pvCtx, _piAddress, &iRows, &iCols);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument dimension"), "getDimFromVar");
            return sciErr;
        }

        if (iRows != 1 || iCols != 1)
        {
            addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Wrong size for argument %d: (%d,%d) expected.\n"), "getProcessMode",
                            getRhsFromAddress(_pvCtx, _piAddress), 1, 1);
            return sciErr;
        }

        sciErr = getMatrixOfIntegerPrecision(_pvCtx, _piAddress, &iPrec);
        if (sciErr.iErr)
        {
            addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument precision"), "getDimFromVar");
            return sciErr;
        }

        switch (iPrec)
        {
            case SCI_INT8:
            {
                char *pcData = NULL;

                sciErr = getMatrixOfInteger8(_pvCtx, _piAddress, &iRows, &iCols, &pcData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = pcData[0];
            }
            break;
            case SCI_UINT8:
            {
                unsigned char *pucData = NULL;

                sciErr = getMatrixOfUnsignedInteger8(_pvCtx, _piAddress, &iRows, &iCols, &pucData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = pucData[0];
            }
            break;
            case SCI_INT16:
            {
                short *psData = NULL;

                sciErr = getMatrixOfInteger16(_pvCtx, _piAddress, &iRows, &iCols, &psData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = psData[0];
            }
            break;
            case SCI_UINT16:
            {
                unsigned short *pusData = NULL;

                sciErr = getMatrixOfUnsignedInteger16(_pvCtx, _piAddress, &iRows, &iCols, &pusData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = pusData[0];
            }
            break;
            case SCI_INT32:
            {
                int *piData = NULL;

                sciErr = getMatrixOfInteger32(_pvCtx, _piAddress, &iRows, &iCols, &piData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = piData[0];
            }
            break;
            case SCI_UINT32:
            {
                unsigned int *puiData = NULL;

                sciErr = getMatrixOfUnsignedInteger32(_pvCtx, _piAddress, &iRows, &iCols, &puiData);
                if (sciErr.iErr)
                {
                    addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Unable to get argument data"), "getDimFromVar");
                    return sciErr;
                }
                *_piVal = puiData[0];
            }
            break;
        }
    }
    else
    {
        addErrorMessage(&sciErr, API_ERROR_GET_DIMFROMVAR, _("%s: Wrong type for input argument #%d: A real scalar or an integer scalar expected.\n"),
                        "getDimFromVar", getRhsFromAddress(_pvCtx, _piAddress));
        return sciErr;
    }
    return sciErr;
}
Exemplo n.º 5
0
static bool export_ints(int _iH5File, int *_piVar, char* _pstName)
{
    int iRet = 0;
    void *piData = NULL;
    int iPrec = 0;
    int piDims[2];

    SciErr sciErr = getMatrixOfIntegerPrecision(pvApiCtx, _piVar, &iPrec);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return false;
    }

    switch (iPrec)
    {
        case SCI_INT8 :
            sciErr = getMatrixOfInteger8(pvApiCtx, _piVar, &piDims[0], &piDims[1], (char**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeInteger8Matrix(_iH5File, _pstName, 2, piDims, (char*)piData);
            break;
        case SCI_UINT8 :
            sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, _piVar, &piDims[0], &piDims[1], (unsigned char**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeUnsignedInteger8Matrix(_iH5File, _pstName, 2, piDims, (unsigned char*)piData);
            break;
        case SCI_INT16 :
            sciErr = getMatrixOfInteger16(pvApiCtx, _piVar, &piDims[0], &piDims[1], (short**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeInteger16Matrix(_iH5File, _pstName, 2, piDims, (short*)piData);
            break;
        case SCI_UINT16 :
            sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, _piVar, &piDims[0], &piDims[1], (unsigned short**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeUnsignedInteger16Matrix(_iH5File, _pstName, 2, piDims, (unsigned short*)piData);
            break;
        case SCI_INT32 :
            sciErr = getMatrixOfInteger32(pvApiCtx, _piVar, &piDims[0], &piDims[1], (int**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeInteger32Matrix(_iH5File, _pstName, 2, piDims, (int*)piData);
            break;
        case SCI_UINT32 :
            sciErr = getMatrixOfUnsignedInteger32(pvApiCtx, _piVar, &piDims[0], &piDims[1], (unsigned int**)&piData);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return false;
            }
            iRet = writeUnsignedInteger32Matrix(_iH5File, _pstName, 2, piDims, (unsigned int*)piData);
            break;
        case SCI_INT64 :
            //sciErr = getMatrixOfInteger64(_piVar, &piDims[0], &piDims[1], (long long**)&piData);
            //if(sciErr.iErr)
            //{
            //	printError(&sciErr, 0);
            //	return false;
            //}
            //iRet = writeInteger64Matrix(_iH5File, _pstName, 2, piDims, (long long*)piData);
            //break;
        case SCI_UINT64 :
            //sciErr = getMatrixOfUnsignedInteger64(_piVar, &piDims[0], &piDims[1], (unsigned long long**)&piData);
            //if(sciErr.iErr)
            //{
            //	printError(&sciErr, 0);
            //	return false;
            //}
            //iRet = writeUnsignedInteger64Matrix(_iH5File, _pstName, 2, piDims, (unsigned long long*)piData);
            //break;
        default :
            return 1;
            break;
    }

    if (iRet)
    {
        return false;
    }

    char pstMsg[512];
    sprintf(pstMsg, "int%d (%d x %d)", 8 * iPrec, piDims[0], piDims[1]);
    print_type(pstMsg);
    return true;
}
Exemplo n.º 6
0
int ScilabObjects::isPositiveIntegerAtAddress(int * addr, void * pvApiCtx)
{
    SciErr err;
    int typ = 0, row, col, prec;

    err = getVarDimension(pvApiCtx, addr, &row, &col);
    if (err.iErr)
    {
        return -1;
    }

    if (row != 1 || col != 1)
    {
        return -1;
    }

    err = getVarType(pvApiCtx, addr, &typ);
    if (err.iErr)
    {
        return -1;
    }

    if (typ == sci_ints)
    {
        err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
        if (err.iErr)
        {
            return -1;
        }
        switch (prec)
        {
            case SCI_INT8:
            {
                char * cvalue = 0;
                err = getMatrixOfInteger8(pvApiCtx, addr, &row, &col, &cvalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*cvalue);
            }
            break;
            case SCI_UINT8:
            {
                unsigned char * ucvalue = 0;
                err = getMatrixOfUnsignedInteger8(pvApiCtx, addr, &row, &col, &ucvalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*ucvalue);
            }
            break;
            case SCI_INT16:
            {
                short * svalue = 0;
                err = getMatrixOfInteger16(pvApiCtx, addr, &row, &col, &svalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*svalue);
            }
            break;
            case SCI_UINT16:
            {
                unsigned short * usvalue = 0;
                err = getMatrixOfUnsignedInteger16(pvApiCtx, addr, &row, &col, &usvalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*usvalue);
            }
            break;
            case SCI_INT32:
            {
                int * ivalue = 0;
                err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &ivalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*ivalue);
            }
            break;
            case SCI_UINT32:
            {
                unsigned int * uivalue = 0;
                err = getMatrixOfUnsignedInteger32(pvApiCtx, addr, &row, &col, &uivalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*uivalue);
            }
            break;
#ifdef __SCILAB_INT64__
            case SCI_INT64:
            {
                long long * llvalue = 0;
                err = getMatrixOfInteger64(pvApiCtx, addr, &row, &col, &llvalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*llvalue);
            }
            break;
            case SCI_UINT64:
            {
                unsigned long long * ullvalue = 0;
                err = getMatrixOfUnsignedInteger64(pvApiCtx, addr, &row, &col, &ullvalue);
                if (err.iErr)
                {
                    return -1;
                }
                return (int)(*ullvalue);
            }
            break;
#endif
            default:
                return -1;
        }
    }
    else if (typ == sci_matrix)
    {
        double * dvalue = 0;

        if (isVarComplex(pvApiCtx, addr))
        {
            return -1;
        }

        err = getMatrixOfDouble(pvApiCtx, addr, &row, &col, &dvalue);
        if (err.iErr)
        {
            return -1;
        }

        if (*dvalue - (double)(int)(*dvalue) == 0.0)
        {
            return (int)(*dvalue);
        }
    }

    return -1;
}
Exemplo n.º 7
0
int ScilabObjects::getArgumentId(int * addr, int * tmpvars, const bool isRef, const bool isClass, const int envId, void * pvApiCtx)
{
    SciErr err;
    int typ, row = 0, col = 0, returnId;
    const ScilabAbstractEnvironmentWrapper & wrapper = ScilabEnvironments::getEnvironment(envId).getWrapper();

    err = getVarType(pvApiCtx, addr, &typ);
    if (err.iErr)
    {
        removeTemporaryVars(envId, tmpvars);
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    if (isClass && typ != sci_mlist)
    {
        removeTemporaryVars(envId, tmpvars);
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External Class expected"));
    }

    switch (typ)
    {
        case sci_matrix :
        {
            double * mat = 0;

            if (isVarComplex(pvApiCtx, addr))
            {
                double * imag = 0;
                err = getComplexMatrixOfDouble(pvApiCtx, addr, &row, &col, &mat, &imag);
                if (err.iErr)
                {
                    removeTemporaryVars(envId, tmpvars);
                    throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                }

                returnId = wrap(row, col, mat, imag, wrapper, isRef);
            }
            else
            {
                err = getMatrixOfDouble(pvApiCtx, addr, &row, &col, &mat);
                if (err.iErr)
                {
                    removeTemporaryVars(envId, tmpvars);
                    throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                }

                returnId = wrap<double>(row, col, mat, wrapper, isRef);
            }

            tmpvars[++tmpvars[0]] = returnId;

            return returnId;
        }
        case sci_ints :
        {
            int prec = 0;
            void * ints = 0;

            err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
            if (err.iErr)
            {
                removeTemporaryVars(envId, tmpvars);
                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
            }

            switch (prec)
            {
                case SCI_INT8 :
                    err = getMatrixOfInteger8(pvApiCtx, addr, &row, &col, (char**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<char>(row, col, static_cast<char *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_UINT8 :
                    err = getMatrixOfUnsignedInteger8(pvApiCtx, addr, &row, &col, (unsigned char**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<unsigned char>(row, col, static_cast<unsigned char *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_INT16 :
                    err = getMatrixOfInteger16(pvApiCtx, addr, &row, &col, (short**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<short>(row, col, static_cast<short *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_UINT16 :
                    err = getMatrixOfUnsignedInteger16(pvApiCtx, addr, &row, &col, (unsigned short**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<unsigned short>(row, col, static_cast<unsigned short *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_INT32 :
                    err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, (int**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<int>(row, col, static_cast<int *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_UINT32 :
                    err = getMatrixOfUnsignedInteger32(pvApiCtx, addr, &row, &col, (unsigned int**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<unsigned int>(row, col, static_cast<unsigned int *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;

#ifdef __SCILAB_INT64__
                case SCI_INT64 :
                    err = getMatrixOfInteger64(pvApiCtx, addr, &row, &col, (long long**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<long long>(row, col, static_cast<long long *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
                case SCI_UINT64 :
                    err = getMatrixOfUnsignedInteger64(pvApiCtx, addr, &row, &col, (unsigned long long**)(&ints));
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }

                    returnId = wrap<unsigned long long>(row, col, static_cast<unsigned long long *>(ints), wrapper, isRef);
                    tmpvars[++tmpvars[0]] = returnId;
                    return returnId;
#endif
            }
        }
        case sci_strings :
        {
            char ** matS = NULL;
            if (getAllocatedMatrixOfString(pvApiCtx, addr, &row, &col, &matS))
            {
                removeTemporaryVars(envId, tmpvars);
                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
            }

            returnId = wrap<char *>(row, col, matS, wrapper, isRef);
            freeAllocatedMatrixOfString(row, col, matS);
            tmpvars[++tmpvars[0]] = returnId;

            return returnId;
        }
        case sci_boolean :
        {
            int * matB;

            err = getMatrixOfBoolean(pvApiCtx, addr, &row, &col, &matB);
            if (err.iErr)
            {
                removeTemporaryVars(envId, tmpvars);
                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
            }

            returnId = wrapBool(row, col, matB, wrapper, isRef);
            tmpvars[++tmpvars[0]] = returnId;

            return returnId;
        }
        case sci_mlist :
        {
            int * id = 0;
            int type = getMListType(addr, pvApiCtx);
            int eId = getEnvironmentId(addr, pvApiCtx);

            if (eId != envId)
            {
                removeTemporaryVars(envId, tmpvars);
                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Incompatible External Objects"));
            }

            if (isClass)
            {
                if (type == EXTERNAL_CLASS)
                {
                    err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
                    if (err.iErr)
                    {
                        removeTemporaryVars(envId, tmpvars);
                        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                    }
                    return *id;
                }
                else
                {
                    removeTemporaryVars(envId, tmpvars);
                    throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External Class expected"));
                }
            }

            if (type == EXTERNAL_OBJECT || type == EXTERNAL_CLASS)
            {
                err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id);
                if (err.iErr)
                {
                    removeTemporaryVars(envId, tmpvars);
                    throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
                }
                return *id;
            }
            else if (type == EXTERNAL_VOID)
            {
                return -1;
            }
            else
            {
                removeTemporaryVars(envId, tmpvars);
                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("External object expected"));
            }

            break;
        }
        default :
        {
            removeTemporaryVars(envId, tmpvars);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Unable to wrap. Unmanaged datatype ?"));
        }
    }
}
Exemplo n.º 8
0
int get_integer_info(void* _pvCtx, int _iRhs, int* _piParent, int *_piAddr, int _iItemPos)
{
    SciErr sciErr;
    int iPrec               = 0;
    int iRows               = 0;
    int iCols               = 0;
    char* pcData            = NULL;
    short* psData           = NULL;
    int* piData             = NULL;
    unsigned char* pucData  = NULL;
    unsigned short* pusData = NULL;
    unsigned int* puiData   = NULL;

    if (_iItemPos == 0)
    {
        //Not in list
        sciErr = getMatrixOfIntegerPrecision(_pvCtx, _piAddr, &iPrec);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        switch (iPrec)
        {
            case SCI_INT8 :
                sciErr = getMatrixOfInteger8(_pvCtx, _piAddr, &iRows, &iCols, &pcData);
                break;
            case SCI_INT16 :
                sciErr = getMatrixOfInteger16(_pvCtx, _piAddr, &iRows, &iCols, &psData);
                break;
            case SCI_INT32 :
                sciErr = getMatrixOfInteger32(_pvCtx, _piAddr, &iRows, &iCols, &piData);
                break;
            case SCI_UINT8 :
                sciErr = getMatrixOfUnsignedInteger8(_pvCtx, _piAddr, &iRows, &iCols, &pucData);
                break;
            case SCI_UINT16 :
                sciErr = getMatrixOfUnsignedInteger16(_pvCtx, _piAddr, &iRows, &iCols, &pusData);
                break;
            case SCI_UINT32 :
                sciErr = getMatrixOfUnsignedInteger32(_pvCtx, _piAddr, &iRows, &iCols, &puiData);
                break;
            default :
                return 1;
        }
    }
    else
    {
        sciErr = getMatrixOfIntegerPrecision(_pvCtx, _piAddr, &iPrec);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        switch (iPrec)
        {
            case SCI_INT8 :
                sciErr = getMatrixOfInteger8InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &pcData);
                break;
            case SCI_INT16 :
                sciErr = getMatrixOfInteger16InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &psData);
                break;
            case SCI_INT32 :
                sciErr = getMatrixOfInteger32InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &piData);
                break;
            case SCI_UINT8 :
                sciErr = getMatrixOfUnsignedInteger8InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &pucData);
                break;
            case SCI_UINT16 :
                sciErr = getMatrixOfUnsignedInteger16InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &pusData);
                break;
            case SCI_UINT32 :
                sciErr = getMatrixOfUnsignedInteger32InList(_pvCtx, _piParent, _iItemPos, &iRows, &iCols, &puiData);
                break;
            default :
                return 1;
        }
    }

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

    insert_indent();

    if (iPrec > 10)
    {
        sciprint("Unsigned ");
    }

    sciprint("Integer %d bits (%d x %d)\n", (iPrec % 10) * 8, iRows, iCols);
    return 0;;
}