# HG changeset patch
# User Nicholas R. Jankowski <jankowskin@asme.org>
# Date 1506545791 14400
#      Wed Sep 27 16:56:31 2017 -0400
# Node ID 8fbf625dd136891ffdd5e5a223a074d9d50b38e6
# Parent  1a53f0c855db2cdc7c77d209ecac91a19872c631
integral.m: update to use recently changed quadcc (bug #50604)

* scripts/general/integral.m: integral will now make general use of quadcc for all but arrayvalued and waypoints calls

diff -r 1a53f0c855db -r 8fbf625dd136 scripts/general/integral.m
--- a/scripts/general/integral.m	Wed Sep 27 15:56:39 2017 -0400
+++ b/scripts/general/integral.m	Wed Sep 27 16:56:31 2017 -0400
@@ -23,10 +23,11 @@
 ## Numerically evaluate the integral of @var{f} from @var{a} to @var{b} using
 ## adaptive quadrature.
 ##
-## @code{integral} is a wrapper for @code{quadgk} (for scalar integrands) and
-## @code{quadv} (for array-valued integrands) intended to provide @sc{matlab}
-## compatibility.  More control of the numerical integration may be achievable
-## by calling the various quadrature functions directly.
+## @code{integral} is a wrapper for @code{quadcc} (for general scalar 
+## integrands), @code{quadgk} (for integrals with specified integratio paths), 
+## and @code{quadv} (for array-valued integrands) intended to provide 
+## @sc{matlab} compatibility.  More control of the numerical integration may be 
+## achievable by calling the various quadrature functions directly.
 ##
 ## @var{f} is a function handle, inline function, or string containing the name
 ## of the function to evaluate.  The function @var{f} must be vectorized and
@@ -52,7 +53,8 @@
 ## @code{integral} expects @var{f} to return a scalar value unless
 ## @var{arrayvalued} is specified as true.  This option will cause
 ## @code{integral} to perform the integration over the entire array and return
-## @var{q} with the same dimensions as returned by @var{f}.
+## @var{q} with the same dimensions as returned by @var{f}. For more detail see
+## @code{quadv}.
 ##
 ## @item AbsTol
 ## Define the absolute error tolerance for the quadrature.  The default
@@ -90,9 +92,10 @@
 ## inputs in place regardless of the class of the integration limits.
 ##
 ## @item
-## As a consequence of using @code{quadgk} and @code{quadv}, certain option
-## combinations are not supported.  Currently, @qcode{"ArrayValued"} cannot be
-## combined with @qcode{"RelTol"} or @qcode{"Waypoints"}.
+## As a consequence of using @code{quadcc}, @code{quadgk} and @code{quadv}, 
+## certain option combinations are not supported.  Currently, 
+## @qcode{"ArrayValued"} cannot be combined with @qcode{"RelTol"} or 
+## @qcode{"Waypoints"}. Any @qcode{"ArrayValued"} call will simply 
 ## @end enumerate
 ##
 ## @seealso{integral2, integral3, quad, quadgk, quadv, quadl, quadcc, trapz,
@@ -107,8 +110,8 @@
 
   if (nargin == 3)
     ## Pass the simplest case directly to general integrator.
-    ## Let quadgk function handle input checks on function and limits.
-    q = quadgk (f, a, b);
+    ## Let quadcc function handle input checks on function and limits.
+    q = quadcc (f, a, b);
   else
     ## Parse options to determine how to call integrator.
     abstol = [];
@@ -137,30 +140,45 @@
       endswitch
     endwhile
 
-    if (! arrayvalued)
-      ## quadgk will accept empty values of optional parameters.
-      q = quadgk (f, a, b,
-                  "AbsTol", abstol, "RelTol", reltol, "WayPoints", waypoints);
-    else
-      ## FIXME: Replace warning with array compatible call to quadgk
+    if (arrayvalued)
+      ## pass vector valued function to quadgv, checking for conflicting params
+      
+      ## FIXME: Replace warning when have array compatible call with waypoints
       if (! isempty (waypoints))
         warning(["integral: array-valued quadrature routine currently ", ...
                  "unable to handle WayPoints.  WayPoints are ignored."]);
       endif
 
-      ## FIXME: Remove warning once we have reltol compatible arrayval'd
-      ##        quad or arrayfun call to quadgk.
+      ## FIXME: Remove warning once we have reltol compatible arrayval'd quadfn
       if (! isempty (reltol))
         warning(["integral: array-valued quadrature only accepts AbsTol.", ...
                  "  RelTol ignored."]);
       endif
-
       if (isempty (abstol))
         issingle = isa (a, "single") || isa (b, "single");
         abstol = ifelse (issingle, 1e-5, 1e-10);
       endif
 
       q = quadv (f, a, b, abstol);
+    
+    else
+      issingle = isa (a, "single") || isa (b, "single") ...
+                 || isa (waypoints, "single");
+      if (isempty (abstol))
+        abstol = ifelse (issingle, 1e-5, 1e-10);
+      endif
+
+      if (isempty (reltol))
+        reltol = ifelse (issingle, 1e-4, 1e-6);
+      endif
+
+      if (! isempty (waypoints))
+        
+        q = quadgk (f, a, b,
+                      "AbsTol", abstol, "RelTol", reltol, "WayPoints", waypoints);
+      else
+        q = quadcc (f, a, b, [abstol reltol]);
+      endif
     endif
   endif
 
