      SUBROUTINE SECSV (CARD,IUO,IOBS,B,NX,FATAL)

*** WRITE OBSERVATION EQUATION FOR SITE VELOCITY 

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      PARAMETER (MXSSN = 9999)
      CHARACTER*80 CARD
      LOGICAL FATAL
      LOGICAL GETSSN
      LOGICAL ADDCON
      LOGICAL ELFLAG,DFFLAG
      LOGICAL LMSL,LSS,LUP
      LOGICAL LBB,LGF,LCS,LVD,LVA,LVZ,LVS,
     &        LVR,LVG,LVC,LIS,LPS,LPG,LDR,LOS,LAP
      DIMENSION B(*),NX(*)
      DIMENSION WEI(2,2), VEL(2,2,3)
      DIMENSION IC(31),C(31)
      COMMON /CONST/ PI,PI2,RAD,RADSEC,TWOPI
      COMMON /FLAGS/ ELFLAG(MXSSN),DFFLAG(MXSSN)
      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      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 /CDGRID/ GRDLX, GRDUX, GRDLY, GRDUY, ICNTX, ICNTY,
     &                ITREF
      COMMON /VF/ VFACTR(31)
      CHARACTER*6  CVECN, CSTDN, CVECE, CSTDE, CVECU, CSTDU

      JDUM = 0

      READ (CARD,1) ISSN, CVECN, CSTDN, CVECE, CSTDE,
     &                          CVECU, CSTDU
    1 FORMAT(2X, I4,16X, 6A6)


      CALL NBLANK(CVECN,2,IDUM)
      READ (CVECN,2) VECN
      CALL NBLANK(CSTDN,2,IDUM)
      READ(CSTDN,2) STDN

      CALL NBLANK(CVECE,2,IDUM)
      READ (CVECE,2) VECE
      CALL NBLANK(CSTDE,2,IDUM)
      READ(CSTDE,2) STDE

      CALL NBLANK(CVECU,2,IDUM)
      READ (CVECU,2) VECU
      CALL NBLANK(CSTDU,2,IDUM)
      READ(CSTDU,2) STDU

    2 FORMAT(F6.5)

      IF (.NOT.GETSSN(ISSN,ISN) ) THEN
         CALL LINE (3)
         WRITE(6,10) CARD
   10    FORMAT('0ERROR - NO *80* OR *91* RECORD--',A80,/)
         RETURN
      ENDIF

      CALL GETGLA(GLAT,ISN,B)
      CALL GETGLO(GLON,ISN,B)

*** DEFAULT STD. DEV. IS 0.01 MM/YR

      IF (CARD(29:34).EQ.'      ') STDN = 0.00001D0
      IF (CARD(41:46).EQ.'      ') STDE = 0.00001D0
      IF (CARD(53:58).EQ.'      ') STDU = 0.00001D0

*** MULTIPLY STANDARD DEVIATION BY VARIANCE FACTOR
      STDN = STDN * DSQRT(VFACTR(25))
      STDE = STDE * DSQRT(VFACTR(26))
      STDU = STDU * DSQRT(VFACTR(27))
*** CHANGE LAT AND LONG VELOCITIES FROM METERS/YR TO ARC SECONDS

      CALL RADCUR (GLAT,RMER,RPV)
      RPAR = RPV * DCOS(GLAT)

      VECN = (VECN/RMER) * RADSEC
      STDN = (STDN/RMER) * RADSEC

      VECE = (VECE/RPAR) * RADSEC
      STDE = (STDE/RPAR) * RADSEC

      CALL GRDPOS(GLON,GLAT,I,J)
      CALL GRDWEI(GLON,GLAT,I,J,WEI)
      CALL GRDVEC(I,J,VEL,B)

      LENG = 4
      C(1) = WEI(1,1)
      C(2) = WEI(2,1)
      C(3) = WEI(1,2)
      C(4) = WEI(2,2)

      C(5) = GLAT
      C(6) = GLON

*** KIND = 25 -- NORTHWARD SITE VELOCITY CONSTRAINT (LATITUDE)

      IF (CARD(23:28).NE.'      ') THEN
        KIND = 25
        NCON = NCON + 1
        IOBS = IOBS + 1
        IC(1) = IUNGRD(I  ,J  ,1)
        IC(2) = IUNGRD(I+1,J  ,1)
        IC(3) = IUNGRD(I  ,J+1,1)
        IC(4) = IUNGRD(I+1,J+1,1)

        OBS0 = (WEI(1,1) * VEL(1,1,1)
     &        + WEI(2,1) * VEL(2,1,1)
     &        + WEI(1,2) * VEL(1,2,1)
     &        + WEI(2,2) * VEL(2,2,1)) * RADSEC

        OBSB = VECN
        CMO = ( OBS0 - OBSB )
        IF (IMODE.EQ.0) CMO = 0.D0

        IF (.NOT.ADDCON(IC,LENG,NX)) THEN
          WRITE(6,666)
  666     FORMAT("OERROR - INSUFFICIENT STORAGE FOR CONNECTIVITY",/)
          CALL ABORT2
        ENDIF
        WRITE (IUO) KIND,ISN,JDUM,IC,C,LENG,CMO,OBSB,STDN,
     &              IOBS,I,J,JDUM
      ENDIF

*** KIND = 26 -- EASTWARD SITE VELOCITY CONSTRAINT (LONGITUDE)

      IF (CARD(35:40).NE.'      ') THEN
        KIND = 26
        NCON = NCON + 1
        IOBS = IOBS + 1
        IC(1) = IUNGRD(I  ,J  ,2)
        IC(2) = IUNGRD(I+1,J  ,2)
        IC(3) = IUNGRD(I  ,J+1,2)
        IC(4) = IUNGRD(I+1,J+1,2)

        OBS0 = (WEI(1,1) * VEL(1,1,2)
     &        + WEI(2,1) * VEL(2,1,2)
     &        + WEI(1,2) * VEL(1,2,2)
     &        + WEI(2,2) * VEL(2,2,2)) * RADSEC

        OBSB = VECE
        CMO = ( OBS0 - OBSB )
        IF (IMODE.EQ.0) CMO = 0.D0

        IF (.NOT.ADDCON(IC,LENG,NX)) THEN
          WRITE(6,666)
          CALL ABORT2
        ENDIF
        WRITE (IUO) KIND,ISN,JDUM,IC,C,LENG,CMO,OBSB,STDE,
     &              IOBS,I,J,JDUM
      ENDIF

*** KIND = 27 -- UPWARD SITE VELOCITY CONSTRAINT (LATITUDE)

      IF (CARD(47:52).NE.'      ') THEN
        KIND = 27
        NCON = NCON + 1
        IOBS = IOBS + 1
        IC(1) = IUNGRD(I  ,J  ,3)
        IC(2) = IUNGRD(I+1,J  ,3)
        IC(3) = IUNGRD(I  ,J+1,3)
        IC(4) = IUNGRD(I+1,J+1,3)

        OBS0 = (WEI(1,1) * VEL(1,1,3)
     &        + WEI(2,1) * VEL(2,1,3)
     &        + WEI(1,2) * VEL(1,2,3)
     &        + WEI(2,2) * VEL(2,2,3))

        OBSB = VECU
        CMO = ( OBS0 - OBSB )
        IF (IMODE.EQ.0) CMO = 0.D0

        IF (.NOT.ADDCON(IC,LENG,NX)) THEN
          WRITE(6,666)
          CALL ABORT2
        ENDIF
        WRITE (IUO) KIND,ISN,JDUM,IC,C,LENG,CMO,OBSB,STDU,
     &              IOBS,I,J,JDUM
      ENDIF

*** ECHO OBSERVATION NUMBERS

      IF (LCS) THEN
        CALL LINE (1)
        WRITE (6,3) IOBS,CARD
    3   FORMAT (1X,I6,3X,A80)
      ENDIF
   
      RETURN
      END
