# HG changeset patch
# User Michael Godfrey <michaeldgodfrey@gmail.com>
# Date 1345426737 14400
# Node ID 662bf9f53ef0cc1c3706c8a0b997c3491c55f3ea
# Parent  aa7f4e33c524ececa1dbdd104bfc0ab4628158ef
update for non-distinct pairs

diff -r aa7f4e33c524 -r 662bf9f53ef0 scripts/general/interp1.m
--- a/scripts/general/interp1.m	Sun Aug 19 15:16:42 2012 -0400
+++ b/scripts/general/interp1.m	Sun Aug 19 21:38:57 2012 -0400
@@ -26,9 +26,9 @@
 ##
 ## One-dimensional interpolation.  Interpolate @var{y}, defined at the
 ## points @var{x}, at the points @var{xi}.  The sample points @var{x}
-## must be monotonic.  If not specified, @var{x} is taken to be the
-## indices of @var{y}.  If @var{y} is an array, treat the columns
-## of @var{y} separately.
+## must be distinct except for a pair as described below.  If not specified,
+## @var{x} is taken to be the indices of @var{y}.  If @var{y} is an array,
+## treat the columns of @var{y} separately.
 ##
 ## Method is one of:
 ##
@@ -71,7 +71,7 @@
 ## The discontinuous interpolant is right-continuous if @var{x} is increasing,
 ## left-continuous if it is decreasing.
 ## Discontinuities are (currently) only allowed for "nearest" and "linear"
-## methods; in all other cases, @var{x} must be strictly monotonic.
+## methods; in all other cases, the @var{x} values must be distinct.
 ##
 ## An example of the use of @code{interp1} is
 ##
@@ -168,10 +168,26 @@
     y = y(p,:);
   endif
 
- ## check whether sample point @var{x} are distinct; give error if not.
-  if (any (diff (x) == 0))
-    error ("interp1: X should have distinct values");
-  endif
+ ## check whether sample points @var{x} are distinct; give warning if not.
+ if (any ((diff (x(1:(end-1))) == 0) & (diff (x(2:end)) == 0)))
+     warning ("interp1: X should have distinct values");
+   endif
+
+#   if (any (diff (x) == 0))
+#    warning ("interp1: For compatibility X should have distinct values");
+#  endif
+
+ ## test for x is distinct except for one pair
+  ds = 2;
+  xd = max(size(x));
+  while (ds < xd)
+    if (all(x(ds+1:xd) - x(ds-1)) == 0)
+      if (x(ds+1) == x(ds))
+        error ("interp1: Only one pair of non-distinct X values is allowed");
+      endif 
+    endif
+    ds++;
+  endwhile
 
   starmethod = method(1) == "*";
 
# HG changeset patch
# User Michael Godfrey <michaeldgodfrey@gmail.com>
# Date 1345426737 14400
# Node ID 662bf9f53ef0cc1c3706c8a0b997c3491c55f3ea
# Parent  aa7f4e33c524ececa1dbdd104bfc0ab4628158ef
update for non-distinct pairs

diff -r aa7f4e33c524 -r 662bf9f53ef0 scripts/general/interp1.m
--- a/scripts/general/interp1.m	Sun Aug 19 15:16:42 2012 -0400
+++ b/scripts/general/interp1.m	Sun Aug 19 21:38:57 2012 -0400
@@ -26,9 +26,9 @@
 ##
 ## One-dimensional interpolation.  Interpolate @var{y}, defined at the
 ## points @var{x}, at the points @var{xi}.  The sample points @var{x}
-## must be monotonic.  If not specified, @var{x} is taken to be the
-## indices of @var{y}.  If @var{y} is an array, treat the columns
-## of @var{y} separately.
+## must be distinct except for a pair as described below.  If not specified,
+## @var{x} is taken to be the indices of @var{y}.  If @var{y} is an array,
+## treat the columns of @var{y} separately.
 ##
 ## Method is one of:
 ##
@@ -71,7 +71,7 @@
 ## The discontinuous interpolant is right-continuous if @var{x} is increasing,
 ## left-continuous if it is decreasing.
 ## Discontinuities are (currently) only allowed for "nearest" and "linear"
-## methods; in all other cases, @var{x} must be strictly monotonic.
+## methods; in all other cases, the @var{x} values must be distinct.
 ##
 ## An example of the use of @code{interp1} is
 ##
@@ -168,10 +168,26 @@
     y = y(p,:);
   endif
 
- ## check whether sample point @var{x} are distinct; give error if not.
-  if (any (diff (x) == 0))
-    error ("interp1: X should have distinct values");
-  endif
+ ## check whether sample points @var{x} are distinct; give warning if not.
+ if (any ((diff (x(1:(end-1))) == 0) & (diff (x(2:end)) == 0)))
+     warning ("interp1: X should have distinct values");
+   endif
+
+#   if (any (diff (x) == 0))
+#    warning ("interp1: For compatibility X should have distinct values");
+#  endif
+
+ ## test for x is distinct except for one pair
+  ds = 2;
+  xd = max(size(x));
+  while (ds < xd)
+    if (all(x(ds+1:xd) - x(ds-1)) == 0)
+      if (x(ds+1) == x(ds))
+        error ("interp1: Only one pair of non-distinct X values is allowed");
+      endif 
+    endif
+    ds++;
+  endwhile
 
   starmethod = method(1) == "*";
 
