SUBROUTINE SUCDDH
!     ------------------------------------------------------------------

!**   *SUCDDH* IS THE SET-UP ROUTINE FOR MODULE *YOMCDDH*

!     Original    C.Jakob         E.C.M.W.F.      15/05/00

!     PURPOSE
!     -------

!          This routine fills the character arrays that 
!          contain the names of variables and fluxes for
!          the writeout of the surface variables/fluxes to
!          the DDH file. The arrays are kept in module YOMCDDH.
!          The writeout is performed in routine PPFIDH.  

!     INTERFACE.
!     ----------

!     CALL *SUCDDH* FROM *SU0YOMA*

!          JJMorcrette 020930  UV, PAR, CAPE 
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!        M.Hamrud      01-Dec-2003 CY28R1 Cleaning
!        JJMorcrette 20060721 PP of clear-sky PAR and TOA incident soalr radiation
!        S.Serrar      26-09-2005 add DDH names for GHG 
!        S.Serrar      07-09-2006 DDH names for new tracers
!        S.Serrar      17-07-2007 update DDH for GEMS adding methane
!        JJMorcrette 20061002 DDH for aerosol physics
!        JJMorcrette 20100512 bug-fix for FDIR, CDIR
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPRB, JPIM
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMCDDH  , ONLY : CADHTLS  ,CADHTSS  ,CADHTTS  ,CADHTIS  ,&
 & CADHSSS  ,CADHIIS ,CADHWLS  ,CADHFSS  
USE YOMMDDH  , ONLY : NDHVFS   ,NDHFFS   ,NDHVTLS  ,NDHFTLS  ,&
 & NDHVTSS  ,NDHFTSS ,NDHVTTS  ,NDHFTTS  ,NDHVTIS  ,&
 & NDHFTIS  ,NDHVSSS ,NDHFSSS  ,NDHVIIS  ,NDHFIIS  ,&
 & NDHVWLS  ,NDHFWLS   

USE YOM_YGFL, ONLY : LCO2SFC, NGHG, YGHG, NTRAC, YTRAC, LSF6SFC, &
 & NACTAERO, YAERO, LAEROSFC, LCH4SFC, YCH4S , YGRG, NGRG, LGRGSFC, &
 & LFIRE


IMPLICIT NONE

INTEGER(KIND=JPIM) :: JFLX

CHARACTER(LEN=3) :: CLTXT(7)

INTEGER(KIND=JPIM) :: JVAR , IFSVAR_ECMWF , IFSFLX_ECMWF
REAL(KIND=JPRB) :: ZHOOK_HANDLE
!     ------------------------------------------------------------------

!     1) Allocate the arrays

! Tiles
IF (LHOOK) CALL DR_HOOK('SUCDDH',0,ZHOOK_HANDLE)
ALLOCATE (CADHTLS(NDHVTLS+NDHFTLS))

! Snow energy budget
ALLOCATE (CADHTSS(NDHVTSS+NDHFTSS))

! Soil energy budget
ALLOCATE (CADHTTS(NDHVTTS+NDHFTTS))

! Sea-ice energy budget
ALLOCATE (CADHTIS(NDHVTIS+NDHFTIS))

! Snow water budget
ALLOCATE (CADHSSS(NDHVSSS+NDHFSSS))

! Interception layer water budget
ALLOCATE (CADHIIS(NDHVIIS+NDHFIIS))

! Soil water budget
ALLOCATE (CADHWLS(NDHVWLS+NDHFWLS))

! Free-style variables and fluxes
ALLOCATE (CADHFSS(NDHVFS+NDHFFS))

!     2) Fill the arrays with variable and flux names
!        Note: The order of names has to agree with the order
!              of filling the PDH**S arrays in CALLPAR
!              Generally variables should be before the fluxes.

! Tiles

CADHTLS(1)='SVGTLF'
CADHTLS(2)='SVGTLT'
CADHTLS(3)='SVGTLALB'
CADHTLS(4)='SFGTLSWDO'
CADHTLS(5)='SFGTLSWUP'
CADHTLS(6)='SFGTLLWDO'
CADHTLS(7)='SFGTLLWUP'
CADHTLS(8)='SFGTLSH'
CADHTLS(9)='SFGTLLH'
CADHTLS(10)='SFGTLG'
CADHTLS(11)='SFGTLE'

! Snow energy budget

CADHTSS(1)='SVLTSC'
CADHTSS(2)='SVLTST'
CADHTSS(3)='SVLTSCT'
CADHTSS(4)='SVLTSDEP'
CADHTSS(5)='SVLTSRHO'
CADHTSS(6)='SVLTSALB'
CADHTSS(7)='SFLTSSWDO'
CADHTSS(8)='SFLTSSWUP'
CADHTSS(9)='SFLTSLWDO'
CADHTSS(10)='SFLTSLWUP'
CADHTSS(11)='SFLTSSH'
CADHTSS(12)='SFLTSLH'
CADHTSS(13)='SFLTSG'
CADHTSS(14)='SFLTSMLT'
CADHTSS(15)='SFLTSESC' 

! Soil energy budget

CADHTTS(1)='SVLTTC'
CADHTTS(2)='SVLTTT'
CADHTTS(3)='SVLTTCT'
CADHTTS(4)='SVLTTDEP'
CADHTTS(5)='SFLTTSWDO'
CADHTTS(6)='SFLTTSWUP'
CADHTTS(7)='SFLTTLWDO'
CADHTTS(8)='SFLTTLWUP'
CADHTTS(9)='SFLTTSH'
CADHTTS(10)='SFLTTLH'
CADHTTS(11)='SFLTTG'
CADHTTS(12)='SFLTTMLT'
CADHTTS(13)='SFLTTGSN'
CADHTTS(14)='SFLTTGT'
CADHTTS(15)='SFLTTGESC'

! Sea-ice energy budget

CADHTIS(1)='SVITIC'
CADHTIS(2)='SVITIT'
CADHTIS(3)='SVITICT'
CADHTIS(4)='SVITIDEP'
CADHTIS(5)='SFITISWDO'
CADHTIS(6)='SFITISWUP'
CADHTIS(7)='SFITILWDO'
CADHTIS(8)='SFITILWUP'
CADHTIS(9)='SFITISH'
CADHTIS(10)='SFITILH'
CADHTIS(11)='SFITIG'
CADHTIS(12)='SFITIMLT'
CADHTIS(13)='SFITIGSN'

! Snow water budget

CADHSSS(1)='SVLSS'
CADHSSS(2)='SFLSSLSSF'
CADHSSS(3)='SFLSSCVSF'
CADHSSS(4)='SFLSSE'
CADHSSS(5)='SFLSSMLT'

! Interception layer water budget

CADHIIS(1)='SVLII'
CADHIIS(2)='SFLIILSINT'
CADHIIS(3)='SFLIICVINT'
CADHIIS(4)='SFLIIE'

! Soil water budget

CADHWLS(1)='SVLWL'
CADHWLS(2)='SVLWLI'
CADHWLS(3)='SFLWLLSTHR'
CADHWLS(4)='SFLWLCVTHR'
CADHWLS(5)='SFLWLMLTHR'
CADHWLS(6)='SFLWLRO'
CADHWLS(7)='SFLWLE'
CADHWLS(8)='SFLWLG'
CADHWLS(9)='SFLWLBGE'
CADHWLS(10)='SFLWLCOND'

! Free-style variables and fluxes

CADHFSS(1)='SVGFST2M'
CADHFSS(2)='SVGFSQ2M'
CADHFSS(3)='SVGFS10U'
CADHFSS(4)='SVGFS10V'
CADHFSS(5)='SVGFSTSK'
CADHFSS(6)='SVGFSZ0M'
CADHFSS(7)='SVGFSZ0H'
CADHFSS(8)='SVGFSAL'
CADHFSS(9)='SVGFSBLH'
CADHFSS(10)='SVGFSLF'
CADHFSS(11)='SVGFSIF'
CADHFSS(12)='SVGFSFG'
CADHFSS(13)='SVGFSZ'
CADHFSS(14)='SVGFSTCC'
CADHFSS(15)='SVGFSLCC'
CADHFSS(16)='SVGFSMCC'
CADHFSS(17)='SVGFSHCC'

IFSVAR_ECMWF=17

DO JVAR=1,NACTAERO
  CADHFSS(IFSVAR_ECMWF+JVAR)='SVGFS'//TRIM(YAERO(JVAR)%CNAME)
ENDDO
IFSVAR_ECMWF=IFSVAR_ECMWF+NACTAERO

DO JVAR=1,NGHG
  CADHFSS(IFSVAR_ECMWF+JVAR)='SVGFS'//TRIM(YGHG(JVAR)%CNAME)
ENDDO
IFSVAR_ECMWF=IFSVAR_ECMWF+NGHG

IF(YCH4S%LACTIVE)THEN
  CADHFSS(IFSVAR_ECMWF+1)='SVGFS'//TRIM(YCH4S%CNAME)
ENDIF

! all tracers
DO JVAR=1,NTRAC
!  IF(YTRAC(JVAR)%IGRBCODE==210182) THEN
    CADHFSS(IFSVAR_ECMWF+JVAR)='SVGFS'//TRIM(YTRAC(JVAR)%CNAME)
!  ENDIF
ENDDO
IFSVAR_ECMWF=IFSVAR_ECMWF+NTRAC

DO JVAR=1,NGRG
  CADHFSS(IFSVAR_ECMWF+JVAR)='SVGFS'//TRIM(YGRG(JVAR)%CNAME)
ENDDO
IFSVAR_ECMWF=IFSVAR_ECMWF+NGRG

CADHFSS(NDHFFS)='SVGFSINCSR'
CADHFSS(NDHVFS+1)='SFGFSSWDO'
CADHFSS(NDHVFS+2)='SFGFSLWDO'
CADHFSS(NDHVFS+3)='SFGFSSUND'
CADHFSS(NDHVFS+4)='SFGFSES'
CADHFSS(NDHVFS+5)='SFGFSSMLT'
CADHFSS(NDHVFS+6)='SFGFSLSR'
CADHFSS(NDHVFS+7)='SFGFSCR'
CADHFSS(NDHVFS+8)='SFGFSLSF'
CADHFSS(NDHVFS+9)='SFGFSCF'
CADHFSS(NDHVFS+10)='SFGFSSSHF'
CADHFSS(NDHVFS+11)='SFGFSSLHF'
CADHFSS(NDHVFS+12)='SFGFSSW'
CADHFSS(NDHVFS+13)='SFGFSLW'
CADHFSS(NDHVFS+14)='SFGFSE'
CADHFSS(NDHVFS+15)='SFGFSRO'
CADHFSS(NDHVFS+16)='SFGFSSWC'
CADHFSS(NDHVFS+17)='SFGFSLWC'
CADHFSS(NDHVFS+18)='SFGFSLSPF'
CADHFSS(NDHVFS+19)='SFGFSPAR'
CADHFSS(NDHVFS+20)='SFGFSUV'
CADHFSS(NDHVFS+21)='SFGFSCAPE'
CADHFSS(NDHVFS+22)='SFGFSPARC'
CADHFSS(NDHVFS+23)='SFGFSTISR'
CADHFSS(NDHVFS+24)='SFGFSVIMD'
CADHFSS(NDHVFS+25)='SFGFSTSRC'
CADHFSS(NDHVFS+26)='SFGFSTTRC'
CADHFSS(NDHVFS+27)='SFGFSFDIR'
CADHFSS(NDHVFS+28)='SFGFSCDIR'

IFSFLX_ECMWF=28

CLTXT(1)='SRC'
CLTXT(2)='DDP'
CLTXT(3)='SDM'
CLTXT(4)='WDL'
CLTXT(5)='WDC'
CLTXT(6)='NGT'
CLTXT(7)='TAU'

IF (LAEROSFC) THEN
  DO JVAR=1,NACTAERO
    DO JFLX=1,7
      CADHFSS(NDHVFS+IFSFLX_ECMWF+(JVAR-1)*7+JFLX)='SFGF'//TRIM(YAERO(JVAR)%CNAME)//CLTXT(JFLX)
    ENDDO
  ENDDO
  IFSFLX_ECMWF=IFSFLX_ECMWF+NACTAERO*7
ENDIF

IF(LCO2SFC) THEN
  CADHFSS(NDHVFS+IFSFLX_ECMWF+1)='SFGFSCO2O'
  CADHFSS(NDHVFS+IFSFLX_ECMWF+2)='SFGFSCO2B'
  CADHFSS(NDHVFS+IFSFLX_ECMWF+3)='SFGFSCO2A'
  IFSFLX_ECMWF=IFSFLX_ECMWF+3
  IF(LFIRE) THEN
    CADHFSS(NDHVFS+IFSFLX_ECMWF+1)='SFGFSCO2F'
    IFSFLX_ECMWF=IFSFLX_ECMWF+1
  ENDIF
ENDIF
IF(LCH4SFC) THEN
  CADHFSS(NDHVFS+IFSFLX_ECMWF+1)='SFGFSCH4AG'
  IFSFLX_ECMWF=IFSFLX_ECMWF+1
  IF(LFIRE) THEN
    CADHFSS(NDHVFS+IFSFLX_ECMWF+1)='SFGFSCH4F'
    IFSFLX_ECMWF=IFSFLX_ECMWF+1
  ENDIF
ENDIF
IF(LSF6SFC) THEN
  CADHFSS(NDHVFS+IFSFLX_ECMWF+1)='SFGFSSF6'
ENDIF
! general tracers
  DO JVAR=1,NTRAC
      CADHFSS(NDHVFS+IFSFLX_ECMWF+JVAR)='SFGF'//TRIM(YTRAC(JVAR)%CNAME)
  ENDDO
  IFSFLX_ECMWF=IFSFLX_ECMWF+NTRAC

IF (LGRGSFC) THEN
  DO JVAR=1,NGRG
      CADHFSS(NDHVFS+IFSFLX_ECMWF+JVAR)='SFGF'//TRIM(YGRG(JVAR)%CNAME)
  ENDDO
  IFSFLX_ECMWF=IFSFLX_ECMWF+NGRG
ENDIF

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

END SUBROUTINE SUCDDH     
