bug 11022: -append can be use in save and export_to_hdf5 functions at any position... 11/7211/2
Antoine ELIAS [Tue, 22 May 2012 09:10:01 +0000 (11:10 +0200)]
Change-Id: I06cf4f94476f24a8a5a64deb2b6a9d6653dac8bc

scilab/modules/hdf5/sci_gateway/cpp/sci_export_to_hdf5.cpp
scilab/modules/io/macros/%_save.sci
scilab/modules/io/sci_gateway/c/sci_save.c
scilab/modules/m2sci/macros/matfile2sci.sci

index c08bde1..d84a73c 100644 (file)
@@ -67,7 +67,6 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
     char** pstNameList  = NULL;
     char *pstFileName   = NULL;
     bool bExport        = false;
-    int iStartVarName   = 1;
     bool bAppendMode    = false;
 
     SciErr sciErr;
@@ -87,21 +86,22 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
         return 1;
     }
 
-    if(strcmp(pstNameList[1], "-append") == 0)
+    piAddrList = (int**)MALLOC(sizeof(int*) * (iNbVar));
+    for (int i = 1 ; i < Rhs ; i++)
     {
-        bAppendMode = true;
-        iStartVarName = 2;
-    }
-
-    piAddrList = (int**)MALLOC(sizeof(int*) * (iNbVar - iStartVarName));
-    for (int i = iStartVarName ; i < Rhs ; i++)
-    {
-        sciErr = getVarAddressFromName(pvApiCtx, pstNameList[i], &piAddrList[i - iStartVarName]);
-        if (sciErr.iErr)
+        if(strcmp(pstNameList[i], "-append") == 0)
         {
-            Scierror(999, _("%s: Wrong value for input argument #%d: Defined variable expected.\n"), fname, i + 1);
-            printError(&sciErr, 0);
-            return 1;
+            bAppendMode = true;
+        }
+        else
+        {
+            sciErr = getVarAddressFromName(pvApiCtx, pstNameList[i], &piAddrList[i]);
+            if (sciErr.iErr)
+            {
+                Scierror(999, _("%s: Wrong value for input argument #%d: Defined variable expected.\n"), fname, i + 1);
+                printError(&sciErr, 0);
+                return 1;
+            }
         }
     }
 
@@ -154,9 +154,14 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
             //import all data
             for(int i = 0 ; i < iNbItem ; i++)
             {
-                for(int j = 0 ; j < Rhs - iStartVarName; j++)
+                for(int j = 1 ; j < Rhs ; j++)
                 {
-                    if(strcmp(pstVarNameList[i], pstNameList[j + iStartVarName]) == 0)
+                    if(strcmp(pstNameList[i], "-append") == 0)
+                    {
+                        continue;
+                    }
+
+                    if(strcmp(pstVarNameList[i], pstNameList[j]) == 0)
                     {
 
                         Scierror(999, _("%s: Variable \'%s\' already exists in file \'%s\'."), fname, pstVarNameList[i], pstNameList[0]);
@@ -170,9 +175,14 @@ int sci_export_to_hdf5(char *fname, unsigned long fname_len)
     }
 
     // export data
-    for (int i = 0 ; i < Rhs - iStartVarName; i++)
+    for (int i = 1 ; i < Rhs ; i++)
     {
-        bExport = export_data(iH5File, piAddrList[i], pstNameList[i + iStartVarName]);
+        if(strcmp(pstNameList[i], "-append") == 0)
+        {
+            continue;
+        }
+
+        bExport = export_data(iH5File, piAddrList[i], pstNameList[i]);
         if (bExport == false)
         {
             break;
index 40efe77..28989e4 100644 (file)
@@ -12,6 +12,11 @@ function [] = %_save(filename, varargin)
 
     varList = list();
     for i = 1:size(varargin)
+
+        if varargin(i) == "-append" then
+            continue;
+        end
+
         temp = evstr(varargin(i));
 
         if isList(temp) then
index 2bce654..fe55c74 100644 (file)
@@ -96,30 +96,32 @@ int sci_save(char *fname, unsigned long fname_len)
                 return 1;
             }
 
-            //try to get variable by name
-            sciErr = getVarAddressFromName(pvApiCtx, pstVarI, &piAddrI2);
-            if (sciErr.iErr)
+            if(strcmp(pstVarI, "-append") != 0)
             {
-                // Try old save because here the input variable can be of type "string" but not a variable name
-                // Ex: a=""; save(filename, a);
-                iOldSave = TRUE;
-                break;
-            }
-
-            if (piAddrI2 == 0)
-            {
-                iOldSave = TRUE;
-                break;
+                //try to get variable by name
+                sciErr = getVarAddressFromName(pvApiCtx, pstVarI, &piAddrI2);
+                if (sciErr.iErr)
+                {
+                    // Try old save because here the input variable can be of type "string" but not a variable name
+                    // Ex: a=""; save(filename, a);
+                    iOldSave = TRUE;
+                    break;
+                }
+
+                if (piAddrI2 == 0)
+                {
+                    iOldSave = TRUE;
+                    break;
+                }
             }
 
             freeAllocatedSingleString(pstVarI);
+        }
 
-            {
-                int lw = 0;
-                //call "overload" to prepare data to export_to_hdf5 function.
-                C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
-            }
-
+        {
+            int lw = 0;
+            //call "overload" to prepare data to export_to_hdf5 function.
+            C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
         }
     }
     else
index 8706c92..5bea804 100644 (file)
@@ -36,7 +36,7 @@ ierrsave = 0;
 
 //--loop on the stored variables
 while Name<>"" & ierr==0 & ierrsave==0
-  ierrsave = execstr(Name + " = Matrix; export_to_hdf5(fdo, ""-append"", """+Name+""")", "errcatch")
+  ierrsave = execstr(Name + " = Matrix; save(fdo, ""-append"", """+Name+""")", "errcatch")
   if ierrsave==0 then
     //-- Read next variable
     ierr = execstr("[Name, Matrix, Class] = matfile_varreadnext(fdi);", "errcatch");