Check the number of input arguments in the %sp_gsort function 09/8409/2
Adeline CARNIS [Mon, 30 Jul 2012 12:59:48 +0000 (14:59 +0200)]
Change-Id: I290437e2cdad6d9de1dea83bbb2b28b57e9bb752

scilab/modules/elementary_functions/macros/%sp_gsort.sci

index 3c6b347..9b96fcc 100644 (file)
@@ -9,6 +9,15 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\r
 \r
 function A = %sp_gsort(A, optsort, directionsort)\r
+    rhs = argn(2);\r
+    select rhs\r
+    case 1\r
+        optsort = 'g';\r
+        directionsort = 'd';\r
+    case 2\r
+        directionsort = 'd';\r
+    end\r
+\r
     [ij, v, mn] = spget(A);\r
 \r
     if mn(1) <> 1 & mn(2) <> 1 then\r
@@ -21,31 +30,54 @@ function A = %sp_gsort(A, optsort, directionsort)
         if mn(2) == 1 then\r
             dif = mn(1) - length(v);\r
             v = gsort(v, optsort, directionsort);\r
+            \r
+            last = find(v<0);\r
+            first = find(v>0);\r
+            \r
+            if last == [] & first <> [] then\r
+                if strcmp(directionsort, 'i')== 0 then\r
+                    ij(:,1) = first(:) + dif;\r
+                else\r
+                    ij(:,1) = first(:);\r
+                end\r
+            elseif first == [] & last <> [] then\r
+                ij(:,1) = last(:) + dif;\r
+            else\r
+                if strcmp(directionsort, 'i')== 0 then\r
+                    ij(:,1) = [last(:); first(:) + dif];\r
+                else\r
+                    ij(:,1) = [first(:); last(:) + dif];\r
+                end\r
+            end\r
+            \r
         elseif mn(1) == 1 then\r
             dif = mn(2) - length(v);\r
             v = gsort(v, optsort, directionsort);\r
-        end\r
-\r
-        last = find(v<0);\r
-        first = find(v>0);\r
-\r
-        if last == [] & first <> [] then\r
-            if strcmp(directionsort, 'i')== 0 then\r
-                ij(:,1) = first(:) + dif;\r
+            \r
+            last = find(v<0);\r
+            first = find(v>0);\r
+            \r
+            if last == [] & first <> [] then\r
+                if strcmp(directionsort, 'i')== 0 then\r
+                    ij(:,2) = first(:) + dif;\r
+                else\r
+                    ij(:,2) = first(:);\r
+                end\r
+            elseif first == [] & last <> [] then\r
+                ij(:,1) = last(:) + dif;\r
             else\r
-                ij(:,1) = first(:);\r
-            end\r
-        elseif first == [] & last <> [] then\r
-            ij(:,1) = last(:) + dif;\r
-        else\r
-            if strcmp(directionsort, 'i')== 0 then\r
-                ij(:,1) = [last(:); first(:) + dif];\r
-            else\r
-                ij(:,1) = [first(:); last(:) + dif];\r
+                if strcmp(directionsort, 'i')== 0 then\r
+                    ij(:,2) = [last(:); first(:) + dif];\r
+                else\r
+                    ij(:,2) = [first(:); last(:) + dif];\r
+                end\r
             end\r
+            \r
         end\r
-\r
         A = sparse(ij, v, mn)\r
     end\r
+\r
 endfunction\r
+\r
+\r
 \r\r