      SUBROUTINE STRERR (A,NX,SIGUWT)

*** WRITE COVARIANCE MATRIX OF STRAIN PARAMETERS

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      LOGICAL GETA,LBB,LGF,LCS,LVD,LVA,LVZ,LVS,
     &        LVR,LVG,LVC,LIS,LPS,LPG,LDR,LOS,LAP
      LOGICAL LMSL,LSS,LUP
      DIMENSION A(*),NX(*)
      DIMENSION ACOEF(2,4), LVAL(8), SIG11(4,4), SIG12(4,4) 
      DIMENSION SIG22(4,4), R(2,2), W(4), VAR(10)
      COMMON /OPRINT/ CRIT,LBB,LGF,LCS,LVD,LVA,LVZ,LVS,
     &                LVR,LVG,LVC,LIS,LPS,LPG,LDR,LOS,LAP
      COMMON /STRUCT/ NSTA,NAUX,NUNK,IDIM,NSTAS,NOBS,NCON,NZ,NCD
      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      COMMON /CDGRID/ GRDLX, GRDUX, GRDLY, GRDUY, ICNTX, ICNTY,
     &                ITREF
      COMMON /CONST/ PI,PI2,RAD,RADSEC,TWOPI


      OPEN(10,FILE='dfile',STATUS='UNKNOWN',FORM='UNFORMATTED')
      S2 = SIGUWT * SIGUWT
      R2 = RADSEC * RADSEC

*** COMPUTE MIDPOINT OF GRID
      GLAT = (GRDUY - GRDLY) / 2.0D0
      GLON = (GRDUX - GRDLX) / 2.0D0

*** COMPUTE RADIUS OF CURVATURE AT GRID MIDPOINT
      CALL RADCUR(GLAT,RMER,RPV)
      RPAR = RPV * DCOS(GLAT)

*** Compute elements of the ACOEF matrix where
***     DER = ACOEF * V
*** Here DER is the derivative matrix
***     DER(1) = the derivative wrt latitude
***     DER(2) = the derivative wrt longitude (east positive)
*** and V is the vector
***     V(1) = VEL(1,1,_) * WEI(1,1)
***     V(2) = VEL(2,1,_) * WEI(2,1)
***     V(3) = VEL(1,2,_) * WEI(1,2)
***     V(4) = VEL(2,2,_) * WEI(2,2)
*** and the derivative is evaluated at the center of a grid cell
      XMESH = ((GRDUX - GRDLX) / ICNTX) * RPAR
      YMESH = ((GRDUY - GRDLY) / ICNTY) * RMER
      AREA  = XMESH * YMESH
      ACX = XMESH / (2.D0 * AREA)
      ACY = YMESH / (2.D0 * AREA)
      ACOEF(1,1) = -ACX
      ACOEF(1,2) = -ACX
      ACOEF(1,3) =  ACX
      ACOEF(1,4) =  ACX
      ACOEF(2,1) = -ACY
      ACOEF(2,2) =  ACY
      ACOEF(2,3) = -ACY
      ACOEF(2,4) =  ACY

*** LOOP OVER VELOCITY GRID PARAMETERS

      DO 300 IGRD = 1, ICNTX
        DO 200 JGRD = 1, ICNTY 
           LVAL(1) = IUNGRD(IGRD,JGRD,1)
           LVAL(2) = IUNGRD(IGRD+1,JGRD,1)
           LVAL(3) = IUNGRD(IGRD  ,JGRD+1,1)
           LVAL(4) = IUNGRD(IGRD+1,JGRD+1,1)
           LVAL(5) = IUNGRD(IGRD  ,JGRD  ,2)
           LVAL(6) = IUNGRD(IGRD+1,JGRD  ,2)
           LVAL(7) = IUNGRD(IGRD  ,JGRD+1,2)
           LVAL(8) = IUNGRD(IGRD+1,JGRD+1,2)

           DO 150 I = 1,4
           DO 130 J = 1,4
             IF(.NOT.GETA(LVAL(I),LVAL(J),SIG11(I,J),A,NX)) THEN
                SIG11(I,J) = 0.D0
             ELSE
                SIG11(I,J) = RMER * RMER * SIG11(I,J) / R2
             ENDIF

             IF(.NOT.GETA(LVAL(I),LVAL(J+4),SIG12(I,J),A,NX)) THEN
                SIG12(I,J) = 0.0D0
             ELSE
                SIG12(I,J) = RMER * RPAR * SIG12(I,J) / R2
             ENDIF

             IF(.NOT.GETA(LVAL(I+4),LVAL(J+4),SIG22(I,J),A,NX)) THEN
                SIG22(I,J) = 0.0D0
             ELSE
                SIG22(I,J) = RPAR * RPAR * SIG22(I,J) / R2
             ENDIF
  130       CONTINUE
  150       CONTINUE

            CALL ABAT(ACOEF,SIG11,R,W,2,4)
                VAR(1) = R(1,1)
                VAR(2) = R(1,2)
                VAR(3) = R(2,2)
            CALL ABAT(ACOEF,SIG12,R,W,2,4)
                VAR(4) = R(1,1)
                VAR(5) = R(2,1)
                VAR(7) = R(1,2)
                VAR(8) = R(2,2)
            CALL ABAT(ACOEF,SIG22,R,W,2,4)
                VAR(6) = R(1,1)
                VAR(9) = R(1,2)
                VAR(10) = R(2,2)

            IF(LSS) THEN
              DO 170 K = 1,10
                VAR(K) = VAR(K) * S2
  170         CONTINUE
            ENDIF
         
            WRITE(10) (VAR(L), L=1,10)
  200     CONTINUE
  300   CONTINUE
      CLOSE(10,STATUS='KEEP')
      RETURN
      END
