Xcos: fix for the to_workspace search 48/12148/4
Paul BIGNIER [Fri, 26 Jul 2013 11:59:04 +0000 (13:59 +0200)]
Fixed the case when the to_workspace block buffersize was larger than the number of steps

By imitation with xcos_simulate.sci.

Change-Id: I51a79bfdd07278bcc0ff569cff276b1fdbe6a720

scilab/modules/scicos/macros/scicos_auto/scicos_simulate.sci
scilab/modules/xcos/macros/xcos_simulate.sci

index 45c2433..c86d8d7 100644 (file)
@@ -394,35 +394,31 @@ function [alreadyran, %cpr, Resume_line, TOWS_vals, Names] = do_terminate1(scs_m
         // Second step: Link the variable names to their values vectors,
         //and call '[names(1), names(2), ...] = resume(names(1), names(2), ...)' to save the variable into Scilab
         if ~isempty(Names) then
-            execstr("Names1val  = "+Names(1)+"_val;");
-            execstr("Names1valt = "+Names(1)+"_valt;");
-            // If input is a matrix, use function matrix() to reshape the saved values
-            if (size(Names1val, "r") > buff_sizes(1)) then  // In this case, size(Names(1), 'r') = buff_sizes(1) * nCols2
-                nRows = buff_sizes(1);
-                nCols  = size(Names1val, "c");
-                nCols2 = size(Names1val, "r") / buff_sizes(1);
-                Names1val = matrix(Names1val, nCols, nCols2, nRows);
-            end
-            // Replace default struct with value vector of first element of 'Names'
-            TOWS_vals.values = Names1val;
-            TOWS_vals.time   = Names1valt;
-            Resume_line_args = Names(1);  // Will contain 'names(1), names(2), ...'
-            for i=2:size(Names, "c")
+            for i=1:size(Names, "c")
                 execstr("NamesIval = "+Names(i)+"_val;");
+                execstr("NamesIvalt = "+Names(i)+"_valt;");
                 // If input is a matrix, use function matrix() to reshape the saved values
-                if (size(NamesIval, "r") > buff_sizes(i)) then  // In this case, size(Names(i), 'r') = buff_sizes(i) * nCols2
-                    nRows = buff_sizes(i);
+                // Check condition using time vector, if we have more values than time stamps, split it
+                if (size(NamesIval, "r") > size(NamesIvalt, "r")) then  // In this case, size(Names(i), 'r') = buff_sizes(i) * nCols2
+                    nRows  = size(NamesIvalt, "r");
                     nCols  = size(NamesIval, "c");
-                    nCols2 = size(NamesIval, "r") / buff_sizes(i);
+                    nCols2 = size(NamesIval, "r") / nRows;
                     NamesIval = matrix(NamesIval, nCols, nCols2, nRows);
                 end
-                ierr = execstr("TOWS_vals = [TOWS_vals struct(''values'', NamesIval,''time'',"+Names(i)+"_valt)];", "errcatch");
-                if ierr <> 0 then
-                    str_err = split_lasterror(lasterror());
-                    message(["Simulation problem" ; "Unable to find To Workspace Variable {"+Names(i)+"}:" ; str_err]);
-                    break;
+                if i == 1 then
+                    // Replace default struct with value vector of first element of 'Names'
+                    TOWS_vals.values = NamesIval;
+                    TOWS_vals.time   = NamesIvalt;
+                    Resume_line_args = Names(1);
+                else
+                    ierr = execstr("TOWS_vals = [TOWS_vals struct(''values'', NamesIval, ''time'', NamesIvalt)];", "errcatch");
+                    if ierr <> 0 then
+                        str_err = split_lasterror(lasterror());
+                        message(["Simulation problem" ; "Unable to find To Workspace Variable {"+Names(i)+"}:" ; str_err]);
+                        break;
+                    end
+                    Resume_line_args   = Resume_line_args + ", " + Names(i);  // Concatenate the variable names up to the last one
                 end
-                Resume_line_args   = Resume_line_args + ", " + Names(i);  // Concatenate the variable names up to the last one
             end
             Resume_line = "[" + Resume_line_args + "] = resume(" + Resume_line_args + ");";  // Build the message
             // Will execute Resume_line at the end of the main function, because it does not return control
index 082ead5..b8013b8 100644 (file)
@@ -390,17 +390,17 @@ function %cpr = xcos_simulate(scs_m, needcompile)
     //and call '[names(1), names(2), ...] = resume(names(1), names(2), ...)' to save the variable into Scilab
     if ~isempty(Names) then
         for i=1:size(Names, "c")
-            execstr("NamesIval = "+Names(i)+"_val;");
+            execstr("NamesIval  = "+Names(i)+"_val;");
             execstr("NamesIvalt = "+Names(i)+"_valt;");
             // If input is a matrix, use function matrix() to reshape the saved values
             // Check condition using time vector, if we have more values than time stamps, split it
             if (size(NamesIval, "r") > size(NamesIvalt, "r")) then
-                nRows =  size(NamesIvalt, "r");
+                nRows  = size(NamesIvalt, "r");
                 nCols  = size(NamesIval, "c");
                 nCols2 = size(NamesIval, "r") / nRows;
                 NamesIval = matrix(NamesIval, nCols, nCols2, nRows);
             end
-            ierr = execstr(Names(i)+" = struct(''values'', NamesIval,''time'',NamesIvalt)", "errcatch");
+            ierr = execstr(Names(i)+" = struct(''values'', NamesIval, ''time'', NamesIvalt)", "errcatch");
             if ierr <> 0 then
                 str_err = split_lasterror(lasterror());
                 message(["Simulation problem" ; "Unable to resume To Workspace Variable {"+Names(i)+"}:" ; str_err]);
@@ -409,7 +409,7 @@ function %cpr = xcos_simulate(scs_m, needcompile)
             if i == 1 then
                 Resume_line_args = Names(1);
             else
-                Resume_line_args   = Resume_line_args + ", " + Names(i);  // Concatenate the variable names up to the last one
+                Resume_line_args = Resume_line_args + ", " + Names(i);  // Concatenate the variable names up to the last one
             end
         end
         Resume_line = "[" + Resume_line_args + "] = resume(" + Resume_line_args + ");";  // Build the message