        SUBROUTINE HTWD(IZ,SMM,SWW,IN,RKK,KDIM)

        INTEGER    KDIM,N

        PARAMETER  (N=10)

        REAL*8     SMX,RHE,RKK
        REAL*8     SMM(N),SWW(N)
        INTEGER    IZ(KDIM,KDIM),I1,I2,IN

        if (IN.gt.N) STOP 'HTWD: N'

        SMX=0.D0
        DO 119 I1=1,KDIM
        DO 119 I2=1,KDIM
        RHE=IZ(I1,I2)
        SMX=SMX+RHE
        SMM(IN)=SMM(IN)+RHE*RKK
        SWW(IN)=SWW(IN)+RHE**2*RKK
119     CONTINUE
        SMX=SMX*RKK
        SWW(IN)=SWW(IN)-SMX**2

        RETURN
        END       
