      function CAPCOR(NAT,NFIRST,NLAST,NUMAT,P,H)
      implicit double precision (A-H,O-Z)
      include 'MOP6FILE'
      dimension P(*), H(*), NFIRST(NUMAT), NLAST(NUMAT), NAT(NUMAT)
******************************************************************
*
*    CORRECTION TO ELECTRONIC ENERGY DUE TO CAPPED BONDS
*
******************************************************************
      SUM=0.D0
      do 40 I=1,NUMAT
         NI=NAT(I)
         IL=NFIRST(I)
         IU=NLAST(I)
         if (NI.EQ.102) then
C
C   do ENTIRE ROW - NO NEED TO CHECK FURTHER.
C
            J=(NLAST(I)*(NLAST(I)+1))/2
            II=IU-1
            do 10 K=1,II
               J=J-1
   10       SUM=SUM+P(J)*H(J)
         else
            do 30 J=1,I
               JL=NFIRST(J)
               if (NAT(J).EQ.102) then
                  do  20 K=IL,IU
                     KK=(K*(K-1))/2+JL
   20             SUM=SUM+P(KK)*H(KK)
               end if
   30       continue
         end if
   40 continue
C
C   DOUBLE SUM SINCE WE ONLY CALCULATED LOWER HALF, AND CAPCOR
C   WILL APPEAR IN 1/2*P(H+F).  ONLY H PART OF F WILL BE USED.
      CAPCOR=-SUM*2.D0
      return
      end
