c
c
c***********************************************************************
c
      subroutine COV ( mmax, npkg, sigma2, a )
c
c-----------------------------------------------------------------------
c
c        compute the unscaled covariance matrix of the
c     n + kg parameters.  this involves computing 
c
c                       2     -1    -t
c                  sigma  *  t   * t
c
c     where the (n+kg) x (n+kg) upper triangular matrix t
c     is described in subroutine postpr.  the result
c     overwrites the first n+kg rows and columns of the
c     matrix a.  the resulting matrix is symmetric.
c
c        reference:  lawson and hanson, solving least
c     squares problems, prentice-hall, 1974, pp. 67-
c     70, 281.
c
c  ......................................................
c
      real a(mmax,npkg)
c
      do 1470 j=1,npkg
1470     a(j,j)=1./a(j,j)
c
c              invert t upon itself
c
      if (npkg.eq.1) go to 1500
      nm1=npkg-1
      do 1490 i=1,nm1
         ip1=i+1
         do 1490 j=ip1,npkg
            jm1=j-1 
            sum=0.
            do 1480 l=i,jm1
1480           sum=sum+a(i,l)*a(l,j)
1490        a(i,j)=-sum*a(j,j)
c
c              now form the matrix product
c
1500  do 1520 i=1,npkg
         do 1520 j=i,npkg
            sum=0.
            do 1510 l=j,npkg
1510           sum=sum+a(i,l)*a(j,l)
            sum=sum*sigma2
            a(i,j)=sum
1520        a(j,i)=sum
c
      return
c
      end 
