SUBROUTINE AER_TAU2MIXR &
 & ( KIDIA  , KFDIA  , KLON, KLEV , KAERO, KWHAT, KWAVL, &
 &   PAPH   , PAERTAU, PRHCL, &
 &   PAERMSS &
 & )

!*** * AER_TAU2MIXR* - COMPUTATION OF AEROSOL MASS(ES) FROM OPTICAL DEPTH(S)

!**   INTERFACE.
!     ----------
!          *AER_TAU2MIXR* IS CALLED FROM *CALLPAR*.

!     AUTHOR.
!     -------
!        J.-J. MORCRETTE/ A. BENEDETTI  *ECMWF*

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 2005-09-21

!     PURPOSE.
!     --------
!       produce mass mixing ratio profile from profile of optical thickness 
!       at 550 nm given from the old aerosol climatology

!-----------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOMCST    ,ONLY : RG
USE YOEAEROP  ,ONLY : ALF_SU
USE YOEAERSNK ,ONLY : RRHTAB
!USE YOMLUN    ,ONLY : NULOUT

IMPLICIT NONE

!-----------------------------------------------------------------------

!*       0.1   ARGUMENTS
!              ---------

INTEGER(KIND=JPIM),INTENT(IN)  :: KLON 
INTEGER(KIND=JPIM),INTENT(IN)  :: KIDIA 
INTEGER(KIND=JPIM),INTENT(IN)  :: KFDIA 
INTEGER(KIND=JPIM),INTENT(IN)  :: KLEV
INTEGER(KIND=JPIM),INTENT(IN)  :: KAERO
INTEGER(KIND=JPIM),INTENT(IN)  :: KWAVL, KWHAT

REAL(KIND=JPRB)   ,INTENT(IN)  :: PAPH(KLON,0:KLEV)
REAL(KIND=JPRB)   ,INTENT(IN)  :: PAERTAU(KLON,KLEV,KAERO)
REAL(KIND=JPRB)   ,INTENT(IN)  :: PRHCL(KLON,KLEV)

REAL(KIND=JPRB)   ,INTENT(OUT) :: PAERMSS(KLON,KLEV,KAERO)


!*       0.5   LOCAL VARIABLES
!              ---------------

INTEGER(KIND=JPIM) :: JAER, JK, JL, JTAB
INTEGER(KIND=JPIM) :: IRH(KLON,KLEV)

REAL(KIND=JPRB) :: ZALF(KAERO), ZDP

REAL(KIND=JPRB) :: ZHOOK_HANDLE

!-----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('AER_TAU2MIXR',0,ZHOOK_HANDLE)

!-- units:
!   ------
! ZALF is the extinction coefficient           m2 g-1
! PAEROP is the aerosol mass mixing ratio      kg kg-1
! PCAERO is the optical thickness              ND     (KWHAT=2)

IRH(:,:)=1
PAERMSS(:,:,:)= 0.0_JPRB

IF (KWHAT == 2) THEN 
!-- inputs PCAERO are optical thicknesses at 0.55 microns. From those
! get aerosol mass in kg/kg

!-- define RH index from "clear-sky" (not yet!) relative humidity
  DO JK=1,KLEV
    DO JL=KIDIA,KFDIA
      DO JTAB=1,12
        IF (PRHCL(JL,JK)*100. > RRHTAB(JTAB)) THEN
          IRH(JL,JK)=JTAB
        ENDIF
      ENDDO
    ENDDO
  ENDDO

  DO JAER=1,KAERO
    DO JK=1,KLEV
      DO JL=KIDIA,KFDIA        
        ZALF(JAER)=ALF_SU(IRH(JL,JK),KWAVL)
        PAERMSS(JL,JK,JAER)=0._JPRB

        ZDP=PAPH(JL,JK)-PAPH(JL,JK-1)
        IF (ZALF(JAER) /= 0.0_JPRB .OR. ZDP /=0.0_JPRB ) THEN 
          PAERMSS(JL,JK,JAER)=PAERTAU(JL,JK,JAER)*RG/(ZDP*ZALF(JAER)*1000._JPRB)
        ENDIF
      ENDDO
    ENDDO
  ENDDO
ENDIF
!-----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('AER_TAU2MIXR',1,ZHOOK_HANDLE)
END SUBROUTINE AER_TAU2MIXR

