SUBROUTINE FPINIPHY

!**** *FPINIPHY*  - CONTROL POST-PROCESSING ON PHYSICAL FIELDS

!     PURPOSE.
!     --------
!        CONTROL THAT THE POINTERS OF PHYSICAL FIELDS TO POST-PROCESS ARE
!        DEFINED.

!**   INTERFACE.
!     ----------
!       *CALL* *FPINIPHY*

!        EXPLICIT ARGUMENTS
!        --------------------

!        IMPLICIT ARGUMENTS
!        --------------------
!        PTRGP0
!        PTRGPD

!     METHOD.
!     -------
!        SEE DOCUMENTATION

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

!     REFERENCE.
!     ----------
!        ECMWF Research Department documentation of the IFS

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

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 94-04-08
!        Modified : 96-02-07 R. El Khatib (ISBA Fields in FULL-POS)
!        Modified : 99-03-15 D. Giard (superficial frozen water)
!        Modified : 99-05-06 D.Dent       (allow budget values)
!        Modified : 00-03-28 R. El Khatib (surf. rel. moisture, anysotropy 
!                   momentum, RMS of geopotential)
!        Modified : 00-10-25 D. Giard (Albedos for bare ground & vegetation)
!        R. El Khatib : 01-08-07 Pruning options
!        Modified : 02-09-04 E. Bazile (new snow scheme LVGSN)
!    R. El Khatib : 03-04-17 Fullpos improvemnts
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        G. Hello : 05-04-25 lground option (surfex)
!     ------------------------------------------------------------------

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

USE YOMCT0B  , ONLY : LECMWF
USE PARFPOS  , ONLY :  JPOSVX2
USE YOMCT0   , ONLY :  LFPART2  ,LCANARI
USE YOMLUN   , ONLY :  NULERR
USE YOMAFN   , ONLY :  GFP_LSM  ,GFP_ST   ,GFP_DST  ,GFP_SSW  ,GFP_ALV  , &
 & GFP_DSW  ,GFP_CSSW ,GFP_CDSW ,GFP_SD   ,GFP_SR   ,GFP_ALS  ,GFP_ASEA , &
 & GFP_AL   ,GFP_EMIS ,GFP_SDOG ,GFP_VEG  ,GFP_ACOT ,GFP_BV   ,GFP_ALAN , &
 & GFP_DPAT ,GFP_IVEG ,GFP_RSMIN,GFP_ARG  ,GFP_SAB  ,GFP_FSSW ,GFP_ASOO , &
 & GFP_D2   ,GFP_LAI  ,GFP_Z0H  ,GFP_ALSN ,GFP_SNDE ,GFP_PCAPG,GFP_ADES , &
 & GFP_BSR  ,GFP_BAAL ,GFP_HV   ,GFP_IC   ,GFP_FDSW ,GFP_PCAAG,GFP_O3A  , &
 & GFP_PSRHU,GFP_PADOU,GFP_PADOV,GFP_O3B  ,GFP_O3C  
USE YOMFPC   , ONLY : CFPPHY   ,NFPPHY   ,NFPCLI   ,NFPSURFEX
USE YOMPHY   , ONLY : LSNV     ,LSOLV    ,LFGEL    ,LVGSN    ,LAEROSEA , &
 & LAEROLAN ,LAEROSOO ,LAERODES ,LO3ABC  ,LMPHYS
USE YOMARPHY , ONLY : LMSE
USE YOMDPHY  , ONLY : NVXTR2

IMPLICIT NONE

CHARACTER :: CLMARK*39

INTEGER(KIND=JPIM) :: IERR, JFLD
LOGICAL :: LLMSE, LLSOLV ,LLAEROSEA , LLAEROLAN ,LLAEROSOO ,LLAERODES ,LLO3ABC
LOGICAL :: LLFP_CLASSIC, LLFP_SURFEX, LLFP_MIX
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

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

!*       1. CONTROL VALUE OF ANY REQUIRED POINTER
!           -------------------------------------

IF (LHOOK) CALL DR_HOOK('FPINIPHY',0,ZHOOK_HANDLE)
IERR=0
IF(LECMWF) THEN
! I don't know how to make these checks for ECMWF/MH
ELSE
  LLMSE=LMSE
  LLSOLV=LMPHYS.AND.LSOLV
  LLAEROSEA=LMPHYS.AND.LAEROSEA
  LLAEROLAN=LMPHYS.AND.LAEROLAN
  LLAEROSOO=LMPHYS.AND.LAEROSOO
  LLAERODES=LMPHYS.AND.LAERODES
  LLO3ABC=LMPHYS.AND.LO3ABC
  LLFP_CLASSIC = (NFPCLI == 3)
  LLFP_SURFEX  = .NOT.LFPART2.AND.LLMSE
  LLFP_MIX=(.NOT.LLMSE .OR. NFPSURFEX == 1 .OR. (LLMSE .AND. LFPART2))
  DO JFLD=1,NFPPHY
    IF(  (CFPPHY(JFLD) == GFP_BV%CLNAME)) CYCLE
    IF(  (CFPPHY(JFLD) == GFP_LSM%CLNAME  .AND..NOT.(LMPHYS.AND.LLFP_MIX))&
     & .OR.(CFPPHY(JFLD) == GFP_ST%CLNAME   .AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_DST%CLNAME  .AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_SSW%CLNAME  .AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_SD%CLNAME   .AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_DSW%CLNAME  .AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_CSSW%CLNAME .AND..NOT.(LCANARI.OR.LLFP_CLASSIC.OR.LLFP_SURFEX))&
     & .OR.(CFPPHY(JFLD) == GFP_CDSW%CLNAME .AND..NOT.(LCANARI.OR.LLFP_CLASSIC.OR.LLFP_SURFEX))&
     & .OR.(CFPPHY(JFLD) == GFP_SR%CLNAME   .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_AL%CLNAME   .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_EMIS%CLNAME .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_SDOG%CLNAME .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_VEG%CLNAME  .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_ACOT%CLNAME .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_DPAT%CLNAME .AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_IVEG%CLNAME .AND..NOT.LLSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_RSMIN%CLNAME.AND..NOT.LLSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_ARG%CLNAME  .AND..NOT.(LMPHYS.AND.(LSOLV.OR.LLMSE)))&
     & .OR.(CFPPHY(JFLD) == GFP_SAB%CLNAME  .AND..NOT.(LMPHYS.AND.(LSOLV.OR.LLMSE)))&
     & .OR.(CFPPHY(JFLD) == GFP_D2%CLNAME   .AND..NOT.(LMPHYS.AND.(LSOLV.OR.LLMSE)))&
     & .OR.(CFPPHY(JFLD) == GFP_LAI%CLNAME  .AND..NOT.LSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_Z0H%CLNAME  .AND..NOT.LSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_HV%CLNAME   .AND..NOT.LSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_BSR%CLNAME  .AND..NOT.((LMPHYS.AND..NOT.LLMSE).AND.(LSOLV.AND.LSNV)))&
     & .OR.(CFPPHY(JFLD) == GFP_BAAL%CLNAME .AND..NOT.((LMPHYS.AND..NOT.LLMSE).AND.(LSOLV.AND.LSNV)))&
     & .OR.(CFPPHY(JFLD) == GFP_ALS%CLNAME  .AND..NOT.(LLSOLV.AND.LVGSN))&
     & .OR.(CFPPHY(JFLD) == GFP_ALV%CLNAME  .AND..NOT.(LLSOLV.AND.LVGSN))&
     & .OR.(CFPPHY(JFLD) == GFP_ASEA%CLNAME .AND..NOT.LLAEROSEA)&
     & .OR.(CFPPHY(JFLD) == GFP_ALAN%CLNAME .AND..NOT.LLAEROLAN)&
     & .OR.(CFPPHY(JFLD) == GFP_ASOO%CLNAME .AND..NOT.LLAEROSOO)&
     & .OR.(CFPPHY(JFLD) == GFP_ADES%CLNAME .AND..NOT.LLAERODES)&
     & .OR.(CFPPHY(JFLD) == GFP_O3A%CLNAME  .AND..NOT.LLO3ABC)&
     & .OR.(CFPPHY(JFLD) == GFP_O3B%CLNAME  .AND..NOT.LLO3ABC)&
     & .OR.(CFPPHY(JFLD) == GFP_O3C%CLNAME  .AND..NOT.LLO3ABC)&
     & .OR.(CFPPHY(JFLD) == GFP_PADOU%CLNAME.AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_PADOV%CLNAME.AND..NOT.(LMPHYS.AND..NOT.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_PSRHU%CLNAME.AND..NOT.LMPHYS)&
     & .OR.(CFPPHY(JFLD) == GFP_PCAPG%CLNAME.AND..NOT.LCANARI)&
     & .OR.(CFPPHY(JFLD) == GFP_PCAAG%CLNAME.AND..NOT.LCANARI)&
     & .OR.(CFPPHY(JFLD) == GFP_ALSN%CLNAME .AND..NOT.(LLSOLV.AND.(LSNV.OR.LVGSN)))&
     & .OR.(CFPPHY(JFLD) == GFP_SNDE%CLNAME .AND..NOT.(LLSOLV.AND.(LSNV.OR.LVGSN)))&
     & .OR.(CFPPHY(JFLD) == GFP_IC%CLNAME   .AND..NOT.LLSOLV)&
     & .OR.(CFPPHY(JFLD) == GFP_FDSW%CLNAME .AND..NOT.((LLSOLV.AND.LFGEL).OR.LLMSE))&
     & .OR.(CFPPHY(JFLD) == GFP_FSSW%CLNAME .AND..NOT.((LLSOLV.AND.LFGEL).OR.LLMSE))&
     & ) THEN  
      IERR=IERR+1
      CLMARK=CFPPHY(JFLD)//' IS UNDEFINED !'
      WRITE(NULERR,*) CLMARK
    ENDIF
  ENDDO
ENDIF
IF (IERR > 0) CALL ABOR1('FPINIPHY: ABOR1 CALLED')

IF (JPOSVX2 < NVXTR2) THEN
  CALL ABOR1('FPINIPHY : JPOSVX2 SMALLER THAN NVXTR2 !')
ENDIF

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