int readBooleanSparseMatrix_v1(int _iDatasetId, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos) { hid_t obj = 0; hobj_ref_t pRef[2] = {0}; herr_t status; /* * Read the data. */ status = H5Dread(_iDatasetId, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pRef); if (status < 0) { return -1; } //read Row data obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[0]); status = readInteger32Matrix_v1(obj, 1, _iRows, _piNbItemRow); if (status < 0) { return -1; } //read cols data obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[1]); status = readInteger32Matrix_v1(obj, 1, _iNbItem, _piColPos); if (status < 0) { return -1; } return 0; }
int readCommonSparseComplexMatrix_v1(int _iDatasetId, int _iComplex, int _iRows, int _iCols, int _iNbItem, int *_piNbItemRow, int *_piColPos, double *_pdblReal, double *_pdblImg) { hid_t obj = 0; hobj_ref_t pRef[3] = {0}; herr_t status; /* * Read the data. */ status = H5Dread(_iDatasetId, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, pRef); if (status < 0) { return -1; } //read Row data obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[0]); status = readInteger32Matrix_v1(obj, 1, _iRows, _piNbItemRow); if (status < 0) { return -1; } //read cols data obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[1]); status = readInteger32Matrix_v1(obj, 1, _iNbItem, _piColPos); if (status < 0) { return -1; } //read sparse data obj = H5Rdereference(_iDatasetId, H5R_OBJECT, &pRef[2]); if (_iComplex) { status = readDoubleComplexMatrix_v1(obj, 1, _iNbItem, _pdblReal, _pdblImg); } else { status = readDoubleMatrix_v1(obj, 1, _iNbItem, _pdblReal); } if (status < 0) { return -1; } return 0; }
static bool import_integer_v1(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname) { int iRet = 0; int iRows = 0; int iCols = 0; int iPrec = 0; SciErr sciErr; iRet = getDatasetDims_v1(_iDatasetId, &iRows, &iCols); if (iRet) { return false; } iRet = getDatasetPrecision_v1(_iDatasetId, &iPrec); if (iRet) { return false; } switch (iPrec) { case SCI_INT8: { char *pcData = NULL; pcData = (char *)MALLOC(sizeof(char) * iRows * iCols); iRet = readInteger8Matrix_v1(_iDatasetId, iRows, iCols, pcData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfInteger8(pvCtx, _pstVarname, iRows, iCols, pcData); } else { sciErr = createMatrixOfInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pcData); } FREE(pcData); } break; case SCI_UINT8: { unsigned char *pucData = NULL; pucData = (unsigned char *)MALLOC(sizeof(unsigned char) * iRows * iCols); iRet = readUnsignedInteger8Matrix_v1(_iDatasetId, iRows, iCols, pucData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfUnsignedInteger8(pvCtx, _pstVarname, iRows, iCols, pucData); } else { sciErr = createMatrixOfUnsignedInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pucData); } FREE(pucData); } break; case SCI_INT16: { short *psData = NULL; psData = (short *)MALLOC(sizeof(short) * iRows * iCols); iRet = readInteger16Matrix_v1(_iDatasetId, iRows, iCols, psData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfInteger16(pvCtx, _pstVarname, iRows, iCols, psData); } else { sciErr = createMatrixOfInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, psData); } FREE(psData); } break; case SCI_UINT16: { unsigned short *pusData = NULL; pusData = (unsigned short *)MALLOC(sizeof(unsigned short) * iRows * iCols); iRet = readUnsignedInteger16Matrix_v1(_iDatasetId, iRows, iCols, pusData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfUnsignedInteger16(pvCtx, _pstVarname, iRows, iCols, pusData); } else { sciErr = createMatrixOfUnsignedInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pusData); } FREE(pusData); } break; case SCI_INT32: { int *piData = NULL; piData = (int *)MALLOC(sizeof(int) * iRows * iCols); iRet = readInteger32Matrix_v1(_iDatasetId, iRows, iCols, piData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfInteger32(pvCtx, _pstVarname, iRows, iCols, piData); } else { sciErr = createMatrixOfInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, piData); } FREE(piData); } break; case SCI_UINT32: { unsigned int *puiData = NULL; puiData = (unsigned int *)MALLOC(sizeof(unsigned int) * iRows * iCols); iRet = readUnsignedInteger32Matrix_v1(_iDatasetId, iRows, iCols, puiData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfUnsignedInteger32(pvCtx, _pstVarname, iRows, iCols, puiData); } else { sciErr = createMatrixOfUnsignedInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, puiData); } FREE(puiData); } break; case SCI_INT64: { #ifdef __SCILAB_INT64__ long long *pllData = NULL; pllData = (long long *)MALLOC(sizeof(long long) * iRows * iCols); iRet = readInteger64Matrix_v1(_iDatasetId, iRows, iCols, pllData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfInteger64(pvCtx, _pstVarname, iRows, iCols, pllData); } else { sciErr = createMatrixOfInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pllData); } FREE(pllData); #else return false; #endif } break; case SCI_UINT64: { #ifdef __SCILAB_INT64__ unsigned long long *pullData = NULL; pullData = (unsigned long long *)MALLOC(sizeof(unsigned long long) * iRows * iCols); iRet = readUnsignedInteger64Matrix_v1(_iDatasetId, iRows, iCols, pullData); if (iRet) { return false; } if (_piAddress == NULL) { sciErr = createNamedMatrixOfUnsignedInteger64(pvCtx, _pstVarname, iRows, iCols, pullData); } else { sciErr = createMatrixOfUnsignedInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, pullData); } FREE(pullData); #else return false; #endif } break; default: return false; } #ifdef PRINT_DEBUG char pstMsg[512]; sprintf(pstMsg, "integer_%d (%d x %d)", _iItemPos, iRows, iCols); print_tree(pstMsg); #endif if (sciErr.iErr) { printError(&sciErr, 0); return false; } return true; }
static bool import_hypermat_v1(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname) { int iRet = 0; int iRows = 0; int iCols = 0; int iItems = 0; hobj_ref_t *piItemRef = NULL; // an hypermatrix is stored in an mlist if (_iVarType != sci_mlist) { return false; } iRet = getListDims_v1(_iDatasetId, &iItems); if (iRet) { return false; } if (iItems != 3) { // hypermatrix have 3 elements return false; } iRet = getListItemReferences_v1(_iDatasetId, &piItemRef); if (iRet) { return false; } // get first item int iItemDataset = 0; iRet = getListItemDataset_v1(_iDatasetId, piItemRef, 0, &iItemDataset); if (iRet || iItemDataset == 0) { return false; } // get first item type int iItemType = getScilabTypeFromDataSet_v1(iItemDataset); if (iItemType != sci_strings) { return false; } // get size of first item iRet = getDatasetDims_v1(iItemDataset, &iRows, &iCols); if (iRet < 0) { return false; } if (iRows * iCols != 3) { return false; } // get data of first item for check the type of mlist char** pstData = new char*[iRows * iCols]; iRet = readStringMatrix_v1(iItemDataset, iRows, iCols, pstData); if (iRet || strcmp(pstData[0], "hm") != 0) { FREE(piItemRef); for (int i = 0; i < iRows * iCols; i++) { FREE(pstData[i]); } delete[] pstData; return false; } for (int i = 0; i < iRows * iCols; i++) { FREE(pstData[i]); } delete[] pstData; pstData = NULL; // get second item, the Size of hypermatrix iRet = getListItemDataset_v1(_iDatasetId, piItemRef, 1, &iItemDataset); if (iRet) { return false; } iRet = getDatasetDims_v1(iItemDataset, &iRows, &iCols); if (iRet < 0) { return false; } if (iRows != 1) { return false; } int* piDimsArray = new int[iCols]; iRet = readInteger32Matrix_v1(iItemDataset, iRows, iCols, piDimsArray); if (iRet) { delete[] piDimsArray; return false; } // get third item, the Data of hypermatrix // import data like a "type" (Double, Int, ...) instead of mlist iRet = getListItemDataset_v1(_iDatasetId, piItemRef, 2, &iItemDataset); bool bRet = import_data_v1(pvCtx, iItemDataset, _iItemPos, _piAddress, _pstVarname); if (bRet == false) { delete[] piDimsArray; return false; } // get imported hypermatrix from List or Context types::GenericType* pGT = NULL; types::InternalType* pIT = NULL; if (_piAddress) { types::List* pL = (types::List*)_piAddress; pIT = pL->get(_iItemPos - 1); } else { wchar_t* pwcsName = to_wide_string(_pstVarname); pIT = symbol::Context::getInstance()->getCurrentLevel(symbol::Symbol(pwcsName)); FREE(pwcsName); } // reshape data with size of hypermatrix pGT = pIT->getAs<types::GenericType>(); pGT->reshape(piDimsArray, iCols); delete[] piDimsArray; iRet = deleteListItemReferences_v1(_iDatasetId, piItemRef); if (iRet) { return false; } return true; }