*DECK ALDERV
      SUBROUTINE ALDERV(N,X,Y)
*
*-----------------------------------------------------------------------
*
* NUMERICAL DERIVATION OF AN ARRAY OF VALUES USING THE ORDER 4 CESCHINO
* METHOD (COMPATIBLE WITH CUBIC SPLINES).
*
* INPUT PARAMETERS:
*     N : NUMBER OF POINTS.
*     X : ABSCISSAS. DIMENSION X(N)
*     Y : ORDINATES. DIMENSION Y(N)
*
* OUTPUT PARAMETER:
*     Y : DERIVATIVES. DIMENSION Y(N)
*
*------------------------------------------ AUTHOR: A. HEBERT ; 1981 ---
*
      INTEGER N
      REAL X(N),Y(N)
      REAL, DIMENSION(:,:), ALLOCATABLE ::WK
*
      IF(N.LE.1) CALL XABORT('ALDERV: INVALID NUMBER OF POINTS.')
      IF(N.EQ.2) GO TO 40
      ALLOCATE(WK(2,N))
      HP=1.0/(X(2)-X(1))
      WK(1,1)=HP
      WK(2,1)=HP
      YLAST=Y(1)
      Y(1)=2.0*HP*HP*(Y(2)-Y(1))
      DO 10 I=2,N-1
      HM=HP
      HP=1.0/(X(I+1)-X(I))
      WK(1,I)=2.0*(HM+HP)
      WK(2,I)=HP
      PMX=3.0*(HM*HM*(Y(I)-YLAST)+HP*HP*(Y(I+1)-Y(I)))
      YLAST=Y(I)
   10 Y(I)=PMX
      HM=HP
      WK(1,N)=HM
      WK(2,N)=HM
      Y(N)=2.0*HM*HM*(Y(N)-YLAST)
*
* FORWARD ELIMINATION.
      PMX=WK(1,1)
      Y(1)=Y(1)/PMX
      DO 20 I=2,N
      GAR=WK(2,I-1)
      WK(2,I-1)=WK(2,I-1)/PMX
      PMX=WK(1,I)-GAR*WK(2,I-1)
   20 Y(I)=(Y(I)-GAR*Y(I-1))/PMX
*
* BACK SUBSTITUTION.
      DO 30 I=N-1,1,-1
   30 Y(I)=Y(I)-WK(2,I)*Y(I+1)
      DEALLOCATE(WK)
      RETURN
*
   40 Y(1)=(Y(2)-Y(1))/(X(2)-X(1))
      Y(2)=Y(1)
      RETURN
      END
