      SUBROUTINE AMB2(IOFFST,FOFFST,LOCDB,DT, IOFF2A,L2A,RMS2A, LAMB2)

C     Routine maintains information about integer-cycle ambiguities
C     derived from the "secondary" algorithm, NEWSATAMB, that uses
C     the known baseline and directions to the satellites to calculate
C     integer-cycle corrections.  It sets an output flag if the values
C     have been consistent enough over a long period to justify
C     establishing a pair entirely on the basis of the secondary
C     algorithm.

C     Arguments:
C     Input only:
C        IOFFST    [I*4]: Integer-cycle offset returned by NEWSATAMB.
C        FOFFST    [I*4]: Fractional-cycle offset returned by NEWSATAMB.
C        LOCDB     [I*4]: Location of this pair in the pairs database.
C        DT        [R*8]: Interval between data epochs [seconds].

C     Input and Output:
C        IOFF2A(*) [I*4]: Previous value of IOFFST.  Index is location
C                         in the pairs database.
C        L2A(*)    [I*4]: Number of consecutive previous epochs at which
C                         IOFF2A has been the offset for this pair.
C                         Index is location in the pairs database.
C        RMS2A(*)  [R*8]: Mean square value of FOFFST for the previous
C                         L2A epochs for this pair.  Index is location in
C                         the pairs database.
C     Output only:
C        LAMB2     [L*1]: TRUE iff the statistics justify establishment
C                         of this pair from the secondary algorithm alone.

      IMPLICIT REAL*8 (A-H,O-Z)
      LOGICAL*1 LAMB2

      DIMENSION IOFF2A(*),L2A(*),RMS2A(*)

      DATA L2AMIN /20/                       ! Require 20 points
      DATA TA2MIN1 /2.4D2/                   ! or 240 seconds
      DATA TA2MIN2 /2.4D2/
      DATA RMS2AMX1 /6.4D-3/                 ! ~ rms of 0.08 cycles
      DATA RMS2AMX2 /1.0D-2/                 ! ~ rms of 0.1  cycles
      DATA RMS2AMX3 /4.16667D-2/             ! ~ rms of 0.204124145...


      IF (IOFFST.EQ.IOFF2A(LOCDB)) THEN         ! Same offset as last time
         L2A(LOCDB) = L2A(LOCDB) + 1            ! Increment count
         T2A = L2A(LOCDB)                       ! of consecutive values
         RMS2A(LOCDB) = ((T2A - 1.0D0)/T2A)*RMS2A(LOCDB) +
     3                  (1.0D0/T2A)*(FOFFST*FOFFST)   ! Adjust square of rms
         IF ((RMS2A(LOCDB).GT.RMS2AMX3).OR.           ! rms > 0.2041...
     2       ((RMS2A(LOCDB).GT.RMS2AMX2).AND.         ! rms of 0.1
     3        ((DT*(L2A(LOCDB) - 1)).GT.TA2MIN2)))  THEN    ! Interval > 240 s
            L2A(LOCDB) = 1                      ! rms is really too big:
            RMS2A(LOCDB) = FOFFST*FOFFST        ! reset everything & try again
         END IF
      ELSE                                      ! A different value this time
         IOFF2A(LOCDB) = IOFFST                 ! Initialize value
         L2A(LOCDB) = 1                         ! Initialize count
         RMS2A(LOCDB) = FOFFST*FOFFST  ! Init. mean square fractional offset
      END IF
      LAMB2 =                       ! TRUE iff a candidate via this algorithm
     2   (((DT*(L2A(LOCDB) - 1)).GE.TA2MIN1).OR.(L2A(LOCDB).GE.L2AMIN))
     3   .AND.(RMS2A(LOCDB).LE.RMS2AMX1)

      RETURN
      END
