SUBROUTINE SUCUMF2(KSMAX)

!     THIS ROUTINE DEFINES DISPOSABLE PARAMETERS FOR 
!     THE LINEARIZED MASSFLUX SCHEME

!     P. Lopez, ECMWF (Aug 2006) Separate routine for new linearized convection.
!     R. Forbes, May 2008        Changed factor in RTAUMEL2 from 1.5 to 0.66

!          INTERFACE
!          ---------

!          THIS ROUTINE IS CALLED FROM *INIPHY*

!          MODIFICATIONS
!          -------------

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

USE YOMLUN   , ONLY : NULOUT   ,NULNAM
USE YOMDIM   , ONLY : NFLEVG
USE YOECUMF2 , ONLY : ENTRPEN2  ,ENTRSCV2 ,ENTRORG2 ,ENTRDD2 ,&
 & RMFDEPS2  ,RDEPTHS2  ,&
 & RPRCON2   ,RTAU2     ,RCUCOV2   ,RCPECONS2 ,RTAUMEL2 ,&
 & LMFMID2   ,LMFDD2    ,LMFDUDV2  ,LMFUVDIS2,&
 & NJKT12    ,NJKT22    ,NJKT32    ,RUVPER2   ,&
 & RMFSOLCT2 ,RMFSOLTQ2 ,RMFSOLUV2 ,&
 & RMFCMIN2  ,RMFCFL2   ,RMFLIC2   ,RMFLIA2
USE YOMCST  , ONLY : RG
USE YOMSTA  , ONLY : STPRE
USE YOMCUMFS , ONLY : LECUMFS, LECUMFS2, LREGCV  

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KSMAX

#include "namcumfs.h"

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

!     1.           SPECIFY PARAMETERS FOR LINEARIZED MASSFLUX-SCHEME
!                  -------------------------------------------------

!     ENTRPEN: AVERAGE ENTRAINMENT RATE FOR PENETRATIVE CONVECTION
!     -------

INTEGER(KIND=JPIM) :: JLEV
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "posnam.intfb.h"

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

!LLL ENTRPEN2=1.2E-4_JPRB
ENTRPEN2=0.8E-4_JPRB

!     ENTRSCV2: AVERAGE ENTRAINMENT RATE FOR SHALLOW CONVECTION
!     --------

ENTRSCV2=3.0E-4_JPRB

!     NOTA:ORGANIZED ENTRAINMENT RATES ARE MULTIPLIED BY rg in cuascn2.F90
!          AND VERTICALLY SCALED BY FUNCTION (qs/qsb)**3.

!     ENTRORG2: ORGANIZED ENTRAINMENT FOR POSITIVELY BUOYANT DEEP CONVECTION 1/(RG M)
!     --------  
!ENTRORG2=2.4E-4_JPRB
ENTRORG2=0.8E-4_JPRB

!     ENTRDD2: AVERAGE ENTRAINMENT RATE FOR DOWNDRAFTS
!     -------

ENTRDD2 =2.0E-4_JPRB

!     RMFCMIN2:   MINIMUM MASSFLUX VALUE (FOR SAFETY)
!     --------

RMFCMIN2=1.E-10_JPRB

!     RMFDEPS2:   FRACTIONAL MASSFLUX FOR DOWNDRAFTS AT LFS
!     --------

RMFDEPS2=0.35_JPRB

!     RDEPTHS2:   MAXIMUM ALLOWED SHALLOW CLOUD DEPTH (Pa)
!     --------

RDEPTHS2=2.E4_JPRB

!     RPRCON2:    COEFFICIENTS FOR DETERMINING CONVERSION FROM CLOUD WATE
!     -------

!LLL RPRCON2 =1.4E-3_JPRB !increased value to avoid UTropo warm bias
RPRCON2 =1.7E-3_JPRB 

!                COEFFICIENTS FOR RAIN EVAPORATION BELOW CLOUD
!                AND MELTING
!                ---------------------------------------------
!     RCPECONS2:  KESSLER COEFFICIENT
!     RCUCOV2:    ASSUMED CONVECTIVE CLOUD COVER
!     RTAUMEL2:   MELTING TIME SCALE

RCUCOV2=0.05_JPRB
RCPECONS2=5.44E-4_JPRB/RG
RTAUMEL2=5._JPRB*3.6E3_JPRB*0.66_JPRB

!     SET ADJUSTMENT TIME SCALE FOR CAPE CLOSURE AS A FUNCTION
!     OF MODEL RESOLUTION
!     RTAU IS 20 MINUTES FOR RESOLUTIONS HIGHER THAN TL319
!     RTAU IS 10 MINUTES FOR RESOLUTIONS HIGHER THAN TL511
!     RTAU IS 1 HOUR FOR ANY OTHER RESOLUTION
!     --------------------------------------------------------

RTAU2=3600.0_JPRB

IF (KSMAX > 319) RTAU2=1200.0_JPRB
IF (KSMAX > 511) RTAU2=600.0_JPRB

RTAU2=1.0_JPRB+0.33_JPRB*REAL(799)/REAL(KSMAX)
RTAU2=MIN(3.0_JPRB,RTAU2)

!     LOGICAL SWITCHES
!     ----------------

LMFMID2  =.TRUE.   ! mid-level convection
LMFDD2   =.TRUE.   ! use downdrafts
LMFDUDV2 =.TRUE.   ! use convective momentum transport
LMFUVDIS2=.FALSE.  ! use kinetic energy dissipation (addit T-tendency)

!     UPDRAUGHT VELOCITY PERTURBATION FOR IMPLICIT (M/S)
!     --------------------------------------------------

RUVPER2=0.3_JPRB

!     MASSFLUX SOLVERs FOR MOMEMTUM AND TRACERS
!     0: EXPLICIT 0-1 SEMI-IMPLICIT >=1: IMPLICIT
!     -------------------------------------------

RMFSOLUV2=1.0_JPRB  ! mass flux solver for momentum
RMFSOLTQ2=1.0_JPRB  ! mass flux solver for T and q 
RMFSOLCT2=1.0_JPRB  ! mass flux solver for chemical tracers

RMFLIC2=1.0_JPRB   ! use CFL mass flux limit (1) or absolut limit (0)
RMFLIA2=0.0_JPRB   ! value of absolut mass flux limit

!     TOP INTEGER LEVELS (cheaper computations)
!     -----------------------------------------

NJKT12=2
NJKT22=2
NJKT32=NFLEVG-2
DO JLEV=NFLEVG,2,-1
  IF (STPRE(JLEV) > 350.E2_JPRB) NJKT12=JLEV
  IF (STPRE(JLEV) >  60.E2_JPRB) NJKT22=JLEV
  IF (STPRE(JLEV) > 950.E2_JPRB) NJKT32=JLEV
ENDDO
NJKT32=MIN(NFLEVG-2,NJKT32)

WRITE(NULOUT,*)'SUCUMF2: NJKT12=',NJKT12,' NJKT22=',NJKT22,' NJKT32=',NJKT32
WRITE(UNIT=NULOUT,FMT='('' COMMON YOECUMF2 '')')
WRITE(UNIT=NULOUT,FMT='('' LMFMID2 = '',L5 &
 & ,'' LMFDD2 = '',L5,'' LMFDUDV2 = '',L5 &
 & ,'' RTAU2 = '',E12.5,'' s-1'')') &
 & LMFMID2,LMFDD2,LMFDUDV2,RTAU2  

!   NEW SIMPLIFIED CONVECTION SCHEME
!   --------------------------------

LECUMFS=.FALSE.
LECUMFS2=.FALSE.
LREGCV=.FALSE.

!     RMFCFL2: MASSFLUX MULTIPLE OF CFL STABILITY CRITERIUM
!     Default value for implicit formulation (resolution dependent)
!     -------------------------------------------------------------

!LOP IF(KSMAX >= 511) THEN
!LOP   RMFCFL2=3.0_JPRB
!LOP ELSE
!LOP   RMFCFL2=5.0_JPRB
!LOP ENDIF

CALL POSNAM(NULNAM,'NAMCUMFS')
READ(NULNAM,NAMCUMFS)

!LOP IF (RMFSOLTQ2 <= 0.5_JPRB) RMFCFL2=1.0_JPRB
!LOP Force mass flux limiter for T and q to 1*CFL (for stability)
RMFCFL2=1.0_JPRB

WRITE(UNIT=NULOUT,FMT='('' COMMON YOMCUMFS '')')
WRITE(UNIT=NULOUT,FMT='('' LECUMFS = '',L5 &
 & ,'' LECUMFS2 = '',L5 &
 & ,'' LREGCV = '',L5 &
 & )') &
 & LECUMFS,LECUMFS2,LREGCV  
WRITE(UNIT=NULOUT,FMT='('' RMFSOLUV2 = '',E12.5 &
 & ,'' RMFSOLTQ2 = '',E12.5,'' RMFSOLCT2 = '',E12.5)') &
 & RMFSOLUV2 ,RMFSOLTQ2 ,RMFSOLCT2  
WRITE(UNIT=NULOUT,FMT='('' RMFCFL2 = '',E12.5)') RMFCFL2  

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