gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
interv.f
Go to the documentation of this file.
1  subroutine interv ( xt, lxt, x, left, mflag )
2 
3 c*********************************************************************72
4 c
5 cc INTERV brackets a real value in an ascending vector of values.
6 c
7 c from * a practical guide to splines * by C. de Boor
8 computes left = max( i : xt(i) .lt. xt(lxt) .and. xt(i) .le. x ) .
9 c
10 c****** i n p u t ******
11 c xt.....a real sequence, of length lxt , assumed to be nondecreasing
12 c lxt.....number of terms in the sequence xt .
13 c x.....the point whose location with respect to the sequence xt is
14 c to be determined.
15 c
16 c****** o u t p u t ******
17 c left, mflag.....both integers, whose value is
18 c
19 c 1 -1 if x .lt. xt(1)
20 c i 0 if xt(i) .le. x .lt. xt(i+1)
21 c i 0 if xt(i) .lt. x .eq. xt(i+1) .eq. xt(lxt)
22 c i 1 if xt(i) .lt. xt(i+1) .eq. xt(lxt) .lt. x
23 c
24 c In particular, mflag = 0 is the 'usual' case. mflag .ne. 0
25 c indicates that x lies outside the CLOSED interval
26 c xt(1) .le. y .le. xt(lxt) . The asymmetric treatment of the
27 c intervals is due to the decision to make all pp functions cont-
28 c inuous from the right, but, by returning mflag = 0 even if
29 C x = xt(lxt), there is the option of having the computed pp function
30 c continuous from the left at xt(lxt) .
31 c
32 c****** m e t h o d ******
33 c The program is designed to be efficient in the common situation that
34 c it is called repeatedly, with x taken from an increasing or decrea-
35 c sing sequence. This will happen, e.g., when a pp function is to be
36 c graphed. The first guess for left is therefore taken to be the val-
37 c ue returned at the previous call and stored in the l o c a l varia-
38 c ble ilo . A first check ascertains that ilo .lt. lxt (this is nec-
39 c essary since the present call may have nothing to do with the previ-
40 c ous call). Then, if xt(ilo) .le. x .lt. xt(ilo+1), we set left =
41 c ilo and are done after just three comparisons.
42 c Otherwise, we repeatedly double the difference istep = ihi - ilo
43 c while also moving ilo and ihi in the direction of x , until
44 c xt(ilo) .le. x .lt. xt(ihi) ,
45 c after which we use bisection to get, in addition, ilo+1 = ihi .
46 c left = ilo is then returned.
47 c
48  implicit none
49 
50  integer left,lxt,mflag, ihi,ilo,istep,middle
51  double precision x,xt(lxt)
52  data ilo /1/
53  save ilo
54  ihi = ilo + 1
55  if (ihi .lt. lxt) go to 20
56  if (x .ge. xt(lxt)) go to 110
57  if (lxt .le. 1) go to 90
58  ilo = lxt - 1
59  ihi = lxt
60 c
61  20 if (x .ge. xt(ihi)) go to 40
62  if (x .ge. xt(ilo)) go to 100
63 c
64 c **** now x .lt. xt(ilo) . decrease ilo to capture x .
65  istep = 1
66  31 ihi = ilo
67  ilo = ihi - istep
68  if (ilo .le. 1) go to 35
69  if (x .ge. xt(ilo)) go to 50
70  istep = istep*2
71  go to 31
72  35 ilo = 1
73  if (x .lt. xt(1)) go to 90
74  go to 50
75 c **** now x .ge. xt(ihi) . increase ihi to capture x .
76  40 istep = 1
77  41 ilo = ihi
78  ihi = ilo + istep
79  if (ihi .ge. lxt) go to 45
80  if (x .lt. xt(ihi)) go to 50
81  istep = istep*2
82  go to 41
83  45 if (x .ge. xt(lxt)) go to 110
84  ihi = lxt
85 c
86 c **** now xt(ilo) .le. x .lt. xt(ihi) . narrow the interval.
87  50 middle = (ilo + ihi)/2
88  if (middle .eq. ilo) go to 100
89 c note. it is assumed that middle = ilo in case ihi = ilo+1 .
90  if (x .lt. xt(middle)) go to 53
91  ilo = middle
92  go to 50
93  53 ihi = middle
94  go to 50
95 c**** set output and return.
96  90 mflag = -1
97  left = 1
98  return
99  100 mflag = 0
100  left = ilo
101  return
102  110 mflag = 1
103  if (x .eq. xt(lxt)) mflag = 0
104  left = lxt
105  111 if (left .eq. 1) return
106  left = left - 1
107  if (xt(left) .lt. xt(lxt)) return
108  go to 111
109  end
subroutine interv(xt, lxt, x, left, mflag)
Definition: interv.f:2
gtkIOStream: /tmp/gtkiostream/src/deBoor/interv.f Source File
GTK+ IOStream  Beta