HDF5 improvement 20/16820/6
Antoine ELIAS [Wed, 8 Jul 2015 09:31:50 +0000 (11:31 +0200)]
 * Add hdf5_file_version function

 * Add management of usertype (save via new save function in usertype or overload / load via overload)
{t/m}list can be saved and loaded with Undefined fields -> bug 9621

 * Add save overload for scicos UserType (from https://codereview.scilab.org/#/c/16765/)
 * Add load overload for scicos UserType

Change-Id: I686356f590ad7e80610fde08f7e1b3b6557192b7

32 files changed:
scilab/modules/ast/includes/types/user.hxx
scilab/modules/ast/src/cpp/types/overload.cpp
scilab/modules/fileio/tests/nonreg_tests/bug_2484.dia.ref
scilab/modules/fileio/tests/nonreg_tests/bug_9621.dia.ref
scilab/modules/fileio/tests/nonreg_tests/bug_9621.tst
scilab/modules/hdf5/Makefile.am
scilab/modules/hdf5/Makefile.in
scilab/modules/hdf5/includes/h5_attributeConstants.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_hdf5_file_version.cpp [new file with mode: 0644]
scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5_v3.cpp
scilab/modules/hdf5/sci_gateway/cpp/sci_listvar_in_hdf5_v3.cpp
scilab/modules/hdf5/sci_gateway/hdf5_gateway.xml
scilab/modules/hdf5/src/c/hdf5.vcxproj
scilab/modules/hdf5/src/c/hdf5.vcxproj.filters
scilab/modules/io/macros/%_sodload.sci
scilab/modules/io/tests/unit_tests/saveload.dia.ref
scilab/modules/io/tests/unit_tests/saveload.tst
scilab/modules/scicos/macros/scicos_scicos/%Block_load.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%Block_save.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%Link_load.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%Link_save.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%Text_load.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%Text_save.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%diagram_load.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/%diagram_save.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/scicos_block.sci
scilab/modules/scicos/macros/scicos_scicos/scicos_diagram.sci
scilab/modules/scicos/macros/scicos_scicos/scicos_link.sci
scilab/modules/scicos/macros/scicos_scicos/scicos_load.sci [new file with mode: 0644]
scilab/modules/scicos/macros/scicos_scicos/scicos_save.sci [new file with mode: 0644]

index 7afc758..0d0adf0 100644 (file)
@@ -51,9 +51,9 @@ public :
     /*** User will be asked to implement the following methods      ***/
     /*** in order Scilab engine to manage correctly this user type  ***/
 
-    std::wstring    getTypeStr() = 0;
-    std::wstring    getShortTypeStr() = 0;
-    InternalType*   clone() = 0;
+    virtual std::wstring    getTypeStr() = 0;
+    virtual std::wstring    getShortTypeStr() = 0;
+    virtual InternalType*   clone() = 0;
 
 public :
     /*** User can overload these methods                            ***/
@@ -151,6 +151,14 @@ public :
         return NULL;
     }
 
+    //called by save to export your usertype as basic scilab type
+    //if you do not want to overload this function, save will call %yourtype_save overload function
+    virtual InternalType* save()
+    {
+        return nullptr;
+    }
+
+    //load must be done by overload %yourtype_load and must returns a pointer on your UserType
 };
 }
 
index 39e6ca5..cb4136e 100644 (file)
@@ -91,7 +91,7 @@ types::Function::ReturnValue Overload::call(std::wstring _stOverloadingFunctionN
             std::wstring wstError(pwstError);
             FREE(pwstError);
             FREE(pstFuncName);
-            throw ast::ScilabError(wstError, 999, Location());
+            throw ast::ScilabError(wstError, 999, Location(1, 1, 1, 1));
         }
         else
         {
@@ -101,7 +101,7 @@ types::Function::ReturnValue Overload::call(std::wstring _stOverloadingFunctionN
             std::wstring wstError(pwstError);
             FREE(pwstError);
             FREE(pstFuncName);
-            throw ast::ScilabError(wstError, 999, Location());
+            throw ast::ScilabError(wstError, 999, Location(1, 1, 1, 1));
         }
     }
     types::Callable *pCall = pIT->getAs<types::Callable>();
index b19dac8..6495a7d 100644 (file)
@@ -17,5 +17,5 @@ a(2) = 10;
 save(TMPDIR+"/test.sav","a");
 if execstr("listvarinfile(TMPDIR+""/test.sav"");", "errcatch")<>0 then bugmes();quit;end
 Name                     Type           Size            Bytes
----------------------------------------------------------------
-a                        list           2               45        
+-------------------------------------------------------------
+a                        list           2               8         
index 218fea4..679c1e9 100644 (file)
@@ -22,5 +22,8 @@ newobj = tlist(["MYTYPE"
 "c" ]);
 newobj.a = %t;
 newobj.c = 0.05;
-refMsg = msprintf(_("List element number 3 is Undefined."));
-assert_checkerror("save(""pb.dat"", ""newobj"")", refMsg);
+saved = newobj;
+save("TMPDIR/pb.dat", "newobj");
+clear newobj;
+load("TMPDIR/pb.dat");
+assert_checkequal(newobj, saved);
index a38b0aa..b137f47 100644 (file)
@@ -24,6 +24,8 @@ newobj = tlist(["MYTYPE"
 newobj.a = %t;
 newobj.c = 0.05;
 
-refMsg = msprintf(_("List element number 3 is Undefined."));
-
-assert_checkerror("save(""pb.dat"", ""newobj"")", refMsg);
+saved = newobj;
+save("TMPDIR/pb.dat", "newobj");
+clear newobj;
+load("TMPDIR/pb.dat");
+assert_checkequal(newobj, saved);
index 6b29e2a..77a7cf6 100644 (file)
@@ -59,6 +59,7 @@ GATEWAY_CXX_SOURCES = \
     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_hdf5_file_version.cpp \
     sci_gateway/cpp/sci_h5dump.cpp \
     sci_gateway/cpp/sci_h5open.cpp \
     sci_gateway/cpp/sci_h5close.cpp \
index a492fb5..b81ed0e 100644 (file)
@@ -216,6 +216,7 @@ am__objects_3 = sci_gateway/cpp/libscihdf5_la-hdf5_gw.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_hdf5_file_version.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 \
@@ -659,6 +660,7 @@ GATEWAY_CXX_SOURCES = \
     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_hdf5_file_version.cpp \
     sci_gateway/cpp/sci_h5dump.cpp \
     sci_gateway/cpp/sci_h5open.cpp \
     sci_gateway/cpp/sci_h5close.cpp \
@@ -1080,6 +1082,9 @@ 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/$(am__dirstamp) \
        sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
+sci_gateway/cpp/libscihdf5_la-sci_hdf5_file_version.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)
@@ -1191,6 +1196,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_h5rm.Plo@am__quote@
 @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_hdf5_file_version.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@
@@ -1553,6 +1559,13 @@ sci_gateway/cpp/libscihdf5_la-sci_listvar_in_hdf5_v3.lo: sci_gateway/cpp/sci_lis
 @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_hdf5_file_version.lo: sci_gateway/cpp/sci_hdf5_file_version.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_hdf5_file_version.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_hdf5_file_version.Tpo -c -o sci_gateway/cpp/libscihdf5_la-sci_hdf5_file_version.lo `test -f 'sci_gateway/cpp/sci_hdf5_file_version.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_hdf5_file_version.cpp
+@am__fastdepCXX_TRUE@  $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_hdf5_file_version.Tpo sci_gateway/cpp/$(DEPDIR)/libscihdf5_la-sci_hdf5_file_version.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@     $(AM_V_CXX)source='sci_gateway/cpp/sci_hdf5_file_version.cpp' object='sci_gateway/cpp/libscihdf5_la-sci_hdf5_file_version.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_hdf5_file_version.lo `test -f 'sci_gateway/cpp/sci_hdf5_file_version.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_hdf5_file_version.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 838afa8..1921a38 100644 (file)
@@ -43,6 +43,7 @@ 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";
+static const char g_SCILAB_CLASS_USERTYPE[]     = "usertype";
 
 //integer precision
 #define SCI_INT8    1
index 531d0f4..1bcd4b2 100644 (file)
@@ -25,5 +25,6 @@ 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);
+CPP_GATEWAY_PROTOTYPE_EXPORT(sci_hdf5_file_version, HDF5_SCILAB_IMPEXP);
 
 #endif /* !__HDF5_GW_HXX__ */
index 7b09deb..43320ce 100644 (file)
@@ -24,6 +24,9 @@
 #include "sparse.hxx"
 #include "macrofile.hxx"
 #include "graphichandle.hxx"
+#include "user.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
 #include "handle_properties.hxx"
 #include "context.hxx"
 #include "serializervisitor.hxx"
@@ -53,12 +56,13 @@ static int export_double(int parent, const std::string& name, types::Double* dat
 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);
+static int export_struct(int parent, const std::string& name, types::Struct* data, const char* type = g_SCILAB_CLASS_STRUCT);
 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_usertype(int parent, const std::string& name, types::UserType* 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);
@@ -66,7 +70,7 @@ static int export_void(int parent, const std::string& name);
 static int export_undefined(int parent, const std::string& name);
 
 /*--------------------------------------------------------------------------*/
-static const std::string fname("export_to_hdf5");
+static const std::string fname("save");
 /*--------------------------------------------------------------------------*/
 types::Function::ReturnValue sci_export_to_hdf5(types::typed_list &in, int _iRetCount, types::typed_list &out)
 {
@@ -217,8 +221,6 @@ types::Function::ReturnValue sci_export_to_hdf5(types::typed_list &in, int _iRet
 
     //close hdf5 file
     closeHDF5File(iH5File);
-
-    out.push_back(new types::Bool(1));
     return types::Function::OK;
 }
 /*--------------------------------------------------------------------------*/
@@ -324,6 +326,9 @@ int export_data(int parent, const std::string& name, types::InternalType* data)
         case types::InternalType::ScilabHandle:
             dataset = export_handles(parent, name, data->getAs<types::GraphicHandle>());
             break;
+        case types::InternalType::ScilabUserType:
+            dataset = export_usertype(parent, name, data->getAs<types::UserType>());
+            break;
         default:
         {
             break;
@@ -423,10 +428,10 @@ 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)
+static int export_struct(int parent, const std::string& name, types::Struct* data, const char* type)
 {
     //create a group with struct name
-    int dset = openList6(parent, name.data(), g_SCILAB_CLASS_STRUCT);
+    int dset = openList6(parent, name.data(), type);
     //store struct dimensions
     std::vector<int> dims = {1, data->getDims()};
     int ret = writeIntegerMatrix6(dset, "__dims__", H5T_NATIVE_INT32, "32", 2, dims.data(), data->getDimsArray());
@@ -854,3 +859,62 @@ static int export_macro(int parent, const std::string& name, types::Macro* data)
     closeList6(dset);
     return dset;
 }
+
+static int export_usertype(int parent, const std::string& name, types::UserType* data)
+{
+    types::InternalType* it = data->save();
+    if (it == nullptr)
+    {
+        types::typed_list in;
+        in.push_back(data);
+
+        types::typed_list out;
+        //overload
+        ast::ExecVisitor exec;
+        // rational case
+        std::wstring wstFuncName = L"%" + data->getShortTypeStr() + L"_save";
+        types::Callable::ReturnValue ret = Overload::call(wstFuncName, in, 1, out, &exec);
+        if (ret != types::Callable::OK)
+        {
+            return -1;
+        }
+
+        if (out.size() != 1)
+        {
+            for (auto& i : out)
+            {
+                i->killMe();
+            }
+            return -1;
+        }
+
+        it = out[0];
+    }
+
+    if (it->isUserType())
+    {
+        it->killMe();
+        return -1;
+    }
+
+    //create a struct around "usertype" to be able to restore it.
+    types::Struct* str = new types::Struct(1, 1);
+    types::SingleStruct* ss = str->get()[0];
+
+    //add fields
+    ss->addField(L"type");
+    ss->addField(L"data");
+
+    //assign values to new fields
+    ss->set(L"type", new types::String(data->getShortTypeStr().data()));
+    ss->set(L"data", it);
+
+    int ret = export_struct(parent, name, str, g_SCILAB_CLASS_USERTYPE);
+
+    //protect data against delete
+    it->IncreaseRef();
+    delete str;
+    it->DecreaseRef();
+
+    return ret;
+}
\ No newline at end of file
diff --git a/scilab/modules/hdf5/sci_gateway/cpp/sci_hdf5_file_version.cpp b/scilab/modules/hdf5/sci_gateway/cpp/sci_hdf5_file_version.cpp
new file mode 100644 (file)
index 0000000..c432582
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+* 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 <hdf5.h>
+#include "hdf5_gw.hxx"
+#include "function.hxx"
+#include "string.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
+
+extern "C"
+{
+#include "sci_malloc.h"
+#include "Scierror.h"
+#include "expandPathVariable.h"
+#include "h5_fileManagement.h"
+#include "h5_attributeConstants.h"
+#include "h5_readDataFromFile.h"
+}
+
+static const std::string fname("hdf5_file_version");
+
+types::Function::ReturnValue sci_hdf5_file_version(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+    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);
+    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;
+    }
+
+    std::wstring wstFuncName;
+    //manage version information
+    int version = getSODFormatAttribute(iFile);
+    closeHDF5File(iFile);
+
+    if (version == -1)
+    {
+        version = 1;
+    }
+
+    out.push_back(new Double(static_cast<double>(version)));
+    return types::Function::OK;
+}
\ No newline at end of file
index 3ddfb7c..5ed2d00 100644 (file)
@@ -31,6 +31,7 @@
 #include "context.hxx"
 #include "handle_properties.hxx"
 #include "deserializervisitor.hxx"
+#include "execvisitor.hxx"
 
 std::unordered_map<int, Links::PathList> Links::paths;
 
@@ -62,10 +63,10 @@ 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 types::InternalType* import_usertype(int dataset);
 
 
 /*--------------------------------------------------------------------------*/
@@ -286,6 +287,12 @@ types::InternalType* import_data(int dataset)
         return new types::ListUndefined();
     }
 
+    if (type == g_SCILAB_CLASS_USERTYPE)
+    {
+        return import_usertype(dataset);
+    }
+
+
     return nullptr;
 }
 
@@ -1026,3 +1033,73 @@ static types::InternalType* import_macro(int dataset)
     closeList6(dataset);
     return macro;
 }
+
+static types::InternalType* import_usertype(int dataset)
+{
+    types::InternalType* it = import_struct(dataset);
+    if (it == nullptr || it->isStruct() == false)
+    {
+        delete it;
+        return nullptr;
+    }
+
+
+    types::Struct* str = it->getAs<types::Struct>();
+    
+    if(str->isScalar() == false)
+    {
+        delete it;
+        return nullptr;
+    }
+    
+    types::SingleStruct* ss = str->get()[0];
+
+    //extract type from struct
+    types::InternalType* itType  = ss->get(L"type");
+    if (itType == nullptr || itType->getId() != types::InternalType::IdScalarString)
+    {
+        delete it;
+        return nullptr;
+    }
+
+    types::String* s = it->getAs<types::String>();
+    wchar_t* type = s->get()[0];
+
+    types::InternalType* data = ss->get(L"data");
+    if (data == nullptr)
+    {
+        delete it;
+        return nullptr;
+    }
+
+    //call %yourtype_load overload
+    types::typed_list in;
+    in.push_back(data);
+
+    types::typed_list out;
+    //overload
+    ast::ExecVisitor exec;
+    // rational case
+    std::wstring wstFuncName = L"%" + data->getShortTypeStr() + L"_load";
+    types::Callable::ReturnValue ret = Overload::call(wstFuncName, in, 1, out, &exec);
+
+    //clean temporary variables
+    delete it; //included type and data
+
+    if (ret != types::Callable::OK)
+    {
+        return nullptr;
+    }
+
+    if (out.size() != 1)
+    {
+        for (auto& i : out)
+        {
+            i->killMe();
+        }
+
+        return nullptr;
+    }
+
+    return out[0];
+}
index 01ef63b..33d7d47 100644 (file)
@@ -67,11 +67,7 @@ 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);
@@ -122,7 +118,7 @@ types::Function::ReturnValue sci_listvar_in_hdf5_v3(types::typed_list &in, int _
         std::vector<char*> vars(items);
         items = getVariableNames6(iFile, vars.data());
 
-        if (_iRetCount == 1 && verbose)
+        if (_iRetCount == 1)
         {
             sciprint("Name                     Type           Size            Bytes\n");
             sciprint("-------------------------------------------------------------\n");
@@ -133,11 +129,6 @@ types::Function::ReturnValue sci_listvar_in_hdf5_v3(types::typed_list &in, int _
             info[i].name = vars[i];
             info[i].size = 0;
 
-            if (varnameOnly)
-            {
-                continue;
-            }
-
             int dset = getDataSetIdFromName(iFile, vars[i]);
             if (dset == 0)
             {
index c16ff57..79d5683 100644 (file)
@@ -29,6 +29,7 @@
     <gateway name="sci_listvar_in_hdf5_v2"              function="listvar_in_hdf5_v2"       type="0" />
     <gateway name="sci_listvar_in_hdf5_v3"              function="listvar_in_hdf5_v3"       type="1" />
     <gateway name="sci_is_hdf5_file"                    function="is_hdf5_file"             type="0" />
+    <gateway name="sci_hdf5_file_version"               function="hdf5_file_version"        type="1" />
     <gateway name="sci_h5dump"                          function="h5dump"                   type="0" />
     <gateway name="sci_h5open"                          function="h5open"                   type="0" />
     <gateway name="sci_h5close"                         function="h5close"                  type="0" />
index d59cca2..db2d77a 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
     <ProjectConfiguration Include="Debug|Win32">
     <ClCompile Include="..\..\sci_gateway\cpp\sci_h5rm.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_h5umount.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_h5write.cpp" />
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_hdf5_file_version.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_import_from_hdf5.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_import_from_hdf5_v3.cpp" />
     <ClCompile Include="..\..\sci_gateway\cpp\sci_is_hdf5_file.cpp" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index ddbd0fa..f59465b 100644 (file)
     <ClCompile Include="..\cpp\handle_properties.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\cpp\sci_hdf5_file_version.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_hdf5_scilab.h">
index 5131d2d..73b6c82 100644 (file)
@@ -1017,7 +1017,7 @@ function %_sodload(%__filename__, varargin)
         end
     end
 
-    if isfile(%__filename__) & is_hdf5_file(%__filename__) then
+    if isfile(%__filename__) & is_hdf5_file(%__filename__) & hdf5_file_version(%__filename__) < 3 then
         %__resumeList__ = %__convertVariable__(%__resumeList__, %__resumeVarlist__);
     end
 
index c823392..192ea70 100644 (file)
@@ -186,3 +186,40 @@ assert_checkequal(l.position, [-1, -2, 1]);
 xs2png(f, TMPDIR + "/saveplot2.png");
 md5_2 = getmd5(TMPDIR + "/saveplot2.png");
 assert_checkequal(md5_1, md5_2);
+// Scicos objects
+clear;
+loadXcosLibs();
+d = scicos_diagram();
+save(TMPDIR + "/diagram.sod", "d");
+refD = d;
+clear d;
+load(TMPDIR + "/diagram.sod");
+assert_checktrue(and(d==refD));
+b = scicos_block();
+save(TMPDIR + "/Block.sod", "b");
+refB = b;
+clear b;
+load(TMPDIR + "/Block.sod");
+assert_checktrue(and(b==refB));
+t = TEXT_f("define");
+save(TMPDIR + "/Text.sod", "t");
+refT = t;
+clear t;
+load(TMPDIR + "/Text.sod");
+assert_checktrue(and(t==refT));
+l = scicos_link();
+save(TMPDIR + "/Link.sod", "l");
+refL = l;
+clear l;
+load(TMPDIR + "/Link.sod");
+assert_checktrue(and(l==refL));
+d = scicos_diagram();
+S = scicos_block();
+subD = scicos_diagram(objs = list(scicos_link()));
+S.model.rpar = subD;
+d.objs(1) = S;
+save(TMPDIR + "/SuperBlock.sod", "d");
+refD = d;
+clear d;
+load(TMPDIR + "/SuperBlock.sod");
+assert_checktrue(and(d==refD));
index 3d45c7a..38e6d04 100644 (file)
@@ -221,4 +221,45 @@ md5_2 = getmd5(TMPDIR + "/saveplot2.png");
 assert_checkequal(md5_1, md5_2);
 
 
-
+// Scicos objects
+clear;
+loadXcosLibs();
+
+d = scicos_diagram();
+save(TMPDIR + "/diagram.sod", "d");
+refD = d;
+clear d;
+load(TMPDIR + "/diagram.sod");
+assert_checktrue(and(d==refD));
+
+b = scicos_block();
+save(TMPDIR + "/Block.sod", "b");
+refB = b;
+clear b;
+load(TMPDIR + "/Block.sod");
+assert_checktrue(and(b==refB));
+
+t = TEXT_f("define");
+save(TMPDIR + "/Text.sod", "t");
+refT = t;
+clear t;
+load(TMPDIR + "/Text.sod");
+assert_checktrue(and(t==refT));
+
+l = scicos_link();
+save(TMPDIR + "/Link.sod", "l");
+refL = l;
+clear l;
+load(TMPDIR + "/Link.sod");
+assert_checktrue(and(l==refL));
+
+d = scicos_diagram();
+S = scicos_block();
+subD = scicos_diagram(objs = list(scicos_link()));
+S.model.rpar = subD;
+d.objs(1) = S;
+save(TMPDIR + "/SuperBlock.sod", "d");
+refD = d;
+clear d;
+load(TMPDIR + "/SuperBlock.sod");
+assert_checktrue(and(d==refD));
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Block_load.sci b/scilab/modules/scicos/macros/scicos_scicos/%Block_load.sci
new file mode 100644 (file)
index 0000000..7356aec
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Block_load(in)
+    out = scicos_load(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Block_save.sci b/scilab/modules/scicos/macros/scicos_scicos/%Block_save.sci
new file mode 100644 (file)
index 0000000..3279f27
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Block_save(in)
+    out = scicos_save(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Link_load.sci b/scilab/modules/scicos/macros/scicos_scicos/%Link_load.sci
new file mode 100644 (file)
index 0000000..15422ae
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Link_load(in)
+    out = scicos_load(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Link_save.sci b/scilab/modules/scicos/macros/scicos_scicos/%Link_save.sci
new file mode 100644 (file)
index 0000000..871ca5e
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Link_save(in)
+    out = scicos_save(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Text_load.sci b/scilab/modules/scicos/macros/scicos_scicos/%Text_load.sci
new file mode 100644 (file)
index 0000000..499d1fe
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Text_load(in)
+    out = scicos_load(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%Text_save.sci b/scilab/modules/scicos/macros/scicos_scicos/%Text_save.sci
new file mode 100644 (file)
index 0000000..7c3632e
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %Text_save(in)
+    out = scicos_save(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%diagram_load.sci b/scilab/modules/scicos/macros/scicos_scicos/%diagram_load.sci
new file mode 100644 (file)
index 0000000..21f5a83
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %diagram_load(in)
+    out = scicos_load(in);
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/%diagram_save.sci b/scilab/modules/scicos/macros/scicos_scicos/%diagram_save.sci
new file mode 100644 (file)
index 0000000..82428a1
--- /dev/null
@@ -0,0 +1,12 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function out = %diagram_save(in)
+    out = scicos_save(in);
+endfunction
index bcfff84..02af600 100644 (file)
@@ -19,7 +19,7 @@
 // See the file ../license.txt
 //
 
-function blk=scicos_block(v1,v2,v3,v4,v5)
+function blk=scicos_block(v1,v2,v3,v4)
     //Block data structure initialization
     if exists("graphics","local")==0 then graphics=scicos_graphics(),end
     if exists("model","local")==0 then model=scicos_model(),end
index 136b569..3d1c255 100644 (file)
@@ -19,7 +19,7 @@
 // See the file ../license.txt
 //
 
-function scs_m=scicos_diagram(v1,v2,v3)
+function scs_m=scicos_diagram(v1,v2,v3,v4)
     if exists("props","local")==0 then props=scicos_params(),end
     if exists("objs","local")==0 then objs=list(),end
     if exists("version","local")==0 then version="",end
index 44795c6..df58e7e 100644 (file)
@@ -19,7 +19,7 @@
 // See the file ../license.txt
 //
 
-function lnk=scicos_link(v1,v2,v3,v4,v5,v6,v7,v8)
+function lnk=scicos_link(v1,v2,v3,v4,v5,v6,v7)
     //initialisation de link scicos_new
     if exists("xx","local")==0 then xx=[],end
     if exists("yy","local")==0 then yy=[],end
@@ -28,7 +28,7 @@ function lnk=scicos_link(v1,v2,v3,v4,v5,v6,v7,v8)
     if exists("ct","local")==0 then ct=[1,1],end
     if exists("from","local")==0 then from=[],end
     if exists("to","local")==0 then to=[],end
+
     lnk=scicos_new(["Link","xx","yy","id","thick","ct","from","to"],..
     xx,yy,id,thick,ct,from,to)
-
 endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/scicos_load.sci b/scilab/modules/scicos/macros/scicos_scicos/scicos_load.sci
new file mode 100644 (file)
index 0000000..2ab1695
--- /dev/null
@@ -0,0 +1,22 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function o = scicos_load(ml)
+    select typeof(ml)
+    case "diagram" then
+        o = scicos_diagram(props=ml.props, objs=ml.objs, version=ml.version, contrib=ml.contrib);
+    case "Block" then
+        o = scicos_block(graphics=ml.graphics, model=ml.model, gui=ml.gui, doc=ml.doc);
+    case "Text" then
+        o = TEXT_f("define");
+        o.graphics = ml.graphics;
+    else // "Link"
+        o = scicos_link(xx=ml.xx, yy=ml.yy, id=ml.id, thick=ml.thick, ct=ml.ct, from=ml.from, to=ml.to);
+    end
+endfunction
diff --git a/scilab/modules/scicos/macros/scicos_scicos/scicos_save.sci b/scilab/modules/scicos/macros/scicos_scicos/scicos_save.sci
new file mode 100644 (file)
index 0000000..564f065
--- /dev/null
@@ -0,0 +1,57 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
+//
+// 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
+
+function ml = scicos_save(o)
+    f = getfield(1, o);
+    ml = mlist(f);
+
+    // Here, the cases need to be separated to dig in 'objs' and 'rpar' properties,
+    // in order to do a deep recursive conversion to mlist
+
+    select typeof(o)
+    case "diagram" then
+        ml.props = o.props;
+        if length(o.objs) > 0 then
+            ml.objs = list();
+            for i=1:length(o.objs)
+                if isScicosObject(o.objs(i)) then
+                    ml.objs(i) = scicos_save(o.objs(i))
+                else
+                    ml.objs(i) = o.objs(i);
+                end
+            end
+        else
+            ml.objs = o.objs;
+        end
+        ml.version = o.version;
+        ml.contrib = o.contrib;
+    case "Block" then
+        ml.graphics = o.graphics;
+        ml.model = o.model;
+        if isScicosObject(ml.model.rpar) then
+            ml.model.rpar = scicos_save(ml.model.rpar);
+        end
+        ml.gui = o.gui;
+        ml.doc = o.doc;
+    else // "Text" or "Link"
+        for i=f(2:$)
+            ml(i) = o(i);
+        end
+    end
+endfunction
+
+function result = isScicosObject(var)
+    result = %f;
+    // 128: user-type
+    if type(var) == 128 then
+        if typeof(var) == "diagram" | typeof(var) == "Block" | typeof(var) == "Text"  | typeof(var) == "Link" then
+            result = %t;
+        end
+    end
+endfunction