!+ Subroutine to set amounts of gases from a file.
!
! Method:
!	A file is opened and read to find directives. These 
!	directives set the number of amounts of the gases and
!	the minimum and maximum amounts.
!
! 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 SET_AMOUNT_FILE(IERR
     &   , N_ABSORB, TYPE_ABSORB, L_GEN_LOWTRAN
     &   , N_AMOUNT, L_GAS_REQUIRED, U
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/gas_list.pcf'
      INCLUDE 'incl/gas_list.ncf'
      INCLUDE 'incl/error.pcf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     N_ABSORB
!             NUMBER OF ABSORBERS
     &   , TYPE_ABSORB(NPD_SPECIES)
!             TYPE NUMBERS OF ABSORBERS
      LOGICAL	!, INTENT(IN)
     &     L_GEN_LOWTRAN(NPD_GASES)
!             FLAG TO GENERATE LOWTRAN DATA
      INTEGER	!, INTENT(OUT)
     &     N_AMOUNT
!             NUMBER OF AMOUNTS
      LOGICAL	!, INTENT(OUT)
     &     L_GAS_REQUIRED(NPD_SPECIES)
!             GASES FOR WHICH DATA ARE REQUIRED
      REAL*8	!, INTENT(OUT)
     &     U(NPD_GASES, NPD_AMOUNT)
!             AMOUNTS OF GASES
!
!
!     LOCAL VARIABLES.
!
      LOGICAL
     &     LOCK_CODE
!             LOGICAL TO FORBID INTERACTIVE LOOPING
      EXTERNAL
     &     LOCK_CODE
!
      CHARACTER
     &     LINE*80
!             LINE READ FROM FILE
     &   , WORD*16
!             SUBSTRING OF DATA
      INTEGER
     &     I_BEGIN
!             BEGINNING OF SUBSTRING
     &   , I_END
!             END OF SUBSTRING
      INTEGER
     &     IGAS
!             TYPE NUMBER OF GAS
     &   , IOS
!             I/O ERROR FLAG
     &   , I
!             LOOP VARIABLE
     &   , J
!             LOOP VARIABLE
      LOGICAL
     &     L_NUMBER_SET
!             TRUE ONCE NUMBER IS SET
     &   , L_DONE
!             FLAG FOR ASSIGNMENT
      REAL*8
     &     AMOUNT_MIN
!             MINIMUM AMOUNT
     &   , AMOUNT_MAX
!             MAXIMUM AMOUNT
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     OPEN_FILE_IN, READ_WORD
!
!
      INCLUDE 'incl/gas_names.dcf'
!
!
!
!     OPEN THE FILE SETTING THE AMOUNTS.
      CALL OPEN_FILE_IN(IERR, IU_FILE_IN
     &   , 'ENTER NAME OF FILE CONTAINING SETTINGS OF AMOUNTS.')
!
!     READ LINES UNTIL A DIRECTIVE IS FOUND.
      IOS=0
      L_NUMBER_SET=.FALSE.
      DO WHILE (IOS.EQ.0)
         READ(IU_FILE_IN, '(A)', END=1) LINE
!
!        CHECK LINES FOR DIRECTIVES.
         IF (LINE(1:7).EQ.'*NUMBER') THEN
            I_BEGIN=8
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(I16)', IOSTAT=IOS) N_AMOUNT
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: THE NUMBER OF AMOUNTS IS INCORRECTLY SET.'
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
            L_NUMBER_SET=.TRUE.
!
         ELSE IF (LINE(1:7).EQ.'*AMOUNT') THEN
!           PROCESS THE REMAINDER OF THE LINE TO EXTRACT THE DATA.
            I_BEGIN=8
            CALL READ_WORD(IERR, LINE, 80, I_BEGIN, I_END, WORD)
            IF (IERR.NE.I_NORMAL) RETURN
            READ(WORD, '(I16)', IOSTAT=IOS) IGAS
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: GAS 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) AMOUNT_MIN
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: MINIMUM AMOUNT 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) AMOUNT_MAX
            IF (IOS.NE.0) THEN
               WRITE(IU_ERR, '(/A)')
     &            '*** ERROR: MAXIMUM AMOUNT IS INCORRECTLY SPECIFIED '
     &            //' IN LINE:'
               WRITE(IU_ERR, '(A)') LINE
               IERR=I_ERR_FATAL
               RETURN
            ENDIF
!
!           CHECK WHETHER THE GAS IS IN THE FILE.
            I=1
            L_DONE=.FALSE.
            DO WHILE ( (I.LE.N_ABSORB).AND.(.NOT.L_DONE) )
               IF (TYPE_ABSORB(I).EQ.IGAS) THEN
!                 CHECK THAT THE GAS IS RECOGNIZED BY LOWTRAN.
                  IF (L_GEN_LOWTRAN(I)) THEN
                     L_GAS_REQUIRED(I)=.TRUE.
                     DO J=1, N_AMOUNT
                        U(IGAS, J)
     &                     =EXP((1.0D+00/DBLE(N_AMOUNT-1))
     &                     *(DBLE(J-1)*LOG(AMOUNT_MAX)
     &                     +DBLE(N_AMOUNT-J)*LOG(AMOUNT_MIN)))
                     ENDDO
                  ELSE
                     L_GAS_REQUIRED(I)=.FALSE.
                  ENDIF
                  L_DONE=.TRUE.
               ENDIF
               I=I+1
            ENDDO
         ENDIF
      ENDDO
!
1     CLOSE(IU_FILE_IN)
!
!
      RETURN
      END
