      SUBROUTINE FORMC (KIND,C,B,ISN,JSN,IAUX,ITIME)

*** COMPUTE THE OBS EQUATION COEFFICIENTS FROM THE PARAMETERS

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      PARAMETER ( PERYR = 365.25D0 * 24.D0 * 60.D0 )
      DIMENSION B(*), LSTA(3)
      DIMENSION C(31),CL(6),CR(6)
      DIMENSION RI(3,3),RJ(3,3),RK(3,3)
      LOGICAL LMSL,LSS,LUP
      COMMON /STRUCT/ NSTA,NAUX,NUNK,IDIM,NSTAS,NOBS,NCON,NZ,NCD
      COMMON /CONST/ PI,PI2,RAD,RADSEC,TWOPI
      COMMON /FAULT/ STRK
      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      COMMON /TILTIN/ TSMALL, TAUDIR(2), TAUIN(2)
      SAVE RI,RJ,RK
      SAVE XIT,YIT,ZIT,XJT,YJT,ZJT,XKT,YKT,ZKT
      SAVE GPHII,GLAMI,DTIMEI,GPHIJ,GLAMJ,DTIMEJ,GPHIK,GLAMK,DTIMEK

*** KIND = 0 IS AN AUXILIARY PARAMETER CONSTRAINT

      IF (KIND.EQ.0) THEN
        C(1) = 1.D0

*** KIND = 1 KIND = 2 KIND = 3 ARE SIMPLE COORDINATE CONSTRAINTS

      ELSEIF (KIND.GE.1 .AND. KIND.LE.3) THEN
        C(1) = 1.D0

*** KIND = 4 IS DIFFERENTIAL X (GPS)

      ELSEIF (KIND.EQ.4) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        IF (IAUX.GT.0) DELX = XJT - XIT
        C(1) = -RI(1,1)
        C(2) = -RI(2,1)
        C(3) = -RI(3,1)
        C(4) = +RJ(1,1)
        C(5) = +RJ(2,1)
        C(6) = +RJ(3,1)
        IF (IAUX.GT.0) C(7) = -DELX
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 5 IS DIFFERENTIAL Y (GPS)

      ELSEIF (KIND.EQ.5) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        IF (IAUX.GT.0) DELY = YJT - YIT
        C(1) = -RI(1,2)
        C(2) = -RI(2,2)
        C(3) = -RI(3,2)
        C(4) = +RJ(1,2)
        C(5) = +RJ(2,2)
        C(6) = +RJ(3,2)
        IF (IAUX.GT.0) C(7) = -DELY
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 6 IS DIFFERENTIAL Z (GPS)

      ELSEIF (KIND.EQ.6) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        IF (IAUX.GT.0) DELZ = ZJT - ZIT
        C(1) = -RI(1,3)
        C(2) = -RI(2,3)
        C(3) = -RI(3,3)
        C(4) = +RJ(1,3)
        C(5) = +RJ(2,3)
        C(6) = +RJ(3,3)
        IF (IAUX.GT.0) C(7) = -DELZ
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 7 IS MARK TO MARK DISTANCE

      ELSEIF (KIND.EQ.7) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT
        CALL GETGLB ( DX,DY,DZ, RI,RJ, P1,Q1,R1,T1, P2,Q2,R2,T2, S )
        C(1) = +P1 / S
        C(2) = +Q1 / S
        C(3) = +T1 / S
        C(4) = +P2 / S
        C(5) = +Q2 / S
        C(6) = +T2 / S
        IF (IAUX.GT.0) C(7) = -S
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 8 IS AN ASTRONOMIC AZIMUTH

      ELSEIF (KIND.EQ.8) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        U =        -SLOI * DX +        CLOI * DY
        V = -SLAI * CLOI * DX - SLAI * SLOI * DY + CLAI * DZ
        U2V2 = U * U + V * V

        C(1) =  -V * ( -SLOI * RI(1,1) + CLOI * RI(1,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(1,1) - SLAI * SLOI * RI(1,2)
     &                  + CLAI * RI(1,3) ) / U2V2
        C(2) =  -V * ( -SLOI * RI(2,1) + CLOI * RI(2,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(2,1) - SLAI * SLOI * RI(2,2)
     &                  + CLAI * RI(2,3) ) / U2V2
        C(3) =  -V * ( -SLOI * RI(3,1) + CLOI * RI(3,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(3,1) - SLAI * SLOI * RI(3,2)
     &                  + CLAI * RI(3,3) ) / U2V2
        C(4) =  +V * ( -SLOI * RJ(1,1) + CLOI * RJ(1,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(1,1) - SLAI * SLOI * RJ(1,2)
     &                  + CLAI * RJ(1,3) ) / U2V2
        C(5) =  +V * ( -SLOI * RJ(2,1) + CLOI * RJ(2,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(2,1) - SLAI * SLOI * RJ(2,2)
     &                  + CLAI * RJ(2,3) ) / U2V2
        C(6) =  +V * ( -SLOI * RJ(3,1) + CLOI * RJ(3,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(3,1) - SLAI * SLOI * RJ(3,2)
     &                  + CLAI * RJ(3,3) ) / U2V2
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 9 IS A ZENITH DISTANCE

      ELSEIF (KIND.EQ.9) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT
        CALL GETGLB ( DX,DY,DZ, RI,RJ, P1,Q1,R1,T1, P2,Q2,R2,T2, S )

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        W = CLAI * CLOI * DX + CLAI * SLOI * DY + SLAI * DZ

        TRM1 = -1.D0 / DSQRT( S * S - W * W )
        TRM2 = TRM1 * ( -W / ( S * S ) )
        C(1) =  TRM1 * ( -RI(1,1) * CLAI * CLOI
     &                    - RI(1,2) * CLAI * SLOI - RI(1,3) * SLAI )
     &          + TRM2 * P1
        C(2) =  TRM1 * ( -RI(2,1) * CLAI * CLOI
     &                    - RI(2,2) * CLAI * SLOI - RI(2,3) * SLAI )
     &          + TRM2 * Q1
        C(3) =  TRM1 * ( -RI(3,1) * CLAI * CLOI
     &                    - RI(3,2) * CLAI * SLOI - RI(3,3) * SLAI )
     &          + TRM2 * T1
        C(4) =  TRM1 * ( +RJ(1,1) * CLAI * CLOI
     &                    + RJ(1,2) * CLAI * SLOI + RJ(1,3) * SLAI )
     &          + TRM2 * P2
        C(5) =  TRM1 * ( +RJ(2,1) * CLAI * CLOI
     &                    + RJ(2,2) * CLAI * SLOI + RJ(2,3) * SLAI )
     &          + TRM2 * Q2
        C(6) =  TRM1 * ( +RJ(3,1) * CLAI * CLOI
     &                    + RJ(3,2) * CLAI * SLOI + RJ(3,3) * SLAI )
     &          + TRM2 * T2
        IF (IAUX.GT.0) THEN
          CALL GETAUX (VAL,IAUX,B)
          RP = VAL * P1 / R1
          RQ = VAL * Q1 / R1
          C(1) = C(1) + RP
          C(2) = C(2) + RQ
          C(4) = C(4) - RP
          C(5) = C(5) - RQ
          C(7) = -R1
        ENDIF
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 10 IS HORIZONTAL ANGLE (MARK-TO-MARK)
*** DERIVITIVES W.R.T. HEIGHT ARE NOT COMPUTED AND ARE ESSENTIALLY =0

      ELSEIF (KIND.EQ.10) THEN

        KSN = IAUX
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        CALL GETPK (RK,GPHIK,GLAMK,DTIMEK,XKT,YKT,ZKT,KSN,ITIME,B)

        DXL = XJT - XIT
        DXR = XKT - XIT
        DYL = YJT - YIT
        DYR = YKT - YIT
        DZL = ZJT - ZIT
        DZR = ZKT - ZIT

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        UL =        -SLOI * DXL +        CLOI * DYL
        VL = -SLAI * CLOI * DXL - SLAI * SLOI * DYL + CLAI * DZL
        U2V2L = UL * UL + VL * VL
        UR =        -SLOI * DXR +        CLOI * DYR
        VR = -SLAI * CLOI * DXR - SLAI * SLOI * DYR + CLAI * DZR
        U2V2R = UR * UR + VR * VR

        CL(1) = -VL * ( -SLOI * RI(1,1) + CLOI * RI(1,2) ) / U2V2L
     &          + UL * ( -SLAI * CLOI * RI(1,1) - SLAI * SLOI * RI(1,2)
     &                   + CLAI * RI(1,3) ) / U2V2L
        CL(2) = -VL * ( -SLOI * RI(2,1) + CLOI * RI(2,2) ) / U2V2L
     &          + UL * ( -SLAI * CLOI * RI(2,1) - SLAI * SLOI * RI(2,2)
     &                   + CLAI * RI(2,3) ) / U2V2L
        CL(3) = -VL * ( -SLOI * RI(3,1) + CLOI * RI(3,2) ) / U2V2L
     &          + UL * ( -SLAI * CLOI * RI(3,1) - SLAI * SLOI * RI(3,2)
     &                   + CLAI * RI(3,3) ) / U2V2L
        CL(4) = +VL * ( -SLOI * RJ(1,1) + CLOI * RJ(1,2) ) / U2V2L
     &          - UL * ( -SLAI * CLOI * RJ(1,1) - SLAI * SLOI * RJ(1,2)
     &                   + CLAI * RJ(1,3) ) / U2V2L
        CL(5) = +VL * ( -SLOI * RJ(2,1) + CLOI * RJ(2,2) ) / U2V2L
     &          - UL * ( -SLAI * CLOI * RJ(2,1) - SLAI * SLOI * RJ(2,2)
     &                   + CLAI * RJ(2,3) ) / U2V2L
        CL(6) = +VL * ( -SLOI * RJ(3,1) + CLOI * RJ(3,2) ) / U2V2L
     &          - UL * ( -SLAI * CLOI * RJ(3,1) - SLAI * SLOI * RJ(3,2)
     &                   + CLAI * RJ(3,3) ) / U2V2L
        CR(1) = -VR * ( -SLOI * RI(1,1) + CLOI * RI(1,2) ) / U2V2R
     &          + UR * ( -SLAI * CLOI * RI(1,1) - SLAI * SLOI * RI(1,2)
     &                   + CLAI * RI(1,3) ) / U2V2R
        CR(2) = -VR * ( -SLOI * RI(2,1) + CLOI * RI(2,2) ) / U2V2R
     &          + UR * ( -SLAI * CLOI * RI(2,1) - SLAI * SLOI * RI(2,2)
     &                   + CLAI * RI(2,3) ) / U2V2R
        CR(3) = -VR * ( -SLOI * RI(3,1) + CLOI * RI(3,2) ) / U2V2R
     &          + UR * ( -SLAI * CLOI * RI(3,1) - SLAI * SLOI * RI(3,2)
     &                   + CLAI * RI(3,3) ) / U2V2R
        CR(4) = +VR * ( -SLOI * RK(1,1) + CLOI * RK(1,2) ) / U2V2R
     &          - UR * ( -SLAI * CLOI * RK(1,1) - SLAI * SLOI * RK(1,2)
     &                   + CLAI * RK(1,3) ) / U2V2R
        CR(5) = +VR * ( -SLOI * RK(2,1) + CLOI * RK(2,2) ) / U2V2R
     &          - UR * ( -SLAI * CLOI * RK(2,1) - SLAI * SLOI * RK(2,2)
     &                   + CLAI * RK(2,3) ) / U2V2R
        CR(6) = +VR * ( -SLOI * RK(3,1) + CLOI * RK(3,2) ) / U2V2R
     &          - UR * ( -SLAI * CLOI * RK(3,1) - SLAI * SLOI * RK(3,2)
     &                   + CLAI * RK(3,3) ) / U2V2R
        C(1) =  CR(1) - CL(1)
        C(2) =  CR(2) - CL(2)
        C(3) = -CL(4)
        C(4) = -CL(5)
        C(5) =  CR(4)
        C(6) =  CR(5)
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          LSTA(3) = KSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,3,KIND,B)
        ENDIF

*** KIND = 11 IS A HORIZONTAL DIRECTION

      ELSEIF (KIND.EQ.11) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        U =        -SLOI * DX +        CLOI * DY
        V = -SLAI * CLOI * DX - SLAI * SLOI * DY + CLAI * DZ
        U2V2 = U * U + V * V

        C(1) =  -V * ( -SLOI * RI(1,1) + CLOI * RI(1,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(1,1) - SLAI * SLOI * RI(1,2)
     &                  + CLAI * RI(1,3) ) / U2V2
        C(2) =  -V * ( -SLOI * RI(2,1) + CLOI * RI(2,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(2,1) - SLAI * SLOI * RI(2,2)
     &                  + CLAI * RI(2,3) ) / U2V2
        C(3) =  -V * ( -SLOI * RI(3,1) + CLOI * RI(3,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(3,1) - SLAI * SLOI * RI(3,2)
     &                  + CLAI * RI(3,3) ) / U2V2
        C(4) =  +V * ( -SLOI * RJ(1,1) + CLOI * RJ(1,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(1,1) - SLAI * SLOI * RJ(1,2)
     &                  + CLAI * RJ(1,3) ) / U2V2
        C(5) =  +V * ( -SLOI * RJ(2,1) + CLOI * RJ(2,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(2,1) - SLAI * SLOI * RJ(2,2)
     &                  + CLAI * RJ(2,3) ) / U2V2
        C(6) =  +V * ( -SLOI * RJ(3,1) + CLOI * RJ(3,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(3,1) - SLAI * SLOI * RJ(3,2)
     &                  + CLAI * RJ(3,3) ) / U2V2
        IF (IAUX.GT.0) C(7) = -1.D0
        IF (NCD.GT.0) THEN
          LSTA(1) = ISN
          LSTA(2) = JSN
          CALL FORMCD (C,IAUX,DTIMEI,LSTA,2,KIND,B)
        ENDIF

*** KIND = 12 IS A CONSTRAINED AZIMUTH

      ELSEIF (KIND.EQ.12) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        U =        -SLOI * DX +        CLOI * DY
        V = -SLAI * CLOI * DX - SLAI * SLOI * DY + CLAI * DZ
        U2V2 = U * U + V * V

        C(1) =  -V * ( -SLOI * RI(1,1) + CLOI * RI(1,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(1,1) - SLAI * SLOI * RI(1,2)
     &                  + CLAI * RI(1,3) ) / U2V2
        C(2) =  -V * ( -SLOI * RI(2,1) + CLOI * RI(2,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(2,1) - SLAI * SLOI * RI(2,2)
     &                  + CLAI * RI(2,3) ) / U2V2
        C(3) =  -V * ( -SLOI * RI(3,1) + CLOI * RI(3,2) ) / U2V2
     &           + U * ( -SLAI * CLOI * RI(3,1) - SLAI * SLOI * RI(3,2)
     &                  + CLAI * RI(3,3) ) / U2V2
        C(4) =  +V * ( -SLOI * RJ(1,1) + CLOI * RJ(1,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(1,1) - SLAI * SLOI * RJ(1,2)
     &                  + CLAI * RJ(1,3) ) / U2V2
        C(5) =  +V * ( -SLOI * RJ(2,1) + CLOI * RJ(2,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(2,1) - SLAI * SLOI * RJ(2,2)
     &                  + CLAI * RJ(2,3) ) / U2V2
        C(6) =  +V * ( -SLOI * RJ(3,1) + CLOI * RJ(3,2) ) / U2V2
     &           - U * ( -SLAI * CLOI * RJ(3,1) - SLAI * SLOI * RJ(3,2)
     &                  + CLAI * RJ(3,3) ) / U2V2


*** KIND = 13 IS A CONSTRAINED MARK TO MARK DISTANCE

      ELSEIF (KIND.EQ.13) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT
        CALL GETGLB ( DX,DY,DZ, RI,RJ, P1,Q1,R1,T1, P2,Q2,R2,T2, S )
        C(1) = P1 / S
        C(2) = Q1 / S
        C(3) = T1 / S
        C(4) = P2 / S
        C(5) = Q2 / S
        C(6) = T2 / S
        IF (IAUX.GT.0) C(7) = -S

*** KIND = 14 IS A CONSTRAINED ZENITH DISTANCE

      ELSEIF (KIND.EQ.14) THEN
        CALL GETPI (RI,GPHII,GLAMI,DTIMEI,XIT,YIT,ZIT,ISN,ITIME,B)
        CALL GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJT,YJT,ZJT,JSN,ITIME,B)
        DX = XJT - XIT
        DY = YJT - YIT
        DZ = ZJT - ZIT
        CALL GETGLB ( DX,DY,DZ, RI,RJ, P1,Q1,R1,T1, P2,Q2,R2,T2, S )

        CALL GETALA (ALAI,ISN,B)
        SLAI = DSIN(ALAI)
        CLAI = DCOS(ALAI)
        CALL GETALO (ALOI,ISN,B)
        SLOI = DSIN(ALOI)
        CLOI = DCOS(ALOI)

        W = CLAI * CLOI * DX + CLAI * SLOI * DY + SLAI * DZ

        TRM1 = -1.D0 / DSQRT( S * S - W * W )
        TRM2 = TRM1 * ( -W / ( S * S ) )
        C(1) =  TRM1 * ( -RI(1,1) * CLAI * CLOI
     &                    - RI(1,2) * CLAI * SLOI - RI(1,3) * SLAI )
     &          + TRM2 * P1
        C(2) =  TRM1 * ( -RI(2,1) * CLAI * CLOI
     &                    - RI(2,2) * CLAI * SLOI - RI(2,3) * SLAI )
     &          + TRM2 * Q1
        C(3) =  TRM1 * ( -RI(3,1) * CLAI * CLOI
     &                    - RI(3,2) * CLAI * SLOI - RI(3,3) * SLAI )
     &          + TRM2 * T1
        C(4) =  TRM1 * ( +RJ(1,1) * CLAI * CLOI
     &                    + RJ(1,2) * CLAI * SLOI + RJ(1,3) * SLAI )
     &          + TRM2 * P2
        C(5) =  TRM1 * ( +RJ(2,1) * CLAI * CLOI
     &                    + RJ(2,2) * CLAI * SLOI + RJ(2,3) * SLAI )
     &          + TRM2 * Q2
        C(6) =  TRM1 * ( +RJ(3,1) * CLAI * CLOI
     &                    + RJ(3,2) * CLAI * SLOI + RJ(3,3) * SLAI )
     &          + TRM2 * T2

*** KIND = 15 KIND = 16 KIND = 17 ARE CONSTRAINED HEIGHT DIFFERENCES

      ELSEIF (KIND.GE.15 .AND. KIND.LE.17) THEN
        C(1) = -1.D0
        C(2) = +1.D0
*** KIND = 18 IS A CONSTRAINED MINIMAL DISTANCE PERP. TO FAULT

      ELSEIF (KIND.EQ.18) THEN

        SSTRK = DSIN(STRK)
        CSTRK = DCOS(STRK)
        CALL GETGLA (GLAI,ISN,B)
        CLAI = DCOS(GLAI)
        CALL RADCUR (GLAI,RMER,RPV)
      
        C(1) =  SSTRK * RMER / RADSEC
        C(2) =  -CSTRK * RPV * CLAI / RADSEC
        C(3) =  -SSTRK * RMER / RADSEC
        C(4) =  CSTRK * RPV * CLAI / RADSEC

      ELSE
        WRITE (6,1) KIND
    1   FORMAT ('0ERROR - ILLEGAL KIND IN FORMC  = ',I5)
        CALL ABORT2
      ENDIF

      RETURN
      END

      SUBROUTINE GETPI (RI,GPHII,GLAMI,DTIMEI,XI,YI,ZI,ISN,ITIME,B)

*** BUILD A NEW ROTATION MATRIX IF NEW ISN

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      DIMENSION B(*),RI(3,3)
      COMMON /LASTSN/ ISNX,JSNX,KSNX,ITIMEX,JTIMEX,KTIMEX

      IF (ISN.NE.ISNX .OR. ITIME.NE.ITIMEX) THEN
        CALL BUILDG (RI,GPHII,GLAMI,DTIMEI,XI,YI,ZI,ISN,ITIME,B)
        ISNX = ISN
        ITIMEX = ITIME
      ENDIF

      RETURN
      END


      SUBROUTINE GETPJ (RJ,GPHIJ,GLAMJ,DTIMEJ,XJ,YJ,ZJ,JSN,ITIME,B)

*** BUILD A NEW ROTATION MATRIX IF NEW JSN

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      DIMENSION B(*),RJ(3,3)
      COMMON /LASTSN/ ISNX,JSNX,KSNX,ITIMEX,JTIMEX,KTIMEXX

      IF (JSN.NE.JSNX .OR. ITIME.NE.JTIMEX) THEN
        CALL BUILDG (RJ,GPHIJ,GLAMJ,DTIMEJ,XJ,YJ,ZJ,JSN,ITIME,B)
        JSNX = JSN
        JTIMEX = ITIME
      ENDIF

      RETURN
      END


      SUBROUTINE GETPK (RK,GPHIK,GLAMK,DTIMEK,XK,YK,ZK,KSN,ITIME,B)

*** BUILD A NEW ROTATION MATRIX IF NEW KSN

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      DIMENSION B(*),RK(3,3)
      COMMON /LASTSN/ ISNX,JSNX,KSNX,ITIMEX,JTIMEX,KTIMEX

      IF (KSN.NE.KSNX .OR. ITIME.NE.KTIMEX) THEN
        CALL BUILDG (RK,GPHIK,GLAMK,DTIMEK,XK,YK,ZK,KSN,ITIME,B)
        KSNX = KSN
        KTIMEX = ITIME
      ENDIF

      RETURN
      END


      SUBROUTINE BUILDG (R,GLAT,GLON,DTIME,X,Y,Z,ISN,ITIME,B)

*** RETURN THE GLOBAL ROTATION MATRIX

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      LOGICAL LMSL,LSS,LUP
      DIMENSION B(*),R(3,3)

      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      COMMON /CONST/ PI,PI2,RAD,RADSEC,TWOPI

      COMMON /CDGRID/ GRDLX, GRDUX, GRDLY, GRDUY, ICNTX, ICNTY,
     &                ITREF	


      CALL GETGLA (GLAT0,ISN,B)
      CALL GETGLO (GLON0,ISN,B)
      CALL GETMSL (GMSL0,ISN,B)
      CALL GETGH (GH0,ISN,B)
      EHT0 = GMSL0 + GH0

      CALL TCOORD (GLAT0,GLON0,EHT0,B,
     &             GLAT,GLON,EHT,ITIME,DTIME)

      SLAT = DSIN(GLAT)
      CLAT = DCOS(GLAT)
      SLON = DSIN(GLON)
      CLON = DCOS(GLON)

      W2 = 1.D0 - E2 * SLAT * SLAT
      EN = AX / DSQRT(W2)
      ENLA = EN * E2 * SLAT * CLAT / W2

      R(1,1) = (              -(EN + EHT) * SLAT * CLON +
     &                               ENLA * CLAT * CLON ) / RADSEC
      R(1,2) = (              -(EN + EHT) * SLAT * SLON +
     &                               ENLA * CLAT * SLON ) / RADSEC
      R(1,3) = ( (EN * (1.D0 - E2) + EHT) * CLAT        +
     &                 (1.D0 - E2) * ENLA * SLAT        ) / RADSEC

      R(2,1) = ( -(EN + EHT) * CLAT * SLON ) / RADSEC
      R(2,2) = ( (EN + EHT) * CLAT * CLON ) / RADSEC
      R(2,3) = 0.D0

      R(3,1) = CLAT * CLON
      R(3,2) = CLAT * SLON
      R(3,3) = SLAT

      CALL TOXYZ (GLAT,GLON,EHT,X,Y,Z)

      RETURN
      END
