SUBROUTINE PHYMFPOS(KPROMA,KST,KND,POROG,PGM,PGEMU,PGELAM,PUT0,PVT0,PTT0,&
 & LDQ,PQT0,LDL,PLT0, &
 & LDI,PIT0,LDR,PRRT0,LDS,PSNT0,LDG,PGRT0,LDA,PAT0,&
 & PSPT0,PTS0,PSD0,PSW0,PSF0,PHV0,PSR0,PCLSM,PCZ0H,PCVEG,PCIVE,PCARG,PCD2,&
 & PCSAB,PXTCLS,PXRHCLS,PXQCLS,PXUCLS,PXVCLS,&
 & PAUX,KFLDAUX,PGPP,KFLDSPP)  

!**** *PHYMFPOS* - post-processing

!     PURPOSE.
!     -------
!           Physico-dynamic post-processing interface for Meteo-France.

!**   INTERFACE.
!     ---------
!        *CALL* *PHYMFPOS(...)

!        EXPLICIT ARGUMENTS :
!        ------------------
!            INPUT :
!        KPROMA    : horizontal dimension 
!        KST       : first point to post-process 
!        KND       : last point to post-process 
!        POROG     : Surface geopotential
!        PGM       : Map factor
!        PGEMU     : Sine of geographic latitude
!        PGELAM    : geographic longitude
!        PUT0      : zonal wind time t
!        PVT0      : meridional wind time t
!        PTT0      : temperature time t
!        PQT0      : humidity time t
!        PLT0      : upper air liquid water time t
!        PIT0      : upper air ice time t
!        PRRT0     : upper air rain time t
!        PSNT0     : upper air snow time t
!        PGRT0     : upper air graupel time t
!        PSPT0     : surface pressure variable time t
!        PTS0      : surface temperature
!        PSD0      : snow depth
!        PSW0      : surface water content
!        PSF0      : surface frost
!        PHV0      : resistance to evapotranspiration
!        PSR0      : model roughness length times g
!        PCLSM     : land-sea mask
!        PCZ0H     : roughness length for heat times g
!        PCVEG     : percentage of vegetation
!        PCIVE     : index of vegetation
!        PCARG     : percentage of silt
!        PCD2      : soild depth
!        PCSAB     : percentage of sand
!        PXTCLS    : Tcls from model
!        PXRHCLS   : RHcls from model
!        PXQCLS    : QCLS from model
!        PXUCLS    : Ucls from model
!        PXVCLS    : Vcls from model
!        KFLDAUX   : number of fields in output array (not fitted)
!        KFLDSPP   : number of fields in output array (fitted)
!            OUTPUT (post-processed fields) :
!        PAUX     : fields to remain gridpoint
!        PGPP     : fields to be spectrally fitted

!     EXTERNALS.
!     ---------

!     AUTHOR.
!     -------
!        RYAD EL KHATIB *METEO-FRANCE*

!     MODIFICATIONS.
!     -------------
!   ORIGINAL : 2000-10-06
!   R. El Khatib : 01-01-05 plug-in FPCICA instead of FPCAPE
!   R. El Khatib : 01-08-07 Pruning options
!   R. El Khatib : 03-08-12 gfl
!   R. El Khatib : 03-04-17 Fullpos improvemnts
!   M.Hamrud      01-Oct-2003 CY28 Cleaning
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!    G. Hello     : 07-07 MOdel radiances
!     ------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULOUT
USE YOMDIM   , ONLY : NFLEVG
USE YOMDYNA  , ONLY : LRWSDLR
USE YOMGEM   , ONLY : VAH      ,VBH      ,VDELB    ,VC
USE YOMCST   , ONLY : RV       ,RCPV     ,RETV     ,RCW      ,RCS      , &
 & RLVTT    ,RLSTT    ,RTT      ,RALPW    ,RBETW    ,RGAMW    , &
 & RALPS    ,RBETS    ,RGAMS    ,RALPD    ,RBETD    ,RGAMD      
USE YOMPHY   , ONLY : LNEIGE
USE YOMFPC   , ONLY : NFPCAPE  ,CFPFMT, LMOCONVAR
USE YOMVPOS  , ONLY : QFPTYPE
USE YOMAFN   , ONLY : TFP_UCLS ,TFP_VCLS ,TFP_TCLS ,TFP_QCLS ,TFP_RCLS ,&
 & TFP_FCLS ,TFP_CAPE ,TFP_CIEN ,TFP_UGST ,TFP_VGST ,TFP_FGST ,&
 & TFP_SMC  ,TFP_ASMC ,TFP_DYNDS,TFP_LCL, TFP_FCL , TFP_EL, &
 & TFP_MSAT7C1,TFP_MSAT7C2,&
 & TFP_MSAT8C1,TFP_MSAT8C2,TFP_MSAT8C3,TFP_MSAT8C4,&
 & TFP_MSAT8C5,TFP_MSAT8C6,TFP_MSAT8C7,TFP_MSAT8C8,&
 & TFP_MSAT9C1,TFP_MSAT9C2,TFP_MSAT9C3,TFP_MSAT9C4,&
 & TFP_MSAT9C5,TFP_MSAT9C6,TFP_MSAT9C7,TFP_MSAT9C8,&
 & TFP_GOES11C1,TFP_GOES11C2,TFP_GOES11C3,TFP_GOES11C4,&
 & TFP_GOES12C1,TFP_GOES12C2,TFP_GOES12C3,TFP_GOES12C4,&
 & TFP_MTSAT1C1,TFP_MTSAT1C2,TFP_MTSAT1C3,TFP_MTSAT1C4  

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

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KPROMA 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDAUX 
INTEGER(KIND=JPIM),INTENT(IN)    :: KFLDSPP 
INTEGER(KIND=JPIM),INTENT(IN)    :: KST 
INTEGER(KIND=JPIM),INTENT(IN)    :: KND 
REAL(KIND=JPRB)   ,INTENT(IN)    :: POROG(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEMU(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUT0(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVT0(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDQ 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDL 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDI 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PIT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDR 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRRT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDS 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSNT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDG 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGRT0(KPROMA,NFLEVG) 
LOGICAL           ,INTENT(IN)    :: LDA 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAT0(KPROMA,NFLEVG) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSPT0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTS0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSD0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSW0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSF0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PHV0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSR0(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCLSM(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCZ0H(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCVEG(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCIVE(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCARG(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCD2(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCSAB(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXTCLS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXRHCLS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXQCLS(KPROMA)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXUCLS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PXVCLS(KPROMA) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PAUX(KPROMA,KFLDAUX)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PGPP(KPROMA,KFLDSPP)

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

!     ==== WORKING ARRAYS ===

!     ZPRESH, ZPRESF : HALF LEVEL, FULL LEVEL PRESSURES

REAL(KIND=JPRB) :: ZPRESH(KPROMA,0:NFLEVG),  ZPRESF(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZDELP (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZRDELP(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLNPR (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZALPH (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZRTGR (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZRPRE (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZRPP  (KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLNPRESF(KPROMA,NFLEVG)

REAL(KIND=JPRB) :: ZUT0(KPROMA,NFLEVG), ZVT0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZTT0(KPROMA,NFLEVG), ZQT0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZLT0(KPROMA,NFLEVG), ZIT0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZRRT0(KPROMA,NFLEVG), ZSNT0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZSPD0(KPROMA,NFLEVG), ZR0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZGRT0(KPROMA,NFLEVG), ZAT0(KPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZXQCLS(KPROMA) ! (analysed) specific moisture at PBL height
REAL(KIND=JPRB) :: ZTS0(KPROMA) ! local soil temperature 
REAL(KIND=JPRB) :: Z1SGM(KPROMA)  ! Reverse map factor
REAL(KIND=JPRB) :: ZQO3(KPROMA,0:NFLEVG)

!     ==== LOCAL POST-PROCESSED FIELDS  ===

REAL(KIND=JPRB) :: ZUCLS(KPROMA) ,ZVCLS(KPROMA) ,ZFCLS(KPROMA) ,ZTCLS(KPROMA)
REAL(KIND=JPRB) :: ZUGST(KPROMA) ,ZVGST(KPROMA) ,ZFGST(KPROMA) ,ZUSMC(KPROMA)
REAL(KIND=JPRB) :: ZQCLS(KPROMA) ,ZRHCLS(KPROMA),ZPCLS(KPROMA) ,ZVSMC(KPROMA)
REAL(KIND=JPRB) :: ZCAPE(KPROMA) ,ZCIN(KPROMA)  ,ZUASM(KPROMA) ,ZVASM(KPROMA)
REAL(KIND=JPRB) :: ZTBMSAT7(KPROMA,2), ZTBMSAT8(KPROMA,8), ZTBMSAT9(KPROMA,8)
REAL(KIND=JPRB) :: ZTBGOES11(KPROMA,4), ZTBGOES12(KPROMA,4), ZTBMTSAT1(KPROMA,4)
INTEGER(KIND=JPIM) :: ILCL(KPROMA) ! Lifting condensation level
INTEGER(KIND=JPIM) :: IFCL(KPROMA) ! Free convection level
INTEGER(KIND=JPIM) :: IEL(KPROMA)  ! Equilibrium level
REAL(KIND=JPRB) :: ZLCL(KPROMA) !  Lifting condensation level (height)
REAL(KIND=JPRB) :: ZFCL(KPROMA) ! Free convection level (height)
REAL(KIND=JPRB) :: ZEL(KPROMA)  ! Equilibrium level (height)

!     ==== OTHER VARIABLES  ===

REAL(KIND=JPRB) :: ZDELTA, ZES

INTEGER(KIND=JPIM) :: JLEV, ICAPE, JI

LOGICAL :: LLPBL  ! Computation of PBL fields
LOGICAL :: LLICV  ! to activate the computation of CAPE & CIEN
LOGICAL :: LLSMC  ! to activate the computation of Surface MOCON
LOGICAL :: LLASMC ! to activate the computation of analysed surface MOCON
LOGICAL :: LLMTS  ! to activate the computation of model radiances
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"
#include "fpachmt.intfb.h"
#include "fpcica.intfb.h"
#include "gnhdlrb.intfb.h"
#include "gppref.intfb.h"
#include "gppreh.intfb.h"
#include "gprcp.intfb.h"
#include "gpxyb.intfb.h"
#include "mts_phys.intfb.h"
#include "fcttrm.h"

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

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

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

!*       1.    INITIALIZATIONS.
!              ---------------

LLSMC =QFPTYPE%LL(TFP_SMC%ICOD)
LLASMC=QFPTYPE%LL(TFP_ASMC%ICOD)
LLICV = (CFPFMT == 'MODEL') .AND. &
 & (QFPTYPE%LL(TFP_CAPE%ICOD) .OR. QFPTYPE%LL(TFP_CIEN%ICOD))  
LLMTS = QFPTYPE%LL(TFP_MSAT7C1%ICOD) .OR. QFPTYPE%LL(TFP_MSAT7C2%ICOD) .OR. &
      & QFPTYPE%LL(TFP_MSAT8C1%ICOD) .OR. QFPTYPE%LL(TFP_MSAT8C2%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT8C3%ICOD) .OR. QFPTYPE%LL(TFP_MSAT8C4%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT8C5%ICOD) .OR. QFPTYPE%LL(TFP_MSAT8C6%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT8C7%ICOD) .OR. QFPTYPE%LL(TFP_MSAT8C8%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT9C1%ICOD) .OR. QFPTYPE%LL(TFP_MSAT9C2%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT9C3%ICOD) .OR. QFPTYPE%LL(TFP_MSAT9C4%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT9C5%ICOD) .OR. QFPTYPE%LL(TFP_MSAT9C6%ICOD).OR. &
      & QFPTYPE%LL(TFP_MSAT9C7%ICOD) .OR. QFPTYPE%LL(TFP_MSAT9C8%ICOD).OR. &
      & QFPTYPE%LL(TFP_GOES11C1%ICOD) .OR. QFPTYPE%LL(TFP_GOES11C2%ICOD).OR. &
      & QFPTYPE%LL(TFP_GOES11C3%ICOD) .OR. QFPTYPE%LL(TFP_GOES11C4%ICOD).OR. &
      & QFPTYPE%LL(TFP_GOES12C1%ICOD) .OR. QFPTYPE%LL(TFP_GOES12C2%ICOD).OR. &
      & QFPTYPE%LL(TFP_GOES12C3%ICOD) .OR. QFPTYPE%LL(TFP_GOES12C4%ICOD).OR. &
      & QFPTYPE%LL(TFP_MTSAT1C1%ICOD) .OR. QFPTYPE%LL(TFP_MTSAT1C2%ICOD).OR. &
      & QFPTYPE%LL(TFP_MTSAT1C3%ICOD) .OR. QFPTYPE%LL(TFP_MTSAT1C4%ICOD)
LLPBL = LLSMC .OR. LLASMC .OR. (LLICV .AND. NFPCAPE >= 3) .OR.  &
 & ((CFPFMT == 'MODEL') .AND.                                     &
 & QFPTYPE%LL(TFP_UCLS%ICOD) .OR. QFPTYPE%LL(TFP_VCLS%ICOD) .OR. &
 & QFPTYPE%LL(TFP_TCLS%ICOD) .OR. QFPTYPE%LL(TFP_QCLS%ICOD) .OR. &
 & QFPTYPE%LL(TFP_RCLS%ICOD) .OR. QFPTYPE%LL(TFP_FCLS%ICOD) .OR. &
 & QFPTYPE%LL(TFP_UGST%ICOD) .OR. QFPTYPE%LL(TFP_VGST%ICOD) .OR. &
 & QFPTYPE%LL(TFP_FGST%ICOD))  


IF (LLPBL .OR. LLMTS) THEN
  DO JLEV = 1, NFLEVG
    DO JI=KST,KND
      ZUT0(JI,JLEV) = PUT0(JI,JLEV)*PGM(JI)
      ZVT0(JI,JLEV) = PVT0(JI,JLEV)*PGM(JI)
    ENDDO
  ENDDO
ENDIF
IF (LLPBL .OR. LLICV .OR. LLMTS) THEN
  DO JLEV = 1, NFLEVG
    DO JI=KST,KND
      ZTT0(JI,JLEV) = PTT0(JI,JLEV)
    ENDDO
    IF (LDQ) THEN
      DO JI=KST,KND
        ZQT0(JI,JLEV) = PQT0(JI,JLEV)
      ENDDO
    ELSE
      ZQT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDL) THEN
      DO JI=KST,KND
        ZLT0(JI,JLEV) = PLT0(JI,JLEV)
      ENDDO
    ELSE
      ZLT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDI) THEN
      DO JI=KST,KND
        ZIT0(JI,JLEV) = PIT0(JI,JLEV)
      ENDDO
    ELSE
      ZIT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDR) THEN
      DO JI=KST,KND
        ZRRT0(JI,JLEV) = PRRT0(JI,JLEV)
      ENDDO
    ELSE
      ZRRT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDS) THEN
      DO JI=KST,KND
        ZSNT0(JI,JLEV) = PSNT0(JI,JLEV)
      ENDDO
    ELSE
      ZSNT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDG) THEN
      DO JI=KST,KND
        ZGRT0(JI,JLEV) = PGRT0(JI,JLEV)
      ENDDO
    ELSE
      ZGRT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
    IF (LDA) THEN
      DO JI=KST,KND
        ZAT0(JI,JLEV) = PAT0(JI,JLEV)
      ENDDO
    ELSE
      ZAT0(KST:KND,JLEV) = 0.0_JPRB
    ENDIF
  ENDDO
ENDIF

IF (LLPBL.OR.LLICV.OR.LLMTS) THEN
  ! Compute pressures.
  DO JI=KST,KND
    ZPRESH(JI,NFLEVG) = EXP(PSPT0(JI))
  ENDDO
  CALL GPPREH(KPROMA,KST,KND,NFLEVG,VAH,VBH,ZPRESH)
  CALL GPXYB(KPROMA,KST,KND,NFLEVG,VDELB,VC,ZPRESH,ZDELP,&
   & ZRDELP,ZLNPR,ZALPH,ZRTGR,ZRPRE,ZRPP)
  CALL GPPREF(KPROMA,KST,KND,NFLEVG,ZALPH,ZPRESH,ZPRESF)

  ! Provisional treatment of the deep-layer NH equations.
  ! Same remarks as in POS. Additionally, NH effects 
  ! are neglected in this conversion because these effects are
  ! weak and because the input data are not available.
  IF (LRWSDLR) THEN
    WRITE (NULOUT,*) ' PHYMFPOS: tests in progress for LRWSDLR!!'
    ! Compute R.
    CALL GPRCP(KPROMA,KST,KND,NFLEVG,PQ=ZQT0(1,1),PQI=ZIT0(1,1),&
     & PQL=ZLT0(1,1),PQR=ZRRT0(1,1),PQS=ZSNT0(1,1),PQG=ZGRT0(1,1),&
     & PR=ZR0)
    ! Save log(presim).
    DO JLEV=1,NFLEVG
      DO JI=KST,KND
        ZLNPRESF(JI,JLEV)=LOG(ZPRESF(JI,JLEV))
      ENDDO
    ENDDO
    ! Transform "presim" quantities into "prehyd" quantities.
    ZSPD0(KST:KND,1:KPROMA)=0.0_JPRB
    CALL GNHDLRB(KPROMA,KST,KND,.TRUE.,POROG,ZTT0,ZR0,ZSPD0, &
     & ZPRESF,ZPRESH,ZDELP,ZRDELP,ZLNPR,ZALPH)
    ! From now on PSPT0 should not be used any more in PHYMFPOS.
    ! Use ZPRESH instead.
  ENDIF
ENDIF

DO JI=KST,KND
  Z1SGM(JI)=1.0_JPRB/PGM(JI)
ENDDO

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

!*       2.    POST-PROCESSING.
!              ---------------

!*      2.1   PBL fields

IF (LLPBL) THEN
  CALL FPACHMT(KPROMA,KST,KND,NFLEVG,POROG,ZTT0,ZQT0,ZIT0,ZLT0,ZRRT0,     &
   & ZSNT0,ZGRT0,ZUT0,ZVT0,ZPRESH(1,NFLEVG),PCLSM,PTS0,PSR0,PCZ0H,PCVEG,  &
   & PCARG,PCD2,PCIVE,PCSAB,PSD0,PSW0,PSF0,PHV0,ZQCLS,ZRHCLS,ZTCLS,ZUCLS, &
   & ZVCLS,ZFCLS,ZUGST,ZVGST,ZFGST,ZPCLS, &
   & PRESH=ZPRESH,PRESF=ZPRESF,PLNPR=ZLNPR,PALPH=ZALPH)  
  IF (CFPFMT == 'MODEL') THEN
    CALL STORE_DATA(TFP_UCLS%ICOD,1,ZUCLS)
    CALL STORE_DATA(TFP_VCLS%ICOD,1,ZVCLS)
    CALL STORE_DATA(TFP_UGST%ICOD,1,ZUGST)
    CALL STORE_DATA(TFP_VGST%ICOD,1,ZVGST)
    CALL STORE_DATA(TFP_FCLS%ICOD,1,ZFCLS)
    CALL STORE_DATA(TFP_FGST%ICOD,1,ZFGST)
    CALL STORE_DATA(TFP_TCLS%ICOD,1,ZTCLS)
    CALL STORE_DATA(TFP_QCLS%ICOD,1,ZQCLS)
    CALL STORE_DATA(TFP_RCLS%ICOD,1,ZRHCLS)
  ENDIF
ENDIF

!*      2.2   Convection indexes

IF (LLICV) THEN
  IF (NFPCAPE == 4) THEN
    ICAPE=3
    CALL FPCICA(KST,KND,KPROMA,NFLEVG,ICAPE,PXTCLS,ZPCLS,PXRHCLS,ZTT0,ZPRESF,&
     & ZQT0,ZCAPE,ZCIN,ILCL,IFCL,IEL)  
  ELSE
    ICAPE=NFPCAPE
    CALL FPCICA(KST,KND,KPROMA,NFLEVG,ICAPE,ZTCLS,ZPCLS,ZRHCLS,ZTT0,ZPRESF,&
     & ZQT0,ZCAPE,ZCIN,ILCL,IFCL,IEL)  
  ENDIF
  CALL STORE_DATA(TFP_CAPE%ICOD,1,ZCAPE)
  CALL STORE_DATA(TFP_CIEN%ICOD,1,ZCIN)
  ZLCL=ILCL
  ZFCL=IFCL
  ZEL=IEL
  CALL STORE_DATA(TFP_LCL%ICOD ,1,ZLCL)
  CALL STORE_DATA(TFP_FCL%ICOD ,1,ZFCL)
  CALL STORE_DATA(TFP_EL%ICOD ,1,ZEL)
ENDIF

!*      2.3   Surface moisture convergence

IF (LLSMC) THEN
  DO JI=KST,KND
    ZUSMC(JI)=-ZQCLS(JI)*ZUCLS(JI)
    ZVSMC(JI)=-ZQCLS(JI)*ZVCLS(JI)
  ENDDO
  CALL STORE_DATA(TFP_SMC%ICOD,1,ZUSMC)
  CALL STORE_DATA(TFP_SMC%ICOD,2,ZVSMC)
ENDIF

IF (LLASMC) THEN
 IF (LMOCONVAR) THEN
!specific mocon computation for variational diagnostic purposes
    DO JI=KST,KND
      ZUASM(JI)=-PQT0(JI,NFLEVG-1)*PUT0(JI,NFLEVG)*PGM(JI)
      ZVASM(JI)=-PQT0(JI,NFLEVG-1)*PVT0(JI,NFLEVG)*PGM(JI)
    ENDDO
  ELSE
  DO JI=KST,KND
!   Compute specific moisture at PBL height 
    IF(LNEIGE) THEN
      ZDELTA=MAX(0.0_JPRB,SIGN(1.0_JPRB,RTT-PXTCLS(JI)))
    ELSE
      ZDELTA=0.0_JPRB
    ENDIF
    ZES=FOEW(MAX(PXTCLS(JI),1.0_JPRB),ZDELTA)
    ZXQCLS(JI)=-PXRHCLS(JI)*ZES &
     & /(RETV*PXRHCLS(JI)*ZES-ZPCLS(JI)*(RETV+1.0_JPRB))  
!   Compute moisture convergence not reduced :
    ZUASM(JI)=-ZXQCLS(JI)*PXUCLS(JI)*PGM(JI)
    ZVASM(JI)=-ZXQCLS(JI)*PXVCLS(JI)*PGM(JI)
  ENDDO
  ENDIF
  CALL STORE_DATA(TFP_ASMC%ICOD,1,ZUASM)
  CALL STORE_DATA(TFP_ASMC%ICOD,2,ZVASM)
ENDIF

!*         2.4 Model Radiances
IF (LLMTS) THEN
   ! this O3 initialization is scratched by the  RTTOV climatology in MTS_PHYS
   ZQO3(:,:) = 1.E-9_JPRB 
   ZTS0(:)=MIN(MAX(PTS0(:),200._JPRB),350._JPRB)
   IF (.NOT. LLPBL) THEN
     ! these local are necessary for the points belonging to the unphysical extension 
     !  domain of ALADIN or AROME 
     ZUCLS=MIN(MAX(PXUCLS,-70._JPRB),70._JPRB)
     ZVCLS=MIN(MAX(PXVCLS,-70._JPRB),70._JPRB)
     ZTCLS=MIN(MAX(PXTCLS,200._JPRB),350._JPRB)
     ZQCLS=MIN(MAX(PXQCLS,1.E-9_JPRB),0.04_JPRB)
   ENDIF 

   CALL MTS_PHYS(KST,KND,KPROMA,NFLEVG,PGEMU,PGELAM,POROG,ZPRESH,ZPRESF,ZLNPR,ZALPH,&
    &ZUT0,ZVT0,ZTT0,ZQT0,ZQO3,ZLT0,ZIT0,ZAT0,ZTS0,PCLSM,ZUCLS,ZVCLS,&
    &ZTCLS,ZQCLS,&
    &ZTBMSAT7,ZTBMSAT8,ZTBMSAT9,ZTBGOES11,ZTBGOES12,ZTBMTSAT1)
    
   IF(QFPTYPE%LL(TFP_MSAT7C1%ICOD)) CALL STORE_DATA(TFP_MSAT7C1%ICOD,1,ZTBMSAT7(:,1))
   IF(QFPTYPE%LL(TFP_MSAT7C2%ICOD)) CALL STORE_DATA(TFP_MSAT7C2%ICOD,1,ZTBMSAT7(:,2))
   IF(QFPTYPE%LL(TFP_MSAT8C1%ICOD)) CALL STORE_DATA(TFP_MSAT8C1%ICOD,1,ZTBMSAT8(:,1))
   IF(QFPTYPE%LL(TFP_MSAT8C2%ICOD)) CALL STORE_DATA(TFP_MSAT8C2%ICOD,1,ZTBMSAT8(:,2))
   IF(QFPTYPE%LL(TFP_MSAT8C3%ICOD)) CALL STORE_DATA(TFP_MSAT8C3%ICOD,1,ZTBMSAT8(:,3))
   IF(QFPTYPE%LL(TFP_MSAT8C4%ICOD)) CALL STORE_DATA(TFP_MSAT8C4%ICOD,1,ZTBMSAT8(:,4))
   IF(QFPTYPE%LL(TFP_MSAT8C5%ICOD)) CALL STORE_DATA(TFP_MSAT8C5%ICOD,1,ZTBMSAT8(:,5))
   IF(QFPTYPE%LL(TFP_MSAT8C6%ICOD)) CALL STORE_DATA(TFP_MSAT8C6%ICOD,1,ZTBMSAT8(:,6))
   IF(QFPTYPE%LL(TFP_MSAT8C7%ICOD)) CALL STORE_DATA(TFP_MSAT8C7%ICOD,1,ZTBMSAT8(:,7))
   IF(QFPTYPE%LL(TFP_MSAT8C8%ICOD)) CALL STORE_DATA(TFP_MSAT8C8%ICOD,1,ZTBMSAT8(:,8))
   IF(QFPTYPE%LL(TFP_MSAT9C1%ICOD)) CALL STORE_DATA(TFP_MSAT9C1%ICOD,1,ZTBMSAT9(:,1))
   IF(QFPTYPE%LL(TFP_MSAT9C2%ICOD)) CALL STORE_DATA(TFP_MSAT9C2%ICOD,1,ZTBMSAT9(:,2))
   IF(QFPTYPE%LL(TFP_MSAT9C3%ICOD)) CALL STORE_DATA(TFP_MSAT9C3%ICOD,1,ZTBMSAT9(:,3))
   IF(QFPTYPE%LL(TFP_MSAT9C4%ICOD)) CALL STORE_DATA(TFP_MSAT9C4%ICOD,1,ZTBMSAT9(:,4))
   IF(QFPTYPE%LL(TFP_MSAT9C5%ICOD)) CALL STORE_DATA(TFP_MSAT9C5%ICOD,1,ZTBMSAT9(:,5))
   IF(QFPTYPE%LL(TFP_MSAT9C6%ICOD)) CALL STORE_DATA(TFP_MSAT9C6%ICOD,1,ZTBMSAT9(:,6))
   IF(QFPTYPE%LL(TFP_MSAT9C7%ICOD)) CALL STORE_DATA(TFP_MSAT9C7%ICOD,1,ZTBMSAT9(:,7))
   IF(QFPTYPE%LL(TFP_MSAT9C8%ICOD)) CALL STORE_DATA(TFP_MSAT9C8%ICOD,1,ZTBMSAT9(:,8))
   IF(QFPTYPE%LL(TFP_GOES11C1%ICOD)) CALL STORE_DATA(TFP_GOES11C1%ICOD,1,ZTBGOES11(:,1))
   IF(QFPTYPE%LL(TFP_GOES11C2%ICOD)) CALL STORE_DATA(TFP_GOES11C2%ICOD,1,ZTBGOES11(:,2))
   IF(QFPTYPE%LL(TFP_GOES11C3%ICOD)) CALL STORE_DATA(TFP_GOES11C3%ICOD,1,ZTBGOES11(:,3))
   IF(QFPTYPE%LL(TFP_GOES11C4%ICOD)) CALL STORE_DATA(TFP_GOES11C4%ICOD,1,ZTBGOES11(:,4))
   IF(QFPTYPE%LL(TFP_GOES12C1%ICOD)) CALL STORE_DATA(TFP_GOES12C1%ICOD,1,ZTBGOES12(:,1))
   IF(QFPTYPE%LL(TFP_GOES12C2%ICOD)) CALL STORE_DATA(TFP_GOES12C2%ICOD,1,ZTBGOES12(:,2))
   IF(QFPTYPE%LL(TFP_GOES12C3%ICOD)) CALL STORE_DATA(TFP_GOES12C3%ICOD,1,ZTBGOES12(:,3))
   IF(QFPTYPE%LL(TFP_GOES12C4%ICOD)) CALL STORE_DATA(TFP_GOES12C4%ICOD,1,ZTBGOES12(:,4))
   IF(QFPTYPE%LL(TFP_MTSAT1C1%ICOD)) CALL STORE_DATA(TFP_MTSAT1C1%ICOD,1,ZTBMTSAT1(:,1))
   IF(QFPTYPE%LL(TFP_MTSAT1C2%ICOD)) CALL STORE_DATA(TFP_MTSAT1C2%ICOD,1,ZTBMTSAT1(:,2))
   IF(QFPTYPE%LL(TFP_MTSAT1C3%ICOD)) CALL STORE_DATA(TFP_MTSAT1C3%ICOD,1,ZTBMTSAT1(:,3))
   IF(QFPTYPE%LL(TFP_MTSAT1C4%ICOD)) CALL STORE_DATA(TFP_MTSAT1C4%ICOD,1,ZTBMTSAT1(:,4))

ENDIF

IF (LHOOK) CALL DR_HOOK('PHYMFPOS',1,ZHOOK_HANDLE)

!------------------------------------------------------------------
CONTAINS

SUBROUTINE STORE_DATA(K,KPOS,PDATA)

INTEGER(KIND=JPIM), INTENT(IN) :: K             ! Field code/index
INTEGER(KIND=JPIM), INTENT(IN) :: KPOS          ! Relative adress of input data
REAL(KIND=JPRB),    INTENT(IN) :: PDATA(KPROMA) ! input data

INTEGER(KIND=JPIM) :: ILOC ! Absolute adress of data in output array
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('PHYMFPOS:STORE_DATA',0,ZHOOK_HANDLE)
IF (QFPTYPE%LL(K)) THEN
  SELECT CASE (QFPTYPE%ISF(K))
  CASE (0)
!         Not fitted data 
    ILOC=QFPTYPE%IGPX(K)
    SELECT CASE (ABS(TFP_DYNDS(K)%IORDR))
    CASE (0)
      DO JI=KST,KND
        PAUX(JI,ILOC) = PDATA(JI)
      ENDDO
    CASE (1)
      DO JI=KST,KND
        PAUX(JI,ILOC) = PDATA(JI)*Z1SGM(JI)
      ENDDO
    CASE (2)
      DO JI=KST,KND
        PAUX(JI,ILOC) = PDATA(JI)*(Z1SGM(JI)**2)
      ENDDO
    END SELECT
  CASE (1:)
!         Fitted data 
    IF (KPOS > 0 .AND. KPOS <= QFPTYPE%ISKP(K)) THEN
      ILOC=QFPTYPE%IGT1(K,KPOS)
    ELSE
      CALL ABOR1('PHYMFPOS.STORE_DATA : INTERNAL ERROR KPOS')
    ENDIF
    SELECT CASE (ABS(TFP_DYNDS(K)%IORDR))
    CASE (0)
      DO JI=KST,KND
        PGPP(JI,ILOC) = PDATA(JI)
      ENDDO
    CASE (1)
      DO JI=KST,KND
        PGPP(JI,ILOC) = PDATA(JI)*Z1SGM(JI)
      ENDDO
    CASE (2)
      DO JI=KST,KND
        PGPP(JI,ILOC) = PDATA(JI)*(Z1SGM(JI)**2)
      ENDDO
    END SELECT
  END SELECT 
ENDIF 
IF (LHOOK) CALL DR_HOOK('PHYMFPOS:STORE_DATA',1,ZHOOK_HANDLE)

END SUBROUTINE STORE_DATA

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

END SUBROUTINE PHYMFPOS
