c
c
c***********************************************************************
c
      subroutine ADA ( np1, n, kg, m, mmax, npp2, iv, a, t, alf, isel,
c
     *                phinp1, nconp1 )
c
c-----------------------------------------------------------------------
c
c  evaluate the functions phi and their partial derivatives 
c  d phi(j)/d alf(k) at the sample points t(i).
c    isel=1 means compute both the functions and
c           derivatives
c    isel=2 means compute only the functions phi
c    isel=3 means compute only the derivatives
c
c-------------------------------------------------------------------------------
c
      PARAMETER ( maxn=100, maxkg=50, maxp=200 )
c
c-------------------------------------------------------------------------------
c
      real  a(mmax,npp2), alf(kg), t(mmax,iv)
c
      real  c(maxn), ndi(maxp), dph(maxn+1,maxkg)
c
      integer  inc(maxkg,maxn+1), p
c
      logical  phinp1, nc
c
      common /ncblk/ nc
      common /blkinc/ inc
      common /blkph/ ph
      common /blkndi/ ndi
      common /blkdph/ dph
      common /blockp/ p
c
      real  ph(maxn+1)
c
c--------------------------------------------------------------------------
c
      go to ( 1680 , 1690 , 1710 ) , isel
c
c  calculate function values & store them in first (n+1)
c  columns of a.
c
1680  phinp1=.true. 
      nph=np1
      nconp1=1
1690  if (.not.phinp1) nph=n
      do 1700 i=1,m 
         ii=i
c       ---------------------------------------------------
         call CALC ( ii, kg, n, mmax, iv, c, alf, t, eta )
c       ---------------------------------------------------
         do 1700 j=nconp1,nph 
            a(i,j)=ph(j)
1700  continue
      nc=.true.
      if (isel.eq.2) go to 1730
      if (kg.eq.0) go to 1730 
c
c  calculate nonvanishing partial derivatives & store them
c  in columns (n+2) through (n+p+2) of a.
c
c  check to see if any derivatives are to be calculated numerically
c
1710  do 1712 i=1,p 
         if (ndi(i).ne.0.0) goto 1715
1712  continue
c
c  all derivatives are to be calculated from closed form
c
      do 1714 k=1,m 
         kk = k
c       ----------------------------------------------
         call DERIV ( kk, t, mmax, iv, alf, kg, np1 )
c       ----------------------------------------------
         ik = np1
         do 1714 i=1,kg
            do 1714 j=1,np1
               if (inc(i,j).ne.1) goto 1714
               ik = ik+1
               a(k,ik) = dph(j,i)
1714  continue
      return
1715  continue
c
c  one or more derivatives are to be calculated numerically 
c
      ik=np1
      do 1720 i=1,kg
         ii=i
         do 1720 j=1,np1
            jj=j
            if (inc(i,j).ne.1) go to 1720
            ik=ik+1 
            in=ik-np1
            do 1719 k=1,m
               kk=k 
c             ----------------------------------------------------
               call NUMDER ( ii, jj, kk, in, n, kg, iv, mmax, t,
c
     1                       alf, a(k,ik) )
c             ----------------------------------------------------
1719        continue
1720  continue
c
1730  return
c
      end
