*DECK ALROOT
      SUBROUTINE ALROOT(A,M,ROOTS)
*
*-----------------------------------------------------------------------
*
* FIND THE ROOTS OF A POLYNOMIAL.
*
* INPUT PARAMETERS:
*  A     : POLYNOMIAL COEFFICIENTS. DIMENSION A(M+1)
*  M     : POLYNOMIAL ORDER.
*
* OUTPUT PARAMETER:
*  ROOTS : COMPLEX ROOTS. COMPLEX ROOTS(M)
*
*-----------------------------------------------------------------------
*
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      COMPLEX*16 AAA,BBB,SQ1,TEST,SQRTM3,ROTMP
      PARAMETER (SQRTM3=(0.0,1.73205080756888))
      DOUBLE PRECISION A(M+1),EPS
      PARAMETER (EPS=1.D-6,MAXM=101)
      COMPLEX*16 ROOTS(M),AD(MAXM),X,B,C
*
      IF(M+1.GT.MAXM) CALL XABORT('ALROOT: INSUFFICIENT STORAGE.')
      IF(A(M+1).EQ.0.0D0) CALL XABORT('ALROOT: INVALID COEFFICIENT.')
      IF(M.EQ.1) THEN
         ROOTS(1)=-A(1)/A(2)
      ELSE IF(M.EQ.2) THEN
         CQ=A(2)/A(3)
         DQ=A(1)/A(3)
         AAA=CQ*CQ-4.0D0*DQ
         AAA=SQRT(AAA)
         ROOTS(1)=-0.5D0*(CQ+AAA)
         ROOTS(2)=-0.5D0*(CQ-AAA)
      ELSE IF(M.EQ.3) THEN
         BQ=A(3)/A(4)
         CQ=A(2)/A(4)
         DQ=A(1)/A(4)
         AA=(3.0D0*CQ-BQ**2)/3.0D0
         BB=(2.0D0*BQ**3-9.0D0*BQ*CQ+27.0D0*DQ)/27.0D0
         SQ1=BB**2/4.0D0+AA**3/27.0D0
         TEST=BB/2.0D0-SQRT(SQ1)
         IF(DBLE(TEST).EQ.0.0) THEN
            AAA=0.0D0
         ELSE IF(DBLE(TEST).GT.0.0) THEN
            AAA=-(TEST)**(1.0D0/3.0D0)
         ELSE
            AAA=(-TEST)**(1.0D0/3.0D0)
         ENDIF
         TEST=BB/2.0D0+SQRT(SQ1)
         IF(DBLE(TEST).EQ.0.0) THEN
            BBB=0.0D0
         ELSE IF(DBLE(TEST).GT.0.0) THEN
            BBB=-(TEST)**(1.0D0/3.0D0)
         ELSE
            BBB=(-TEST)**(1.0D0/3.0D0)
         ENDIF
         ROOTS(1)=AAA+BBB-BQ/3.0D0
         ROOTS(2)=-(AAA+BBB)/2.0D0+(AAA-BBB)*SQRTM3/2.0D0-BQ/3.0D0
         ROOTS(3)=-(AAA+BBB)/2.0D0-(AAA-BBB)*SQRTM3/2.0D0-BQ/3.0D0
      ELSE IF(M.EQ.4) THEN
         AQ=A(4)/A(5)
         BQ=A(3)/A(5)
         CQ=A(2)/A(5)
         DQ=A(1)/A(5)
         BC=-BQ
         CC=AQ*CQ-4.D0*DQ
         DC=DQ*(4.D0*BQ-AQ*AQ)-CQ*CQ
         AA=(3.0D0*CC-BC**2)/3.0D0
         BB=(2.0D0*BC**3-9.0D0*BC*CC+27.0D0*DC)/27.0D0
         SQ1=BB**2/4.0D0+AA**3/27.0D0
         TEST=BB/2.0D0-SQRT(SQ1)
         IF(DBLE(TEST).EQ.0.0) THEN
            AAA=0.0D0
         ELSE IF(DBLE(TEST).GT.0.0) THEN
            AAA=-(TEST)**(1.0D0/3.0D0)
         ELSE
            AAA=(-TEST)**(1.0D0/3.0D0)
         ENDIF
         TEST=BB/2.0D0+SQRT(SQ1)
         IF(DBLE(TEST).EQ.0.0) THEN
            BBB=0.0D0
         ELSE IF(DBLE(TEST).GT.0.0) THEN
            BBB=-(TEST)**(1.0D0/3.0D0)
         ELSE
            BBB=(-TEST)**(1.0D0/3.0D0)
         ENDIF
         ROTMP=AAA+BBB-BC/3.0D0
         TEST=SQRT(0.25D0*AQ*AQ-BQ+ROTMP)
         IF(TEST.EQ.0.0D0) THEN
            SQ1=SQRT(ROTMP*ROTMP-4.0D0*DQ)
            AAA=SQRT(0.75D0*AQ*AQ-2.0D0*BQ+2.0D0*SQ1)
            BBB=SQRT(0.75D0*AQ*AQ-2.0D0*BQ-2.0D0*SQ1)
         ELSE
            SQ1=(4.0D0*AQ*BQ-8.0D0*CQ-AQ*AQ*AQ)/(4.0D0*TEST)
            AAA=SQRT(0.75D0*AQ*AQ-TEST*TEST-2.0D0*BQ+SQ1)
            BBB=SQRT(0.75D0*AQ*AQ-TEST*TEST-2.0D0*BQ-SQ1)
         ENDIF
         ROOTS(1)=-0.25D0*AQ+0.5D0*TEST+0.5D0*AAA
         ROOTS(2)=-0.25D0*AQ+0.5D0*TEST-0.5D0*AAA
         ROOTS(3)=-0.25D0*AQ-0.5D0*TEST+0.5D0*BBB
         ROOTS(4)=-0.25D0*AQ-0.5D0*TEST-0.5D0*BBB
      ELSE
         DO 10 J=1,M+1
   10    AD(J)=CMPLX(A(J),0.D0)
         DO 20 J=M,1,-1
         X=CMPLX(0.D0,0.D0)
         CALL ALGUER(AD,J,X,ITS)
         IF(ABS(DIMAG(X)).LE.2.D0*EPS**2*ABS(DBLE(X)))
     1   X=CMPLX(DBLE(X),0.D0)
         ROOTS(J)=X
         B=AD(J+1)
         DO 20 JJ=J,1,-1
         C=AD(JJ)
         AD(JJ)=B
   20    B=X*B+C
         DO 30 J=1,M+1
   30    AD(J)=CMPLX(A(J),0.D0)
         DO 40 J=1,M
         CALL ALGUER(AD,M,ROOTS(J),ITS)
   40    CONTINUE
      ENDIF
*
      DO 60 J=2,M
      X=ROOTS(J)
      DO 50 I=J-1,1,-1
      IF(DBLE(ROOTS(I)).LE.DBLE(X)) GOTO 60
   50 ROOTS(I+1)=ROOTS(I)
      I=0
   60 ROOTS(I+1)=X
      RETURN
      END
