/*--------------------------------------------------------------------------*/
static int getCommonAllocatedNamedSinglePoly(void* _pvCtx, const char* _pstName, int _iComplex, int* _piNbCoef, double** _pdblReal, double** _pdblImg)
{
    SciErr sciErr = sciErrInit();
    int iRows	= 0;
    int iCols	= 0;

    double* pdblReal = NULL;
    double* pdblImg	 = NULL;

    if (isNamedScalar(_pvCtx, _pstName) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_NAMED_SINGLE_POLY, _("%s: Wrong type for input argument \"%s\": A scalar expected.\n"), _iComplex ? "getAllocatedNamedSingleComplexPoly" : "getAllocatedNamedSinglePoly", _pstName);
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    sciErr = readCommonNamedMatrixOfPoly(_pvCtx, _pstName, _iComplex, &iRows, &iCols, _piNbCoef, &pdblReal, &pdblImg);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_NAMED_SINGLE_POLY, _("%s: Unable to get argument \"%s\""), _iComplex ? "getAllocatedNamedSingleComplexPoly" : "getAllocatedNamedSinglePoly", _pstName);
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pdblReal = (double*)MALLOC(sizeof(double) **_piNbCoef);
    memcpy(*_pdblReal, pdblReal, sizeof(double) **_piNbCoef);

    if (_iComplex)
    {
        *_pdblImg	= (double*)MALLOC(sizeof(double) **_piNbCoef);
        memcpy(*_pdblImg, pdblImg, sizeof(double) **_piNbCoef);
    }
    return 0;
}
SciErr getPolyVariableName(void* _pvCtx, int* _piAddress, char* _pstVarName, int* _piVarNameLen)
{
    SciErr sciErr = sciErrInit();

    if (_piAddress == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getPolyVariableName");
        return sciErr;
    }

    if (!((types::InternalType*)_piAddress)->isPoly())
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_TYPE, _("%s: Invalid argument type, %s expected"), "getPolyVariableName", _("polynomial matrix"));
        return sciErr;
    }

    if (*_piVarNameLen == 0)
    {
        *_piVarNameLen = (int)((types::InternalType*)_piAddress)->getAs<types::Polynom>()->getVariableName().size();
        //No error
    }

    if (_pstVarName == NULL)
    {
        return sciErr;
    }

    char* pstTemp = wide_string_to_UTF8(((types::InternalType*)_piAddress)->getAs<types::Polynom>()->getVariableName().c_str());
    strcpy(_pstVarName, pstTemp);
    FREE(pstTemp);
    *_piVarNameLen = static_cast<int>(strlen(_pstVarName));
    return sciErr;
}
Пример #3
0
SciErr getHypermatPolyVariableName(void* _pvCtx, int* _piAddress, char* _pstVarName, int* _piVarNameLen)
{
    SciErr sciErr = sciErrInit();
    void * entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);

    if (ret || entries == NULL || ((types::InternalType*)entries)->isPoly() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getHypermatPolyVariableName");
        return sciErr;
    }

    types::Polynom* p = (types::Polynom*)entries;
    std::wstring var = p->getVariableName();

    char* varname = wide_string_to_UTF8(var.data());
    *_piVarNameLen = static_cast<int>(strlen(varname));

    if (_pstVarName)
    {
        strcpy(_pstVarName, varname);
    }

    FREE(varname);
    return sciErr;
}
Пример #4
0
int checkInputArgument(void* _pvCtx, int _iMin, int _iMax)
{
    SciErr sciErr = sciErrInit();

    /*
    * store the name in recu array, fname can be a non null terminated char array
    * Get_Iname() can be used in other function to get the interface name
    */
    int cx0 = 0;
    C2F(cvname) (&C2F(recu).ids[(C2F(recu).pt + 1) * nsiz - nsiz],  ((StrCtx *) _pvCtx)->pstName, &cx0, (unsigned long int)strlen(((StrCtx *)_pvCtx)->pstName));

    if (_iMin <= nbInputArgument(_pvCtx) && _iMax >= nbInputArgument(_pvCtx))
    {
        return 1;
    }

    if (_iMax == _iMin)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMax);
    }
    else
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMin, _iMax);
    }

    return 0;
}
Пример #5
0
SciErr createComplexHypermatOfPoly(void *_pvCtx, int _iVar, char* _pstVarName, int * _dims, int _ndims, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
{
    SciErr sciErr = sciErrInit();
    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::typed_list in = *pStr->m_pIn;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    wchar_t* w = to_wide_string(_pstVarName);
    types::Polynom* p = new types::Polynom(w, _ndims, _dims, _piNbCoef);
    p->setComplex(true);

    int size = p->getSize();
    if (size == 0)
    {
        delete p;
        out[rhs - 1] = types::Double::Empty();
        FREE(w);
        return sciErr;
    }

    types::SinglePoly** s = p->get();

    for (int i = 0; i < size; ++i)
    {
        s[i]->setCoef(_pdblReal[i], _pdblImg[i]);
    }

    out[rhs - 1] = p;
    FREE(w);
    return sciErr;
}
Пример #6
0
SciErr createHypermatOfString(void *_pvCtx, int _iVar, int * _dims, int _ndims, const char* const* _pstStrings)
{
    SciErr sciErr = sciErrInit();
    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::typed_list in = *pStr->m_pIn;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    types::String* p = new types::String(_ndims, _dims);
    int size = p->getSize();

    if (size == 0)
    {
        delete p;
        out[rhs - 1] = types::Double::Empty();
        return sciErr;
    }

    for (int i = 0; i < size; ++i)
    {
        wchar_t* w = to_wide_string(_pstStrings[i]);
        p->set(i, w);
        FREE(w);
    }

    out[rhs - 1] = p;
    return sciErr;
}
Пример #7
0
/*--------------------------------------------------------------------------*/
int getAllocatedSingleString(void* _pvCtx, int* _piAddress, char** _pstData)
{
    SciErr sciErr = sciErrInit();
    int iRows = 0;
    int iCols = 0;
    int iLen = 0;

    if (isScalar(_pvCtx, _piAddress) == 0 || isStringType(_pvCtx, _piAddress) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_STRING, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "getAllocatedSingleString", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    sciErr = getMatrixOfString(_pvCtx, _piAddress, &iRows, &iCols, &iLen, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_STRING, _("%s: Unable to get argument data"), "getAllocatedSingleString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pstData = (char*)MALLOC(sizeof(char) * (iLen + 1)); //+1 for null termination

    sciErr = getMatrixOfString(_pvCtx, _piAddress, &iRows, &iCols, &iLen, _pstData);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_STRING, _("%s: Unable to get argument data"), "getAllocatedSingleString");
        printError(&sciErr, 0);
        FREE(*_pstData);
        return sciErr.iErr;
    }

    return 0;
}
Пример #8
0
/*--------------------------------------------------------------------------*/
int getAllocatedNamedSingleWideString(void* _pvCtx, const char* _pstName, wchar_t** _pwstData)
{
    SciErr sciErr = sciErrInit();
    int iRows = 0;
    int iCols = 0;
    int iLen = 0;

    if (isNamedScalar(_pvCtx, _pstName) == 0 || isNamedStringType(_pvCtx, _pstName) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_NAMED_SINGLE_WIDE_STRING, _("%s: Wrong type for input argument \"%s\": A single string expected.\n"), "getAllocatedNamedSingleWideString", _pstName);
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    sciErr = readNamedMatrixOfWideString(_pvCtx, _pstName, &iRows, &iCols, &iLen, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_NAMED_SINGLE_WIDE_STRING, _("%s: Unable to get argument data"), "getAllocatedNamedSingleWideString");
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pwstData = (wchar_t*)MALLOC(sizeof(wchar_t) * (iLen + 1)); //+1 for null termination

    sciErr = readNamedMatrixOfWideString(_pvCtx, _pstName, &iRows, &iCols, &iLen, _pwstData);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_NAMED_SINGLE_WIDE_STRING, _("%s: Unable to get argument data"), "getAllocatedNamedSingleWideString");
        printError(&sciErr, 0);
        FREE(*_pwstData);
        return sciErr.iErr;
    }

    return 0;
}
Пример #9
0
int allocSingleString(void* _pvCtx, int _iVar, int _iLen, const char** _pstStrings)
{
    SciErr sciErr = sciErrInit();

    types::GatewayStruct* pGstr = (types::GatewayStruct*)_pvCtx;
    types::typed_list in = *pGstr->m_pIn;
    types::InternalType** out = pGstr->m_pOut;
    types::String *pStr = NULL;


    char* pstStrings = new char[_iLen];

    memset(pstStrings, ' ', _iLen);
    if (_pstStrings == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString");
        return sciErr.iErr;
    }
    _pstStrings[0] = pstStrings;

    pStr = new types::String(pstStrings);

    if (pStr == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString");
        return sciErr.iErr;
    }

    int rhs = _iVar - *getNbInputArgument(_pvCtx);
    out[rhs - 1] = pStr;


    return sciErr.iErr;
}
SciErr createCommonMatrixOfPoly(void* _pvCtx, int _iVar, int _iComplex, char* _pstVarName, int _iRows, int _iCols, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg)
{
    SciErr sciErr = sciErrInit();
    if (_pvCtx == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), _iComplex ? "createComplexMatrixOfPoly" : "createMatrixOfPoly");
        return sciErr;
    }

    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::InternalType** out = pStr->m_pOut;
    int rhs = _iVar - *getNbInputArgument(_pvCtx);

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        types::Double *pDbl = new types::Double(_iRows, _iCols);
        if (pDbl == NULL)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
            return sciErr;
        }

        out[rhs - 1] = pDbl;
        return sciErr;
    }

    wchar_t* pstTemp = to_wide_string(_pstVarName);
    std::wstring wstTemp(pstTemp);
    types::Polynom* pP = new types::Polynom(wstTemp, _iRows, _iCols, _piNbCoef);
    FREE(pstTemp);
    if (pP == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocated variable"), _iComplex ? "createComplexMatrixOfPoly" : "createMatrixOfPoly");
        return sciErr;
    }

    if (_iComplex)
    {
        pP->setComplex(true);
    }

    out[rhs - 1] = pP;

    for (int i = 0 ; i < pP->getSize() ; i++)
    {
        types::Double* pD = new types::Double(_piNbCoef[i], 1, _iComplex == 1);
        pD->set(_pdblReal[i]);
        if (_iComplex)
        {
            pD->setImg(_pdblImg[i]);
        }
        pP->setCoef(i, pD);
        delete pD;
    }

    return sciErr;
}
Пример #11
0
/*--------------------------------------------------------------------------*/
int checkOutputArgumentAtMost(void* _pvCtx, int _iMax)
{
    SciErr sciErr = sciErrInit();

    if (_iMax >= nbOutputArgument(_pvCtx))
    {
        return 1;
    }

    Scierror(78, _("%s: Wrong number of output argument(s): at most %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMax);
    return 0;
}
Пример #12
0
/*--------------------------------------------------------------------------*/
int checkInputArgumentAtLeast(void* _pvCtx, int _iMin)
{
    SciErr sciErr = sciErrInit();

    if (_iMin <= nbInputArgument(_pvCtx))
    {
        return 1;
    }

    Scierror(77, _("%s: Wrong number of input argument(s): at least %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMin);
    return 0;
}
Пример #13
0
SciErr getHypermatOfString(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piLength, char** _pstStrings)
{
    SciErr sciErr = sciErrInit();
    void * entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);

    if (ret || entries == NULL || ((types::InternalType*)entries)->isString() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getHypermatOfString");
        return sciErr;
    }

    types::String* p = (types::String*)entries;
    *_dims = p->getDimsArray();
    *_ndims = p->getDims();
    int size = p->getSize();

    if (_piLength == NULL)
    {
        return sciErr;
    }


    if (_pstStrings == NULL || *_pstStrings == NULL)
    {
        wchar_t** s = p->get();
        for (int i = 0; i < size; i++)
        {
            char* c = wide_string_to_UTF8(s[i]);
            _piLength[i] = (int)strlen(c);
            FREE(c);
        }
    }
    else
    {
        wchar_t** s = p->get();
        for (int i = 0; i < size; i++)
        {
            if (_pstStrings[i] == NULL)
            {
                addErrorMessage(&sciErr, API_ERROR_INVALID_SUBSTRING_POINTER, _("%s: Invalid argument address"), "getHypermatOfString");
                return sciErr;
            }

            char* c = wide_string_to_UTF8(s[i]);
            strcpy(_pstStrings[i], c);
            FREE(c);
        }
    }

    return sciErr;
}
Пример #14
0
/*--------------------------------------------------------------------------*/
SciErr createNamedMatrixOfString(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const char* const* _pstStrings)
{
    SciErr sciErr = sciErrInit();

    // check variable name
    if (checkNamedVarFormat(_pvCtx, _pstName) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Invalid variable name: %s."), "createNamedMatrixOfString", _pstName);
        return sciErr;
    }

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        if (createNamedEmptyMatrix(_pvCtx, _pstName))
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
            return sciErr;
        }

        return sciErr;
    }

    types::String* pS = new types::String(_iRows, _iCols);
    if (pS == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name: %s."), "createNamedMatrixOfString", _pstName);
        return sciErr;
    }

    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        wchar_t* pstTemp = to_wide_string(_pstStrings[i]);
        pS->set(i, pstTemp);
        FREE(pstTemp);
    }

    wchar_t* pwstName = to_wide_string(_pstName);
    symbol::Context* ctx = symbol::Context::getInstance();
    symbol::Symbol sym = symbol::Symbol(pwstName);
    FREE(pwstName);
    if (ctx->isprotected(sym) == false)
    {
        ctx->put(sym, pS);
    }
    else
    {
        delete pS;
        addErrorMessage(&sciErr, API_ERROR_REDEFINE_PERMANENT_VAR, _("Redefining permanent variable.\n"));
    }
    return sciErr;
}
Пример #15
0
/*--------------------------------------------------------------------------*/
SciErr getVarType(void *_pvCtx, int *_piAddress, int *_piType)
{
    SciErr sciErr = sciErrInit();

    if (_piAddress == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getVarType");
        return sciErr;
    }

    *_piType = _piAddress[0];
    return sciErr;
}
/*--------------------------------------------------------------------------*/
static int getCommonAllocatedMatrixOfPoly(void* _pvCtx, int* _piAddress, int _iComplex, int* _piRows, int* _piCols, int** _piNbCoef, double*** _pdblReal, double*** _pdblImg)
{
    SciErr sciErr = sciErrInit();
    double* pdblReal	= NULL;
    double* pdblImg		= NULL;

    sciErr = getCommonMatrixOfPoly(_pvCtx, _piAddress, _iComplex, _piRows, _piCols, NULL, NULL, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_MATRIX_POLY, _("%s: Unable to get argument #%d"), _iComplex ? "getAllocatedMatrixOfComplexPoly" : "getAllocatedMatrixOfPoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_piNbCoef = (int*)MALLOC(sizeof(int) **_piRows **_piCols);

    sciErr = getCommonMatrixOfPoly(_pvCtx, _piAddress, _iComplex, _piRows, _piCols, *_piNbCoef, NULL, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_MATRIX_POLY, _("%s: Unable to get argument #%d"), _iComplex ? "getAllocatedMatrixOfComplexPoly" : "getAllocatedMatrixOfPoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pdblReal = (double**)MALLOC(sizeof(double*) **_piRows **_piCols);
    for (int i = 0 ; i < *_piRows **_piCols ; i++)
    {
        (*_pdblReal)[i] = (double*)MALLOC(sizeof(double) * (*_piNbCoef)[i]);
    }

    if (_iComplex)
    {
        *_pdblImg	= (double**)MALLOC(sizeof(double*) **_piRows **_piCols);
        for (int i = 0 ; i < *_piRows **_piCols ; i++)
        {
            (*_pdblImg)[i] = (double*)MALLOC(sizeof(double) * (*_piNbCoef)[i]);
        }
    }

    sciErr = getCommonMatrixOfPoly(_pvCtx, _piAddress, _iComplex, _piRows, _piCols, *_piNbCoef, *_pdblReal, _pdblImg == NULL ? NULL : *_pdblImg);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_MATRIX_POLY, _("%s: Unable to get argument #%d"), _iComplex ? "getAllocatedSingleComplexPoly" : "getAllocatedSinglePoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    return 0;
}
Пример #17
0
SciErr getHypermatDimensions(void *_pvCtx, int *_piAddress, int **_dims, int *_ndims)
{
    SciErr sciErr = sciErrInit();
    types::InternalType* it = (types::InternalType*)_piAddress;
    if (it->isGenericType() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_NOT_MATRIX_TYPE, _("%s: matrix argument expected"), "getHypermatDimensions");
        return sciErr;
    }

    types::GenericType* gt = it->getAs<types::GenericType>();
    *_ndims = gt->getDims();
    *_dims = gt->getDimsArray();
    return sciErr;
}
SciErr createComplexZMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, const doublecomplex* _pdblData)
{
    SciErr sciErr = sciErrInit();
    const doublecomplex *pdblZ = NULL;

    sciErr = allocComplexZMatrixOfDouble(_pvCtx, _iVar, _iRows, _iCols, &pdblZ);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_CREATE_ZDOUBLE, _("%s: Unable to create variable in Scilab memory"), "allocComplexMatrixOfDouble");
        return sciErr;
    }

    memcpy((void*)pdblZ, _pdblData, _iRows * _iCols * sizeof(doublecomplex));
    return sciErr;
}
Пример #19
0
/*--------------------------------------------------------------------------*/
SciErr getVarNameFromPosition(void *_pvCtx, int _iVar, char *_pstName)
{
    SciErr sciErr = sciErrInit();
    int iNameLen = 0;
    int iJob1 = 1;

    CvNameL(&vstk_.idstk[(Top - Rhs + _iVar - 1) * 6], _pstName, &iJob1, &iNameLen);
    if (iNameLen == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Unable to get name of argument #%d"), "getVarNameFromPosition", _iVar);
        return sciErr;
    }

    _pstName[iNameLen] = '\0';
    return sciErr;
}
SciErr allocComplexZMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, const doublecomplex** _pdblData)
{
    SciErr sciErr = sciErrInit();
    double *pdblReal	= NULL;
    double *pdblImg		= NULL;

    sciErr = allocCommonMatrixOfDouble(_pvCtx, _iVar, 'z', 1, _iRows, _iCols, &pdblReal, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_ALLOC_COMPLEX_DOUBLE, _("%s: Unable to create variable in Scilab memory"), "allocComplexMatrixOfDouble");
        return sciErr;
    }

    *_pdblData = (doublecomplex*)pdblReal;
    return sciErr;
}
Пример #21
0
SciErr getComplexHypermatOfPoly(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int* _piNbCoef, double** _pdblReal, double** _pdblImg)
{
    SciErr sciErr = sciErrInit();
    void * entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);

    if (ret || entries == NULL || ((types::InternalType*)entries)->isPoly() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getComplexHypermatOfPoly");
        return sciErr;
    }

    types::Polynom* p = (types::Polynom*)entries;

    if (p->isComplex() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_COMPLEXITY, _("%s: Bad call to get a non complex matrix"), "getComplexHypermatOfPoly");
        return sciErr;
    }

    *_dims = p->getDimsArray();
    *_ndims = p->getDims();

    if (_piNbCoef == NULL)
    {
        return sciErr;
    }

    p->getSizes(_piNbCoef);

    if (_pdblReal == NULL)
    {
        return sciErr;
    }

    int size = p->getSize();
    types::SinglePoly** s = p->get();

    for (int i = 0; i < size; i++)
    {
        memcpy(_pdblReal[i], s[i]->get(), sizeof(double) * s[i]->getSize());
        memcpy(_pdblImg[i], s[i]->getImg(), sizeof(double) * s[i]->getSize());
    }

    return sciErr;
}
Пример #22
0
SciErr getHypermatOfDouble(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, double** _pdblReal)
{
    SciErr sciErr = sciErrInit();
    void* entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);
    if (ret || entries == NULL || ((types::InternalType*)entries)->isDouble() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_DOUBLE, _("%s: Unable to get argument #%d"), "getHypermatOfDouble", getRhsFromAddress(_pvCtx, _piAddress));
    }

    types::Double* d = (types::Double*)entries;
    *_dims = d->getDimsArray();
    *_ndims = d->getDims();
    *_pdblReal = d->get();
    return sciErr;
}
Пример #23
0
/*--------------------------------------------------------------------------*/
int deleteNamedVariable(void* _pvCtx, const char* _pstName)
{
    SciErr sciErr = sciErrInit();
    int iVarID[nsiz];
    int iZero = 0;
    int il;
    int sRhs = Rhs;
    int sLhs = Lhs;
    int sTop = Top;

    if (isNamedVarExist(_pvCtx, _pstName) == 0)
    {
        return 0;
    }

    if (!checkNamedVarFormat(_pvCtx, _pstName))
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name: %s."), "createNamedComplexZMatrixOfDouble", _pstName);
        return 0;
    }

    //get varId from varName
    C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName));

    //create a null matrix at the Top of the stack
    Top = Top + 1;
    il = iadr(*Lstk(Top));
    *istk(il) = 0;
    *Lstk(Top + 1) = *Lstk(Top) + 1;
    Rhs = 0;

    //Replace existing value by null matrix to delete it
    C2F(stackp) (iVarID, &iZero);
    Rhs = sRhs;
    Lhs = sLhs;
    Top = sTop ;
    if (C2F(iop).err > 0/* || C2F(errgst).err1 > 0*/)
    {
        return 0;
    }

    //No Idea :x
    Fin = 1;
    return 1;
}
Пример #24
0
/*--------------------------------------------------------------------------*/
SciErr getVarAddressFromName(void *_pvCtx, const char *_pstName, int **_piAddress)
{
    SciErr sciErr = sciErrInit();
    int iVarID[nsiz];
    int *piAddr = NULL;

    //get variable id from name
    C2F(str2name) (_pstName, iVarID, (int)strlen(_pstName));

    //define scope of search
    Fin = -6;
    Err = 0;
    //search variable
    C2F(stackg) (iVarID);

    //No idea :(
    if (*Infstk(Fin) == 2)
    {
        Fin = *istk(iadr(*Lstk(Fin)) + 1 + 1);
    }

    if (Err > 0 || Fin == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Unable to get address of variable \"%s\""), "getVarAddressFromName", _pstName);
        return sciErr;
    }

    //get variable address
    getNewVarAddressFromPosition(_pvCtx, Fin, &piAddr);
    if (piAddr[0] < 0)
    {
        //get address from reference
        int iStackRef = *Lstk(Fin);
        int iStackAddr = iadr(iStackRef);
        int iNewStackRef = iStackAddr + 1;
        int iNewStackPtr = *istk(iNewStackRef);
        int iNewStackAddr = iadr(iNewStackPtr);

        piAddr = istk(iNewStackAddr);
    }

    *_piAddress = piAddr;
    return sciErr;
}
Пример #25
0
SciErr getHypermatOfUnsignedInteger64(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, unsigned long long** _pullData64)
{
    SciErr sciErr = sciErrInit();
    void * entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);

    if (ret || entries == NULL || ((types::InternalType*)entries)->isUInt64() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getHypermatOfUnsignedInteger64");
        return sciErr;
    }

    types::UInt64* p = (types::UInt64*)entries;
    *_dims = p->getDimsArray();
    *_ndims = p->getDims();
    *_pullData64 = p->get();
    return sciErr;
}
Пример #26
0
SciErr getHypermatOfBoolean(void* _pvCtx, int* _piAddress, int **_dims, int *_ndims, int** _piBool)
{
    SciErr sciErr = sciErrInit();
    void * entries = NULL;

    int ret = getHypermatEntries(_pvCtx, _piAddress, &entries);

    if (ret || entries == NULL || ((types::InternalType*)entries)->isBool() == false)
    {
        addErrorMessage(&sciErr, API_ERROR_INVALID_POINTER, _("%s: Invalid argument address"), "getHypermatOfBoolean");
        return sciErr;
    }

    types::Bool* p = (types::Bool*)entries;
    *_dims = p->getDimsArray();
    *_ndims = p->getDims();
    *_piBool = p->get();
    return sciErr;
}
Пример #27
0
/*--------------------------------------------------------------------------*/
int checkOutputArgument(void* _pvCtx, int _iMin, int _iMax)
{
    SciErr sciErr = sciErrInit();

    if (_iMin <= nbOutputArgument(_pvCtx) && _iMax >= nbOutputArgument(_pvCtx))
    {
        return 1;
    }

    if (_iMax == _iMin)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMax);
    }
    else
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), ((StrCtx *) _pvCtx)->pstName, _iMin, _iMax);
    }

    return 0;
}
/*--------------------------------------------------------------------------*/
static int getCommonAllocatedSinglePoly(void* _pvCtx, int* _piAddress, int _iComplex, int* _piNbCoef, double** _pdblReal, double** _pdblImg)
{
    SciErr sciErr = sciErrInit();
    int iRows	= 0;
    int iCols	= 0;

    double* pdblReal = NULL;
    double* pdblImg	 = NULL;

    if (isScalar(_pvCtx, _piAddress) == 0)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_POLY, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), _iComplex ? "getAllocatedSingleComplexPoly" : "getAllocatedSinglePoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    sciErr = getCommonMatrixOfPoly(_pvCtx, _piAddress, _iComplex, &iRows, &iCols, _piNbCoef, NULL, NULL);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_POLY, _("%s: Unable to get argument #%d"), _iComplex ? "getAllocatedSingleComplexPoly" : "getAllocatedSinglePoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    *_pdblReal = (double*)MALLOC(sizeof(double) **_piNbCoef);

    if (_iComplex)
    {
        *_pdblImg	= (double*)MALLOC(sizeof(double) **_piNbCoef);
    }

    sciErr = getCommonMatrixOfPoly(_pvCtx, _piAddress, _iComplex, &iRows, &iCols, _piNbCoef, _pdblReal, _pdblImg);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_GET_ALLOC_SINGLE_POLY, _("%s: Unable to get argument #%d"), _iComplex ? "getAllocatedSingleComplexPoly" : "getAllocatedSinglePoly", getRhsFromAddress(_pvCtx, _piAddress));
        printError(&sciErr, 0);
        return sciErr.iErr;
    }

    return 0;
}
Пример #29
0
/*--------------------------------------------------------------------------*/
SciErr getNamedVarDimension(void *_pvCtx, const char *_pstName, int *_piRows, int *_piCols)
{
    SciErr sciErr = sciErrInit();
    int *piAddr = NULL;

    sciErr = getVarAddressFromName(_pvCtx, _pstName, &piAddr);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_NAMED_VARDIM, _("%s: Unable to get dimension of variable \"%s\""), "getNamedVarDimension", _pstName);
        return sciErr;
    }

    sciErr = getVarDimension(_pvCtx, piAddr, _piRows, _piCols);
    if (sciErr.iErr)
    {
        addErrorMessage(&sciErr, API_ERROR_NAMED_VARDIM, _("%s: Unable to get dimension of variable \"%s\""), "getNamedVarDimension", _pstName);
        return sciErr;
    }

    return sciErr;
}
Пример #30
0
/*--------------------------------------------------------------------------*/
SciErr createMatrixOfString(void* _pvCtx, int _iVar, int _iRows, int _iCols, const char* const * _pstStrings)
{
    SciErr sciErr = sciErrInit();

    int rhs = _iVar - *getNbInputArgument(_pvCtx);
    types::GatewayStruct* pStr = (types::GatewayStruct*)_pvCtx;
    types::InternalType** out = pStr->m_pOut;

    //return empty matrix
    if (_iRows == 0 && _iCols == 0)
    {
        types::Double *pDbl = new types::Double(_iRows, _iCols);
        if (pDbl == NULL)
        {
            addErrorMessage(&sciErr, API_ERROR_CREATE_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createEmptyMatrix");
            return sciErr;
        }

        out[rhs - 1] = pDbl;
        return sciErr;
    }

    types::String* pS = new types::String(_iRows, _iCols);
    if (pS == NULL)
    {
        addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocated variable"), "createMatrixOfString");
        return sciErr;
    }

    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        wchar_t* pstTemp = to_wide_string(_pstStrings[i]);
        pS->set(i, pstTemp);
        FREE(pstTemp);
    }

    out[rhs - 1] = pS;

    return sciErr;
}