!+ Subroutine to set moist aerosol properties independent of bands.
!
! Method:
!	The mean relative humidities are calculated and pointers to
!	the lookup tables are set.
!
! 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_MOIST_AEROSOL_PROPERTIES(N_PROFILE, N_LAYER
     &   , L_LAYER, N_AEROSOL, I_AEROSOL_PARAMETRIZATION, NHUMIDITY
     &   , WATER_MIX_RATIO, T, P, DELTA_HUMIDITY
     &   , MEAN_REL_HUMIDITY, I_HUMIDITY_POINTER
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_field.ucf'
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/layer_distrib.ucf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(IN)
     &     N_PROFILE
!             NUMBER OF PROFILES
     &   , N_LAYER
!             NUMBER OF LAYERS
     &   , N_AEROSOL
!             NUMBER OF AEROSOL SPECIES
     &   , I_AEROSOL_PARAMETRIZATION(NPD_AEROSOL_SPECIES)
!             PARAMETRIZATIONS OF AEROSOL
!             SPECIES
     &   , NHUMIDITY(NPD_AEROSOL_SPECIES)
!             NUMBER OF HUMIDITY VALUES
      INTEGER	!, INTENT(OUT)
     &     I_HUMIDITY_POINTER(NPD_PROFILE, NPD_LAYER)
!             POINTERS TO LOOK-UP TABLES
      LOGICAL	!, INTENT(IN)
     &     L_LAYER
!             LAYER FLAG
      REAL*8	!, INTENT(IN)
     &     WATER_MIX_RATIO(NPD_PROFILE, 0: NPD_LAYER)
!             MIXING RATIO OF WATER VAPOUR
     &   , T(NPD_PROFILE, 0: NPD_LAYER)
!             TEMPERATURES
     &   , P(NPD_PROFILE, 0: NPD_LAYER)
!             PRESSURES
      REAL*8	!, INTENT(OUT)
     &     MEAN_REL_HUMIDITY(NPD_PROFILE, NPD_LAYER)
!             MEAN HUMIDITIES OF LAYERS
     &   , DELTA_HUMIDITY
!             INCREMENT IN HUMIDITY
!
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP VARIABLE
     &   , L
!             LOOP VARIABLE
      REAL*8
     &     MIX_RATIO_SAT(NPD_PROFILE, 0: NPD_LAYER)
!             SATURATED HUMIDITY MIXING RATIO
     &   , RELATIVE_HUMIDITY_BASE(NPD_PROFILE)
!             RELATIVE HUMIDITY AT BASE OF LAYER
     &   , RELATIVE_HUMIDITY_TOP(NPD_PROFILE)
!             RELATIVE HUMIDITY AT TOP OF LAYER
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     QSAT_GILL
!
!
!
!     SET UP ARRAY OF POINTERS TO INCLUDE THE EFFECTS OF HUMIDITY.
!     CALCULATE THE SATURATED MIXING RATIO.
      CALL QSAT_GILL(MIX_RATIO_SAT, T, P
     &   , N_PROFILE, N_LAYER, L_LAYER
     &   , NPD_PROFILE, NPD_LAYER)
!     THE LOOK-UP TABLE IS ASSUMED TO BE UNIFORM IN HUMIDITY.
      DELTA_HUMIDITY=1.0D+00/(NHUMIDITY(1)-1.0D+00)
      IF (L_LAYER) THEN
         DO I=1, N_LAYER
            DO L=1, N_PROFILE
               MEAN_REL_HUMIDITY(L, I)
     &            =WATER_MIX_RATIO(L, I)*(1.0D+00-MIX_RATIO_SAT(L, I))
     &            /((1.0D+00-WATER_MIX_RATIO(L, I))*MIX_RATIO_SAT(L, I))
               I_HUMIDITY_POINTER(L, I)=1
     &            +INT(MEAN_REL_HUMIDITY(L, I)/DELTA_HUMIDITY)
            ENDDO
         ENDDO
      ELSE
         DO L=1, N_PROFILE
            RELATIVE_HUMIDITY_BASE(L)
     &         =WATER_MIX_RATIO(L, 0)*(1.0D+00-MIX_RATIO_SAT(L, 0))
     &         /((1.0D+00-WATER_MIX_RATIO(L, 0))*MIX_RATIO_SAT(L, 0))
         ENDDO
         DO I=1, N_LAYER
            DO L=1, N_PROFILE
               RELATIVE_HUMIDITY_TOP(L)=RELATIVE_HUMIDITY_BASE(L)
               RELATIVE_HUMIDITY_BASE(L)
     &            =WATER_MIX_RATIO(L, I)*(1.0D+00-MIX_RATIO_SAT(L, I))
     &            /((1.0D+00-WATER_MIX_RATIO(L, I))*MIX_RATIO_SAT(L, I))
               MEAN_REL_HUMIDITY(L, I)=RELATIVE_HUMIDITY_BASE(L)
     &            +WEIGHT_UPPER_AEROSOL*(RELATIVE_HUMIDITY_TOP(L)
     &            -RELATIVE_HUMIDITY_BASE(L))
               I_HUMIDITY_POINTER(L, I)=1
     &            +INT(MEAN_REL_HUMIDITY(L, I)/DELTA_HUMIDITY)
            ENDDO
         ENDDO
      ENDIF
!
!
      RETURN
      END
