CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      SUBROUTINE CORRECT_VSW(VSW)
C+
C
C FUNCTIONAL DESCRIPTION:
C
C     Subroutine to correct the solar wind speed from the PM.  The correction
C     is based on the speed itself, and is based on a series of linear fits to
C     several different speed ranges. 
C
C FORMAL ARGUMENTS:
C
C     VSW:
C       R*4	  I/O	Variable containing the input solar wind speed.  Upon
C			return it will contain the corrected solar wind speed.
C
C INTERFACE:
C
!	INTERFACE
!	  SUBROUTINE CORRECT_VSW(VSW)
!	    REAL(KIND=4), INTENT(INOUT) :: VSW
!	  END SUBROUTINE CORRECT_VSW
!	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.4   10-FEB-1997
C
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     New segments (Fred's "version F")
C  J. PAQUETTE  31-JAN-1997     New segments (Fred's "version G")
C  J. PAQUETTE  31-JAN-1997     New segments (Fred's "version G9"); eliminate upper limit test, 
C                               mean division
C  J. PAQUETTE  10-FEB-1997     If Vsw < lower limit of fit, then apply correction factor 
C                               corresponding to the lower limit.
C  L. Bleau	 1-APR-1999	added comments
C  L. Bleau	16-APR-1999	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.4'
C
      IMPLICIT NONE
      INTEGER NUM_SEGMENTS
      PARAMETER (NUM_SEGMENTS=17)
      INTEGER I
      LOGICAL SEGMENT
      REAL*4 VSW 
      REAL*4 LLIMIT(NUM_SEGMENTS)/250., 352., 360., 380., 435., 450., 460., 468., 474., 485., 495., 540., 
     &                            595., 625., 740., 800., 930./
      REAL*4 ULIMIT(NUM_SEGMENTS)/352., 360., 380., 435., 450., 460., 468., 474., 485., 495., 540., 595., 
     &                            625., 740., 800., 930., 9999./
      REAL*4 OFFSET(NUM_SEGMENTS)/0.5959, 1.01, 1.55, 0.9109, 0.7, 0.775, 1.2925, 2.326, 1.7586, 1.45, 1.01, 0.4591, 
     &                            1.9917, 0.7326, 1.2367, 0.8469, 0.99/
      REAL*4 INV_SLOPE(NUM_SEGMENTS) /850., 1.E15, -666.7, 5500., 1500., 2000., -1600., -352.9, -611.1, -1000., -9000., 1100.0, 
     &                                -600.0, 2875.0, -3000.0, 6500.0, 1.E15/
C
C Set flag telling us whether we've found the right segment to .FALSE.
C
      SEGMENT = .FALSE.
C
C If Vsw < lower limit of fit, apply the correction factor corresponding to the lower limit
C
      IF(VSW .LT. LLIMIT(1))THEN
        VSW =VSW/(OFFSET(1) + LLIMIT(1)/INV_SLOPE(1))
        SEGMENT = .TRUE.
      ENDIF
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_SEGMENTS))
        IF((VSW .GE. LLIMIT(I)).AND.(VSW .LT. ULIMIT(I)))THEN
          VSW =VSW/(OFFSET(I) + VSW/INV_SLOPE(I))
          SEGMENT = .TRUE. 
        ENDIF
        I = I + 1
 200  CONTINUE
C
      RETURN
      END
