#ifdef RS6K
@PROCESS NOCHECK
#endif
SUBROUTINE GP_MODEL(CDCONF)
!****-------------------------------------------------------------------
!**** *GP_MODEL* - Grid-point model
!****-------------------------------------------------------------------
!     Purpose.   Computations in grid-point space 
!     --------   

!**   Interface.
!     ----------
!        *CALL* *GP_MODEL (..)

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

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

!     Method.
!     -------

!     Externals.   See includes below.
!     ----------

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

!     Author.
!     -------
!        Deborah Salmond   *ECMWF*

! Modifications
! -------------
!   C. Fischer   01-03-06: Merge LAM version into global code
!   K. YESSAD    01-07-06: Update dummy arguments of CALL_SL.
!   Modified 01-08-30 by K. YESSAD: pruning and some other cleanings.
!   R. El Khatib 01-08-07: Pruning options
!   D.Salmond (15-10-01) FULLIMP mods
!   J.Vivoda (03-2002) PC schemes for NH dynamics (LPC_XXXX keys) 
!   K. YESSAD (10-2002): option lwrtcfou=T: allow to store a temporal
!    average of transmission coefficients + cleanings.
!   P.Smolikova 02-09-30 : variable d4 in NH (GPPAUX etc.)
!   R. El Khatib : 02-21-20 Fullpos B-level distribution + remove IO scheme
!   Modified 02-10-01 G.Mozdzynski: support for radiation on-demand comms
!   C. Fischer   03-07-16: gppaux -> gmv or zslbuf2aux and zgt1aux -> gmvt1
!   K. YESSAD (04-2003): bug correction for CALL_SL.
!   G. Hello (11-2003): initialization of ZSLBUF to zero.
!   M. Tudor (10-2003): GFLPT
!   01-Oct-2003 M. Hamrud  CY28 Cleaning
!     Modified 04-01-21 C.Temperton: bugfixes for SWE.
!     M.Hortal   01-12-2003  Introduce the possibility of extra-fields coming from the dynamics
!     D.Salmond  02-Apr-2004 Rain Assimilation
!   10-Jun-2004 J. Masek   NH cleaning (LPC_NOTR, LFULLIMP)
!   01-Jul-2004 K. Yessad  Make clearer the tests for PC scheme.
!   29-Jul-2004 R. El Khatib  Security with NRADFR
!   06-Dec-2004 J. Hague  Load Balancing for Rain Assimilation
!   17-Feb-2005 J. Hague  Multiple Helpers for Load balancing
!   15-Feb-2006 R. Zaaboul  Remove call to SURFEXT
!   22-Nov-2005 D.Salmond & M.Hortal   Mods for coarser/finer physics
!   22-Nov-2005 J. Hague   Clean Load balancing
!   03-03-2006  R.Brozkova set T1 arrays to zero for security (extension zone problem)
!   05-04-2006  M. Jidane : CY31 Phasing
!   01-08-2006  D. Salmond : 4D-Var rain assimilation
!   06-Feb-2007 A.Geer   Call 1DVAR rain during final analysis trajectory to get TBs
!   04-Jun-2007 M. Jidane  : Fix NSLCORE bug
!   25-Apr-2008 A. Geer    : Mutilple sensor 4D-Var rain assimilation
!   23-APR-2008 S.Serrar   : A Tracer Mass Fixer is implemented for GEMS/GHG (controlled by LTRCMFIX)
!   N. Wedi and K. Yessad (Jan 2008): different dev for NH model and PC scheme
!   01-Oct-2008 A. Geer    : Rainy 4D-Var tidying up
!   GMozdzynski/JJMorcrette 20090129 bugfix dynamical extra fields
!   K. Yessad Dec 2008: merge SLCOMM+SLCOMM1 -> SLCOMM.
!   K. Yessad Dec 2008: merge the different (E)SLEXTPOL.. -> (E)SLEXTPOL.
!   09-Mar-2009 W. Bell    : Add azimuth angle for windsat
!   10-Jun-2009 A. Geer   Rainy 4D-Var passive mode and diagnostics
!   16-Dec-2009   F. Karbou	 Allow surface emissivity handling
! End Modifications
!------------------------------------------------------------------------------
!   2013 J. von Hardenberg :  EC-Earth backporting of Advection Mass Fixer routine from c38r1

USE PARKIND1 , ONLY : JPIM     ,JPRB
USE YOMHOOK  , ONLY : LHOOK    ,DR_HOOK
USE YOMVAR , ONLY: NUPTRA, MUPTRA
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA   ,NGPBLKS  ,NDGENL   ,&
 & NDGLG    ,NDGSAG   ,NDGENG   ,NDGSAL  
USE YOMCT0   , ONLY : NSTOP    ,LSLAG    ,NPROC    ,LRETCFOU ,LWRTCFOU ,&
 & NCONF    ,LELAM    ,LCANARI  ,LPC_FULL ,LTWOTL, LSCREEN, LCOUPLO4_ENV
USE YOMCT3   , ONLY : NSTEP
USE YOMGEM   , ONLY : RCOLON   ,RSILON   ,RINDX    ,RINDY    ,NLOENG   ,&
 & RATATH   ,RATATX   ,NGPTOT   ,NGPTOT_CAP  ,VAH   ,VBH
USE YOMDYN   , ONLY : NSITER   ,NCURRENT_ITER
USE YOMGC    , ONLY : RCORI    ,GEMU     ,GSQM2    ,GELAM    ,&
 & GECLO    ,GESLO    ,GM       ,GOMVRL   ,GOMVRM   ,&
 & GNORDL   ,GNORDM   ,OROG     ,OROGL    ,OROGM  
USE YOMSC2   , ONLY : NFLDSLB1 ,NFLDSLB2 ,NSLWIDE 
USE YOERAD   , ONLY : NRADFR
USE YOEPHY   , ONLY : LEPHYS   ,LERADI   ,LAGPHY    ,LERAIN  ,NEPHYS_PCFULL ,&
 & LEMWAVE, LESMOS
USE YOMMP    , ONLY : NSLCORE  ,NASLB1   ,NSLPROCS ,NSLPAD   ,&
 & NSLRPT  ,NSLSPT   ,NSLSENDPOS,&
 & NSLRECVPOS,NSENDPTR,NRECVPTR ,NSLCOMM   ,&
 & NSLSTA    ,NSLONL  ,NSLOFF   ,NFRSTLOFF ,&
 & MYFRSTACTLAT       ,MYLSTACTLAT
USE PTRSLB1  , ONLY : RPARSL1   
USE YOMGMV   , ONLY : GMV,GMVS,GMVT1,GMVT1S,YT0,YT9,YT1,YPH9
USE YOMGFL   , ONLY : GFL,GFLT1,GFLPT,GFLPC
USE YOMSEP   , ONLY : NVSEPC, NVSEPL, LFINDVSEP
USE YOMSLPHY , ONLY : LSLPHY
USE YOMDPHY  , ONLY : NVEXTRDYN
USE YOM_YGFL , ONLY : YGFL, YGHG, LTRCMFIX, NGHG
USE OML_MOD, ONLY : OML_MAX_THREADS
USE YOMCPG   , ONLY : LCPG_SPLIT
USE YOM_PTR_SSMI , ONLY : LERAIN_ACTIVE, M_TB_OB
USE YOMMWAVE , ONLY : LEMWAVE_ACTIVE, N_SATSENS, NMWAVE_DIAG, NMWAVE_P, NMWAVE_GNRM
USE YOMSMOS  , ONLY : LESMOS_ACTIVE, NPOL_MAX
USE PARMWAVE , ONLY : NMAX_CHAN
USE YOMPHY   , ONLY : LMPHYS
USE YOM_SSMI , ONLY : RAIN_2DCHAN_GP
USE YOMONEDVAR , ONLY : LERAIN_LB, STREAM1D_NUM, STREAM1D_MODE, &
  & STREAM1D_ACTIVE
USE MPL_MODULE , ONLY : MPL_BARRIER, MPL_ALLGATHERV
USE YOMDYNCORE, ONLY : LAQUA, LHELDSUAREZ
USE YOMTVRAD , ONLY : MNSERIES 

USE YOE_CUCONVCA  , ONLY : LCUCONV_CA

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

IMPLICIT NONE

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

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


REAL(KIND=JPRB) :: ZEXTRADYN(NPROMA,NFLEVG,NVEXTRDYN,NGPBLKS)

!   --- PHYSICS TENDENCIES TO BE INTERPOLATED AT THE ORIGIN POINT ---
REAL(KIND=JPRB), ALLOCATABLE :: ZPBUP9(:,:,:),ZPBVP9(:,:,:),ZPBTP9(:,:,:),&
 & ZPBGFLP9(:,:,:,:)  
!   --- MISCELLANEOUS ---
REAL(KIND=JPRB), ALLOCATABLE :: ZSLBUF1AUX(:,:),ZSLBUF1(:,:),ZSLBUF2(:,:,:)

INTEGER(KIND=JPIM) :: IBL,ICEND,ICENDE,&
 & IOFF,JKGLO,JROF,IGPCOMP,IBLKS

INTEGER(KIND=JPIM) :: IVSEPC(NGPBLKS), IVSEPL(NGPBLKS)
INTEGER(KIND=JPIM) :: IDUMARR(2)

LOGICAL :: LLADNMI,LLINC,LLRETCFOU,LLWRTCFOU0,LL2D
LOGICAL :: LL_CALLRADDRV
LOGICAL :: LL_CALL_SL

REAL(KIND=JPRB) :: ZZZ

INTEGER(KIND=JPIM) :: IST, IEND, JLEV , JGFL
REAL(KIND=JPRB) :: ZPRE9(NPROMA,0:NFLEVG),ZPRE1(NPROMA,0:NFLEVG)

REAL(KIND=JPRB) :: ZSPT1(NPROMA),ZSPT9(NPROMA)

REAL(KIND=JPRB) :: ZFIELD3DT1(NPROMA,NFLEVG),ZFIELD3DT0(NPROMA,NFLEVG)
REAL(KIND=JPRB) :: ZFIELD2DT1(NPROMA,0:NFLEVG),ZFIELD2DT0(NPROMA,0:NFLEVG)
REAL(KIND=JPRB) :: ZFIELD1D(NPROMA,2*NGHG,NGPBLKS) ,ZNORMS(3,2*NGHG) 


!------ Timing and Printout Variables ----------------
CHARACTER(LEN=1) :: CLCONF 
INTEGER(KIND=JPIM) :: ICNTA(NPROC)
INTEGER(KIND=JPIM) :: J,ICNT,IFIRST=0,JSTREAM1D

REAL(KIND=JPRB), ALLOCATABLE :: ZMWAVE_OBS_BUF(:,:,:), &
  & ZMWAVE_TB_BUF(:,:,:), ZMWAVE_OERR_BUF(:,:,:), &
  & ZMWAVE_DIAG_BUF(:,:,:), ZMWAVE_GNORM_BUF(:,:,:), ZMWAVE_ZEN_BUF(:,:), &
  & ZMWAVE_AZI_BUF(:,:),ZMWAVE_P19_BUF(:,:,:), ZMWAVE_P37_BUF(:,:,:), &
  & ZMWAVE_PERS1_BUF(:,:,:)
INTEGER(KIND=JPIM), ALLOCATABLE :: IMWAVE_BUF(:,:,:)

REAL(KIND=JPRB), ALLOCATABLE :: ZSMOS_OBS_BUF(:,:), ZSMOS_TB_BUF(:,:), ZSMOS_ANGLE(:,:)
INTEGER(KIND=JPIM), ALLOCATABLE :: ISMOS_BUF(:,:) 

REAL(KIND=JPRB) :: ZHOOK_HANDLE

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

#include "abor1.intfb.h"
#include "call_sl.intfb.h"
#include "cpg.intfb.h"
#include "cpg2.intfb.h"
#include "cpg2lag.intfb.h"
#include "cpglag.intfb.h"
#include "define_pointers_mp9.intfb.h"
#include "gp_ssmi.intfb.h"
#include "gp_ssmi_inv.intfb.h"
#include "gp_ptr_ssmi.intfb.h"
#include "mwave_get.intfb.h"
#include "mwave_put.intfb.h"
#include "mwave_get_tl.intfb.h"
#include "smos_process.intfb.h"
#include "smos_update.intfb.h"
#include "ec_phys_drv.intfb.h"
! #include "surfext.intfb.h"
#include "raddrv.intfb.h"
#include "slcomm.intfb.h"
#include "slextpol.intfb.h"
#include "onedvar_raintb_prc.intfb.h"
#include "couplo4_exchange.intfb.h"

#include "gpnorm1.intfb.h"
#include "gppwc.intfb.h"
#include "gppreh.intfb.h"

#include "sucuconv_ca.intfb.h"
#include "tracmf.intfb.h"

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

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

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

!     ------------------------------------------------------------------
!*       1.    INITIALISATION 
!     ------------------------------------------------------------------

ZEXTRADYN(:,:,:,:)=0.0_JPRB

! Total number of grid points - ndglg*ndlon in global / ndguxg*ndlon in LAM
! used for model computations

! Changed NGPTOT into IGPCOMP in order to pass properly
! the scan of NSLCORE values for the LAM models
IF(.NOT.LELAM) THEN
  IGPCOMP=NGPTOT
ELSE
  IGPCOMP=MIN(NGPTOT,NGPTOT_CAP)
ENDIF

IF(NCONF/100 == 2.OR.NCONF/10 == 42.OR.NCONF/10 == 52) THEN
  LL2D = .TRUE.
ELSE
  LL2D = .FALSE.
ENDIF

LLRETCFOU = (.NOT.LAGPHY).AND.(CDCONF(3:3) == 'A'.OR.CDCONF(2:2) == 'E')&
 & .AND.LRETCFOU  
LLWRTCFOU0 = (.NOT.LAGPHY).AND.(CDCONF(3:3) == 'A')&
 & .AND.(CDCONF(4:4) == 'A')&
 & .AND.(NSTEP >= 1 .AND. NSTEP <= NSTOP-1).AND.LWRTCFOU  

IF (CDCONF(3:3) == 'A'.OR.CDCONF(3:3) == 'B'.OR.CDCONF(3:3) == '1') THEN
  IF(YGFL%NUMFLDS>0.AND..NOT.ALLOCATED(GFL)) THEN
    CALL ABOR1('GP_MODEL: GFL NOT ALLOCATED')
  ENDIF
  IF(LPC_FULL.AND.LSLAG.AND.(LEPHYS.OR.LMPHYS).AND..NOT.ALLOCATED(GFLPT)) THEN
    CALL ABOR1('GP_MODEL: GFLPT NOT ALLOCATED')
  ENDIF
  IF(LPC_FULL.AND..NOT.LTWOTL.AND..NOT.ALLOCATED(GFLPC)) THEN
    CALL ABOR1('GP_MODEL: GFLPC NOT ALLOCATED FOR 3TL PC SCHEME')
  ENDIF  
ELSE

ENDIF


CALL GSTATS(1228,0)
IF(.NOT.ALLOCATED(GMVT1))  THEN
  ALLOCATE(GMVT1(NPROMA,NFLEVG,YT1%NDIM,NGPBLKS))
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(J)
  DO J=1,NGPBLKS
    GMVT1(:,:,:,J)=0.0_JPRB
  ENDDO
!$OMP END PARALLEL DO
ENDIF
IF(.NOT.ALLOCATED(GMVT1S)) THEN
  ALLOCATE(GMVT1S(NPROMA,YT1%NDIMS,NGPBLKS))
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(J)
  DO J=1,NGPBLKS
    GMVT1S(:,:,J)=0.0_JPRB
  ENDDO
!$OMP END PARALLEL DO
ENDIF
IF(.NOT.ALLOCATED(GFLT1))  THEN
  ALLOCATE(GFLT1(NPROMA,NFLEVG,YGFL%NDIM1,NGPBLKS))
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(J)
  DO J=1,NGPBLKS
    GFLT1(:,:,:,J)=0.0_JPRB
  ENDDO
!$OMP END PARALLEL DO
ENDIF
CALL GSTATS(1228,1)

IF (LCANARI .AND. LHOOK) CALL DR_HOOK('GP_MODEL',1,ZHOOK_HANDLE)
IF (LCANARI) RETURN

CALL GSTATS(1228,0)
ALLOCATE (ZSLBUF1(NASLB1,NFLDSLB1))
IF (NSLPAD > 0)THEN
!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(J)
  DO J=1,NFLDSLB1
    ZSLBUF1(:,J)=HUGE(ZZZ)
  ENDDO
!$OMP END PARALLEL DO
ENDIF
ALLOCATE(ZSLBUF2(NPROMA,NFLDSLB2,NGPBLKS))

!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(J)
DO J=1,NGPBLKS
  ZSLBUF2(:,:,J)=0.0_JPRB
ENDDO
!$OMP END PARALLEL DO
CALL GSTATS(1228,1)

IF(CDCONF(6:6) == 'V' .AND. MNSERIES > 0 .AND. LEMWAVE)THEN
  LEMWAVE_ACTIVE=.TRUE.
ELSE
  LEMWAVE_ACTIVE=.FALSE.
ENDIF
ALLOCATE( ZMWAVE_OBS_BUF(NGPTOT,NMAX_CHAN,N_SATSENS) )
ALLOCATE( ZMWAVE_TB_BUF(NGPTOT,NMAX_CHAN,N_SATSENS) )
ALLOCATE( ZMWAVE_OERR_BUF(NGPTOT,NMAX_CHAN,N_SATSENS) )
ALLOCATE( ZMWAVE_PERS1_BUF(NGPTOT,NMAX_CHAN,N_SATSENS) )
ALLOCATE( ZMWAVE_DIAG_BUF(NGPTOT,NMWAVE_DIAG,N_SATSENS) )
ALLOCATE( ZMWAVE_P19_BUF(NGPTOT,NMWAVE_P,N_SATSENS) )
ALLOCATE( ZMWAVE_P37_BUF(NGPTOT,NMWAVE_P,N_SATSENS) )
ALLOCATE( ZMWAVE_GNORM_BUF(NGPTOT,NMWAVE_GNRM,N_SATSENS) )
ALLOCATE( ZMWAVE_ZEN_BUF(NGPTOT,N_SATSENS) )
ALLOCATE( ZMWAVE_AZI_BUF(NGPTOT,N_SATSENS) )
ALLOCATE( IMWAVE_BUF(NGPTOT,NMAX_CHAN,N_SATSENS) )

LESMOS=.FALSE.  ! To be changed when setup in prepIFS
IF(CDCONF(6:6) == 'V' .AND. LESMOS) THEN
  LESMOS_ACTIVE=.TRUE.
ELSE
  LESMOS_ACTIVE=.FALSE.
ENDIF
ALLOCATE( ZSMOS_OBS_BUF(NGPTOT,0:NPOL_MAX-1) )
ALLOCATE( ISMOS_BUF(NGPTOT,0:NPOL_MAX-1) )
ALLOCATE( ZSMOS_TB_BUF(NGPTOT,0:NPOL_MAX-1) )
ALLOCATE( ZSMOS_ANGLE(NGPTOT,0:NPOL_MAX-1) )

!     ------------------------------------------------------------------
!*       2.    AROME/ALARO EXTERNALIZED SURFACE
!     -----------------------------------------------------------------

! THIS HAS BEEN MOVED UNDER APL_AROME IN THE NPROMA LOOP

IF(LPC_FULL.AND.LTWOTL.AND.LEPHYS)THEN
  CALL DEFINE_POINTERS_MP9
ENDIF

!     ------------------------------------------------------------------
!*       3.    DYNAMICS
!     ------------------------------------------------------------------

IF (.NOT.LL2D) THEN

  IF(LCPG_SPLIT) THEN
    IBLKS=NGPBLKS
  ELSE
    IBLKS=OML_MAX_THREADS()
  ENDIF

  CALL CPG(&
   & CDCONF(4:4),LLRETCFOU,LLWRTCFOU0, &
   & IGPCOMP,IBLKS,LCPG_SPLIT, &
   & GMV,GMVS, &
   & ZSLBUF1,ZSLBUF2,GMVT1,GMVT1S,GFLT1,ZEXTRADYN)

ELSE
!$OMP parallel private(ICEND,IBL,IOFF,ZSLBUF1AUX)
  IF (.NOT.ALLOCATED(ZSLBUF1AUX)) ALLOCATE(ZSLBUF1AUX(NPROMA,NFLDSLB1))
!$OMP do schedule(static,1)
  DO JKGLO=1,IGPCOMP,NPROMA
    ICEND=MIN(NPROMA,IGPCOMP-JKGLO+1)
    IBL=(JKGLO-1)/NPROMA+1
    IOFF=JKGLO

    CALL CPG2(CDCONF(4:4),ICEND,JKGLO,&
     & ZSLBUF1AUX,ZSLBUF2(1,1,IBL),GMV(1,1,1,IBL),GMVS(1,1,IBL),&
     & RCORI(IOFF),GM(IOFF),RATATH(IOFF),RATATX(IOFF),&
     & GOMVRL(IOFF),GOMVRM(IOFF),&
     & OROG(IOFF),OROGL(IOFF) ,OROGM(IOFF),&
     & GMV(1,1,YT0%MU,IBL)  ,GMV(1,1,YT0%MV,IBL),&
     & GMV(1,1,YT0%MUL,IBL) ,GMV(1,1,YT0%MVL,IBL),&
     & GMV(1,1,YT0%MDIV,IBL),GMV(1,1,YT0%MVOR,IBL),&
     & GMVS(1,YT0%MSP,IBL)  ,GMVS(1,YT0%MSPL,IBL),&
     & GMVS(1,YT0%MSPM,IBL),&
     & GMV(1,1,YT9%MU,IBL)  ,GMV(1,1,YT9%MV,IBL),&
     & GMV(1,1,YT9%MDIV,IBL),GMV(1,1,YT9%MSPNL,IBL),&
     & GMVS(1,YT9%MSP,IBL)  ,GMVS(1,YT9%MSPL,IBL),&
     & GMVS(1,YT9%MSPM,IBL),&
     & GMVT1(1,1,YT1%MU,IBL)  ,GMVT1(1,1,YT1%MV,IBL),&
     & GMVT1S(1,YT1%MSP,IBL))  

!          move data from blocked form to latitude (NASLB) form
    IF (LSLAG) THEN
      DO JROF=JKGLO,MIN(JKGLO-1+NPROMA,IGPCOMP)
        ZSLBUF1(NSLCORE(JROF),:)=ZSLBUF1AUX(JROF-JKGLO+1,:)
      ENDDO
    ENDIF
  ENDDO
!$OMP end do
  IF (ALLOCATED(ZSLBUF1AUX)) DEALLOCATE(ZSLBUF1AUX)
!$OMP end parallel
ENDIF

LLADNMI = CDCONF(4:4) == 'E' .OR. CDCONF(4:4) == 'F'

!     ------------------------------------------------------------------
!*       4.     ECMWF RADIATION
!     ------------------------------------------------------------------

IF (.NOT.LL2D) THEN
  IF ( (LEPHYS.OR.LAQUA) .AND. LAGPHY .AND. .NOT.LLADNMI .AND. &
     & LERADI .AND. CDCONF(4:4) /= 'T') THEN
    IF (NRADFR == 0 ) THEN
      CALL ABOR1('GP_MODEL: NRADFR=0 !')
    ELSEIF (MOD(NSTEP,NRADFR) == 0) THEN
      IF (LPC_FULL) THEN
        IF (NEPHYS_PCFULL == 3) &
         & LL_CALLRADDRV=(NCURRENT_ITER == NSITER)
        IF (NEPHYS_PCFULL == 2) LL_CALLRADDRV=(NCURRENT_ITER == 0)
      ELSE
        LL_CALLRADDRV=.TRUE.
      ENDIF
      IF (LL_CALLRADDRV) THEN
        CALL GSTATS(8,2)
        CALL GSTATS(13,0)
        CALL RADDRV(NGPTOT,NFLDSLB2,NGPBLKS,&
         & GMV,GMVS,&
         & GELAM(1),GEMU(1),GESLO(1),GECLO(1),ZSLBUF2,GFL)
        CALL GSTATS(13,1)
        CALL GSTATS(8,3)
      ENDIF
    ENDIF
  ENDIF
ENDIF

IF (LCOUPLO4_ENV) THEN
! call of oasis4 exchange - get chemistry
   CALL COUPLO4_EXCHANGE(1)
ENDIF


!     ------------------------------------------------------------------
!*       5.     SEMI-LAGRANGIAN INTERPOLATION
!     ------------------------------------------------------------------

IF (LSLAG.AND.LSLPHY) THEN
  ALLOCATE (ZPBUP9(NPROMA,NFLEVG,NGPBLKS))
  ALLOCATE (ZPBVP9(NPROMA,NFLEVG,NGPBLKS))
  ALLOCATE (ZPBTP9(NPROMA,NFLEVG,NGPBLKS))
  ALLOCATE (ZPBGFLP9(NPROMA,NFLEVG,YGFL%NUMFLDS,NGPBLKS))
ENDIF

IF (.NOT.LL2D) THEN

  IVSEPC(:) = 0
  IVSEPL(:) = 0
  
  LL_CALL_SL=LSLAG.AND.((NCURRENT_ITER == 0).OR.(NCURRENT_ITER > 0 .AND. LPC_FULL))
  IF(LL_CALL_SL) THEN

!FIELDS: ZSLBUF1 contains PB1 fields to be interpolated (input)
!FIELDS: ZSLBUF2 contains PB2 fields (input and output)

    CALL CALL_SL(CDCONF(4:4),&
     & IVSEPC,IVSEPL,ZSLBUF1,ZSLBUF2,GFLT1,&
     & ZPBUP9,ZPBVP9,ZPBTP9,ZPBGFLP9)

    IF(ALLOCATED(ZSLBUF1))DEALLOCATE(ZSLBUF1)

  ENDIF

  CALL GSTATS(8,2)
  CALL GSTATS(10,0)

!     ------------------------------------------------------------------
!*     TRACER MASS FIXER - MADE OPTIONAL THROUGH LTRCMFIX
!      A FIX FOR A LOSS OR GAIN OF MASS DUE TO THE ADVECTION SCHEME ONLY
!     ------------------------------------------------------------------

IF (LTRCMFIX) THEN
      CALL TRACMF (GMVS, GMVT1S, GFL, GFLT1 )
ENDIF

IF (ALLOCATED(ZSLBUF1)) DEALLOCATE(ZSLBUF1)

IF(LEMWAVE_ACTIVE) THEN
  IF(LSCREEN)THEN
    CALL MWAVE_GET(ZMWAVE_OBS_BUF,IMWAVE_BUF,ZMWAVE_ZEN_BUF,ZMWAVE_AZI_BUF)
  ELSE
    CALL MWAVE_GET_TL(IMWAVE_BUF,ZMWAVE_ZEN_BUF,ZMWAVE_AZI_BUF, &
      & ZMWAVE_P19_BUF,ZMWAVE_P37_BUF,ZMWAVE_OERR_BUF,ZMWAVE_PERS1_BUF)
  ENDIF
ENDIF

IF(CDCONF(6:6) == 'V' .AND. LERAIN .AND. MNSERIES > 0 .AND. &
     &   (NUPTRA == 0 .OR. NUPTRA == MUPTRA) ) THEN

  LERAIN_ACTIVE=.TRUE.

  ! Prevent load balancing on final trajectory (no 
  ! time-consuming 1D-Var retrievals are made.)
  IF (NUPTRA == MUPTRA) LERAIN_LB=.FALSE. 

  CALL GP_PTR_SSMI
  CALL GP_SSMI

  ! Count number of active observations
  ICNT=0
  DO J=1,NGPTOT
    DO JSTREAM1D=1,STREAM1D_NUM
      IF (STREAM1D_MODE(JSTREAM1D) == STREAM1D_ACTIVE ) THEN
        IF(RAIN_2DCHAN_GP(J,JSTREAM1D,1,M_TB_OB) /= 0.0_JPRB) THEN
          ICNT=ICNT+1
        ENDIF
      ENDIF
    ENDDO
  ENDDO
  IFIRST=IFIRST+1
  CALL GSTATS(704,0)
  CALL MPL_BARRIER(CDSTRING='GP_MODEL:')
  CALL GSTATS(704,1)

  CALL MPL_ALLGATHERV(ICNT,ICNTA,CDSTRING='GP_MODEL:')

  !--- Load Balancing
  IF(LERAIN_LB) CALL ONEDVAR_RAINTB_PRC(ICNTA)
                ! Set up helper processors
ELSE
  LERAIN_ACTIVE=.FALSE.
ENDIF

! SMOS OBSERVATIONS TO MODEL GRID POINT
IF(LESMOS_ACTIVE) THEN
  IF(LSCREEN)THEN
       CALL SMOS_PROCESS(ZSMOS_OBS_BUF,ISMOS_BUF,ZSMOS_ANGLE)
  ENDIF
ENDIF

!     ------------------------------------------------------------------
!*       6.    ECMWF Physics
!     ------------------------------------------------------------------

  IF ((LCUCONV_CA)) CALL SUCUCONV_CA(NSTEP) !update CA

  IF(((LEPHYS.OR.LAQUA.OR.LHELDSUAREZ) .AND. LAGPHY .AND. .NOT. LLADNMI)) THEN
    CLCONF=CDCONF(4:4)
    IF(CDCONF(4:4)=='S')CLCONF='A'
    CALL EC_PHYS_DRV(CLCONF,ZSLBUF2,ZPBUP9,ZPBVP9,ZPBTP9,ZPBGFLP9,ZEXTRADYN, &
      &   ZMWAVE_OBS_BUF,ZMWAVE_ZEN_BUF,ZMWAVE_AZI_BUF,ZMWAVE_TB_BUF, &
      &   ZMWAVE_OERR_BUF,ZMWAVE_PERS1_BUF,&
      &   ZMWAVE_DIAG_BUF,ZMWAVE_P19_BUF,ZMWAVE_P37_BUF,ZMWAVE_GNORM_BUF,&
      &   IMWAVE_BUF ,&
      &   ZSMOS_OBS_BUF,ZSMOS_TB_BUF,ZSMOS_ANGLE,&
      &   ISMOS_BUF)
  ENDIF


  IF(LSLAG.AND.LSLPHY)THEN
    DEALLOCATE (ZPBUP9,ZPBVP9,ZPBTP9,ZPBGFLP9)
  ENDIF

IF(LEMWAVE_ACTIVE)THEN
  CALL MWAVE_PUT(ZMWAVE_TB_BUF,ZMWAVE_OERR_BUF, ZMWAVE_PERS1_BUF,&
    & ZMWAVE_DIAG_BUF,ZMWAVE_P19_BUF,ZMWAVE_P37_BUF,ZMWAVE_GNORM_BUF,IMWAVE_BUF)
ENDIF

IF (LESMOS_ACTIVE)THEN
  IF (LSCREEN) THEN
     CALL SMOS_UPDATE(ZSMOS_TB_BUF,ISMOS_BUF)
  ENDIF
ENDIF

IF(LERAIN_ACTIVE)THEN
  CALL GP_SSMI_INV
ENDIF

IF (LCOUPLO4_ENV) THEN
!   call of oasis4 exchange - put meteo
   CALL COUPLO4_EXCHANGE(2)
ENDIF

!     ------------------------------------------------------------------
!*       7.    TRANSFER TO PUT1 ARRAYS
!     ------------------------------------------------------------------

  CALL GSTATS(1002,0)
!$OMP PARALLEL DO SCHEDULE(DYNAMIC,1) PRIVATE(JKGLO,ICEND,IBL,IOFF,ICENDE)
  DO JKGLO=1,IGPCOMP,NPROMA
    ICEND=MIN(NPROMA,IGPCOMP-JKGLO+1)
    ICENDE=MIN(NPROMA,NGPTOT-JKGLO+1)
    IBL=(JKGLO-1)/NPROMA+1
    IOFF=JKGLO

    CALL CPGLAG(CDCONF(4:4),&
     & ICEND,JKGLO,ICENDE,&
     & GMV(1,1,1,IBL),GMVS(1,1,IBL),&
     & GM(IOFF),OROG(IOFF),OROGL(IOFF),OROGM(IOFF),&
     & ZSLBUF2(1,1,IBL),GFLT1(1,1,1,IBL),&
     & GMVT1(1,1,1,IBL),&
     & GMVT1S(1,1,IBL),&
     & GFL(1,1,1,IBL))

  ENDDO
!$OMP END PARALLEL DO
  CALL GSTATS(1002,1)

  CALL GSTATS(10,1)
  CALL GSTATS(8,3)

  IF (LFINDVSEP) THEN
    DO IBL=1,NGPBLKS
      NVSEPC=MAX(NVSEPC,IVSEPC(IBL))
      NVSEPL=MAX(NVSEPL,IVSEPL(IBL))
    ENDDO
  ENDIF

ELSE

  IF (LSLAG) THEN
    IF (NPROC > 1) THEN
      LLINC = .FALSE.
      CALL SLCOMM(NASLB1,NSLPROCS,NSLRPT,&
       & NSLSPT,NSLSENDPOS,NSLRECVPOS,NSENDPTR,NRECVPTR,NSLCOMM,&
       & IDUMARR,NFLDSLB1,LLINC,0,ZSLBUF1)
    ENDIF
    CALL SLEXTPOL(NSLWIDE,NSLWIDE,&
     & NASLB1,NDGSAG,NDGENG,NDGSAL,NDGENL,NFLDSLB1,NSLSTA,NSLONL,NSLOFF,&
     & NDGLG,NLOENG,NFRSTLOFF,MYFRSTACTLAT,MYLSTACTLAT,IDUMARR,1,&
     & RPARSL1,ZSLBUF1) 
  ENDIF
  DO JKGLO=1,NGPTOT,NPROMA
    ICEND=MIN(NPROMA,NGPTOT-JKGLO+1)
    IBL=(JKGLO-1)/NPROMA+1
    IOFF=JKGLO
    CALL CPG2LAG(ICEND,&
     & NASLB1,ZSLBUF1,ZSLBUF2(1,1,IBL),GMV(1,1,1,IBL),GMVS(1,1,IBL),&
     & GM(IOFF),GEMU(IOFF),GSQM2(IOFF),GECLO(IOFF),&
     & GESLO(IOFF),GNORDL(IOFF),&
     & GNORDM(IOFF),RCOLON(IOFF),&
     & RSILON(IOFF),RINDX(IOFF),RINDY(IOFF),&
     & GMVT1(1,1,YT1%MU,IBL)  ,GMVT1(1,1,YT1%MV,IBL),&
     & GMVT1S(1,YT1%MSP,IBL))  
  ENDDO
ENDIF

IF (ALLOCATED(ZSLBUF1)) DEALLOCATE(ZSLBUF1)
IF (ALLOCATED(ZSLBUF2)) DEALLOCATE(ZSLBUF2)

DEALLOCATE( ZMWAVE_OBS_BUF, ZMWAVE_TB_BUF, ZMWAVE_OERR_BUF, &
  & ZMWAVE_PERS1_BUF,&
  & ZMWAVE_DIAG_BUF, ZMWAVE_P19_BUF, ZMWAVE_P37_BUF, ZMWAVE_GNORM_BUF, &
  & ZMWAVE_ZEN_BUF, ZMWAVE_AZI_BUF,IMWAVE_BUF  )

DEALLOCATE ( ZSMOS_OBS_BUF, ISMOS_BUF, ZSMOS_TB_BUF, ZSMOS_ANGLE)
!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('GP_MODEL',1,ZHOOK_HANDLE)
END SUBROUTINE GP_MODEL
