!+ Function to calculate the solar irradiance at a given wavelength.
!
! Method:
!	The wavelength is bracketed between two points of the solar
!	spectrum and linear interpolation is used in the interval.
!	At long wavelngths a Rayleigh-Jeans tail is used.
!
! 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. 
!
!- ---------------------------------------------------------------------
      FUNCTION SOLAR_INTENSITY(LAMBDA
     &   , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/astron_constants.ccf'
!
!     DUMMY ARGUMENTS
!
      REAL*8	!, INTENT(OUT)
     &     SOLAR_INTENSITY
!             RETURNED INTENSITY
!
      INTEGER	!, INTENT(IN)
     &     N_SOLAR_POINTS
!             NUMBER OF SPECTRAL POINTS
      REAL*8	!, INTENT(IN)
     &     LAMBDA
!             WAVELENGTH
     &   , SOLAR_WAVELENGTH(NPD_SOLAR_POINTS)
!             WAVELENGTHS OF SPECTRUM
     &   , SOLAR_IRRAD(NPD_SOLAR_POINTS)
!             SOLAR IRRADIANCE AT TOA
!
!     LOCAL VARIABLES.
      INTEGER
     &     I_SHORT
!             ARRAY POINT JUST BELOW LAMBDA
     &   , I_LONG
!             ARRAY POINT JUST ABOVE LAMBDA
      REAL*8
     &     FRACTION
!             FRACTION OF INTERVAL COVERED
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     POINT_BRACKET
!
!     FUNCTIONS CALLED:
      REAL*8
     &     PLANCK
!             PLANCKIAN FUNCTION
      EXTERNAL
     &     PLANCK
!
!
!
!     FIND THE POINTS OF THE WAVELENGTH ARRAY BRACKETTING LAMBDA.
      CALL POINT_BRACKET(LAMBDA, N_SOLAR_POINTS, SOLAR_WAVELENGTH
     &   , I_SHORT, I_LONG)
!
!     IF LAMBDA LIES WITHIN THE RANGE COVERED WE INTERPOLATE: IF NOT
!     USE A SIMPLE EXTRAPOLATION
      IF (I_SHORT.EQ.0) THEN
!        LAMBDA IS AT A WAVELENGTH SHORTER THAN ANY IN THE SPECTRUM.
         SOLAR_INTENSITY=0.0D+00
      ELSE IF (I_LONG.GT. N_SOLAR_POINTS) THEN
!        USE A BLACK BODY FIT AT THE EFFECTIVE TEMPERATURE.
         SOLAR_INTENSITY=PLANCK(T_EFFECTIVE_SOLAR, LAMBDA)
     &      *(SUN_RADIUS/D_EARTH_SUN)**2
      ELSE
!        WITHIN THE SPECTRUM USE LINEAR INTERPOLATION.
         FRACTION=(LAMBDA-SOLAR_WAVELENGTH(I_SHORT))
     &       /(SOLAR_WAVELENGTH(I_LONG)-SOLAR_WAVELENGTH(I_SHORT))
         SOLAR_INTENSITY=FRACTION*SOLAR_IRRAD(I_LONG)
     &      +(1.0D+00-FRACTION)*SOLAR_IRRAD(I_SHORT)
      ENDIF
!
!
      RETURN
      END
