!+ Subroutine to calculate weightings across a spectral band.
!
! Method:
!	The array ABSCISSA hold the points at which weightings
!	are required. This routine deals with excluded regions
!	in the band. The actual weights are calculated by 
!	WEIGHTINGS_SINGLE for a contiguous band.
!
! 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 WEIGHTINGS(IERR
     &   , I_WEIGHT, L_WAVE_NUMBER
     &   , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD, T
     &   , ABSCISSA_SHORTER, ABSCISSA_LONGER
     &   , N_EXCLUDE, EXCLUDE_SHORTER, EXCLUDE_LONGER
     &   , N_ABSCISSA, ABSCISSA
     &   , I_BEGIN, N_INT_WEIGHT, WEIGHT_COEFF
     &   , WEIGHT_COEFF_EXCLUDE
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/error.pcf'
!
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
!
      INTEGER	!, INTENT(IN)
     &     I_WEIGHT
!             WEIGHTING OPTION
     &   , N_SOLAR_POINTS
!             SIZE OF SOLAR SPECTRUM
     &   , N_ABSCISSA
!             NUMBER OF ABSCISSA POINTS
     &   , N_EXCLUDE
!             NUMBER OF REGIONS TO EXCLUDE
!
      INTEGER	!, INTENT(OUT)
     &     I_BEGIN
!             BEGINNING OF DATA RANGE
     &   , N_INT_WEIGHT
!             NUMBER OF WEIGHTING INTERVALS
!
      LOGICAL	!, INTENT(IN)
     &     L_WAVE_NUMBER
!             ABSCISSA IS WAVENUMBER
!
      REAL*8	!, INTENT(IN)
     &     T
!             TEMPERATURE OF BLACK BODY
     &   , ABSCISSA_SHORTER
!             SHORTER ABSCISSA OF BAND
     &   , ABSCISSA_LONGER
!             LONGER ABSCISSA OF BAND
     &   , ABSCISSA(N_ABSCISSA)
!             ABSCISSAE OF INPUT DATA
     &   , SOLAR_WAVELENGTH(NPD_SOLAR_POINTS)
!             WAVELENGTHS OF SOLAR SPECTRUM
     &   , SOLAR_IRRAD(NPD_SOLAR_POINTS)
!             SOLAR IRRADIANCES AT TOA
     &   , EXCLUDE_SHORTER(NPD_EXCLUDE)
!             SHORTER LIMITS OF EXCLUDED REGIONS.
     &   , EXCLUDE_LONGER(NPD_EXCLUDE)
!             LONGER LIMITS OF EXCLUDED REGIONS.
!
      REAL*8	!, INTENT(OUT)
     &     WEIGHT_COEFF(0: N_ABSCISSA)
!             ABSCISSAE OF WEIGHTINGS
     &   , WEIGHT_COEFF_EXCLUDE(0: N_ABSCISSA)
!             WEIGHTING COEFFICEINTS FOR EXCLUDED REGIONS.
!             (REALLY A WORK ARRAY, BUT PASSED AS AN ARGUMENT
!             BECAUSE OF ITS VARIABLE DIMENSION).
!
!
!     LOCAL VARIABLES
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
     &   , I_BEGIN_EXCLUDE
!             INITIAL POINT OF EXCLUDED REGION
     &   , N_INT_WEIGHT_EXCLUDE
!             NUMBER OF INTERVALS IN EXCLUDED REGION
     &   , OFFSET
!             OFFSET OF BEGINNING OF EXCLUDED REGION
!
      REAL*8
     &     INTEGRAL_WEIGHT
!             INTEGRAL OF WEIGHTING FUNCTION
     &   , INTEGRAL_WEIGHT_EXCLUDE
!             INTEGRAL OF WEIGHTING FUNCTION ACROSS EXCLUDED REGION.
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     WEIGHTINGS_SINGLE
!
!
!
!     CHECK THAT THE RANGE COVERED BY THE DATA IS GREATER THAN THE
!     BAND TO BE TREATED.
      IF ( (ABSCISSA(N_ABSCISSA).LT.ABSCISSA_LONGER).OR.
     &     (ABSCISSA(1).GT.ABSCISSA_SHORTER) ) THEN
         WRITE(IU_ERR, '(/A)')
     &      '*** ERROR: DATA DO NOT COVER THE RANGE TO BE WEIGHTED.'
      ENDIF
!
      CALL WEIGHTINGS_SINGLE(IERR
     &   , I_WEIGHT, L_WAVE_NUMBER
     &   , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD, T
     &   , ABSCISSA_SHORTER, ABSCISSA_LONGER
     &   , N_ABSCISSA, ABSCISSA
     &   , I_BEGIN, N_INT_WEIGHT, WEIGHT_COEFF
     &   , INTEGRAL_WEIGHT
     &   )
      IF (IERR.NE.I_NORMAL) RETURN
!
!     REMOVE CONTRIBUTIONS FROM THE EXCLUDED REGIONS.
      DO I=1, N_EXCLUDE
         CALL WEIGHTINGS_SINGLE(IERR
     &      , I_WEIGHT, L_WAVE_NUMBER
     &      , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD, T
     &      , EXCLUDE_SHORTER(I), EXCLUDE_LONGER(I)
     &      , N_ABSCISSA, ABSCISSA
     &      , I_BEGIN_EXCLUDE, N_INT_WEIGHT_EXCLUDE
     &      , WEIGHT_COEFF_EXCLUDE
     &      , INTEGRAL_WEIGHT_EXCLUDE
     &      )
         IF (IERR.NE.I_NORMAL) RETURN
!
!        ADJUST THE WEIGHTING COEFFICIENTS AND THE INTEGRAL.
         INTEGRAL_WEIGHT=INTEGRAL_WEIGHT-INTEGRAL_WEIGHT_EXCLUDE
         OFFSET=I_BEGIN_EXCLUDE-I_BEGIN
         DO J=0, N_INT_WEIGHT_EXCLUDE
            WEIGHT_COEFF(OFFSET+J)=WEIGHT_COEFF(OFFSET+J)
     &         -WEIGHT_COEFF_EXCLUDE(J)
         ENDDO
      ENDDO
!
!     NORMALIZE BY THE INTEGRAL OF THE WEIGHTING COEFFICIENTS.
      DO J=0, N_INT_WEIGHT
         WEIGHT_COEFF(J)=WEIGHT_COEFF(J)/INTEGRAL_WEIGHT
      ENDDO
!
!
!
      RETURN
      END
