       SUBROUTINE BTCHKB(BRTTMP,CHAN,NSPOT,LWRLIM,UPRLIM,FACTOR,
     .                   SPTCNF,CHNAVL,NUMLIN)
       IMPLICIT NONE
C***********************************************************************
C
C  NAME- BTCHKB
C
C  LANGUAGE- FORTRAN 77       TYPE- SUBROUTINE   COMPUTER- IBM SP
C
C  VERSION- 1.0        DATE- 1/15/04    PROGRAMMER- FRANK TILLEY (RAYTHEON)
C
C  FUNCTION-  THIS SUBROUTINE PERFORMS A GROSS LIMITS CHECK ON
C             BRIGHTNESS TEMPERATURES FOR ALL THE SPOTS OF A GIVEN
C             CHANNEL.  IF A BRIGHTNESS TEMPERATURE FOR ANY SPOT FAILS
C             THE LIMITS CHECK, THE SPOT CONFIDENCE FOR THAT SPOT IS
C             DECREASED BY THE AMOUNT GIVEN IN FACTOR, AND THE CHANNEL
C
C  CALLING SEQUENCE PARAMETERS-
C    VARIABLE   TYPE  I/O   DESCRIPTION
C    --------   ----  ---   -----------
C    BRTTMP     REAL   I    BRIGHTNESS TEMPERATURE VECTOR (DIM NSPOT)
C    CHAN       INT    I    CHANNEL OF INSTRUMENT BEING CHECKED
C    NSPOT      INT    I    NUMBER OF SPOTS IN A SCAN FOR THE INSTRUMENT
C    LWRLIM     REAL   I    LOWER LIMIT ON BRIGHTNESS TEMPERATURE FOR
C                           THE INSTRUMENT CHANNEL (FROM CDB)
C    UPRLIM     REAL   I    UPPER LIMIT ON BRIGHTNESS TEMPERATURE FOR
C                           THE INSTRUMENT CHANNEL (FROM CDB)
C    FACTOR     REAL   I    AMOUNT BY WHICH TO LOWER SPOT CONFIDENCE
C                           IF BRIGHTNESS TEMPERATURE LIMITS FOR
C                           CHANNEL ARE NOT MET (FROM CDB)
C    SPTCNF     REAL  I/O   SPOT CONFIDENCE VECTOR (DIMENSION NSPOT)
C                           VALUES ARE FROM 0 - 100
C    CHNAVL     INT   I/O   CHANNEL AVAILABILITY (DIMENSION NSPOT)
C
C  LOCAL VARIABLES-
C    VARIABLE     TYPE    DESCRIPTION
C    --------     ----    -----------
C    BIT          INT     BIT TO SET IN CHANNEL AVAILABILITY
C    SPOT         INT     DO LOOP COUNTER FOR SPOTS IN SCAN LINE
C
C  FUNCTIONS USED- IBCLR
C
C  COMMON BLOCKS USED- HIRSTAT
C
C  EXIT STATES-NONE
C
C  COMMENTS- THIS SUBROUTINE IS ONLY CALLED FOR DATA WHICH HAS BEEN
C            CHECKED AND IS CONSIDERED USABLE (THUS NO VALUES SHOULD
C            BE MISSING)
C
C***********************************************************************
C
      INCLUDE'AMASTAT'
      INTEGER   NSPOT, SPOT, BIT, CHAN
      INTEGER   CHNAVL(NSPOT),NUMLIN
      REAL   BRTTMP(NSPOT), SPTCNF(NSPOT), LWRLIM, UPRLIM, FACTOR
C
      DO 10 SPOT = 1, NSPOT
        IF ((BRTTMP(SPOT).GT.UPRLIM).OR.(BRTTMP(SPOT).LT.LWRLIM)) THEN
ccft     IF(AMAOFF(CHAN))THEN
ccft      BADAMA(SPOT,NUMLIN,CHAN) = 1
ccft      BADARET(SPOT,NUMLIN) = .TRUE.
ccft      BRTTMP(SPOT) = (UPRLIM + LWRLIM) / 2
ccft     ELSE
C
C  BRIGHTNESS TEMP FALLS OUTSIDE OF LIMITS - ADJUST SPOT CONFIDENCE
C
          SPTCNF(SPOT) = SPTCNF(SPOT) - FACTOR
C
C  FORCE VALUE TO ZERO IF LESS THAN ZERO
C
          IF (SPTCNF(SPOT).LT.0.0) SPTCNF(SPOT) = 0.0
C
C  SET BIT FOR CHANNEL IN CHANNEL AVAILABILITY TO ZERO
C
          BIT = 32 - CHAN
          CHNAVL(SPOT) = IBCLR(CHNAVL(SPOT), BIT)
ccft     ENDIF
C
        ENDIF
C
   10 CONTINUE
C
      RETURN
      END
