MODULE YOMSPSDT

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE SPECTRAL_ARP_MOD, ONLY : SPECTRAL_ARP
USE GRIDPOINT_FIELDS_MIX, ONLY : GRIDPOINT_FIELD

IMPLICIT NONE

SAVE

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

!*    control parameters for Stochastically Perturbed Parametrization Tendency 
!*    scheme (SPPT; a.k.a. stochastic physics)

!     LSPSDT              .T. when spectral SDT scheme is used
!     LCLIP_SPEC_SDT      .T. when spherical harmonics  coefficients are clipped
!     LCLIP_GRID_SDT      .T. when the grid point field is clipped
!     LWRITE_ARP          .T. to write ARP to GRIB file
!     COPATSP_SDT         File name for spectral representation of AR(1)
!     COPATGP_SDT         File name for gridpoint representation of AR(1), i.e. sum of
!                         all scales and possibly clipped.

!     LUSESETRAN_SDT      .T. implies that setran is used to modify the seed value
!     NSEED_SDT           integer seed for random number generator
!     LRESETSEED_SDT      reset the random number seed at each timestep to get reproducible results when restart is performed
!     SDEV_SDT            Standard deviation of multiplicative noise in grid point space
!     TAU_SDT             Correlation time scale of Markov chain

!     CSPEC_SHAPE_SDT     Shape of variance spectrum
!     XLCOR_SDT           horizontal correlation length scale (m)
!     XWC_KAPPA_T         Coefficient controlling the Weaver&Courtier (2001) spectrum
!     NWAVES_TESTSPEC_SDT number of wave numbers with nonzero power in test spectrum
!     NWN_TESTSPEC_SDT    wavenumbers with nonzero power in test spectrum
!     XCLIP_RATIO_SDT     Relative amplitude at which the clipping takes place
!
!     LRDPATINIT_SDT       .T. read initial state of pattern from a grib file
!     LWRPATTRUN_SDT       .T. write state of pattern at truncation time to grib file
!     CIPATINIT_SDT       File name for initial state of pattern
!     COPATTRUN_SDT       File name for pattern at VAREPS truncation timestep
!
!     LQPERTLIMIT         .T. quasi-symmetric limiting of humidity perturbations 
!                             between 0 and saturation
!     NQSAT_SDT           0, original treatment of supersaturation
!                         3 moderated amplitude applied vertically consistent
!     XMEANRED_THICKNESS_SDT layer thickness (Pa) over which reduction factor is computed
!     LTAPER_BL0          .T. to taper perturbations to 0 in the boundary layer
!     XSIGMATOP           normalized pressure of top of tapering layer
!     XSIGMABOT           normalized pressure of bottom of tapering layer
!     LTAPER_ST0          .T. to taper perturbations to 0 above tropopause
!     XPRESSTOP_ST0       pressure at top of tapering layer
!     XPRESSBOT_ST0       pressure at bottom of tapering layer

!     LFIXSPPT            .T. when average changes of physical tendencies are fixed to 0 in FIXSPPT

INTEGER(KIND=JPIM)            :: NSCALES_SDT
INTEGER(KIND=JPIM), PARAMETER :: NMAXSCALES_SDT=5
INTEGER(KIND=JPIM)            :: NWAV_TESTSPEC_SDT
INTEGER(KIND=JPIM), DIMENSION(4000) :: NWN_TESTSPEC_SDT
INTEGER(KIND=JPIM) :: NSEED_SDT

REAL(KIND=JPRB), DIMENSION(NMAXSCALES_SDT)    :: SDEV_SDT 
REAL(KIND=JPRB), DIMENSION(NMAXSCALES_SDT)    :: TAU_SDT
REAL(KIND=JPRB), DIMENSION(NMAXSCALES_SDT)    :: XWC_KAPPA_T
REAL(KIND=JPRB), DIMENSION(NMAXSCALES_SDT)    :: XLCOR_SDT 
REAL(KIND=JPRB)    :: XCLIP_RATIO_SDT
REAL(KIND=JPRB)    :: XMEANRED_THICKNESS_SDT
REAL(KIND=JPRB)    :: SDEVTOT_SDT

LOGICAL            :: LSPSDT 
LOGICAL            :: LFIXSPPT 
LOGICAL            :: LCLIP_SPEC_SDT
LOGICAL            :: LCLIP_GRID_SDT
LOGICAL            :: LWRITE_ARP
LOGICAL            :: LQPERTLIMIT2
LOGICAL            :: LRDPATINIT_SDT 
LOGICAL            :: LWRPATTRUN_SDT

INTEGER(KIND=JPIM) :: NQSAT_SDT
LOGICAL            :: LUSESETRAN_SDT 
LOGICAL            :: LRESETSEED_SDT 

CHARACTER(LEN=128) :: CSPEC_SHAPE_SDT
CHARACTER(LEN=256) :: CIPATINIT_SDT
CHARACTER(LEN=256) :: COPATTRUN_SDT
CHARACTER(LEN=256) :: COPATSP_SDT
CHARACTER(LEN=256) :: COPATGP_SDT

LOGICAL            :: LTAPER_BL0
REAL(KIND=JPRB)    :: XSIGMATOP
REAL(KIND=JPRB)    :: XSIGMABOT

LOGICAL            :: LTAPER_ST0
REAL(KIND=JPRB)    :: XPRESSTOP_ST0
REAL(KIND=JPRB)    :: XPRESSBOT_ST0

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

TYPE (SPECTRAL_ARP)    :: YSPSDT_AR1
TYPE (GRIDPOINT_FIELD) :: YGPSDT

REAL(KIND=JPRB)        :: XTAPER3, XTAPER2, XTAPER1, XTAPER0
REAL(KIND=JPRB)        :: XTAPER3_ST0, XTAPER2_ST0, XTAPER1_ST0, XTAPER0_ST0
END MODULE YOMSPSDT
