static types::InternalType* import_boolean(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(); } types::Bool* bools = new types::Bool(dims, d.data()); int* b = bools->get(); readBooleanMatrix(dataset, b); return bools; }
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; }
static bool read_sparse(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo) { int iRet = 0; int iRows = 0; int iCols = 0; int iNbItem = 0; int iComplex = 0; iRet = getSparseDimension(_iDatasetId, &iRows, &iCols, &iNbItem); if (iRet) { return false; } iComplex = isComplexData(_iDatasetId); _pInfo->iDims = 2; _pInfo->piDims[0] = iRows; _pInfo->piDims[1] = iCols; _pInfo->iSize = 20 + iRows * 4 + iNbItem * 4 + (iNbItem * (iComplex + 1) * 8); generateInfo(_pInfo, "sparse"); closeDataSet(_iDatasetId); return true; }
static bool read_boolean(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()); info.size = size * sizeof(int); generateInfo(info); closeDataSet(dataset); return true; }
static bool read_boolean(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo) { int iSize = 0; int iComplex = 0; iSize = getDatasetInfo(_iDatasetId, &iComplex, &_pInfo->iDims, _pInfo->piDims); _pInfo->iSize = (3 + iSize) * 4; generateInfo(_pInfo, "boolean"); closeDataSet(_iDatasetId); return true; }
static bool read_double(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo) { int iSize = 0; int iComplex = 0; iSize = getDatasetInfo(_iDatasetId, &iComplex, &_pInfo->iDims, _pInfo->piDims); _pInfo->iSize = (2 + (iSize * (iComplex + 1))) * 8; generateInfo(_pInfo, "constant"); closeDataSet(_iDatasetId); return true; }
static bool read_integer(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()); int prec = 0; getDatasetPrecision(dataset, &prec); info.size = size * (prec % 10); generateInfo(info); closeDataSet(dataset); return true; }
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; }
static types::InternalType* import_double(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(); } types::Double* dbl = new types::Double(dims, d.data(), complex == 1); double* real = dbl->get(); double* img = dbl->getImg(); if (complex) { readDoubleComplexMatrix(dataset, real, img); } else { readDoubleMatrix(dataset, real); } return dbl; }
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 bool import_undefined(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname) { SciErr sciErr; if (_piAddress) { sciErr = createUndefinedInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos); } else { return false; } if (sciErr.iErr) { printError(&sciErr, 0); return false; } //close undefined dataset closeDataSet(_iDatasetId); 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 read_undefined(int dataset, VarInfo6& info) { info.size = 0; closeDataSet(dataset); return true; }
types::InternalType* import_data(int dataset) { //get var type char* ctype = getScilabTypeFromDataSet6(dataset); std::string type(ctype); FREE(ctype); if (type == g_SCILAB_CLASS_DOUBLE) { return import_double(dataset); } if (type == g_SCILAB_CLASS_STRING) { return import_string(dataset); } if (type == g_SCILAB_CLASS_INT) { return import_int(dataset); } if (type == g_SCILAB_CLASS_BOOLEAN) { return import_boolean(dataset); } if (type == g_SCILAB_CLASS_LIST) { return import_list(dataset, new types::List()); } if (type == g_SCILAB_CLASS_TLIST) { return import_list(dataset, new types::TList()); } if (type == g_SCILAB_CLASS_MLIST) { return import_list(dataset, new types::MList()); } if (type == g_SCILAB_CLASS_STRUCT) { return import_struct(dataset); } if (type == g_SCILAB_CLASS_POLY) { return import_poly(dataset); } if (type == g_SCILAB_CLASS_SPARSE) { return import_sparse(dataset); } if (type == g_SCILAB_CLASS_BSPARSE) { return import_boolean_sparse(dataset); } if (type == g_SCILAB_CLASS_CELL) { return import_cell(dataset); } if (type == g_SCILAB_CLASS_HANDLE) { return import_handles(dataset); } if (type == g_SCILAB_CLASS_MACRO) { return import_macro(dataset); } if (type == g_SCILAB_CLASS_VOID) { closeDataSet(dataset); return new types::Void(); } if (type == g_SCILAB_CLASS_UNDEFINED) { closeDataSet(dataset); return new types::ListUndefined(); } if (type == g_SCILAB_CLASS_USERTYPE) { return import_usertype(dataset); } return nullptr; }
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; }
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 read_undefined(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo) { _pInfo->iSize = 1; closeDataSet(_iDatasetId); return true; }
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; }