      subroutine dcsevu (x, y, nx, sc, ic, u, ds, m1, dds, m2, ierr)
C*******************************************************************************
C*                                                                             *
C*    ROUTINE NAME:  DCSEVU                                                    *
C*                                                                             *
C*    PURPOSE:  computes first and second derivitives for a bicubic spline     *
C*                                                                             *
C*    AUTHOR:   Steve Reid - 26 August 1999                                    *
C*              S & E Computing                                                *
C*                                                                             *
C*    INPUTS:   x   - vector of length nx                                      *
C*              y   - vector of length nx                                      *
C*              nx  - number of elements in vectors x and y, where nx >= 2     *
C*              sc  - spline coefficient array dimensioned (nx - 1, 3)=(ic, 3) *
C*              ic  - row dimension of sc array as dimensioned in the calling  *
C*                    program                                                  *
C*              u   - vector of length max (m1, m2) containing abcissae of the *
C*                    points at which the first and/or second derivitives of   *
C*                    the cubic spline is to be evaluated                      *
C*              m1  - number of elements in vector ds                          *
C*              m2  - number of elements in vector dds                         *
C*                                                                             *
C*    OUTPUTS:  ds   - vector of length m1, containing the first derivitive    *
C*                     of the spline approximation at each u(i)                *
C*              dds  - vector of length m2, containing the second derivitive   *
C*                     of the spline approximation at each u(i)                *
C*              ierr - error code (point out of bounds warnings)               *
C*                       33 = u(i) < x(1)                                      *
C*                       34 = u(i) > x(nx)                                     *
C*                                                                             *
C*    ROUTINE CALLED:  uertst                                                  *
C*                                                                             *
C*    LIMITATIONS:  The elements of input vectors x and y are assumed to be    *
C*                  pre-sorted into ascending order.  The input ic must be     *
C*                  greater than or equal to nx.                               *
C*                                                                             *
C*******************************************************************************
      implicit none
      integer i, ic, ierr, j, m1, m2, mmax, nx 
      real*8 d, dds(m2), ds(m1), sc(ic, 3), u(m1), x(nx), y(nx)
      character*6 isub /'dcsevu'/
c
c--Validate that the desired points are within range.
c
      ierr = 0
      i    = 1
      dowhile (ierr .eq. 0 .and. i .le. m1)
         if (u(i) .lt. x(1)) then
            ierr = 33
         elseif (u(i) .gt. x(nx)) then
            ierr = 34
         else
            i = i + 1
         endif
      enddo
      if (ierr .ne. 0) go to 9000
      mmax = max (m1, m2)
      do i = 1, mmax
c
c--find j such that x(j) <= u(i) < x(j + 1).
c
         j = 1
         dowhile (j .lt. nx .and. u(i) .gt. x(j + 1))
            j = j + 1
         enddo
         if (u(i) .gt. x(nx - 1)) then
            j = nx - 1
         endif
         d = u(i) - x(j)     ! offset from lower boundary
c
c--Compute the first derivitive.
c
         if (i .le. m1) then
            ds(i) = (3.0 * sc(j, 3) * d + 2.0 * sc(j, 2)) * d
     &              + sc(j, 1)
         endif
c
c--Compute the second derivitive.
c
         if (i .le. m2) then
            dds(i) = 6.0 * sc(j, 3) * d + 2.0 * sc(j, 2)
         endif
      enddo
      go to 9990
c
c--Error exit.
c
 9000 continue
      call uertst (ierr, isub)
c
c--Normal exit.
c
 9990 continue
      return
      end
