hdf5: force some hdf5 lib functions, force no depreacated functions, convert code... 05/11205/2
Antoine ELIAS [Wed, 3 Apr 2013 13:06:32 +0000 (15:06 +0200)]
Change-Id: Ieeab92fe2e6e3e6fd8a2234f553c47c5cf5f4d10

scilab/modules/hdf5/sci_gateway/cpp/sci_import_from_hdf5.cpp
scilab/modules/hdf5/src/c/h5_readDataFromFile.c
scilab/modules/hdf5/src/c/h5_readDataFromFile_v1.c
scilab/modules/hdf5/src/c/h5_writeDataToFile.c
scilab/modules/hdf5/src/c/hdf5.vcxproj
scilab/modules/hdf5/src/cpp/H5Group.cpp
scilab/modules/hdf5/tests/unit_tests/h5isGroup.tst
scilab/modules/hdf5/tests/unit_tests/h5readattr.dia.ref
scilab/modules/hdf5/tests/unit_tests/h5readattr.tst

index 9470c0a..4ebab38 100644 (file)
@@ -186,7 +186,7 @@ int sci_import_from_hdf5(char *fname, unsigned long fname_len)
 static bool import_variable(int _iFile, char* _pstVarName)
 {
     int iDataSetId = getDataSetIdFromName(_iFile, _pstVarName);
-    if (iDataSetId == 0)
+    if (iDataSetId <= 0)
     {
         return false;
     }
index 633e04e..159eaa9 100644 (file)
@@ -84,7 +84,7 @@ static int readIntAttribute(int _iDatasetId, const char *_pstName)
 
     if (H5Aiterate(_iDatasetId, H5_INDEX_NAME, H5_ITER_NATIVE, &n, find_attr_by_name, (void *)_pstName) > 0)
     {
-        iAttributeId = H5Aopen_name(_iDatasetId, _pstName);
+        iAttributeId = H5Aopen(_iDatasetId, _pstName, H5P_DEFAULT);
         if (iAttributeId < 0)
         {
             return -1;
@@ -121,7 +121,7 @@ static char* readAttribute(int _iDatasetId, const char *_pstName)
 
     if (H5Aiterate(_iDatasetId, H5_INDEX_NAME, H5_ITER_NATIVE, &n, find_attr_by_name, (void *)_pstName) > 0)
     {
-        iAttributeId = H5Aopen_name(_iDatasetId, _pstName);
+        iAttributeId = H5Aopen(_iDatasetId, _pstName, H5P_DEFAULT);
         if (iAttributeId < 0)
         {
             return NULL;
@@ -379,13 +379,15 @@ int getVariableNames(int _iFile, char **pstNameList)
     herr_t status = 0;
     int iNbItem = 0;
     H5O_info_t oinfo;
+    H5G_info_t ginfo;
 
-    status = H5Gget_num_objs(_iFile, &iCount);
+    status = H5Gget_info(_iFile, &ginfo);
     if (status != 0)
     {
         return 0;
     }
 
+    iCount = ginfo.nlinks;
     for (i = 0; i < iCount; i++)
     {
         status = H5Oget_info_by_idx(_iFile, "/", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT);
@@ -398,11 +400,9 @@ int getVariableNames(int _iFile, char **pstNameList)
         {
             if (pstNameList != NULL)
             {
-                int iLen = 0;
-
-                iLen = (int)H5Gget_objname_by_idx(_iFile, i, NULL, iLen);
-                pstNameList[iNbItem] = (char *)MALLOC(sizeof(char) * (iLen + 1));   //null terminated
-                H5Gget_objname_by_idx(_iFile, i, pstNameList[iNbItem], iLen + 1);
+                ssize_t iLen = H5Lget_name_by_idx(_iFile, ".", H5_INDEX_NAME, H5_ITER_INC, i, 0, 0, H5P_DEFAULT) + 1;
+                pstNameList[iNbItem] = (char*)MALLOC(sizeof(char) * iLen);
+                H5Lget_name_by_idx(_iFile, ".", H5_INDEX_NAME, H5_ITER_INC, i, pstNameList[iNbItem], iLen, H5P_DEFAULT);
             }
             iNbItem++;
         }
index cbfa649..560292b 100644 (file)
@@ -327,13 +327,15 @@ int getVariableNames_v1(int _iFile, char **pstNameList)
     herr_t status = 0;
     int iNbItem = 0;
     H5O_info_t oinfo;
+    H5G_info_t ginfo;
 
-    status = H5Gget_num_objs(_iFile, &iCount);
+    status = H5Gget_info(_iFile, &ginfo);
     if (status != 0)
     {
         return 0;
     }
 
+    iCount = ginfo.nlinks;
     for (i = 0; i < iCount; i++)
     {
         status = H5Oget_info_by_idx(_iFile, "/", H5_INDEX_NAME, H5_ITER_NATIVE, i, &oinfo, H5P_DEFAULT);
@@ -346,11 +348,9 @@ int getVariableNames_v1(int _iFile, char **pstNameList)
         {
             if (pstNameList != NULL)
             {
-                int iLen = 0;
-
-                iLen = (int)H5Gget_objname_by_idx(_iFile, i, NULL, iLen);
-                pstNameList[iNbItem] = (char *)MALLOC(sizeof(char) * (iLen + 1));   //null terminated
-                H5Gget_objname_by_idx(_iFile, i, pstNameList[iNbItem], iLen + 1);
+                ssize_t iLen = H5Lget_name_by_idx(_iFile, ".", H5_INDEX_NAME, H5_ITER_INC, i, 0, 0, H5P_DEFAULT) + 1;
+                pstNameList[iNbItem] = (char*)MALLOC(sizeof(char) * iLen);
+                H5Lget_name_by_idx(_iFile, ".", H5_INDEX_NAME, H5_ITER_INC, i, pstNameList[iNbItem], iLen, H5P_DEFAULT);
             }
             iNbItem++;
         }
@@ -375,11 +375,12 @@ int getDataSetId_v1(int _iFile)
 {
     herr_t status = 0;
     int iDatasetId = 0;
+    hsize_t idx = 0;
 
     /*
     * Begin iteration.
     */
-    status = H5Giterate(_iFile, "/", NULL, op_func_v1, &iDatasetId);
+    status = H5Literate(_iFile, H5_INDEX_NAME, H5_ITER_NATIVE, &idx, op_func_v1, &iDatasetId);
     if (status < 0)
     {
         return -1;
index b789bb5..5cd6ab6 100644 (file)
@@ -1791,6 +1791,8 @@ int closeList(int _iFile, void *_pvList, char *_pstListName, int _iNbItem, int _
 static int deleteHDF5group(int _iFile, char* _pstName)
 {
     hid_t status = 0;
+    char** pstChildName = NULL;
+
     //open group
     char* pstGroupName = createGroupName(_pstName);
     hid_t groupID = H5Gopen(_iFile, pstGroupName, H5P_DEFAULT);
@@ -1808,25 +1810,30 @@ static int deleteHDF5group(int _iFile, char* _pstName)
         //for each child,
         for (i = 0 ; i < groupInfo.nlinks ; i++)
         {
-            ssize_t size = 0;
             char* pstPathName = NULL;
-            char* pstChildName = NULL;
             //build child path
             pstPathName = createPathName(pstGroupName, i);
 
             //try to delete child and his children
             deleteHDF5group(_iFile, pstPathName);
+            FREE(pstPathName);
+        }
 
+        pstChildName = (char**)MALLOC(sizeof(char*) * groupInfo.nlinks);
+
+        for (i = 0 ; i < groupInfo.nlinks ; i++)
+        {
             //get child name
-            size = H5Lget_name_by_idx(groupID, ".", H5_INDEX_NAME, H5_ITER_INC, 0, 0, 0, H5P_DEFAULT) + 1;
-            pstChildName = (char*)MALLOC(sizeof(char) * size);
-            H5Lget_name_by_idx(groupID, ".", H5_INDEX_NAME, H5_ITER_INC, 0, pstChildName, size, H5P_DEFAULT);
+            ssize_t size = H5Lget_name_by_idx(groupID, ".", H5_INDEX_NAME, H5_ITER_INC, i, 0, 0, H5P_DEFAULT) + 1;
+            pstChildName[i] = (char*)MALLOC(sizeof(char) * size);
+            H5Lget_name_by_idx(groupID, ".", H5_INDEX_NAME, H5_ITER_INC, i, pstChildName[i], size, H5P_DEFAULT);
+        }
 
+        for (i = 0 ; i < groupInfo.nlinks ; i++)
+        {
             //unlink child
-            status = H5Ldelete(groupID, pstChildName, H5P_DEFAULT);
-
-            FREE(pstChildName);
-            FREE(pstPathName);
+            status = H5Ldelete(groupID, pstChildName[i], H5P_DEFAULT);
+            FREE(pstChildName[i]);
 
             if (status < 0)
             {
@@ -1834,6 +1841,7 @@ static int deleteHDF5group(int _iFile, char* _pstName)
             }
         }
 
+        FREE(pstChildName);
         //close group
         status = H5Gclose(groupID);
         if (status < 0)
index a418c1f..b2bfcbc 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">
@@ -77,7 +77,7 @@
     <ClCompile>
       <Optimization>Disabled</Optimization>
       <AdditionalIncludeDirectories>.;../../includes;../../../output_stream/includes;../../../core/includes;../../../api_scilab/includes;../../../localization/includes;../../../../libs/intl;../../../../libs/hdf5/include;../../../windows_tools/includes;../../../fileio/includes;../../../commons/src/jni;../../../jvm/includes;../../../../java/jdk/include;../../../../java/jdk/include/win32;../jni;../cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>H5Topen_vers=2;H5Dcreate_vers=2;H5Aiterate_vers=2;H5Gcreate_vers=2;H5Gopen_vers=2;H5Tget_array_dims_vers=2;H5Acreate_vers=2;NO_DEPRECATED_SYMBOLS;_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
       <DisableSpecificWarnings>4251;%(DisableSpecificWarnings)</DisableSpecificWarnings>
     <ClCompile>
       <Optimization>Disabled</Optimization>
       <AdditionalIncludeDirectories>.;../../includes;../../../output_stream/includes;../../../core/includes;../../../api_scilab/includes;../../../localization/includes;../../../../libs/intl;../../../../libs/hdf5/include;../../../windows_tools/includes;../../../fileio/includes;../../../commons/src/jni;../../../jvm/includes;../../../../java/jdk/include;../../../../java/jdk/include/win32;../jni;../cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>H5Topen_vers=2;H5Dcreate_vers=2;H5Aiterate_vers=2;H5Gcreate_vers=2;H5Gopen_vers=2;H5Tget_array_dims_vers=2;H5Acreate_vers=2;NO_DEPRECATED_SYMBOLS;_CRT_SECURE_NO_DEPRECATE;FORDLL;_DEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
       <DisableSpecificWarnings>4251;%(DisableSpecificWarnings)</DisableSpecificWarnings>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
       <AdditionalIncludeDirectories>.;../../includes;../../../output_stream/includes;../../../core/includes;../../../api_scilab/includes;../../../localization/includes;../../../../libs/intl;../../../../libs/hdf5/include;../../../windows_tools/includes;../../../fileio/includes;../../../commons/src/jni;../../../jvm/includes;../../../../java/jdk/include;../../../../java/jdk/include/win32;../jni;../cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>H5Topen_vers=2;H5Dcreate_vers=2;H5Aiterate_vers=2;H5Gcreate_vers=2;H5Gopen_vers=2;H5Tget_array_dims_vers=2;H5Acreate_vers=2;NO_DEPRECATED_SYMBOLS;_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <WholeProgramOptimization>false</WholeProgramOptimization>
       <AdditionalIncludeDirectories>.;../../includes;../../../output_stream/includes;../../../core/includes;../../../api_scilab/includes;../../../localization/includes;../../../../libs/intl;../../../../libs/hdf5/include;../../../windows_tools/includes;../../../fileio/includes;../../../commons/src/jni;../../../jvm/includes;../../../../java/jdk/include;../../../../java/jdk/include/win32;../jni;../cpp;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>H5Topen_vers=2;H5Dcreate_vers=2;H5Aiterate_vers=2;H5Gcreate_vers=2;H5Gopen_vers=2;H5Tget_array_dims_vers=2;H5Acreate_vers=2;NO_DEPRECATED_SYMBOLS;_CRT_SECURE_NO_DEPRECATE;FORDLL;NDEBUG;_WINDOWS;_USRDLL;HDF5_SCILAB_EXPORTS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <StringPooling>true</StringPooling>
       <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
       <WarningLevel>Level3</WarningLevel>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
index 158a3f4..e39a28b 100644 (file)
@@ -328,14 +328,9 @@ herr_t H5Group::printLsInfo(hid_t g_id, const char * name, const H5L_info_t * in
     H5O_info_t oinfo;
     herr_t err;
     H5Object * hobj = 0;
-    hid_t obj;
+    hid_t obj = 0;
     OpDataPrintLs & opdata = *(OpDataPrintLs *)op_data;
 
-    if (obj < 0)
-    {
-        return (herr_t) - 1;
-    }
-
     switch (info->type)
     {
         case H5L_TYPE_SOFT:
index c53278d..b46e5d9 100644 (file)
@@ -4,8 +4,9 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-
 // <-- CLI SHELL MODE -->
+//
+// <-- ENGLISH IMPOSED -->
 
 msgerr = msprintf(gettext("%s: Wrong number of input argument(s): 1 expected."), "h5isGroup");
 assert_checkerror("h5isGroup()",msgerr,77);
index 09ca1d6..427ea96 100644 (file)
@@ -21,21 +21,12 @@ assert_checkerror("h5readattr(""42"",""42"",""42"")",msgerr,999);
 x = int8(matrix(1:80, 10, 8));
 save(TMPDIR + "/x.sod", "x");
 version = string(getversion('scilab'));
-version = getversion()+" "+strcat([version(1),version(2),version(3)],'.')
- version  =
- scilab-branch-master 5.5.0   
+version = getversion()+" "+strcat([version(1),version(2),version(3)],'.');
 a = h5open(TMPDIR + "/x.sod");
 scilab_version = h5readattr(a, "/", "SCILAB_scilab_version");
 assert_checkequal(scilab_version,version);
-scilab_class = h5readattr(a.root.x, "SCILAB_Class")
- scilab_class  =
- integer   
-assert_checkequal(scilab_class,"integer")
- ans  =
-  T  
+scilab_class = h5readattr(a.root.x, "SCILAB_Class");
+assert_checkequal(scilab_class,"integer");
 msgerr = msprintf(gettext("%s: Cannot open attribute: %s\n"), ..
                 "h5readattr","test");
 assert_checkerror("h5readattr(a.root.x, ""test"")",msgerr,999);
index 9ceb7ef..6f44d9d 100644 (file)
@@ -23,15 +23,15 @@ assert_checkerror("h5readattr(""42"",""42"",""42"")",msgerr,999);
 x = int8(matrix(1:80, 10, 8));
 save(TMPDIR + "/x.sod", "x");
 version = string(getversion('scilab'));
-version = getversion()+" "+strcat([version(1),version(2),version(3)],'.')
+version = getversion()+" "+strcat([version(1),version(2),version(3)],'.');
 
 a = h5open(TMPDIR + "/x.sod");
 
 scilab_version = h5readattr(a, "/", "SCILAB_scilab_version");
 assert_checkequal(scilab_version,version);
 
-scilab_class = h5readattr(a.root.x, "SCILAB_Class")
-assert_checkequal(scilab_class,"integer")
+scilab_class = h5readattr(a.root.x, "SCILAB_Class");
+assert_checkequal(scilab_class,"integer");
 
 msgerr = msprintf(gettext("%s: Cannot open attribute: %s\n"), ..
                 "h5readattr","test");