CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
       SUBROUTINE BACKGROUND_C(RATES,FLAG)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C    Subroutine to calculate the background for the PM rates, and subtract this
C    background from each rate. This version attempts to remove "anomalous"
C    counts caused by an as-yet unexplained instrumental effect
C
C FORMAL ARGUMENTS:
C
C    RATES:
C      I*4	  I/O	An integer array of length 6.  Upon entry it contains
C			the original rates, and upon return will contain the
C			modified rates.
C    FLAG:
C      I*4	  I	unused
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE BACKGROUND (RATES, FLAG)
!	    INTEGER(KIND=4), DIMENSION(6), INTENT(INOUT) :: RATES
!	    INTEGER, INTENT(IN) :: FLAG
!	  END SUBROUTINE BACKGROUND
!	END INTERFACE
C
C IMPLICIT INPUTS:
C
C    None
C
C IMPLICIT OUTPUTS:
C
C    None
C
C SIDE EFFECTS:
C
C    None
C
C COMMON BLOCKS:
C
C    None
C
C INCLUDE FILES:
C
C    None
C
C DESIGN:
C
C    calculate background as 95% of lowest of rates, but not less than 150
C    subtract background from all rates values
C    locate largest rate step
C    if largest rate step is 3 or more, adjust all lower steps
C
C CREATED:
C
C    10-NOV-1997     John Paquette
C
C This version:   1.4   29-MAR-2000
C
C DEVELOPMENT HISTORY:
C 
C  Author       Date		Description of Change 
C  --------	-----------	--------------------- 
C  J. PAQUETTE  10-NOV-1997     Created 
C  J. PAQUETTE  20-NOV-1997     Corrects rates instead of passing back background;
C                               tries to remove anomalous peaks
C  J. PAQUETTE   4-DEC-1997     "Cleaned-up" version
C  L. Bleau	13-APR-1999	added comments
C  L. Bleau	16-APR-1999	added declarations, IMPLICIT NONE
C  L. Bleau	 2-NOV-1999	added comments
C  L. Bleau	15-NOV-1999	added comments
C  J. PAQUETTE  29-MAR-2000     No longer require background to be at least 150.
C                               Background is 0.96*minimum PM rate
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CDEC$  IDENT	'1.4'
       IMPLICIT NONE
       INTEGER*4 FLAG, RATES(6), MAXIMUM, PEAK_STEP, I
       REAL*8 BACKGND, PMMIN
C
       PMMIN = MIN(RATES(1), RATES(2), RATES(3), RATES(4), RATES(5), RATES(6))
       BACKGND = 0.96*PMMIN
C
       DO 100 I = 1, 6
         RATES(I)  = RATES(I) - BACKGND
 100   CONTINUE       
C
       MAXIMUM = 0
       DO 200 I = 1, 6
         IF(RATES(I) .GE. MAXIMUM)THEN
           MAXIMUM = RATES(I)
           PEAK_STEP = I
         ENDIF
 200   CONTINUE
C
       IF(PEAK_STEP .EQ. 3)THEN
         IF(RATES(1) .GT. 0.8*RATES(2)) RATES(1) = 0.8*RATES(2)
       ELSEIF(PEAK_STEP .EQ. 4)THEN
         IF(RATES(2) .GT. 0.8*RATES(3)) RATES(2) = 0.8*RATES(3)
         IF(RATES(1) .GT. 0.5*RATES(2)) RATES(1) = 0.5*RATES(2)
       ELSEIF(PEAK_STEP .EQ. 5)THEN
         IF(RATES(3) .GT. 0.8*RATES(4)) RATES(3) = 0.8*RATES(4)
         IF(RATES(2) .GT. 0.5*RATES(3)) RATES(2) = 0.5*RATES(3)
         IF(RATES(1) .GT. 0.5*RATES(2)) RATES(1) = 0.5*RATES(2)
       ELSEIF(PEAK_STEP .EQ. 6)THEN           
         IF(RATES(4) .GT. 0.8*RATES(5)) RATES(4) = 0.8*RATES(5)
         IF(RATES(3) .GT. 0.5*RATES(4)) RATES(3) = 0.5*RATES(4)
         IF(RATES(2) .GT. 0.5*RATES(3)) RATES(2) = 0.5*RATES(3)
         IF(RATES(1) .GT. 0.5*RATES(2)) RATES(1) = 0.5*RATES(2)
       ENDIF
C
       RETURN
       END
