SUBROUTINE RADTR_ML(KSAT,KSENSOR,KDPROF,KPROF,KMXCH,KNCH,PRCH,&
 & LDCLOUD,&
 & PZENANG,PAZIANG,PSOLZENANG,PSOLAZIANG,PLAT,POROG,&
 & PPRESF5,PTF5,PQF5,PO3F5,PCLWF5,PCIWF5,PCCF5,YDGEMSPROF,&
 & PPSSAT,PTSSAT,PLSSAT,PT2SAT,PH2SAT,PCTOP,PCAMT,&
 & PUSSAT,PVSSAT,PEMIS,PTBCLR,PTBTOT,PTAU,PRADCLDLEV,PCLDLEV,POBS,PVAROUT,PTAUSFC)  

!**** *RADTR_ML* - INTERFACE TO TOVS RAD. TRANSFER CODE

!     PURPOSE.
!     -------
!     SET UP REASONABLE CHUNKS OF WORK FOR THE TOVS RADIANCE
!     CALCULATION. RT INPUT IS ON MODEL LEVELS

!**   INTERFACE.
!**   ---------
!**   *CALL* * RADTR_ML( )*  (FROM TOVCLR)
!     WHERE PZENANG: Satellite zenith Angle
!           PAZIANG: Satellite azimuth angle
!           PSOLZENANG: Solar zenith angle
!           PSOLAZIANG: Solar azimuth angle
!           PLAT:    Latitude [deg]
!           POROG:   Orography [m^2 s^-2]
!           KSAT   : NOAA-sateliite id
!           KSENSOR: Sensor id
!           KNCH   : Number of channels to be computed
!           PRCH   : List of channels to be computed
!           KDPROF : First dimension of arrays
!           KPROF  : Actual number of TOVS points
!           PLSSAT : MODEL SURFACE TYPE
!           PEMIS  : Surface emissivity for each channel
!           PTBCLR : Clear brightness temperatures  (output)
!           PTBTOT : Total brightness temperatures  (output)
!           POBS   : Observed brightness temperatures (optional input)
!           PVAROUT: Various optional output for emis/skin temp retrieval
!           PTAUSFC  : Transmittance to surface    (output)

!**   EXTERNALS
!     ---------
!        RTTOV   - RT-CODE

!     MODIFICATIONS
!     -------------
!     Erik Andersson 920304 : DOCTORize and multi-task.
!     Erik Andersson 920818 : New version of RT-code
!     Erik Andersson 921216 : Remove regression extrapolation
!     Erik Andersson 970220 : F90, simplify code.
!     Roger Saunders 970811 : Made surface emissivity, cloud and ozone
!                               variables
!     Erik Andersson 971117 : Add ozone profile input
!     Rose Munro     980108 : Add satellite view angle input
!     Rose Munro     980624 : Alter tests on max/min regr. prof. for new RT
!     Roger Saunders 980815 : Modified for RTTOV5 new interface
!     Niels Bormann  010921 : Output transmittances for AMV/SATOB obs oper.,
!                             correct dimensions of ztau,zradov for new RTTOV 
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        O.Spaniel     Oct-2004 cleaning AL29
!     Niels Bormann  Dec 2007 : New routine (based on RADTRCLD) for RTTOV-9
!     Richard Engelen  081015 : Archive total transmittance for use in blacklist
!     Alan Geer      Jul 2008 : Fix units for orography (IFS uses m^2 s^-2)
!     Richard Engelen  090210 : More flexible interface between tracers and RTTOV input
!     ------------------------------------------------------------------

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

USE YOMVAR   , ONLY : LTOVSCV  , LCLDSINK
USE YOMDIM   , ONLY : NFLEVG
USE YOMDIMO  , ONLY :   NMXTCHU  ,&
 & NPTNAV    ,NPNSAV   ,NPNSSV   ,NPNCV   
USE YOMTVRAD , ONLY :NJPPF    , MSENSOR_AIRS, MSENSOR_IASI, &
 & AIRSCHAN_BACK, IASICHAN_BACK, LABORT_RTTOV_FAILURE
USE YOMANCS  , ONLY : RMDI, NMDI
USE YOM_YGFL , ONLY : NGHG
USE YOMCST   , ONLY : RG
USE TYPE_GEMS_PROFILES
USE YOMCOSJO , ONLY : JOT
USE YOMCOCTP , ONLY : NSATEM

USE YOMLUN, ONLY : NULERR

IMPLICIT NONE

!*    0.1  Global arrays

INTEGER(KIND=JPIM),INTENT(IN)    :: KDPROF 
INTEGER(KIND=JPIM),INTENT(IN)    :: KPROF
INTEGER(KIND=JPIM),INTENT(IN)    :: KSAT
INTEGER(KIND=JPIM),INTENT(IN)    :: KSENSOR
INTEGER(KIND=JPIM),INTENT(IN)    :: KMXCH 
INTEGER(KIND=JPIM),INTENT(IN)    :: KNCH(KDPROF)
LOGICAL,           INTENT(IN)    :: LDCLOUD
REAL(KIND=JPRB)   ,INTENT(IN)    :: PZENANG(KDPROF),PCTOP(KDPROF),PCAMT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAZIANG(KDPROF)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSOLZENANG(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSOLAZIANG(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRCH(KDPROF,KMXCH) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PPRESF5(KDPROF,NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTF5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQF5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PO3F5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLWF5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCIWF5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCCF5(KDPROF,0:NFLEVG)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PPSSAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSSAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLSSAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PT2SAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PH2SAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUSSAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVSSAT(KDPROF) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEMIS(KDPROF,KMXCH) 
TYPE (TYPE_GEMSPROF)   ,INTENT(IN) :: YDGEMSPROF(KDPROF,NGEMS)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTBCLR(KDPROF,KMXCH) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTBTOT(KDPROF,KMXCH)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PTAU(KDPROF,KMXCH,NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PRADCLDLEV(KDPROF,KMXCH,NFLEVG+1)
REAL(KIND=JPRB)   ,INTENT(OUT), OPTIONAL   :: PTAUSFC(KDPROF,KMXCH) 
REAL(KIND=JPRB)   ,INTENT(OUT), OPTIONAL   :: PCLDLEV(KDPROF,KMXCH) 
INTEGER(KIND=JPIM), DIMENSION(NJPPF*NMXTCHU) :: ICHID,IPFID
INTEGER(KIND=JPIM), DIMENSION(NJPPF)         :: ISURF
INTEGER(KIND=JPIM), DIMENSION(NJPPF)         :: INCH
INTEGER(KIND=JPIM), DIMENSION(NJPPF)         :: IFAIL
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU):: ZTBCLR ! Clear brightness temperatures
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU):: ZRADCLR! Clear radiances (mw/cm-1/ster/sq.m) 
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU):: ZTBTOT ! Total brightness temperatures
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU):: ZRADTOT! Total radiances (mw/cm-1/ster/sq.m) 
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU):: ZRADCLD! 100% cloudy radiances (mw/cm-1/ster/sq.m) 
REAL(KIND=JPRB)   ,INTENT(IN), OPTIONAL    :: POBS(KDPROF,KMXCH)
REAL(KIND=JPRB)   ,INTENT(OUT), OPTIONAL   :: PVAROUT(KDPROF,KMXCH,4)


REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU)           :: ZTAUSFC,ZEM
REAL(KIND=JPRB), DIMENSION(NFLEVG+1,NJPPF)          :: ZPPRES
REAL(KIND=JPRB), DIMENSION(NFLEVG+1,NPTNAV+2,NJPPF) :: ZPROF
REAL(KIND=JPRB), DIMENSION(NPNSAV,NJPPF)            :: ZPROFS
REAL(KIND=JPRB), DIMENSION(NPNSSV,NJPPF)            :: ZPROFSS
REAL(KIND=JPRB), DIMENSION(NPNCV,NJPPF)             :: ZPROFCV
REAL(KIND=JPRB), DIMENSION(NJPPF)                   :: ZLAT,ZOROG
REAL(KIND=JPRB), DIMENSION(NJPPF)                   :: ZZENANG,ZAZIANG
REAL(KIND=JPRB), DIMENSION(NJPPF)                   :: ZSOLZENANG,ZSOLAZIANG
REAL(KIND=JPRB), DIMENSION(NFLEVG+1,KMXCH*NJPPF)    :: ZRADCLDLEV,ZTAU
REAL(KIND=JPRB), DIMENSION(NJPPF*NMXTCHU)           :: ZOBS
REAL(KIND=JPRB), DIMENSION(4,NJPPF*NMXTCHU)         :: ZVAROUT

!*         Local variables for Cloud detection (AIRS & IASI only)
REAL(KIND=JPRB) :: Z_D0,Z_D1,Z_XINC,Z_XLEVSAVE
INTEGER(KIND=JPIM) :: IFOUND


INTEGER(KIND=JPIM) :: IPACK,IFIN,IEND,IDONE,ICHPF,IMXCHPF
INTEGER(KIND=JPIM) :: JJPACK,JJPF,JCH,JLEV,JF,JP

LOGICAL :: LL_LINTERP
LOGICAL :: LL_RETR_EMIS_TSKIN
LOGICAL, DIMENSION(4) :: LLTRACER
CHARACTER(LEN=80) :: CLERROR

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

IF (LHOOK) CALL DR_HOOK('RADTR_ML',0,ZHOOK_HANDLE)

LL_LINTERP = .TRUE.

LL_RETR_EMIS_TSKIN = PRESENT(POBS) .AND. PRESENT(PVAROUT)

!*    1.0  Number of packets
!*    ------------------------------------------------------------------

IPACK=KPROF/NJPPF+1
IFIN=MOD(KPROF,NJPPF)
IF(IFIN == 0) THEN
  IPACK=IPACK-1
  IFIN=NJPPF
ENDIF

!*    1.1  Allocate RTTOV temporary arrays
!*    ------------------------------------------------------------------

IMXCHPF=KMXCH*NJPPF
CALL RTTOV_EC_ALLOC(IFAIL, KSAT, IMXCHPF, NJPPF, NFLEVG+1, &
 &    LDCLOUD, LL_LINTERP,                                 &
 &    1_JPIM)


!*    2.0  Make packets, Call RT-code.
!*    ------------------------------------------------------------------

IDONE=0
PACKET_LOOP: DO JJPACK=1,IPACK
  IFAIL(:)=0

  IF(JJPACK == IPACK) THEN
    IEND=IFIN
  ELSE
    IEND=NJPPF
  ENDIF

!*    2.1  Profile variables, surface, T2m, q2m, Ts and Ps.
!*         Ozon, cloud pressure and amount, emissivity
!*         Surface indicators and angles

  PF_LOOP_S: DO JJPF=1,IEND


    ZPPRES(1:NFLEVG,JJPF)=PPRESF5(JJPF+IDONE,1:NFLEVG)/100._JPRB
    ZPPRES(NFLEVG+1,JJPF)=PPSSAT(JJPF+IDONE)/100._JPRB

    ZPROF(1:NFLEVG,1,JJPF) = PTF5(JJPF+IDONE,1:NFLEVG)
    ZPROF(NFLEVG+1,1,JJPF) = PTF5(JJPF+IDONE,NFLEVG)
    ZPROF(1:NFLEVG,2,JJPF) = PQF5(JJPF+IDONE,1:NFLEVG)
    ZPROF(NFLEVG+1,2,JJPF) = PQF5(JJPF+IDONE,NFLEVG)
    ZPROF(1:NFLEVG,3,JJPF) = PO3F5(JJPF+IDONE,1:NFLEVG)
    ZPROF(NFLEVG+1,3,JJPF) = PO3F5(JJPF+IDONE,NFLEVG)

    ZPROFS(1,JJPF)=PT2SAT(JJPF+IDONE)
    ZPROFS(2,JJPF)=PH2SAT(JJPF+IDONE)
    ZPROFS(3,JJPF)=PPSSAT(JJPF+IDONE)/100._JPRB
    ZPROFS(4,JJPF)=PUSSAT(JJPF+IDONE)
    ZPROFS(5,JJPF)=PVSSAT(JJPF+IDONE)
    ZPROFSS(1,JJPF)=PTSSAT(JJPF+IDONE)
    IF(LTOVSCV .AND. LCLDSINK) THEN
      ZPROFCV(1,JJPF)=MIN(MAX(PCTOP(JJPF+IDONE),51.0_JPRB),1012.0_JPRB)     ! cloud top pressure
      ZPROFCV(2,JJPF)=MIN(MAX(PCAMT(JJPF+IDONE),0.0_JPRB),1.0_JPRB)     ! cloud amount
    ELSE
      ZPROFCV(1,JJPF)= 500.0_JPRB     ! cloud top pressure
      ZPROFCV(2,JJPF)= 0.0_JPRB       ! cloud amount
    ENDIF

    ZZENANG(JJPF)=PZENANG(JJPF+IDONE)
    ZAZIANG(JJPF)=PAZIANG(JJPF+IDONE)
    ZSOLZENANG(JJPF)=PSOLZENANG(JJPF+IDONE)
    ZSOLAZIANG(JJPF)=PSOLAZIANG(JJPF+IDONE)
    ZLAT(JJPF)  =PLAT(JJPF+IDONE)
    ZOROG(JJPF) =POROG(JJPF+IDONE)/RG ! convert to m
    IF(PLSSAT(JJPF+IDONE)  <=  0.5_JPRB) THEN
      ISURF(JJPF)=1
    ELSE
      ISURF(JJPF)=0
    ENDIF
  ENDDO PF_LOOP_S

  IF(LDCLOUD)THEN
    DO JJPF=1,IEND
      ZPROF(1:NFLEVG,4,JJPF) = PCLWF5(JJPF+IDONE,1:NFLEVG)
      ZPROF(NFLEVG+1,4,JJPF) = PCLWF5(JJPF+IDONE,NFLEVG)
      ZPROF(1:NFLEVG,5,JJPF) = PCIWF5(JJPF+IDONE,1:NFLEVG)
      ZPROF(NFLEVG+1,5,JJPF) = PCIWF5(JJPF+IDONE,NFLEVG)
      ZPROF(1:NFLEVG,6,JJPF) = PCCF5(JJPF+IDONE,1:NFLEVG)
      ZPROF(NFLEVG+1,6,JJPF) = PCCF5(JJPF+IDONE,NFLEVG)
    ENDDO
  ELSE
    ZPROF(:,4:6,1:IEND) = 0.0_JPRB
  ENDIF

!*    2.2  Additional gases

  LLTRACER(:)=.FALSE.
  IF(NGHG > 0) THEN
    DO JF=1,NGEMS
      DO JJPF=1,IEND
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210061) JP=7 !CO2
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210063) JP=8 !N2O
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210062) JP=9 !CH4
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210061) LLTRACER(1)=.TRUE. !CO2
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210063) LLTRACER(2)=.TRUE. !N2O
        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210062) LLTRACER(3)=.TRUE. !CH4
        ZPROF(1:NFLEVG,JP,JJPF) = YDGEMSPROF(JJPF+IDONE,JF)%MODELPROF(1:NFLEVG)
        ZPROF(NFLEVG+1,JP,JJPF) = YDGEMSPROF(JJPF+IDONE,JF)%MODELPROF(NFLEVG)
      ENDDO
    ENDDO
  ENDIF 
! The following bit has not been tested yet
!  IF(NGRG > 0) THEN
!    DO JF=1,NGEMS
!      DO JJPF=1,IEND
!        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210123) JP=10 !CO
!        IF(YDGEMSPROF(JJPF+IDONE,JF)%IGRIB == 210123) LLTRACER(4)=.TRUE. !CO
!        ZPROF(1:NFLEVG,JP,JJPF) = YDGEMSPROF(JJPF+IDONE,JF)%MODELPROF(1:NFLEVG)
!        ZPROF(NFLEVG+1,JP,JJPF) = YDGEMSPROF(JJPF+IDONE,JF)%MODELPROF(NFLEVG)
!      ENDDO
!    ENDDO
!  ENDIF 

!*    2.3  Set indices of TOVS channels
!*         Perform radiative transfer calculations

  ICHPF=0
  PF_LOOP_RI: DO JJPF=1,IEND
    INCH(JJPF)=KNCH(JJPF+IDONE)
    DO JCH=1,KNCH(JJPF+IDONE)
      ICHPF=ICHPF+1
      ICHID(ICHPF)=NINT(PRCH(JJPF+IDONE,JCH))
      IPFID(ICHPF)=JJPF
      ZEM(ICHPF)=PEMIS(JJPF+IDONE,JCH)
      IF ( LL_RETR_EMIS_TSKIN ) ZOBS(ICHPF)=POBS(JJPF+IDONE,JCH)
    ENDDO
  ENDDO PF_LOOP_RI

  ! Reset channel numbers to the values in the reduced set initialised in 
  ! RTTVI
  SELECT CASE (KSENSOR)
     CASE (MSENSOR_AIRS)
        ICHID(1:ICHPF) = AIRSCHAN_BACK(ICHID(1:ICHPF))
     CASE (MSENSOR_IASI)
        ICHID(1:ICHPF) = IASICHAN_BACK(ICHID(1:ICHPF))
  END SELECT
  IF (ANY(ICHID(1:ICHPF) == -NMDI)) THEN
    WRITE(CLERROR, *) &
     &  'Error in channel subsetting for RTTOV for'//JOT(NSATEM)%jost(ksat)%sname
    CALL ABOR1(CLERROR)
  ENDIF

!*    2.4  Call RTTOV

  CALL RTTOV_EC(IFAIL, KSAT, ICHPF, IEND, NFLEVG+1,           &
   &    ICHID, IPFID,                                         &
   &    ZPPRES, ZPROF, ZPROFS, ZPROFSS, ISURF, ZEM, ZPROFCV,  &
   &    ZZENANG, ZAZIANG, ZSOLZENANG, ZSOLAZIANG, ZLAT, ZOROG,&
   &    LDCLOUD, LL_LINTERP,LLTRACER,                          &
   &    ZTBCLR, ZRADCLR, ZTBTOT, ZRADTOT, ZRADCLD, ZRADCLDLEV,&
   &    ZTAU, ZTAUSFC, LL_RETR_EMIS_TSKIN, ZOBS, ZVAROUT) 

!*    2.5  Construct output array containing model radiances, transmittances

  ICHPF=0
  IF(ANY(IFAIL(:) == 2))THEN
    WRITE(CLERROR, *) &
     &  'Problems in RTTOV call for '//JOT(NSATEM)%jost(ksat)%sname
    IF( LABORT_RTTOV_FAILURE ) THEN
      CALL ABOR1(CLERROR)
    ELSE
      WRITE(NULERR,*) 'WARNING: '//CLERROR
      WRITE(NULERR,*) '  Setting FG to missing values'
    ENDIF
  ENDIF
  PF_LOOP_RO: DO JJPF=1,IEND
    IF(IFAIL(JJPF) /= 0)THEN
      DO JCH=1,KNCH(JJPF+IDONE)
        ICHPF=ICHPF+1
        PTBCLR(JJPF+IDONE,JCH)=RMDI
        PTBTOT(JJPF+IDONE,JCH)=RMDI
        PTAU(JJPF+IDONE,JCH,:)=RMDI
        PRADCLDLEV(JJPF+IDONE,JCH,:)=RMDI
        IF (PRESENT(PTAUSFC)) PTAUSFC(JJPF+IDONE,JCH)=RMDI
      ENDDO
    ELSE
      DO JCH=1,KNCH(JJPF+IDONE)
        ICHPF=ICHPF+1
        PTBCLR(JJPF+IDONE,JCH)=ZTBCLR(ICHPF)
        PTBTOT(JJPF+IDONE,JCH)=ZTBTOT(ICHPF)
        PTAU(JJPF+IDONE,JCH,:)=ZTAU(:,ICHPF)
        PRADCLDLEV(JJPF+IDONE,JCH,:)=ZRADCLDLEV(:,ICHPF)
        IF (PRESENT(PTAUSFC)) PTAUSFC(JJPF+IDONE,JCH)=ZTAUSFC(ICHPF)
      ENDDO
    ENDIF
  ENDDO PF_LOOP_RO

!*    2.6 Construct output array containing surface emissivity

  ICHPF=0
  PF_LOOP_EMIS: DO JJPF=1,IEND
    DO JCH=1,KNCH(JJPF+IDONE)   
      ICHPF=ICHPF+1
      PEMIS(JJPF+IDONE,JCH) = ZEM(ICHPF)
    ENDDO
  ENDDO PF_LOOP_EMIS

!*    2.7  Preparation for AIRS and IASI cloud detection

  !     Ranking a. level determination (All channels)
  IF ( (KSENSOR == MSENSOR_AIRS .OR. KSENSOR == MSENSOR_IASI) &
   &   .AND. PRESENT(PCLDLEV) ) THEN
    ICHPF=0
    DO JJPF=1,IEND
      DO JCH=1,KNCH(JJPF+IDONE)
        ICHPF=ICHPF+1
        IF(IFAIL(JJPF) == 0)THEN
          IFOUND=0
          Z_XLEVSAVE=0.0_JPRB
          Z_XINC=0.0_JPRB
        
          DO JLEV=NFLEVG,1,-1
            Z_D0=ABS((ZRADCLDLEV(JLEV,ICHPF)-ZRADCLR(ICHPF))/ZRADCLR(ICHPF))
            IF(IFOUND == 0.AND.Z_D0 > 0.01_JPRB)THEN
              Z_XLEVSAVE=REAL(JLEV)
  
              IF(JLEV < NFLEVG)THEN
                Z_D1=ABS((ZRADCLDLEV(JLEV+1,ICHPF)-ZRADCLR(ICHPF))/ZRADCLR(ICHPF))
              ELSE
                Z_D1=0.0_JPRB !ESSENTIALLY ASSUME ZERO AT LEVEL NFLEVG+1=SURFACE
              ENDIF

              Z_XINC=(0.01_JPRB-Z_D0)/(Z_D0-Z_D1)
              IFOUND=1
            ENDIF
          ENDDO
          PCLDLEV(JJPF+IDONE,JCH)=Z_XLEVSAVE-Z_XINC
        ENDIF
      ENDDO
    ENDDO
  ENDIF

!          2.7   Output things from emissivity/skin temperature retrievals


  IF ( LL_RETR_EMIS_TSKIN ) THEN
    ICHPF=0
    DO JJPF=1,IEND
      DO JCH=1,KNCH(JJPF+IDONE)
        ICHPF=ICHPF+1

        PVAROUT(JJPF+IDONE,JCH,:)=ZVAROUT(:,ICHPF)

      ENDDO
    ENDDO
  ENDIF

  IDONE=IDONE+IEND
ENDDO PACKET_LOOP

!*    3.0  Deallocate RTTOV temporary arrays

CALL RTTOV_EC_ALLOC(IFAIL, KSAT, IMXCHPF, NJPPF, NFLEVG+1, &
 &    LDCLOUD, LL_LINTERP,                                 &
 &    0_JPIM)

IF (LHOOK) CALL DR_HOOK('RADTR_ML',1,ZHOOK_HANDLE)
END SUBROUTINE RADTR_ML
