PROGRAM MASTER

USE PARKIND1  ,ONLY : JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE OML_MOD, ONLY : OML_INIT, OML_INIT_LOCK, OML_MAX_THREADS
USE STACK_MIX
USE YOMERRTRAP
USE YOMABRT
USE CPLNG

IMPLICIT NONE

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

#include "cnt0.intfb.h"

! Must be first for signal handlers
!$OMP PARALLEL DO PRIVATE(I),SCHEDULE(STATIC,1)
DO I=1,OML_MAX_THREADS()
  CALL SET_ERR_TRAP
ENDDO
!$OMP END PARALLEL DO 

! OASIS3 or OASIS4 interface must be initialized before any DR_HOOK call.
CALL CPLNG_INIT

IF (LHOOK) CALL DR_HOOK('MASTER',0,ZHOOK_HANDLE)
CALL INIT_STACK(1)

CALL OML_INIT_LOCK(MAB_LOCK(1))

CALL CNT0

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

! OASIS3 or OASIS4 interface must be finalised after last DR_HOOK call.
CALL CPLNG_FINALIZE

END PROGRAM MASTER
