!+ Subroutine to calculate densities.
!
! Method:
!	This routine calculates the density of air and the molar
!	densities of the broadening species for the self and foreign-
!	broadened continua using the gas law including the effect
!	of water vapour.
!
! 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 CALCULATE_DENSITY(N_PROFILE, N_LAYER, L_CONTINUUM
     &   , WATER_FRAC, P, T, I_TOP
     &   , DENSITY, MOLAR_DENSITY_WATER, MOLAR_DENSITY_FRN
     &   )
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/physical_constants_0.ccf'
      INCLUDE 'incl/physical_constants_1.ccf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     N_PROFILE
!             NUMBER OF PROFILES
     &   , N_LAYER
!             NUMBER OF LAYERS
     &   , I_TOP
!             TOP VERTICAL INDEX
      LOGICAL
     &     L_CONTINUUM
!             CONTINUUM FLAG
      REAL*8	!, INTENT(IN)
     &     WATER_FRAC(NPD_PROFILE, 0: NPD_LAYER)
!             MASS FRACTION OF WATER
     &   , P(NPD_PROFILE, 0: NPD_LAYER)
!             PRESSURE
     &   , T(NPD_PROFILE, 0: NPD_LAYER)
!             TEMPERATURE
      REAL*8	!, INTENT(OUT)
     &     DENSITY(NPD_PROFILE, 0: NPD_LAYER)
!             AIR DENSITY
     &   , MOLAR_DENSITY_WATER(NPD_PROFILE, 0: NPD_LAYER)
!             MOLAR DENSITY OF WATER
     &   , MOLAR_DENSITY_FRN(NPD_PROFILE, 0: NPD_LAYER)
!             MOLAR DENSITY OF FOREIGN SPECIES
!
!     LOCAL VARIABLES.
      INTEGER
     &     L
!             LOOP VARIABLE
     &   , I
!             LOOP VARIABLE
!
!
!     FIND THE AIR DENSITY FIRST.
      DO I=I_TOP, N_LAYER
         DO L=1, N_PROFILE
            DENSITY(L, I)=P(L, I)/(R_GAS_DRY*T(L, I)
     &         *(1.0D+00+(RATIO_MOLAR_WEIGHT-1.00D+00)
     &         *WATER_FRAC(L, I)))
         ENDDO
      ENDDO
!
      IF (L_CONTINUUM) THEN
         DO I=I_TOP, N_LAYER
            DO L=1, N_PROFILE
               MOLAR_DENSITY_FRN(L, I)=DENSITY(L, I)
     &            *(1.0D+00-WATER_FRAC(L, I))/MOL_WEIGHT_AIR
               MOLAR_DENSITY_WATER(L, I)=DENSITY(L, I)
     &            *WATER_FRAC(L, I)*(RATIO_MOLAR_WEIGHT/MOL_WEIGHT_AIR)
            ENDDO
         ENDDO
      ENDIF
!
!
      RETURN
      END
