!+ Subroutine to make spectral blocks of type 9.
!
! Method:
!       Straightforward.
!
! 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_9(IERR
     &   , N_BAND, N_BAND_CONTINUUM, INDEX_CONTINUUM
     &   , K_CONTINUUM, I_SCALE_FNC_CONT, SCALE_CONTINUUM
     &   , P_REF_CONTINUUM, T_REF_CONTINUUM
     &   , L_PRESENT_9
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/def_pp_io.icf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/physical_constants_0.ccf'
      INCLUDE 'incl/continuum.pcf'
      INCLUDE 'incl/scale_fnc.pcf'
      INCLUDE 'incl/file_type.pcf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_BAND
!             NUMBER OF BANDS
     &   , N_BAND_CONTINUUM(NPD_BAND)
!             NUMBER OF CONTINUA IN BANDS
     &   , INDEX_CONTINUUM(NPD_BAND, NPD_CONTINUUM)
!             LIST OF ACTIVE CONTINUA
     &   , I_SCALE_FNC_CONT(NPD_BAND, NPD_CONTINUUM)
!             SCALING FUNCTIONS FOR CONTINUA
      LOGICAL	!, INTENT(OUT)
     &     L_PRESENT_9
!             PRESENCE FLAG
      REAL*8	!, INTENT(OUT)
     &     K_CONTINUUM(NPD_BAND, NPD_CONTINUUM)
!             CONTINUUM EXTINCTIONS
     &   , SCALE_CONTINUUM(NPD_SCALE_VARIABLE, NPD_BAND, NPD_CONTINUUM)
!             CONTINUUM SCALING PARAMETERS
     &   , P_REF_CONTINUUM(NPD_CONTINUUM, NPD_BAND)
!             CONTINUUM REFERENCE PRESSURE
     &   , T_REF_CONTINUUM(NPD_CONTINUUM, NPD_BAND)
!             CONTINUUM REFERENCE TEMPERATURE
!
!     LOCAL ARGUMENTS.
      CHARACTER
     &     LINE*80
!             INPUT LINE
      INTEGER
     &     I_INPUT_TYPE
!             TYPE OF INPUT FILE
     &   , I_INDEX
!             INDEX NUMBER OF CONTINUUM
     &   , I_BAND
!             NUMBER OF BAND
     &   , I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      LOGICAL
     &     L_INDEX_BAND(NPD_BAND, NPD_SPECIES)
!             CONTINUA PRESENT
     &   , NON_BLANK
!             FUNCTION TO DETECT BLANK LINES
      REAL*8
     &     DUMMY
!             DUMMY READING VARIABLE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_FILE_IN
!
!
      INCLUDE 'incl/scale_fnc.dcf'
!
!
!
!     OBTAIN THE BAND DATA FORM THE PREPARED FILE OF ESFT TERMS.
      CALL OPEN_FILE_IN(IERR, IU_ESFT
     &   , 'ENTER THE NAME OF THE FILE CONTAINING THE CONTINUUM FIT.')
      IF (IERR.NE.I_NORMAL) RETURN
!
!
!     ASSEMBLE THE LIST OF INDEXING NUMBERS.
      DO I=1, N_BAND
         DO J=1, NPD_CONTINUUM
            L_INDEX_BAND(I, J)=.FALSE.
         ENDDO
         DO J=1, N_BAND_CONTINUUM(I)
            L_INDEX_BAND(I, INDEX_CONTINUUM(I, J))=.TRUE.
         ENDDO
      ENDDO
!
100      READ(IU_ESFT, '(15X, I5, //)', END=999) I_INPUT_TYPE
         IF (I_INPUT_TYPE.NE.IT_FILE_CONT_FIT) THEN
            WRITE(IU_ERR, '(/A)')
     &         '*** ERROR: THE INPUT FILE IS OF AN INVALID TYPE.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
         READ(IU_ESFT, '(14X, I5, 21X, I5)') I_BAND, I_INDEX
!
!        FIND THE POSITION OF THIS DATUM IN THE ARRAY OF CONTINUA.
         IF (.NOT.L_INDEX_BAND(I_BAND, I_INDEX)) THEN
            WRITE(IU_ERR, '(/A)')
     &         '*** ERROR: THE CONTINUUM DATA AND THE SPECTRAL '
     &         //'FILE ARE INCONSISTENT.'
            IERR=I_ERR_FATAL
            RETURN
         ENDIF
!
         READ(IU_ESFT, '(18X, 1PE10.3, 21X, 1PE10.3)')
     &      P_REF_CONTINUUM(I_INDEX, I_BAND)
     &    , T_REF_CONTINUUM(I_INDEX, I_BAND)
         READ(IU_ESFT, '(//)')
!        READ OVER THE TRANSMISSION DATA.
2        READ(IU_ESFT, '(A)') LINE
         IF (NON_BLANK(LINE)) GOTO 2
         READ(IU_ESFT, '(/, 74X, I5, //)')
     &      I_SCALE_FNC_CONT(I_BAND, I_INDEX)
         READ(IU_ESFT, '(2(3X, 1PE16.9), (T39, 2(3X, 1PE16.9)))')
     &      K_CONTINUUM(I_BAND, I_INDEX), DUMMY
     &         , (SCALE_CONTINUUM(L, I_BAND, I_INDEX)
     &         , L=1, N_SCALE_VARIABLE(I_SCALE_FNC_CONT(I_BAND
     &         , I_INDEX)))
         READ(IU_ESFT, '(/)')
         GOTO 100
!
999   L_PRESENT_9=.TRUE.
      CLOSE(IU_ESFT)
!
!
      RETURN
      END
