SUBROUTINE SUPARAR(KULOUT)

!**** *SUPARAR*   - Initialize common parameters used in physics for AROME 
!                   and SURFEX

!     Purpose.
!     --------
!           Initialize MODD_PARAMETERS, MODD_CST, MODD_CONF,
!           MODD_RAIN_ICE_DESCR, MODD_RAIN_ICE_PARAM, MODD_BUDGET  
!           parameters used in meso_NH Physics and aladin/meso_NH physics
!           interface 

!**   Interface.
!     ----------
!        *CALL* *SUPARAR(KULOUT)

!        Explicit arguments :
!        --------------------
!        KULOUT : Logical unit for the output

!        Implicit arguments :
!        --------------------
!        COMMON YOMPHY2

!     Method.
!     -------
!        See documentation

!     Externals.
!     ----------

!     Reference.
!     ----------
!        Documentation AROME 

!     Author.
!     -------
!        R. Zaaboul

!     Modifications.
!     --------------
!        Original : 28-Feb-2006
!     17-Apr-2007 S.Ivatek-S: Cleaning of not used ZGPAR and ZGPAR2
!     11-Jan-2008 Y.Seity: delete NDIAGFR for Surfex output replaced by nshists
! End Modifications
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK    ,DR_HOOK
USE YOM_YGFL  ,ONLY : YH 
USE YOMCT0    ,ONLY : NSHISTS
USE YOMARAR   ,ONLY : NRR      ,NRRL     ,NRRI     ,NSWB_MNH ,NGPAR    , &
 &          MINPRR   ,MACPRR   ,MINPRS   ,MACPRS   ,MINPRG   ,MACPRG   , &
 &          MALBDIR  ,MALBSCA  ,MVTS     ,MVEMIS   ,MSWDIR   ,MSWDIF   , &
 &          LOSUBG_COND        ,LOSUBG_AUCV        ,LOWARM   , LOSEDIC , &
 &          LOSIGMAS ,LSQUALL  ,NREFROI1 ,NREFROI2 ,VSQUALL  ,NPTP     , &
 &          NPRINTFR ,LDIAGWMAX,NDIAGWMAX,NDTCHEM  ,LAROBU_ENABLE,&
 &          MRAIN    ,MSNOW    ,MGZ0     ,MGZ0H    ,MVQS,&
 &          CMF_UPDRAFT, CMF_CLOUD, LMIXUV

USE YOMPHY    ,ONLY : LRAYFM   ,LRAYFM15
USE YOMDYN    ,ONLY : TSTEP
USE YOMDIM    ,ONLY : NUNDEFLD
USE YOMARPHY  ,ONLY : LMPA     ,LMSE
USE YOMIOS    ,ONLY : NPCKFGP 
USE YOMLUN    ,ONLY : NULNAM
USE YOMGPPB   ,ONLY : GPARBUF
USE GRIDPOINT_BUFFERS_MIX , ONLY : ALLOCATE_GRIDPOINT_BUFFER  


IMPLICIT NONE
!     ------------------------------------------------------------------

INTEGER(KIND=JPIM)               :: KULOUT ! UNDETERMINED INTENT
INTEGER(KIND=JPIM) :: INDEF

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "posnam.intfb.h"

!     ------------------------------------------------------------------
#include "namparar.h"
!     ------------------------------------------------------------------
!         1. Set implicit default values for YOMARAR
!  certaines à mettre en namelist ?
! for microphysics
IF (LHOOK) CALL DR_HOOK('SUPARAR',0,ZHOOK_HANDLE)
IF (YH%LACTIVE) THEN
  NRR=7
  NRRL=2
  NRRI=4
ELSE
  NRR=6
  NRRL=2
  NRRI=3
ENDIF
LOSUBG_COND=.FALSE.
LOSUBG_AUCV=.FALSE.
LOSIGMAS=.FALSE.
LOSEDIC=.FALSE.
NSWB_MNH=6
NPRINTFR=3600*36
! for squall line academic case
LSQUALL=.FALSE.
NREFROI1=1
NREFROI2=1 
VSQUALL=0._JPRB 
NPTP=1
LDIAGWMAX=.FALSE.
NDIAGWMAX=1
LOWARM=.TRUE.

! default option for Mass Flux Scheme (Pergaud et al)
CMF_UPDRAFT = 'EDKF'
! DIRE ou STAT
CMF_CLOUD ='DIRE'
LMIXUV= .TRUE.

! default value for chemical time step factor
NDTCHEM=1_JPIM
! default value for Budget
LAROBU_ENABLE=.FALSE.

!read namelist for parametrisations
CALL POSNAM(NULNAM,'NAMPARAR')
READ (NULNAM,NAMPARAR)
IF (.NOT.LMPA.AND..NOT.LRAYFM.AND..NOT.LRAYFM15) THEN
  NSWB_MNH=1
ENDIF
!       3.Initialisation du buffer contenant les variables pseudo-historiques

! initialisation de la dimension du buffer

NGPAR=0
INDEF=NUNDEFLD
MINPRR=INDEF
MACPRR=INDEF
MINPRS=INDEF
MACPRS=INDEF
MINPRG=INDEF
MACPRG=INDEF
MALBDIR=INDEF
MALBSCA=INDEF
MVTS=INDEF
MVEMIS=INDEF
MSWDIR=INDEF
MSWDIF=INDEF
MRAIN=INDEF
MSNOW=INDEF
MVQS=INDEF
MGZ0=INDEF
MGZ0H=INDEF

! initialisation des pointeurs

IF (LMPA) THEN
  NGPAR=6
  MINPRR=1
  MACPRR=2
  MINPRS=3
  MACPRS=4
  MINPRG=5
  MACPRG=6
  IF (LMSE) THEN
    NGPAR=NGPAR+3+4*NSWB_MNH
    MALBDIR=7
    MALBSCA=7+NSWB_MNH
    MVTS=MALBSCA+NSWB_MNH
    MVQS=MVTS+1
    MVEMIS=MVQS+1
    MSWDIR=MVEMIS+1
    MSWDIF=MSWDIR+NSWB_MNH
  ENDIF
ELSE
  IF (LMSE) THEN
    NGPAR=7
    MRAIN=1
    MSNOW=2
    MVTS=3
    MVQS=4
    MGZ0=5
    MGZ0H=6
    MVEMIS=7
    MALBSCA=8
    MALBDIR=MALBSCA+NSWB_MNH
    NGPAR=NGPAR+2*NSWB_MNH
    IF (LRAYFM.OR.LRAYFM15) THEN
      MSWDIR=MALBDIR+NSWB_MNH
      MSWDIF=MSWDIR+NSWB_MNH
      NGPAR=NGPAR+2*NSWB_MNH
    ENDIF
  ENDIF
ENDIF

! allocation du buffer 
IF (NGPAR /= 0) THEN
  CALL ALLOCATE_GRIDPOINT_BUFFER ('GPARBUF',GPARBUF,NGPAR,NPCKFGP)
  WRITE (KULOUT,*)'GPARBUF%IFIELDS et GPARBUF%IPACK',GPARBUF%IFIELDS,&
   & GPARBUF%IPACK  
ENDIF

!         4. Write in kulout
WRITE(UNIT=KULOUT,FMT='('' COMMON YOMARAR '')')
WRITE(UNIT=KULOUT,FMT='('' LOSUBG_COND = '',L5,'' LOSUBG_AUCV = '',L5, &
 & '' LOSEDIC = '',L5,''LOSIGMAS ='',L5,''LSQUALL = '',L5)')&
 & LOSUBG_COND, LOSUBG_AUCV, LOSEDIC, LOSIGMAS,LSQUALL  
WRITE(UNIT=KULOUT,FMT='('' NREFROI1 = '',I3, &
 & '' NREFROI2 = '',I3,'' VSQUALL = '',f6.2)')NREFROI1, NREFROI2,VSQUALL  
WRITE(UNIT=KULOUT,FMT='('' NGPAR = '',I3, &
 & '' MINPRR = '',I3,'' MACPRR = '',I3,'' MINPRS = '',I3,&
 & '' MACPRS = '',I3,'' MINPRG = '',I3,'' MACPRG = '',I3)')&
 & NGPAR,MINPRR,MACPRR,MINPRS,MACPRS,MINPRG,MACPRG  
WRITE(UNIT=KULOUT,FMT='('' MALBDIR = '',I3, &
 & '' MALBSCA = '',I3,'' MVTS = '',I3,'' MVEMIS = '',I3,&
 & ''NSWB_MNH = '',I3)')&
 & MALBDIR,MALBSCA,MVTS,MVEMIS,NSWB_MNH  
WRITE(UNIT=KULOUT,FMT='('' NPRINTFR = '',I3, ''NPTP = '',I3)')&
 & NPRINTFR,NPTP
WRITE(UNIT=KULOUT,FMT='('' LDIAGWMAX = '',L5, &
 & '' NDIAGWMAX = '',I3,'' NDTCHEM = '',I3)')&
 & LDIAGWMAX, NDIAGWMAX,NDTCHEM  
WRITE(UNIT=KULOUT,FMT='('' NRR = '',I3, &
 & '' NRRL = '',I3,'' NRRI = '',I3)')&
 & NRR, NRRL, NRRI  

! -----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('SUPARAR',1,ZHOOK_HANDLE)
END SUBROUTINE SUPARAR
