!+ Subroutine to make spectral blocks of type 3.
!
! Method:
!	A solar spectrum is read if necessary. The monochromatic
!	Rayeligh sattering coefficients are calculated and 
!	weighted with the solar spectrum.
!
! 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 MAKE_BLOCK_3(IERR
     &   , N_BAND, WAVE_LENGTH_SHORT, WAVE_LENGTH_LONG
     &   , L_SOLAR_SPECTRUM, N_SOLAR_POINTS
     &   , SOLAR_WAVELENGTH, SOLAR_IRRAD
     &   , RAYLEIGH_COEFFICIENT, L_PRESENT_3
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_BAND
!             NUMBER OF BANDS
      INTEGER	!, INTENT(INOUT)
     &     N_SOLAR_POINTS
!             NUMBER OF SOLAR SPECTRAL POINTS
      LOGICAL	!, INTENT(INOUT)
     &     L_SOLAR_SPECTRUM
!             FLAG FOR SOLAR SPECTRUM
      LOGICAL	!, INTENT(OUT)
     &     L_PRESENT_3
!             PRESENCE FLAG
      REAL*8	!, INTENT(IN)
     &     WAVE_LENGTH_SHORT(NPD_BAND)
!             BOTTOM OF EACH BAND
     &   , WAVE_LENGTH_LONG(NPD_BAND)
!             TOP OF EACH BAND
      REAL*8	!, INTENT(INOUT)
     &     SOLAR_WAVELENGTH(NPD_SOLAR_POINTS)
!             SOLAR WAVELENGTHS
     &   , SOLAR_IRRAD(NPD_SOLAR_POINTS)
!             SOLAR IRRADIANCE
      REAL*8	!, INTENT(OUT)
     &     RAYLEIGH_COEFFICIENT(NPD_BAND)
!             RAYLEIGH COEFICIENTS BANDS
!
!     LOCAL VARIABLES
      INTEGER
     &     N_INT
!             NUMBER OF INTERVALS FOR INTEGRATION
     &   , I_BEGIN
!             BEGINNING OF SPECTRUM IN BAND
     &   , I_END
!             END OF SPECTRUM IN BAND
     &   , I_DUMMY
!             DUMMY READING VARIABLE
     &   , I
!             LOOP VARIABLE
     &   , K
!             LOOP VARIABLE
      REAL*8
     &     WAVE_INT(NPD_SOLAR_POINTS)
!             WAVELNGTHS FOR INTEGRATION
     &   , WEIGHT_INT(NPD_SOLAR_POINTS)
!             WEIGHTING SOLAR IRRADIANCES
     &   , PRODUCT_INT(NPD_SOLAR_POINTS)
!             IRRADIANCE TIMES RAYLEIGH COEF.
!
!     FUNCTIONS CALLED:
      REAL*8
     &     RAYLEIGH_SCATTER
!             FUNCTION FOR RAYLEIGH SCATTERING
     &   , SOLAR_INTENSITY
!             FUNCTION FOR INTENSITY
     &   , TRAPEZOID
!             TRAPEZOIDAL INTEGRATION FUNCTION
      EXTERNAL
     &     RAYLEIGH_SCATTER, SOLAR_INTENSITY, TRAPEZOID
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     READ_SOLAR_SPECTRUM, INNER_BRACKET, POINT_BRACKET
!
!
!
!     IF A SOLAR SPECTRUM IS ALREADY PRESENT THAT IS USED, OTHERWISE
!     ONE IS READ IN.
      IF (L_SOLAR_SPECTRUM) THEN
         WRITE(IU_USER, '(/A)')
     &      'RAYLEIGH SCATTERING COEFFICIENTS WILL BE AVERAGED USING '
         WRITE(IU_USER, '(A/)')
     &      'THE SOLAR SPECTRUM READ IN EARLIER.'
      ELSE
         CALL READ_SOLAR_SPECTRUM(IERR, L_SOLAR_SPECTRUM
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
         IF (IERR.NE.I_NORMAL) RETURN
      ENDIF
!
!     IN EACH BAND THE SCATTERING COEFFICIENT IS AVERAGED AT THE POINTS
!     OF THE SOLAR SPECTRUM AND THE LIMITS OF THE BAND.
      DO I=1, N_BAND
         CALL POINT_BRACKET(WAVE_LENGTH_SHORT(I)
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH
     &      , I_DUMMY, I_BEGIN)
         CALL POINT_BRACKET(WAVE_LENGTH_LONG(I)
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH
     &      , I_END, I_DUMMY)
!        I_BEGIN AND I_END ARE THE POINTS OF THE SOLAR SPECTRUM
!        JUST WITHIN THE BAND. FORM AN ARRAY OF WAVELENGTH POINTS FOR
!        INTEGRATION
         N_INT=1
         WAVE_INT(N_INT)=WAVE_LENGTH_SHORT(I)
         WEIGHT_INT(N_INT)=SOLAR_INTENSITY(WAVE_INT(N_INT)
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
         PRODUCT_INT(N_INT)=WEIGHT_INT(N_INT)
     &      *RAYLEIGH_SCATTER(WAVE_INT(N_INT))
         DO K=I_BEGIN, I_END
            N_INT=N_INT+1
            WAVE_INT(N_INT)=SOLAR_WAVELENGTH(K)
            WEIGHT_INT(N_INT)=SOLAR_INTENSITY(WAVE_INT(N_INT)
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
            PRODUCT_INT(N_INT)=WEIGHT_INT(N_INT)
     &         *RAYLEIGH_SCATTER(WAVE_INT(N_INT))
         ENDDO
         N_INT=N_INT+1
         WAVE_INT(N_INT)=WAVE_LENGTH_LONG(I)
         WEIGHT_INT(N_INT)=SOLAR_INTENSITY(WAVE_INT(N_INT)
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
         PRODUCT_INT(N_INT)=WEIGHT_INT(N_INT)
     &      *RAYLEIGH_SCATTER(WAVE_INT(N_INT))
         RAYLEIGH_COEFFICIENT(I)=
     &      TRAPEZOID(N_INT, WAVE_INT, PRODUCT_INT)
         RAYLEIGH_COEFFICIENT(I)=
     &      RAYLEIGH_COEFFICIENT(I)
     &      /TRAPEZOID(N_INT, WAVE_INT, WEIGHT_INT)
      ENDDO
!
      L_PRESENT_3=.TRUE.
!
!
      RETURN
      END
