C Library Functions  - interv (3)

from * a practical guide to splines * by C. de Boor
computes
  left = max( i : xt(i) .lt. xt(lxt) .and. xt(i) .le. x ) .
****** i n p u t ******
xt.....a real sequence, of length
  lxt , assumed to be nondecreasing
lxt.....number of terms in the sequence
  xt .
x.....the point whose location with respect to the sequence
  xt is to be determined.
****** o u t p u t ****** left, mflag.....both integers, whose value is
1 -1 if x .lt. xt(1)
i 0 if xt(i) .le. x .lt. xt(i+1)
i 0 if xt(i) .lt. x .eq. xt(i+1) .eq. xt(lxt)
i 1 if xt(i) .lt. xt(i+1) .eq. xt(lxt) .lt. x
        In particular,  mflag = 0  is the ’usual’ case.  mflag .ne. 0
        indicates that  x  lies outside the CLOSED interval
        xt(1) .le. y .le. xt(lxt) . The asymmetric treatment of the
        intervals is due to the decision to make all pp functions cont-
        inuous from the right, but, by returning  mflag = 0  even if
        x = xt(lxt), there is the option of having the computed pp function
        continuous from the left at  xt(lxt) .

****** m e t h o d ****** The program is designed to be efficient in the common situation that
it is called repeatedly, with
  x taken from an increasing or decrea- sing sequence. This will happen, e.g., when a pp function is to be
graphed. The first guess for
  left is therefore taken to be the val-
ue returned at the previous call and stored in the
  l o c a l varia-
ble ilo . A first check ascertains that ilo .lt. lxt (this is nec- essary since the present call may have nothing to do with the previ-
ous call). Then, if
  xt(ilo) .le. x .lt. xt(ilo+1), we set left =
ilo and are done after just three comparisons.
Otherwise, we repeatedly double the difference
  istep = ihi - ilo
while also moving
  ilo and ihi in the direction of x , until xt(ilo) .le. x .lt. xt(ihi) , after which we use bisection to get, in addition, ilo+1 = ihi .
left = ilo
  is then returned.


Nemo Release 3.1 interv (3) June 29, 2025
Generated by manServer 1.08 from 4369f5b6-55f3-40e3-84a9-5dea3c899e82 using man macros.