GetStructVariable : now manage multiple element structs. 40/16440/3
Sylvain GENIN [Mon, 4 May 2015 15:16:13 +0000 (17:16 +0200)]
Test: test_run("matio","bug_9354");

Change-Id: I51549604f1653bae4b7b4dcd277946d22ecdbd01

scilab/modules/matio/src/cpp/CreateMatlabTreeVariable.cpp
scilab/modules/matio/src/cpp/GetStructVariable.cpp

index db5fcba..9d3f08b 100644 (file)
@@ -33,11 +33,21 @@ InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
     int iRank = matVariable->rank;
     if (iRank != 0)
     {
-        piDims = (int *)MALLOC(iRank * sizeof(int));
-
-        for (int i = 0; i < iRank; ++i)
+        if (iRank == 1)
+        {
+            iRank = 2;
+            piDims = (int *)MALLOC(iRank * sizeof(int));
+            piDims[0] = (int)matVariable->dims[0];
+            piDims[1] = 1;
+        }
+        else
         {
-            piDims[i] = (int)matVariable->dims[i];
+            piDims = (int *)MALLOC(iRank * sizeof(int));
+
+            for (int i = 0; i < iRank; ++i)
+            {
+                piDims[i] = (int)matVariable->dims[i];
+            }
         }
     }
 
index bdd65d0..8351be3 100644 (file)
@@ -52,7 +52,6 @@ matvar_t* GetStructMatVar(types::Struct* pStruct, const char *name, int matfile_
     matvar_t* pMatVarOut = NULL;
 
     /* OTHERS LIST ENTRIES: ALL CELL VALUES */
-
     size_t* pszDims = (size_t*)MALLOC(Dims * sizeof(size_t));
     if (pszDims == NULL)
     {
@@ -69,7 +68,6 @@ matvar_t* GetStructMatVar(types::Struct* pStruct, const char *name, int matfile_
     {
         pszDims[K] = ((int*)pDims)[K];
     }
-    pszDims[1] = pszDims[1] * isizeFieldNames;
 
     structEntries = (matvar_t **)MALLOC(sizeof(matvar_t*) * prodDims * isizeFieldNames + 1);
     if (structEntries == NULL)
@@ -99,7 +97,7 @@ matvar_t* GetStructMatVar(types::Struct* pStruct, const char *name, int matfile_
         }
     }
 
-    pMatVarOut = Mat_VarCreate(name, MAT_C_STRUCT, MAT_T_STRUCT, prodDims , pszDims, structEntries, 0);
+    pMatVarOut = Mat_VarCreate(name, MAT_C_STRUCT, MAT_T_STRUCT, prodDims * isizeFieldNames, pszDims, structEntries, 0);
 
     FREE(pszDims);
     return pMatVarOut;