      SUBROUTINE COVLGH(SN,SE,SU,ISN,JSN,B,I,G,NR,NC,LENG)

*** CONVERT COVARIANCE MATRIX TO LGH

      IMPLICIT DOUBLE PRECISION (A-H, O-Z)
      IMPLICIT INTEGER (I-N)
      DIMENSION B(*)
      DIMENSION SXYZ(3,3),SNEU(3,3)
      DIMENSION RM(3,3),W(3)
      DIMENSION G(NR,NC)
      SAVE GLA1, GLO1, GLA2, GLO2
      SAVE SB, CB, SL, CL
      SAVE ISNX, JSNX
      DATA ISNX /0/, JSNX /0/

      IF (ISN .NE. ISNX  .OR.  JSN .NE. JSNX) THEN
        IF (ISN .NE. ISNX) THEN
          CALL GETGLA (GLA1, ISN, B)
          CALL GETGLO (GLO1, ISN, B)
          ISNX = ISN
        ENDIF
        IF (JSN .NE. JSNX) THEN
          CALL GETGLA (GLA2, JSN, B)
          CALL GETGLO (GLO2, JSN, B)
          JSNX = JSN
        ENDIF

*** COMPUTE MEAN ORIENTATION

        GLA = (GLA1 + GLA2)/2.D0
        GLO = (GLO1 + GLO2)/2.D0

        SB = DSIN(GLA)
        CB = DCOS(GLA)
        SL = DSIN(GLO)
        CL = DCOS(GLO)
      ENDIF

*** GET COVARIANCE MATRIX

      NVEC=NR/3
      CALL GLOCAT(N1,N2,N3,N4,N5,NVEC,LENG)

      SX=G(I-2,N5)
      SY=G(I-1,N5)
      SZ=G(I,N5)
      RHOXY=G(I-2,N5+1)
      RHOYZ=G(I-1,N5+1)
      RHOXZ=G(I,N5+1)
      SXYZ(1,1)=SX*SX
      SXYZ(1,2)=SX*SY*RHOXY
      SXYZ(1,3)=SX*SZ*RHOXZ
      SXYZ(2,1)=SXYZ(1,2)
      SXYZ(2,2)=SY*SY
      SXYZ(2,3)=SY*SZ*RHOYZ
      SXYZ(3,1)=SXYZ(1,3)
      SXYZ(3,2)=SXYZ(2,3)
      SXYZ(3,3)=SZ*SZ

*** PUT TOGETHER ROTATION MATRIX --- CMP

      RM(1,1)=-SB*CL
      RM(2,1)=-SL
      RM(3,1)=CB*CL
      RM(1,2)=-SB*SL
      RM(2,2)=CL
      RM(3,2)=CB*SL
      RM(1,3)=CB
      RM(2,3)=0
      RM(3,3)=SB

*** USE THE SUBROUTINE TO DO THE TRANSFORMATION

      N=3
      CALL ABAT(RM,SXYZ,SNEU,W,N,N)

*** CALCULATE THE RESIDUALS

      SN=DSQRT(SNEU(1,1))
      SE=DSQRT(SNEU(2,2))
      SU=DSQRT(SNEU(3,3))

      RETURN
      END
