Ejemplo n.º 1
0
static bool import_string(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
{
    SciErr sciErr;
    int iRet = 0;
    char **pstData = NULL;
    int iDims = 0;
    int* piDims = NULL;
    int iComplex = 0;
    int iSize = 0;

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

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

    pstData = (char **)MALLOC(iSize * sizeof(char *));

    iRet = readStringMatrix(_iDatasetId, pstData);
    if (iRet)
    {
        FREE(piDims);
        return false;
    }

    if (_piAddress == NULL)
    {
        sciErr = createNamedMatrixOfString(pvCtx, _pstVarname, piDims[0], piDims[1], pstData);
    }
    else                        //if not null this variable is in a list
    {
        sciErr = createMatrixOfStringInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], pstData);
    }

    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        FREE(piDims);
        freeStringMatrix(_iDatasetId, pstData);
        FREE(pstData);
        return false;
    }

    FREE(piDims);
    freeStringMatrix(_iDatasetId, pstData);
    FREE(pstData);

    return true;
}
Ejemplo n.º 2
0
static bool read_string(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
{
    int iRet = 0;
    int iSize = 0;
    int iComplex = 0;
    char** pstData = NULL;

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

    pstData = (char **)MALLOC(iSize * sizeof(char *));
    iRet = readStringMatrix(_iDatasetId, pstData);


    for (int i = 0 ; i < _pInfo->piDims[0] * _pInfo->piDims[1] ; i++)
    {
        _pInfo->iSize += (int)strlen(pstData[i]) * 4;
    }


    freeStringMatrix(_iDatasetId, pstData);
    FREE(pstData);
    //always full double size
    _pInfo->iSize += (8 - (_pInfo->iSize % 8));
    //header + offset
    _pInfo->iSize += 16 + (1 + iSize) * 4;

    generateInfo(_pInfo, "string");
    return true;
}
Ejemplo n.º 3
0
static bool read_string(int dataset, VarInfo6& info)
{
    int complex = 0;
    int ret = getDatasetInfo(dataset, &complex, &info.dims, NULL);
    if (ret < 0)
    {
        closeDataSet(dataset);
        return false;
    }

    info.pdims.resize(info.dims);
    int size = getDatasetInfo(dataset, &complex, &info.dims, info.pdims.data());

    std::vector<char*> str(size);
    ret = readStringMatrix(dataset, str.data());

    for (int i = 0; i < size; i++)
    {
        info.size += (int)strlen(str[i]) * sizeof(wchar_t);
    }

    freeStringMatrix(dataset, str.data());

    generateInfo(info);
    return true;
}
Ejemplo n.º 4
0
static types::InternalType* import_string(int dataset)
{
    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();
    }

    std::vector<char*> s(size);
    ret = readStringMatrix(dataset, s.data());

    types::String* str = new types::String(dims, d.data());
    wchar_t** pstr = str->get();

    for (int i = 0; i < size; ++i)
    {
        pstr[i] = to_wide_string(s[i]);
    }

    freeStringMatrix(dataset, s.data());

    return str;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
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;
}