      function DIAGI(IALPHA,IBETA,EIGA,XY,NMOS)
      implicit double precision(A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension XY(NMECI,NMECI,NMECI,NMECI), EIGA(NMECI),
     1IALPHA(NMOS), IBETA(NMOS)
************************************************************************
*
*  CALCULATES THE ENERGY OF A MICROSTATE DEFINED BY IALPHA AND IBETA
*
************************************************************************
      X=0.0D0
      do 20 I=1,NMOS
         if (IALPHA(I).NE.0) then
            X=X+EIGA(I)
            do 10  J=1,NMOS
               X=X+((XY(I,I,J,J)-XY(I,J,I,J))*IALPHA(J)*0.5D0 +
     1        (XY(I,I,J,J)            )*IBETA(J))
   10       continue
         end if
   20 continue
      do 40 I=1,NMOS
         if (IBETA(I).NE.0) then
            X=X+EIGA(I)
            do 30 J=1,I
   30       X=X+(XY(I,I,J,J)-XY(I,J,I,J))*IBETA(J)
         end if
   40 continue
      DIAGI=X
      return
      end
