      SUBROUTINE Energy_GEDIIS(MRESET,MSET,ci,GeomSet,GradSet,ESET,NCoord,ER_star)
      IMPLICIT NONE
      integer, parameter :: KINT = kind(1)
      integer, parameter :: KREAL = kind(1.0d0)


	  INTEGER(KINT) :: MRESET, MSET, NCoord
	  REAL(KREAL) :: ci(MRESET), GeomSet(MRESET*NCoord), GradSet(MRESET*NCoord), ESET(MRESET)
	  REAL(KREAL) :: ER_star, tmp
	  
	  INTEGER(KINT) :: I, J, IX, JX, INV, JNV, KX
	  
	  LOGICAL PRINT
	  
      PRINT=.FALSE.
	  
      IF (PRINT)  WRITE(*,'(/,''      BEGIN Energy_GEDIIS   '')')
	  
      ER_star=0.D0
      INV=-NCoord
      DO IX=1,MSET
         INV=INV+NCoord
         JNV=-NCoord
         DO JX=1,MSET
            JNV=JNV+NCoord
            tmp=0.D0
	        DO KX=1, NCoord
	           tmp = tmp + (((GradSet(INV+KX)-GradSet(JNV+KX))*(GeomSet(INV+KX)-GeomSet(JNV+KX)))/2.D0)
	        END DO
			ER_star = ER_star + ci(IX)*ci(JX)*tmp
         END DO
      END DO

	  DO I=1, MSET
	     ER_star = ER_star + (ci(I)*ESET(I))		
	  END DO

      IF (PRINT)  WRITE(*,'(/,''       END Energy_GEDIIS  '',/)')

      END SUBROUTINE Energy_GEDIIS
