int putComplexPolynomial(char * variableName, char * polyVarName, double ** data, int nbRow, int nbCol, int * nbCoef, double ** imag, int nbRowI, int nbColI, int * nbCoefI) { SciErr sciErr; sciErr = createNamedComplexMatrixOfPoly(NULL, variableName, polyVarName, nbRow, nbCol, nbCoef, data, imag); if (sciErr.iErr) { printError(&sciErr, 0); return -1; } return 0; }
static bool import_poly(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname) { int iRet = 0; int iComplex = 0; char pstVarName[64] = { 0 }; double **pdblReal = NULL; double **pdblImg = NULL; int *piNbCoef = NULL; int iDims = 0; int* piDims = NULL; int iSize = 0; SciErr sciErr; iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL); if (iRet < 0) { return false; } piDims = (int*)MALLOC(sizeof(int) * iDims); iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims); if (iComplex) { piNbCoef = (int *)MALLOC(iSize * sizeof(int)); pdblReal = (double **)MALLOC(iSize * sizeof(double *)); pdblImg = (double **)MALLOC(iSize * sizeof(double *)); iRet = readPolyComplexMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal, pdblImg); } else { piNbCoef = (int *)MALLOC(iSize * sizeof(int)); pdblReal = (double **)MALLOC(iSize * sizeof(double *)); iRet = readPolyMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal); } if (iRet) { FREE(piDims); FREE(piNbCoef); for (int i = 0; i < iSize; i++) { FREE(pdblReal[i]); } FREE(pdblReal); if (iComplex) { for (int i = 0; i < iSize; i++) { FREE(pdblImg[i]); } FREE(pdblImg); } return false; } if (_piAddress == NULL) { if (iComplex) { sciErr = createNamedComplexMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg); } else { sciErr = createNamedMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal); } } else //if not null this variable is in a list { if (iComplex) { sciErr = createComplexMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg); } else { sciErr = createMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal); } } FREE(piDims); FREE(piNbCoef); for (int i = 0; i < iSize; i++) { FREE(pdblReal[i]); } FREE(pdblReal); if (iComplex) { for (int i = 0; i < iSize; i++) { FREE(pdblImg[i]); } FREE(pdblImg); } if (sciErr.iErr) { printError(&sciErr, 0); return false; } return true; }
static bool import_poly_v1(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname) { int iRet = 0; int iRows = 0; int iCols = 0; int iComplex = 0; char pstVarName[64] = { 0 }; double **pdblReal = NULL; double **pdblImg = NULL; int *piNbCoef = NULL; SciErr sciErr; iRet = getDatasetDims_v1(_iDatasetId, &iRows, &iCols); if (iRet) { return false; } iComplex = isComplexData_v1(_iDatasetId); if (iComplex) { piNbCoef = (int *)MALLOC(iRows * iCols * sizeof(int)); pdblReal = (double **)MALLOC(iRows * iCols * sizeof(double *)); pdblImg = (double **)MALLOC(iRows * iCols * sizeof(double *)); iRet = readPolyComplexMatrix_v1(_iDatasetId, pstVarName, iRows, iCols, piNbCoef, pdblReal, pdblImg); } else { piNbCoef = (int *)MALLOC(iRows * iCols * sizeof(int)); pdblReal = (double **)MALLOC(iRows * iCols * sizeof(double *)); iRet = readPolyMatrix_v1(_iDatasetId, pstVarName, iRows, iCols, piNbCoef, pdblReal); } if (iRet) { FREE(piNbCoef); for (int i = 0; i < iRows * iCols; i++) { FREE(pdblReal[i]); } FREE(pdblReal); if (iComplex) { for (int i = 0; i < iRows * iCols; i++) { FREE(pdblImg[i]); } FREE(pdblImg); } return false; } if (_piAddress == NULL) { if (iComplex) { sciErr = createNamedComplexMatrixOfPoly(pvCtx, _pstVarname, pstVarName, iRows, iCols, piNbCoef, pdblReal, pdblImg); } else { sciErr = createNamedMatrixOfPoly(pvCtx, _pstVarname, pstVarName, iRows, iCols, piNbCoef, pdblReal); } } else //if not null this variable is in a list { if (iComplex) { sciErr = createComplexMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, iRows, iCols, piNbCoef, pdblReal, pdblImg); } else { sciErr = createMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, iRows, iCols, piNbCoef, pdblReal); } } FREE(piNbCoef); for (int i = 0; i < iRows * iCols; i++) { FREE(pdblReal[i]); } FREE(pdblReal); if (iComplex) { for (int i = 0; i < iRows * iCols; i++) { FREE(pdblImg[i]); } FREE(pdblImg); } if (sciErr.iErr) { printError(&sciErr, 0); return false; } #ifdef PRINT_DEBUG char pstMsg[512]; sprintf(pstMsg, "poly_%d (%d x %d)", _iItemPos, iRows, iCols); print_tree(pstMsg); #endif return true; }