      function AABBCD(IOCCA1, IOCCB1, IOCCA2, IOCCB2, NMOS)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension IOCCA1(NMOS), IOCCB1(NMOS), IOCCA2(NMOS), IOCCB2(NMOS)
***********************************************************************
*
* AABBCD EVALUATES THE C.I. MATRIX ELEMENT FOR TWO MICROSTATES DIFFERING
*       BY TWO SETS OF M.O.S. ONE MICROSTATE HAS AN ALPHA ELECTRON
*       IN PSI(I) AND A BETA ELECTRON IN PSI(K) FOR WHICH THE OTHER
*       MICROSTATE HAS AN ALPHA ELECTRON IN PSI(J) AND A BETA ELECTRON
*       IN PSI(L)
*
***********************************************************************
      common /XYIJKL/ XY(NMECI,NMECI,NMECI,NMECI)
      common /SPQR/ ISPQR(NMECI*NMECI,NMECI),IS,ILOOP, JLOOP
      do 10 I=1,NMOS
   10 if (IOCCA1(I) .NE. IOCCA2(I)) go to 20
   20 do 30 J=I+1,NMOS
   30 if (IOCCA1(J) .NE. IOCCA2(J)) go to 40
   40 do 50 K=1,NMOS
   50 if (IOCCB1(K) .NE. IOCCB2(K)) go to 60
   60 do 70 L=K+1,NMOS
   70 if (IOCCB1(L) .NE. IOCCB2(L)) go to 80
   80 if ( I.EQ.K .AND. J.EQ.L .AND. IOCCA1(I).NE.IOCCB1(I)) then
         ISPQR(ILOOP,IS)=JLOOP
         IS=IS+1
      end if
      if (IOCCA1(I) .LT. IOCCA2(I)) then
         M=I
         I=J
         J=M
      end if
      if (IOCCB1(K) .LT. IOCCB2(K)) then
         M=K
         K=L
         L=M
      end if
      XR=XY(I,J,K,L)
C#      write(MIOB,'(4I5,F12.6)') I,J,K,L,XR
C
C   NOW UNTANGLE THE MICROSTATES
C
      IJ=1
      if ( I.GT.K .AND. J.GT.L .OR. I.LE.K .AND. J.LE.L) IJ=0
      if ( I.GT.K ) IJ=IJ+IOCCA1(K)+IOCCB1(I)
      if ( J.GT.L ) IJ=IJ+IOCCA2(L)+IOCCB2(J)
      if (I.GT.K) then
         M=I
         I=K
         K=M
      end if
      do 90 M=I,K
   90 IJ=IJ+IOCCB1(M)+IOCCA1(M)
      if (J.GT.L) then
         M=J
         J=L
         L=M
      end if
      do 100 M=J,L
  100 IJ=IJ+IOCCB2(M)+IOCCA2(M)
C
C   IJ IN THE PERMUTATION NUMBER, .EQUIV. -1 IF IJ IS ODD.
C
      if (MOD(IJ,2).EQ.1) XR=-XR
      AABBCD=XR
      return
      end
