SUBROUTINE M7_EMI &
  &( KIDIA , KFDIA , KLON  , KLEV  , KSW   , KTILES , KTRACER, &
  &  LDLAND, &
  &  PALB  , PALBP , PAPH  , PCI   , PDENS , PDEP   , &
  &  PFRTI , PFWMLT, PGELAM, PGEMU , PGUST , PHSDFOR, &
  &  PLSM  , PSNS  , PTIA  , PTS   , PTSPHY, PWIND  , &
  &  PWS1  , PWSMX , & 
  &  PBCBF , PBCFF , PBCGF , POMBF , POMFF , POMGF  , &
  &  PSO2L , PSO2H , PSOGF , PVOLC , PVOLE , PSOA   , PDMS, & 
  &  PCFLX , PCEN  , PAERODDF, PAEROU1 & 
  &)

!*** * M7_EMI* - CALL ALL ROUTINES FOR SOURCE TERMS

!**   INTERFACE.
!     ----------
!          *M7_EMI* IS CALLED FROM *  *.

!     AUTHOR.
!     -------
!       JJMorcrette, 20100105

!     MODIFICATIONS.
!     --------------
!        

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

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

USE YO_AERO_M7,ONLY : nm7aer, nseasalt, naermod, nmod
USE YO_AERO_TRAC,ONLY : idt_dms, idt_so2

USE YOEAERSRC ,ONLY : NAERWND
USE YOM_YGFL  ,ONLY : NGHG, NGRG, NTRAC, NACTAERO

IMPLICIT NONE

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

!*       0.1   ARGUMENTS
!              ---------

INTEGER(KIND=JPIM),INTENT(IN)    :: KLON , KIDIA, KFDIA, KLEV
INTEGER(KIND=JPIM),INTENT(IN)    :: KSW  , KTILES
INTEGER(KIND=JPIM),INTENT(IN)    :: KTRACER 

LOGICAL           ,INTENT(IN)    :: LDLAND(KLON)

REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPH(KLON,0:KLEV), PDENS(KLON,KLEV), PFRTI(KLON,KTILES)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALB(KLON)  , PALBP(KLON,KSW)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCI(KLON)   , PFWMLT(KLON), PDEP(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGELAM(KLON), PGEMU(KLON) , PGUST(KLON), PHSDFOR(KLON), PLSM(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSNS(KLON)  , PTIA(KLON)  , PTS(KLON)    
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWIND(KLON) , PWS1(KLON)  , PWSMX(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PBCBF(KLON) , PBCFF(KLON) , PBCGF(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: POMBF(KLON) , POMFF(KLON) , POMGF(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSO2L(KLON) , PSO2H(KLON) , PSOGF(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVOLC(KLON) , PVOLE(KLON) , PSOA(KLON) , PDMS(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSPHY

REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCFLX(KLON,KTRACER), PCEN(KLON,KLEV,KTRACER)

REAL(KIND=JPRB)   ,INTENT(OUT)   :: PAERODDF(KLON,NACTAERO,8), PAEROU1(KLON,KLEV)

REAL(KIND=JPRB) :: ZFLXM7(KLON,nm7aer), ZXTM1(KLON,KLEV,nm7aer)


!*       0.5   LOCAL VARIABLES
!              ---------------

INTEGER(KIND=JPIM) :: IAEM7BEG, IAEM7END, ISHFTAER, ISTO1, ISTO2, ITRACM7
INTEGER(KIND=JPIM) :: JAER

#include "m7_emi_car.intfb.h"
#include "m7_emi_dms.intfb.h"
#include "m7_emi_du.intfb.h"
#include "m7_emi_so2.intfb.h"
#include "m7_emi_ss_mon.intfb.h"
#include "m7_emi_ss_lsce.intfb.h"
#include "m7_drydep.intfb.h"

REAL(KIND=JPRB) :: ZHOOK_HANDLE
!-----------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('M7_EMI',0,ZHOOK_HANDLE)

!-- emissions are distributed 

!*      0.5  PREPARATORY WORK
!            ----------------

ISHFTAER=0
DO JAER=1,NGHG
  ISHFTAER=ISHFTAER+1
ENDDO
DO JAER=1,NTRAC
  ISHFTAER=ISHFTAER+1
ENDDO
DO JAER=1,NGRG
  ISHFTAER=ISHFTAER+1
ENDDO
IAEM7BEG=ISHFTAER+1
IAEM7END=ISHFTAER+nm7aer

ITRACM7=naermod+nmod

ZFLXM7(KIDIA:KFDIA,1:nm7aer)=0._JPRB
ZXTM1(KIDIA:KFDIA, 1:KLEV, 1:nm7aer) = &
  &   PCEN(KIDIA:KFDIA, 1:KLEV, IAEM7BEG:IAEM7END)


!*      0.7  INITIALIZE SURFACE DIAGNOSTIC QUANTITIES
!            ----------------------------------------

!-- NB: when running M7, NACTAERO and NM7AER should be equal

PAERODDF(KIDIA:KFDIA,1:nm7aer,1:8) = 0._JPRB


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

!*      1.   SURFACE (AND LOW-LEVEL) EMISSIONS
!            ---------------------------------

CALL M7_EMI_CAR &
  & ( KIDIA, KFDIA , KLON , &
  &   PCI  , PGELAM, PGEMU, PLSM , PWIND, &
  &   PBCBF, PBCFF , PBCGF, POMBF, POMFF, POMGF, &
  &   ZFLXM7 &
  & )

CALL M7_EMI_DMS &
  & ( KIDIA, KFDIA, KLON , &
  &   PCI  , PDMS , PLSM , PTS  , PWIND, &
  &   ZFLXM7 &
  & )     

CALL M7_EMI_DU &
  & ( KIDIA, KFDIA, KLON, KSW  , KTILES, NAERWND, &
  &   PALB , PALBP, PDEP, PFRTI, PGUST , PHSDFOR, PLSM, PSNS, PWIND, PWS1, &
  &   ZFLXM7 &
  & )     

CALL M7_EMI_SO2 &
  & ( KIDIA, KFDIA , KLON , &
  &   PCI  , PGELAM, PGEMU, PLSM, PWIND, &
  &   PSO2L, PSO2H , PSOGF, &
  &   ZFLXM7 &
  & )

IF (nseasalt == 1) THEN        !-- sea-salt emission a la Monahan et al., 1986
  CALL M7_EMI_SS_MON &
    & ( KIDIA, KFDIA, KLON , &
    &   PCI  , PLSM , PWIND, &
    &   ZFLXM7 &
    & )

ELSEIF (nseasalt == 2) THEN    !-- sea-salt emission a la LSCE
  CALL M7_EMI_SS_LSCE &
    & ( KIDIA, KFDIA, KLON , &
    &   PCI  , PLSM , PWIND, &
    &   ZFLXM7 &
    & )
   
ENDIF


!*      1.5  FILL THE 2-D DIAGNOSTICS WITH SOURCE FLUXES
!            -------------------------------------------

!--- for debugging/testing: no DMS, no SO2 => no SO4 aerosol (in principle!)

ZFLXM7(KIDIA:KFDIA,idt_dms)=0._JPRB
ZFLXM7(KIDIA:KFDIA,idt_so2)=0._JPRB


PAERODDF(KIDIA:KFDIA,1:nm7aer,1) = ZFLXM7(KIDIA:KFDIA,1:nm7aer)

ISTO1=1
ISTO2=ITRACM7
PAEROU1(KIDIA:KFDIA,ISTO1:ISTO2) = ZFLXM7(KIDIA:KFDIA,1:ITRACM7) 

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

!*      2.   DRY DEPOSITION
!            --------------

CALL M7_DRYDEP &
  &( KIDIA , KFDIA, KLON  , KLEV , KTILES, &
  &  LDLAND, &
  &  PAPH  , PCI  , PDENS , PFRTI, PFWMLT, PLSM , PSNS, &
  &  PTIA  , PTS  , PTSPHY, PWS1 , PWSMX , ZXTM1, &
  &  ZFLXM7 &
  & )

!*      2.5  FILL THE 2-D DIAGNOSTICS WITH DRY DEPOSITION FLUXES
!            ---------------------------------------------------

PAERODDF(KIDIA:KFDIA,1:nm7aer,2) = PAERODDF(KIDIA:KFDIA,1:nm7aer,1)-ZFLXM7(KIDIA:KFDIA,1:nm7aer)

ISTO1=30+1
ISTO2=30+ITRACM7
PAEROU1(KIDIA:KFDIA,ISTO1:ISTO2) = PAERODDF(KIDIA:KFDIA,1:ITRACM7,1)-ZFLXM7(KIDIA:KFDIA,1:ITRACM7) 

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

!*      3.   PUT BACK THE M7 INFORMATION IN THE RELEVANT GFL FIELDS
!            ------------------------------------------------------

PCFLX(KIDIA:KFDIA, IAEM7BEG:IAEM7END) = ZFLXM7(KIDIA:KFDIA, 1:nm7aer) 
PCEN(KIDIA:KFDIA, 1:KLEV, IAEM7BEG:IAEM7END) = ZXTM1(KIDIA:KFDIA, 1:KLEV, 1:nm7aer)

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