1      subroutine fpched(x,m,t,n,k,ib,ie,ier)
2c  subroutine fpched verifies the number and the position of the knots
3c  t(j),j=1,2,...,n of a spline of degree k,with ib derative constraints
4c  at x(1) and ie constraints at x(m), in relation to the number and
5c  the position of the data points x(i),i=1,2,...,m. if all of the
6c  following conditions are fulfilled, the error parameter ier is set
7c  to zero. if one of the conditions is violated ier is set to ten.
8c      1) k+1 <= n-k-1 <= m + max(0,ib-1) + max(0,ie-1)
9c      2) t(1) <= t(2) <= ... <= t(k+1)
10c         t(n-k) <= t(n-k+1) <= ... <= t(n)
11c      3) t(k+1) < t(k+2) < ... < t(n-k)
12c      4) t(k+1) <= x(i) <= t(n-k)
13c      5) the conditions specified by schoenberg and whitney must hold
14c         for at least one subset of data points, i.e. there must be a
15c         subset of data points y(j) such that
16c             t(j) < y(j) < t(j+k+1), j=1+ib1,2+ib1,...,n-k-1-ie1
17c               with ib1 = max(0,ib-1), ie1 = max(0,ie-1)
18c  ..
19c  ..scalar arguments..
20      integer m,n,k,ib,ie,ier
21c  ..array arguments..
22      real*8 x(m),t(n)
23c  ..local scalars..
24      integer i,ib1,ie1,j,jj,k1,k2,l,nk1,nk2,nk3
25      real*8 tj,tl
26c  ..
27      k1 = k+1
28      k2 = k1+1
29      nk1 = n-k1
30      nk2 = nk1+1
31      ib1 = ib-1
32      if(ib1.lt.0) ib1 = 0
33      ie1 = ie-1
34      if(ie1.lt.0) ie1 = 0
35      ier = 10
36c  check condition no 1
37      if(nk1.lt.k1 .or. nk1.gt.(m+ib1+ie1)) go to 80
38c  check condition no 2
39      j = n
40      do 20 i=1,k
41        if(t(i).gt.t(i+1)) go to 80
42        if(t(j).lt.t(j-1)) go to 80
43        j = j-1
44  20  continue
45c  check condition no 3
46      do 30 i=k2,nk2
47        if(t(i).le.t(i-1)) go to 80
48  30  continue
49c  check condition no 4
50      if(x(1).lt.t(k1) .or. x(m).gt.t(nk2)) go to 80
51c  check condition no 5
52      if(x(1).ge.t(k2) .or. x(m).le.t(nk1)) go to 80
53      i = 1
54      jj = 2+ib1
55      l = jj+k
56      nk3 = nk1-1-ie1
57      if(nk3.lt.jj) go to 70
58      do 60 j=jj,nk3
59        tj = t(j)
60        l = l+1
61        tl = t(l)
62  40    i = i+1
63        if(i.ge.m) go to 80
64        if(x(i).le.tj) go to 40
65        if(x(i).ge.tl) go to 80
66  60  continue
67  70  ier = 0
68  80  return
69      end
70