      SUBROUTINE CDIAG(A,VALUE,VEC,N, NEED)
      include 'MOP6FILE'
C
C TO FIND THE EIGENVALUES AND EIGENVECTORS OF A HERMITIAN MATRIX.
      real VALUE(*),H
      complex W(6000)
      complex A(N,*),VEC(N,*)
      complex  FM06AS
      IA=N
      IV=N
C
C REDUCE MATRIX TO A TRI-DIAGONAL HERMITIAN MATRIX.
      call ME08A(A,W,W(N+1),N,IA,W(2*N+1))
C
C FIND THE EIGENVALUES AND EIGENVECTORS OF THE TRI-DIAGONAL MATRIX
      call EC08C(W,W(N+1),VALUE,VEC,N,IV,W(2*N+1))
      if (NEED.EQ.0) go to 50
      if (N.LT.2) return
C
C THE EIGENVECTORS OF THE ORIGINAL MATRIX ARE NOW FOUND BY
C BACK TRANSFORMATION USING INFORMATION STORE IN THE UPPER
C TRIANGLE OF MATRIX A (BY ME08)
      do 40 II=3,N
         I=N-II+1
         H=W(N+I+1)*CONJG(A(I,I+1))
         if (H) 10,40,10
   10    DO30L=1,N
            I1=I+1
            S=FM06AS(N-I,A(I,I+1),IA,VEC(I+1,L),1)
            S=S/H
            DO20K=I1,N
   20       VEC(K,L)=VEC(K,L)+CONJG(A(I,K))*S
   30    continue
   40 continue
   50 call SORT(VALUE,VEC,N)
      return
      end
