!+ Subroutine to read continuum reference p and T from a file.
!
! Method:
!	The name of the file is requested. The file is opened 
!	and read. Directives encoutered are processed.
!
! 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_CONT_REF_PT(IERR
     &   , N_ABSORB, TYPE_ABSORB
     &   , N_INDEX, LIST_INDEX, N_INDEX_BAND, LIST_BAND
     &   , P_REFERENCE, T_REFERENCE
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/continuum.pcf'
      INCLUDE 'incl/continuum.ncf'
      INCLUDE 'incl/error.pcf'
!
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_ABSORB
!             NUMBER OF ABSORBERS
     &   , TYPE_ABSORB(NPD_SPECIES)
!             TYPES OF ABSORBERS
     &   , N_INDEX
!             NUMBER OF INDICES IN DATA
     &   , LIST_INDEX(NPD_SET)
!             LIST OF INDEX TYPES
     &   , N_INDEX_BAND(NPD_SPECIES)
!             NUMBER OF BANDS FOR EACH INDEX
     &   , LIST_BAND(NPD_SPECIES, NPD_BAND)
!             LIST OF BANDS IN WHICH INDEX FALLS
      REAL*8	!, INTENT(OUT)
     &     P_REFERENCE(NPD_SPECIES, NPD_BAND)
!             REFERENCE PRESSURES FOR SCALING
     &   , T_REFERENCE(NPD_SPECIES, NPD_BAND)
!             REFERENCE PRESSURES FOR SCALING
!
!     LOCAL VARIABLES.
      CHARACTER
     &     LINE*80
!             LINE READ FROM INPUT FILE
     &   , WORD*16
!             SUBSTRING OF INPUT LINE
      INTEGER
     &     I_BEGIN
!             BEGINNING OF SUBSTRING
     &   , I_END
!             END OF SUBSTRING
      INTEGER
     &     IOS
!             I/O ERROR FLAG
     &   , I_FIRST_BAND
!             FISRT BAND IN LIST
     &   , I_LAST_BAND
!             FISRT BAND IN LIST
     &   , I_CONTINUUM
!             TYPE OF CONTINUUM CONSIDERED
     &   , I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
     &   , K
!             LOOP VARIABLE
      LOGICAL
     &     L_DONE
!             FLAG SET TO TRUE ON COMPLETION OF ASSIGNMENT
      REAL*8
     &     P0
!             PRESSURE READ FROM FILE
     &   , T0
!             TEMPERATURE READ FROM FILE
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_FILE_IN, READ_WORD
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/continuum_names.dcf'
!
!
!
      CALL OPEN_FILE_IN(IERR, IU_FILE_IN
     &  , 'ENTER THE NAME OF THE FILE SETTING '
     &  //'THE REFERENCE CONDITIONS.')
!
!     SET THE REFERENCE CONDITIONS IN THE REQUIRED BANDS TO NEGATIVE
!     VALUES TO FLAG THE ABSENCE OF DATA.
      DO J=1, N_INDEX
         I=LIST_INDEX(J)
         DO K=1, N_INDEX_BAND(I)
            P_REFERENCE(I, LIST_BAND(I, K))=-1.0D+00
            T_REFERENCE(I, LIST_BAND(I, K))=-1.0D+00
         ENDDO
      ENDDO

!     READ THE FILE LOOKING FOR THE DIRECTIVE "*REF".
1     CONTINUE
         READ(IU_FILE_IN, '(A)', END=999) LINE
         IF (LINE(1:4).EQ.'*REF') THEN
!           PROCESS THE REMAINDER OF THE LINE TO EXTRACT THE DATA.
            I_BEGIN=6
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(I16)', IOSTAT=IOS) I_FIRST_BAND
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: FIRST BAND IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            I_BEGIN=I_END+1
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(I16)', IOSTAT=IOS) I_LAST_BAND
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: LAST BAND IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            I_BEGIN=I_END+1
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(I16)', IOSTAT=IOS) I_CONTINUUM
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: CONTINUUM IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            I_BEGIN=I_END+1
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
!           REAL VALUES ARE READ WITH ".0" IN THE FORMAT. A DECIMAL
!           POINT, IF PRESENT, WILL OVERIDE THE "0"; BUT IF NO POINT
!           IS PRESENT, NO CHARACTERS ARE TAKEN AS LYING TO THE RIGHT
!           THEREOF.
            READ(WORD, '(E16.0)', IOSTAT=IOS) P0
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: PRESSURE IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            I_BEGIN=I_END+1
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(E16.0)', IOSTAT=IOS) T0
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: TEMPERATURE IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
            I=1
            L_DONE=.FALSE.
            DO WHILE ( (I.LE.NPD_CONTINUUM).AND.(.NOT.L_DONE) )
               IF (I_CONTINUUM.EQ.I) THEN
!                 THE CONTINUUM IS IN THE SEPCTRUM SO THE REFERENCE
!                 PRESSURE AND TEMPERATURE ARE SET.
                  DO J=I_FIRST_BAND, I_LAST_BAND
                     P_REFERENCE(I, J)=P0
                     T_REFERENCE(I, J)=T0
                  ENDDO
                  L_DONE=.TRUE.
               ENDIF
               I=I+1
            ENDDO
         ENDIF
      GOTO 1
!
999   CLOSE(IU_FILE_IN)
!
!     CHECK THAT REFERENCE CONDITIONS ARE SET IN ALL THE REQUIRED BANDS.
      DO J=1, N_INDEX
         I=LIST_INDEX(J)
         DO K=1, N_INDEX_BAND(I)
            IF ( (P_REFERENCE(I, LIST_BAND(I, K)).LT.0.0D+00).OR.
     &           (T_REFERENCE(I, LIST_BAND(I, K)).LT.0.0D+00) ) THEN
               WRITE(IU_ERR, '(/A, /A20, A9, I5)')
     &            '*** ERROR: REFERENCE CONDITIONS ARE MISSING FOR '
     &            , NAME_CONTINUUM(I)
     &            , ' IN BAND ', LIST_BAND(I, K)
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
         ENDDO
      ENDDO
!
!
      RETURN
      END
