CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      SUBROUTINE CORRECT_VTH(VTH, VSW)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     Subroutine to correct the solar wind thermal speed from the PM.  The
C     correction is based on the bulk speed and is based on a series of linear
C     fits to several different speed ranges.
C
C FORMAL ARGUMENTS:
C
C     VTH:
C       R*4      I/O	Variable containing the solar wind thermal speed.  Upon
C			return it will contain the corrected solar wind thermal
C			speed.
C
C     VSW:
C       R*4      I	The solar wind speed.
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE CORRECT_VTH(VTH, VSW)
!	    REAL(KIND=4), INTENT(INOUT) :: VTH
!	    REAL(KIND=4), INTENT(IN) :: VSW
!	  END SUBROUTINE CORRECT_VTH
!	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     
C
C CREATED:
C
C     29-JAN-1997    John Paquette
C
C This version:   1.6   16-APR-1999
C
C DEVELOPMENT HISTORY:
C 
C  Author       Date            Description of Change 
C  --------     -----------     --------------------- 
C  J. PAQUETTE  29-JAN-1997     Created
C  J. PAQUETTE  30-JAN-1997     Add 3 more segments for higher Vsw's
C  J. PAQUETTE  31-JAN-1997     New segments from Scott, new correction applied
C  J. PAQUETTE   4-FEB-1997     New segments from Scott
C  J. PAQUETTE   6-FEB-1997     New segments from Scott. Power law fit now 3-part
C  J. PAQUETTE   7-FEB-1997     New high speed segments from meeting today
C  L. Bleau	 1-APR-1999	added comments
C  L. Bleau	16-APR-1999 1.6	added declarations, IMPLICIT NONE
C  L. Bleau	15-NOV-1999	added comments
C  L. Bleau	15-MAR-2000	added comments
C
C-
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CDEC$ IDENT	'1.6'
C
      IMPLICIT NONE
      INTEGER NUM_SEG
      PARAMETER (NUM_SEG=11)
      INTEGER I
      LOGICAL SEGMENT
      REAL*4 VTH, VSW 
      REAL*4 LLIMIT(NUM_SEG)/  0., 350., 365., 377., 424.7, 476, 549.33, 612.44, 700., 770.0, 880.0/
      REAL*4 ULIMIT(NUM_SEG)/350., 365., 377., 424.7, 476, 549.33, 612.44, 700., 770.0, 880.0, 1050.0/
      REAL*4 OFFSET(NUM_SEG)/3.87, 2.8823, 6.2208, -0.50338, 3.9943, -1.7038, 4.6258, -1.818, 
     &                       4.52, -1.78, 2.83/
      REAL*4 SLOPE(NUM_SEG)/-0.007842, -0.00502, -0.014167, 0.0036694, -0.0069207, 0.00505, -0.0064724, 0.00405,
     &                     -0.005, 0.00318, -0.00206/
C
C First correction
C
      IF(VTH .LT. 10.0)THEN
C
C If VTH < 10, correct it as if it were = 10.0
C
        VTH = VTH/(0.17713 * (10.0)**0.47417)
      ELSEIF(VTH .LT. 24.21)THEN
C
C If VTH >= 10 AND < 24.21, correct as shown
C
        VTH = VTH/(0.17713 * (VTH)**0.47417)
      ELSEIF(VTH .LT. 64.95)THEN
C
C If VTH >= 24.21 AND < 64.95, correct as shown
C
        VTH = VTH/(0.096729 * (VTH)**0.6646)
      ELSE
C
C If VTH>= 64.95, correct as shown
C
        VTH = VTH/(1.2274 * (VTH)**0.057698)
      ENDIF
C
C Set flag telling us whether we've found the right segment to .FALSE.
C
      SEGMENT = .FALSE.
C
C Find the segment that the current velocity lies in, then apply correction
C
      I = 1
      DO 200 WHILE((.NOT.SEGMENT).AND.(I .LE. NUM_SEG))
        IF((VSW .GE. LLIMIT(I)).AND.(VSW .LT. ULIMIT(I)))THEN
          VTH =VTH/(OFFSET(I) + VSW*SLOPE(I))
          SEGMENT = .TRUE. 
        ENDIF
        I = I + 1
 200  CONTINUE
C
      RETURN
      END
