      SUBROUTINE MATOUT (A,B,NC,NR,NDIM)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension A(NDIM,NDIM), B(NDIM)
      common /MOLKST/ NUMAT,NAT(NUMATM),NFIRST(NUMATM),NMIDLE(NUMATM),
     1                NLAST(NUMATM), NORBS, NELECS,NALPHA,NBETA,
     2                NCLOSE,NOPEN,NDUMY,FRACT
      common /ELEMTS/ ELEMNT(107)
C**********************************************************************
C
C      MATOUT PRINTS A SQUARE MATRIX OF EIGENVECTORS AND EIGENVALUES
C
C    ON INPUT A CONTAINS THE MATRIX TO BE PRINTED.
C             B CONTAINS THE EIGENVALUES.
C             NC NUMBER OF MOLECULAR ORBITALS TO BE PRINTED.
C             NR IS THE SIZE OF THE SQUARE ARRAY TO BE PRINTED.
C             NDIM IS THE ACTUAL SIZE OF THE SQUARE ARRAY "A".
C             NFIRST AND NLAST CONTAIN ATOM ORBITAL COUNTERS.
C             NAT = ARRAY OF ATOMIC NUMBERS OF ATOMS.
C
C
C***********************************************************************
      character*2 ELEMNT, ATORBS(9), ITEXT(MAXORB), JTEXT(MAXORB)
      dimension NATOM(MAXORB)
      save ATORBS
      data ATORBS/' S','PX','PY','PZ','X2','XZ','Z2','YZ','XY'/
      if (NUMAT.EQ.0) go to 30
      if (NLAST(NUMAT).NE.NR) go to 30
      do 20 I=1,NUMAT
         JLO=NFIRST(I)
         JHI=NLAST(I)
         L=NAT(I)
         K=0
         do 10 J=JLO,JHI
            K=K+1
            ITEXT(J)=ATORBS(K)
            JTEXT(J)=ELEMNT(L)
            NATOM(J)=I
   10    continue
   20 continue
      go to 50
   30 continue
      NR=ABS(NR)
      do 40 I=1,NR
         ITEXT(I)='  '
         JTEXT(I)='  '
   40 NATOM(I)=I
   50 continue
      KA=1
      KC=6
   60 KB=MIN0(KC,NC)
      write(MIOB,100) (I,I=KA,KB)
      if (B(1).NE.0.D0) write(MIOB,110) (B(I),I=KA,KB)
      write(MIOB,120)
      LA=1
      LC=40
   70 LB=MIN0(LC,NR)
      do 80 I=LA,LB
         if (ITEXT(I).EQ.' S') write(MIOB,120)
         write(MIOB,130) ITEXT(I),JTEXT(I),NATOM(I),(A(I,J),J=KA,KB)
   80 continue
      if (LB.EQ.NR) go to 90
      LA=LC+1
      LC=LC+40
      write(MIOB,140)
      go to 70
   90 if (KB.EQ.NC) return
      KA=KC+1
      KC=KC+6
      if (NR.GT.25) write(MIOB,140)
      go to 60
C
  100 format(////,3X,9H ROOT NO.,I5,9I12)
  110 format(/8X,10F12.5)
  120 format(2H  )
  130 format(2(1X,A2),I4,F10.5,10F12.5)
  140 format(1H1)
C
      end
