      SUBROUTINE AEROSOLS(MHSCH3,MHSCH5,AMSU6,PCLOUD,HEIGHT,
     +                    SAMOUNT,SPOT,QCFLAG,RADT8M,RCLOUD,
     +                    RADTC8,RADT8C,DENOMTH,SFCPRS,AEROSOL)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- AEROSOLS
C
C   LANGUAGE- FORTRAN      TYPE- SUBROUTINE        COMPUTER- IBM SP
C
C   VERSION- 1.0    DATE-  3/17/06    PROGRAMMER- FRANK TILLEY (ERT)
C   VERSION- 2.0    DATE- 12/27/07    PROGRAMMER- FRANK TILLEY (IMSG)
C      SIMPLIFIED THE FUNCTION AND REMOVED UNNEEDED CALLING ARGUMENTS.
C   VERSION- 2.1    DATE-  5/29/08    PROGRAMMER- FRANK TILLEY (IMSG)
C      ADDED MHS CHANNEL 3 AND TERRAIN HEIGHT TO THE CALLING ARGUMENTS
C      AND ADDED CODE TO DETECT AEROSOLS OVER HIGH TERRAIN.
C   VERSION- 3.0    DATE- 3/11/09     PROGRAMMER- FRANK TILLEY (IMSG)
C      ADAPTED FROM LOGICAL FUNCTION ISAEROSOL
C
C   FUNCTION - THIS SUBROUTINE CALCULATES A CLOUD AMOUNT USING ALGORITHMS
C              USED FOR AEROSOLS.
C
C   CALLING ARGUMENTS-
C      VARIABLE          TYPE I/O FUNCTION
C      --------          ---- --- --------
C      MHSCH3            REAL  I  MHS CHANNEL 3 BRIGHTNESS TEMPERATURE
C      MHSCH5            REAL  I  MHS CHANNEL 5 BRIGHTNESS TEMPERATURE
C      AMSU6             REAL  I  LIMB-CORRECTED AMSU-A CHANNEL 6
C                                 BRIGHTNESS TEMPERATURE.
C      PCLOUD            REAL  I  CLOUD TOP PRESSURE.
C      HEIGHT            INT   I  TERRAIN HEIGHT IN METERS.
C      SAMOUNT           REAL I/O CLOUD AMOUNT
C      SPOT              INT   I  SPOT NUMBER IN 2X2 BOX
C      QCFLAG            INT  I/O QC FLAG
C      RADT8M            REAL  I  RADIANCE OF HIRS 8 SURFACE TEMPERATURE
C                                 ESTIMATE.
C      RCLOUD            REAL  I  RADIANCE OF CLOUD TOP TEMPERATURE AT
C                                 HIRS 8 FREQUENCY
C      RADTC8            REAL  I  RADIANCE OF PREDICTED CLEAR BRIGHTNESS
C                                 TEMPERATURE WITH NO ADJUSTMENT FOR
C                                 MOISTURE
C      RADT8C            REAL  I  RADIANCE OF PREDICTED CLEAR BRIGHTNESS      
C                                 TEMPERATURE ADJUSTED FOR MOISTURE
C      DENOMTH           REAL  I  THRESHOLD BELOW WHICH A DENOMINATOR 
C                                 VALUE CAUSES THE SPOT TO BE MARKED AS
C                                 CLEAR 
C      SFCPRS            REAL  I  FORECAST SURFACE PRESSURE.
C      AEROSOL           LOG   O  FLAG SET TO TRUE IF THE RESULTING QC
C                                 FLAG IS 2 OR 6.
C
C   SUBPROGRAMS CALLED- NONE
C
C   COMMON AREAS- NONE
C
C**********************************************************************
C
      REAL MHSCH3, MHSCH5, AMSU6, PCLOUD, SAMOUNT, RCLOUD, RADT8M
      REAL RADT8C, RADTC8, DENOMTH, SFCPRS

      INTEGER HEIGHT,QCFLAG(4),SPOT

      LOGICAL AEROSOL
C
      REAL RNUM, RDENOM, DELTER, DELPRS
C      
      AEROSOL = .FALSE.

C -- RECOMPUTE EFFECTIVE CLOUD AMOUNT WITH ONE OF TWO AEROSOL
C    ALGORITHMS AND THEN MAKE ADJUSTMENTS
C
C-- AEROSOL ADJUSTMENT FOR HIGH TERRAIN ATTENUATION
C
      DELTER = 1.0
      IF (HEIGHT.GT.1000) THEN
         IF ((RADT8M/RADT8C) .LT. 1.0) THEN
            DELTER = (RADT8M/RADT8C)
         END IF
      END IF
C
C-- AEROSOL PRESSURE ADJUSTMENT
C
      DELPRS = ALOG(PCLOUD) / ALOG(SFCPRS) 
C
      IF ((RADT8C - RADT8M) .GT. 0.0) THEN
c
         QCFLAG(SPOT) = 2
         RNUM = RADT8C - RADT8M
         RDENOM = RADT8C
         AEROSOL = .TRUE.
         IF (RDENOM .LE. DENOMTH) THEN
            AEROSOL = .FALSE.
            GO TO 1000
         END IF
C
         SAMOUNT = (RNUM / RDENOM) * DELPRS * DELTER
C
         IF (SAMOUNT .LE. 0.001) THEN
            AEROSOL = .FALSE.
            GO TO 1000
         END IF
C
      ELSE

         QCFLAG(SPOT) = 6
         RNUM=1.0
         RDENOM=(RADT8M-RADTC8)*(EXP(RADT8M/RADTC8))
         AEROSOL = .TRUE.
         SAMOUNT = (RNUM / RDENOM) * DELPRS * DELTER
C
         IF (SAMOUNT.LE.0.001) THEN
            AEROSOL = .FALSE.
            GO TO 1000
         END IF
      END IF
C
 1000 CONTINUE
      RETURN
      END
