SUBROUTINE SURF_INQ(KNVTYPES,KNSOTY,PRRCSOIL,PRWSAT,PRWCAP,PRWPWP,PRQWEVAP,PRQWSBCR,&
                  & PRQSNCR,PRWLMAX,PRWSATM,PRWCAPM,PRWPWPM,PRTF1,PRTF2,PRTF3,PRTF4,&
                  & PRTFREEZSICE,PRTMELTSICE,PRCIMIN,PRALFMINSN,&
                  & PRALFMAXSN,PRHOMINSN,PRHOMAXSN,PRDAT,&
                  & PRDAW,PRRCSICE,PRALBSEAD,PREPALB,PRVCOV,PRVLAI,&
                  & PRVROOTSA,PRVLAMSK,PRVLAMSKS,PRVTRSR,PRCHAR,PREPUST,&
                  & PRDSCALE_KPP,PRVC_KPP,PRVD_KPP,PRVE_KPP,PRVDEL_KPP,LDVL_NEW_KPP)

!**   *SURF_INQ*  Extract information from the surface package

!     Purpose.
!     --------
!     Interface routine for extracting information from the surf pack.

!**   Interface.
!     ----------
!     CALL SURF_INQ(...)
!     Explicit arguments : All arguments are optional.
!     --------------------

!     Method.
!     -------

!     Externals: none

!     Author.
!     -------
!        JF Estrade *ECMWF*

!     Modifications.
!     --------------
!        Original : 03-10-01
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        G.Balsamo     01-Sep-2006 Add soil type related information
!     ------------------------------------------------------------------

USE PARKIND1     , ONLY : JPIM     ,JPRB

!ifndef INTERFACE

USE YOMHOOK      , ONLY : LHOOK,   DR_HOOK
USE YOS_SOIL     , ONLY : RRCSOIL, RWSAT,RWCAP,RWPWP,RQWEVAP,RQWSBCR,&
 & RQSNCR,RWLMAX,RTF1,RTF2,RTF3,RTF4,&
 & RTFREEZSICE,RTMELTSICE,RCIMIN,RALFMINSN,&
 & RALFMAXSN,RHOMINSN,RHOMAXSN,RDAT,&
 & RDAW,RRCSICE,&
 & RWSATM,RWCAPM,RWPWPM
USE YOS_DIM      , ONLY : NCSS, NTILES
USE YOS_SOIL     , ONLY : NSOTY
USE YOS_VEG      , ONLY : NVTYPES,RVCOV,RVLAI,RVROOTSA,RVLAMSK,RVLAMSKS,RVTRSR
USE YOS_RDI      , ONLY : RALBSEAD,REPALB
USE YOS_EXC      , ONLY : RCHAR,REPUST
USE YOS_OCEAN_ML , ONLY : RDSCALE_KPP,RVC_KPP,RVD_KPP,RVE_KPP,RVDEL_KPP,LVL_NEW_KPP
USE ABORT_SURF_MOD

!endif INTERFACE

IMPLICIT NONE

! Declaration of arguments

INTEGER(KIND=JPIM) ,OPTIONAL, INTENT(OUT) :: KNSOTY
INTEGER(KIND=JPIM) ,OPTIONAL, INTENT(OUT) :: KNVTYPES
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRRCSOIL
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWSAT
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRQWSBCR
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWCAP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWPWP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRQWEVAP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRQSNCR
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWLMAX
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWSATM(0:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWCAPM(0:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRWPWPM(0:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTFREEZSICE
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTMELTSICE
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRCIMIN
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRALFMINSN
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRALFMAXSN
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRHOMINSN
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRHOMAXSN
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRDAT(:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRDAW(:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRALBSEAD
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PREPALB
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVCOV(0:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVLAI(0:)
REAL(KIND=JPRB)    ,OPTIONAL,INTENT(OUT)  :: PRCHAR
REAL(KIND=JPRB)    ,OPTIONAL,INTENT(OUT)  :: PREPUST
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTF1
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTF2
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTF3
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRTF4
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRRCSICE
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVROOTSA(:,0:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVLAMSK(:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVLAMSKS(:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVTRSR(:)
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRDSCALE_KPP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVC_KPP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVD_KPP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVE_KPP
REAL(KIND=JPRB)    ,OPTIONAL, INTENT(OUT) :: PRVDEL_KPP
LOGICAL            ,OPTIONAL, INTENT(OUT) :: LDVL_NEW_KPP


!ifndef INTERFACE

INTEGER(KIND=JPIM) :: JK, JTYP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

IF (LHOOK) CALL DR_HOOK('SURF_INQ',0,ZHOOK_HANDLE)
IF(PRESENT(KNSOTY))  KNSOTY=NSOTY
IF(PRESENT(KNVTYPES))  KNVTYPES=NVTYPES
IF(PRESENT(PRRCSOIL))  PRRCSOIL=RRCSOIL
IF(PRESENT(PRWSAT))  PRWSAT=RWSAT
IF(PRESENT(PRWCAP))  PRWCAP=RWCAP
IF(PRESENT(PRWPWP))  PRWPWP=RWPWP
IF(PRESENT(PRQWEVAP))  PRQWEVAP=RQWEVAP
IF(PRESENT(PRQWSBCR))  PRQWSBCR=RQWSBCR
IF(PRESENT(PRQSNCR))  PRQSNCR=RQSNCR
IF(PRESENT(PRWLMAX))  PRWLMAX=RWLMAX

IF(PRESENT(PRWSATM)) THEN
  IF(UBOUND(PRWSATM,1) < NSOTY) THEN
    CALL ABORT_SURF('SURF_INQ: PRWSATM TOO SMALL')
  ELSE
    DO JTYP=0,NSOTY
      PRWSATM(JTYP)=RWSATM(JTYP)
    ENDDO
  ENDIF
ENDIF
IF(PRESENT(PRWCAPM)) THEN
  IF(UBOUND(PRWCAPM,1) < NSOTY) THEN
    CALL ABORT_SURF('SURF_INQ: PRWCAPM TOO SMALL')
  ELSE
    DO JTYP=0,NSOTY
      PRWCAPM(JTYP)=RWCAPM(JTYP)
    ENDDO
  ENDIF
ENDIF
IF(PRESENT(PRWPWPM)) THEN
  IF(UBOUND(PRWPWPM,1) < NSOTY) THEN
    CALL ABORT_SURF('SURF_INQ: PRWPWPM TOO SMALL')
  ELSE
    DO JTYP=0,NSOTY
      PRWPWPM(JTYP)=RWPWPM(JTYP)
    ENDDO
  ENDIF
ENDIF

IF(PRESENT(PRTF1))  PRTF1=RTF1
IF(PRESENT(PRTF2))  PRTF2=RTF2
IF(PRESENT(PRTF3))  PRTF3=RTF3
IF(PRESENT(PRTF4))  PRTF4=RTF4
IF(PRESENT(PRTFREEZSICE))  PRTFREEZSICE=RTFREEZSICE
IF(PRESENT(PRTMELTSICE))  PRTMELTSICE=RTMELTSICE
IF(PRESENT(PRCIMIN))  PRCIMIN=RCIMIN
IF(PRESENT(PRALFMINSN))  PRALFMINSN=RALFMINSN
IF(PRESENT(PRALFMAXSN))  PRALFMAXSN=RALFMAXSN
IF(PRESENT(PRHOMINSN))  PRHOMINSN=RHOMINSN
IF(PRESENT(PRHOMAXSN))  PRHOMAXSN=RHOMAXSN
IF(PRESENT(PRRCSICE))  PRRCSICE=RRCSICE
IF(PRESENT(PRALBSEAD)) PRALBSEAD=RALBSEAD
IF(PRESENT(PREPALB)) PREPALB=REPALB
IF(PRESENT(PRCHAR)) PRCHAR=RCHAR
IF(PRESENT(PREPUST)) PREPUST=REPUST

IF(PRESENT(PRDAT)) THEN
  IF(UBOUND(PRDAT,1) < NCSS) THEN
    CALL ABORT_SURF('SURF_INQ: PRDAT TOO SMALL')
  ELSE
    DO JK=1,NCSS
      PRDAT(JK)=RDAT(JK)
    ENDDO
  ENDIF
ENDIF

IF(PRESENT(PRDAW)) THEN
  IF(UBOUND(PRDAW,1) < NCSS) THEN
    CALL ABORT_SURF('SURF_INQ: PRDAW TOO SMALL')
  ELSE
    DO JK=1,NCSS
      PRDAW(JK)=RDAW(JK)
    ENDDO
  ENDIF
ENDIF

IF(PRESENT(PRVCOV)) THEN
  IF(UBOUND(PRVCOV,1) < NVTYPES) THEN
    CALL ABORT_SURF('SURF_INQ: PRVCOV TOO SMALL')
  ELSE
    DO JTYP=0,NVTYPES
      PRVCOV(JTYP)=RVCOV(JTYP)
    ENDDO
  ENDIF
ENDIF

IF(PRESENT(PRVLAI)) THEN
  IF(UBOUND(PRVLAI,1) < NVTYPES) THEN
    CALL ABORT_SURF('SURF_INQ: PRVLAI TOO SMALL')
  ELSE
    DO JTYP=0,NVTYPES
      PRVLAI(JTYP)=RVLAI(JTYP)
    ENDDO
  ENDIF
ENDIF

 IF(PRESENT(PRVROOTSA)) THEN
   IF(UBOUND(PRVROOTSA,1) < NCSS) THEN
     CALL ABORT_SURF('SURF_INQ: 1ST DIMENSION OF PRVROOTSA TOO SMALL')
   ELSE IF (UBOUND(PRVROOTSA,2) < NVTYPES) THEN
     CALL ABORT_SURF('SURF_INQ: 2ND DIMENSION OF PRVROOTSA TOO SMALL')
   ELSE
     DO JTYP=0,NVTYPES
       DO JK=1,NCSS
         PRVROOTSA(JK,JTYP)=RVROOTSA(JK,JTYP)
       ENDDO
     ENDDO
   ENDIF
 ENDIF

 IF(PRESENT(PRVLAMSK)) THEN
   IF(UBOUND(PRVLAMSK,1) < NTILES) THEN
     CALL ABORT_SURF('SURF_INQ: PRVLAMSK TOO SMALL')
   ELSE
     DO JTYP=1,NTILES
       PRVLAMSK(JTYP)=RVLAMSK(JTYP)
     ENDDO
   ENDIF
 ENDIF

 IF(PRESENT(PRVLAMSKS)) THEN
   IF(UBOUND(PRVLAMSKS,1) < NTILES) THEN
     CALL ABORT_SURF('SURF_INQ: PRVLAMSKS TOO SMALL')
   ELSE
     DO JTYP=1,NTILES
       PRVLAMSKS(JTYP)=RVLAMSKS(JTYP)
     ENDDO
   ENDIF
 ENDIF

 IF(PRESENT(PRVTRSR)) THEN
   IF(UBOUND(PRVTRSR,1) < NTILES) THEN
     CALL ABORT_SURF('SURF_INQ: PRVTRSR TOO SMALL')
   ELSE
     DO JTYP=1,NTILES
       PRVTRSR(JTYP)=RVTRSR(JTYP)
     ENDDO
   ENDIF
 ENDIF

IF(PRESENT(PRDSCALE_KPP)) PRDSCALE_KPP = RDSCALE_KPP
IF(PRESENT(PRVC_KPP))     PRVC_KPP     = RVC_KPP
IF(PRESENT(PRVD_KPP))     PRVD_KPP     = RVD_KPP
IF(PRESENT(PRVE_KPP))     PRVE_KPP     = RVE_KPP
IF(PRESENT(PRVDEL_KPP))   PRVDEL_KPP   = RVDEL_KPP
IF(PRESENT(LDVL_NEW_KPP)) LDVL_NEW_KPP = LVL_NEW_KPP

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

!endif INTERFACE

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

END SUBROUTINE SURF_INQ
