SUBROUTINE GSTATS_SETUP( KPROC,KMYPROC,KPRCIDS,&
 & LDSTATS,LDSTATSCPU,LDSYNCSTATS,LDDETAILED_STATS,LDBARRIER_STATS,LDBARRIER_STATS2,&
 & LDSTATS_OMP,LDSTATS_COMMS,LDSTATS_MEM,KSTATS_MEM,LDSTATS_ALLOC,&
 & LDTRACE_STATS,KTRACE_STATS,KPRNT_STATS,LDXML_STATS)

!**** *GSTATS_SETUP*  - Setup stats package

!     PURPOSE.  
!     --------
!      Setup gstats package


!**   INTERFACE.
!     ----------
!       *CALL* *GSTATS_SETUP

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

!        IMPLICIT ARGUMENTS
!        --------------------
!        Module YOMSTATS

!     METHOD.
!     -------


!     EXTERNALS.   USER_CLOCK - timing routine
!     ----------

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

!     AUTHOR.
!     -------
!        Mats Hamrud ECMWF

!     MODIFICATIONS.
!     --------------
!        ORIGINAL : 98-11-15
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB

USE YOMGSTATS

IMPLICIT NONE

LOGICAL :: LDSTATS
LOGICAL :: LDSTATSCPU
LOGICAL :: LDSYNCSTATS
LOGICAL :: LDDETAILED_STATS
LOGICAL :: LDBARRIER_STATS
LOGICAL :: LDBARRIER_STATS2
LOGICAL :: LDSTATS_OMP
LOGICAL :: LDSTATS_COMMS
LOGICAL :: LDTRACE_STATS
INTEGER(KIND=JPIM) :: KTRACE_STATS
INTEGER(KIND=JPIM) :: KPROC,KMYPROC
INTEGER(KIND=JPIM) :: KPRCIDS(KPROC)
INTEGER(KIND=JPIM) :: KSTATS_MEM
INTEGER(KIND=JPIM) :: KPRNT_STATS
LOGICAL :: LDSTATS_MEM
LOGICAL :: LDSTATS_ALLOC
LOGICAL :: LDXML_STATS
!     ------------------------------------------------------------------

LSTATS = LDSTATS
LSTATSCPU = LDSTATSCPU
LSYNCSTATS = LDSYNCSTATS
LDETAILED_STATS=LDDETAILED_STATS
LBARRIER_STATS=LDBARRIER_STATS
LBARRIER_STATS2=LDBARRIER_STATS2
LXML_STATS=LDXML_STATS
LSTATS_OMP = LDSTATS_OMP
LSTATS_COMMS = LDSTATS_COMMS
NSTATS_MEM = KSTATS_MEM
LSTATS_MEM = LDSTATS_MEM
LSTATS_ALLOC = LDSTATS_ALLOC
LTRACE_STATS = LDTRACE_STATS
IF(LTRACE_STATS) NTRACE_STATS = KTRACE_STATS

MYPROC_STATS = KMYPROC
NPROC_STATS  = KPROC
ALLOCATE(NPRCIDS_STATS(NPROC_STATS))
NPRCIDS_STATS(:) = KPRCIDS(1:NPROC_STATS)
IF(NPROC_STATS == 1) LSYNCSTATS = .FALSE.

IF (LTRACE_STATS .AND. NTRACE_STATS>0 ) THEN
  ALLOCATE(NCALL_TRACE(NTRACE_STATS))
  ALLOCATE(TIME_TRACE (NTRACE_STATS))
  NCALL_TRACE(:) = 0
  TIME_TRACE (:) = 0.0_JPRB
ENDIF

NPRNT_STATS=KPRNT_STATS

! write(0,*) "GSTATS_SETUP: NPRNT_STATS=",NPRNT_STATS

RETURN
END SUBROUTINE GSTATS_SETUP


