rewrite import and export HDF5 gateways in c++ 76/16676/17
Antoine ELIAS [Thu, 21 May 2015 15:02:23 +0000 (17:02 +0200)]
Change-Id: I8d7ff7f45730d4c23d65ebbb83b3c6cb37612f8a

64 files changed:
scilab/modules/ast/includes/types/cell.hxx
scilab/modules/ast/includes/types/macro.hxx
scilab/modules/ast/includes/types/sparse.hxx
scilab/modules/ast/src/cpp/analysis/MacroDef.cpp
scilab/modules/ast/src/cpp/operations/types_comparison_eq.cpp
scilab/modules/ast/src/cpp/types/cell.cpp
scilab/modules/ast/src/cpp/types/macro.cpp
scilab/modules/ast/src/cpp/types/sparse.cpp
scilab/modules/core/sci_gateway/cpp/sci_macr2tree.cpp
scilab/modules/fileio/includes/deleteafile.h
scilab/modules/fileio/src/c/deleteafile.c
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/sci_gateway/cpp/sci_macrovar.cpp
scilab/modules/graphic_objects/src/nographic_objects/nographic_objects.c
scilab/modules/graphics/macros/xload.sci
scilab/modules/graphics/src/nographics/nographics.c
scilab/modules/graphics/tests/nonreg_tests/bug_2250.dia.ref
scilab/modules/graphics/tests/nonreg_tests/bug_2250.tst
scilab/modules/graphics/tests/nonreg_tests/bug_4082.dia.ref
scilab/modules/graphics/tests/nonreg_tests/bug_4082.tst
scilab/modules/hdf5/Makefile.am
scilab/modules/hdf5/Makefile.in
scilab/modules/hdf5/includes/gw_hdf5.h
scilab/modules/hdf5/includes/h5_attributeConstants.h
scilab/modules/hdf5/includes/h5_fileManagement.h
scilab/modules/hdf5/includes/h5_readDataFromFile.h
scilab/modules/hdf5/includes/h5_writeDataToFile.h
scilab/modules/hdf5/includes/hdf5_gw.hxx
scilab/modules/hdf5/sci_gateway/cpp/sci_export_to_hdf5.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v2.cpp [new file with mode: 0644]
scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v3.cpp [new file with mode: 0644]
scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp [new file with mode: 0644]
scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp [new file with mode: 0644]
scilab/modules/hdf5/sci_gateway/hdf5_gateway.xml
scilab/modules/hdf5/src/c/h5_fileManagement.c
scilab/modules/hdf5/src/c/h5_readDataFromFile.c
scilab/modules/hdf5/src/c/h5_writeDataToFile.c
scilab/modules/hdf5/src/c/hdf5.vcxproj
scilab/modules/hdf5/src/c/hdf5.vcxproj.filters
scilab/modules/hdf5/src/cpp/handle_properties.cpp [new file with mode: 0644]
scilab/modules/hdf5/src/cpp/handle_properties.hxx [new file with mode: 0644]
scilab/modules/hdf5/src/cpp/sci_import_from_hdf5_v1.cpp [moved from scilab/modules/hdf5/src/cpp/import_from_hdf5_v1.cpp with 99% similarity]
scilab/modules/hdf5/tests/unit_tests/binary_bit-for-bit.tst [new file with mode: 0644]
scilab/modules/integer/tests/unit_tests/intops.dia.ref
scilab/modules/integer/tests/unit_tests/intops.tst
scilab/modules/io/Makefile.am
scilab/modules/io/Makefile.in
scilab/modules/io/macros/%_sodload.sci
scilab/modules/io/sci_gateway/c/sci_save.c [deleted file]
scilab/modules/io/sci_gateway/cpp/sci_lib.cpp
scilab/modules/io/sci_gateway/cpp/sci_load.cpp
scilab/modules/io/src/cpp/io_gw.cpp
scilab/modules/io/src/cpp/io_gw.vcxproj
scilab/modules/io/src/cpp/io_gw.vcxproj.filters
scilab/modules/io/src/cpp/loadlib.cpp
scilab/modules/io/src/cpp/loadlib.hxx
scilab/modules/io/tests/unit_tests/saveload.dia.ref
scilab/modules/io/tests/unit_tests/saveload.tst
scilab/modules/optimization/tests/nonreg_tests/bug_7093.dia.ref
scilab/modules/optimization/tests/nonreg_tests/bug_7093.tst
scilab/modules/scicos/sci_gateway/cpp/sci_data2sig.cpp
scilab/modules/string/sci_gateway/cpp/sci_string.cpp

index 3ada6f7..05e55f3 100644 (file)
@@ -31,12 +31,12 @@ class EXTERN_AST Cell : public ArrayOf<InternalType*>
 public :
     ~Cell();
     Cell();
-    Cell(int _iRows, int _iCols);
-    Cell(int _iDims, int* _piDims);
+    Cell(int _iRows, int _iCols, InternalType** data = nullptr);
+    Cell(int _iDims, int* _piDims, InternalType** data = nullptr);
 
 private :
     Cell(Cell* _oCellCopyMe);
-    void createCell(int _iDims, int* _piDims);
+    void createCell(int _iDims, int* _piDims, InternalType** data);
 public :
 
     void                whoAmI(void)
index ceea1d6..a44e162 100644 (file)
@@ -84,8 +84,8 @@ public :
         m_stPath = _fileName;
     }
 
-    std::list<symbol::Variable*>*   inputs_get();
-    std::list<symbol::Variable*>*   outputs_get();
+    std::list<symbol::Variable*>*   getInputs();
+    std::list<symbol::Variable*>*   getOutputs();
 
     virtual int getNbInputArgument(void);
     virtual int getNbOutputArgument(void);
index dfa27a4..ec02063 100644 (file)
@@ -69,6 +69,8 @@ struct EXTERN_AST Sparse : GenericType
     **/
     Sparse(Double SPARSE_CONST& xadj, Double SPARSE_CONST& adjncy, Double SPARSE_CONST& src, std::size_t r, std::size_t c);
 
+    //constructor to create a sparse from value extract to another ( save / load operation typically)
+    Sparse(int rows, int cols, int nonzeros, int* inner, int* outer, double* real, double* img);
 
     bool isSparse()
     {
@@ -100,12 +102,14 @@ struct EXTERN_AST Sparse : GenericType
         return getReal(_iIndex % m_iRows, _iIndex / m_iRows);
     }
 
+    double* get();
     double get(int r, int c) const;
     double get(int _iIndex) const
     {
         return get(_iIndex % m_iRows, _iIndex / m_iRows);
     }
 
+    std::complex<double>* getImg();
     std::complex<double> getImg(int r, int c) const;
     std::complex<double> getImg(int _iIndex) const
     {
@@ -363,7 +367,9 @@ struct EXTERN_AST Sparse : GenericType
 
     int* getNbItemByRow(int* _piNbItemByRows);
     int* getColPos(int* _piColPos);
-    int  getNbItemByCol(int* _piNbItemByCols, int* _piRowPos);
+    int* getInnerPtr(int* count);
+    int* getOuterPtr(int* count);
+
 
     /**
        "in-place" cast into a sparse matrix of comlpex values
@@ -561,6 +567,9 @@ struct EXTERN_AST SparseBool : GenericType
 
     SparseBool(SparseBool const& o);
 
+    //constructor to create a sparse from value extract to another ( save / load operation typically)
+    SparseBool(int rows, int cols, int trues, int* inner, int* outer);
+
     bool isSparseBool()
     {
         return true;
@@ -645,8 +654,13 @@ struct EXTERN_AST SparseBool : GenericType
      */
     std::size_t nbTrue(std::size_t i) const;
 
+    void setTrue(bool finalize = true);
+    void setFalse(bool finalize = true);
+
     int* getNbItemByRow(int* _piNbItemByRows);
     int* getColPos(int* _piColPos);
+    int* getInnerPtr(int* count);
+    int* getOuterPtr(int* count);
     /**
        output 1-base column numbers of the non zero elements
        @param out : ptr used as an output iterator over double values
@@ -698,6 +712,7 @@ struct EXTERN_AST SparseBool : GenericType
 
     void whoAmI() SPARSE_CONST;
 
+    bool* get();
     bool get(int r, int c) SPARSE_CONST;
     bool get(int _iIndex) SPARSE_CONST
     {
index b06eed4..dc67cae 100644 (file)
 
 namespace analysis
 {
-    ExistingMacroDef::ExistingMacroDef(types::Macro & _macro) : MacroDef(_macro.outputs_get()->size(), _macro.inputs_get()->size(), _macro.getBody()), name(_macro.getName()), se(nullptr), inputs(MacroDef::asVector(_macro.inputs_get())), outputs(MacroDef::asVector(_macro.outputs_get()))
-    {
-        GlobalsCollector::collect(*this);
-    }
+ExistingMacroDef::ExistingMacroDef(types::Macro & _macro) : MacroDef(_macro.getOutputs()->size(), _macro.getInputs()->size(), _macro.getBody()), name(_macro.getName()), se(nullptr), inputs(MacroDef::asVector(_macro.getInputs())), outputs(MacroDef::asVector(_macro.getOutputs()))
+{
+    GlobalsCollector::collect(*this);
+}
 
-    ExistingMacroDef::ExistingMacroDef(const ExistingMacroDef & emd) : MacroDef(emd.inputs.size(), emd.outputs.size(), emd.original), name(emd.name), se(emd.se->clone()), inputs(emd.inputs), outputs(emd.outputs)
-    {
-        GlobalsCollector::collect(*this);
-    }
+ExistingMacroDef::ExistingMacroDef(const ExistingMacroDef & emd) : MacroDef(emd.inputs.size(), emd.outputs.size(), emd.original), name(emd.name), se(emd.se->clone()), inputs(emd.inputs), outputs(emd.outputs)
+{
+    GlobalsCollector::collect(*this);
+}
 
-    ast::SeqExp & ExistingMacroDef::getBody()
-    {
-       se = static_cast<ast::SeqExp *>(original)->clone();
-        return *se;
-    }
+ast::SeqExp & ExistingMacroDef::getBody()
+{
+    se = static_cast<ast::SeqExp *>(original)->clone();
+    return *se;
+}
 
-    const std::wstring & ExistingMacroDef::getName()
-    {
-        return name;
-    }
+const std::wstring & ExistingMacroDef::getName()
+{
+    return name;
+}
 
-    std::vector<symbol::Symbol> ExistingMacroDef::getIn()
-    {
-        return inputs;
-    }
+std::vector<symbol::Symbol> ExistingMacroDef::getIn()
+{
+    return inputs;
+}
 
-    std::vector<symbol::Symbol> ExistingMacroDef::getOut()
-    {
-        return outputs;
-    }
+std::vector<symbol::Symbol> ExistingMacroDef::getOut()
+{
+    return outputs;
+}
 
-    MacroDef * ExistingMacroDef::clone() const
-    {
-        return new ExistingMacroDef(*this);
-    }
+MacroDef * ExistingMacroDef::clone() const
+{
+    return new ExistingMacroDef(*this);
+}
 
-    DeclaredMacroDef::DeclaredMacroDef(ast::FunctionDec * const _dec) : MacroDef(_dec->getReturns().getVars().size(), _dec->getArgs().getVars().size(), dec), dec(nullptr)
-    {
-        GlobalsCollector::collect(*this);
-    }
+DeclaredMacroDef::DeclaredMacroDef(ast::FunctionDec * const _dec) : MacroDef(_dec->getReturns().getVars().size(), _dec->getArgs().getVars().size(), dec), dec(nullptr)
+{
+    GlobalsCollector::collect(*this);
+}
 
-    ast::SeqExp & DeclaredMacroDef::getBody()
-    {
-       dec = static_cast<ast::FunctionDec *>(original)->clone();
-        return static_cast<ast::SeqExp &>(dec->getBody());
-    }
+ast::SeqExp & DeclaredMacroDef::getBody()
+{
+    dec = static_cast<ast::FunctionDec *>(original)->clone();
+    return static_cast<ast::SeqExp &>(dec->getBody());
+}
 
-    const std::wstring & DeclaredMacroDef::getName()
-    {
-        return static_cast<ast::FunctionDec *>(original)->getSymbol().getName();
-    }
+const std::wstring & DeclaredMacroDef::getName()
+{
+    return static_cast<ast::FunctionDec *>(original)->getSymbol().getName();
+}
 
-    std::vector<symbol::Symbol> DeclaredMacroDef::getIn()
-    {
-        return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getArgs().getVars());
-    }
+std::vector<symbol::Symbol> DeclaredMacroDef::getIn()
+{
+    return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getArgs().getVars());
+}
 
-    std::vector<symbol::Symbol> DeclaredMacroDef::getOut()
-    {
-        return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getReturns().getVars());
-    }
+std::vector<symbol::Symbol> DeclaredMacroDef::getOut()
+{
+    return MacroDef::asVector(&static_cast<ast::FunctionDec *>(original)->getReturns().getVars());
+}
 
-    MacroDef * DeclaredMacroDef::clone() const
-    {
-        return new DeclaredMacroDef(dec ? dec : static_cast<ast::FunctionDec *>(original));
-    }
+MacroDef * DeclaredMacroDef::clone() const
+{
+    return new DeclaredMacroDef(dec ? dec : static_cast<ast::FunctionDec *>(original));
+}
 
 } // namespace analysis
index fa31794..d840be7 100644 (file)
@@ -2690,6 +2690,55 @@ InternalType* compequal_M_M<Sparse, Sparse, SparseBool>(Sparse* _pL, Sparse* _pR
         return new Bool(false);
     }
 
+    //int nnzL = static_cast<int>(_pL->nonZeros());
+    //int rowL = _pL->getRows();
+    //int colL = _pL->getCols();
+    //std::vector<int> rowcolL(nnzL * 2, 0);
+    //_pL->outputRowCol(rowcolL.data());
+
+    //int nnzR = static_cast<int>(_pR->nonZeros());
+    //int rowR = _pR->getRows();
+    //int colR = _pR->getCols();
+    //std::vector<int> rowcolR(nnzR * 2, 0);
+    //_pR->outputRowCol(rowcolR.data());
+
+    //int row = std::max(rowL, rowR);
+    //int col = std::max(colL, colR);
+
+    ////create a boolean sparse matrix with dims of sparses
+    //types::SparseBool* ret = new types::SparseBool(row, col);
+    //ret->setTrue(false);
+
+    ////set %f in each pL values
+    //for (int i = 0; i < nnzL; ++i)
+    //{
+    //    ret->set(rowcolL[i] - 1, rowcolL[i + nnzL] - 1, false, false);
+    //}
+
+    ////set _pR[i] == _pL[i] for each _pR values
+    //if(_pL->isComplex() || _pR->isComplex())
+    //{
+    //    for (int i = 0; i < nnzR; ++i)
+    //    {
+    //        std::complex<double> l = _pL->getImg(rowcolR[i] - 1, rowcolR[i + nnzR] - 1);
+    //        std::complex<double> r = _pR->getImg(rowcolR[i] - 1, rowcolR[i + nnzR] - 1);
+    //        ret->set(rowcolL[i] - 1, rowcolL[i + nnzL] - 1, l == r, false);
+    //    }
+    //}
+    //else
+    //{
+    //    for (int i = 0; i < nnzR; ++i)
+    //    {
+    //        double l = _pL->get(rowcolR[i] - 1, rowcolR[i + nnzR] - 1);
+    //        double r = _pR->get(rowcolR[i] - 1, rowcolR[i + nnzR] - 1);
+    //        ret->set(rowcolL[i] - 1, rowcolL[i + nnzL] - 1, l == r, false);
+    //    }
+    //}
+
+    //ret->finalize();
+    //return ret;
+
+
     return _pR->newEqualTo(*_pL);
 }
 
index 1f03758..9714877 100644 (file)
@@ -31,27 +31,35 @@ namespace types
 Cell::Cell()
 {
     int piDims[2] = {0, 0};
-    createCell(2, piDims);
+    createCell(2, piDims, nullptr);
 }
 
-Cell::Cell(int _iRows, int _iCols)
+Cell::Cell(int _iRows, int _iCols, InternalType** data)
 {
     int piDims[2] = {_iRows, _iCols};
-    createCell(2, piDims);
+    createCell(2, piDims, data);
 }
 
-Cell::Cell(int _iDims, int* _piDims)
+Cell::Cell(int _iDims, int* _piDims, InternalType** data)
 {
-    createCell(_iDims, _piDims);
+    createCell(_iDims, _piDims, data);
 }
 
-void Cell::createCell(int _iDims, int* _piDims)
+void Cell::createCell(int _iDims, int* _piDims, InternalType** data)
 {
     InternalType** pIT = NULL;
     create(_piDims, _iDims, &pIT, NULL);
     for (int i = 0; i < m_iSizeMax; i++)
     {
-        m_pRealData[i] = Double::Empty();
+        if (data == nullptr)
+        {
+            m_pRealData[i] = Double::Empty();
+        }
+        else
+        {
+            m_pRealData[i] = data[i];
+        }
+
         m_pRealData[i]->IncreaseRef();
     }
 #ifndef NDEBUG
index 3bf66a9..b9f4937 100644 (file)
@@ -406,12 +406,12 @@ Callable::ReturnValue Macro::call(typed_list &in, optional_list &opt, int _iRetC
     return RetVal;
 }
 
-std::list<symbol::Variable*>* Macro::inputs_get()
+std::list<symbol::Variable*>* Macro::getInputs()
 {
     return m_inputArgs;
 }
 
-std::list<symbol::Variable*>* Macro::outputs_get()
+std::list<symbol::Variable*>* Macro::getOutputs()
 {
     return m_outputArgs;
 }
@@ -443,7 +443,7 @@ bool Macro::operator==(const InternalType& it)
     types::Macro* pRight = const_cast<InternalType &>(it).getAs<types::Macro>();
 
     //check inputs
-    pInput = pRight->inputs_get();
+    pInput = pRight->getInputs();
     if (pInput->size() != m_inputArgs->size())
     {
         return false;
@@ -462,7 +462,7 @@ bool Macro::operator==(const InternalType& it)
     }
 
     //check outputs
-    pOutput = pRight->outputs_get();
+    pOutput = pRight->getOutputs();
     if (pOutput->size() != m_outputArgs->size())
     {
         return false;
index 1dc4e44..02e66bc 100644 (file)
@@ -382,6 +382,62 @@ Sparse::Sparse(Double SPARSE_CONST& xadj, Double SPARSE_CONST& adjncy, Double SP
 #endif
 }
 
+Sparse::Sparse(int rows, int cols, int nonzeros, int* inner, int* outer, double* real, double* img)
+{
+    int* out = nullptr;
+    int* in = nullptr;
+
+    if (img)
+    {
+        matrixCplx = new CplxSparse_t(rows, cols);
+        matrixCplx->reserve((int)nonzeros);
+        out = matrixCplx->outerIndexPtr();
+        in = matrixCplx->innerIndexPtr();
+        matrixReal = nullptr;
+    }
+    else
+    {
+        matrixReal = new RealSparse_t(rows, cols);
+        matrixReal->reserve((int)nonzeros);
+        out = matrixReal->outerIndexPtr();
+        in = matrixReal->innerIndexPtr();
+        matrixCplx = nullptr;
+    }
+
+    //update outerIndexPtr
+    memcpy(out, outer, sizeof(int) * (rows + 1));
+    //update innerIndexPtr
+    memcpy(in, inner, sizeof(int) * nonzeros);
+
+    if (img)
+    {
+        std::complex<double>* data = matrixCplx->valuePtr();
+        for (int i = 0; i < nonzeros; ++i)
+        {
+            data[i] = std::complex<double>(real[i], img[i]);
+        }
+    }
+    else
+    {
+        double* data = matrixReal->valuePtr();
+        for (int i = 0; i < nonzeros; ++i)
+        {
+            data[i] = real[i];
+        }
+
+    }
+
+    m_iCols = cols;
+    m_iRows = rows;
+    m_iSize = cols * rows;
+    m_iDims = 2;
+    m_piDims[0] = m_iRows;
+    m_piDims[1] = m_iCols;
+
+    matrixCplx ? matrixCplx->resizeNonZeros(nonzeros) : matrixReal->resizeNonZeros(nonzeros);
+    //finalize();
+}
+
 template<typename DestIter>
 void Sparse::create(int rows, int cols, Double SPARSE_CONST& src, DestIter o, std::size_t n)
 {
@@ -557,6 +613,16 @@ bool Sparse::isComplex() const
 }
 
 // TODO: should have both a bounds checking and a non-checking interface to elt access
+double* Sparse::get()
+{
+    if (isComplex() == false)
+    {
+        return matrixReal->valuePtr();
+    }
+
+    return nullptr;
+}
+
 double  Sparse::get(int _iRows, int _iCols) const
 {
     return getReal(_iRows, _iCols);
@@ -576,6 +642,16 @@ double Sparse::getReal(int _iRows, int _iCols) const
     return res;
 }
 
+std::complex<double>* Sparse::getImg()
+{
+    if (isComplex())
+    {
+        return matrixCplx->valuePtr();
+    }
+
+    return nullptr;
+}
+
 std::complex<double> Sparse::getImg(int _iRows, int _iCols) const
 {
     std::complex<double> res;
@@ -2030,6 +2106,40 @@ int* Sparse::getColPos(int* _piColPos)
     return _piColPos;
 }
 
+int* Sparse::getInnerPtr(int* count)
+{
+    int* ret = nullptr;
+    if (isComplex())
+    {
+        ret = matrixCplx->innerIndexPtr();
+        *count = matrixCplx->innerSize();
+    }
+    else
+    {
+        ret = matrixReal->innerIndexPtr();
+        *count = matrixReal->innerSize();
+    }
+
+    return ret;
+}
+
+int* Sparse::getOuterPtr(int* count)
+{
+    int* ret = nullptr;
+    if (isComplex())
+    {
+        ret = matrixCplx->outerIndexPtr();
+        *count = matrixCplx->outerSize();
+    }
+    else
+    {
+        ret = matrixReal->outerIndexPtr();
+        *count = matrixReal->outerSize();
+    }
+
+    return ret;
+}
+
 namespace
 {
 template<typename S> struct GetReal: std::unary_function<typename S::InnerIterator, double>
@@ -2356,6 +2466,37 @@ SparseBool::SparseBool(BoolSparse_t* src) : matrixBool(src)
 #endif
 }
 
+SparseBool::SparseBool(int rows, int cols, int trues, int* inner, int* outer)
+{
+    int* out = nullptr;
+    int* in = nullptr;
+
+    matrixBool = new BoolSparse_t(rows, cols);
+    matrixBool->reserve((int)trues);
+    out = matrixBool->outerIndexPtr();
+    in = matrixBool->innerIndexPtr();
+
+    //update outerIndexPtr
+    memcpy(out, outer, sizeof(int) * (rows + 1));
+    //update innerIndexPtr
+    memcpy(in, inner, sizeof(int) * trues);
+
+    bool* data = matrixBool->valuePtr();
+    for (int i = 0; i < trues; ++i)
+    {
+        data[i] = true;
+    }
+
+    m_iCols = cols;
+    m_iRows = rows;
+    m_iSize = cols * rows;
+    m_iDims = 2;
+    m_piDims[0] = m_iRows;
+    m_piDims[1] = m_iCols;
+
+    matrixBool->resizeNonZeros(trues);
+}
+
 void SparseBool::create2(int rows, int cols, Bool SPARSE_CONST& src, Double SPARSE_CONST& idx)
 {
     int nnz = src.getSize();
@@ -3259,6 +3400,55 @@ std::size_t SparseBool::nbTrue(std::size_t r) const
     return piIndex[r + 1] - piIndex[r];
 }
 
+
+void SparseBool::setTrue(bool finalize)
+{
+    int rows = getRows();
+    int cols = getCols();
+
+    typedef Eigen::Triplet<bool> triplet;
+    std::vector<triplet> tripletList;
+
+    for (int i = 0; i < rows; ++i)
+    {
+        for (int j = 0; j < cols; ++j)
+        {
+            tripletList.push_back(triplet(i, j, true));
+        }
+    }
+
+    matrixBool->setFromTriplets(tripletList.begin(), tripletList.end());
+
+    if (finalize)
+    {
+        matrixBool->finalize();
+    }
+}
+
+void SparseBool::setFalse(bool finalize)
+{
+    int rows = getRows();
+    int cols = getCols();
+
+    typedef Eigen::Triplet<bool> triplet;
+    std::vector<triplet> tripletList;
+
+    for (int i = 0; i < rows; ++i)
+    {
+        for (int j = 0; j < cols; ++j)
+        {
+            tripletList.push_back(triplet(i, j, false));
+        }
+    }
+
+    matrixBool->setFromTriplets(tripletList.begin(), tripletList.end());
+
+    if (finalize)
+    {
+        matrixBool->finalize();
+    }
+}
+
 int* SparseBool::getNbItemByRow(int* _piNbItemByRows)
 {
     int* piNbItemByRows = new int[getRows() + 1];
@@ -3289,6 +3479,19 @@ int* SparseBool::outputRowCol(int* out)const
     return sparseTransform(*matrixBool, sparseTransform(*matrixBool, out, GetRow<BoolSparse_t>()), GetCol<BoolSparse_t>());
 }
 
+int* SparseBool::getInnerPtr(int* count)
+{
+    *count = matrixBool->innerSize();
+    return matrixBool->innerIndexPtr();
+}
+
+int* SparseBool::getOuterPtr(int* count)
+{
+    *count = matrixBool->outerSize();
+    return matrixBool->outerIndexPtr();
+}
+
+
 bool SparseBool::operator==(const InternalType& it) SPARSE_CONST
 {
     SparseBool* otherSparse = const_cast<SparseBool*>(dynamic_cast<SparseBool const*>(&it));/* types::GenericType is not const-correct :( */
@@ -3322,6 +3525,7 @@ bool SparseBool::set(int _iRows, int _iCols, bool _bVal, bool _bFinalize) SPARSE
     {
         finalize();
     }
+
     return true;
 }
 
index 5a556f3..074d1e9 100644 (file)
@@ -58,8 +58,8 @@ types::Function::ReturnValue sci_macr2tree(types::typed_list &in, int _iRetCount
         macro = pIT->getAs<types::Macro>();
     }
 
-    std::list<symbol::Variable*>* outputs = macro->outputs_get();
-    std::list<symbol::Variable*>* inputs = macro->inputs_get();
+    std::list<symbol::Variable*>* outputs = macro->getOutputs();
+    std::list<symbol::Variable*>* inputs = macro->getInputs();
     ast::SeqExp* body = macro->getBody();
 
     //create a tlist "program"
index 55ff06d..f2421bf 100644 (file)
 * @param[in] filename
 * @return BOOLEAN TRUE or FALSE
 */
-FILEIO_IMPEXP BOOL deleteafile(char *filename);
+FILEIO_IMPEXP BOOL deleteafile(const char *filename);
 
 /**
 * delete a file by filename
 * @param[in] filenameW wide string
 * @return BOOLEAN TRUE or FALSE
 */
-FILEIO_IMPEXP BOOL deleteafileW(wchar_t *filenameW);
+FILEIO_IMPEXP BOOL deleteafileW(const wchar_t *filenameW);
 
 #endif /* __DELETEAFILE_H__ */
 /*--------------------------------------------------------------------------*/
index fd4f64d..5b06b09 100644 (file)
@@ -22,7 +22,7 @@
 #include "charEncoding.h"
 #include "sci_malloc.h"
 /*--------------------------------------------------------------------------*/
-BOOL deleteafile(char *filename)
+BOOL deleteafile(const char *filename)
 {
 #ifndef _MSC_VER
     {
@@ -64,7 +64,7 @@ BOOL deleteafile(char *filename)
 #endif
 }
 /*--------------------------------------------------------------------------*/
-BOOL deleteafileW(wchar_t *filenameW)
+BOOL deleteafileW(const wchar_t *filenameW)
 {
     BOOL bOK = FALSE;
 #ifndef _MSC_VER
index 7c3cbf3..d158657 100644 (file)
@@ -235,8 +235,8 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         }
 
         // unable for macro with varargin or varargout
-        auto inputs = pMacro->inputs_get();
-        auto outputs = pMacro->outputs_get();
+        auto inputs = pMacro->getInputs();
+        auto outputs = pMacro->getOutputs();
         if ((inputs->size() != 0 && inputs->back()->getSymbol().getName() == L"varargin") ||
                 outputs->size() != 0 && outputs->back()->getSymbol().getName() == L"varargout")
         {
index bdc5d6b..554213b 100644 (file)
@@ -75,8 +75,8 @@ Function::ReturnValue sci_macrovar(types::typed_list &in, int _iRetCount, types:
 
     MacrovarVisitor visit;
 
-    addIn(visit, pM->inputs_get());
-    addOut(visit, pM->outputs_get());
+    addIn(visit, pM->getInputs());
+    addOut(visit, pM->getOutputs());
 
     pM->getBody()->accept(visit);
 
index 1afe8e2..15d72fd 100644 (file)
@@ -80,7 +80,37 @@ BOOL setGraphicObjectProperty(int iUID, const int _iPropertyName, void const* _p
     return FALSE;
 }
 /*--------------------------------------------------------------------------*/
+BOOL setGraphicObjectPropertyAndNoWarn(int iUID, const int _iPropertyName, void const* _pvValue, enum _ReturnType_ _valueTtype, int numElements)
+{
+    return FALSE;
+}
+/*--------------------------------------------------------------------------*/
 void setGraphicObjectRelationship(int iUID, int iUID2)
 {
 }
 /*--------------------------------------------------------------------------*/
+long getHandle(int UID)
+{
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
+int createFigure(int iDockable, int iMenubarType, int iToolbarType, int iDefaultAxes, int iVisible)
+{
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
+int createNewFigureWithAxes(void)
+{
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
+int getObjectFromHandle(void)
+{
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
+int getValidDefaultFigureId(void)
+{
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
index 2b5cbf2..babaad3 100644 (file)
@@ -19,6 +19,12 @@ function []=xload(fil,num)
     if  argn(2)==2 then scf(num),end
     f=gcf()
     res = execstr("load(fil)","errcatch") ;
+    // Get latest figure created by load
+    loadedFig = gcf();
+    for kC=1:size(loadedFig.children, "*")
+        copy(loadedFig.children(kC), f); // Copy axes
+    end
+    delete(loadedFig); // Delete it, returned figure will be the one set as current by xload
     if res==0 then
         f.visible="on"
         f.immediate_drawing="on";
index 209ecb8..6a3cea7 100644 (file)
@@ -368,6 +368,14 @@ void cloneAxesModel(int pstFigureUID)
 /*--------------------------------------------------------------------------*/
 int createNewFigureWithAxes(void)
 {
-    return NULL;
+    return 0;
 }
 
+/*--------------------------------------------------------------------------*/
+int getOrCreateDefaultSubwin(void)
+{
+    return 0;
+}
+
+/*--------------------------------------------------------------------------*/
+
index 7b1cdaa..86423d2 100644 (file)
@@ -18,7 +18,7 @@ backgroundvariable = 5;
 f.background = backgroundvariable;
 userdatavariable = ["my user_data - entry will not be saved, - but i.e. the backgroundvariable will be saved."];
 f.user_data = userdatavariable;
-save(pathconvert(TMPDIR+"/bug_2250.scg",%f), "f")
+save(pathconvert(TMPDIR+"/bug_2250.scg",%f), "f");
 delete(f)
 load(pathconvert(TMPDIR+"/bug_2250.scg",%f))
 figureloaded = gcf();
index 57ad6db..2a0ce35 100644 (file)
@@ -25,7 +25,7 @@ userdatavariable = ["my user_data - entry will not be saved, - but i.e. the back
 
 f.user_data = userdatavariable;
 
-save(pathconvert(TMPDIR+"/bug_2250.scg",%f), "f")
+save(pathconvert(TMPDIR+"/bug_2250.scg",%f), "f");
 
 delete(f)
 
index 9e35797..81c8f3e 100644 (file)
@@ -17,8 +17,8 @@ t=0:0.01:10;
 subplot(211),plot2d(t,sin(t))
 subplot(212),plot2d(t,sin(3*t))
 f = gcf();
-save(TMPDIR+'/foo.scg', "f") //or xsave
+save(TMPDIR+"/foo.scg", "f"); //or xsave
 clf()
-load(TMPDIR+'/foo.scg') //or xload
+load(TMPDIR+"/foo.scg") //or xload
 f = gcf();
 if f.figure_name <> _("Graphic window number %d") then bugmes();quit;end
index f90cb08..f7edb28 100644 (file)
 // http://bugzilla.scilab.org/show_bug.cgi?id=4082
 //
 // <-- Short Description -->
-// 
+//
 // After save ( xsave ) a figure, the load command ( save/xsave ) modify the name of the figure.
 
 t=0:0.01:10;
 subplot(211),plot2d(t,sin(t))
 subplot(212),plot2d(t,sin(3*t))
 f = gcf();
-save(TMPDIR+'/foo.scg',"f") //or xsave
+save(TMPDIR+"/foo.scg","f"); //or xsave
 clf()
-load(TMPDIR+'/foo.scg') //or xload
+load(TMPDIR+"/foo.scg") //or xload
 
 f = gcf();
 
index 4e3e6cf..6b29e2a 100644 (file)
@@ -20,7 +20,7 @@ HDF5_SOURCES = \
     src/c/h5_writeDataToFile.c \
     src/c/h5_readDataFromFile.c \
     src/c/h5_readDataFromFile_v1.c \
-    src/cpp/import_from_hdf5_v1.cpp \
+    src/cpp/sci_import_from_hdf5_v1.cpp \
     src/cpp/listvar_in_hdf5_v1.cpp
 
 HDF5_CXX_SOURCES = \
@@ -46,14 +46,19 @@ HDF5_CXX_SOURCES = \
     src/cpp/H5ArrayData.cpp \
     src/cpp/H5VlenData.cpp \
     src/cpp/H5Options.cpp \
+    src/cpp/handle_properties.cpp \
     src/c/DllmainHdf5.c
 
 GATEWAY_CXX_SOURCES = \
     sci_gateway/cpp/hdf5_gw.cpp \
     sci_gateway/cpp/sci_export_to_hdf5.cpp \
     sci_gateway/cpp/sci_import_from_hdf5.cpp \
+    sci_gateway/cpp/sci_import_from_hdf5_v2.cpp \
+    sci_gateway/cpp/sci_import_from_hdf5_v3.cpp \
     sci_gateway/cpp/sci_is_hdf5_file.cpp \
     sci_gateway/cpp/sci_listvar_in_hdf5.cpp \
+    sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp \
+    sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp \
     sci_gateway/cpp/sci_h5dump.cpp \
     sci_gateway/cpp/sci_h5open.cpp \
     sci_gateway/cpp/sci_h5close.cpp \
@@ -116,6 +121,9 @@ libscihdf5_la_CPPFLAGS = \
     -I$(top_srcdir)/modules/localization/includes/ \
     -I$(top_srcdir)/modules/fileio/includes/ \
     -I$(top_srcdir)/modules/string/includes/ \
+    -I$(top_srcdir)/modules/console/includes/ \
+    -I$(top_srcdir)/modules/graphic_objects/includes/ \
+    -I$(top_srcdir)/modules/graphics/includes/ \
     $(JAVA_JNI_INCLUDE) \
     $(HDF5_CFLAGS) \
     $(AM_CPPFLAGS) \
index 8172392..a492fb5 100644 (file)
@@ -173,7 +173,7 @@ am__objects_1 = src/c/libscihdf5_algo_la-h5_fileManagement.lo \
        src/c/libscihdf5_algo_la-h5_writeDataToFile.lo \
        src/c/libscihdf5_algo_la-h5_readDataFromFile.lo \
        src/c/libscihdf5_algo_la-h5_readDataFromFile_v1.lo \
-       src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo \
+       src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo \
        src/cpp/libscihdf5_algo_la-listvar_in_hdf5_v1.lo
 am__objects_2 = src/cpp/libscihdf5_algo_la-H5Attribute.lo \
        src/cpp/libscihdf5_algo_la-H5AttributesList.lo \
@@ -197,6 +197,7 @@ am__objects_2 = src/cpp/libscihdf5_algo_la-H5Attribute.lo \
        src/cpp/libscihdf5_algo_la-H5ArrayData.lo \
        src/cpp/libscihdf5_algo_la-H5VlenData.lo \
        src/cpp/libscihdf5_algo_la-H5Options.lo \
+       src/cpp/libscihdf5_algo_la-handle_properties.lo \
        src/c/libscihdf5_algo_la-DllmainHdf5.lo
 am_libscihdf5_algo_la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libscihdf5_algo_la_OBJECTS = $(am_libscihdf5_algo_la_OBJECTS)
@@ -209,8 +210,12 @@ libscihdf5_la_DEPENDENCIES = libscihdf5-algo.la $(am__DEPENDENCIES_1)
 am__objects_3 = sci_gateway/cpp/libscihdf5_la-hdf5_gw.lo \
        sci_gateway/cpp/libscihdf5_la-sci_export_to_hdf5.lo \
        sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5.lo \
+       sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo \
+       sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo \
        sci_gateway/cpp/libscihdf5_la-sci_is_hdf5_file.lo \
        sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5.lo \
+       sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo \
+       sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo \
        sci_gateway/cpp/libscihdf5_la-sci_h5dump.lo \
        sci_gateway/cpp/libscihdf5_la-sci_h5open.lo \
        sci_gateway/cpp/libscihdf5_la-sci_h5close.lo \
@@ -615,7 +620,7 @@ HDF5_SOURCES = \
     src/c/h5_writeDataToFile.c \
     src/c/h5_readDataFromFile.c \
     src/c/h5_readDataFromFile_v1.c \
-    src/cpp/import_from_hdf5_v1.cpp \
+    src/cpp/sci_import_from_hdf5_v1.cpp \
     src/cpp/listvar_in_hdf5_v1.cpp
 
 HDF5_CXX_SOURCES = \
@@ -641,14 +646,19 @@ HDF5_CXX_SOURCES = \
     src/cpp/H5ArrayData.cpp \
     src/cpp/H5VlenData.cpp \
     src/cpp/H5Options.cpp \
+    src/cpp/handle_properties.cpp \
     src/c/DllmainHdf5.c
 
 GATEWAY_CXX_SOURCES = \
     sci_gateway/cpp/hdf5_gw.cpp \
     sci_gateway/cpp/sci_export_to_hdf5.cpp \
     sci_gateway/cpp/sci_import_from_hdf5.cpp \
+    sci_gateway/cpp/sci_import_from_hdf5_v2.cpp \
+    sci_gateway/cpp/sci_import_from_hdf5_v3.cpp \
     sci_gateway/cpp/sci_is_hdf5_file.cpp \
     sci_gateway/cpp/sci_listvar_in_hdf5.cpp \
+    sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp \
+    sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp \
     sci_gateway/cpp/sci_h5dump.cpp \
     sci_gateway/cpp/sci_h5open.cpp \
     sci_gateway/cpp/sci_h5close.cpp \
@@ -708,6 +718,9 @@ libscihdf5_la_CPPFLAGS = \
     -I$(top_srcdir)/modules/localization/includes/ \
     -I$(top_srcdir)/modules/fileio/includes/ \
     -I$(top_srcdir)/modules/string/includes/ \
+    -I$(top_srcdir)/modules/console/includes/ \
+    -I$(top_srcdir)/modules/graphic_objects/includes/ \
+    -I$(top_srcdir)/modules/graphics/includes/ \
     $(JAVA_JNI_INCLUDE) \
     $(HDF5_CFLAGS) \
     $(AM_CPPFLAGS) \
@@ -979,7 +992,7 @@ src/cpp/$(am__dirstamp):
 src/cpp/$(DEPDIR)/$(am__dirstamp):
        @$(MKDIR_P) src/cpp/$(DEPDIR)
        @: > src/cpp/$(DEPDIR)/$(am__dirstamp)
-src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo:  \
+src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscihdf5_algo_la-listvar_in_hdf5_v1.lo:  \
        src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1027,6 +1040,8 @@ src/cpp/libscihdf5_algo_la-H5VlenData.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/cpp/libscihdf5_algo_la-H5Options.lo: src/cpp/$(am__dirstamp) \
        src/cpp/$(DEPDIR)/$(am__dirstamp)
+src/cpp/libscihdf5_algo_la-handle_properties.lo:  \
+       src/cpp/$(am__dirstamp) src/cpp/$(DEPDIR)/$(am__dirstamp)
 src/c/libscihdf5_algo_la-DllmainHdf5.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 
@@ -1047,12 +1062,24 @@ sci_gateway/cpp/libscihdf5_la-sci_export_to_hdf5.lo:  \
 sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscihdf5_la-sci_is_hdf5_file.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo:  \
+       sci_gateway/cpp/$(am__dirstamp) \
+       sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/cpp/libscihdf5_la-sci_h5dump.lo:  \
        sci_gateway/cpp/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@@ -1165,8 +1192,12 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5umount.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5write.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v2.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v3.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_is_hdf5_file.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v2.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v3.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_percent_H5Object_e.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_percent_H5Object_fieldnames.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_percent_H5Object_p.Plo@am__quote@
@@ -1197,8 +1228,9 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-H5VariableScope.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-H5VlenData.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-HDF5Scilab.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-import_from_hdf5_v1.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-handle_properties.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-listvar_in_hdf5_v1.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscihdf5_algo_la-sci_import_from_hdf5_v1.Plo@am__quote@
 
 .c.o:
 @am__fastdepCC_TRUE@   $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -1283,12 +1315,12 @@ src/c/libscihdf5_algo_la-DllmainHdf5.lo: src/c/DllmainHdf5.c
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
 
-src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo: src/cpp/import_from_hdf5_v1.cpp
-@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscihdf5_algo_la-import_from_hdf5_v1.Tpo -c -o src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo `test -f 'src/cpp/import_from_hdf5_v1.cpp' || echo '$(srcdir)/'`src/cpp/import_from_hdf5_v1.cpp
-@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscihdf5_algo_la-import_from_hdf5_v1.Tpo src/cpp/$(DEPDIR)/libscihdf5_algo_la-import_from_hdf5_v1.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/import_from_hdf5_v1.cpp' object='src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo' libtool=yes @AMDEPBACKSLASH@
+src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo: src/cpp/sci_import_from_hdf5_v1.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscihdf5_algo_la-sci_import_from_hdf5_v1.Tpo -c -o src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo `test -f 'src/cpp/sci_import_from_hdf5_v1.cpp' || echo '$(srcdir)/'`src/cpp/sci_import_from_hdf5_v1.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscihdf5_algo_la-sci_import_from_hdf5_v1.Tpo src/cpp/$(DEPDIR)/libscihdf5_algo_la-sci_import_from_hdf5_v1.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/sci_import_from_hdf5_v1.cpp' object='src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo' libtool=yes @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscihdf5_algo_la-import_from_hdf5_v1.lo `test -f 'src/cpp/import_from_hdf5_v1.cpp' || echo '$(srcdir)/'`src/cpp/import_from_hdf5_v1.cpp
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscihdf5_algo_la-sci_import_from_hdf5_v1.lo `test -f 'src/cpp/sci_import_from_hdf5_v1.cpp' || echo '$(srcdir)/'`src/cpp/sci_import_from_hdf5_v1.cpp
 
 src/cpp/libscihdf5_algo_la-listvar_in_hdf5_v1.lo: src/cpp/listvar_in_hdf5_v1.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscihdf5_algo_la-listvar_in_hdf5_v1.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscihdf5_algo_la-listvar_in_hdf5_v1.Tpo -c -o src/cpp/libscihdf5_algo_la-listvar_in_hdf5_v1.lo `test -f 'src/cpp/listvar_in_hdf5_v1.cpp' || echo '$(srcdir)/'`src/cpp/listvar_in_hdf5_v1.cpp
@@ -1451,6 +1483,13 @@ src/cpp/libscihdf5_algo_la-H5Options.lo: src/cpp/H5Options.cpp
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscihdf5_algo_la-H5Options.lo `test -f 'src/cpp/H5Options.cpp' || echo '$(srcdir)/'`src/cpp/H5Options.cpp
 
+src/cpp/libscihdf5_algo_la-handle_properties.lo: src/cpp/handle_properties.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT src/cpp/libscihdf5_algo_la-handle_properties.lo -MD -MP -MF src/cpp/$(DEPDIR)/libscihdf5_algo_la-handle_properties.Tpo -c -o src/cpp/libscihdf5_algo_la-handle_properties.lo `test -f 'src/cpp/handle_properties.cpp' || echo '$(srcdir)/'`src/cpp/handle_properties.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) src/cpp/$(DEPDIR)/libscihdf5_algo_la-handle_properties.Tpo src/cpp/$(DEPDIR)/libscihdf5_algo_la-handle_properties.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='src/cpp/handle_properties.cpp' object='src/cpp/libscihdf5_algo_la-handle_properties.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_algo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o src/cpp/libscihdf5_algo_la-handle_properties.lo `test -f 'src/cpp/handle_properties.cpp' || echo '$(srcdir)/'`src/cpp/handle_properties.cpp
+
 sci_gateway/cpp/libscihdf5_la-hdf5_gw.lo: sci_gateway/cpp/hdf5_gw.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-hdf5_gw.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-hdf5_gw.Tpo -c -o sci_gateway/cpp/libscihdf5_la-hdf5_gw.lo `test -f 'sci_gateway/cpp/hdf5_gw.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/hdf5_gw.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-hdf5_gw.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-hdf5_gw.Plo
@@ -1472,6 +1511,20 @@ sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5.lo: sci_gateway/cpp/sci_impor
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5.lo `test -f 'sci_gateway/cpp/sci_import_from_hdf5.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_import_from_hdf5.cpp
 
+sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo: sci_gateway/cpp/sci_import_from_hdf5_v2.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v2.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo `test -f 'sci_gateway/cpp/sci_import_from_hdf5_v2.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_import_from_hdf5_v2.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v2.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v2.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_import_from_hdf5_v2.cpp' object='sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v2.lo `test -f 'sci_gateway/cpp/sci_import_from_hdf5_v2.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_import_from_hdf5_v2.cpp
+
+sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo: sci_gateway/cpp/sci_import_from_hdf5_v3.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v3.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo `test -f 'sci_gateway/cpp/sci_import_from_hdf5_v3.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_import_from_hdf5_v3.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v3.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_import_from_hdf5_v3.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_import_from_hdf5_v3.cpp' object='sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_import_from_hdf5_v3.lo `test -f 'sci_gateway/cpp/sci_import_from_hdf5_v3.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_import_from_hdf5_v3.cpp
+
 sci_gateway/cpp/libscihdf5_la-sci_is_hdf5_file.lo: sci_gateway/cpp/sci_is_hdf5_file.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_is_hdf5_file.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_is_hdf5_file.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_is_hdf5_file.lo `test -f 'sci_gateway/cpp/sci_is_hdf5_file.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_is_hdf5_file.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_is_hdf5_file.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_is_hdf5_file.Plo
@@ -1486,6 +1539,20 @@ sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5.lo: sci_gateway/cpp/sci_listva
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5.lo `test -f 'sci_gateway/cpp/sci_listvar_in_hdf5.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_listvar_in_hdf5.cpp
 
+sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo: sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v2.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo `test -f 'sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v2.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v2.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp' object='sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v2.lo `test -f 'sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp
+
+sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo: sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v3.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo `test -f 'sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v3.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_listvar_in_hdf5_v3.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp' object='sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo `test -f 'sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp
+
 sci_gateway/cpp/libscihdf5_la-sci_h5dump.lo: sci_gateway/cpp/sci_h5dump.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscihdf5_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscihdf5_la-sci_h5dump.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5dump.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_h5dump.lo `test -f 'sci_gateway/cpp/sci_h5dump.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_h5dump.cpp
 @am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5dump.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5dump.Plo
index 8810262..bc25b70 100644 (file)
@@ -18,9 +18,9 @@
 HDF5_SCILAB_IMPEXP int Initialize(void);
 HDF5_SCILAB_IMPEXP int Finalize(void);
 /*--------------------------------------------------------------------------*/
-HDF5_SCILAB_IMPEXP int sci_export_to_hdf5(char *fname, int* pvApiCtx);
-HDF5_SCILAB_IMPEXP int sci_import_from_hdf5(char *fname, int* pvApiCtx);
-HDF5_SCILAB_IMPEXP int sci_listvar_in_hdf5(char *fname, int* pvApiCtx);
+HDF5_SCILAB_IMPEXP int sci_import_from_hdf5_v1(char *fname, int* pvApiCtx);
+HDF5_SCILAB_IMPEXP int sci_import_from_hdf5_v2(char *fname, int* pvApiCtx);
+HDF5_SCILAB_IMPEXP int sci_listvar_in_hdf5_v2(char *fname, int* pvApiCtx);
 HDF5_SCILAB_IMPEXP int sci_is_hdf5_file(char *fname, int* pvApiCtx);
 HDF5_SCILAB_IMPEXP int sci_h5dump(char *fname, int* pvApiCtx);
 HDF5_SCILAB_IMPEXP int sci_h5open(char *fname, int* pvApiCtx);
index c701827..838afa8 100644 (file)
 #ifndef __H5_ATTRIBUTECONSTATS_H__
 #define __H5_ATTRIBUTECONSTATS_H__
 
-#define SOD_FILE_VERSION     2
+#define SOD_FILE_VERSION     3
 
-static const char g_SCILAB_CLASS[]              =      "SCILAB_Class";
-static const char g_SCILAB_CLASS_EMPTY[]        =      "SCILAB_empty";
-static const char g_SCILAB_CLASS_VARNAME[]      =      "SCILAB_varname";
-static const char g_SCILAB_CLASS_COMPLEX[]      =      "SCILAB_complex";
-static const char g_SCILAB_CLASS_PREC[]         =      "SCILAB_precision";
-static const char g_SCILAB_CLASS_ROWS[]         =      "SCILAB_rows";
-static const char g_SCILAB_CLASS_COLS[]         =      "SCILAB_cols";
-static const char g_SCILAB_CLASS_ITEMS[]        =      "SCILAB_items";
-static const char g_SCILAB_CLASS_SOD_VERSION[] =       "SCILAB_sod_version";
-static const char g_SCILAB_CLASS_SCI_VERSION[]  =      "SCILAB_scilab_version";
+static const char g_SCILAB_CLASS[]              = "SCILAB_Class";
+static const char g_SCILAB_CLASS_EMPTY[]        = "SCILAB_empty";
+static const char g_SCILAB_CLASS_VARNAME[]      = "SCILAB_varname";
+static const char g_SCILAB_CLASS_COMPLEX[]      = "SCILAB_complex";
+static const char g_SCILAB_CLASS_PREC[]         = "SCILAB_precision";
+static const char g_SCILAB_CLASS_ROWS[]         = "SCILAB_rows";
+static const char g_SCILAB_CLASS_COLS[]         = "SCILAB_cols";
+static const char g_SCILAB_CLASS_ITEMS[]        = "SCILAB_items";
+static const char g_SCILAB_CLASS_SOD_VERSION[]  = "SCILAB_sod_version";
+static const char g_SCILAB_CLASS_SCI_VERSION[]  = "SCILAB_scilab_version";
 
 
-static const char g_SCILAB_CLASS_DOUBLE[]       =      "double";
-static const char g_SCILAB_CLASS_STRING[]       =      "string";
-static const char g_SCILAB_CLASS_BOOLEAN[]      =      "boolean";
-static const char g_SCILAB_CLASS_INT[]          =      "integer";
-static const char g_SCILAB_CLASS_POLY[]         =      "polynomial";
-static const char g_SCILAB_CLASS_SPARSE[]       =      "sparse";
-static const char g_SCILAB_CLASS_BSPARSE[]      =      "boolean sparse";
-static const char g_SCILAB_CLASS_LIST[]         =      "list";
-static const char g_SCILAB_CLASS_TLIST[]        =      "tlist";
-static const char g_SCILAB_CLASS_MLIST[]        =      "mlist";
-static const char g_SCILAB_CLASS_VOID[]         =      "void";
-static const char g_SCILAB_CLASS_UNDEFINED[]    =      "undefined";
+static const char g_SCILAB_CLASS_DOUBLE[]       = "double";
+static const char g_SCILAB_CLASS_STRING[]       = "string";
+static const char g_SCILAB_CLASS_BOOLEAN[]      = "boolean";
+static const char g_SCILAB_CLASS_INT[]          = "integer";
+static const char g_SCILAB_CLASS_POLY[]         = "polynomial";
+static const char g_SCILAB_CLASS_SPARSE[]       = "sparse";
+static const char g_SCILAB_CLASS_BSPARSE[]      = "boolean sparse";
+static const char g_SCILAB_CLASS_LIST[]         = "list";
+static const char g_SCILAB_CLASS_TLIST[]        = "tlist";
+static const char g_SCILAB_CLASS_MLIST[]        = "mlist";
+static const char g_SCILAB_CLASS_VOID[]         = "void";
+static const char g_SCILAB_CLASS_UNDEFINED[]    = "undefined";
+static const char g_SCILAB_CLASS_STRUCT[]       = "struct";
+static const char g_SCILAB_CLASS_CELL[]         = "cell";
+static const char g_SCILAB_CLASS_HANDLE[]       = "handle";
+static const char g_SCILAB_CLASS_MACRO[]        = "macro";
 
 //integer precision
-#define SCI_INT8       1
-#define SCI_INT16      2
-#define SCI_INT32      4
-#define SCI_INT64      8
-#define SCI_UINT8      11
-#define SCI_UINT16     12
-#define SCI_UINT32     14
-#define SCI_UINT64     18
+#define SCI_INT8    1
+#define SCI_INT16   2
+#define SCI_INT32   4
+#define SCI_INT64   8
+#define SCI_UINT8   11
+#define SCI_UINT16  12
+#define SCI_UINT32  14
+#define SCI_UINT64  18
 
 #endif /* !__H5_ATTRIBUTECONSTATS_H__ */
index 9c2c3a7..bbec13c 100644 (file)
@@ -16,9 +16,9 @@
 #include "dynlib_hdf5_scilab.h"
 
 HDF5_SCILAB_IMPEXP void HDF5cleanup(void);
-HDF5_SCILAB_IMPEXP int createHDF5File(char *name);
-HDF5_SCILAB_IMPEXP int openHDF5File(char *name, int _iAppendMode);
+HDF5_SCILAB_IMPEXP int createHDF5File(const char *name);
+HDF5_SCILAB_IMPEXP int openHDF5File(const char *name, int _iAppendMode);
 HDF5_SCILAB_IMPEXP void closeHDF5File(int file);
-HDF5_SCILAB_IMPEXP int isHDF5File(char* _pstFilename);
+HDF5_SCILAB_IMPEXP int isHDF5File(const char* _pstFilename);
 
 #endif /* !__H5_FILEMANAGEMENT_H__ */
index 03a57d5..bf9ae0f 100644 (file)
@@ -30,7 +30,7 @@ HDF5_SCILAB_IMPEXP int getVariableNames(int _iFile, char **pstNameList);
 
 HDF5_SCILAB_IMPEXP int getDataSetId(int  _iFile);
 
-HDF5_SCILAB_IMPEXP int getDataSetIdFromName(int _iFile, char *_pstName);
+HDF5_SCILAB_IMPEXP int getDataSetIdFromName(int _iFile, const char *_pstName);
 HDF5_SCILAB_IMPEXP void closeDataSet(int _id);
 
 HDF5_SCILAB_IMPEXP int getDatasetInfo(int _iDatasetId, int* _iComplex, int* _iDims, int* _piDims);
@@ -78,4 +78,10 @@ HDF5_SCILAB_IMPEXP int getListItemDataset(int _iDatasetId, void* _piItemRef, int
 HDF5_SCILAB_IMPEXP int deleteListItemReferences(int _iDatasetId, void* _piItemRef);
 
 HDF5_SCILAB_IMPEXP  void reset_item_count();
+
+//Scilab 6
+HDF5_SCILAB_IMPEXP int getVariableNames6(int _iFile, char **names);
+HDF5_SCILAB_IMPEXP char* getScilabTypeFromDataSet6(int dataset);
+HDF5_SCILAB_IMPEXP int getListDims6(int dataset, int* items);
+
 #endif /* !__H5_READDATATOFILE_H__ */
index ab55730..a440aff 100644 (file)
 
 #include "dynlib_hdf5_scilab.h"
 
+#include <hdf5.h>
+
 HDF5_SCILAB_IMPEXP int updateFileVersion(int _iFile);
 HDF5_SCILAB_IMPEXP int updateScilabVersion(int _iFile);
 
-HDF5_SCILAB_IMPEXP char* createGroupName(char* _pstGroupName);
+HDF5_SCILAB_IMPEXP char* createGroupName(const char* _pstGroupName);
 HDF5_SCILAB_IMPEXP char* createPathName(char* _pstGroupName, int _iIndex);
-HDF5_SCILAB_IMPEXP int deleteHDF5Var(int _iFile, char* _pstName);
+HDF5_SCILAB_IMPEXP int deleteHDF5Var(int _iFile, const char* _pstName);
 
 HDF5_SCILAB_IMPEXP int writeDoubleMatrix(int _iFile, char* _pstDatasetName, int _iDims, int* _piDims, double *_pdblData);
 HDF5_SCILAB_IMPEXP int writeDoubleComplexMatrix(int _iFile, char* _pstDatasetName, int _iDims, int* _piDims, double *_pdblReal, double *_pdblImg);
@@ -54,4 +56,19 @@ HDF5_SCILAB_IMPEXP void* openList(int _iFile, char* pstDatasetName, int _iNbItem
 HDF5_SCILAB_IMPEXP int addItemInList(int _iFile, void* _pvList, int _iPos, char* _pstItemName);
 HDF5_SCILAB_IMPEXP int closeList(int _iFile,  void* _pvList, char* _pstListName, int _iNbItem, int _iVarType);
 
+
+/*scilab 6*/
+
+HDF5_SCILAB_IMPEXP int writeDoubleMatrix6(int parent, const char* name, int dims, int* pdims, double* data);
+HDF5_SCILAB_IMPEXP int writeDoubleComplexMatrix6(int parent, const char* name, int dims, int* pdims, double* real, double* img);
+HDF5_SCILAB_IMPEXP int writeStringMatrix6(int parent, const char* name, int dims, int* pdims, char** data);
+HDF5_SCILAB_IMPEXP int writeBooleanMatrix6(int parent, const char* name, int dims, int* pdims, int* data);
+HDF5_SCILAB_IMPEXP int writeIntegerMatrix6(int parent, const char* name, int type, const char* prec, int dims, int* pdims, void* data);
+
+HDF5_SCILAB_IMPEXP int openList6(int parent, const char *name, const char* type);
+HDF5_SCILAB_IMPEXP int closeList6(int lst);
+HDF5_SCILAB_IMPEXP int addItemStruct6(int dataset, hobj_ref_t * refs, int pos, const char *name);
+HDF5_SCILAB_IMPEXP int writeStructField6(int parent, const char* name, int dims, int* pdims, hobj_ref_t * refs);
+HDF5_SCILAB_IMPEXP int writeVoid6(int parent, const char* name);
+HDF5_SCILAB_IMPEXP int writeUndefined6(int parent, const char* name);
 #endif /* !__H5_WRITEDATATOFILE_H__ */
index c7b35e4..531d0f4 100644 (file)
@@ -22,5 +22,8 @@ extern "C"
 
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_export_to_hdf5, HDF5_SCILAB_IMPEXP);
 CPP_GATEWAY_PROTOTYPE_EXPORT(sci_import_from_hdf5, HDF5_SCILAB_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_import_from_hdf5_v3, HDF5_SCILAB_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_listvar_in_hdf5, HDF5_SCILAB_IMPEXP);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_listvar_in_hdf5_v3, HDF5_SCILAB_IMPEXP);
 
 #endif /* !__HDF5_GW_HXX__ */
index b805e86..7b09deb 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2009 - DIGITEO - Antoine ELIAS
+* Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 *
 */
 
+#include <list>
+#include <map>
 #include <hdf5.h>
-#include "internal.hxx"
-#include "types.hxx"
+#include "hdf5_gw.hxx"
+#include "context.hxx"
+#include "string.hxx"
+#include "double.hxx"
 #include "struct.hxx"
 #include "cell.hxx"
+#include "int.hxx"
+#include "polynom.hxx"
+#include "sparse.hxx"
+#include "macrofile.hxx"
+#include "graphichandle.hxx"
+#include "handle_properties.hxx"
+#include "context.hxx"
+#include "serializervisitor.hxx"
 
 extern "C"
 {
-#include <string.h>
-#include <stdio.h>
-#include "gw_hdf5.h"
 #include "sci_malloc.h"
 #include "Scierror.h"
 #include "localization.h"
-#include "sciprint.h"
-#include "api_scilab.h"
+#include "freeArrayOfString.h"
+#include "os_string.h"
 #include "deleteafile.h"
 #include "expandPathVariable.h"
 #include "h5_fileManagement.h"
 #include "h5_writeDataToFile.h"
 #include "h5_readDataFromFile.h"
 #include "h5_attributeConstants.h"
-#include "freeArrayOfString.h"
-#include "os_string.h"
-#include "configvariable_interface.h"
-#include "splitpath.h"
-#include "scicurdir.h"
+#include "HandleManagement.h"
 }
 
-//#define PRINT_DEBUG
-int iLevel = 0;
-static bool isVarExist(int* pvCtx, int _iFile, char* _pstVarName);
-
-static bool export_data(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_list(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType);
-static bool export_struct(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType);
-static bool export_cell(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType);
-static bool export_hypermat(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_double(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_poly(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_boolean(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_sparse(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_boolean_sparse(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_matlab_sparse(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_ints(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_handles(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_strings(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-static bool export_u_function(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_c_function(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_lib(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_lufact_pointer(int* pvCtx, int *_piVar, char* _pstName);
-static bool export_void(int* pvCtx, int _iH5File, int *_piVar, char* _pstName);
-
-void print_type(char* _pstType);
-int extractVarNameList(int* pvCtx, int _iStart, int _iEnd, char** _pstNameList);
-
+/*--------------------------------------------------------------------------*/
+static bool isVarExist(int _iFile, const char* _pstVarName);
+static int extractVarNameList(int* pvCtx, int _iStart, int _iEnd, char** _pstNameList);
+
+int export_data(int parent, const std::string& name, types::InternalType* data);
+static int export_double(int parent, const std::string& name, types::Double* data);
+static int export_string(int parent, const std::string& name, types::String* data);
+static int export_boolean(int parent, const std::string& name, types::Bool* data);
+static int export_list(int parent, const std::string& name, types::List* data);
+static int export_struct(int parent, const std::string& name, types::Struct* data);
+template <class T> static int export_int(int parent, const std::string& name, int type, const char* prec, T* data);
+static int export_poly(int parent, const std::string& name, types::Polynom* data);
+static int export_sparse(int parent, const std::string& name, types::Sparse* data);
+static int export_cell(int parent, const std::string& name, types::Cell* data);
+static int export_macro(int parent, const std::string& name, types::Macro* data);
+
+static int export_boolean_sparse(int parent, const std::string& name, types::SparseBool* data);
+static int export_handles(int parent, const std::string& name, types::GraphicHandle* data);
+static int export_void(int parent, const std::string& name);
+static int export_undefined(int parent, const std::string& name);
 
 /*--------------------------------------------------------------------------*/
-int sci_export_to_hdf5(char *fname, int* pvApiCtx)
+static const std::string fname("export_to_hdf5");
+/*--------------------------------------------------------------------------*/
+types::Function::ReturnValue sci_export_to_hdf5(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    int iNbVar          = 0;
-    int** piAddrList    = NULL;
-    char** pstNameList  = NULL;
-    char *pstFileName   = NULL;
-    bool bExport        = true;
-    bool bAppendMode    = false;
-    int iRhs            = nbInputArgument(pvApiCtx);
-
-    SciErr sciErr;
-
-    CheckInputArgumentAtLeast(pvApiCtx, 1);
-    CheckOutputArgument(pvApiCtx, 0, 1);
-
-    pstNameList = (char**)MALLOC(sizeof(char*) * nbInputArgument(pvApiCtx));
-    iNbVar = extractVarNameList(pvApiCtx, 1, nbInputArgument(pvApiCtx), pstNameList);
-    if (iNbVar == 0)
+    int iH5File = 0;
+    bool bAppendMode = false;
+    int rhs = static_cast<int>(in.size());
+    std::string filename;
+    std::map<std::string, types::InternalType*> vars;
+    symbol::Context* ctx = symbol::Context::getInstance();
+
+    /* Check the number of input argument */
+    if (in.size() < 2)
+    {
+        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 2);
+        return types::Function::Error;
+    }
+
+    if (in[0]->getId() != types::InternalType::IdScalarString)
     {
-        FREE(pstNameList);
-        return 1;
+        Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), fname.data(), 1);
+        return types::Function::Error;
     }
 
-    piAddrList = (int**)MALLOC(sizeof(int*) * (iNbVar));
-    for (int i = 1 ; i < nbInputArgument(pvApiCtx) ; i++)
+    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
+    char* cfilename = wide_string_to_UTF8(wfilename);
+    filename = cfilename;
+    FREE(wfilename);
+    FREE(cfilename);
+
+    for (int i = 1; i < rhs; ++i)
     {
-        if (strcmp(pstNameList[i], "-append") == 0)
+        if (in[i]->getId() != types::InternalType::IdScalarString)
+        {
+            Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), fname.data(), 1);
+            return types::Function::Error;
+        }
+
+        wchar_t* wvar = in[i]->getAs<types::String>()->get()[0];
+        if (wcscmp(wvar, L"-append") == 0)
         {
             bAppendMode = true;
+            continue;
         }
-        else
+
+        types::InternalType* pIT = ctx->get(symbol::Symbol(wvar));
+        if (pIT == NULL)
         {
-            sciErr = getVarAddressFromName(pvApiCtx, pstNameList[i], &piAddrList[i]);
-            if (sciErr.iErr)
-            {
-                freeArrayOfString(pstNameList, iRhs);
-                FREE(piAddrList);
-                Scierror(999, _("%s: Wrong value for input argument #%d: Defined variable expected.\n"), fname, i + 1);
-                printError(&sciErr, 0);
-                return 1;
-            }
+            Scierror(999, _("%s: Wrong value for input argument #%d: Defined variable expected.\n"), fname.data(), i + 1);
+            return types::Function::Error;
         }
+
+        char* cvar = wide_string_to_UTF8(wvar);
+        std::string var(cvar);
+        FREE(cvar);
+
+        //check var exists
+        vars[var] = pIT;
     }
 
     //check append option
-
-    iLevel = 0;
-    // open hdf5 file
-    pstFileName = expandPathVariable(pstNameList[0]);
-    int iH5File = 0;
     if (bAppendMode)
     {
-        iH5File = openHDF5File(pstFileName, bAppendMode);
+        // open hdf5 file
+        iH5File = openHDF5File(filename.data(), bAppendMode);
         if (iH5File < 0)
         {
-            iH5File = createHDF5File(pstFileName);
+            iH5File = createHDF5File(filename.data());
         }
     }
     else
     {
-        iH5File = createHDF5File(pstFileName);
+        iH5File = createHDF5File(filename.data());
     }
 
 
@@ -136,1103 +146,711 @@ int sci_export_to_hdf5(char *fname, int* pvApiCtx)
     {
         if (iH5File == -2)
         {
-            Scierror(999, _("%s: Wrong value for input argument #%d: \"%s\" is a directory"), fname, 1, pstNameList[0]);
+            Scierror(999, _("%s: Wrong value for input argument #%d: \"%s\" is a directory"), fname.data(), 1, filename.data());
         }
         else
         {
-            Scierror(999, _("%s: Cannot open file %s.\n"), fname, pstNameList[0]);
+            Scierror(999, _("%s: Cannot open file %s.\n"), fname.data() , filename.data());
         }
 
-        FREE(piAddrList);
-        freeArrayOfString(pstNameList, iRhs);
-        FREE(pstFileName);
-        return 1;
+        return types::Function::Error;
     }
 
     if (bAppendMode)
     {
         int iVersion = getSODFormatAttribute(iH5File);
-        if (iVersion != -1 && iVersion != SOD_FILE_VERSION)
+        if (iVersion != SOD_FILE_VERSION)
         {
             //to update version must be the same
             closeHDF5File(iH5File);
-            Scierror(999, _("%s: Wrong SOD file format version. Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion);
-            FREE(piAddrList);
-            freeArrayOfString(pstNameList, iRhs);
-            FREE(pstFileName);
-            return 1;
+            Scierror(999, _("%s: Wrong SOD file format version. Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
+            return types::Function::Error;
         }
     }
 
     // export data
-    for (int i = 1 ; i < nbInputArgument(pvApiCtx) ; i++)
+    for (const auto var : vars)
     {
-        if (strcmp(pstNameList[i], "-append") == 0)
-        {
-            continue;
-        }
-
-        if (isVarExist(pvApiCtx, iH5File, pstNameList[i]))
+        if (isVarExist(iH5File, var.first.data()))
         {
             if (bAppendMode)
             {
-                if (deleteHDF5Var(iH5File, pstNameList[i]))
+                if (deleteHDF5Var(iH5File, var.first.data()))
                 {
                     closeHDF5File(iH5File);
-                    Scierror(999, _("%s: Unable to delete existing variable \"%s\"."), fname, pstNameList[i]);
-                    FREE(piAddrList);
-                    freeArrayOfString(pstNameList, iRhs);
-                    FREE(pstFileName);
-                    return 1;
+                    Scierror(999, _("%s: Unable to delete existing variable \"%s\".\n"), fname.data(), var.first.data());
+                    return types::Function::Error;
                 }
             }
             else
             {
                 closeHDF5File(iH5File);
-                Scierror(999, _("%s: Variable \'%s\' already exists in file \'%s\'\nUse -append option to replace existing variable\n."), fname, pstNameList[i], pstNameList[0]);
-                FREE(piAddrList);
-                freeArrayOfString(pstNameList, iRhs);
-                FREE(pstFileName);
-                return 1;
+                Scierror(999, _("%s: Variable \'%s\' already exists in file \'%s\'\nUse -append option to replace existing variable.\n"), fname.data(), var.first.data(), filename.data());
+                return types::Function::Error;
             }
         }
 
-        bExport = export_data(pvApiCtx, iH5File, piAddrList[i], pstNameList[i]);
-        if (bExport == false)
-        {
-            break;
-        }
-    }
-
-    if (bExport && nbInputArgument(pvApiCtx) != 1)
-    {
-        //add or update scilab version and file version in hdf5 file
-        if (updateScilabVersion(iH5File) < 0)
-        {
-            closeHDF5File(iH5File);
-            Scierror(999, _("%s: Unable to update Scilab version in \"%s\"."), fname, pstNameList[0]);
-            FREE(piAddrList);
-            freeArrayOfString(pstNameList, iRhs);
-            FREE(pstFileName);
-            return 1;
-        }
-
-        if (updateFileVersion(iH5File) < 0)
+        int iDataset = export_data(iH5File, var.first, var.second);
+        if (iDataset == -1)
         {
             closeHDF5File(iH5File);
-            Scierror(999, _("%s: Unable to update HDF5 format version in \"%s\"."), fname, pstNameList[0]);
-            FREE(piAddrList);
-            freeArrayOfString(pstNameList, iRhs);
-            FREE(pstFileName);
-            return 1;
+            deleteafile(filename.data());
+            Scierror(999, _("%s: Unable to export variable \'%s\' in file \'%s\'.\n"), fname.data(), var.first.data(), filename.data());
+            return types::Function::Error;
         }
     }
 
-    //close hdf5 file
-    closeHDF5File(iH5File);
-    if (bExport == false && nbInputArgument(pvApiCtx) != 1)
+    //add or update scilab version and file version in hdf5 file
+    if (updateScilabVersion(iH5File) < 0)
     {
-        //remove file
-        deleteafile(pstFileName);
+        closeHDF5File(iH5File);
+        Scierror(999, _("%s: Unable to update Scilab version in \"%s\"."), fname.data(), filename.data());
+        return types::Function::Error;
     }
 
-    FREE(pstFileName);
-    freeArrayOfString(pstNameList, iRhs);
-    FREE(piAddrList);
-
-    //create boolean return value
-    int *piReturn = NULL;
-    sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 1, &piReturn);
-    if (sciErr.iErr)
+    if (updateFileVersion(iH5File) < 0)
     {
-        printError(&sciErr, 0);
-        return 1;
+        closeHDF5File(iH5File);
+        Scierror(999, _("%s: Unable to update HDF5 format version in \"%s\"."), fname.data(), filename.data());
+        return types::Function::Error;
     }
 
-    if (bExport == true || nbInputArgument(pvApiCtx) == 1)
-    {
-        piReturn[0] = 1;
-    }
-    else
-    {
-        piReturn[0] = 0;
-    }
+    //close hdf5 file
+    closeHDF5File(iH5File);
 
-    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
-    ReturnArguments(pvApiCtx);
-    return 0;
+    out.push_back(new types::Bool(1));
+    return types::Function::OK;
 }
-
-static bool export_data(int* pvCtx, int _iH5File, int* _piVar, char* _pstName)
+/*--------------------------------------------------------------------------*/
+static bool isVarExist(int _iFile, const char* _pstVarName)
 {
-    bool bReturn = false;
-    int iType = 0;
-    int iDims = 0;
-    types::InternalType* pIT = (types::InternalType*)_piVar;
-
-    SciErr sciErr = getVarType(pvCtx, _piVar, &iType);
-    if (sciErr.iErr)
+    //check if variable already exists
+    int iNbItem = getVariableNames(_iFile, NULL);
+    if (iNbItem)
     {
-        printError(&sciErr, 0);
-        return false;
-    }
+        char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);
 
-    if (pIT->isGenericType())
-    {
-        types::GenericType* pGT = pIT->getAs<types::GenericType>();
-        iDims = pGT->getDims();
-    }
+        iNbItem = getVariableNames(_iFile, pstVarNameList);
 
-    if (iDims > 2)
-    {
-        bReturn = export_hypermat(pvCtx, _iH5File, _piVar, _pstName);
-    }
-    else
-    {
-        switch (iType)
+        //import all data
+        for (int i = 0; i < iNbItem; i++)
         {
-            case sci_matrix :
-            {
-                bReturn = export_double(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_poly :
-            {
-                bReturn = export_poly(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_boolean :
-            {
-                bReturn = export_boolean(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_sparse :
-            {
-                bReturn = export_sparse(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_boolean_sparse :
-            {
-                bReturn = export_boolean_sparse(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_matlab_sparse :
-            {
-                bReturn = export_matlab_sparse(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case sci_ints :
-            {
-                bReturn = export_ints(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_handles :
-            {
-                bReturn = export_handles(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case sci_strings :
-            {
-                bReturn = export_strings(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            case sci_u_function :
-            {
-                bReturn = export_u_function(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case sci_c_function :
-            {
-                bReturn = export_c_function(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case sci_lib :
-            {
-                bReturn = export_lib(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case sci_list :
-            case sci_tlist :
-            case sci_mlist :
-            {
-                if (pIT->isStruct())
-                {
-                    return export_struct(pvCtx, _iH5File, _piVar, _pstName, iType);
-                }
-                if (pIT->isCell())
-                {
-                    return export_cell(pvCtx, _iH5File, _piVar, _pstName, iType);
-                }
-                bReturn = export_list(pvCtx, _iH5File, _piVar, _pstName, iType);
-                break;
-            }
-            case sci_lufact_pointer :
-            {
-                bReturn = export_lufact_pointer(pvCtx, _piVar, _pstName);
-                break;
-            }
-            case 0 : //void case to "null" items in list
-            {
-                bReturn = export_void(pvCtx, _iH5File, _piVar, _pstName);
-                break;
-            }
-            default :
+            if (strcmp(pstVarNameList[i], _pstVarName) == 0)
             {
-                bReturn = false;
-                break;
+                freeArrayOfString(pstVarNameList, iNbItem);
+                return true;
             }
         }
-    }
-
-    return bReturn;
-}
 
-static bool export_void(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    int iRet = writeVoid(_iH5File, _pstName);
-    if (iRet)
-    {
-        return false;
+        freeArrayOfString(pstVarNameList, iNbItem);
     }
 
-    //char pstMsg[] = "void";
-    //print_type(pstMsg);
-    return true;
+    return false;
 }
-
-static bool export_undefined(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
+/*--------------------------------------------------------------------------*/
+int export_data(int parent, const std::string& name, types::InternalType* data)
 {
-    int iRet = writeUndefined(_iH5File, _pstName);
-    if (iRet)
+    int dataset = -1;
+    switch (data->getType())
     {
-        return false;
+        case types::InternalType::ScilabDouble:
+            dataset = export_double(parent, name, data->getAs<types::Double>());
+            break;
+        case types::InternalType::ScilabString:
+            dataset = export_string(parent, name, data->getAs<types::String>());
+            break;
+        case types::InternalType::ScilabBool:
+            dataset = export_boolean(parent, name, data->getAs<types::Bool>());
+            break;
+        case types::InternalType::ScilabTList:
+        case types::InternalType::ScilabList:
+        case types::InternalType::ScilabMList:
+            dataset = export_list(parent, name, data->getAs<types::List>());
+            break;
+        case types::InternalType::ScilabInt8:
+            dataset = export_int(parent, name, H5T_NATIVE_INT8, "8", data->getAs<types::Int8>());
+            break;
+        case types::InternalType::ScilabInt16:
+            dataset = export_int(parent, name, H5T_NATIVE_INT16, "16", data->getAs<types::Int16>());
+            break;
+        case types::InternalType::ScilabInt32:
+            dataset = export_int(parent, name, H5T_NATIVE_INT32, "32", data->getAs<types::Int32>());
+            break;
+        case types::InternalType::ScilabInt64:
+            dataset = export_int(parent, name, H5T_NATIVE_INT64, "64", data->getAs<types::Int64>());
+            break;
+        case types::InternalType::ScilabUInt8:
+            dataset = export_int(parent, name, H5T_NATIVE_UINT8, "u8", data->getAs<types::UInt8>());
+            break;
+        case types::InternalType::ScilabUInt16:
+            dataset = export_int(parent, name, H5T_NATIVE_UINT16, "u16", data->getAs<types::UInt16>());
+            break;
+        case types::InternalType::ScilabUInt32:
+            dataset = export_int(parent, name, H5T_NATIVE_UINT32, "u32", data->getAs<types::UInt32>());
+            break;
+        case types::InternalType::ScilabUInt64:
+            dataset = export_int(parent, name, H5T_NATIVE_UINT64, "u64", data->getAs<types::UInt64>());
+            break;
+        case types::InternalType::ScilabStruct:
+            dataset = export_struct(parent, name, data->getAs<types::Struct>());
+            break;
+        case types::InternalType::ScilabPolynom:
+            dataset = export_poly(parent, name, data->getAs<types::Polynom>());
+            break;
+        case types::InternalType::ScilabSparse:
+            dataset = export_sparse(parent, name, data->getAs<types::Sparse>());
+            break;
+        case types::InternalType::ScilabSparseBool :
+            dataset = export_boolean_sparse(parent, name, data->getAs<types::SparseBool>());
+            break;
+        case types::InternalType::ScilabCell:
+            dataset = export_cell(parent, name, data->getAs<types::Cell>());
+            break;
+        case types::InternalType::ScilabVoid:
+            dataset = export_void(parent, name);
+            break;
+        case types::InternalType::ScilabListUndefinedOperation:
+            dataset = export_undefined(parent, name);
+            break;
+        case types::InternalType::ScilabMacro:
+            dataset = export_macro(parent, name, data->getAs<types::Macro>());
+            break;
+        case types::InternalType::ScilabMacroFile:
+        {
+            types::MacroFile* pMF = data->getAs<types::MacroFile>();
+            dataset = export_macro(parent, name, pMF->getMacro());
+            break;
+        }
+        case types::InternalType::ScilabHandle:
+            dataset = export_handles(parent, name, data->getAs<types::GraphicHandle>());
+            break;
+        default:
+        {
+            break;
+        }
     }
 
-    //char pstMsg[] = "void";
-    //print_type(pstMsg);
-    return true;
+    return dataset;
 }
 
-static bool export_list(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType)
+/*--------------------------------------------------------------------------*/
+static int export_list(int parent, const std::string& name, types::List* data)
 {
-    int iRet        = 0;
-    bool bReturn    = false;
-    int iItemNumber = 0;
-    SciErr sciErr   = getListItemNumber(pvCtx, _piVar, &iItemNumber);
-    if (sciErr.iErr)
+    int size = data->getSize();
+
+    const char* type = nullptr;
+    switch (data->getType())
     {
-        printError(&sciErr, 0);
-        return false;
+        case types::InternalType::ScilabMList:
+            type = g_SCILAB_CLASS_MLIST;
+            break;
+        case types::InternalType::ScilabTList:
+            type = g_SCILAB_CLASS_TLIST;
+            break;
+        case types::InternalType::ScilabList:
+            type = g_SCILAB_CLASS_LIST;
+            break;
+        default:
+            return -1;
     }
 
+    //create node with list name
+    int dset = openList6(parent, name.data(), type);
 
-    //create groupe name
-    char* pstGroupName = createGroupName(_pstName);
-
-    //char pstMsg[256];
-    //sprintf(pstMsg, "list (%d)", iItemNumber);
-    //print_type(pstMsg);
-
-    iLevel++;
-    //open list
-    void *pvList = openList(_iH5File, pstGroupName, iItemNumber);
-    for (int i = 0 ; i < iItemNumber ; i++)
+    for (int i = 0; i < size; ++i)
     {
-        int *piNewVar = NULL;
-        getListItemAddress(pvCtx, _piVar, i + 1, &piNewVar);//1 indexed
-        char* pstPathName   = createPathName(pstGroupName, i);
-
-        if (piNewVar == NULL)
-        {
-            //undefined item
-            bReturn = export_undefined(pvCtx, _iH5File, piNewVar, pstPathName);
-        }
-        else
+        if (export_data(dset, std::to_string(i).data(), data->get(i)) == -1)
         {
-            bReturn = export_data(pvCtx, _iH5File, piNewVar, pstPathName);
+            closeList6(dset);
+            return -1;
         }
+    }
 
-        iRet = addItemInList(_iH5File, pvList, i, pstPathName);
-        FREE(pstPathName);
-        if (bReturn == false || iRet)
-        {
-            return false;
-        }
+    if (closeList6(dset) == -1)
+    {
+        return -1;
     }
-    iLevel--;
-    closeList(_iH5File, pvList, _pstName, iItemNumber, _iVarType);
-    FREE(pstGroupName);
-    //close list
-    return true;
+    return dset;
 }
-
-static bool export_struct(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType)
+/*--------------------------------------------------------------------------*/
+static int export_double(int parent, const std::string& name, types::Double* data)
 {
-    char STR[] = "st";
-    char DIMS[] = "dims";
-
-    int iItemNumber = 0;
+    int dataset = -1;
 
-    types::Struct* pStruct = (types::Struct*)_piVar;
-    types::SingleStruct** ppSStruct = pStruct->get();
-
-    types::String* pStr = pStruct->getFieldNames();
-    // for empty struct, getFieldNames return NULL
-    if (pStr)
+    if (data->isComplex())
     {
-        iItemNumber = pStr->getSize();
+        dataset = writeDoubleComplexMatrix6(parent, name.data(), data->getDims(), data->getDimsArray(), data->get(), data->getImg());
     }
-
-    char** strStruct = new char*[iItemNumber + 2];
-    strStruct[0] = STR;
-    strStruct[1] = DIMS;
-
-    for (int i = 0; i < iItemNumber; ++i)
+    else
     {
-        strStruct[i + 2] = wide_string_to_UTF8(pStr->get(i));
+        dataset = writeDoubleMatrix6(parent, name.data(), data->getDims(), data->getDimsArray(), data->get());
     }
 
-    //int iVarType = sci_mlist;
-    int iRet = 0;
-    bool bReturn = false;
-
-    //create groupe name
-    char* pstGroupName = createGroupName(_pstName);
-    iLevel++;
-
-    //open list
-    void *pvList = openList(_iH5File, pstGroupName, 2 + iItemNumber);
-
-    //export string ["st" "dims" "field name"]
-
-    int piStrDims[2] = { 1, iItemNumber + 2 };
+    return dataset;
+}
+/*--------------------------------------------------------------------------*/
+template <class T>
+static int export_int(int parent, const std::string& name, int type, const char* prec, T* data)
+{
+    return writeIntegerMatrix6(parent, name.data(), type, prec, data->getDims(), data->getDimsArray(), data->get());
+}
+/*--------------------------------------------------------------------------*/
+static int export_string(int parent, const std::string& name, types::String* data)
+{
+    int size = data->getSize();
+    wchar_t** s = data->get();
+    std::vector<char*> v(size);
 
-    char* pstPathName = createPathName(pstGroupName, 0);
-    iRet = writeStringMatrix(_iH5File, pstPathName, 2, piStrDims, strStruct);
-    if (iRet)
+    //convert UTF16 strings to UTF8
+    for (int i = 0; i < size; ++i)
     {
-        return false;
+        v[i] = wide_string_to_UTF8(s[i]);
     }
 
-    iRet = addItemInList(_iH5File, pvList, 0, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
-    {
-        return false;
-    }
+    int dset = writeStringMatrix6(parent, name.data(), data->getDims(), data->getDimsArray(), v.data());
 
-    // export size
-    int piSizeDims[2] = { 1, 0 };
-    piSizeDims[1] = pStruct->getDims();
-    pstPathName = createPathName(pstGroupName, 1);
-    iRet = writeInteger32Matrix(_iH5File, pstPathName, 2, piSizeDims, pStruct->getDimsArray());
-    if (iRet)
+    //release memory
+    for (int i = 0; i < size; ++i)
     {
-        return false;
+        FREE(v[i]);
     }
 
-    iRet = addItemInList(_iH5File, pvList, 1, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
+    return dset;
+}
+/*--------------------------------------------------------------------------*/
+static int export_boolean(int parent, const std::string& name, types::Bool* data)
+{
+    return writeBooleanMatrix6(parent, name.data(), data->getDims(), data->getDimsArray(), data->get());
+}
+/*--------------------------------------------------------------------------*/
+static int export_struct(int parent, const std::string& name, types::Struct* data)
+{
+    //create a group with struct name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_STRUCT);
+    //store struct dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    int *piNewVar = NULL;
-    if (pStruct->getSize() == 1)
+    int size = data->getSize();
+
+    if (size == 0)
     {
-        for (int i = 0; i < iItemNumber; ++i)
+        if (closeList6(dset) == -1)
         {
+            return -1;
+        }
 
-            char* pstPathName = createPathName(pstGroupName, i + 2);
+        return dset;
+    }
 
-            piNewVar = (int*)ppSStruct[0]->get(pStr->get(i));
+    //create a node for fields references
+    int refs = openList6(dset, "__refs__", g_SCILAB_CLASS_STRUCT);
+    if (refs < 0)
+    {
+        return -1;
+    }
 
+    types::String* fields = data->getFieldNames();
+    int fieldCount = fields->getSize();
+    wchar_t** pfields = fields->get();
 
-            if (piNewVar == NULL)
-            {
-                //undefined item
-                bReturn = export_undefined(pvCtx, _iH5File, piNewVar, pstPathName);
-            }
-            else
-            {
-                bReturn = export_data(pvCtx, _iH5File, piNewVar, pstPathName);
-            }
 
-            iRet = addItemInList(_iH5File, pvList, i + 2, pstPathName);
-            FREE(pstPathName);
-            if (bReturn == false || iRet)
-            {
-                return false;
-            }
-        }
-    }
-    else if (pStruct->getSize() > 1) //
+    std::vector<hobj_ref_t> vrefs(size);
+    //fill main group with struct field name
+    for (int i = 0; i < fieldCount; ++i)
     {
-        types::List* pListe = new types::List();
-
-        for (int i = 0; i < iItemNumber; ++i)
+        char* cfield = wide_string_to_UTF8(pfields[i]);
+        for (int j = 0; j < size; ++j)
         {
-
-            char* pstPathName = createPathName(pstGroupName, i + 2);
-
-            for (int iReadData = 0; iReadData < pStruct->getSize(); ++iReadData)
-            {
-                pListe->set(iReadData, ppSStruct[iReadData]->get(pStr->get(i)));
-            }
-            piNewVar = (int*)pListe;
-
-
-            if (piNewVar == NULL)
-            {
-                //undefined item
-                bReturn = export_undefined(pvCtx, _iH5File, piNewVar, pstPathName);
-            }
-            else
-            {
-                bReturn = export_data(pvCtx, _iH5File, piNewVar, pstPathName);
-            }
-
-            iRet = addItemInList(_iH5File, pvList, i + 2, pstPathName);
-            FREE(pstPathName);
-            if (bReturn == false || iRet)
-            {
-                return false;
+            //get data
+            types::InternalType* val = data->get(j)->get(pfields[i]);
+            //create ref name
+            std::string refname(cfield);
+            refname += "_" + std::to_string(j);
+            //export data in refs group
+            int ref = export_data(refs, refname, val);
+            //create reference of data
+            ret = addItemStruct6(refs, vrefs.data(), j, refname.data());
+            if (ret)
+            {
+                return -1;
             }
         }
 
-        delete pListe;
+        ret = writeStructField6(dset, cfield, data->getDims(), data->getDimsArray(), vrefs.data());
+        FREE(cfield);
+        if (ret < 0)
+        {
+            return -1;
+        }
     }
 
-    iLevel--;
-    closeList(_iH5File, pvList, _pstName, 2 + iItemNumber, _iVarType);
-    FREE(pstGroupName);
-    //close list
-    return true;
-}
-
-static bool export_cell(int* pvCtx, int _iH5File, int *_piVar, char* _pstName, int _iVarType)
-{
-    char CELL[] = "ce";
-    char DIMS[] = "dims";
-    char ENTRIES[] = "entries";
-
-    char* strCell[] = { CELL, DIMS, ENTRIES };
-
-    types::Cell* pCell = (types::Cell*)_piVar;
-
-    //int iVarType = sci_mlist;
-    int iRet = 0;
-    bool bReturn = false;
-
-    //create groupe name
-    char* pstGroupName = createGroupName(_pstName);
-    iLevel++;
-
-    //open list
-    void *pvList = openList(_iH5File, pstGroupName, 3);
-
-    //export string ["cell" "dims" "entries"]
-
-    int piStrDims[2] = { 1, 3 };
-
-    char* pstPathName = createPathName(pstGroupName, 0);
-    iRet = writeStringMatrix(_iH5File, pstPathName, 2, piStrDims, strCell);
-    if (iRet)
+    if (closeList6(refs) == -1)
     {
-        return false;
+        return -1;
     }
 
-    iRet = addItemInList(_iH5File, pvList, 0, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
+    if (closeList6(dset) == -1)
     {
-        return false;
+        return -1;
     }
 
-    // export size
-    int piSizeDims[2] = { 1, 0 };
-    piSizeDims[1] = pCell->getDims();
-    pstPathName = createPathName(pstGroupName, 1);
-    iRet = writeInteger32Matrix(_iH5File, pstPathName, 2, piSizeDims, pCell->getDimsArray());
-    if (iRet)
+    return dset;
+}
+/*--------------------------------------------------------------------------*/
+static int export_void(int parent, const std::string& name)
+{
+    return writeVoid6(parent, name.data());
+}
+/*--------------------------------------------------------------------------*/
+static int export_undefined(int parent, const std::string& name)
+{
+    return writeUndefined6(parent, name.data());
+}
+/*--------------------------------------------------------------------------*/
+static int export_poly(int parent, const std::string& name, types::Polynom* data)
+{
+    //create a group with struct name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_POLY);
+    //store struct dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    iRet = addItemInList(_iH5File, pvList, 1, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
+    //store variable name
+    std::vector<int> vardims = {1, 1};
+    char* varname = wide_string_to_UTF8(data->getVariableName().data());
+    ret = writeStringMatrix6(dset, "__varname__", 2, vardims.data(), &varname);
+    FREE(varname);
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    int *piNewVar = NULL;
-
-    types::List* pListe = new types::List();
-
-    pstPathName = createPathName(pstGroupName, 2);
-
-    for (int iReadData = 0; iReadData < pCell->getSize(); ++iReadData)
+    //create a node for fields references
+    int refs = openList6(dset, "__refs__", g_SCILAB_CLASS_POLY);
+    if (refs < 0)
     {
-        pListe->set(iReadData, pCell->get(iReadData));
+        return -1;
     }
 
-    piNewVar = (int*)pListe;
-
-    if (piNewVar == NULL)
-    {
-        //undefined item
-        bReturn = export_undefined(pvCtx, _iH5File, piNewVar, pstPathName);
-    }
-    else
+    bool complex = data->isComplex();
+    int size = data->getSize();
+    std::vector<hobj_ref_t> vrefs(size);
+    types::SinglePoly** ss = data->get();
+    //fill main group with struct field name
+    for (int j = 0; j < size; ++j)
     {
-        bReturn = export_data(pvCtx, _iH5File, piNewVar, pstPathName);
-    }
+        //get data
+        types::SinglePoly* val = ss[j];
+        //export data in refs group
+        std::vector<int> ssdims = {1, val->getSize()};
+        std::string polyname(std::to_string(j));
+        if (complex)
+        {
+            writeDoubleComplexMatrix6(refs, polyname.data(), 2, ssdims.data(), val->get(), val->getImg());
+        }
+        else
+        {
+            writeDoubleMatrix6(refs, polyname.data(), 2, ssdims.data(), val->get());
+        }
 
-    iRet = addItemInList(_iH5File, pvList, 2, pstPathName);
-    FREE(pstPathName);
-    if (bReturn == false || iRet)
-    {
-        return false;
+        //create reference of data
+        ret = addItemStruct6(refs, vrefs.data(), j, polyname.data());
+        if (ret)
+        {
+            return -1;
+        }
     }
 
-    delete pListe;
-
-    iLevel--;
-    closeList(_iH5File, pvList, _pstName, 3, _iVarType);
-    FREE(pstGroupName);
-    //close list
-    return true;
-}
-
-
-static bool export_hypermat(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    char HM [] = "hm";
-    char DIMS [] = "dims";
-    char ENTRIES [] = "entries";
-
-    char* strHypermat [] = {HM, DIMS, ENTRIES};
-
-    int iVarType    = sci_mlist;
-    int iRet        = 0;
-    bool bReturn    = false;
-    types::GenericType* pGT = (types::GenericType*)_piVar;
-
-    //create groupe name
-    char* pstGroupName = createGroupName(_pstName);
-    iLevel++;
 
-    //open list
-    void *pvList = openList(_iH5File, pstGroupName, 3);
-
-    //export string ["hm" "dims" "entries"]
-    int piStrDims[2] = {1, 3};
-    char* pstPathName = createPathName(pstGroupName, 0);
-    iRet = writeStringMatrix(_iH5File, pstPathName, 2, piStrDims, strHypermat);
-    if (iRet)
-    {
-        return false;
-    }
-
-    iRet = addItemInList(_iH5File, pvList, 0, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
+    if (closeList6(refs) == -1)
     {
-        return false;
+        return -1;
     }
 
-    // export size
-    int piSizeDims[2] = {1, 0};
-    piSizeDims[1] = pGT->getDims();
-    pstPathName = createPathName(pstGroupName, 1);
-    iRet = writeInteger32Matrix(_iH5File, pstPathName, 2, piSizeDims, pGT->getDimsArray());
-    if (iRet)
+    if (closeList6(dset) == -1)
     {
-        return false;
+        return -1;
     }
 
-    iRet = addItemInList(_iH5File, pvList, 1, pstPathName);
-    FREE(pstPathName);
-    if (iRet)
+    return dset;
+}
+/*--------------------------------------------------------------------------*/
+static int export_sparse(int parent, const std::string& name, types::Sparse* data)
+{
+    int nnz = static_cast<int>(data->nonZeros());
+    int row = data->getRows();
+    //create a group with sparse name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_SPARSE);
+    //store sparse dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    // export data
-    int iDims = pGT->getDims();
-    int* piDimsArray = new int[iDims];
-    memcpy(piDimsArray, pGT->getDimsArray(), iDims * sizeof(int));
-
-    pstPathName = createPathName(pstGroupName, 2);
-    // reshape to prevent infinite call of export_hypermat
-    // we have to export a colon vector
-    pGT->reshape(pGT->getSize(), 1);
-    bReturn = export_data(pvCtx, _iH5File, _piVar, pstPathName);
-    // after export reshape again to keep variable unchainged.
-    pGT->reshape(piDimsArray, iDims);
-    delete[] piDimsArray;
-
-    iRet = addItemInList(_iH5File, pvList, 2, pstPathName);
-    FREE(pstPathName);
-    if (bReturn == false || iRet)
+    //store numbers of non zero by rows.
+    std::vector<int> dimsnnz = {1, 1};
+    ret = writeIntegerMatrix6(dset, "__nnz__", H5T_NATIVE_INT32, "32", 2, dimsnnz.data(), &nnz);
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    //close list
-    iLevel--;
-    closeList(_iH5File, pvList, _pstName, 3, iVarType);
-    FREE(pstGroupName);
-
-    return true;
-}
-
-static bool export_double(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    int iRet            = 0;
-    int iComplex        = isVarComplex(pvCtx, _piVar);
-    int piDims[2];
-    int iType = 0;
-    double *pdblReal   = NULL;
-    double *pdblImg            = NULL;
-
-    SciErr sciErr = getVarType(pvCtx, _piVar, &iType);
-    if (sciErr.iErr)
+    //store inner vector
+    int innercount = 0;
+    int* inner = data->getInnerPtr(&innercount);
+    std::vector<int> dimsinner = {1, nnz};
+    ret = writeIntegerMatrix6(dset, "__inner__", H5T_NATIVE_INT32, "32", 2, dimsinner.data(), inner);
+    if (ret < 0)
     {
-        printError(&sciErr, 0);
-        return false;
+        return -1;
     }
 
-    if (iType != sci_matrix)
+    int outercount = 0;
+    int* outer = data->getOuterPtr(&outercount);
+    std::vector<int> dimsouter = {1, outercount + 1};
+    ret = writeIntegerMatrix6(dset, "__outer__", H5T_NATIVE_INT32, "32", 2, dimsouter.data(), outer);
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    if (iComplex)
+    if (data->isComplex())
     {
-        sciErr = getComplexMatrixOfDouble(pvCtx, _piVar, &piDims[0], &piDims[1], &pdblReal, &pdblImg);
-        if (sciErr.iErr)
+        double* real = new double[nnz];
+        double* img = new double[nnz];
+        std::complex<double>* d = data->getImg();
+        for (int i = 0; i < nnz; ++i)
         {
-            printError(&sciErr, 0);
-            return false;
+            real[i] = d[i].real();
+            img[i] = d[i].imag();
         }
 
-        iRet = writeDoubleComplexMatrix(_iH5File, _pstName, 2, piDims, pdblReal, pdblImg);
+
+        std::vector<int> dimsdata = {1, nnz};
+        ret = writeDoubleComplexMatrix6(dset, "__data__", 2, dimsdata.data(), real, img);
+        delete[] real;
+        delete[] img;
+        if (ret < 0)
+        {
+            return -1;
+        }
     }
     else
     {
-        sciErr = getMatrixOfDouble(pvCtx, _piVar, &piDims[0], &piDims[1], &pdblReal);
-        if (sciErr.iErr)
+        std::vector<int> dimsdata = {1, nnz};
+        ret = writeDoubleMatrix6(dset, "__data__", 2, dimsdata.data(), data->get());
+        if (ret < 0)
         {
-            printError(&sciErr, 0);
-            return false;
+            return -1;
         }
-
-        iRet = writeDoubleMatrix(_iH5File, _pstName, 2, piDims, pdblReal);
     }
 
-    if (iRet)
+    if (closeList6(dset) == -1)
     {
-        return false;
+        return -1;
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "double (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
-}
+    return dset;
 
-static bool export_poly(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
+}
+/*--------------------------------------------------------------------------*/
+static int export_boolean_sparse(int parent, const std::string& name, types::SparseBool* data)
 {
-    int iRet = 0;
-    int* piNbCoef = NULL;
-    double** pdblReal = NULL;
-    double** pdblImg = NULL;
-    char pstVarName[64]        = {0};
-    int iVarNameLen = 0;
-    int piDims[2];
-
-    SciErr sciErr = getPolyVariableName(pvCtx, _piVar, pstVarName, &iVarNameLen);
-    if (sciErr.iErr)
+    int nnz = static_cast<int>(data->nbTrue());
+    int row = data->getRows();
+    //create a group with sparse name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_BSPARSE);
+    //store sparse dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        printError(&sciErr, 0);
-        return false;
+        return -1;
     }
 
-    if (isVarComplex(pvCtx, _piVar))
-    {
-        if (getAllocatedMatrixOfComplexPoly(pvCtx, _piVar, &piDims[0], &piDims[1], &piNbCoef, &pdblReal, &pdblImg))
-        {
-            freeAllocatedMatrixOfComplexPoly(piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg);
-            return false;
-        }
-
-        iRet = writePolyComplexMatrix(_iH5File, _pstName, pstVarName, 2, piDims, piNbCoef, pdblReal, pdblImg);
-        freeAllocatedMatrixOfComplexPoly(piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg);
-    }
-    else
+    //store numbers of non zero by rows.
+    std::vector<int> dimsnnz = {1, 1};
+    ret = writeIntegerMatrix6(dset, "__nnz__", H5T_NATIVE_INT32, "32", 2, dimsnnz.data(), &nnz);
+    if (ret < 0)
     {
-        if (getAllocatedMatrixOfPoly(pvCtx, _piVar, &piDims[0], &piDims[1], &piNbCoef, &pdblReal))
-        {
-            freeAllocatedMatrixOfPoly(piDims[0], piDims[1], piNbCoef, pdblReal);
-            return false;
-        }
-
-        iRet = writePolyMatrix(_iH5File, _pstName, pstVarName, 2, piDims, piNbCoef, pdblReal);
-        freeAllocatedMatrixOfPoly(piDims[0], piDims[1], piNbCoef, pdblReal);
+        return -1;
     }
 
-    if (iRet)
+    //store inner vector
+    int innercount = 0;
+    int* inner = data->getInnerPtr(&innercount);
+    std::vector<int> dimsinner = {1, nnz};
+    ret = writeIntegerMatrix6(dset, "__inner__", H5T_NATIVE_INT32, "32", 2, dimsinner.data(), inner);
+    if (ret < 0)
     {
-        return false;
+        return -1;
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "poly (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
-}
-
-static bool export_boolean(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    int *piData = NULL;
-    int piDims[2];
-
-    //for error management
-    SciErr sciErr = getMatrixOfBoolean(pvCtx, _piVar, &piDims[0], &piDims[1], &piData);
-    if (sciErr.iErr)
+    int outercount = 0;
+    int* outer = data->getOuterPtr(&outercount);
+    std::vector<int> dimsouter = {1, outercount + 1};
+    ret = writeIntegerMatrix6(dset, "__outer__", H5T_NATIVE_INT32, "32", 2, dimsouter.data(), outer);
+    if (ret < 0)
     {
-        printError(&sciErr, 0);
-        return 0;
+        return -1;
     }
 
-    int iRet = writeBooleanMatrix(_iH5File, _pstName, 2, piDims, piData);
-    if (iRet)
+    if (closeList6(dset) == -1)
     {
-        //Msg ??
-        return false;
+        return -1;
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "bool (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
+    return dset;
 }
-
-static bool export_boolean_sparse(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
+/*--------------------------------------------------------------------------*/
+static int export_cell(int parent, const std::string& name, types::Cell* data)
 {
-    int iRet = 0;
-    int iNbItem = 0;
-    int* piNbItemRow = NULL;
-    int* piColPos = NULL;
-    int piDims[2];
-
-    SciErr sciErr = getBooleanSparseMatrix(pvCtx, _piVar, &piDims[0], &piDims[1], &iNbItem, &piNbItemRow, &piColPos);
-    if (sciErr.iErr)
+    //create a group with cell name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_CELL);
+    //store cell dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        printError(&sciErr, 0);
-        return false;
+        return -1;
     }
 
-    iRet = writeBooleanSparseMatrix(_iH5File, _pstName, piDims[0], piDims[1], iNbItem, piNbItemRow, piColPos);
-    if (iRet)
+    //create a node for fields references
+    int refs = openList6(dset, "__refs__", g_SCILAB_CLASS_CELL);
+    if (refs < 0)
     {
-        //Msg ??
-        return false;
+        return -1;
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "boolean sparse (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
-}
-
-static bool export_sparse(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    int iRet = 0;
-    int iNbItem = 0;
-    int* piNbItemRow = NULL;
-    int* piColPos = NULL;
-    double* pdblReal = NULL;
-    double* pdblImg = NULL;
-    int piDims[2];
-    SciErr sciErr;
-
-    if (isVarComplex(pvCtx, _piVar))
+    int size = data->getSize();
+    types::InternalType** it = data->get();
+    std::vector<hobj_ref_t> vrefs(size);
+    for (int i = 0; i < size; ++i)
     {
-        sciErr = getComplexSparseMatrix(pvCtx, _piVar, &piDims[0], &piDims[1], &iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return false;
-        }
-
-        iRet = writeSparseComplexMatrix(_iH5File, _pstName, piDims[0], piDims[1], iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
+        std::string refname(std::to_string(i));
+        int ref = export_data(refs, refname, it[i]);
     }
-    else
-    {
-        sciErr = getSparseMatrix(pvCtx, _piVar, &piDims[0], &piDims[1], &iNbItem, &piNbItemRow, &piColPos, &pdblReal);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return false;
-        }
 
-        iRet = writeSparseMatrix(_iH5File, _pstName, piDims[0], piDims[1], iNbItem, piNbItemRow, piColPos, pdblReal);
-    }
 
-    if (iRet)
+    if (closeList6(refs) == -1)
     {
-        return false;
+        return -1;
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "sparse (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
-}
+    if (closeList6(dset) == -1)
+    {
+        return -1;
+    }
 
-static bool export_matlab_sparse(int* pvCtx, int *_piVar, char* _pstName)
-{
-    //print_type(_pstName);
-    return false;
+    return dset;
 }
 
-static bool export_ints(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
+static int export_handles(int parent, const std::string& name, types::GraphicHandle* data)
 {
-    int iRet = 0;
-    void *piData = NULL;
-    int iPrec = 0;
-    int piDims[2];
-
-    SciErr sciErr = getMatrixOfIntegerPrecision(pvCtx, _piVar, &iPrec);
-    if (sciErr.iErr)
+    //create a group with cell name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_HANDLE);
+    //store cell dimensions
+    std::vector<int> dims = {1, data->getDims()};
+    int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
+    if (ret < 0)
     {
-        printError(&sciErr, 0);
-        return false;
+        return -1;
     }
 
-    switch (iPrec)
+    //create a node for fields references
+    int refs = openList6(dset, "__refs__", g_SCILAB_CLASS_HANDLE);
+    if (refs < 0)
     {
-        case SCI_INT8 :
-            sciErr = getMatrixOfInteger8(pvCtx, _piVar, &piDims[0], &piDims[1], (char**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeInteger8Matrix(_iH5File, _pstName, 2, piDims, (char*)piData);
-            break;
-        case SCI_UINT8 :
-            sciErr = getMatrixOfUnsignedInteger8(pvCtx, _piVar, &piDims[0], &piDims[1], (unsigned char**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeUnsignedInteger8Matrix(_iH5File, _pstName, 2, piDims, (unsigned char*)piData);
-            break;
-        case SCI_INT16 :
-            sciErr = getMatrixOfInteger16(pvCtx, _piVar, &piDims[0], &piDims[1], (short**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeInteger16Matrix(_iH5File, _pstName, 2, piDims, (short*)piData);
-            break;
-        case SCI_UINT16 :
-            sciErr = getMatrixOfUnsignedInteger16(pvCtx, _piVar, &piDims[0], &piDims[1], (unsigned short**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeUnsignedInteger16Matrix(_iH5File, _pstName, 2, piDims, (unsigned short*)piData);
-            break;
-        case SCI_INT32 :
-            sciErr = getMatrixOfInteger32(pvCtx, _piVar, &piDims[0], &piDims[1], (int**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeInteger32Matrix(_iH5File, _pstName, 2, piDims, (int*)piData);
-            break;
-        case SCI_UINT32 :
-            sciErr = getMatrixOfUnsignedInteger32(pvCtx, _piVar, &piDims[0], &piDims[1], (unsigned int**)&piData);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return false;
-            }
-            iRet = writeUnsignedInteger32Matrix(_iH5File, _pstName, 2, piDims, (unsigned int*)piData);
-            break;
-        case SCI_INT64 :
-            //sciErr = getMatrixOfInteger64(_piVar, &piDims[0], &piDims[1], (long long**)&piData);
-            //if(sciErr.iErr)
-            //{
-            // printError(&sciErr, 0);
-            // return false;
-            //}
-            //iRet = writeInteger64Matrix(_iH5File, _pstName, 2, piDims, (long long*)piData);
-            //break;
-        case SCI_UINT64 :
-            //sciErr = getMatrixOfUnsignedInteger64(_piVar, &piDims[0], &piDims[1], (unsigned long long**)&piData);
-            //if(sciErr.iErr)
-            //{
-            // printError(&sciErr, 0);
-            // return false;
-            //}
-            //iRet = writeUnsignedInteger64Matrix(_iH5File, _pstName, 2, piDims, (unsigned long long*)piData);
-            //break;
-        default :
-            return 1;
-            break;
+        closeList6(dset);
+        return -1;
     }
 
-    if (iRet)
+    int size = data->getSize();
+    long long* ll = data->get();
+    std::vector<hobj_ref_t> vrefs(size);
+    for (int i = 0; i < size; ++i)
     {
-        return false;
+        //get handle uid
+        int hl = getObjectFromHandle(static_cast<long>(ll[i]));
+        std::string refname(std::to_string(i));
+        if (export_handle(refs, refname, hl) == false)
+        {
+            closeList6(refs);
+            closeList6(dset);
+            return -1;
+        }
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "int%d (%d x %d)", 8 * iPrec, piDims[0], piDims[1]);
-    //print_type(pstMsg);
-    return true;
+    closeList6(refs);
+    closeList6(dset);
+    return dset;
 }
 
-static bool export_handles(int* pvCtx, int *_piVar, char* _pstName)
+static int export_macro(int parent, const std::string& name, types::Macro* data)
 {
-    //print_type(_pstName);
-    return false;
-}
+    int dims[2];
 
-static bool export_strings(int* pvCtx, int _iH5File, int *_piVar, char* _pstName)
-{
-    int iRet = 0;
-    char** pstData = NULL;
-    int piDims[2];
+    //create a group with macro name
+    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_MACRO);
 
-    SciErr sciErr = getMatrixOfString(pvCtx, _piVar, &piDims[0], &piDims[1], NULL, NULL);
-    if (sciErr.iErr)
+    //inputs
+    std::vector<char*> inputNames;
+    auto inputs = data->getInputs();
+    for (auto& input : *inputs)
     {
-        printError(&sciErr, 0);
-        return false;
+        inputNames.push_back(wide_string_to_UTF8(input->getSymbol().getName().data()));
     }
 
-    if (getAllocatedMatrixOfString(pvCtx, _piVar, &piDims[0], &piDims[1], &pstData))
-    {
-        if (pstData)
-        {
-            freeAllocatedMatrixOfString(piDims[0], piDims[1], pstData);
-        }
-
-        return false;
-    }
+    dims[0] = 1;
+    dims[1] = static_cast<int>(inputNames.size());
+    writeStringMatrix6(dset, "inputs", 2, dims, inputNames.data());
 
-    iRet = writeStringMatrix(_iH5File, _pstName, 2, piDims, pstData);
-    freeAllocatedMatrixOfString(piDims[0], piDims[1], pstData);
-    if (iRet)
+    for (auto& in : inputNames)
     {
-        return false;
+        FREE(in);
     }
 
-    //char pstMsg[512];
-    //sprintf(pstMsg, "string (%d x %d)", piDims[0], piDims[1]);
-    //print_type(pstMsg);
-
-    return true;
-}
-
-static bool export_u_function(int* pvCtx, int *_piVar, char* _pstName)
-{
-    //print_type(_pstName);
-    return false;
-}
-
-static bool export_c_function(int* pvCtx, int *_piVar, char* _pstName)
-{
-    //print_type(_pstName);
-    return false;
-}
-
-static bool export_lib(int* pvCtx, int *_piVar, char* _pstName)
-{
-    //print_type(_pstName);
-    return false;
-}
-
-static bool export_lufact_pointer(int* pvCtx, int *_piVar, char* _pstName)
-{
-    /*print_type*/(_pstName);
-    return false;
-}
-
-void print_type(char* _pstType)
-{
-#ifdef PRINT_DEBUG
-    for (int i = 0 ; i < iLevel ; i++)
+    //outputs
+    std::vector<char*> outputNames;
+    auto outputs = data->getOutputs();
+    for (auto& output : *outputs)
     {
-        sciprint("\t");
+        outputNames.push_back(wide_string_to_UTF8(output->getSymbol().getName().data()));
     }
-    sciprint("%s\n", _pstType);
-#endif
-}
 
-int extractVarNameList(int* pvCtx, int _iStart, int _iEnd, char** _pstNameList)
-{
-    int iCount = 0;
+    dims[0] = 1;
+    dims[1] = static_cast<int>(outputNames.size());
+    writeStringMatrix6(dset, "outputs", 2, dims, outputNames.data());
 
-    for (int i = _iStart ; i <= _iEnd ; i++)
+    for (auto& in : outputNames)
     {
-        int* piAddr = NULL;
-        int iType   = 0;
-
-        SciErr sciErr = getVarAddressFromPosition(pvCtx, i, &piAddr);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-
-        if (getAllocatedSingleString(pvCtx, piAddr, &_pstNameList[iCount]))
-        {
-            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "export_to_hdf5", i);
-            return 0;
-        }
-
-        iCount++;
+        FREE(in);
     }
-    return iCount;
-}
 
-/*--------------------------------------------------------------------------*/
-static bool isVarExist(int* pvCtx, int _iFile, char* _pstVarName)
-{
-    //check if variable already exists
-    int iNbItem = getVariableNames(_iFile, NULL);
-    if (iNbItem)
-    {
-        char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);
+    //body
+    ast::Exp* pExp = data->getBody();
+    ast::SerializeVisitor serialMacro(pExp);
 
-        iNbItem = getVariableNames(_iFile, pstVarNameList);
+    unsigned char* serialAst = serialMacro.serialize();
+    //size if the buffer ( unsigned int )
+    unsigned int size = *((unsigned int*)serialAst);
 
-        //import all data
-        for (int i = 0 ; i < iNbItem ; i++)
-        {
-            if (strcmp(pstVarNameList[i], _pstVarName) == 0)
-            {
-                freeArrayOfString(pstVarNameList, iNbItem);
-                return true;
-            }
-        }
+    dims[0] = 1;
+    dims[1] = size;
+    writeIntegerMatrix6(dset, "body", H5T_NATIVE_UINT8, "u8", 2, dims, serialAst);
+    free(serialAst);
 
-        freeArrayOfString(pstVarNameList, iNbItem);
-    }
-
-    return false;
+    closeList6(dset);
+    return dset;
 }
-/*--------------------------------------------------------------------------*/
index f0928e4..4957d6b 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2009 - DIGITEO - Antoine ELIAS
+* Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 */
 
 #include <hdf5.h>
-#include "context.hxx"
-#include "list.hxx"
-#include "struct.hxx"
-#include "cell.hxx"
+#include "hdf5_gw.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
 
 extern "C"
 {
-#include <string.h>
-#include "gw_hdf5.h"
 #include "sci_malloc.h"
 #include "Scierror.h"
-#include "localization.h"
-#include "sciprint.h"
-#include "api_scilab.h"
-#include "../../../call_scilab/includes/call_scilab.h"
+#include "expandPathVariable.h"
 #include "h5_fileManagement.h"
-#include "h5_readDataFromFile.h"
 #include "h5_attributeConstants.h"
-#include "expandPathVariable.h"
-#include "stdlib.h"
-#include "freeArrayOfString.h"
+#include "h5_readDataFromFile.h"
 }
 
-#include "import_from_hdf5_v1.hxx"
+static const std::string fname("import_from_hdf5");
 
-static bool import_variable(int* pvCtx, int _iFile, char* _pstVarName);
-static bool import_data(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_double(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_string(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_boolean(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_integer(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_boolean_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_poly(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_list(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_hypermat(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_struct(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_cell(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_void(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-static bool import_undefined(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
-
-int sci_import_from_hdf5(char *fname, int* pvApiCtx)
+types::Function::ReturnValue sci_import_from_hdf5(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    SciErr sciErr;
-
-    int* piAddr = NULL;
-    char* pstFilename = NULL;
-    char* pstExpandedFilename = NULL;
-    bool bImport = true;
-    const int nbIn = nbInputArgument(pvApiCtx);
-    int iSelectedVar = nbIn - 1;
-
-    CheckInputArgumentAtLeast(pvApiCtx , 1);
-    CheckOutputArgument(pvApiCtx, 1, 1);
-
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
-    if (sciErr.iErr)
+    int rhs = static_cast<int>(in.size());
+    if (rhs < 1)
     {
-        printError(&sciErr, 0);
-        return 1;
+        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
+        return types::Function::Error;
     }
 
-    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFilename))
+    if (in[0]->getId() != types::InternalType::IdScalarString)
     {
-        if (pstFilename)
-        {
-            freeAllocatedSingleString(pstFilename);
-        }
-
-        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
-        return 1;
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
+        return types::Function::Error;
     }
 
-    //open hdf5 file
-    pstExpandedFilename = expandPathVariable(pstFilename);
-    int iFile = openHDF5File(pstExpandedFilename, 0);
+    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
+    char* cfilename = wide_string_to_UTF8(wfilename);
+    std::string filename = cfilename;
+    FREE(wfilename);
+    FREE(cfilename);
+
+    int iFile = openHDF5File(filename.data(), 0);
     if (iFile < 0)
     {
-        Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFilename);
-        FREE(pstExpandedFilename);
-        FREE(pstFilename);
-        return 1;
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
+        return types::Function::Error;
     }
 
-    FREE(pstExpandedFilename);
-    FREE(pstFilename);
-
+    std::wstring wstFuncName;
     //manage version information
-    int iVersion = getSODFormatAttribute(iFile);
-    if (iVersion != SOD_FILE_VERSION)
-    {
-        if (iVersion > SOD_FILE_VERSION)
-        {
-            //can't read file with version newer that me !
-            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion);
-            return 1;
-        }
-        else
-        {
-            //call older import functions and exit or ... EXIT !
-            if (iVersion == 1 || iVersion == -1)
-            {
-                //sciprint("old sci_import_from_hdf5_v1\n");
-                return sci_import_from_hdf5_v1(fname, pvApiCtx);
-            }
-        }
-    }
-
-    if (iSelectedVar)
-    {
-        //selected variable
-        char* pstVarName = NULL;
-        for (int i = 0 ; i < iSelectedVar ; i++)
-        {
-            sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr);
-            if (sciErr.iErr)
-            {
-                printError(&sciErr, 0);
-                return 1;
-            }
-
-            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))
-            {
-                if (pstVarName)
-                {
-                    freeAllocatedSingleString(pstVarName);
-                }
-
-                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, i + 1);
-                return 1;
-            }
-
-            if (import_variable(pvApiCtx, iFile, pstVarName) == false)
-            {
-                FREE(pstVarName);
-                bImport = false;
-                break;
-            }
-
-            FREE(pstVarName);
-            pstVarName = NULL;
-        }
-    }
-    else
-    {
-        //all variables
-        int iNbItem = 0;
-        iNbItem = getVariableNames(iFile, NULL);
-        if (iNbItem != 0)
-        {
-            char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);
-
-            iNbItem = getVariableNames(iFile, pstVarNameList);
-
-            //import all data
-            for (int i = 0; i < iNbItem; i++)
-            {
-                if (import_variable(pvApiCtx, iFile, pstVarNameList[i]) == false)
-                {
-                    bImport = false;
-                    break;
-                }
-            }
-
-            freeArrayOfString(pstVarNameList, iNbItem);
-        }
-    }
-    //close the file
+    int version = getSODFormatAttribute(iFile);
     closeHDF5File(iFile);
-
-    int *piReturn = NULL;
-
-    sciErr = allocMatrixOfBoolean(pvApiCtx, nbIn + 1, 1, 1, &piReturn);
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return 1;
-    }
-
-    if (bImport == true)
-    {
-        piReturn[0] = 1;
-    }
-    else
-    {
-        piReturn[0] = 0;
-    }
-
-    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
-    ReturnArguments(pvApiCtx);
-
-    //  printf("End gateway !!!\n");
-    return 0;
-}
-
-static bool import_variable(int* pvCtx, int _iFile, char* _pstVarName)
-{
-    int iDataSetId = getDataSetIdFromName(_iFile, _pstVarName);
-    if (iDataSetId <= 0)
-    {
-        return false;
-    }
-
-    return import_data(pvCtx, iDataSetId, 0, NULL, _pstVarName);
-}
-
-static bool import_data(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    bool bRet = false;
-
-    //get var type
-    int iVarType = getScilabTypeFromDataSet(_iDatasetId);
-
-    switch (iVarType)
+    switch (version)
     {
-        case sci_matrix:
-        {
-            bRet = import_double(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        case sci_strings:
-        {
-            bRet = import_string(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        case sci_list:
-        case sci_tlist:
-        case sci_mlist:
-        {
-            bRet = import_hypermat(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
-            if (bRet == false)
-            {
-                bRet = import_struct(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
-            }
-            if (bRet == false)
-            {
-                bRet = import_cell(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
-            }
-            if (bRet == false)
-            {
-                bRet = import_list(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
-            }
-            break;
-        }
-        case sci_boolean:
-        {
-            bRet = import_boolean(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        case sci_poly:
-        {
-            bRet = import_poly(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        case sci_ints:
+        case -1:
+        case 1:
         {
-            bRet = import_integer(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            wstFuncName = L"import_from_hdf5_v1";
             break;
         }
-        case sci_sparse:
+        case 2:
         {
-            bRet = import_sparse(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            wstFuncName = L"import_from_hdf5_v2";
             break;
         }
-        case sci_boolean_sparse:
+        case 3:
         {
-            bRet = import_boolean_sparse(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            wstFuncName = L"import_from_hdf5_v3";
             break;
         }
-        case sci_void:             //void item only on list variable
-        {
-            bRet = import_void(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        case sci_undefined:        //undefined item only on list variable
-        {
-            bRet = import_undefined(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
-            break;
-        }
-        default:
-        {
-            Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "import_from_hdf5");
-        }
-    }
-    return bRet;
-}
-
-static bool import_void(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    SciErr sciErr;
-
-    if (_piAddress)
-    {
-        sciErr = createVoidInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos);
-    }
-    else
-    {
-        return false;
-    }
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    //close void dataset
-    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 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
-            FREE(piDims);
-            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
-    {
-        /*bug 7224 : to close dataset */
-        iRet = readEmptyMatrix(_iDatasetId);
-        if (iRet)
-        {
-            if (piDims)
-            {
-                FREE(piDims);
-            }
-
-            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_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;
-}
-
-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);
-            }
-        }
-        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);
-            }
-        }
-        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);
-            }
-        }
-        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);
-            }
-        }
-        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);
-            }
-        }
-        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);
-            }
-        }
-        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);
-            }
-#else
-            FREE(piDims);
-            return false;
-#endif
-        }
-        break;
-        case SCI_UINT64:
+        default :
         {
-#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);
-            }
-#else
-            FREE(piDims);
-            return false;
-#endif
+            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, version);
+            return types::Function::Error;
         }
-        break;
-        default:
-            return false;
-    }
-
-    FREE(piDims);
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    return true;
-}
-
-static bool import_boolean(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    int iRet = 0;
-    int *piData = NULL;
-    int iDims = 0;
-    int* piDims = NULL;
-    int iComplex = 0;
-    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 (iSize == 0)
-    {
-        FREE(piDims);
-        return false;
-    }
-
-    piData = (int *)MALLOC(iSize * sizeof(int));
-    iRet = readBooleanMatrix(_iDatasetId, piData);
-    if (iRet)
-    {
-        FREE(piData);
-        FREE(piDims);
-        return false;
-    }
-
-    if (_piAddress == NULL)
-    {
-        sciErr = createNamedMatrixOfBoolean(pvCtx, _pstVarname, piDims[0], piDims[1], piData);
-    }
-    else                        //if not null this variable is in a list
-    {
-        sciErr = createMatrixOfBooleanInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], piData);
-    }
-
-    FREE(piDims);
-    if (piData)
-    {
-        FREE(piData);
-    }
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    return true;
-}
-
-static bool import_poly(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    int iRet = 0;
-    int iComplex = 0;
-    char pstVarName[64] = { 0 };
-    double **pdblReal = NULL;
-    double **pdblImg = NULL;
-    int *piNbCoef = NULL;
-    int iDims = 0;
-    int* piDims = NULL;
-    int iSize = 0;
-    SciErr sciErr;
-
-    iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL);
-    if (iRet < 0)
-    {
-        return false;
     }
 
-    piDims = (int*)MALLOC(sizeof(int) * iDims);
-    iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);
-
-    if (iComplex)
-    {
-        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
-        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
-        pdblImg = (double **)MALLOC(iSize * sizeof(double *));
-        iRet = readPolyComplexMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal, pdblImg);
-    }
-    else
-    {
-        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
-        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
-        iRet = readPolyMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal);
-    }
-
-    if (iRet)
-    {
-        FREE(piDims);
-        FREE(piNbCoef);
-        for (int i = 0; i < iSize; i++)
-        {
-            FREE(pdblReal[i]);
-        }
-        FREE(pdblReal);
-
-        if (iComplex)
-        {
-            for (int i = 0; i < iSize; i++)
-            {
-                FREE(pdblImg[i]);
-            }
-            FREE(pdblImg);
-        }
-
-        return false;
-    }
-
-    if (_piAddress == NULL)
-    {
-        if (iComplex)
-        {
-            sciErr = createNamedComplexMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg);
-        }
-        else
-        {
-            sciErr = createNamedMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal);
-        }
-    }
-    else                        //if not null this variable is in a list
-    {
-        if (iComplex)
-        {
-            sciErr =
-                createComplexMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal,
-                        pdblImg);
-        }
-        else
-        {
-            sciErr = createMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal);
-        }
-    }
-
-    FREE(piDims);
-    FREE(piNbCoef);
-    for (int i = 0; i < iSize; i++)
-    {
-        FREE(pdblReal[i]);
-    }
-
-    FREE(pdblReal);
-
-    if (iComplex)
-    {
-        for (int i = 0; i < iSize; i++)
-        {
-            FREE(pdblImg[i]);
-        }
-
-        FREE(pdblImg);
-    }
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    return true;
-}
-
-static bool import_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    int iRet = 0;
-    int iRows = 0;
-    int iCols = 0;
-    int iComplex = 0;
-    double *pdblReal = NULL;
-    double *pdblImg = NULL;
-    int iNbItem = 0;
-    int *piNbItemRow = NULL;
-    int *piColPos = NULL;
-    SciErr sciErr;
-
-    iRet = getSparseDimension(_iDatasetId, &iRows, &iCols, &iNbItem);
-    if (iRet)
-    {
-        return false;
-    }
-
-    iComplex = isComplexData(_iDatasetId);
-
-    if (iComplex)
-    {
-        piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
-        piColPos = (int *)MALLOC(iNbItem * sizeof(int));
-        pdblReal = (double *)MALLOC(iNbItem * sizeof(double));
-        pdblImg = (double *)MALLOC(iNbItem * sizeof(double));
-        iRet = readSparseComplexMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
-    }
-    else
-    {
-        piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
-        piColPos = (int *)MALLOC(iNbItem * sizeof(int));
-        pdblReal = (double *)MALLOC(iNbItem * sizeof(double));
-        iRet = readSparseMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
-    }
-
-    if (iRet)
-    {
-        FREE(piNbItemRow);
-        FREE(piColPos);
-        FREE(pdblReal);
-        if (iComplex)
-        {
-            FREE(pdblImg);
-        }
-
-        return false;
-    }
-
-    if (_piAddress == NULL)
-    {
-        if (iComplex)
-        {
-            sciErr = createNamedComplexSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
-        }
-        else
-        {
-            sciErr = createNamedSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
-        }
-    }
-    else //if not null this variable is in a list
-    {
-        if (iComplex)
-        {
-            sciErr = createComplexSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
-        }
-        else
-        {
-            sciErr = createSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
-        }
-    }
-
-    FREE(piNbItemRow);
-    FREE(piColPos);
-    FREE(pdblReal);
-    if (iComplex)
-    {
-        FREE(pdblImg);
-    }
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    return true;
-}
-
-static bool import_boolean_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    int iRet = 0;
-    int iRows = 0;
-    int iCols = 0;
-    int iNbItem = 0;
-    int *piNbItemRow = NULL;
-    int *piColPos = NULL;
-    SciErr sciErr;
-
-    iRet = getSparseDimension(_iDatasetId, &iRows, &iCols, &iNbItem);
-    if (iRet)
-    {
-        return false;
-    }
-
-    piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
-    piColPos = (int *)MALLOC(iNbItem * sizeof(int));
-
-    iRet = readBooleanSparseMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos);
-    if (iRet)
-    {
-        FREE(piNbItemRow);
-        return false;
-    }
-
-    if (_piAddress == NULL)
-    {
-        sciErr = createNamedBooleanSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos);
-    }
-    else                        //if not null this variable is in a list
-    {
-        sciErr = createBooleanSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos);
-    }
-
-    FREE(piNbItemRow);
-    FREE(piColPos);
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    return true;
-}
-
-static bool import_list(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
-{
-    int iRet = 0;
-    int i = 0;
-    int iItems = 0;
-    int *piListAddr = NULL;
-    hobj_ref_t *piItemRef = NULL;
-    SciErr sciErr;
-
-    iRet = getListDims(_iDatasetId, &iItems);
-    if (iRet)
-    {
-        return false;
-    }
-
-    if (iItems == 0)
-    {
-        //special case for empty list
-    }
-    else
-    {
-        iRet = getListItemReferences(_iDatasetId, &piItemRef);
-        if (iRet)
-        {
-            return false;
-        }
-    }
-
-    if (_piAddress == 0)
-    {
-        switch (_iVarType)
-        {
-            case sci_list:
-                sciErr = createNamedList(pvCtx, _pstVarname, iItems, &piListAddr);
-                break;
-            case sci_tlist:
-                sciErr = createNamedTList(pvCtx, _pstVarname, iItems, &piListAddr);
-                break;
-            case sci_mlist:
-                sciErr = createNamedMList(pvCtx, _pstVarname, iItems, &piListAddr);
-                break;
-            default:
-                return false;
-        }
-    }
-    else                        //if not null this variable is in a list
-    {
-        switch (_iVarType)
-        {
-            case sci_list:
-                sciErr = createListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
-                break;
-            case sci_tlist:
-                sciErr = createTListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
-                break;
-            case sci_mlist:
-                sciErr = createMListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
-                break;
-            default:
-                return false;
-        }
-    }
-
-    if (sciErr.iErr)
-    {
-        printError(&sciErr, 0);
-        return false;
-    }
-
-    for (i = 0; i < iItems; i++)
-    {
-        int iItemDataset = 0;
-
-        iRet = getListItemDataset(_iDatasetId, piItemRef, i, &iItemDataset);
-        if (iRet || iItemDataset == 0)
-        {
-            return false;
-        }
-
-        bool bRet = import_data(pvCtx, iItemDataset, i + 1, piListAddr, _pstVarname);
-
-        if (bRet == false)
-        {
-            return false;
-        }
-    }
-
-    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)
-    {
-        return false;
-    }
-
-    // get first item
-    int iItemDataset = 0;
-    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
-    if (iRet || iItemDataset == 0)
-    {
-        return false;
-    }
-
-    // get first item type
-    int iItemType = getScilabTypeFromDataSet(iItemDataset);
-    if (iItemType != sci_strings)
-    {
-        return false;
-    }
-
-    // get size of first item
-    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
-    if (iRet < 0 || iDims != 2)
-    {
-        return false;
-    }
-
-    int* piDims = new int[2];
-    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
-    if (iSize != 3)
-    {
-        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)
-    {
-        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)
-    {
-        return false;
-    }
-
-    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
-    if (iRet < 0 || iDims != 2)
-    {
-        return false;
-    }
-
-    piDims = new int[2];
-    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
-    if (piDims[0] != 1)
-    {
-        delete[] piDims;
-        return false;
-    }
-
-    int* piDimsArray = new int[piDims[1]];
-    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
-    if (iRet)
-    {
-        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)
-    {
-        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;
-}
-/*--------------------------------------------------------------------------*/
-
-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)
-    {
-        return false;
-    }
-
-    // get first item
-    int iItemDataset = 0;
-    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
-    if (iRet || iItemDataset == 0)
-    {
-        return false;
-    }
-
-    // get first item type
-    int iItemType = getScilabTypeFromDataSet(iItemDataset);
-    if (iItemType != sci_strings)
-    {
-        return false;
-    }
-
-    // get size of first item
-    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
-    if (iRet < 0 || iDims != 2)
-    {
-        return false;
-    }
-
-    int* piDims = new int[2];
-    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
-    if (iSize != iItems)
-    {
-        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)
-    {
-        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)
-    {
-        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)
-    {
-        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)
-    {
-        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)
-    {
-        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)
-            {
-                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)
-            {
-                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)
-            {
-                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)
-            {
-                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 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)
-    {
-        return false;
-    }
-
-    // get first item
-    int iItemDataset = 0;
-    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
-    if (iRet || iItemDataset == 0)
-    {
-        return false;
-    }
-
-    // get first item type
-    int iItemType = getScilabTypeFromDataSet(iItemDataset);
-    if (iItemType != sci_strings)
-    {
-        return false;
-    }
-
-    // get size of first item
-    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
-    if (iRet < 0 || iDims != 2)
-    {
-        return false;
-    }
-
-    int* piDims = new int[2];
-    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
-    if (iSize != 3)
-    {
-        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)
-    {
-        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)
-    {
-        return false;
-    }
-
-    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
-    if (iRet < 0 || iDims != 2)
-    {
-        return false;
-    }
-
-    piDims = new int[2];
-    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
-    if (piDims[0] != 1)
-    {
-        delete[] piDims;
-        return false;
-    }
-
-    int* piDimsArray = new int[piDims[1]];
-    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
-    if (iRet)
-    {
-        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)
-    {
-        delete pList;
-        delete pCell;
-        return false;
-    }
-
-    bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, NULL);
-    if (bRet == false)
-    {
-        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;
-}
-/*--------------------------------------------------------------------------*/
 
+    ast::ExecVisitor exec;
+    return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
+}
\ No newline at end of file
diff --git a/scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v2.cpp b/scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v2.cpp
new file mode 100644 (file)
index 0000000..d36b3dd
--- /dev/null
@@ -0,0 +1,1714 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2009 - DIGITEO - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#include <hdf5.h>
+#include "context.hxx"
+#include "list.hxx"
+#include "struct.hxx"
+#include "cell.hxx"
+
+extern "C"
+{
+#include <string.h>
+#include "gw_hdf5.h"
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "api_scilab.h"
+#include "../../../call_scilab/includes/call_scilab.h"
+#include "h5_fileManagement.h"
+#include "h5_readDataFromFile.h"
+#include "h5_attributeConstants.h"
+#include "expandPathVariable.h"
+#include "stdlib.h"
+#include "freeArrayOfString.h"
+}
+
+#include "import_from_hdf5_v1.hxx"
+
+static bool import_variable(int* pvCtx, int _iFile, char* _pstVarName);
+static bool import_data(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_double(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_string(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_boolean(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_integer(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_boolean_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_poly(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_list(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_hypermat(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_struct(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_cell(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_void(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+static bool import_undefined(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname);
+
+static const std::string fname("import_from_hdf5");
+
+int sci_import_from_hdf5_v2(char *fn, int* pvApiCtx)
+{
+    SciErr sciErr;
+
+    int* piAddr = NULL;
+    char* pstFilename = NULL;
+    char* pstExpandedFilename = NULL;
+    bool bImport = true;
+    const int nbIn = nbInputArgument(pvApiCtx);
+    int iSelectedVar = nbIn - 1;
+
+    CheckInputArgumentAtLeast(pvApiCtx , 1);
+    CheckOutputArgument(pvApiCtx, 1, 1);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 1;
+    }
+
+    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFilename))
+    {
+        if (pstFilename)
+        {
+            freeAllocatedSingleString(pstFilename);
+        }
+
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 2);
+        return 1;
+    }
+
+    //open hdf5 file
+    pstExpandedFilename = expandPathVariable(pstFilename);
+    int iFile = openHDF5File(pstExpandedFilename, 0);
+    if (iFile < 0)
+    {
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), pstFilename);
+        FREE(pstExpandedFilename);
+        FREE(pstFilename);
+        return 1;
+    }
+
+    FREE(pstExpandedFilename);
+    FREE(pstFilename);
+
+    //manage version information
+    int iVersion = getSODFormatAttribute(iFile);
+    if (iVersion != SOD_FILE_VERSION)
+    {
+        if (iVersion > SOD_FILE_VERSION)
+        {
+            //can't read file with version newer that me !
+            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
+            return 1;
+        }
+        else
+        {
+            //call older import functions and exit or ... EXIT !
+            if (iVersion == 1 || iVersion == -1)
+            {
+                //sciprint("old sci_import_from_hdf5_v1\n");
+                return sci_import_from_hdf5_v1(fn, pvApiCtx);
+            }
+        }
+    }
+
+    if (iSelectedVar)
+    {
+        //selected variable
+        char* pstVarName = NULL;
+        for (int i = 0 ; i < iSelectedVar ; i++)
+        {
+            sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr);
+            if (sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 1;
+            }
+
+            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))
+            {
+                if (pstVarName)
+                {
+                    freeAllocatedSingleString(pstVarName);
+                }
+
+                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), i + 1);
+                return 1;
+            }
+
+            if (import_variable(pvApiCtx, iFile, pstVarName) == false)
+            {
+                FREE(pstVarName);
+                bImport = false;
+                break;
+            }
+
+            FREE(pstVarName);
+            pstVarName = NULL;
+        }
+    }
+    else
+    {
+        //all variables
+        int iNbItem = 0;
+        iNbItem = getVariableNames(iFile, NULL);
+        if (iNbItem != 0)
+        {
+            char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);
+
+            iNbItem = getVariableNames(iFile, pstVarNameList);
+
+            //import all data
+            for (int i = 0; i < iNbItem; i++)
+            {
+                if (import_variable(pvApiCtx, iFile, pstVarNameList[i]) == false)
+                {
+                    bImport = false;
+                    break;
+                }
+            }
+
+            freeArrayOfString(pstVarNameList, iNbItem);
+        }
+    }
+    //close the file
+    closeHDF5File(iFile);
+
+    int *piReturn = NULL;
+
+    sciErr = allocMatrixOfBoolean(pvApiCtx, nbIn + 1, 1, 1, &piReturn);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 1;
+    }
+
+    if (bImport == true)
+    {
+        piReturn[0] = 1;
+    }
+    else
+    {
+        piReturn[0] = 0;
+    }
+
+    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
+    ReturnArguments(pvApiCtx);
+
+    //  printf("End gateway !!!\n");
+    return 0;
+}
+
+static bool import_variable(int* pvCtx, int _iFile, char* _pstVarName)
+{
+    int iDataSetId = getDataSetIdFromName(_iFile, _pstVarName);
+    if (iDataSetId <= 0)
+    {
+        return false;
+    }
+
+    return import_data(pvCtx, iDataSetId, 0, NULL, _pstVarName);
+}
+
+static bool import_data(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    bool bRet = false;
+
+    //get var type
+    int iVarType = getScilabTypeFromDataSet(_iDatasetId);
+
+    switch (iVarType)
+    {
+        case sci_matrix:
+        {
+            bRet = import_double(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_strings:
+        {
+            bRet = import_string(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_list:
+        case sci_tlist:
+        case sci_mlist:
+        {
+            bRet = import_hypermat(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
+            if (bRet == false)
+            {
+                bRet = import_struct(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
+            }
+            if (bRet == false)
+            {
+                bRet = import_cell(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
+            }
+            if (bRet == false)
+            {
+                bRet = import_list(pvCtx, _iDatasetId, iVarType, _iItemPos, _piAddress, _pstVarname);
+            }
+            break;
+        }
+        case sci_boolean:
+        {
+            bRet = import_boolean(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_poly:
+        {
+            bRet = import_poly(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_ints:
+        {
+            bRet = import_integer(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_sparse:
+        {
+            bRet = import_sparse(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_boolean_sparse:
+        {
+            bRet = import_boolean_sparse(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_void:             //void item only on list variable
+        {
+            bRet = import_void(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        case sci_undefined:        //undefined item only on list variable
+        {
+            bRet = import_undefined(pvCtx, _iDatasetId, _iItemPos, _piAddress, _pstVarname);
+            break;
+        }
+        default:
+        {
+            Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "import_from_hdf5");
+        }
+    }
+    return bRet;
+}
+
+static bool import_void(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    SciErr sciErr;
+
+    if (_piAddress)
+    {
+        sciErr = createVoidInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos);
+    }
+    else
+    {
+        return false;
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    //close void dataset
+    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 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
+            FREE(piDims);
+            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
+    {
+        /*bug 7224 : to close dataset */
+        iRet = readEmptyMatrix(_iDatasetId);
+        if (iRet)
+        {
+            if (piDims)
+            {
+                FREE(piDims);
+            }
+
+            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_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;
+}
+
+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);
+            }
+        }
+        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);
+            }
+        }
+        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);
+            }
+        }
+        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);
+            }
+        }
+        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);
+            }
+        }
+        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);
+            }
+        }
+        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);
+            }
+#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);
+            }
+#else
+            FREE(piDims);
+            return false;
+#endif
+        }
+        break;
+        default:
+            return false;
+    }
+
+    FREE(piDims);
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    return true;
+}
+
+static bool import_boolean(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    int iRet = 0;
+    int *piData = NULL;
+    int iDims = 0;
+    int* piDims = NULL;
+    int iComplex = 0;
+    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 (iSize == 0)
+    {
+        FREE(piDims);
+        return false;
+    }
+
+    piData = (int *)MALLOC(iSize * sizeof(int));
+    iRet = readBooleanMatrix(_iDatasetId, piData);
+    if (iRet)
+    {
+        FREE(piData);
+        FREE(piDims);
+        return false;
+    }
+
+    if (_piAddress == NULL)
+    {
+        sciErr = createNamedMatrixOfBoolean(pvCtx, _pstVarname, piDims[0], piDims[1], piData);
+    }
+    else                        //if not null this variable is in a list
+    {
+        sciErr = createMatrixOfBooleanInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, piDims[0], piDims[1], piData);
+    }
+
+    FREE(piDims);
+    if (piData)
+    {
+        FREE(piData);
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    return true;
+}
+
+static bool import_poly(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    int iRet = 0;
+    int iComplex = 0;
+    char pstVarName[64] = { 0 };
+    double **pdblReal = NULL;
+    double **pdblImg = NULL;
+    int *piNbCoef = NULL;
+    int iDims = 0;
+    int* piDims = NULL;
+    int iSize = 0;
+    SciErr sciErr;
+
+    iRet = getDatasetInfo(_iDatasetId, &iComplex, &iDims, NULL);
+    if (iRet < 0)
+    {
+        return false;
+    }
+
+    piDims = (int*)MALLOC(sizeof(int) * iDims);
+    iSize = getDatasetInfo(_iDatasetId, &iComplex, &iDims, piDims);
+
+    if (iComplex)
+    {
+        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
+        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
+        pdblImg = (double **)MALLOC(iSize * sizeof(double *));
+        iRet = readPolyComplexMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal, pdblImg);
+    }
+    else
+    {
+        piNbCoef = (int *)MALLOC(iSize * sizeof(int));
+        pdblReal = (double **)MALLOC(iSize * sizeof(double *));
+        iRet = readPolyMatrix(_iDatasetId, pstVarName, iDims, piDims, piNbCoef, pdblReal);
+    }
+
+    if (iRet)
+    {
+        FREE(piDims);
+        FREE(piNbCoef);
+        for (int i = 0; i < iSize; i++)
+        {
+            FREE(pdblReal[i]);
+        }
+        FREE(pdblReal);
+
+        if (iComplex)
+        {
+            for (int i = 0; i < iSize; i++)
+            {
+                FREE(pdblImg[i]);
+            }
+            FREE(pdblImg);
+        }
+
+        return false;
+    }
+
+    if (_piAddress == NULL)
+    {
+        if (iComplex)
+        {
+            sciErr = createNamedComplexMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal, pdblImg);
+        }
+        else
+        {
+            sciErr = createNamedMatrixOfPoly(pvCtx, _pstVarname, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal);
+        }
+    }
+    else                        //if not null this variable is in a list
+    {
+        if (iComplex)
+        {
+            sciErr =
+                createComplexMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal,
+                        pdblImg);
+        }
+        else
+        {
+            sciErr = createMatrixOfPolyInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, pstVarName, piDims[0], piDims[1], piNbCoef, pdblReal);
+        }
+    }
+
+    FREE(piDims);
+    FREE(piNbCoef);
+    for (int i = 0; i < iSize; i++)
+    {
+        FREE(pdblReal[i]);
+    }
+
+    FREE(pdblReal);
+
+    if (iComplex)
+    {
+        for (int i = 0; i < iSize; i++)
+        {
+            FREE(pdblImg[i]);
+        }
+
+        FREE(pdblImg);
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    return true;
+}
+
+static bool import_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    int iRet = 0;
+    int iRows = 0;
+    int iCols = 0;
+    int iComplex = 0;
+    double *pdblReal = NULL;
+    double *pdblImg = NULL;
+    int iNbItem = 0;
+    int *piNbItemRow = NULL;
+    int *piColPos = NULL;
+    SciErr sciErr;
+
+    iRet = getSparseDimension(_iDatasetId, &iRows, &iCols, &iNbItem);
+    if (iRet)
+    {
+        return false;
+    }
+
+    iComplex = isComplexData(_iDatasetId);
+
+    if (iComplex)
+    {
+        piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
+        piColPos = (int *)MALLOC(iNbItem * sizeof(int));
+        pdblReal = (double *)MALLOC(iNbItem * sizeof(double));
+        pdblImg = (double *)MALLOC(iNbItem * sizeof(double));
+        iRet = readSparseComplexMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
+    }
+    else
+    {
+        piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
+        piColPos = (int *)MALLOC(iNbItem * sizeof(int));
+        pdblReal = (double *)MALLOC(iNbItem * sizeof(double));
+        iRet = readSparseMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
+    }
+
+    if (iRet)
+    {
+        FREE(piNbItemRow);
+        FREE(piColPos);
+        FREE(pdblReal);
+        if (iComplex)
+        {
+            FREE(pdblImg);
+        }
+
+        return false;
+    }
+
+    if (_piAddress == NULL)
+    {
+        if (iComplex)
+        {
+            sciErr = createNamedComplexSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
+        }
+        else
+        {
+            sciErr = createNamedSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
+        }
+    }
+    else //if not null this variable is in a list
+    {
+        if (iComplex)
+        {
+            sciErr = createComplexSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal, pdblImg);
+        }
+        else
+        {
+            sciErr = createSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos, pdblReal);
+        }
+    }
+
+    FREE(piNbItemRow);
+    FREE(piColPos);
+    FREE(pdblReal);
+    if (iComplex)
+    {
+        FREE(pdblImg);
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    return true;
+}
+
+static bool import_boolean_sparse(int* pvCtx, int _iDatasetId, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    int iRet = 0;
+    int iRows = 0;
+    int iCols = 0;
+    int iNbItem = 0;
+    int *piNbItemRow = NULL;
+    int *piColPos = NULL;
+    SciErr sciErr;
+
+    iRet = getSparseDimension(_iDatasetId, &iRows, &iCols, &iNbItem);
+    if (iRet)
+    {
+        return false;
+    }
+
+    piNbItemRow = (int *)MALLOC(iRows * sizeof(int));
+    piColPos = (int *)MALLOC(iNbItem * sizeof(int));
+
+    iRet = readBooleanSparseMatrix(_iDatasetId, iRows, iCols, iNbItem, piNbItemRow, piColPos);
+    if (iRet)
+    {
+        FREE(piNbItemRow);
+        return false;
+    }
+
+    if (_piAddress == NULL)
+    {
+        sciErr = createNamedBooleanSparseMatrix(pvCtx, _pstVarname, iRows, iCols, iNbItem, piNbItemRow, piColPos);
+    }
+    else                        //if not null this variable is in a list
+    {
+        sciErr = createBooleanSparseMatrixInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iRows, iCols, iNbItem, piNbItemRow, piColPos);
+    }
+
+    FREE(piNbItemRow);
+    FREE(piColPos);
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    return true;
+}
+
+static bool import_list(int* pvCtx, int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, char *_pstVarname)
+{
+    int iRet = 0;
+    int i = 0;
+    int iItems = 0;
+    int *piListAddr = NULL;
+    hobj_ref_t *piItemRef = NULL;
+    SciErr sciErr;
+
+    iRet = getListDims(_iDatasetId, &iItems);
+    if (iRet)
+    {
+        return false;
+    }
+
+    if (iItems == 0)
+    {
+        //special case for empty list
+    }
+    else
+    {
+        iRet = getListItemReferences(_iDatasetId, &piItemRef);
+        if (iRet)
+        {
+            return false;
+        }
+    }
+
+    if (_piAddress == 0)
+    {
+        switch (_iVarType)
+        {
+            case sci_list:
+                sciErr = createNamedList(pvCtx, _pstVarname, iItems, &piListAddr);
+                break;
+            case sci_tlist:
+                sciErr = createNamedTList(pvCtx, _pstVarname, iItems, &piListAddr);
+                break;
+            case sci_mlist:
+                sciErr = createNamedMList(pvCtx, _pstVarname, iItems, &piListAddr);
+                break;
+            default:
+                return false;
+        }
+    }
+    else                        //if not null this variable is in a list
+    {
+        switch (_iVarType)
+        {
+            case sci_list:
+                sciErr = createListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
+                break;
+            case sci_tlist:
+                sciErr = createTListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
+                break;
+            case sci_mlist:
+                sciErr = createMListInNamedList(pvCtx, _pstVarname, _piAddress, _iItemPos, iItems, &piListAddr);
+                break;
+            default:
+                return false;
+        }
+    }
+
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return false;
+    }
+
+    for (i = 0; i < iItems; i++)
+    {
+        int iItemDataset = 0;
+
+        iRet = getListItemDataset(_iDatasetId, piItemRef, i, &iItemDataset);
+        if (iRet || iItemDataset == 0)
+        {
+            return false;
+        }
+
+        bool bRet = import_data(pvCtx, iItemDataset, i + 1, piListAddr, _pstVarname);
+
+        if (bRet == false)
+        {
+            return false;
+        }
+    }
+
+    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)
+    {
+        return false;
+    }
+
+    // get first item
+    int iItemDataset = 0;
+    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
+    if (iRet || iItemDataset == 0)
+    {
+        return false;
+    }
+
+    // get first item type
+    int iItemType = getScilabTypeFromDataSet(iItemDataset);
+    if (iItemType != sci_strings)
+    {
+        return false;
+    }
+
+    // get size of first item
+    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
+    if (iRet < 0 || iDims != 2)
+    {
+        return false;
+    }
+
+    int* piDims = new int[2];
+    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
+    if (iSize != 3)
+    {
+        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)
+    {
+        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)
+    {
+        return false;
+    }
+
+    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
+    if (iRet < 0 || iDims != 2)
+    {
+        return false;
+    }
+
+    piDims = new int[2];
+    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
+    if (piDims[0] != 1)
+    {
+        delete[] piDims;
+        return false;
+    }
+
+    int* piDimsArray = new int[piDims[1]];
+    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
+    if (iRet)
+    {
+        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)
+    {
+        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;
+}
+/*--------------------------------------------------------------------------*/
+
+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)
+    {
+        return false;
+    }
+
+    // get first item
+    int iItemDataset = 0;
+    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
+    if (iRet || iItemDataset == 0)
+    {
+        return false;
+    }
+
+    // get first item type
+    int iItemType = getScilabTypeFromDataSet(iItemDataset);
+    if (iItemType != sci_strings)
+    {
+        return false;
+    }
+
+    // get size of first item
+    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
+    if (iRet < 0 || iDims != 2)
+    {
+        return false;
+    }
+
+    int* piDims = new int[2];
+    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
+    if (iSize != iItems)
+    {
+        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)
+    {
+        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)
+    {
+        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)
+    {
+        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)
+    {
+        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)
+    {
+        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)
+            {
+                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)
+            {
+                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)
+            {
+                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)
+            {
+                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 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)
+    {
+        return false;
+    }
+
+    // get first item
+    int iItemDataset = 0;
+    iRet = getListItemDataset(_iDatasetId, piItemRef, 0, &iItemDataset);
+    if (iRet || iItemDataset == 0)
+    {
+        return false;
+    }
+
+    // get first item type
+    int iItemType = getScilabTypeFromDataSet(iItemDataset);
+    if (iItemType != sci_strings)
+    {
+        return false;
+    }
+
+    // get size of first item
+    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
+    if (iRet < 0 || iDims != 2)
+    {
+        return false;
+    }
+
+    int* piDims = new int[2];
+    int iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
+    if (iSize != 3)
+    {
+        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)
+    {
+        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)
+    {
+        return false;
+    }
+
+    iRet = getDatasetInfo(iItemDataset, &iComplex, &iDims, NULL);
+    if (iRet < 0 || iDims != 2)
+    {
+        return false;
+    }
+
+    piDims = new int[2];
+    iSize = getDatasetInfo(iItemDataset, &iComplex, &iDims, piDims);
+    if (piDims[0] != 1)
+    {
+        delete[] piDims;
+        return false;
+    }
+
+    int* piDimsArray = new int[piDims[1]];
+    iRet = readInteger32Matrix(iItemDataset, piDimsArray);
+    if (iRet)
+    {
+        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)
+    {
+        delete pList;
+        delete pCell;
+        return false;
+    }
+
+    bool bRet = import_data(pvCtx, iItemDataset, 1, (int*)pList, NULL);
+    if (bRet == false)
+    {
+        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;
+}
+/*--------------------------------------------------------------------------*/
+
diff --git a/scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v3.cpp b/scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v3.cpp
new file mode 100644 (file)
index 0000000..3ddfb7c
--- /dev/null
@@ -0,0 +1,1028 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+#include <list>
+#include <map>
+#include <hdf5.h>
+#include "hdf5_gw.hxx"
+#include "context.hxx"
+#include "string.hxx"
+#include "double.hxx"
+#include "struct.hxx"
+#include "cell.hxx"
+#include "int.hxx"
+#include "list.hxx"
+#include "tlist.hxx"
+#include "mlist.hxx"
+#include "polynom.hxx"
+#include "sparse.hxx"
+#include "graphichandle.hxx"
+#include "macro.hxx"
+#include "void.hxx"
+#include "listundefined.hxx"
+#include "context.hxx"
+#include "handle_properties.hxx"
+#include "deserializervisitor.hxx"
+
+std::unordered_map<int, Links::PathList> Links::paths;
+
+extern "C"
+{
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "freeArrayOfString.h"
+#include "os_string.h"
+#include "deleteafile.h"
+#include "expandPathVariable.h"
+#include "h5_fileManagement.h"
+#include "h5_writeDataToFile.h"
+#include "h5_readDataFromFile.h"
+#include "h5_attributeConstants.h"
+#include "HandleManagement.h"
+
+}
+/*--------------------------------------------------------------------------*/
+static bool import_variable(int file, std::string& name);
+types::InternalType* import_data(int dataset);
+static types::InternalType* import_double(int dataset);
+static types::InternalType* import_string(int dataset);
+static types::InternalType* import_boolean(int dataset);
+static types::InternalType* import_int(int dataset);
+static types::InternalType* import_list(int dataset, types::List* lst);
+static types::InternalType* import_struct(int dataset);
+static types::InternalType* import_poly(int dataset);
+static types::InternalType* import_cell(int dataset);
+static types::InternalType* import_handles(int dataset);
+
+static types::InternalType* import_sparse(int dataset);
+static types::InternalType* import_boolean_sparse(int dataset);
+static types::InternalType* import_macro(int dataset);
+
+
+/*--------------------------------------------------------------------------*/
+static const std::string fname("import_from_hdf5");
+/*--------------------------------------------------------------------------*/
+types::Function::ReturnValue sci_import_from_hdf5_v3(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    std::string filename;
+    int rhs = static_cast<int>(in.size());
+
+    if (rhs < 1)
+    {
+        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
+        return types::Function::Error;
+    }
+
+    if (in[0]->getId() != types::InternalType::IdScalarString)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
+        return types::Function::Error;
+    }
+
+    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
+    char* cfilename = wide_string_to_UTF8(wfilename);
+    filename = cfilename;
+    FREE(wfilename);
+    FREE(cfilename);
+
+    int iFile = openHDF5File(filename.data(), 0);
+    if (iFile < 0)
+    {
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
+        return types::Function::Error;
+    }
+
+    //manage version information
+    int iVersion = getSODFormatAttribute(iFile);
+    if (iVersion != SOD_FILE_VERSION)
+    {
+        if (iVersion > SOD_FILE_VERSION)
+        {
+            //can't read file with version newer that me !
+            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
+            return types::Function::Error;
+        }
+        else
+        {
+            //call older import functions and exit or ... EXIT !
+            if (iVersion == 1 || iVersion == -1)
+            {
+                //sciprint("old sci_import_from_hdf5_v1\n");
+                //return sci_import_from_hdf5_v1(fname, pvApiCtx);
+            }
+        }
+    }
+
+    if (rhs > 1)
+    {
+        for (int i = 1; i < rhs; ++i)
+        {
+            std::string var;
+            char* cvar = wide_string_to_UTF8(in[i]->getAs<types::String>()->get()[0]);
+            var = cvar;
+            FREE(cvar);
+
+            if (import_variable(iFile, var) == false)
+            {
+                Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), var.data());
+                return types::Function::Error;
+            }
+        }
+    }
+    else
+    {
+        //restore all variables
+        int iNbItem = 0;
+        iNbItem = getVariableNames6(iFile, NULL);
+        if (iNbItem != 0)
+        {
+            std::vector<char*> vars(iNbItem);
+            iNbItem = getVariableNames6(iFile, vars.data());
+            for (auto &var : vars)
+            {
+                std::string s(var);
+                if (import_variable(iFile, s) == false)
+                {
+                    Scierror(999, _("%s: Unable to load \'%s\'.\n"), fname.data(), var);
+                    return types::Function::Error;
+                }
+            }
+        }
+    }
+
+    //close the file
+    closeHDF5File(iFile);
+
+    out.push_back(new types::Bool(1));
+    return types::Function::OK;
+}
+
+static bool import_variable(int file, std::string& name)
+{
+    int dataset = getDataSetIdFromName(file, name.data());
+    if (dataset <= 0)
+    {
+        return false;
+    }
+
+    types::InternalType* data = import_data(dataset);
+    if (data != nullptr)
+    {
+        wchar_t* var = to_wide_string(name.data());
+        //update macro name
+        if (data->isMacro())
+        {
+            types::Macro* macro = data->getAs<types::Macro>();
+            macro->setName(var);
+            symbol::Context::getInstance()->addMacro(macro);
+        }
+        else
+        {
+            //add to context
+            symbol::Context::getInstance()->put(symbol::Symbol(var), data);
+        }
+        FREE(var);
+        return true;
+    }
+
+    return false;
+}
+
+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();
+    }
+
+    return nullptr;
+}
+
+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 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_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 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 types::InternalType* import_list(int dataset, types::List* lst)
+{
+    int count = 0;
+    int ret  = getListDims6(dataset, &count);
+    if (ret)
+    {
+        closeList6(dataset);
+        delete lst;
+        return nullptr;
+    }
+
+    if (count == 0)
+    {
+        closeList6(dataset);
+        return lst;
+    }
+
+    //get children
+
+    for (int i = 0; i < count; ++i)
+    {
+        int data = getDataSetIdFromName(dataset, std::to_string(i).data());
+        if (data <= 0)
+        {
+            closeList6(dataset);
+            delete lst;
+            return nullptr;
+        }
+
+        types::InternalType* child = import_data(data);
+        if (child == nullptr)
+        {
+            closeList6(dataset);
+            delete lst;
+            return nullptr;
+        }
+
+        lst->append(child);
+    }
+
+    closeList6(dataset);
+    return lst;
+}
+
+static int getDimsNode(int dataset, int* complex, std::vector<int>& dims)
+{
+    dims.clear();
+    int id = getDataSetIdFromName(dataset, "__dims__");
+    if (id < 0)
+    {
+        return 0;
+    }
+
+    //get dims dimension count
+    int dim = 0;
+    getDatasetInfo(id, complex, &dim, NULL);
+    //get dims dimension
+    std::vector<int> d(dim);
+    int size = getDatasetInfo(id, complex, &dim, d.data());
+
+    //get dims value
+    dims.resize(size);
+    readInteger32Matrix(id, dims.data());
+
+    size = dims[0];
+    for (int i = 1; i < dims.size(); ++i)
+    {
+        size *= dims[i];
+    }
+    return size;
+}
+
+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);
+        return new types::Struct();
+    }
+
+    types::SingleStruct** sstr = str->get();
+
+    int fieldCount = 0;
+    int ret = getListDims6(dataset, &fieldCount);
+    if (ret < 0)
+    {
+        closeList6(dataset);
+        return str;
+    }
+
+    //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);
+
+        if (strcmp(name, "__dims__") != 0 && strcmp(name, "__refs__") != 0)
+        {
+            wchar_t* field = to_wide_string(name);
+            str->addField(field);
+
+            int dataref = getDataSetIdFromName(dataset, name);
+            if (dataref < 0)
+            {
+                closeList6(dataset);
+                FREE(name);
+                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)
+            {
+                FREE(name);
+                return nullptr;
+            }
+
+
+            //import field
+            for (int j = 0; j < refcount; ++j)
+            {
+                int data = H5Rdereference(refs, H5R_OBJECT, &vrefs[j]);
+                if (data < 0)
+                {
+                    FREE(name);
+                    return nullptr;
+                }
+
+                types::InternalType* val = import_data(data);
+                if (val == nullptr)
+                {
+                    FREE(name);
+                    return nullptr;
+                }
+
+                sstr[j]->set(field, val);
+
+            }
+            FREE(field);
+
+            closeDataSet(dataref);
+        }
+
+        FREE(name);
+    }
+    //str->addField();
+
+    closeList6(refs);
+    closeList6(dataset);
+    return str;
+}
+
+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;
+}
+
+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());
+
+    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());
+
+    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());
+
+    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;
+}
+
+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());
+
+    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());
+
+    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());
+}
+
+static types::InternalType* import_cell(int dataset)
+{
+    //get sparse dimensions
+    int complex = 0;
+    std::vector<int> pdims;
+    int size = getDimsNode(dataset, &complex, pdims);
+
+    if (size == 0)
+    {
+        closeList6(dataset);
+        return new types::Cell();
+    }
+
+    //open __refs__ node
+    int refs = getDataSetIdFromName(dataset, "__refs__");
+    std::vector<types::InternalType*> data(size);
+    for (int i = 0; i < size; ++i)
+    {
+        int ref = getDataSetIdFromName(refs, std::to_string(i).data());
+        types::InternalType* val = import_data(ref);
+        if (val == nullptr)
+        {
+            return nullptr;
+        }
+
+        data[i] = val;
+    }
+
+    types::Cell* cell = new types::Cell(static_cast<int>(pdims.size()), pdims.data(), data.data());
+
+    closeList6(refs);
+    closeList6(dataset);
+    return cell;
+}
+
+static types::InternalType* import_handles(int dataset)
+{
+    //get sparse dimensions
+    int complex = 0;
+    std::vector<int> pdims;
+    int size = getDimsNode(dataset, &complex, pdims);
+
+    if (size == 0)
+    {
+        closeList6(dataset);
+        return nullptr;
+    }
+
+    //open __refs__ node
+    int refs = getDataSetIdFromName(dataset, "__refs__");
+    types::GraphicHandle* handles = new types::GraphicHandle(static_cast<int>(pdims.size()), pdims.data());
+    long long* h = handles->get();
+    for (int i = 0; i < size; ++i)
+    {
+        int ref = getDataSetIdFromName(refs, std::to_string(i).data());
+        int val = import_handle(ref, -1);
+        if (val < 0)
+        {
+            return nullptr;
+        }
+
+        h[i] = getHandle(val);
+    }
+
+    closeList6(refs);
+    closeList6(dataset);
+
+
+    //update links property of legend handle
+    if (Links::count())
+    {
+        std::list<int> legends = Links::legends();
+        for (auto& i : legends)
+        {
+            Links::PathList paths = Links::get(i);
+            update_link_path(i, paths);
+        }
+    }
+    return handles;
+
+}
+
+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());
+    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());
+    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());
+    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");
+
+    closeList6(dataset);
+    return macro;
+}
index c8ac83d..0bacad6 100644 (file)
@@ -1,6 +1,6 @@
 /*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2012 - DIGITEO - Antoine ELIAS
+* Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 */
 
 #include <hdf5.h>
+#include "hdf5_gw.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
+
 extern "C"
 {
-#include <string.h>
-#include "gw_hdf5.h"
 #include "sci_malloc.h"
 #include "Scierror.h"
-#include "localization.h"
-#include "sciprint.h"
-#include "api_scilab.h"
-#include "../../../call_scilab/includes/call_scilab.h"
+#include "expandPathVariable.h"
 #include "h5_fileManagement.h"
-#include "h5_readDataFromFile.h"
 #include "h5_attributeConstants.h"
-#include "expandPathVariable.h"
-#include "freeArrayOfString.h"
+#include "h5_readDataFromFile.h"
 }
 
-#include "listvar_in_hdf5_v1.hxx"
-#include <vector>
+static const std::string fname("listvar_in_hdf5");
 
-typedef struct __VAR_INFO__
+types::Function::ReturnValue sci_listvar_in_hdf5(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
-    char pstInfo[128];
-    char varName[128];
-    int iType;
-    int iSize;
-    int iDims;
-    int piDims[2];
-
-    __VAR_INFO__() : iType(0), iSize(0), iDims(0)
+    int rhs = static_cast<int>(in.size());
+    if (rhs < 1)
     {
-        memset(pstInfo, 0, sizeof(pstInfo) / sizeof(pstInfo[0]));
-        memset(varName, 0, sizeof(varName) / sizeof(varName[0]));
+        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
+        return types::Function::Error;
     }
-} VarInfo;
-
-static bool read_data(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_double(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_string(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_boolean(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_integer(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_sparse(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_boolean_sparse(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_poly(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_list(int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_void(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
-static bool read_undefined(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
 
-static void generateInfo(VarInfo* _pInfo, const char* _pstType);
-
-int sci_listvar_in_hdf5(char *fname, int* pvApiCtx)
-{
-    SciErr sciErr;
-    int *piAddr     = NULL;
-    char* pstFile   = NULL;
-    int iFile       = 0;
-    int iNbItem     = 0;
-    VarInfo* pInfo  = NULL;
-    const int nbIn = nbInputArgument(pvApiCtx);
-
-    CheckInputArgument(pvApiCtx, 1, 1);
-    CheckOutputArgument(pvApiCtx, 1, 4);
-
-    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
-    if (sciErr.iErr)
+    if (in[0]->getId() != types::InternalType::IdScalarString)
     {
-        printError(&sciErr, 0);
-        return 1;
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
+        return types::Function::Error;
     }
 
-    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile))
-    {
-        if (pstFile)
-        {
-            FREE(pstFile);
-        }
+    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
+    char* cfilename = wide_string_to_UTF8(wfilename);
+    std::string filename = cfilename;
+    FREE(wfilename);
+    FREE(cfilename);
 
-        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
-        return 1;
-    }
-
-    char* pstFileName = expandPathVariable(pstFile);
-    iFile = openHDF5File(pstFileName, 0);
+    int iFile = openHDF5File(filename.data(), 0);
     if (iFile < 0)
     {
-        Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile);
-        FREE(pstFileName);
-        FREE(pstFile);
-        return 1;
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
+        return types::Function::Error;
     }
 
-    FREE(pstFileName);
-    FREE(pstFile);
-
+    std::wstring wstFuncName;
     //manage version information
-    int iVersion = getSODFormatAttribute(iFile);
-    if (iVersion != SOD_FILE_VERSION)
-    {
-        if (iVersion > SOD_FILE_VERSION)
-        {
-            //can't read file with version newer that me !
-            closeHDF5File(iFile);
-            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion);
-            return 1;
-        }
-        else
-        {
-            //call older import functions and exit or ... EXIT !
-            if (iVersion == 1 || iVersion == -1)
-            {
-                //sciprint("old sci_listvar_in_hdf5_v1\n");
-                return sci_listvar_in_hdf5_v1(fname, pvApiCtx);
-            }
-        }
-    }
-
-    iNbItem = getVariableNames(iFile, NULL);
-    if (iNbItem != 0)
-    {
-        char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem);
-        pInfo = (VarInfo*)MALLOC(iNbItem * sizeof(VarInfo));
-        int b;
-
-        if (Lhs == 1)
-        {
-            sciprint("Name                     Type           Size            Bytes\n");
-            sciprint("---------------------------------------------------------------\n");
-        }
-
-        iNbItem = getVariableNames(iFile, pstVarNameList);
-        for (int i = 0; i < iNbItem; i++)
-        {
-            int iDataSetId = getDataSetIdFromName(iFile, pstVarNameList[i]);
-            if (iDataSetId == 0)
-            {
-                break;
-            }
-
-            strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName) - 1);
-            pInfo[i].iSize = 0;
-            b = read_data(iDataSetId, 0, NULL, &pInfo[i]) == false;
-            if (b)
-            {
-                break;
-            }
-
-            if (Lhs == 1)
-            {
-                sciprint("%s\n", pInfo[i].pstInfo);
-            }
-        }
-
-        freeArrayOfString(pstVarNameList, iNbItem);
-    }
-    else
-    {
-        //no variable returms [] for each Lhs
-        for (int i = 0 ; i < Lhs ; i++)
-        {
-            createEmptyMatrix(pvApiCtx, nbIn + i + 1);
-            AssignOutputVariable(pvApiCtx, i + 1) = nbIn + i + 1;
-        }
-
-        ReturnArguments(pvApiCtx);
-        return 0;
-    }
-
+    int version = getSODFormatAttribute(iFile);
     closeHDF5File(iFile);
-
-    //1st Lhs
-    char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem);
-    for (int i = 0 ; i < iNbItem ; i++)
+    switch (version)
     {
-        pstVarName[i] = pInfo[i].varName;
-    }
-
-    sciErr = createMatrixOfString(pvApiCtx, nbIn + 1, iNbItem, 1, pstVarName);
-    FREE(pstVarName);
-    if (sciErr.iErr)
-    {
-        FREE(pInfo);
-        printError(&sciErr, 0);
-        return 1;
-    }
-
-    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
-
-    if (Lhs > 1)
-    {
-        //2nd Lhs
-        double* pdblType;
-        sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 2, iNbItem, 1, &pdblType);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            FREE(pInfo);
-            return 1;
-        }
-
-        for (int i = 0 ; i < iNbItem ; i++)
+        case -1:
+        case 1:
+        case 2:
         {
-            pdblType[i] = pInfo[i].iType;
-        }
-
-        AssignOutputVariable(pvApiCtx, 2) = nbIn + 2;
-
-        if (Lhs > 2)
-        {
-            //3rd Lhs
-            int* pList = NULL;
-            sciErr = createList(pvApiCtx, nbIn + 3, iNbItem, &pList);
-            for (int i = 0 ; i < iNbItem ; i++)
-            {
-                double* pdblDims = NULL;
-                allocMatrixOfDoubleInList(pvApiCtx, nbIn + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims);
-                for (int j = 0 ; j < pInfo[i].iDims ; j++)
-                {
-                    pdblDims[j] = pInfo[i].piDims[j];
-                }
-            }
-
-            AssignOutputVariable(pvApiCtx, 3) = nbIn + 3;
-        }
-
-        if (Lhs > 3)
-        {
-            //4th Lhs
-            double* pdblSize = NULL;
-            sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 4, iNbItem, 1, &pdblSize);
-            for (int i = 0 ; i < iNbItem ; i++)
-            {
-                pdblSize[i] = pInfo[i].iSize;
-            }
-
-            AssignOutputVariable(pvApiCtx, 4) = nbIn + 4;
-        }
-
-    }
-
-    FREE(pInfo);
-    ReturnArguments(pvApiCtx);
-    return 0;
-}
-
-static bool read_data(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
-{
-    bool bRet = false;
-
-    _pInfo->iType = getScilabTypeFromDataSet(_iDatasetId);
-    switch (_pInfo->iType)
-    {
-        case sci_matrix:
-        {
-            bRet = read_double(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_strings:
-        {
-            bRet = read_string(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_list:
-        case sci_tlist:
-        case sci_mlist:
-        {
-            bRet = read_list(_iDatasetId, _pInfo->iType, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_boolean:
-        {
-            bRet = read_boolean(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_poly:
-        {
-            bRet = read_poly(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_ints:
-        {
-            bRet = read_integer(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_sparse:
-        {
-            bRet = read_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_boolean_sparse:
-        {
-            bRet = read_boolean_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            wstFuncName = L"listvar_in_hdf5_v2";
             break;
         }
-        case sci_void:             //void item only on list variable
+        case 3:
         {
-            bRet = read_void(_iDatasetId, _iItemPos, _piAddress, _pInfo);
-            break;
-        }
-        case sci_undefined:        //undefined item only on list variable
-        {
-            bRet = read_undefined(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            wstFuncName = L"listvar_in_hdf5_v3";
             break;
         }
         default:
         {
-            Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5");
-            break;
-        }
-    }
-
-    return bRet;
-}
-
-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_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;
-}
-
-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_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 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_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;
-    }
-
-    _pInfo->iDims = 2;
-    _pInfo->piDims[0] = iRows;
-    _pInfo->piDims[1] = iCols;
-    _pInfo->iSize = 20 + iRows * 4 + iNbItem * 4;
-
-    generateInfo(_pInfo, "boolean sparse");
-    closeDataSet(_iDatasetId);
-    return true;
-}
-
-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]);
+            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, version);
+            return types::Function::Error;
         }
     }
 
-    FREE(piNbCoef);
-    FREE(pdblReal);
-    if (iComplex)
-    {
-        FREE(pdblImg);
-    }
 
-    generateInfo(_pInfo, "polynomial");
-    return true;
-}
-
-static bool read_list(int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
-{
-    int iRet = 0;
-    int iItems = 0;
-    int *piListAddr = NULL;
-    hobj_ref_t *piItemRef = NULL;
-
-    iRet = getListDims(_iDatasetId, &iItems);
-    if (iRet)
-    {
-        return false;
-    }
-
-    if (iItems == 0)
-    {
-        //special case for empty list
-    }
-    else
-    {
-        iRet = getListItemReferences(_iDatasetId, &piItemRef);
-        if (iRet)
-        {
-            return false;
-        }
-    }
-    //_pInfo = (VarInfo*)MALLOC(sizeof(VarInfo));
-    _pInfo->iDims = 1;
-    _pInfo->piDims[0] = iItems;
-    _pInfo->iSize = (2 + iItems + 1) * 4;
-
-    for (int i = 0; i < iItems; i++)
-    {
-        int iItemDataset = 0;
-
-        iRet = getListItemDataset(_iDatasetId, piItemRef, i, &iItemDataset);
-        if (iRet || iItemDataset == 0)
-        {
-            return false;
-        }
-        VarInfo info;
-        bool bRet = read_data(iItemDataset, i + 1, piListAddr, &info);
-        if (bRet == false)
-        {
-            return false;
-        }
-
-        _pInfo->iSize += info.iSize;
-    }
-
-    if (_iVarType == sci_list)
-    {
-        generateInfo(_pInfo, "list");
-    }
-    else if (_iVarType == sci_tlist)
-    {
-        generateInfo(_pInfo, "tlist");
-    }
-    else if (_iVarType == sci_mlist)
-    {
-        generateInfo(_pInfo, "mlist");
-    }
-
-    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
-    if (iRet)
-    {
-        return false;
-    }
-
-
-    return true;
-}
-
-static bool read_void(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
-{
-    _pInfo->iSize = 1;
-    closeDataSet(_iDatasetId);
-    return true;
-}
-
-static bool read_undefined(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
-{
-    _pInfo->iSize = 1;
-    closeDataSet(_iDatasetId);
-    return true;
-}
-
-static void generateInfo(VarInfo* _pInfo, const char* _pstType)
-{
-    char pstSize[17];
-
-    if (_pInfo->iDims == 2)
-    {
-        sprintf(pstSize, "%d by %d", _pInfo->piDims[0], _pInfo->piDims[1]);
-    }
-    else if (_pInfo->iDims == 1)
-    {
-        sprintf(pstSize, "%d", _pInfo->piDims[0]);
-    }
-    else
-    {
-        pstSize[0] = '\0';
-    }
-
-    sprintf(_pInfo->pstInfo, "%-*s%-*s%-*s%-*d", 25, _pInfo->varName, 15, _pstType, 16, pstSize, 10, _pInfo->iSize);
-}
+    ast::ExecVisitor exec;
+    return Overload::call(wstFuncName, in, _iRetCount, out, &exec);
+}
\ No newline at end of file
diff --git a/scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp b/scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v2.cpp
new file mode 100644 (file)
index 0000000..12d1b85
--- /dev/null
@@ -0,0 +1,602 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2012 - DIGITEO - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#include <hdf5.h>
+extern "C"
+{
+#include <string.h>
+#include "gw_hdf5.h"
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "api_scilab.h"
+#include "../../../call_scilab/includes/call_scilab.h"
+#include "h5_fileManagement.h"
+#include "h5_readDataFromFile.h"
+#include "h5_attributeConstants.h"
+#include "expandPathVariable.h"
+#include "freeArrayOfString.h"
+}
+
+#include "listvar_in_hdf5_v1.hxx"
+#include <vector>
+
+typedef struct __VAR_INFO__
+{
+    char pstInfo[128];
+    char varName[128];
+    int iType;
+    int iSize;
+    int iDims;
+    int piDims[2];
+
+    __VAR_INFO__() : iType(0), iSize(0), iDims(0)
+    {
+        memset(pstInfo, 0, sizeof(pstInfo) / sizeof(pstInfo[0]));
+        memset(varName, 0, sizeof(varName) / sizeof(varName[0]));
+    }
+} VarInfo;
+
+static bool read_data(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_double(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_string(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_boolean(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_integer(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_sparse(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_boolean_sparse(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_poly(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_list(int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_void(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+static bool read_undefined(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo);
+
+static void generateInfo(VarInfo* _pInfo, const char* _pstType);
+
+int sci_listvar_in_hdf5_v2(char *fname, int* pvApiCtx)
+{
+    SciErr sciErr;
+    int *piAddr     = NULL;
+    char* pstFile   = NULL;
+    int iFile       = 0;
+    int iNbItem     = 0;
+    VarInfo* pInfo  = NULL;
+    const int nbIn = nbInputArgument(pvApiCtx);
+
+    CheckInputArgument(pvApiCtx, 1, 1);
+    CheckOutputArgument(pvApiCtx, 1, 4);
+
+    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+    if (sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 1;
+    }
+
+    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile))
+    {
+        if (pstFile)
+        {
+            FREE(pstFile);
+        }
+
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
+        return 1;
+    }
+
+    char* pstFileName = expandPathVariable(pstFile);
+    iFile = openHDF5File(pstFileName, 0);
+    if (iFile < 0)
+    {
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname, pstFile);
+        FREE(pstFileName);
+        FREE(pstFile);
+        return 1;
+    }
+
+    FREE(pstFileName);
+    FREE(pstFile);
+
+    //manage version information
+    int iVersion = getSODFormatAttribute(iFile);
+    if (iVersion != SOD_FILE_VERSION)
+    {
+        if (iVersion > SOD_FILE_VERSION)
+        {
+            //can't read file with version newer that me !
+            closeHDF5File(iFile);
+            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname, SOD_FILE_VERSION, iVersion);
+            return 1;
+        }
+        else
+        {
+            //call older import functions and exit or ... EXIT !
+            if (iVersion == 1 || iVersion == -1)
+            {
+                //sciprint("old sci_listvar_in_hdf5_v1\n");
+                return sci_listvar_in_hdf5_v1(fname, pvApiCtx);
+            }
+        }
+    }
+
+    iNbItem = getVariableNames(iFile, NULL);
+    if (iNbItem != 0)
+    {
+        char** pstVarNameList = (char**)MALLOC(sizeof(char*) * iNbItem);
+        pInfo = (VarInfo*)MALLOC(iNbItem * sizeof(VarInfo));
+        int b;
+
+        if (Lhs == 1)
+        {
+            sciprint("Name                     Type           Size            Bytes\n");
+            sciprint("---------------------------------------------------------------\n");
+        }
+
+        iNbItem = getVariableNames(iFile, pstVarNameList);
+        for (int i = 0; i < iNbItem; i++)
+        {
+            int iDataSetId = getDataSetIdFromName(iFile, pstVarNameList[i]);
+            if (iDataSetId == 0)
+            {
+                break;
+            }
+
+            strncpy(pInfo[i].varName, pstVarNameList[i], sizeof(pInfo[i].varName) - 1);
+            pInfo[i].iSize = 0;
+            b = read_data(iDataSetId, 0, NULL, &pInfo[i]) == false;
+            if (b)
+            {
+                break;
+            }
+
+            if (Lhs == 1)
+            {
+                sciprint("%s\n", pInfo[i].pstInfo);
+            }
+        }
+
+        freeArrayOfString(pstVarNameList, iNbItem);
+    }
+    else
+    {
+        //no variable returms [] for each Lhs
+        for (int i = 0 ; i < Lhs ; i++)
+        {
+            createEmptyMatrix(pvApiCtx, nbIn + i + 1);
+            AssignOutputVariable(pvApiCtx, i + 1) = nbIn + i + 1;
+        }
+
+        ReturnArguments(pvApiCtx);
+        return 0;
+    }
+
+    closeHDF5File(iFile);
+
+    //1st Lhs
+    char** pstVarName = (char**)MALLOC(sizeof(char*) * iNbItem);
+    for (int i = 0 ; i < iNbItem ; i++)
+    {
+        pstVarName[i] = pInfo[i].varName;
+    }
+
+    sciErr = createMatrixOfString(pvApiCtx, nbIn + 1, iNbItem, 1, pstVarName);
+    FREE(pstVarName);
+    if (sciErr.iErr)
+    {
+        FREE(pInfo);
+        printError(&sciErr, 0);
+        return 1;
+    }
+
+    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
+
+    if (Lhs > 1)
+    {
+        //2nd Lhs
+        double* pdblType;
+        sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 2, iNbItem, 1, &pdblType);
+        if (sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            FREE(pInfo);
+            return 1;
+        }
+
+        for (int i = 0 ; i < iNbItem ; i++)
+        {
+            pdblType[i] = pInfo[i].iType;
+        }
+
+        AssignOutputVariable(pvApiCtx, 2) = nbIn + 2;
+
+        if (Lhs > 2)
+        {
+            //3rd Lhs
+            int* pList = NULL;
+            sciErr = createList(pvApiCtx, nbIn + 3, iNbItem, &pList);
+            for (int i = 0 ; i < iNbItem ; i++)
+            {
+                double* pdblDims = NULL;
+                allocMatrixOfDoubleInList(pvApiCtx, nbIn + 3, pList, i + 1, 1, pInfo[i].iDims, &pdblDims);
+                for (int j = 0 ; j < pInfo[i].iDims ; j++)
+                {
+                    pdblDims[j] = pInfo[i].piDims[j];
+                }
+            }
+
+            AssignOutputVariable(pvApiCtx, 3) = nbIn + 3;
+        }
+
+        if (Lhs > 3)
+        {
+            //4th Lhs
+            double* pdblSize = NULL;
+            sciErr = allocMatrixOfDouble(pvApiCtx, nbIn + 4, iNbItem, 1, &pdblSize);
+            for (int i = 0 ; i < iNbItem ; i++)
+            {
+                pdblSize[i] = pInfo[i].iSize;
+            }
+
+            AssignOutputVariable(pvApiCtx, 4) = nbIn + 4;
+        }
+
+    }
+
+    FREE(pInfo);
+    ReturnArguments(pvApiCtx);
+    return 0;
+}
+
+static bool read_data(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
+{
+    bool bRet = false;
+
+    _pInfo->iType = getScilabTypeFromDataSet(_iDatasetId);
+    switch (_pInfo->iType)
+    {
+        case sci_matrix:
+        {
+            bRet = read_double(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_strings:
+        {
+            bRet = read_string(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_list:
+        case sci_tlist:
+        case sci_mlist:
+        {
+            bRet = read_list(_iDatasetId, _pInfo->iType, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_boolean:
+        {
+            bRet = read_boolean(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_poly:
+        {
+            bRet = read_poly(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_ints:
+        {
+            bRet = read_integer(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_sparse:
+        {
+            bRet = read_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_boolean_sparse:
+        {
+            bRet = read_boolean_sparse(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_void:             //void item only on list variable
+        {
+            bRet = read_void(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        case sci_undefined:        //undefined item only on list variable
+        {
+            bRet = read_undefined(_iDatasetId, _iItemPos, _piAddress, _pInfo);
+            break;
+        }
+        default:
+        {
+            Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5");
+            break;
+        }
+    }
+
+    return bRet;
+}
+
+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_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;
+}
+
+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_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 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_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;
+    }
+
+    _pInfo->iDims = 2;
+    _pInfo->piDims[0] = iRows;
+    _pInfo->piDims[1] = iCols;
+    _pInfo->iSize = 20 + iRows * 4 + iNbItem * 4;
+
+    generateInfo(_pInfo, "boolean sparse");
+    closeDataSet(_iDatasetId);
+    return true;
+}
+
+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;
+}
+
+static bool read_list(int _iDatasetId, int _iVarType, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
+{
+    int iRet = 0;
+    int iItems = 0;
+    int *piListAddr = NULL;
+    hobj_ref_t *piItemRef = NULL;
+
+    iRet = getListDims(_iDatasetId, &iItems);
+    if (iRet)
+    {
+        return false;
+    }
+
+    if (iItems == 0)
+    {
+        //special case for empty list
+    }
+    else
+    {
+        iRet = getListItemReferences(_iDatasetId, &piItemRef);
+        if (iRet)
+        {
+            return false;
+        }
+    }
+    //_pInfo = (VarInfo*)MALLOC(sizeof(VarInfo));
+    _pInfo->iDims = 1;
+    _pInfo->piDims[0] = iItems;
+    _pInfo->iSize = (2 + iItems + 1) * 4;
+
+    for (int i = 0; i < iItems; i++)
+    {
+        int iItemDataset = 0;
+
+        iRet = getListItemDataset(_iDatasetId, piItemRef, i, &iItemDataset);
+        if (iRet || iItemDataset == 0)
+        {
+            return false;
+        }
+        VarInfo info;
+        bool bRet = read_data(iItemDataset, i + 1, piListAddr, &info);
+        if (bRet == false)
+        {
+            return false;
+        }
+
+        _pInfo->iSize += info.iSize;
+    }
+
+    if (_iVarType == sci_list)
+    {
+        generateInfo(_pInfo, "list");
+    }
+    else if (_iVarType == sci_tlist)
+    {
+        generateInfo(_pInfo, "tlist");
+    }
+    else if (_iVarType == sci_mlist)
+    {
+        generateInfo(_pInfo, "mlist");
+    }
+
+    iRet = deleteListItemReferences(_iDatasetId, piItemRef);
+    if (iRet)
+    {
+        return false;
+    }
+
+
+    return true;
+}
+
+static bool read_void(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
+{
+    _pInfo->iSize = 1;
+    closeDataSet(_iDatasetId);
+    return true;
+}
+
+static bool read_undefined(int _iDatasetId, int _iItemPos, int *_piAddress, VarInfo* _pInfo)
+{
+    _pInfo->iSize = 1;
+    closeDataSet(_iDatasetId);
+    return true;
+}
+
+static void generateInfo(VarInfo* _pInfo, const char* _pstType)
+{
+    char pstSize[17];
+
+    if (_pInfo->iDims == 2)
+    {
+        sprintf(pstSize, "%d by %d", _pInfo->piDims[0], _pInfo->piDims[1]);
+    }
+    else if (_pInfo->iDims == 1)
+    {
+        sprintf(pstSize, "%d", _pInfo->piDims[0]);
+    }
+    else
+    {
+        pstSize[0] = '\0';
+    }
+
+    sprintf(_pInfo->pstInfo, "%-*s%-*s%-*s%-*d", 25, _pInfo->varName, 15, _pstType, 16, pstSize, 10, _pInfo->iSize);
+}
diff --git a/scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp b/scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp
new file mode 100644 (file)
index 0000000..01ef63b
--- /dev/null
@@ -0,0 +1,839 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2012 - DIGITEO - Antoine ELIAS
+*
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at
+* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+*
+*/
+
+#include <vector>
+#include "function.hxx"
+#include "string.hxx"
+#include "double.hxx"
+#include "list.hxx"
+#include "hdf5_gw.hxx"
+#include "configvariable.hxx"
+
+extern "C"
+{
+#include <hdf5.h>
+#include "sci_types.h" //sci_matrix, sci_ints, ...
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "localization.h"
+#include "sciprint.h"
+#include "h5_fileManagement.h"
+#include "h5_readDataFromFile.h"
+#include "h5_writeDataToFile.h"
+#include "h5_attributeConstants.h"
+#include "expandPathVariable.h"
+}
+
+typedef struct __VAR_INFO6__
+{
+    char info[128];
+    std::string name;
+    std::string ctype;
+    int type;
+    int size;
+    int dims;
+    std::vector<int> pdims;
+} VarInfo6;
+
+static bool read_data(int dataset, VarInfo6& info);
+static bool read_short_data(int dataset, VarInfo6& info);
+static bool read_double(int dataset, VarInfo6& info);
+static bool read_string(int dataset, VarInfo6& info);
+static bool read_boolean(int dataset, VarInfo6& info);
+static bool read_integer(int dataset, VarInfo6& info);
+static bool read_sparse(int dataset, VarInfo6& info);
+static bool read_boolean_sparse(int dataset, VarInfo6& info);
+static bool read_poly(int dataset, VarInfo6& info);
+static bool read_list(int dataset, VarInfo6& info, std::string type);
+static bool read_void(int dataset, VarInfo6& info);
+static bool read_undefined(int dataset, VarInfo6& info);
+static bool read_struct(int dataset, VarInfo6& info);
+static bool read_cell(int dataset, VarInfo6& info);
+static bool read_handles(int dataset, VarInfo6& info);
+
+static void generateInfo(VarInfo6& info);
+static int getDimsNode(int dataset, int* complex, std::vector<int>& dims);
+
+static const std::string fname("listvar_in_hdf5");
+
+types::Function::ReturnValue sci_listvar_in_hdf5_v3(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    bool verbose = ConfigVariable::getVerbose();
+    int rhs = static_cast<int>(in.size());
+
+    bool varnameOnly = (rhs == 1 && verbose == false);
+
+    if (rhs != 1)
+    {
+        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), fname.data(), 1);
+        return types::Function::Error;
+    }
+
+    if (_iRetCount < 1 && _iRetCount > 4)
+    {
+        Scierror(999, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), fname.data(), 1, 4);
+        return types::Function::Error;
+    }
+
+    //get filename
+    if (in[0]->getId() != types::InternalType::IdScalarString)
+    {
+        Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname.data(), 1);
+        return types::Function::Error;
+    }
+
+    //open hdf5 file
+    wchar_t* wfilename = expandPathVariableW(in[0]->getAs<types::String>()->get()[0]);
+    char* cfilename = wide_string_to_UTF8(wfilename);
+    std::string filename = cfilename;
+    FREE(wfilename);
+    FREE(cfilename);
+
+    int iFile = openHDF5File(filename.data(), 0);
+    if (iFile < 0)
+    {
+        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), filename.data());
+        return types::Function::Error;
+    }
+
+    //manage version information
+    int iVersion = getSODFormatAttribute(iFile);
+    if (iVersion != SOD_FILE_VERSION)
+    {
+        //can't read file with version newer that me !
+        closeHDF5File(iFile);
+        Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
+        return types::Function::Error;
+    }
+
+    int items = getVariableNames6(iFile, nullptr);
+    std::vector<VarInfo6> info(items);
+    if (items != 0)
+    {
+        std::vector<char*> vars(items);
+        items = getVariableNames6(iFile, vars.data());
+
+        if (_iRetCount == 1 && verbose)
+        {
+            sciprint("Name                     Type           Size            Bytes\n");
+            sciprint("-------------------------------------------------------------\n");
+        }
+
+        for (int i = 0; i < items; i++)
+        {
+            info[i].name = vars[i];
+            info[i].size = 0;
+
+            if (varnameOnly)
+            {
+                continue;
+            }
+
+            int dset = getDataSetIdFromName(iFile, vars[i]);
+            if (dset == 0)
+            {
+                break;
+            }
+
+
+            if (_iRetCount != 2)
+            {
+                if (read_data(dset, info[i]) == false)
+                {
+                    break;
+                }
+
+                if (_iRetCount == 1)
+                {
+                    sciprint("%s\n", info[i].info);
+                }
+            }
+            else // == 2
+            {
+                if (read_short_data(dset, info[i]) == false)
+                {
+                    break;
+                }
+            }
+        }
+    }
+    else
+    {
+        //no variable returms [] for each Lhs
+        for (int i = 0; i < _iRetCount; i++)
+        {
+            out.push_back(types::Double::Empty());
+        }
+
+        return types::Function::OK;
+    }
+
+    closeHDF5File(iFile);
+
+    //1st Lhs
+    types::String* out1 = new types::String(items, 1);
+    for (int i = 0; i < items; i++)
+    {
+        out1->set(i, info[i].name.data());
+    }
+
+    out.push_back(out1);
+
+    //2nd
+    if (_iRetCount > 1)
+    {
+        types::Double* out2 = new types::Double(items, 1);
+        double* pout2 = out2->get();
+        for (int i = 0; i < items; i++)
+        {
+            pout2[i] = info[i].type;
+        }
+
+        out.push_back(out2);
+    }
+
+    if (_iRetCount > 2)
+    {
+        //3rd Lhs
+        types::List* out3 = new types::List();
+        for (int i = 0; i < items; i++)
+        {
+            int dims = info[i].dims;
+            types::Double* item = new types::Double(1, dims);
+            double* pitem = item->get();
+            for (int j = 0; j < dims; j++)
+            {
+                pitem[j] = static_cast<double>(info[i].pdims[j]);
+            }
+
+            out3->append(item);
+        }
+
+        out.push_back(out3);
+    }
+
+    if (_iRetCount > 3)
+    {
+        //4th Lhs
+        types::Double* out4 = new types::Double(items, 1);
+        double* pout4 = out4->get();
+        for (int i = 0; i < items; i++)
+        {
+            pout4[i] = info[i].size;
+        }
+
+        out.push_back(out4);
+    }
+
+    return types::Function::OK;
+}
+
+static bool read_short_data(int dataset, VarInfo6& info)
+{
+    char* ctype = getScilabTypeFromDataSet6(dataset);
+    std::string type(ctype);
+    FREE(ctype);
+    info.ctype = type;
+
+    if (type == g_SCILAB_CLASS_DOUBLE)
+    {
+        info.type = sci_matrix;
+    }
+    else if (type == g_SCILAB_CLASS_STRING)
+    {
+        info.type = sci_strings;
+    }
+    else if (type == g_SCILAB_CLASS_LIST)
+    {
+        info.type = sci_list;
+    }
+    else if (type == g_SCILAB_CLASS_TLIST)
+    {
+        info.type = sci_tlist;
+    }
+    else if (type == g_SCILAB_CLASS_MLIST)
+    {
+        info.type = sci_mlist;
+    }
+    else if (type == g_SCILAB_CLASS_BOOLEAN)
+    {
+        info.type = sci_boolean;
+    }
+    else if (type == g_SCILAB_CLASS_POLY)
+    {
+        info.type = sci_poly;
+    }
+    else if (type == g_SCILAB_CLASS_INT)
+    {
+        info.type = sci_ints;
+    }
+    else if (type == g_SCILAB_CLASS_SPARSE)
+    {
+        info.type = sci_sparse;
+    }
+    else if (type == g_SCILAB_CLASS_BSPARSE)
+    {
+        info.type = sci_boolean_sparse;
+    }
+    else if (type == g_SCILAB_CLASS_VOID)
+    {
+        info.type = sci_void;
+    }
+    else if (type == g_SCILAB_CLASS_UNDEFINED)
+    {
+        info.type = sci_undefined;
+    }
+    else if (type == g_SCILAB_CLASS_STRUCT)
+    {
+        info.type = sci_mlist;
+    }
+    else if (type == g_SCILAB_CLASS_CELL)
+    {
+        info.type = sci_mlist;
+    }
+    else
+    {
+        Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5");
+        return false;
+    }
+
+    return true;
+}
+
+static bool read_data(int dataset, VarInfo6& info)
+{
+    bool bRet = false;
+
+    char* ctype = getScilabTypeFromDataSet6(dataset);
+    std::string type(ctype);
+    FREE(ctype);
+    info.ctype = type;
+
+    if (type == g_SCILAB_CLASS_DOUBLE)
+    {
+        info.type = sci_matrix;
+        return read_double(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_STRING)
+    {
+        info.type = sci_strings;
+        return read_string(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_LIST)
+    {
+        info.type = sci_list;
+        return read_list(dataset, info, "list");
+    }
+
+    if (type == g_SCILAB_CLASS_TLIST)
+    {
+        info.type = sci_tlist;
+        return read_list(dataset, info, "tlist");
+    }
+
+    if (type == g_SCILAB_CLASS_MLIST)
+    {
+        info.type = sci_mlist;
+        return read_list(dataset, info, "mlist");
+    }
+
+    if (type == g_SCILAB_CLASS_BOOLEAN)
+    {
+        info.type = sci_boolean;
+        return read_boolean(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_POLY)
+    {
+        info.type = sci_poly;
+        return read_poly(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_INT)
+    {
+        info.type = sci_ints;
+        return read_integer(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_SPARSE)
+    {
+        info.type = sci_sparse;
+        return read_sparse(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_BSPARSE)
+    {
+        info.type = sci_boolean_sparse;
+        return read_boolean_sparse(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_VOID)
+    {
+        info.type = sci_void;
+        return read_void(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_UNDEFINED)
+    {
+        info.type = sci_undefined;
+        return read_undefined(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_STRUCT)
+    {
+        info.type = sci_mlist;
+        return read_struct(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_CELL)
+    {
+        info.type = sci_mlist;
+        return read_cell(dataset, info);
+    }
+
+    if (type == g_SCILAB_CLASS_HANDLE)
+    {
+        info.type = sci_handles;
+        return read_handles(dataset, info);
+    }
+
+    Scierror(999, _("%s: Invalid HDF5 Scilab format.\n"), "listvar_in_hdf5");
+    return false;
+}
+
+static bool read_double(int dataset, VarInfo6& info)
+{
+    int complex = 0;
+    int ret = getDatasetInfo(dataset, &complex, &info.dims, NULL);
+    if (ret < 0)
+    {
+        closeDataSet(dataset);
+        return nullptr;
+    }
+
+    info.pdims.resize(info.dims);
+    int size = getDatasetInfo(dataset, &complex, &info.dims, info.pdims.data());
+    info.size = size * (complex + 1) * sizeof(double);
+
+    generateInfo(info);
+    closeDataSet(dataset);
+    return true;
+}
+
+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 nullptr;
+    }
+
+    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_boolean(int dataset, VarInfo6& info)
+{
+    int complex = 0;
+    int ret = getDatasetInfo(dataset, &complex, &info.dims, NULL);
+    if (ret < 0)
+    {
+        closeDataSet(dataset);
+        return nullptr;
+    }
+
+    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_integer(int dataset, VarInfo6& info)
+{
+    int complex = 0;
+    int ret = getDatasetInfo(dataset, &complex, &info.dims, NULL);
+    if (ret < 0)
+    {
+        closeDataSet(dataset);
+        return nullptr;
+    }
+
+    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 bool read_sparse(int dataset, VarInfo6& info)
+{
+    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);
+
+    info.dims = 2;
+    info.pdims.resize(2);
+    info.pdims[0] = pdims[0];
+    info.pdims[1] = pdims[1];
+    //nnz(double) + rows(int) + nnz(int)
+    info.size = sizeof(double) * nnz * (complex + 1) + info.pdims[0] * sizeof(int) + nnz * sizeof(int);
+
+    generateInfo(info);
+    closeList6(dataset);
+    return true;
+}
+
+static bool read_boolean_sparse(int dataset, VarInfo6& info)
+{
+    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);
+
+    info.dims = 2;
+    info.pdims[0] = pdims[0];
+    info.pdims[1] = pdims[1];
+    //rows(int) + nnz(int)
+    info.size = info.pdims[0] * sizeof(int) + nnz * sizeof(int);
+
+    generateInfo(info);
+    closeList6(dataset);
+    return true;
+}
+
+static bool read_poly(int dataset, VarInfo6& info)
+{
+    int complex = 0;
+    int size = getDimsNode(dataset, &complex, info.pdims);
+    info.size = 0;
+
+    //open __refs__ node
+    int refs = getDataSetIdFromName(dataset, "__refs__");
+
+    for (int i = 0; i < size; ++i)
+    {
+        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());
+        info.size += datasize * sizeof(double) * (complex + 1);
+    }
+
+    closeList6(refs);
+    closeList6(dataset);
+
+    generateInfo(info);
+    return true;
+}
+
+static bool read_list(int dataset, VarInfo6& info, std::string type)
+{
+    int ret = 0;
+    int items = 0;
+
+    ret = getListDims6(dataset, &items);
+    if (ret)
+    {
+        return false;
+    }
+
+    info.dims = 1;
+    info.pdims.resize(1);
+    info.pdims[0] = items;
+    info.size = 0;
+
+    for (int i = 0; i < items; i++)
+    {
+        int data = getDataSetIdFromName(dataset, std::to_string(i).data());
+        if (data <= 0)
+        {
+            closeList6(dataset);
+            return false;
+        }
+
+
+        VarInfo6 info2;
+        bool bRet = read_data(data, info2);
+        if (bRet == false)
+        {
+            return false;
+        }
+
+        info.size += info2.size;
+    }
+
+    closeList6(dataset);
+    generateInfo(info);
+    return true;
+}
+
+static bool read_void(int dataset, VarInfo6& info)
+{
+    info.size = 0;
+    closeDataSet(dataset);
+    return true;
+}
+
+static bool read_undefined(int dataset, VarInfo6& info)
+{
+    info.size = 0;
+    closeDataSet(dataset);
+    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_cell(int dataset, VarInfo6& info)
+{
+    //get cell dimensions
+    int complex = 0;
+    int size = getDimsNode(dataset, &complex, info.pdims);
+    info.dims = static_cast<int>(info.pdims.size());
+
+    if (size == 0)
+    {
+        info.size = 0;
+        generateInfo(info);
+        closeList6(dataset);
+        return true;
+    }
+
+    //open __refs__ node
+    int refs = getDataSetIdFromName(dataset, "__refs__");
+    for (int i = 0; i < size; ++i)
+    {
+        int ref = getDataSetIdFromName(refs, std::to_string(i).data());
+        VarInfo6 info2;
+        if (read_data(ref, info2) == false)
+        {
+            closeList6(refs);
+            closeList6(dataset);
+            return false;
+        }
+
+        info.size += info2.size;
+    }
+
+    closeList6(refs);
+    closeList6(dataset);
+
+    generateInfo(info);
+    return true;
+}
+static bool read_handles(int dataset, VarInfo6& info)
+{
+    //get cell dimensions
+    int complex = 0;
+    int size = getDimsNode(dataset, &complex, info.pdims);
+    info.dims = static_cast<int>(info.pdims.size());
+
+    if (size == 0)
+    {
+        info.size = 0;
+        generateInfo(info);
+        closeList6(dataset);
+        return true;
+    }
+
+    ////open __refs__ node
+    //int refs = getDataSetIdFromName(dataset, "__refs__");
+    //for (int i = 0; i < size; ++i)
+    //{
+    //    int ref = getDataSetIdFromName(refs, std::to_string(i).data());
+    //    VarInfo6 info2;
+    //    if (read_data(ref, info2) == false)
+    //    {
+    //        closeList6(refs);
+    //        closeList6(dataset);
+    //        return false;
+    //    }
+
+    //    info.size += info2.size;
+    //}
+
+    //closeList6(refs);
+    closeList6(dataset);
+
+    generateInfo(info);
+    return true;
+}
+static void generateInfo(VarInfo6& info)
+{
+    std::ostringstream ostr;
+
+    if (info.dims != 0)
+    {
+        ostr << info.pdims[0];
+        for (int i = 1; i < info.dims; ++i)
+        {
+            ostr << " by " << info.pdims[i];
+        }
+    }
+
+    sprintf(info.info, "%-*s%-*s%-*s%-*d", 25, info.name.data(), 15, info.ctype.data(), 16, ostr.str().data(), 10, info.size);
+}
+
+static int getDimsNode(int dataset, int* complex, std::vector<int>& dims)
+{
+    dims.clear();
+    int id = getDataSetIdFromName(dataset, "__dims__");
+    if (id < 0)
+    {
+        return 0;
+    }
+
+    //get dims dimension count
+    int dim = 0;
+    getDatasetInfo(id, complex, &dim, NULL);
+    //get dims dimension
+    std::vector<int> d(dim);
+    int size = getDatasetInfo(id, complex, &dim, d.data());
+
+    //get dims value
+    dims.resize(size);
+    readInteger32Matrix(id, dims.data());
+
+    size = dims[0];
+    for (int i = 1; i < dims.size(); ++i)
+    {
+        size *= dims[i];
+    }
+    return size;
+}
+
index 96a630d..c16ff57 100644 (file)
  Don't touch if you do not know what you are doing
 -->
 <module name="hdf5">
-    <gateway name="sci_export_to_hdf5"                  function="export_to_hdf5"           type="0" />
-    <gateway name="sci_import_from_hdf5"                function="import_from_hdf5"         type="0" />
-    <gateway name="sci_listvar_in_hdf5"                 function="listvar_in_hdf5"          type="0" />
+    <gateway name="sci_export_to_hdf5"                  function="export_to_hdf5"           type="1" />
+    <gateway name="sci_export_to_hdf5"                  function="save"                     type="1" />
+    <gateway name="sci_import_from_hdf5"                function="import_from_hdf5"         type="1" />
+    <gateway name="sci_import_from_hdf5_v1"             function="import_from_hdf5_v1"