CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
	SUBROUTINE FISH(PM_RATE, CURRENTTIME, SPEED, VTH, DEN_FI, MOMENTS)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     Hybrid of Hefti and Fred
C
C COMMON BLOCKS:
C
C    None
C
C INCLUDE FILES:
C
C    None
C
C CREATED:
C
C    18-FEB-1997   by   John Paquette
C
C This version:   1.9    5-MAY-1998
C
C DEVELOPMENT HISTORY:
C
C  Author       Date            Description of Change 
C  --------     -----------     --------------------- 
C  J. PAQUETTE  18-FEB-1997     Created (from HEFFALUMP)
C  J. PAQUETTE  20-FEB-1997     Weight rates with V**-2 not V**-4
C  J. PAQUETTE  24-FEB-1997     New constants (and an entirely new correction) for Vth;
C                               new constants for density
C  J. PAQUETTE  24-FEB-1997     Correct error in density
C  J. PAQUETTE  25-FEB-1997     New density algorithm
C  J. PAQUETTE  10-NOV-1997     Use variable background
C  J. PAQUETTE  10-NOV-1997     Derive background from subroutine
C  J. PAQUETTE  20-NOV-1997     Background taken care of elsewhere
C  J. PAQUETTE   4-DEC-1997     Renamed to FISH
C  J. PAQUETTE   5-MAY-1998     New time decay; also, allow for for bias change on 4/18/98
C  L. Bleau	19-APR-1999	added IMPICIT NONE, declarations
C 
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CDEC$   IDENT	'1.9'
	IMPLICIT NONE
	REAL*8 SLP_V
	PARAMETER (SLP_V = 4.6901D2)
	REAL*8 OFF_V
	PARAMETER (OFF_V = 2.2249D1)
	REAL*8 SLP_VTH
	PARAMETER (SLP_VTH = 2.8972D2)
	REAL*8 OFF_VTH
	PARAMETER (OFF_VTH = -9.4D-1)
	REAL*8 SEC06MAR962110
	PARAMETER (SEC06MAR962110 = 1204837800.D0)
	REAL*8 SEC10JUN961855
	PARAMETER (SEC10JUN961855 = 1213124100.D0)
	REAL*8 SEC18APR980000
        PARAMETER (SEC18APR980000 = 1271548800.D0)
	REAL*8 SEC01JAN960000
	PARAMETER (SEC01JAN960000 = 1199145600.D0)
        INTEGER*4 PM_RATE(6), FLAG, I
	REAL*8 PMRATE(6), SQRTPMEQ(6), BACKGND
	REAL*8 PMEQ(6)/0.302,0.474,0.758,1.228,1.962,3.149/
	REAL*8 SPEED, VTH, MOMENT0, MOMENTS(2), CURRENTTIME, DEN_FI
C
	MOMENT0 = 0.0
	MOMENTS(1) = 0.0
	MOMENTS(2) = 0.0
C
C Convert rates to REAL*8; Calculate square root of E/Q voltages
C
	DO 10 I=1, 6
          PMRATE(7-I) = PM_RATE(I)
	  SQRTPMEQ(I) = SQRT(PMEQ(I))
10	CONTINUE
C
C Background taken care of elsewhere
C
        BACKGND = 0.0
C
C Get measured rates, correct for E/Q window
C	 
	DO 20 I=1, 6
C
C Background (Ipavich)
C
	  PMRATE(I) = DMAX1(0.0D0, PMRATE(I) - BACKGND)
C
C Account for E/Q window for moments
C
	  PMRATE(I) = PMRATE(I)/PMEQ(I)
C
C Total for density
C
	  MOMENT0 = MOMENT0 + PMRATE(I)
20	CONTINUE
C
	CALL HEFMOM(SQRTPMEQ, PMRATE, MOMENTS)
	SPEED = MOMENTS(1)
	VTH   = SQRT(MOMENTS(2))
C
C Apply corrections (in any case)
C	
	SPEED = SPEED * SLP_V + OFF_V
        VTH    = VTH * SLP_VTH + OFF_VTH
C
C Further correction for Vth
C
        IF(VTH .LT. 20.0)THEN
          VTH=VTH/(0.2 + 0.041997*VTH)
        ELSEIF(VTH .LT. 60.0)THEN
          VTH=VTH/(1.0545 - 7.3106E-4*VTH)
        ELSE
          VTH=VTH/(1.412 - 0.0066897*VTH)
        ENDIF
C
        MOMENT0 = MOMENT0/1.D4
        DEN_FI = 0.22 * MOMENT0
C
C Renormalize density if time is before Mar 6 1996 at 2110, when bias changed (PM MCP bias=level 150
C before 6 MAR 96, 155 thereafter). Since the bias increased, and we are normalizing the early data 
C to the data after Mar 6, the density from before Mar 6 must be increased
C
	IF (CURRENTTIME .LT. SEC06MAR962110) DEN_FI = DEN_FI * 1.28897
C
C On Jun 10, the threshold was changed. Since we are normalizing the data after Jun 10 to the data 
C in the interval from Mar 6 to Jun 10, after the threshold change, density after Jun 10 must be 
C increased.
C
	IF (CURRENTTIME .GE. SEC10JUN961855) DEN_FI = DEN_FI * 0.620065
C
C On Apr 16, 1998 MTOF was turned off due to loss of Vf referenced voltages and a high main current.
C It remained off for all of the 17th and most of the 18th. When the PM was turned back on, the MCP
C bias was increased to 160. As a result, desities after that date must be decreased.
C
        IF (CURRENTTIME .GE. SEC18APR980000) DEN_FI = DEN_FI / 1.9
C
C Remove decay in density caused by loss of MCP gain. At first, the decay was exponential, with a 
C relatively short time constant. Then the rate of decay slowed. As a result the function chosen to 
C fit the decay was of the form A*EXP(-T/B) + C*EXP(-T/D) + E, where the additive contant is 
C inserted to guarantee that the MCP gain does not reach zero.
C
        DEN_FI = DEN_FI/(1.6331*EXP(-(CURRENTTIME - SEC01JAN960000)/5.1858E6) + 
     &           0.54036*EXP(-(CURRENTTIME - SEC01JAN960000)/8.4945E7) + 0.05)
C
        IF (DEN_FI .LT. 0.0) DEN_FI = 0.0
        IF (SPEED .LT. 100.0) SPEED = 100.0
        IF (VTH   .LT. 0.0) VTH   = 0.0
C
        RETURN
        END
