!+ Subroutine to select weighting for scattering.
!
! Method:
!	The weighting function for the monochromatic single
!	scattering properties is selected by the user from a
!	menu of possible functions. The user also sets the method 
!	of weighting, that is, thin or thick averaging.
!	
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	Version		Date			Comment
!	1.0		12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77  with extensions listed in documentation.
!
!- ---------------------------------------------------------------------
      SUBROUTINE SELECT_WEIGHT_SCATTER(IERR, I_WEIGHT, T_WEIGHT
     &   , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD
     &   , I_METHOD_WEIGHT)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/method_weight.pcf'
      INCLUDE 'incl/weighting.pcf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY VARIABLES.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
     &   , I_WEIGHT
!             TYPE OF WEIGHTING FUNCTION
     &   , I_METHOD_WEIGHT
!             METHOD OF WEIGHTING
     &   , N_SOLAR_POINTS
!             SIZE OF SOLAR SPECTRUM
      REAL*8	!, INTENT(OUT)
     &     SOLAR_WAVELENGTH(NPD_SOLAR_POINTS)
!             POINTS OF SOLAR SPECTRUM
     &   , SOLAR_IRRAD(NPD_SOLAR_POINTS)
!             SOLAR IRRADIANCES
     &   , T_WEIGHT
!             WEIGHTING TEMPERATURE
!
!
!     LOCAL VARIABLES
!
      LOGICAL
     &     LOCK_CODE
!             LOGICAL TO FORBID INTERACTIVE LOOPING
      EXTERNAL
     &     LOCK_CODE
!
      INTEGER
     &     IOS
!             I/O FLAG
      LOGICAL
     &     L_SOLAR_SPECTRUM
!             LOGICAL FOR READING OF SPECTRUM
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SOLAR_SPECTRUM
!
!
!
!     DISPLAY MENU OF WEIGHTING FUNCTIONS.
      WRITE(IU_USER, '(/A)')
     &   'SELECT THE TYPE OF WEIGHTING FUNCTION.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_PLANCK
     &   , '. PLANCKIAN WEIGHTING AT A GIVEN TEMPERATURE.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_DPLANCK
     &   , '. DIFFERENTIAL PLANCKIAN WEIGHTING AT A GIVEN  '
     &   //'TEMPERATURE.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_SOLAR
     &   , '. TOA SOLAR SPECTRAL WEIGHTING.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_UNIFORM
     &   , '. UNIFORM WEIGHTING.'
      WRITE(IU_USER, '(A/)') 'ENTER REQUIRED NUMBER.'
1     READ(IU_STDIN, *, IOSTAT=IOS) I_WEIGHT
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(A)') '+++ ERRONEOUS RESPONSE:'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error.finc'
         ELSE
            WRITE(IU_USER, '(A)') 'PLEASE: RE-ENTER.'
            GOTO 1
         ENDIF
      ENDIF
      IF ( (I_WEIGHT.NE.IP_WEIGHT_PLANCK).AND.
     &     (I_WEIGHT.NE.IP_WEIGHT_DPLANCK).AND.
     &     (I_WEIGHT.NE.IP_WEIGHT_SOLAR).AND.
     &     (I_WEIGHT.NE.IP_WEIGHT_UNIFORM) ) THEN
         WRITE(IU_ERR, '(A)') '+++ RESPONSE OUT OF RANGE:'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error.finc'
         ELSE
            WRITE(IU_USER, '(A)') 'PLEASE RE-ENTER.'
            GOTO 1
         ENDIF
      ENDIF
!
      IF ( (I_WEIGHT.EQ.IP_WEIGHT_PLANCK)
     &   .OR.(I_WEIGHT.EQ.IP_WEIGHT_DPLANCK) ) THEN
         WRITE(IU_USER, '(/A)')
     &      'SPECIFY THE TEMPERATURE FOR WEIGHTING.'
2        READ(IU_STDIN, *, IOSTAT=IOS) T_WEIGHT
         IF (IOS.NE.0) THEN
            WRITE(IU_ERR, '(A)') '+++ UNRECOGNIZED RESPONSE: '
            IF (LOCK_CODE(.TRUE.)) THEN
               INCLUDE 'batch_error.finc'
            ELSE
               WRITE(IU_USER, '(A)') 'PLEASE RE-TYPE.'
               GOTO 2
            ENDIF
         ENDIF
      ENDIF
!
!     IF SOLAR WEIGHTING IS USED READ THE DATA IN.
      IF (I_WEIGHT.EQ.IP_WEIGHT_SOLAR) THEN
         CALL READ_SOLAR_SPECTRUM(IERR, L_SOLAR_SPECTRUM
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
         IF (IERR.NE.I_NORMAL) RETURN
      ENDIF
!
!     DISPLAY MENU OF METHODS OF WEIGHTING.
      WRITE(IU_USER, '(/A)')
     &   'SELECT THE METHOD OF WEIGHTING THE OPTICAL PROPERTIES.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_THIN
     &   , '. SIMPLE AVERAGING OF SINGLE SCATTERING PROPERTIES.'
      WRITE(IU_USER, '(3X, I2, A)' ) IP_WEIGHT_THICK
     &   , '. THICK AVERAGING OF REFLECTION.'
      WRITE(IU_USER, '(A/)') 'ENTER REQUIRED NUMBER.'
3     READ(IU_STDIN, *, IOSTAT=IOS) I_METHOD_WEIGHT
      IF (IOS.NE.0) THEN
         WRITE(IU_ERR, '(A)') '+++ ERRONEOUS RESPONSE:'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error.finc'
         ELSE
            WRITE(IU_USER, '(A)') 'PLEASE: RE-ENTER.'
            GOTO 3
         ENDIF
      ENDIF
!
      IF ( (I_METHOD_WEIGHT.NE.IP_WEIGHT_THIN).AND.
     &     (I_METHOD_WEIGHT.NE.IP_WEIGHT_THICK) ) THEN
         WRITE(IU_ERR, '(A)') '+++ RESPONSE OUT OF RANGE:'
         IF (LOCK_CODE(.TRUE.)) THEN
            INCLUDE 'batch_error.finc'
         ELSE
            WRITE(IU_USER, '(A)') 'PLEASE RE-ENTER.'
            GOTO 3
         ENDIF
      ENDIF
!
!
!
      RETURN
      END
