!+ Subroutine to read a solar spectrum.
!
! Method:
!	The solar spetrum is read a a file of irradiances against
!	wavelengths.
!
! 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 READ_SOLAR_SPECTRUM(IERR, L_SOLAR_SPECTRUM
     &   , N_SOLAR_POINTS, SOLAR_WAVELENGTH, SOLAR_IRRAD)
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/def_pp_io.icf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
     &   , N_SOLAR_POINTS
!             NUMBER OF SOLAR DATA POINTS
      LOGICAL	!, INTENT(OUT)
     &     L_SOLAR_SPECTRUM
!             SOLAR SPECTRAL FLAG
      REAL*8	!, INTENT(OUT)
     &     SOLAR_WAVELENGTH(NPD_SOLAR_POINTS)
!             WAVELENGTHS FOR IRRADIANCE
     &   , SOLAR_IRRAD(NPD_SOLAR_POINTS)
!             SOLAR IRRADIANCE AT TOA
!
!     LOCAL VARIABLES.
      CHARACTER
     &     LINE*80
!             LINE OF INPUT DATA
      INTEGER
     &     IOS
!             I/O ERROR FLAG
     &   , I
!             LOOP VARIABLE
      LOGICAL
     &     L_DATA_REGION
!             FLAG FOR REGION OF DATA WITHIN FILE.
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_FILE_IN
!
!
!
!     OBTAIN THE FILE CONTAINING THE SOLAR SPECTRUM.
      CALL OPEN_FILE_IN(IERR, IU_SOLAR 
     &   , 'ENTER THE NAME OF THE FILE CONTAINING '
     &   //'THE SOLAR IRRADIANCE DATA.'
     &   )
      IF (IERR.NE.I_NORMAL) RETURN
!
!     READ IN THE FILE.
      L_DATA_REGION=.FALSE.
      I=0
3     READ(IU_SOLAR, '(A)', END=4) LINE
         IF (L_DATA_REGION) THEN
            IF (LINE(1:4).NE.'*END') THEN
               BACKSPACE(IU_SOLAR)
               I=I+1
               IF (I.GE.NPD_SOLAR_POINTS) THEN
                  WRITE(IU_ERR, '(A)')
     &               '*** ERROR: THERE ARE TOO MANY POINTS IN THE'
     &               //'SOLAR_SPECTRUM.'
                  IERR=I_ERR_FATAL
                  RETURN
               ENDIF
               READ(IU_SOLAR, *, IOSTAT=IOS)
     &            SOLAR_WAVELENGTH(I), SOLAR_IRRAD(I)
               IF (IOS.NE.0) THEN
                  WRITE(IU_ERR, '(A)')
     &               '*** ERROR: THE SOLAR_SPECTRUM COULD NOT BE READ.'
                  IERR=I_ERR_IO
                  RETURN
               ENDIF
            ELSE
               L_DATA_REGION=.FALSE.
            ENDIF
         ELSE
            IF (LINE(1:11).EQ.'*BEGIN_DATA') THEN
               L_DATA_REGION=.TRUE.
            ENDIF
         ENDIF
!
      GOTO 3
!
4     CLOSE(IU_SOLAR)
      N_SOLAR_POINTS=I
!
!
!     CHECK THAT READING WAS CARRIED OUT: FAILURE TO READ THE DATA
!     WILL CAUSE N_SOLAR_POINTS TO BE 0.
      IF (N_SOLAR_POINTS.EQ.0) THEN
         WRITE(IU_ERR, '(/A, /A)') '*** ERROR: NO DATA WERE READ.'
     &      , 'CHECK FORMAT OF FILE OF IRRADIANCES.'
      ENDIF
!
!     NOW THE SPECTRUM HAS BEEN READ, SET THE READING FLAG.
      L_SOLAR_SPECTRUM=.TRUE.
!
!
      RETURN
      END
