      program test
      implicit double precision (a-h,o-z)
      dimension tau(20),t(60),alpha(20),biatx_ref(10),
     +          biatx_in(10)
      dimension scratch(20,20),biatx_glo_ref(20),biatx_glo_in(20)
      character*1 home(4)
      data tau /4*0.d0,1.d0,2.d0,3.d0,4*4.d0,9*0.d0/
      data t   /4*0.d0,2*1.d0,2*2.d0,2*3.d0,4*4.d0,46*0.d0/
      data in_knots /11/
      data iref_knots /14/
      data k /4/
      data npoint /10/
c     vio_data (CLS, Cursor home)
c
c     HOME = ANSI ESC. SEQUENCE: CURSOR HOME,CLS
      data home/27,91,50,74/
c
      write(*,*) ' Initial number of knots: (11)'
      read(*,*) in_knots
      write(*,*) ' Initial knots (0,0,0,0,1,2,3,4,4,4,4):'
      read(*,*) (tau(i),i=1,in_knots)
      write(*,*) ' Refined number of knots: (14)'
      read(*,*) iref_knots
      write(*,*) ' Refined knots:(0,0,0,0,1,1,2,2,3,3,4,4,4,4)'
      read(*,*) (t(i),i=1,iref_knots)
      write(*,10) in_knots,iref_knots
10    format(' number of knots:'/2x,' initial:',i5/2x,' refined:',i5//)
      write(*,*) ' order of the spline space (4):'
      read(*,*) k
      write(*,*) home
c
c     calculating all nontrivial discrete B-splines
c
      do, jot=1,20
          do, ka=1,20
              scratch(ka,jot)=0.d0
          enddo
      enddo
      do, j=1,iref_knots-k
          call interv(tau,in_knots,t(j),lleft,mflag)
          call knotins(tau,t,k,j,lleft,alpha)
          do, jot=1,k
              scratch(j,jot+lleft-k)=alpha(jot)
          enddo
      enddo
      write(*,*) ' DISCRETE B-SPLINES MATRIX'
      do, ka=1,10
          write(*,'(10(f7.3,1x))' ) (scratch(ka,jot),jot=1,10)
      enddo
      pause ' <ENTER> to continue'
      write(*,*) home
      write(*,*) ' CHECKING THE KNOT INSERTION ALGORITHM'
      write(*,*) ' number of points to test: (10)'
      read(*,*) npoint
      dx=(tau(in_knots)-tau(1))/dble(npoint-1)
      do , ii=0,npoint-2
      x=tau(1)+dble(ii)*dx
c
c     calculating all nontrivial B-splines on refined mesh for given x
c
      call interv(t,iref_knots,x,left,mflag)
      call bsplvb(t,k,1,x,left,biatx_ref)
      do, ka=1,k+iref_knots-k
            biatx_glo_ref(ka)=0.d0
      enddo
      do, jot=1,k
            biatx_glo_ref(jot+left-k)=biatx_ref(jot)
      enddo
      write(*,*) ' All B-splines on a refined mesh at x=',x
      write(*,'(10(f7.3),1x)') (biatx_glo_ref(i),i=1,10)
c
c     calculating all nontrivial B-splines on initial mesh for given x
c
      call interv(tau,in_knots,x,left,mflag)
      call bsplvb(tau,k,1,x,left,biatx_in)
      do, ka=1,k+in_knots-k
            biatx_glo_in(ka)=0.d0
      enddo
      do, jot=1,k
            biatx_glo_in(jot+left-k)=biatx_in(jot)
      enddo
      write(*,*) ' All B-splines on initial mesh at x=',x
      write(*,'(10(f7.3),1x)') (biatx_glo_in(i),i=1,10)
      write(*,20)
20    format(' B-spl., via deBoor-Cox | B-spl. via knot insertion'/
     +        51('=')/)
      do, i=1,in_knots-k
         suma=0.d0
         do, jot=1,iref_knots-k
            suma=suma+scratch(jot,i)*biatx_glo_ref(jot)
         enddo
         write(*,30) biatx_glo_in(i),suma
30       format(1x,d21.15,2x,'|',d21.15)
      enddo
      enddo
      end
