Differential_equations: fix ode gateway to match Scilab 5 33/16933/2
Paul Bignier [Thu, 30 Jul 2015 08:08:21 +0000 (10:08 +0200)]
 * When using root-find feature, Scilab 5 returned [] in case no root was found
 * Tested by Demos->Simulation->ODE->Chemical_process_(Stiff)

Change-Id: I69089f2d1d335d65f37471c77c9cf3da5e01abdd

scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp

index 281ecba..da8f96e 100644 (file)
@@ -1336,7 +1336,6 @@ types::Function::ReturnValue sci_ode(types::typed_list &in, int _iRetCount, type
                 bCatch = true;
                 err = 1;
             }
-
             // FREE allocated data
             if (err == 1) // error case
             {
@@ -1522,15 +1521,23 @@ types::Function::ReturnValue sci_ode(types::typed_list &in, int _iRetCount, type
             }
         }
 
-        types::Double* pDblRd = new types::Double(1, sizeOfRd);
-        //rd: The first entry contains the stopping time.
-        pDblRd->set(0, C2F(lsr001).tlast);
-        for (int i = 0; i < pDblNg->get(0); i++)
+        types::Double* pDblRd = NULL;
+        if (sizeOfRd == 1) // Not root found, return empty matrix
         {
-            if (jroot[i])
+            pDblRd = types::Double::Empty();
+        }
+        else
+        {
+            pDblRd = new types::Double(1, sizeOfRd);
+            //rd: The first entry contains the stopping time.
+            pDblRd->set(0, C2F(lsr001).tlast);
+            for (int i = 0; i < pDblNg->get(0); i++)
             {
-                k++;
-                pDblRd->set(k, (double)i + 1);
+                if (jroot[i])
+                {
+                    k++;
+                    pDblRd->set(k, (double)i + 1);
+                }
             }
         }
         out.push_back(pDblRd); // rd