      SUBROUTINE ADJST (B,GOOGE,SHIFTS,G,NX,A,LAWORK,LNWORK,IUO,IUO2)

*** ADJUSTMENT ROUTINE

      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      IMPLICIT INTEGER (I-N)
      LOGICAL LBB,LGF,LCS,LVD,LVA,LVZ,LVS,
     &        LVR,LVG,LVC,LIS,LPS,LPG,LDR,LOS,LAP
      LOGICAL LMSL,LSS,LUP
      LOGICAL CONVRG,VFCVRG
      DIMENSION B(*),GOOGE(*),SHIFTS(*),G(*),NX(*),A(*)
      COMMON /NUMVFS/ NVFTOT,NVFREE
      COMMON /OPRINT/ CRIT,LBB,LGF,LCS,LVD,LVA,LVZ,LVS,
     &                LVR,LVG,LVC,LIS,LPS,LPG,LDR,LOS,LAP
      COMMON /OPT/ AX,E2,DMSL,DGH,VM,VP,CTOL,ITMAX,ITMIN,IMODE,
     &             LMSL,LSS,LUP
      COMMON /STRUCT/ NSTA,NAUX,NUNK,IDIM,NSTAS,NOBS,NCON,NZ,NCD
      COMMON /STUFF/ ITER

*** READ DATA AND FORM OBS EQS AND CONNECTION MATRIX
*** REORDER FOR MINIMUM PROFILE

      CALL SECOND (IUO,B,G,NX,LNWORK)
      ITER = 0

*** INITIALIZE SHIFTS

      IF (IMODE.NE.0) THEN
        IF (LPS) THEN
          DO 30 I = 1,NSTA
            I1 = IUNSHF(I,1)
            I2 = IUNSHF(I,2)
            I3 = IUNSHF(I,3)
            SHIFTS(I1) = 0.D0
            SHIFTS(I2) = 0.D0
            SHIFTS(I3) = 0.D0
   30     CONTINUE
        ENDIF

*** LIST THE OBSERVATIONAL SUMMARY

        CALL OBSSUM (IUO,G)

*** FORM NORMALS AND SOLVE

        CALL HEAD
        CALL LINE (2)
        WRITE (6,2)
    2   FORMAT ('0',11('*'),' COMMENCING ADJUSTMENT ',11('*') )
      ENDIF
  100 CALL NORMAL (IUO, ITER, A, G, NX, LAWORK, GOOGE)

*** UPDATE UNKNOWNS AND TEST CONVERGENCE

      IF (IMODE.EQ.0) THEN
        CALL FINAL (IUO,A,NX,B,SHIFTS,GOOGE,G,SIGUWT)
      ELSEIF ( CONVRG(A,NX,B,SHIFTS,SIGUWT) .AND. ITER.GE.ITMIN ) THEN
        CALL LINE (2)
        WRITE (6,3)
    3   FORMAT ('0*********** ADJUSTMENT CONVERGED *************')
        IF (NVFREE.LE.0) CALL FINAL (IUO,A,NX,B,SHIFTS,GOOGE,G,SIGUWT)
      ELSE
        IF (ITER.GE.ITMAX) THEN
          CALL LINE (2)
          WRITE (6,1)
    1     FORMAT ('0WARNING - SLOWLY CONVERGING SOLUTION')
          IF (LDR) THEN
            CALL FINAL (IUO,A,NX,B,SHIFTS,GOOGE,G,SIGUWT)
            CALL ABORT2
          ELSE
            CALL ABORT2
          ENDIF
        ELSE
          CALL FORMOB (IUO,IUO2,B,G)
          ITER = ITER + 1
          GO TO 100
        ENDIF
      ENDIF

*** VARIANCE FACTOR ITERATION
*** VFCVRG REFORMS OBS. EQS., COMPUTES INVERSE, AND TESTS V.F. CONVERGE

      IF (NVFREE.GT.0) THEN
  200   IF ( VFCVRG(IUO,IUO2,B,G,A,NX,GOOGE) ) THEN
          CALL LINE (2)
          WRITE (6,5)
    5     FORMAT ('0***** VARIANCE FACTOR ADJUSTMENT CONVERGED *******')
          CALL FINAL (IUO,A,NX,B,SHIFTS,GOOGE,G,SIGUWT)
        ELSEIF (ITER.GE.ITMAX) THEN
          CALL LINE (2)
          WRITE (6,4)
    4     FORMAT ('0WARNING - SLOWLY CONVERGING VARIANCE FACTOR',
     &            ' SOLUTION ',50('*') )
          IF (LDR) THEN
            CALL FINAL (IUO,A,NX,B,SHIFTS,GOOGE,G,SIGUWT)
            CALL ABORT2
          ELSE
            CALL ABORT2
          ENDIF
        ELSE
          CALL NORMAL (IUO, ITER, A, G, NX, LAWORK, GOOGE)
          ITER = ITER + 1
          IF ( CONVRG(A,NX,B,SHIFTS,SIGUWT) ) THEN
            CONTINUE
          ENDIF
          GO TO 200
        ENDIF
      ENDIF

      RETURN
      END
