SciErr createCommonNamedMatrixOfPoly(void* _pvCtx, const char* _pstName, char* _pstVarName, int _iComplex, int _iRows, int _iCols, const int* _piNbCoef, const double* const* _pdblReal, const double* const* _pdblImg) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int *piAddr = NULL; int iTotalLen = 0; //return named empty matrix if (_iRows == 0 && _iCols == 0) { double dblReal = 0; sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix"); } return sciErr; } if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createCommonNamedMatrixOfPoly"); return sciErr; } C2F(str2name)(_pstName, iVarID, (unsigned long)strlen(_pstName)); Top = Top + Nbvars + 1; getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); //write matrix information sciErr = fillCommonMatrixOfPoly(_pvCtx, piAddr, _pstVarName, _iComplex, _iRows, _iCols, _piNbCoef, _pdblReal, _pdblImg, &iTotalLen); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_POLY, _("%s: Unable to create %s named \"%s\""), _iComplex ? "createNamedComplexMatrixOfPoly" : "createNamedMatrixOfPoly", _("matrix of double"), _pstName); return sciErr; } //update "variable index" updateLstk(Top, *Lstk(Top) + 4, iTotalLen); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createCommonNamedMatrixOfDouble(void* _pvCtx, const char* _pstName, int _iComplex, int _iRows, int _iCols, const double* _pdblReal, const double* _pdblImg) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int iSize = _iRows * _iCols; int *piAddr = NULL; double *pdblReal = NULL; double *pdblImg = NULL; int iOne = 1; if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createCommonNamedMatrixOfDouble"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; int iMemSize = _iRows * _iCols * (_iComplex + 1) + 2; int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(Top)); if (iMemSize > iFreeSpace) { addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize); return sciErr; } getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); //write matrix information fillCommonMatrixOfDouble(_pvCtx, piAddr, _iComplex, _iRows, _iCols, &pdblReal, &pdblImg); //copy data in stack C2F(dcopy)(&iSize, const_cast<double*>(_pdblReal), &iOne, pdblReal, &iOne); if(_iComplex) { C2F(dcopy)(&iSize, const_cast<double*>(_pdblImg), &iOne, pdblImg, &iOne); } //update "variable index" updateLstk(Top, *Lstk(Top) + sadr(4), iSize * (_iComplex + 1) * 2); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createNamedPointer(void* _pvCtx, const char* _pstName, int* _pvPtr) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; void* pvPtr = NULL; int *piAddr = NULL; if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedPointer"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; int iMemSize = 1; int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top))); if (iMemSize > iFreeSpace) { addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize); return sciErr; } getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); //write matrix information sciErr = fillPointer(_pvCtx, piAddr, &pvPtr); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_POINTER, _("%s: Unable to create %s named \"%s\""), "createNamedPointer", _("pointer"), _pstName); return sciErr; } //copy data in stack ((double*)pvPtr)[0] = (double) ((unsigned long int)_pvPtr); updateLstk(Top, *Lstk(Top) + sadr(4), 2); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createNamedComplexZMatrixOfDouble(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const doublecomplex* _pdblData) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int iSize = _iRows * _iCols; int *piAddr = NULL; double *pdblReal = NULL; double *pdblImg = NULL; if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedComplexZMatrixOfDouble"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); //write matrix information fillCommonMatrixOfDouble(_pvCtx, piAddr, 1, _iRows, _iCols, &pdblReal, &pdblImg); vGetPointerFromDoubleComplex(_pdblData, _iRows * _iCols, pdblReal, pdblImg); //update "variable index" updateLstk(Top, *Lstk(Top) + sadr(4), iSize * (2) * 2); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createNamedBooleanSparseMatrix(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, int _iNbItem, const int* _piNbItemRow, const int* _piColPos) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int iPos = 0; int* piAddr = NULL; int* piNbItemRow = NULL; int* piColPos = NULL; //return named empty matrix if(_iRows == 0 && _iCols == 0) { double dblReal = 0; sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix"); } return sciErr; } if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedBooleanSparseMatrix"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; int iMemSize = (int)( ( (double)iPos / 2) + 0.5); int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(Top)); if (iMemSize > iFreeSpace) { addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize); return sciErr; } getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); sciErr = fillBooleanSparseMatrix(_pvCtx, piAddr, _iRows, _iCols, _iNbItem, &piNbItemRow, &piColPos); if(sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_BOOLEAN_SPARSE, _("%s: Unable to create %s named \"%s\""), "createNamedBooleanSparseMatrix", _("boolean sparse matrix"), _pstName); return sciErr; } memcpy(piNbItemRow, _piNbItemRow, _iRows * sizeof(int)); memcpy(piColPos, _piColPos, _iNbItem * sizeof(int)); iPos = 5;//4 for header + 1 for NbItem iPos += _iRows + _iNbItem; //update "variable index" updateLstk(Top, *Lstk(Top) + iPos, 0); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createNamedMatrixOfBoolean(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const int* _piBool) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int* piBool = NULL; int *piAddr = NULL; //return named empty matrix if(_iRows == 0 && _iCols == 0) { double dblReal = 0; sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix"); } return sciErr; } if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createNamedMatrixOfBoolean"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; int iMemSize = (int)(((double)(_iRows * _iCols) / 2) + 2); int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top))); if (iMemSize > iFreeSpace) { addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize); return sciErr; } getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); //write matrix information sciErr = fillMatrixOfBoolean(_pvCtx, piAddr, _iRows, _iCols, &piBool); if(sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_BOOLEAN, _("%s: Unable to create %s named \"%s\""), "createNamedMatrixOfBoolean", _("matrix of boolean"), _pstName); return sciErr; } //copy data in stack memcpy(piBool, _piBool, sizeof(int) * _iRows * _iCols); updateLstk(Top, *Lstk(Top) + sadr(3), (_iRows * _iCols) / (sizeof(double)/sizeof(int))); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }
SciErr createCommonNamedSparseMatrix(void* _pvCtx, const char* _pstName, int _iComplex, int _iRows, int _iCols, int _iNbItem, const int* _piNbItemRow, const int* _piColPos, const double* _pdblReal, const double* _pdblImg) { SciErr sciErr; sciErr.iErr = 0; sciErr.iMsgCount = 0; int iVarID[nsiz]; int iSaveRhs = Rhs; int iSaveTop = Top; int iTotalSize = 0; int iPos = 0; int* piAddr = NULL; int* piNbItemRow = NULL; int* piColPos = NULL; int iOne = 1; double* pdblReal = NULL; double* pdblImg = NULL; //return named empty matrix if(_iRows == 0 && _iCols == 0) { double dblReal = 0; sciErr = createNamedMatrixOfDouble(_pvCtx, _pstName, 0, 0, &dblReal); if (sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_EMPTY_MATRIX, _("%s: Unable to create variable in Scilab memory"), "createNamedEmptyMatrix"); } return sciErr; } if (!checkNamedVarFormat(_pvCtx, _pstName)) { addErrorMessage(&sciErr, API_ERROR_INVALID_NAME, _("%s: Invalid variable name."), "createCommonNamedSparseMatrix"); return sciErr; } C2F(str2name)(_pstName, iVarID, (int)strlen(_pstName)); Top = Top + Nbvars + 1; //header + offset int iMemSize = (5 + _iRows + _iNbItem + !((_iRows + _iNbItem) % 2)) / 2; //+ items size iMemSize += _iNbItem * (_iComplex + 1); int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top))); if (iMemSize > iFreeSpace) { addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, iMemSize); return sciErr; } getNewVarAddressFromPosition(_pvCtx, Top, &piAddr); sciErr = fillCommonSparseMatrix(_pvCtx, piAddr, _iComplex, _iRows, _iCols, _iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg, &iTotalSize); if(sciErr.iErr) { addErrorMessage(&sciErr, API_ERROR_CREATE_NAMED_SPARSE, _("%s: Unable to create %s named \"%s\""), _iComplex ? "createNamedComplexSparseMatrix" : "createNamedSparseMatrix", _("sparse matrix"), _pstName); return sciErr; } memcpy(piNbItemRow, _piNbItemRow, _iRows * sizeof(int)); memcpy(piColPos, _piColPos, _iNbItem * sizeof(int)); C2F(dcopy)(&_iNbItem, const_cast<double*>(_pdblReal), &iOne, pdblReal, &iOne); if(_iComplex) { C2F(dcopy)(&_iNbItem, const_cast<double*>(_pdblImg), &iOne, pdblImg, &iOne); } iPos = 5;//4 for header + 1 for NbItem iPos += _iRows + _iNbItem; //update "variable index" updateLstk(Top, *Lstk(Top) + iPos, iTotalSize); Rhs = 0; //Add name in stack reference list createNamedVariable(iVarID); Top = iSaveTop; Rhs = iSaveRhs; return sciErr; }