static bool read_integer(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
{
    int iRet = 0;
    int iPrec = 0;
    int iSize = 0;
    int iComplex = 0;

    iSize = getDatasetInfo(_iDatasetId, &iComplex, &_pInfo->iDims, _pInfo->piDims);
    getDatasetPrecision(_iDatasetId, &iPrec);

    _pInfo->iSize = 16 + iSize * (iPrec % 10);

    generateInfo(_pInfo, "integer");
    closeDataSet(_iDatasetId);
    return true;
}
static int readComplexPoly(int _iDatasetId, int *_piNbCoef, double **_pdblReal, double **_pdblImg)
{
    int iComplex = 0;
    int iSize = 0;
    int iDims = 0;
    //Get the datatype and its size.

    iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, _piNbCoef);

    //Allocate space for string data.
    *_pdblReal = (double *)MALLOC(*_piNbCoef * sizeof(double));
    *_pdblImg = (double *)MALLOC(*_piNbCoef * sizeof(double));

    //Read the data and return result.
    return readDoubleComplexMatrix(_iDatasetId, *_pdblReal, *_pdblImg);
}
static bool read_poly(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
{
    int iRet = 0;
    int iComplex = 0;
    char pstVarName[64] = { 0 };
    double **pdblReal = NULL;
    double **pdblImg = NULL;
    int *piNbCoef = NULL;
    int iSize = 0;

    iSize = getDatasetInfo(_iDatasetId, &iComplex, &_pInfo->iDims, _pInfo->piDims);
    _pInfo->iSize = 8 * 4 + (iSize + 1) * 4;

    if (iComplex)
    {
        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
        pdblImg = (double **)MALLOC(iSize * sizeof(double *));
        iRet = readPolyComplexMatrix(_iDatasetId, pstVarName, 2, _pInfo->piDims, piNbCoef, pdblReal, pdblImg);
    }
    else
    {
        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
        iRet = readPolyMatrix(_iDatasetId, pstVarName, 2, _pInfo->piDims, piNbCoef, pdblReal);
    }

    for (int i = 0 ; i < iSize ; i++)
    {
        _pInfo->iSize += piNbCoef[i] * 8 * (iComplex + 1);
        FREE(pdblReal[i]);
        if (iComplex)
        {
            FREE(pdblImg[i]);
        }
    }

    FREE(piNbCoef);
    FREE(pdblReal);
    if (iComplex)
    {
        FREE(pdblImg);
    }

    generateInfo(_pInfo, "polynomial");
    return true;
}
Exemple #4
0
void litiv::IDataReporter_<litiv::eDatasetEval_BinaryClassifier>::writeEvalReport() const {
    if(!getTotPackets() || !getDatasetInfo()->isUsingEvaluator()) {
        IDataReporter_<litiv::eDatasetEval_None>::writeEvalReport();
        return;
    }
    else if(isGroup() && !isBare())
        for(const auto& pBatch : getBatches(true))
            pBatch->writeEvalReport();
    IMetricsCalculatorConstPtr pMetrics = getMetrics(true);
    lvAssert(pMetrics.get());
    const BinClassifMetricsCalculator& oMetrics = dynamic_cast<const BinClassifMetricsCalculator&>(*pMetrics.get());;
    std::cout << "\t" << CxxUtils::clampString(std::string(size_t(!isGroup()),'>')+getName(),12) << " => Rcl=" << std::fixed << std::setprecision(4) << oMetrics.dRecall << " Prc=" << oMetrics.dPrecision << " FM=" << oMetrics.dFMeasure << " MCC=" << oMetrics.dMCC << std::endl;
    std::ofstream oMetricsOutput(PlatformUtils::AddDirSlashIfMissing(getOutputPath())+"../"+getName()+".txt");
    if(oMetricsOutput.is_open()) {
        oMetricsOutput << std::fixed;
        oMetricsOutput << "Video segmentation evaluation report for '" << getName() << "' :\n\n";
        oMetricsOutput << "            |     Rcl    |     Spc    |     FPR    |     FNR    |     PBC    |     Prc    |     FM     |     MCC    \n";
        oMetricsOutput << "------------|------------|------------|------------|------------|------------|------------|------------|------------\n";
        oMetricsOutput << IDataReporter_<eDatasetEval_BinaryClassifier>::writeInlineEvalReport(0);
        oMetricsOutput << "\nHz: " << getTotPackets()/getProcessTime() << "\n";
        oMetricsOutput << CxxUtils::getLogStamp();
    }
}
static bool import_struct(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an struct is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems < 2)
    {
        // struct have 2 elements minimal
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != iItems)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    char** pstDataSave = new char*[iSize - 2];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "st") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        delete[] pstDataSave;
        return false;
    }

    for (int i = 2; i < iSize; ++i)
    {
        pstDataSave[-2 + i] = new char[strlen(pstData[i]) + 1];
        strcpy(pstDataSave[-2 + i], pstData[i]);
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of struct
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        for (int i = 0; i < (-2 + iItems); ++i)
        {
            delete pstDataSave[i];
        }
        delete[] pstDataSave;
        pstDataSave = NULL;
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    types::Struct* pStruct = new types::Struct(piDims[1], piDimsArray);

    wchar_t* pwstName = NULL;
    for (int i = 0; i < (-2 + iItems); ++i)
    {
        pwstName = to_wide_string(pstDataSave[i]);
        pStruct->addField(pwstName);
        delete pstDataSave[i];
        FREE(pwstName);
    }

    delete[] pstDataSave;
    pstDataSave = NULL;

    types::SingleStruct** ppSStruct =  pStruct->get();
    types::String* pStr = pStruct->getFieldNames();

    types::List* pList = new types::List();
    // fill the list to avoid api_scilab error about the list size.
    pList->set(0, types::Double::Empty());

    if (pStruct->getSize() == 1)
    {
        types::InternalType* pIT = NULL;
        for (int i = 0; i < pStr->getSize(); ++i)
        {
            int iItemDataset = 0;
            iRet = getListItemDataset(_iDatasetId, piItemRef, i + 2, &iItemDataset);
            if (iRet || iItemDataset == 0)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            wchar_t* pwcsName = pStr->get(i);
            char* pcName = wide_string_to_UTF8(pwcsName);

            bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, pcName);
            if (bRet == false)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            pIT = pList->get(0);
            ppSStruct[0]->set(pwcsName, pIT);
            FREE(pcName);
        }
    }
    else if (pStruct->getSize() > 1)
    {
        for (int i = 0; i < pStr->getSize(); ++i)
        {
            int iItemDataset = 0;
            iRet = getListItemDataset(_iDatasetId, piItemRef, i + 2, &iItemDataset);
            if (iRet || iItemDataset == 0)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            wchar_t* pwcsName = pStr->get(i);
            char* pcName = wide_string_to_UTF8(pwcsName);

            bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, pcName);
            if (bRet == false)
            {
                deleteListItemReferences(_iDatasetId, piItemRef);
                delete pList;
                delete pStruct;
                return false;
            }

            types::List* pListData = pList->get(0)->getAs<types::List>();
            for (int iWriteData = 0; iWriteData < pStruct->getSize(); ++iWriteData)
            {
                ppSStruct[iWriteData]->set(pwcsName, pListData->get(iWriteData));
            }

            FREE(pcName);
        }

    }

    delete pList;
    if (_piAddress == NULL)
    {
        pwstName = to_wide_string(_pstVarname);
        symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pStruct);
        FREE(pwstName);
    }
    else
    {
        types::List* pParentList = (types::List*)_piAddress;
        pParentList->set(_iItemPos - 1, pStruct);
    }

    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
    if (iRet)
    {
        return false;
    }

    return true;
}
static types::InternalType* import_int(int dataset)
{
    types::InternalType* pOut = nullptr;
    int complex = 0;
    int dims = 0;
    int ret = getDatasetInfo(dataset, &complex, &dims, NULL);
    if (ret < 0)
    {
        closeDataSet(dataset);
        return nullptr;
    }

    std::vector<int> d(dims);
    int size = getDatasetInfo(dataset, &complex, &dims, d.data());


    if (dims == 0 || size <= 0)
    {
        closeDataSet(dataset);
        return types::Double::Empty();
    }

    int prec = 0;
    ret = getDatasetPrecision(dataset, &prec);
    if (ret != 0)
    {
        closeDataSet(dataset);
        return nullptr;
    }

    switch (prec)
    {
        case SCI_INT8:
        {
            types::Int8* pi = new types::Int8(dims, d.data());
            ret = readInteger8Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT16:
        {
            types::Int16* pi = new types::Int16(dims, d.data());
            ret = readInteger16Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT32:
        {
            types::Int32* pi = new types::Int32(dims, d.data());
            ret = readInteger32Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_INT64:
        {
            types::Int64* pi = new types::Int64(dims, d.data());
            ret = readInteger64Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT8:
        {
            types::UInt8* pi = new types::UInt8(dims, d.data());
            ret = readUnsignedInteger8Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT16:
        {
            types::UInt16* pi = new types::UInt16(dims, d.data());
            ret = readUnsignedInteger16Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT32:
        {
            types::UInt32* pi = new types::UInt32(dims, d.data());
            ret = readUnsignedInteger32Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        case SCI_UINT64:
        {
            types::UInt64* pi = new types::UInt64(dims, d.data());
            ret = readUnsignedInteger64Matrix(dataset, pi->get());
            pOut = pi;
            break;
        }
        default:
            return nullptr;
            break;
    }

    return pOut;
}
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 read_struct(int dataset, VarInfo6& info)
{
    int complex = 0;
    int size = getDimsNode(dataset, &complex, info.pdims);
    info.dims = static_cast<int>(info.pdims.size());
    info.size = 0;

    if (size == 0)
    {
        generateInfo(info);
        closeList6(dataset);
        return true;
    }
    int fieldCount = 0;
    int ret = getListDims6(dataset, &fieldCount);
    if (ret < 0)
    {
        closeList6(dataset);
        return false;
    }

    //open __refs__ node
    int refs = getDataSetIdFromName(dataset, "__refs__");
    H5O_info_t oinfo;
    for (int i = 0; i < fieldCount; ++i)
    {
        H5Oget_info_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT);
        ssize_t len = H5Lget_name_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, i, 0, 0, H5P_DEFAULT) + 1;
        char* name = (char*)MALLOC(sizeof(char) * len);
        H5Lget_name_by_idx(dataset, ".", H5_INDEX_NAME, H5_ITER_INC, i, name, len, H5P_DEFAULT);
        std::string cname(name);
        FREE(name);

        if (cname != "__dims__" && cname != "__refs__")
        {
            int dataref = getDataSetIdFromName(dataset, cname.data());
            if (dataref < 0)
            {
                closeList6(dataset);
                return false;
            }

            int refdim = 0;
            getDatasetInfo(dataref, &complex, &refdim, NULL);
            std::vector<int> refdims(refdim);
            int refcount = getDatasetInfo(dataref, &complex, &refdim, refdims.data());
            std::vector<hobj_ref_t> vrefs(refcount);
            ret = H5Dread(dataref, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, vrefs.data());
            if (ret < 0)
            {
                return false;
            }


            //import field
            for (int j = 0; j < refcount; ++j)
            {
                int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]);
                if (data < 0)
                {
                    return false;
                }

                VarInfo6 info2;
                ret = read_data(data, info2);
                if (ret == false)
                {
                    return false;
                }

                info.size += info2.size;

            }

            closeDataSet(dataref);
        }
    }

    generateInfo(info);
    closeList6(refs);
    closeList6(dataset);
    return true;
}
static bool import_double(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    SciErr sciErr;
    int iRet = 0;
    double *pdblReal = NULL;
    double *pdblImg = NULL;
    int iDims = 0;
    int* piDims = NULL;
    int iComplex = 0;
    int iSize = 0;

    iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL);
    if (iRet < 0)
    {
        return false;
    }

    if (iDims)
    {
        if (iDims > 2)
        {
            //hypermatrix
            return false;
        }

        piDims = (int*)MALLOC(sizeof(int) * iDims);
        iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);

        if (iSize > 0)
        {
            pdblReal = (double *)MALLOC(iSize * sizeof(double));

            if (iComplex)
            {
                pdblImg = (double *)MALLOC(iSize * sizeof(double));
                iRet = readDoubleComplexMatrix(_iDatasetId, pdblReal, pdblImg);
            }
            else
            {
                iRet = readDoubleMatrix(_iDatasetId, pdblReal);
            }

            //to be sure ti have 2 dims
            if (iDims == 1)
            {
                FREE(piDims);
                piDims = (int*)MALLOC(sizeof(int) * 2);
                piDims[0] = 1;
                piDims[1] = iSize;
            }
        }
    }

    if (iDims == 0 || iSize == 0) //empty matrix
    {
        if (piDims)
        {
            FREE(piDims);
        }

        /*bug 7224 : to close dataset */
        iRet = readEmptyMatrix(_iDatasetId);
        if (iRet)
        {
            return false;
        }

        // Hack to sure that piDims will not be null at line 372.
        iDims = 2;
        piDims = (int*)MALLOC(sizeof(int) * iDims);
        memset(piDims, 0, sizeof(int) * iDims);
        pdblReal = (double*)MALLOC(sizeof(double) * 1);
        pdblReal[0] = 0;
        iComplex = 0;
    }

    if (_piAddress == NULL)
    {
        if (iComplex)
        {
            sciErr = createNamedComplexMatrixOfDouble(pvCtx, _pstVarname, piDims[0], piDims[1], pdblReal, pdblImg);
        }
        else
        {
            sciErr = createNamedMatrixOfDouble(pvCtx, _pstVarname, piDims[0], piDims[1], pdblReal);
        }
    }
    else //if not null this variable is in a list
    {
        if (iComplex)
        {
            sciErr = createComplexMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pdblReal, pdblImg);
        }
        else
        {
            sciErr = createMatrixOfDoubleInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pdblReal);
        }
    }

    FREE(piDims);
    FREE(pdblReal);
    if (iComplex)
    {
        FREE(pdblImg);
    }

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

    return true;
}
static bool import_integer(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iDims = 0;
    int* piDims = NULL;
    int iComplex = 0;
    int iSize = 0;
    int iPrec = 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);

    iRet = getDatasetPrecision(_iDatasetId, &iPrec);
    if (iRet)
    {
        FREE(piDims);
        return false;
    }

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

            pcData = (char *)MALLOC(sizeof(char) * iSize);
            iRet = readInteger8Matrix(_iDatasetId, pcData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger8(pvCtx, _pstVarname, piDims[0], piDims[1], pcData);
            }
            else
            {
                sciErr = createMatrixOfInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pcData);
            }

            FREE(pcData);
        }
        break;
        case SCI_UINT8:
        {
            unsigned char *pucData = NULL;

            pucData = (unsigned char *)MALLOC(sizeof(unsigned char) * iSize);
            iRet = readUnsignedInteger8Matrix(_iDatasetId, pucData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger8(pvCtx, _pstVarname, piDims[0], piDims[1], pucData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger8InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pucData);
            }

            FREE(pucData);
        }
        break;
        case SCI_INT16:
        {
            short *psData = NULL;

            psData = (short *)MALLOC(sizeof(short) * iSize);
            iRet = readInteger16Matrix(_iDatasetId, psData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger16(pvCtx, _pstVarname, piDims[0], piDims[1], psData);
            }
            else
            {
                sciErr = createMatrixOfInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], psData);
            }

            FREE(psData);
        }
        break;
        case SCI_UINT16:
        {
            unsigned short *pusData = NULL;

            pusData = (unsigned short *)MALLOC(sizeof(unsigned short) * iSize);
            iRet = readUnsignedInteger16Matrix(_iDatasetId, pusData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger16(pvCtx, _pstVarname, piDims[0], piDims[1], pusData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger16InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pusData);
            }

            FREE(pusData);
        }
        break;
        case SCI_INT32:
        {
            int *piData = NULL;

            piData = (int *)MALLOC(sizeof(int) * iSize);
            iRet = readInteger32Matrix(_iDatasetId, piData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger32(pvCtx, _pstVarname, piDims[0], piDims[1], piData);
            }
            else
            {
                sciErr = createMatrixOfInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], piData);
            }

            FREE(piData);
        }
        break;
        case SCI_UINT32:
        {
            unsigned int *puiData = NULL;

            puiData = (unsigned int *)MALLOC(sizeof(unsigned int) * iSize);
            iRet = readUnsignedInteger32Matrix(_iDatasetId, puiData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger32(pvCtx, _pstVarname, piDims[0], piDims[1], puiData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger32InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], puiData);
            }

            FREE(puiData);
        }
        break;
        case SCI_INT64:
        {
#ifdef __SCILAB_INT64__
            long long *pllData = NULL;

            pllData = (long long *)MALLOC(sizeof(long long) * iSize);
            iRet = readInteger64Matrix(_iDatasetId, pllData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfInteger64(pvCtx, _pstVarname, piDims[0], piDims[1], pllData);
            }
            else
            {
                sciErr = createMatrixOfInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pllData);
            }

            FREE(pllData);
#else
            FREE(piDims);
            return false;
#endif
        }
        break;
        case SCI_UINT64:
        {
#ifdef __SCILAB_INT64__
            unsigned long long *pullData = NULL;

            pullData = (unsigned long long *)MALLOC(sizeof(unsigned long long) * iSize);
            iRet = readUnsignedInteger64Matrix(_iDatasetId, pullData);
            if (iRet)
            {
                FREE(piDims);
                return false;
            }

            if (_piAddress == NULL)
            {
                sciErr = createNamedMatrixOfUnsignedInteger64(pvCtx, _pstVarname, piDims[0], piDims[1], pullData);
            }
            else
            {
                sciErr = createMatrixOfUnsignedInteger64InNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pullData);
            }

            FREE(pullData);
#else
            FREE(piDims);
            return false;
#endif
        }
        break;
        default:
            return false;
    }

    FREE(piDims);

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

    return true;
}
Exemple #11
0
static types::InternalType* import_macro(int dataset)
{
    int complex = 0;
    int dims = 0;
    int size = 0;
    std::vector<int> d(2);

    std::list<symbol::Variable*>* inputList = new std::list<symbol::Variable*>();
    std::list<symbol::Variable*>* outputList = new std::list<symbol::Variable*>();
    ast::Exp* body = nullptr;

    symbol::Context* ctx = symbol::Context::getInstance();

    //inputs
    int inputNode = getDataSetIdFromName(dataset, "inputs");
    size = getDatasetInfo(inputNode, &complex, &dims, d.data());
    if (size < 0)
    {
        delete inputList;
        delete outputList;
        closeList6(dataset);
        return nullptr;
    }
    std::vector<char*> inputNames(size);

    if (size != 0)
    {
        readStringMatrix(inputNode, inputNames.data());

        for (auto & input : inputNames)
        {
            wchar_t* winput = to_wide_string(input);
            symbol::Variable* var = ctx->getOrCreate(symbol::Symbol(winput));
            FREE(winput);
            inputList->push_back(var);
        }

        freeStringMatrix(inputNode, inputNames.data());
    }
    else
    {
        closeDataSet(inputNode);
    }

    //outputs
    int outputNode = getDataSetIdFromName(dataset, "outputs");
    size = getDatasetInfo(outputNode, &complex, &dims, d.data());
    if (size < 0)
    {
        delete inputList;
        delete outputList;
        closeList6(dataset);
        return nullptr;
    }
    std::vector<char*> outputNames(size);

    if (size != 0)
    {
        readStringMatrix(outputNode, outputNames.data());

        for (auto & output : outputNames)
        {
            wchar_t* woutput = to_wide_string(output);
            symbol::Variable* var = ctx->getOrCreate(symbol::Symbol(woutput));
            FREE(woutput);
            outputList->push_back(var);
        }

        freeStringMatrix(outputNode, outputNames.data());
    }
    else
    {
        closeDataSet(outputNode);
    }

    //body
    int bodyNode = getDataSetIdFromName(dataset, "body");
    size = getDatasetInfo(bodyNode, &complex, &dims, d.data());
    if (size < 0)
    {
        delete inputList;
        delete outputList;
        closeList6(dataset);
        return nullptr;
    }
    std::vector<unsigned char> bodybin(size);
    readUnsignedInteger8Matrix(bodyNode, bodybin.data());

    ast::DeserializeVisitor ds(bodybin.data());
    body = ds.deserialize();

    //wname+1 is to remove "/" at the start of the var name from HDF5
    types::Macro* macro = new types::Macro(L"", *inputList, *outputList, *body->getAs<ast::SeqExp>(), L"script");
    delete body;
    closeList6(dataset);
    return macro;
}
static bool import_cell(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an hypermatrix is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems != 3)
    {
        // cell have 3 elements
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != 3)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "ce") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        return false;
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of cell
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    types::Cell* pCell = new types::Cell(piDims[1], piDimsArray);
    types::List* pList = new types::List();
    pList->set(0, types::Double::Empty());

    iRet = getListItemDataset(_iDatasetId, piItemRef, 2, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete pList;
        delete pCell;
        return false;
    }

    bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, NULL);
    if (bRet == false)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete pList;
        delete pCell;
        return false;
    }

    types::List* pListData = pList->get(0)->getAs<types::List>();
    for (int iWriteData = 0; iWriteData < pCell->getSize(); ++iWriteData)
    {
        pCell->set(iWriteData, pListData->get(iWriteData));
    }

    delete pList;

    if (_piAddress == NULL)
    {
        wchar_t* pwstName = to_wide_string(_pstVarname);
        symbol::Context::getInstance()->put(symbol::Symbol(pwstName), pCell);
        FREE(pwstName);
    }
    else
    {
        types::List* pParentList = (types::List*)_piAddress;
        pParentList->set(_iItemPos - 1, pCell);
    }

    iRet = deleteListItemReferences(_iDatasetId, piItemRef);

    if (iRet)
    {
        return false;
    }

    return true;
}
static bool import_hypermat(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    int iRet = 0;
    int iComplex = 0;
    int iDims = 0;
    int iItems = 0;
    hobj_ref_t *piItemRef = NULL;

    // an hypermatrix is stored in an mlist
    if (_iVarType != sci_mlist)
    {
        return false;
    }

    iRet = getListDims(_iDatasetId, &iItems);
    if (iRet)
    {
        return false;
    }

    if (iItems != 3)
    {
        // hypermatrix have 3 elements
        return false;
    }

    iRet = getListItemReferences(_iDatasetId, &piItemRef);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item
    int iItemDataset = 0;
    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
    if (iRet || iItemDataset == 0)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get first item type
    int iItemType = getScilabTypeFromDataSet(iItemDataset);
    if (iItemType != sci_strings)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    // get size of first item
    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    int* piDims = new int[2];
    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (iSize != 3)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    delete[] piDims;
    piDims = NULL;

    // get data of first item for check the type of mlist
    char** pstData = new char*[iSize];
    iRet = readStringMatrix(iItemDataset, pstData);
    if (iRet || strcmp(pstData[0], "hm") != 0)
    {
        // if not the good type, do not h5close (deleteListItemReferences)
        FREE(piItemRef);
        freeStringMatrix(iItemDataset, pstData);
        delete[] pstData;
        return false;
    }

    freeStringMatrix(iItemDataset, pstData);
    delete[] pstData;
    pstData = NULL;

    // get second item, the Size of hypermatrix
    iRet = getListItemDataset(_iDatasetId, piItemRef, 1, &iItemDataset);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
    if (iRet < 0 || iDims != 2)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        return false;
    }

    piDims = new int[2];
    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
    if (piDims[0] != 1)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        return false;
    }

    int* piDimsArray = new int[piDims[1]];
    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
    if (iRet)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        delete[] piDimsArray;
        return false;
    }

    // get third item, the Data of hypermatrix
    // import data like a "type" (Double, Int, ...) instead of mlist
    iRet = getListItemDataset(_iDatasetId, piItemRef, 2, &iItemDataset);
    bool bRet = import_data(pvCtx, iItemDataset, _iItemPos, _piAddress, _pstVarname);
    if (bRet == false)
    {
        deleteListItemReferences(_iDatasetId, piItemRef);
        delete[] piDims;
        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, piDims[1]);

    delete[] piDims;
    delete[] piDimsArray;


    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
    if (iRet)
    {
        return false;
    }

    return true;
}
Exemple #14
0
static types::InternalType* import_boolean_sparse(int dataset)
{
    //get sparse dimensions
    int complex = 0;
    std::vector<int> pdims;
    int size = getDimsNode(dataset, &complex, pdims);

    //get non zeros count
    int nnz = 0;
    int datannz = getDataSetIdFromName(dataset, "__nnz__");
    readInteger32Matrix(datannz, &nnz);

    if (nnz == 0)
    {
        closeList6(dataset);
        return new types::SparseBool(pdims[0], pdims[1]);
    }

    //get inner vector
    int datain = getDataSetIdFromName(dataset, "__inner__");
    int dimin = 0;
    int sizein = getDatasetInfo(datain, &complex, &dimin, NULL);
    std::vector<int> dimsin(dimin);
    sizein = getDatasetInfo(datain, &complex, &dimin, dimsin.data());
    if (sizein < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    std::vector<int> in(sizein);
    int ret = readInteger32Matrix(datain, in.data());
    if (ret < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    //get outer vector
    int dataout = getDataSetIdFromName(dataset, "__outer__");
    int dimout = 0;
    int sizeout = getDatasetInfo(dataout, &complex, &dimout, NULL);
    std::vector<int> dimsout(dimout);
    sizeout = getDatasetInfo(dataout, &complex, &dimout, dimsout.data());
    if (sizeout < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    std::vector<int> out(sizeout);
    ret = readInteger32Matrix(dataout, out.data());
    if (ret < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    closeList6(dataset);

    return new types::SparseBool(pdims[0], pdims[1], nnz, in.data(), out.data());
}
Exemple #15
0
static types::InternalType* import_sparse(int dataset)
{
    types::Sparse* sp = nullptr;
    //get sparse dimensions
    int complex = 0;
    std::vector<int> pdims;
    int size = getDimsNode(dataset, &complex, pdims);

    //get non zeros count
    int nnz = 0;
    int datannz = getDataSetIdFromName(dataset, "__nnz__");
    readInteger32Matrix(datannz, &nnz);

    if (nnz == 0)
    {
        closeList6(dataset);
        return new types::Sparse(pdims[0], pdims[1]);
    }

    //get inner vector
    int datain = getDataSetIdFromName(dataset, "__inner__");
    int dimin = 0;
    int sizein = getDatasetInfo(datain, &complex, &dimin, NULL);
    std::vector<int> dimsin(dimin);
    sizein = getDatasetInfo(datain, &complex, &dimin, dimsin.data());
    if (sizein < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    std::vector<int> in(sizein);
    int ret = readInteger32Matrix(datain, in.data());
    if (ret < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    //get outer vector
    int dataout = getDataSetIdFromName(dataset, "__outer__");
    int dimout = 0;
    int sizeout = getDatasetInfo(dataout, &complex, &dimout, NULL);
    std::vector<int> dimsout(dimout);
    sizeout = getDatasetInfo(dataout, &complex, &dimout, dimsout.data());
    if (sizeout < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    std::vector<int> out(sizeout);
    ret = readInteger32Matrix(dataout, out.data());
    if (ret < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    //get data
    int ddata = getDataSetIdFromName(dataset, "__data__");
    int dimdata = 0;
    int sizedata = getDatasetInfo(ddata, &complex, &dimdata, NULL);
    std::vector<int> dimsdata(dimdata);
    sizedata = getDatasetInfo(ddata, &complex, &dimdata, dimsdata.data());
    if (sizedata < 0)
    {
        closeList6(dataset);
        return nullptr;
    }

    std::vector<double> real(sizedata);

    if (complex)
    {
        std::vector<double> img(sizedata);
        ret = readDoubleComplexMatrix(ddata, real.data(), img.data());
        if (ret < 0)
        {
            closeList6(dataset);
            return nullptr;
        }

        sp = new types::Sparse(pdims[0], pdims[1], nnz, in.data(), out.data(), real.data(), img.data());
    }
    else
    {
        ret = readDoubleMatrix(ddata, real.data());
        if (ret < 0)
        {
            closeList6(dataset);
            return nullptr;
        }

        sp = new types::Sparse(pdims[0], pdims[1], nnz, in.data(), out.data(), real.data(), nullptr);
    }

    closeList6(dataset);
    return sp;
}
Exemple #16
0
static types::InternalType* import_poly(int dataset)
{
    //get poly dims node
    int complex = 0;
    std::vector<int> pdims;
    int size = getDimsNode(dataset, &complex, pdims);

    //get variable name
    char* var = NULL;
    int varname = getDataSetIdFromName(dataset, "__varname__");
    readStringMatrix(varname, &var);
    wchar_t* wvar = to_wide_string(var);
    std::wstring wvarname(wvar);
    FREE(wvar);
    freeStringMatrix(varname, &var);

    types::Polynom* p = new types::Polynom(wvarname, static_cast<int>(pdims.size()), pdims.data());
    types::SinglePoly** pss = p->get();

    //open __refs__ node
    int refs = getDataSetIdFromName(dataset, "__refs__");
    size = p->getSize();

    //loop on children
    for (int i = 0; i < size; ++i)
    {
        //forge name
        std::string polyname(std::to_string(i));
        int poly = getDataSetIdFromName(refs, polyname.data());

        //get dims
        complex = 0;
        int dims = 0;
        int ret = getDatasetInfo(poly, &complex, &dims, NULL);
        if (ret < 0)
        {
            return nullptr;
        }

        std::vector<int> d(dims);
        int datasize = getDatasetInfo(poly, &complex, &dims, d.data());

        types::SinglePoly* ss = NULL;

        //get coef
        if (dims == 0 || datasize <= 0)
        {
            ss = new types::SinglePoly();
        }
        else if (complex)
        {
            double* real = NULL;
            double* img = NULL;
            //create singlepoly
            ss = new types::SinglePoly(&real, &img, datasize - 1);
            readDoubleComplexMatrix(poly, real, img);
        }
        else
        {
            double* real = NULL;
            ss = new types::SinglePoly(&real, datasize - 1);
            readDoubleMatrix(poly, real);
        }

        pss[i] = ss;
    }

    closeList6(refs);
    closeList6(dataset);
    return p;
}
Exemple #17
0
static types::InternalType* import_struct(int dataset)
{
    //get struct dims node
    int complex = 0;
    std::vector<int> pdims;
    int size = getDimsNode(dataset, &complex, pdims);

    types::Struct* str = new types::Struct(static_cast<int>(pdims.size()), pdims.data());
    size = str->getSize();
    if (size == 0)
    {
        //empty struct
        closeList6(dataset);
        delete str;
        return new types::Struct();
    }

    types::SingleStruct** sstr = str->get();

    int fieldCount = 0;
    int ret = getListDims6(dataset, &fieldCount);
    if (ret < 0)
    {
        closeList6(dataset);
        return str;
    }

    //get fields name
    int dfield = getDataSetIdFromName(dataset, "__fields__");
    int dim = 0;
    getDatasetInfo(dfield, &complex, &dim, NULL);
    std::vector<int> d(dim);
    size = getDatasetInfo(dfield, &complex, &dim, d.data());
    if (size < 0)
    {
        closeList6(dataset);
        delete str;
        return nullptr;
    }

    //get dims value
    std::vector<char*> fields(size);
    readStringMatrix(dfield, fields.data());

    //open __refs__ node
    int refs = getDataSetIdFromName(dataset, "__refs__");

    for (const auto & name : fields)
    {
        wchar_t* field = to_wide_string(name);
        str->addField(field);

        int dataref = getDataSetIdFromName(dataset, name);
        if (dataref < 0)
        {
            closeList6(dataset);
            freeStringMatrix(dfield, fields.data());
            FREE(field);
            delete str;
            return nullptr;
        }

        int refdim = 0;
        getDatasetInfo(dataref, &complex, &refdim, NULL);
        std::vector<int> refdims(refdim);
        int refcount = getDatasetInfo(dataref, &complex, &refdim, refdims.data());
        std::vector<hobj_ref_t> vrefs(refcount);
        ret = H5Dread(dataref, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, vrefs.data());
        if (ret < 0)
        {
            freeStringMatrix(dfield, fields.data());
            FREE(field);
            delete str;
            return nullptr;
        }


        //import field
        for (int j = 0; j < refcount; ++j)
        {
            int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]);
            if (data < 0)
            {
                freeStringMatrix(dfield, fields.data());
                FREE(field);
                delete str;
                return nullptr;
            }

            types::InternalType* val = import_data(data);
            if (val == nullptr)
            {
                freeStringMatrix(dfield, fields.data());
                FREE(field);
                delete str;
                return nullptr;
            }

            sstr[j]->set(field, val);

        }

        FREE(field);
        closeDataSet(dataref);
    }

    freeStringMatrix(dfield, fields.data());
    closeList6(refs);
    closeList6(dataset);
    return str;
}