SUBROUTINE SCAN2H(CDCONF)

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

USE YOMCT0   , ONLY : NCONF    ,NPROC
USE YOMLDDH  , ONLY : LHDOUFG  ,LHDOUFZ  ,LHDOUFD  ,LHDOUP
USE YOMSEP   , ONLY : NVSEPC   ,NVSEPL   ,LFINDVSEP
USE MPL_MODULE, ONLY : MPL_ALLREDUCE

!**** *SCAN2H* - Caller for SCAN2M*

!     Purpose.
!     --------
!        Prepare for calling SCAN2M.
!        Calls SCAN2M - interface to grid-point computations.

!**   Interface.
!     ----------
!        *CALL* *SCAN2H(CDCONF)

!        Explicit arguments :  CDCONF - configuration of work (see doc.)
!        --------------------

!        Implicit arguments :  None.
!        --------------------

!     Method.
!     -------

!     Externals.   SCAN2M  - comp. in grid-point space
!     ----------   
!                  ZERODDH - zero DDH fields
!                  USER_CLOCK - timing

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

!     Author.
!     -------
!        Mats Hamrud  *ECMWF*

!     Modifications.
!     --------------
!        Original : 93-03-01
!        R. El Khatib : 93-05-10 Spectral brake"
!        Modified : 93-01-18 M.Hamrud (use only one Fourier file)
!        Modified by K. YESSAD and R. EL KHATIB: 18/02/1994:
!                         Harmonisation of enhanced diffusions (LFREIN).
!        Modified : 94-04-05 Ryad El Khatib (Full-POS implementation)
!        Modified : 94-04-08 M.Hamrud (upper air grid point workfile)
!        Modified by K. YESSAD (MARCH 1997): parallelisation of FULL-POS.
!        Modified by D. Dent (OCTOBER 1997): replace SECOND by USER_CLOCK
!        Modified 98-08-10 by K. YESSAD: removal of LRPOLE option.
!        - removal of LRPOLE in YOMCT0 and code under LRPOLE.
!        Modified : 00-02-10 C. Temperton (NVSEP, used in S/L adjoint)
!        Modified 00-06-15 by C. Temperton: NVSEP -> NVSEPC,NVSEPL.
!        Modified 00-04-18 by M. Szczech: add horizontal diffusion for O3.
!        R. El Khatib : 00-07-28 fullpos buffer 2 only in  new conf. 'G'  ;
!                    reorganize fullpos conf(5:5)
!        Modified 00-08-03 by M.Hamrud : remove shared memory option
!        R. El Khatib : 02-21-20 Fullpos B-level distribution + rm IO scheme
!        R. El Khatib : 03-04-17 Fullpos improvemnts
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        K. Yessad 04-11-15: debugging in enhanced diffusion + minor cleanings
!        20-Feb-2005 J. Vivoda     2D vertical model fix
!        K. Yessad (Sep 2008): prune enhanced diffusion (lfrein).
!     ------------------------------------------------------------------

IMPLICIT NONE

CHARACTER(LEN=9)  ,INTENT(IN)    :: CDCONF 

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

LOGICAL :: LLDUM, LLVFP
REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "ini1scan2m.intfb.h"
#include "scan2m.intfb.h"
#include "zeroddh.intfb.h"

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

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

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

!*       1.    CALL COMPUTATIONS DONE IN GRID-POINT SPACE.
!              -------------------------------------------

!*    1.1   INITIAL SETTINGS

IF (NCONF == 1.OR.NCONF==302) THEN
  IF (LHDOUFG.OR.LHDOUFZ.OR.LHDOUFD.OR.LHDOUP) CALL ZERODDH
ENDIF

!*    1.2   ALLOCATE AUXILIARY BUFFER FOR PRESSURE LEVEL POST PROCESSING

CALL INI1SCAN2M(CDCONF,NCONF,LLDUM,LLDUM,LLVFP,LLDUM,LLDUM)

!*    1.3   CALLS GRID-POINT CALCULATIONS

CALL SCAN2M(CDCONF)

!*    1.4   COMMUNICATE NVSEPC AND NVSEPL

IF (NPROC > 1.AND.LFINDVSEP) THEN
  CALL GSTATS(521,0)
  CALL MPL_ALLREDUCE(NVSEPC,'MAX',CDSTRING='SCAN2H:')
  CALL MPL_ALLREDUCE(NVSEPL,'MAX',CDSTRING='SCAN2H:')
  CALL GSTATS(521,1)
ENDIF

8 FORMAT(1X,'ARRAY ',A10,' ALLOCATED ',8I8)
9 FORMAT(1X,'ARRAY ',A10,' DEALLOCATED ')

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