c
c 
c***********************************************************************
c
      subroutine NUMDER ( i, j, k, in, n, kg, iv, mmax, t, alf, dv )
c
c------------------------------------------------------------------------
c
c  given an array of numerical derivative increments,
c  calculate derivates numerically if increment is not zero,
c  use closed form in subroutine deriv if increment is zero.
c
c
      PARAMETER ( maxn=100, maxkg=50, maxp=200 ) 
c
      real  t(mmax,iv), alf(kg), ndi(maxp) 
c
      logical nc
c
      common /ncblk/ nc
      common /blkndi/ ndi
      common /blkdph/ dph
c
      real  dph(maxn+1,maxkg), cc(maxn)
c
c----------------------------------------------------------------------
c
      dk=ndi(in)
      if (dk.eq.0.) go to 1750
c
c  derivative to be calculated numerically using forward
c  difference quotient.
c
      np1=n+1
      do 1740 jj=1,n
1740     cc(jj)=0.
      if (j.ne.np1) cc(j)=1.
      nc=.false.
c    --------------------------------------------------
      call CALC ( k, kg, n, mmax, iv, cc, alf, t, yc )
c    --------------------------------------------------
      asave=alf(i)
      alf(i)=asave+dk
c    --------------------------------------------------
      call CALC ( k, kg, n, mmax, iv, cc, alf, t, yd )
c    --------------------------------------------------
      nc=.true.
      dv=(yd-yc)/dk 
      alf(i)=asave
      return
c
c  derivative to be calculated from closed form in
c  subroutine deriv.
c
c    ---------------------------------------------
1750  call DERIV ( k, t, mmax, iv, alf, kg, np1 )
c    ---------------------------------------------
c
      dv=dph(j,i)
c
      return
c
      end 
