Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diaar5.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diaar5.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diaar5.F90	(revision 13103)
@@ -77,5 +77,5 @@
       REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: zarea_ssh , zbotpres       ! 2D workspace 
       REAL(wp), ALLOCATABLE, DIMENSION(:,:)     :: zpe, z2d                   ! 2D workspace 
-      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   :: zrhd , zrhop, ztpot   ! 3D workspace
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)   :: zrhd , ztpot               ! 3D workspace
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:) :: ztsn                       ! 4D workspace
 
@@ -87,5 +87,5 @@
       IF( l_ar5 ) THEN 
          ALLOCATE( zarea_ssh(jpi,jpj), zbotpres(jpi,jpj), z2d(jpi,jpj) )
-         ALLOCATE( zrhd(jpi,jpj,jpk) , zrhop(jpi,jpj,jpk) )
+         ALLOCATE( zrhd(jpi,jpj,jpk) )
          ALLOCATE( ztsn(jpi,jpj,jpk,jpts) )
          zarea_ssh(:,:) = e1e2t(:,:) * ssh(:,:,Kmm)
@@ -155,11 +155,7 @@
       
          !                                         ! steric sea surface height
-         CALL eos( ts(:,:,:,:,Kmm), zrhd, zrhop, gdept(:,:,:,Kmm) )                 ! now in situ and potential density
-         zrhop(:,:,jpk) = 0._wp
-         CALL iom_put( 'rhop', zrhop )
-         !
          zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
          DO jk = 1, jpkm1
-            zbotpres(:,:) = zbotpres(:,:) + e3t(:,:,jk,Kmm) * zrhd(:,:,jk)
+            zbotpres(:,:) = zbotpres(:,:) + e3t(:,:,jk,Kmm) * rhd(:,:,jk)
          END DO
          IF( ln_linssh ) THEN
@@ -168,9 +164,9 @@
                   DO jj = 1,jpj
                      iks = mikt(ji,jj)
-                     zbotpres(ji,jj) = zbotpres(ji,jj) + ssh(ji,jj,Kmm) * zrhd(ji,jj,iks) + riceload(ji,jj)
+                     zbotpres(ji,jj) = zbotpres(ji,jj) + ssh(ji,jj,Kmm) * rhd(ji,jj,iks) + riceload(ji,jj)
                   END DO
                END DO
             ELSE
-               zbotpres(:,:) = zbotpres(:,:) + ssh(:,:,Kmm) * zrhd(:,:,1)
+               zbotpres(:,:) = zbotpres(:,:) + ssh(:,:,Kmm) * rhd(:,:,1)
             END IF
          END IF
@@ -293,5 +289,4 @@
       IF( l_ar5 ) THEN
         DEALLOCATE( zarea_ssh , zbotpres, z2d )
-        DEALLOCATE( zrhd      , zrhop    )
         DEALLOCATE( ztsn                 )
       ENDIF
@@ -367,5 +362,6 @@
       IF(   iom_use( 'voltot'  ) .OR. iom_use( 'sshtot'    )  .OR. iom_use( 'sshdyn' )  .OR.  & 
          &  iom_use( 'masstot' ) .OR. iom_use( 'temptot'   )  .OR. iom_use( 'saltot' ) .OR.  &    
-         &  iom_use( 'botpres' ) .OR. iom_use( 'sshthster' )  .OR. iom_use( 'sshsteric' )  ) L_ar5 = .TRUE.
+         &  iom_use( 'botpres' ) .OR. iom_use( 'sshthster' )  .OR. iom_use( 'sshsteric' ) .OR. &
+         &  iom_use( 'rhop' )  ) L_ar5 = .TRUE.
   
       IF( l_ar5 ) THEN
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diawri.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diawri.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DIA/diawri.F90	(revision 13103)
@@ -171,4 +171,6 @@
          CALL iom_put( "sbs", z2d )                ! bottom salinity
       ENDIF
+
+      CALL iom_put( "rhop", rhop(:,:,:) )          ! 3D potential density (sigma0)
 
       IF ( iom_use("taubot") ) THEN                ! bottom stress
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DOM/istate.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DOM/istate.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/DOM/istate.F90	(revision 13103)
@@ -24,5 +24,4 @@
    USE dom_oce        ! ocean space and time domain 
    USE daymod         ! calendar
-   USE divhor         ! horizontal divergence            (div_hor routine)
    USE dtatsd         ! data temperature and salinity   (dta_tsd routine)
    USE dtauvd         ! data: U & V current             (dta_uvd routine)
@@ -131,7 +130,4 @@
          uu   (:,:,:,Kmm)   = uu  (:,:,:,Kbb)
          vv   (:,:,:,Kmm)   = vv  (:,:,:,Kbb)
-         hdiv(:,:,jpk) = 0._wp               ! bottom divergence set one for 0 to zero at jpk level
-         CALL div_hor( 0, Kbb, Kmm )         ! compute interior hdiv value  
-!!gm                                    hdiv(:,:,:) = 0._wp
 
 !!gm POTENTIAL BUG :
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbrst.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbrst.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbrst.F90	(revision 13103)
@@ -192,5 +192,5 @@
       CHARACTER(len=256)     :: cl_path
       CHARACTER(len=256)     :: cl_filename
-      CHARACTER(len=256)     :: cl_kt
+      CHARACTER(len=8  )     :: cl_kt
       CHARACTER(LEN=12 )     :: clfmt            ! writing format
       TYPE(iceberg), POINTER :: this
@@ -213,11 +213,11 @@
          ! file name
          WRITE(cl_kt, '(i8.8)') kt
-         cl_filename = TRIM(cexper)//"_"//TRIM(ADJUSTL(cl_kt))//"_"//TRIM(cn_icbrst_out)
+         cl_filename = TRIM(cexper)//"_"//cl_kt//"_"//TRIM(cn_icbrst_out)
          IF( lk_mpp ) THEN
             idg = MAX( INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1, 4 )          ! how many digits to we need to write? min=4, max=9
             WRITE(clfmt, "('(a,a,i', i1, '.', i1, ',a)')") idg, idg          ! '(a,a,ix.x,a)'
-            WRITE(cl_filename,clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
+            WRITE(cl_filename,  clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
          ELSE
-            WRITE(cl_filename,'(A,".nc")') TRIM(cl_filename)
+            WRITE(cl_filename,'(a,a)') TRIM(cl_filename),               '.nc'
          ENDIF
 
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbtrj.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbtrj.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/ICB/icbtrj.F90	(revision 13103)
@@ -66,5 +66,5 @@
       CHARACTER(len=80)      ::   cl_filename
       CHARACTER(LEN=12)      ::   clfmt            ! writing format
-      CHARACTER(LEN=20)      ::   cldate_ini, cldate_end
+      CHARACTER(LEN=8 )      ::   cldate_ini, cldate_end
       TYPE(iceberg), POINTER ::   this
       TYPE(point)  , POINTER ::   pt
@@ -82,11 +82,11 @@
 
       ! define trajectory output name
-      cl_filename = 'trajectory_icebergs_'//TRIM(ADJUSTL(cldate_ini))//'-'//TRIM(ADJUSTL(cldate_end))
+      cl_filename = 'trajectory_icebergs_'//cldate_ini//'-'//cldate_end
       IF ( lk_mpp ) THEN
          idg = MAX( INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1, 4 )          ! how many digits to we need to write? min=4, max=9
          WRITE(clfmt, "('(a,a,i', i1, '.', i1, ',a)')") idg, idg          ! '(a,a,ix.x,a)'
-         WRITE(cl_filename,clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
+         WRITE(cl_filename,  clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
       ELSE
-         WRITE(cl_filename,'(A,".nc")') TRIM(cl_filename)
+         WRITE(cl_filename,'(a,a)') TRIM(cl_filename),               '.nc'
       ENDIF
       IF( lwp .AND. nn_verbose_level >= 0 )   WRITE(numout,'(2a)') 'icebergs, icb_trj_init: creating ',TRIM(cl_filename)
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/IOM/iom_def.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/IOM/iom_def.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/IOM/iom_def.F90	(revision 13103)
@@ -33,5 +33,5 @@
    INTEGER, PARAMETER, PUBLIC ::   jpmax_vars   = 1200 !: maximum number of variables in one file
    INTEGER, PARAMETER, PUBLIC ::   jpmax_dims   =  4   !: maximum number of dimensions for one variable
-   INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  5   !: maximum number of digits for the cpu number in the file name
+   INTEGER, PARAMETER, PUBLIC ::   jpmax_digits =  9   !: maximum number of digits for the cpu number in the file name
 
 
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/LBC/lib_mpp.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/LBC/lib_mpp.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/LBC/lib_mpp.F90	(revision 13103)
@@ -1221,5 +1221,5 @@
       CHARACTER(LEN=10) ::   clfmt            ! writing format
       INTEGER           ::   iost
-      INTEGER           ::   idg  ! number of digits
+      INTEGER           ::   idg              ! number of digits
       !!----------------------------------------------------------------------
       !
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/SBC/sbccpl.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/SBC/sbccpl.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/SBC/sbccpl.F90	(revision 13103)
@@ -1785,7 +1785,6 @@
             ENDDO
          ELSE
-            qns_tot(:,:) = qns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
+            zqns_tot(:,:) = zqns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
             DO jl = 1, jpl
-               zqns_tot(:,:   ) = zqns_tot(:,:) + picefr(:,:) * frcv(jpr_qnsice)%z3(:,:,1)
                zqns_ice(:,:,jl) = frcv(jpr_qnsice)%z3(:,:,1)
             END DO
@@ -1928,7 +1927,6 @@
             END DO
          ELSE
-            qsr_tot(:,:   ) = qsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
+            zqsr_tot(:,:) = zqsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
             DO jl = 1, jpl
-               zqsr_tot(:,:   ) = zqsr_tot(:,:) + picefr(:,:) * frcv(jpr_qsrice)%z3(:,:,1)
                zqsr_ice(:,:,jl) = frcv(jpr_qsrice)%z3(:,:,1)
             END DO
Index: /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/TRD/trdtra.F90
===================================================================
--- /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/TRD/trdtra.F90	(revision 13102)
+++ /NEMO/branches/2020/dev_r12973_AGRIF_CMEMS/src/OCE/TRD/trdtra.F90	(revision 13103)
@@ -82,5 +82,6 @@
       REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   ptra    ! now tracer variable
       !
-      INTEGER ::   jk   ! loop indices
+      INTEGER ::   jk    ! loop indices
+      INTEGER ::   i01   ! 0 or 1
       REAL(wp),        DIMENSION(jpi,jpj,jpk) ::   ztrds             ! 3D workspace
       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) ::   zwt, zws, ztrdt   ! 3D workspace
@@ -90,8 +91,10 @@
          IF( trd_tra_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_tra : unable to allocate arrays' )
       ENDIF
-
+      !
+      i01 = COUNT( (/ PRESENT(pu) .OR. ( ktrd /= jptra_xad .AND. ktrd /= jptra_yad .AND. ktrd /= jptra_zad ) /) )
+      !
       IF( ctype == 'TRA' .AND. ktra == jp_tem ) THEN   !==  Temperature trend  ==!
          !
-         SELECT CASE( ktrd )
+         SELECT CASE( ktrd*i01 )
          !                            ! advection: transform the advective flux into a trend
          CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd, pu, ptra, 'X', trdtx, Kmm ) 
@@ -112,5 +115,5 @@
       IF( ctype == 'TRA' .AND. ktra == jp_sal ) THEN      !==  Salinity trends  ==!
          !
-         SELECT CASE( ktrd )
+         SELECT CASE( ktrd*i01 )
          !                            ! advection: transform the advective flux into a trend
          !                            !            and send T & S trends to trd_tra_mng
@@ -163,5 +166,5 @@
       IF( ctype == 'TRC' ) THEN                           !==  passive tracer trend  ==!
          !
-         SELECT CASE( ktrd )
+         SELECT CASE( ktrd*i01 )
          !                            ! advection: transform the advective flux into a masked trend
          CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd , pu , ptra, 'X', ztrds, Kmm ) 
Index: /utils/tools_dev_r12970_AGRIF_CMEMS/DOMAINcfg/src/agrif_connect.F90
===================================================================
--- /utils/tools_dev_r12970_AGRIF_CMEMS/DOMAINcfg/src/agrif_connect.F90	(revision 13102)
+++ /utils/tools_dev_r12970_AGRIF_CMEMS/DOMAINcfg/src/agrif_connect.F90	(revision 13103)
@@ -123,5 +123,5 @@
                      e3t_interp(ji,jj,jk) = MAX( ptab(ji,jj,jk),MIN(e3zps_min, e3t_1d(jk)*e3zps_rat) )
                      e3t_interp(ji,jj,jk) = MIN( e3t_interp(ji,jj,jk),e3t_1d(jk) )
-                     e3t_0(ji,jj,jk) = ztabramp(ji,jj)*e3t_0(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_interp(ji,jj,jk)
+                     e3t_0(ji,jj,jk) = ( 1. + ztabramp(ji,jj) )*e3t_0(ji,jj,jk) + ztabramp(ji,jj)*e3t_interp(ji,jj,jk)
                   ENDIF
              END DO
Index: ils/tools_dev_r12970_AGRIF_CMEMS/DOMAINcfg/src/agrif_connection.F90
===================================================================
--- /utils/tools_dev_r12970_AGRIF_CMEMS/DOMAINcfg/src/agrif_connection.F90	(revision 13102)
+++ 	(revision )
@@ -1,159 +1,0 @@
-#if defined key_agrif
-   SUBROUTINE Agrif_connection
-   use dom_oce
-   use agrif_parameters
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE  Agrif_Sponge ***
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, ind1, ind2
-      INTEGER  ::   ispongearea, istart
-      REAL(wp) ::   z1_spongearea
-      !!----------------------------------------------------------------------
-      !
-         ! Define ramp from boundaries towards domain interior at T-points
-         ! Store it in ztabramp
-
-         ALLOCATE(ztabramp(jpi,jpj))
-         ispongearea = 1 + npt_connect * Agrif_irhox()
-         istart = npt_copy * Agrif_irhox()
-         z1_spongearea = 1._wp / REAL( ispongearea )
-         
-         ztabramp(:,:) = 0._wp
-
-         ! --- West --- !
-         IF( ((nbondi == -1) .OR. (nbondi == 2) ).AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6)) THEN
-            ind1 = 1+nbghostcells + istart
-            ind2 = ind1 + ispongearea 
-            DO jj = 1, jpj
-               DO ji = ind1, ind2                
-                  ztabramp(ji,jj) = REAL( ind2 - ji ) * z1_spongearea * umask(ind1,jj,1)
-               END DO
-            ENDDO
-         ENDIF
-
-         ! --- East --- !
-         IF( ((nbondi == 1) .OR. (nbondi == 2) ).AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6)) THEN
-            !ind1 = nlci - nbghostcells - ispongearea
-            ind2 = nlci - nbghostcells - istart
-            ind1 = ind2 -ispongearea
-           
-            
-            DO jj = 1, jpj
-               DO ji = ind1, ind2
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ji - ind1 ) * z1_spongearea * umask(ind2-1,jj,1) )
-               ENDDO
-            ENDDO
-         ENDIF
-
-         ! --- South --- !
-         IF(( (nbondj == -1) .OR. (nbondj == 2) ).AND.(ln_bry_south)) THEN
-            ! ind1 = 1+nbghostcells
-            ! ind2 = 1+nbghostcells + ispongearea
-            ind1 = 1+nbghostcells + istart
-            ind2 = ind1 + ispongearea 
-            DO jj = ind1, ind2 
-               DO ji = 1, jpi
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - jj ) * z1_spongearea * vmask(ji,ind1,1) )
-               END DO
-            ENDDO
-         ENDIF
-
-         ! --- North --- !
-         IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN
-            ! ind1 = nlcj - nbghostcells - ispongearea
-            ! ind2 = nlcj - nbghostcells
-            
-            ind2 = nlcj - nbghostcells - istart
-            ind1 = ind2 -ispongearea
-            
-            DO jj = ind1, ind2
-               DO ji = 1, jpi
-                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( jj - ind1 ) * z1_spongearea * vmask(ji,ind2-1,1) )
-               END DO
-            ENDDO
-         ENDIF
-      !
-      !
-   END SUBROUTINE Agrif_connection
-   
-   SUBROUTINE Agrif_make_connection
-   use dom_oce
-   use agrif_parameters
-      !!----------------------------------------------------------------------
-      !!                 *** ROUTINE  Agrif_Sponge ***
-      !!----------------------------------------------------------------------
-      INTEGER  ::   ji, jj, ind1, ind2
-      INTEGER  ::   ispongearea, istart
-      REAL(wp) ::   z1_spongearea
-      !!----------------------------------------------------------------------
-      !
-         ! Define ramp from boundaries towards domain interior at T-points
-         ! Store it in ztabramp
-
-         ispongearea = 1 + npt_connect * Agrif_irhox()
-         istart = npt_copy * Agrif_irhox()
-
-         ! --- West --- !
-         IF( (nbondi == -1) .OR. (nbondi == 2) ) THEN
-            
-            ind1 = 1+nbghostcells + istart
-            ind2 = ind1 + ispongearea
-            DO jk=1,jpk            
-             DO jj = 1, jpj
-               DO ji = ind1, ind2
-                
-                ! print *,'VAL = ',ztabramp(ji,jj)*e3t_interp(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_0(ji,jj,jk), &
-                ! e3t_0(ji,jj,jk)
-                  e3t_0(ji,jj,jk) = ztabramp(ji,jj)*e3t_interp(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_0(ji,jj,jk)
-               ENDDO
-              ENDDO
-            ENDDO
-         ENDIF
-
-         ! --- East --- !
-         IF( (nbondi == 1) .OR. (nbondi == 2) ) THEN
-            ind2 = nlci - nbghostcells - istart
-            ind1 = ind2 -ispongearea
-            DO jk=1,jpk    
-            DO jj = 1, jpj
-               DO ji = ind1, ind2
-                  e3t_0(ji,jj,jk) = ztabramp(ji,jj)*e3t_interp(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_0(ji,jj,jk)
-               ENDDO
-            ENDDO
-            ENDDO
-         ENDIF
-
-         ! --- South --- !
-         IF( (nbondj == -1) .OR. (nbondj == 2) ) THEN
-            ind1 = 1+nbghostcells + istart
-            ind2 = ind1 + ispongearea 
-            DO jk=1,jpk    
-            DO jj = ind1, ind2 
-               DO ji = 1, jpi
-                  e3t_0(ji,jj,jk) = ztabramp(ji,jj)*e3t_interp(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_0(ji,jj,jk)
-               END DO
-            ENDDO
-            ENDDO
-         ENDIF
-
-         ! --- North --- !
-         IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN
-            
-            ind2 = nlcj - nbghostcells - istart
-            ind1 = ind2 -ispongearea
-            DO jk=1,jpk               
-            DO jj = ind1, ind2
-               DO ji = 1, jpi
-                  e3t_0(ji,jj,jk) = ztabramp(ji,jj)*e3t_interp(ji,jj,jk)+(1.-ztabramp(ji,jj))*e3t_0(ji,jj,jk)
-               END DO
-            ENDDO
-            ENDDO
-         ENDIF
-      !
-      !
-   END SUBROUTINE Agrif_make_connection
-   
-#else
-subroutine agrif_connection_empty
-end subroutine agrif_connection_empty
-#endif
