      SUBROUTINE XDXDCL(XDXD,ZLK,K,M)
C
C     'XDXDCL' CALCULATES THE SQUARES OF THE RELATIVE VELOCITIES OF
C     AN ELEMENT IN THE ELEMENT FRAME.
C
      IMPLICIT REAL*8 (A-H,O-Z)
      INTEGER*4 P,Q,R
C
      COMMON/COMALP/ SZ02(10),SZ03(10),SZ04(10),SZ12(3,10),SZ13(3,10),
     .               SZ14(3,10),SZ15(3,10),SZ16(3,10),SZ21(9,10),
     .               SZ22(9,10),SZ23(9,10),SZ25(9,10),
     .               SZ26(9,10),SZ27(9,10),SZ28(9,10),SZ31(27,10),
     .               SZ32(27,10),SZ33(27,10),SZ34(27,10),SZ35(27,10),
     .               SZ41(81,10),SZ42(81,10),SZ43(81,10)
C
      COMMON/DEBUG3/ISWTCH
C
      COMMON/IPOOL1/ IGRAV,IDAMP,IK,K1,ITIM,IAB,IAPS,IBB,IBPS,NK(10),
     .               LK(10),LLK(10)
C
C
      DIMENSION XDXD(3,3),ZLK(10)
C
C
      IF(ISWTCH.EQ.0) WRITE(6,20002) K,M
      SUM7=0.0D0
      SUM8=0.0D0
      SUM11=0.0D0
      SUM12=0.0D0
C
      DO 40 N=1,M
      SUM5=0.0D0
      SUM6=0.0D0
      SUM9=0.0D0
      SUM10=0.0D0
C
      DO 30 P=1,M
      SUM3=0.0D0
      SUM4=0.0D0
C
      DO 20 Q=1,M
      SUM1=0.0D0
      SUM2=0.0D0
C
      DO 10 R=1,M
      A1=FUNA(K,K1,R)
      B1=FUNB(K,K1,R)
      IR=27*(N-1)+9*(P-1)+3*(Q-1)+R
      SUM1=SUM1+B1*SZ41(IR,K)
   10 SUM2=SUM2+A1*SZ41(IR,K)
C
      AD1=ADFUN(K,K1,Q)
      BD1=BDFUN(K,K1,Q)
      SUM3=SUM3 + BD1*SUM1
   20 SUM4=SUM4 + AD1*SUM2
C
      A1=FUNA(K,K1,P)
      B1=FUNB(K,K1,P)
      AD1=ADFUN(K,K1,P)
      BD1=BDFUN(K,K1,P)
      IP=3*(N-1)+P
C
      SUM5=SUM5 + A1*(SUM3 + SUM4)
      SUM6=SUM6 + B1*(SUM3 + SUM4)
      SUM9=SUM9+AD1*SZ21(IP,K)
   30 SUM10=SUM10+BD1*SZ21(IP,K)
C
      AD1=ADFUN(K,K1,N)
      BD1=BDFUN(K,K1,N)
C
      SUM7=SUM7  + AD1*SUM5
      SUM8=SUM8  + BD1*SUM6
      SUM11=SUM11 + AD1*SUM9
   40 SUM12=SUM12 + BD1*SUM10
C
      XDXD(1,1)=(SUM7 + SUM8)/(ZLK(K)*ZLK(K))
      XDXD(2,2)=SUM11
      XDXD(3,3)=SUM12
C
      IF(ISWTCH.EQ.0) WRITE(6,10000) ((XDXD(I,J),J=1,3),I=1,3)
C
      RETURN
C
10000 FORMAT('0XDX(K,I,J)',//3G15.5)
20002 FORMAT('0',5X,'XDXDCL ',2I4)
20010 FORMAT('0',2X,'J2 = SUM OF ZZT1')
C
      END
