!+ Subroutine to check data and options supplied for consistency.
!
! Method:
!	The options requested are compared with data read from
!	the spectral file to check for consistency.
!
! 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 CHECK_DATA(IERR
     &   , N_PROFILE
     &   , ISOLIR
     &   , L_PRESENT
     &   , L_RAYLEIGH, L_AEROSOL, L_GAS, L_CONTINUUM
     &   , L_CLOUD, I_CLOUD, L_DROP, L_ICE
     &   , L_DROP_TYPE, L_ICE_TYPE, I_DROP, I_ICE
     &   , L_SURFACE, I_SURFACE
     &   , L_DOPPLER_ON, L_DOPPLER_PRESENT, N_ABSORB
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/spectral_region.pcf'
      INCLUDE 'incl/cloud_scheme.pcf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_PROFILE
!             NUMBER OF PROFILES
     &   , ISOLIR
!             VISIBLE OR IR
     &   , I_CLOUD
!             CLOUD SCHEME
     &   , I_DROP
!             DROPLET TYPE
     &   , I_ICE
!             ICE CRYSTAL TYPE
     &   , I_SURFACE(NPD_PROFILE)
!             SURFACE TYPE
     &   , N_ABSORB
!             NUMBER OF GASEOUS ABSORBERS
      LOGICAL	!, INTENT(IN)
     &     L_PRESENT(0: NPD_TYPE)
!             ARRAY OF DATA TYPES PRESENT
     &   , L_RAYLEIGH
!             INCLUDE RAYLEIGH SCATTERING
     &   , L_AEROSOL
!             INCLUDE AEROSOLS
     &   , L_GAS
!             INCLUDE GAS ABSORPTION
     &   , L_CONTINUUM
!             INCLUDE CONTINUUM ABSORPTION
     &   , L_CLOUD
!             INCLUDE CLOUDS
     &   , L_DROP
!             INCLUDE DROPLETS
     &   , L_DROP_TYPE(NPD_DROP_TYPE)
!             DROP TYPES INCLUDED
     &   , L_ICE_TYPE(NPD_ICE_TYPE)
!             ICE CRYSTAL TYPES INCLUDED
     &   , L_ICE
!             INCLUDE ICE
     &   , L_SURFACE(NPD_SURFACE)
!             SURFACE TYPES PRESENT
     &   , L_DOPPLER_ON(NPD_SPECIES)
!             ACTIVATED DOPPLER FLAGS
     &   , L_DOPPLER_PRESENT(NPD_SPECIES)
!             GASES FOR WHICH DOPPLER INFORMATION IS PRESENT
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
!
!
      IF (.NOT.L_PRESENT(7)) THEN
         WRITE(IU_ERR, '(/A)') '*** ERROR: NO SURFACE DATA ARE '
     &      //'INCLUDED IN THE SPECTRAL FILE.'
         IERR=I_ERR_FATAL
         RETURN
      ENDIF
      DO L=1, N_PROFILE
         IF (.NOT.L_SURFACE(I_SURFACE(L))) THEN
            WRITE(IU_ERR, '(A, I5, A)') 
     &         '*** ERROR: THE SURFACE TYPE REQUESTED IS '
     &         , I_SURFACE(L)
     &         , ' NO SURFACE DATA EXIST FOR THIS SURFACE.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDDO
!
      IF (ISOLIR.EQ.IP_SOLAR) THEN
!        THE SPECTRAL FILE MUST CONTAIN SOLAR FLUXES.
         IF (.NOT.L_PRESENT(2)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: SOLAR FLUXES MUST BE INCLUDED IN THE'
     &         , ' SPECTRAL FILE.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDIF
!
      IF (L_RAYLEIGH) THEN
!        CHECK THAT RAYLEIGH SCATTERING DATA ARE PROVIDED.
         IF (.NOT.L_PRESENT(3)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: RAYLEIGH SCATTERING IS TO BE INCLUDED BUT'
            WRITE(IU_ERR, '(A)') 'THE SPECTRAL FILE CONTAINS NO '
     &         //'RAYLEIGH SCATTERING COEFFICIENTS.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDIF
!
      IF (L_AEROSOL) THEN
!        CHECK THAT THE DATA FOR AEROSOLS IS PRESENT.
         IF (.NOT.L_PRESENT(11)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: AEROSOLS ARE TO BE INCLUDED, BUT'
            WRITE(IU_ERR, '(A)') 'THE SPECTRAL FILE CONTAINS NO'
     &         //' AEROSOL DATA.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDIF
!
      IF (L_GAS) THEN
!        CHECK FOR THE PRESENCE OF GASEOUS ABSORPTION DATA.
         IF (.NOT.L_PRESENT(4)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: GASEOUS ABSORPTION IS TO BE INCLUDED, BUT'
            WRITE(IU_ERR, '(A)') 'THE SPECTRAL FILE DOES NOT CONTAIN'
            WRITE(IU_ERR, '(A)') 'A LIST OF ABSORBERS IN EACH BAND.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
!        CHECK FOR THE PRESENCE OF ESFT DATA.
         IF (.NOT.L_PRESENT(5)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: GASEOUS ABSORPTION IS TO BE INCLUDED, BUT'
            WRITE(IU_ERR, '(A)') 'THE SPECTRAL FILE DOES NOT CONTAIN'
            WRITE(IU_ERR, '(A)') 'A LIST OF ESFT TERMS.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDIF
!
      IF (L_CONTINUUM) THEN
!        CHECK CONDITIONS FOR CONTINUUM ABSORPTION.
         IF (.NOT.L_GAS) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: CONTINUUM ABSORPTION IS NOT PERMITTED'
            WRITE(IU_ERR, '(A)') 'WITHOUT GASEOUS LINE ABSORPTION.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
         IF (.NOT.L_PRESENT(9)) THEN
            WRITE(IU_ERR, '(/A)') 
     &         '*** ERROR: CONTINUUM ABSORPTION IS TO BE INCLUDED.'
            WRITE(IU_ERR, '(A)') 'THE SPECTRAL FILE DOES NOT CONTAIN'
            WRITE(IU_ERR, '(A)') 'CONTINUUM EXTINCTION DATA.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
      ENDIF
!
      IF (L_CLOUD) THEN
!        CHECK THE DATA FOR CLOUD ABSORPTION.
         IF (L_DROP) THEN
!           ABSORPTION BY WATER DROPLETS IS INCLUDED.
!           CHECK FOR BLOCKS OF THE RIGHT TYPE.
            IF (.NOT.L_PRESENT(10)) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: EXTINCTION BY DROPLETS IS TO BE INCLUDED.'
               WRITE(IU_ERR, '(A)')
     &            'THE SPECTRAL FILE CONTAINS NO RELEVANT DATA.'
               IERR=I_ERR_FATAL
               RETURN
            ELSE IF (.NOT.L_DROP_TYPE(I_DROP)) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: I_DROP HAS BEEN SET TO A VALUE FOR '
     &            //'WHICH NO DATA EXIST.'
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
         ENDIF
!
         IF (L_ICE) THEN
!           SCATTERING BY ICE CRYSTALS IS INCLUDED.
!           CHECK FOR BLOCKS OF THE RIGHT TYPE.
            IF (.NOT.L_PRESENT(12)) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: EXTINCTION BY ICE CRYSTALS IS TO '
     &            //'BE INCLUDED.'
               WRITE(IU_ERR, '(A)')
     &            'THE SPECTRAL FILE CONTAINS NO RELEVANT DATA.'
               IERR=I_ERR_FATAL
               RETURN
            ELSE IF (.NOT.L_ICE_TYPE(I_ICE)) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: I_ICE HAS BEEN SET TO A VALUE FOR '
     &            //'WHICH NO DATA EXIST.'
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
         ENDIF
!
      ENDIF
!
      DO I=1, N_ABSORB
         IF (L_DOPPLER_ON(I)) THEN
            IF (.NOT.L_DOPPLER_PRESENT(I)) THEN
               WRITE(IU_ERR, '(/A)') 
     &            '*** ERROR: INADEQUATE DOPPLER '
     &            //'BROADENING INFORMATION.'
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
         ENDIF
      ENDDO
!
!
      RETURN
      END
