Index: NEMO/branches/2020/dev_r12512_HPC-04_mcastril_Mixed_Precision_implementation/src/NST/agrif_oce_sponge.F90
===================================================================
--- NEMO/branches/2020/dev_r12512_HPC-04_mcastril_Mixed_Precision_implementation/src/NST/agrif_oce_sponge.F90	(revision 12546)
+++ NEMO/branches/2020/dev_r12512_HPC-04_mcastril_Mixed_Precision_implementation/src/NST/agrif_oce_sponge.F90	(revision 13220)
@@ -80,4 +80,6 @@
       Agrif_SpecialValue=0.
       Agrif_UseSpecialValue = ln_spc_dyn
+      use_sign_north = .TRUE.
+      sign_north = -1.
       !
       tabspongedone_u = .FALSE.
@@ -90,4 +92,5 @@
       !
       Agrif_UseSpecialValue = .FALSE.
+      use_sign_north = .FALSE.
 #endif
       !
@@ -127,42 +130,51 @@
 
          ! --- West --- !
-         ztabramp(:,:) = 0._wp
-         ind1 = 1+nbghostcells
-         DO ji = mi0(ind1), mi1(ind1)                
-            ztabramp(ji,:) = ssumask(ji,:)
-         END DO
-         !
-         zmskwest(:) = 0._wp
-         zmskwest(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+         IF( lk_west) THEN
+            ztabramp(:,:) = 0._wp
+            ind1 = 1+nbghostcells
+            DO ji = mi0(ind1), mi1(ind1)                
+               ztabramp(ji,:) = ssumask(ji,:)
+            END DO
+            !
+            zmskwest(:) = 0._wp
+            zmskwest(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+         ENDIF
 
          ! --- East --- !
-         ztabramp(:,:) = 0._wp
-         ind1 = jpiglo - nbghostcells - 1
-         DO ji = mi0(ind1), mi1(ind1)                 
-            ztabramp(ji,:) = ssumask(ji,:)
-         END DO
-         !
-         zmskeast(:) = 0._wp
-         zmskeast(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+         IF( lk_east ) THEN
+            ztabramp(:,:) = 0._wp
+            ind1 = jpiglo - nbghostcells - 1
+            DO ji = mi0(ind1), mi1(ind1)                 
+               ztabramp(ji,:) = ssumask(ji,:)
+            END DO
+            !
+            zmskeast(:) = 0._wp
+            zmskeast(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+         ENDIF
 
          ! --- South --- !
-         ztabramp(:,:) = 0._wp
-         ind1 = 1+nbghostcells
-         DO jj = mj0(ind1), mj1(ind1)                 
-            ztabramp(:,jj) = ssvmask(:,jj)
-         END DO
-         !
-         zmsksouth(:) = 0._wp
-         zmsksouth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+         IF( lk_south ) THEN
+            ztabramp(:,:) = 0._wp
+            ind1 = 1+nbghostcells
+            DO jj = mj0(ind1), mj1(ind1)                 
+               ztabramp(:,jj) = ssvmask(:,jj)
+            END DO
+            !
+            zmsksouth(:) = 0._wp
+            zmsksouth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+         ENDIF
 
          ! --- North --- !
-         ztabramp(:,:) = 0._wp
-         ind1 = jpjglo - nbghostcells - 1
-         DO jj = mj0(ind1), mj1(ind1)                 
-            ztabramp(:,jj) = ssvmask(:,jj)
-         END DO
-         !
-         zmsknorth(:) = 0._wp
-         zmsknorth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+         IF( lk_north) THEN
+            ztabramp(:,:) = 0._wp
+            ind1 = jpjglo - nbghostcells - 1
+            DO jj = mj0(ind1), mj1(ind1)                 
+               ztabramp(:,jj) = ssvmask(:,jj)
+            END DO
+            !
+            zmsknorth(:) = 0._wp
+            zmsknorth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+         ENDIF
+
          ! JC: SPONGE MASKING TO BE SORTED OUT:
          zmskwest(:)  = 1._wp
@@ -192,75 +204,85 @@
 
          ! --- West --- !
-         ind1 = 1+nbghostcells
-         ind2 = 1+nbghostcells + ispongearea 
-         DO ji = mi0(ind1), mi1(ind2)   
-            DO jj = 1, jpj               
-               ztabramp(ji,jj) = REAL( ind2 - mig(ji) ) * z1_ispongearea * zmskwest(jj)
-            END DO
-         END DO
-
-         ! ghost cells:
-         ind1 = 1
-         ind2 = nbghostcells + 1
-         DO ji = mi0(ind1), mi1(ind2)   
-            DO jj = 1, jpj               
-               ztabramp(ji,jj) = zmskwest(jj)
-            END DO
-         END DO
+         IF(lk_west) THEN
+            ind1 = 1+nbghostcells
+            ind2 = 1+nbghostcells + ispongearea 
+            DO ji = mi0(ind1), mi1(ind2)   
+               DO jj = 1, jpj               
+                  ztabramp(ji,jj) = REAL( ind2 - mig(ji) ) * z1_ispongearea * zmskwest(jj)
+               END DO
+            END DO         
+
+            ! ghost cells:
+            ind1 = 1
+            ind2 = nbghostcells + 1
+            DO ji = mi0(ind1), mi1(ind2)   
+               DO jj = 1, jpj               
+                  ztabramp(ji,jj) = zmskwest(jj)
+               END DO
+            END DO
+         ENDIF
 
          ! --- East --- !
-         ind1 = jpiglo - nbghostcells - ispongearea
-         ind2 = jpiglo - nbghostcells
-         DO ji = mi0(ind1), mi1(ind2)
-            DO jj = 1, jpj
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_ispongearea) * zmskeast(jj)
-            ENDDO
-         END DO
-
-         ! ghost cells:
-         ind1 = jpiglo - nbghostcells
-         ind2 = jpiglo
-         DO ji = mi0(ind1), mi1(ind2)
-            DO jj = 1, jpj
-               ztabramp(ji,jj) = zmskeast(jj)
-            ENDDO
-         END DO
+         IF(lk_east) THEN
+            ind1 = jpiglo - nbghostcells - ispongearea
+            ind2 = jpiglo - nbghostcells
+            DO ji = mi0(ind1), mi1(ind2)
+
+               DO jj = 1, jpj
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_ispongearea) * zmskeast(jj)
+               ENDDO
+            END DO
+
+            ! ghost cells:
+            ind1 = jpiglo - nbghostcells
+            ind2 = jpiglo
+            DO ji = mi0(ind1), mi1(ind2)
+
+               DO jj = 1, jpj
+                  ztabramp(ji,jj) = zmskeast(jj)
+               ENDDO
+            END DO
+         ENDIF
 
          ! --- South --- !
-         ind1 = 1+nbghostcells
-         ind2 = 1+nbghostcells + jspongearea
-         DO jj = mj0(ind1), mj1(ind2) 
-            DO ji = 1, jpi
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_jspongearea) * zmsksouth(ji)
-            END DO
-         END DO
-
-         ! ghost cells:
-         ind1 = 1
-         ind2 = nbghostcells + 1
-         DO jj = mj0(ind1), mj1(ind2) 
-            DO ji = 1, jpi
-               ztabramp(ji,jj) = zmsksouth(ji)
-            END DO
-         END DO
+         IF( lk_south ) THEN 
+            ind1 = 1+nbghostcells
+            ind2 = 1+nbghostcells + jspongearea
+            DO jj = mj0(ind1), mj1(ind2) 
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_jspongearea) * zmsksouth(ji)
+               END DO
+            END DO
+
+            ! ghost cells:
+            ind1 = 1
+            ind2 = nbghostcells + 1
+            DO jj = mj0(ind1), mj1(ind2) 
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = zmsksouth(ji)
+               END DO
+            END DO
+         ENDIF
 
          ! --- North --- !
-         ind1 = jpjglo - nbghostcells - jspongearea
-         ind2 = jpjglo - nbghostcells
-         DO jj = mj0(ind1), mj1(ind2)
-            DO ji = 1, jpi
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_jspongearea) * zmsknorth(ji)
-            END DO
-         END DO
-
-         ! ghost cells:
-         ind1 = jpjglo - nbghostcells
-         ind2 = jpjglo
-         DO jj = mj0(ind1), mj1(ind2)
-            DO ji = 1, jpi
-               ztabramp(ji,jj) = zmsknorth(ji)
-            END DO
-         END DO
-
+         IF( lk_north ) THEN  
+            ind1 = jpjglo - nbghostcells - jspongearea
+            ind2 = jpjglo - nbghostcells
+            DO jj = mj0(ind1), mj1(ind2)
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_jspongearea) * zmsknorth(ji)
+               END DO
+            END DO
+
+            ! ghost cells:
+            ind1 = jpjglo - nbghostcells
+            ind2 = jpjglo
+            DO jj = mj0(ind1), mj1(ind2)
+               DO ji = 1, jpi
+                  ztabramp(ji,jj) = zmsknorth(ji)
+               END DO
+            END DO
+         ENDIF
+      
       ENDIF
 
@@ -334,5 +356,5 @@
       INTEGER  ::   ji, jj, jk, jn   ! dummy loop indices
       INTEGER  ::   iku, ikv
-      REAL(wp) :: ztsa, zabe1, zabe2, zbtr, zhtot, ztrelax
+      REAL(wp) :: ztsa, zabe1, zabe2, zbtr, zhtot
       REAL(wp), DIMENSION(i1:i2,j1:j2,jpk) :: ztu, ztv
       REAL(wp), DIMENSION(i1:i2,j1:j2,jpk,n1:n2) ::tsbdiff
@@ -438,9 +460,4 @@
          ENDDO
 
-         !* set relaxation time scale
-         IF( l_1st_euler .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_tra  / (        rn_Dt )
-         ELSE                                          ;   ztrelax =   rn_trelax_tra  / (2._wp * rn_Dt )
-         ENDIF
-
          DO jn = 1, jpts            
             DO jk = 1, jpkm1
@@ -448,5 +465,5 @@
                DO jj = j1,j2
                   DO ji = i1,i2-1
-                     zabe1 = rn_sponge_tra * fspu(ji,jj) * umask(ji,jj,jk) * e2_e1u(ji,jj) * e3u(ji,jj,jk,Kmm_a)
+                     zabe1 = rn_sponge_tra * r1_Dt * fspu(ji,jj) * umask(ji,jj,jk) * e1e2u(ji,jj) * e3u(ji,jj,jk,Kmm_a)
                      ztu(ji,jj,jk) = zabe1 * ( tsbdiff(ji+1,jj  ,jk,jn) - tsbdiff(ji,jj,jk,jn) ) 
                   END DO
@@ -455,5 +472,5 @@
                DO ji = i1,i2
                   DO jj = j1,j2-1
-                     zabe2 = rn_sponge_tra * fspv(ji,jj) * vmask(ji,jj,jk) * e1_e2v(ji,jj) * e3v(ji,jj,jk,Kmm_a)
+                     zabe2 = rn_sponge_tra * r1_Dt * fspv(ji,jj) * vmask(ji,jj,jk) * e1e2v(ji,jj) * e3v(ji,jj,jk,Kmm_a)
                      ztv(ji,jj,jk) = zabe2 * ( tsbdiff(ji  ,jj+1,jk,jn) - tsbdiff(ji,jj,jk,jn) )
                   END DO
@@ -480,5 +497,5 @@
                         ! horizontal diffusive trends
                         ztsa = zbtr * (  ztu(ji,jj,jk) - ztu(ji-1,jj,jk) + ztv(ji,jj,jk) - ztv(ji,jj-1,jk)  ) &
-                             &  - ztrelax * fspt(ji,jj) * tsbdiff(ji,jj,jk,jn) 
+                             &  - rn_trelax_tra * r1_Dt * fspt(ji,jj) * tsbdiff(ji,jj,jk,jn) 
                         ! add it to the general tracer trends
                         ts(ji,jj,jk,jn,Krhs_a) = ts(ji,jj,jk,jn,Krhs_a) + ztsa
@@ -507,5 +524,5 @@
 
       ! sponge parameters 
-      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr, zhtot, ztrelax
+      REAL(wp) :: ze2u, ze1v, zua, zva, zbtr, zhtot
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: ubdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: rotdiff, hdivdiff
@@ -595,8 +612,4 @@
          ubdiff(i1:i2,j1:j2,:) = (uu(i1:i2,j1:j2,:,Kbb_a) - tabres(i1:i2,j1:j2,:,1))*umask(i1:i2,j1:j2,:)
 #endif
-         !* set relaxation time scale
-         IF( l_1st_euler .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_dyn  / (        rn_Dt )
-         ELSE                                          ;   ztrelax =   rn_trelax_dyn  / (2._wp * rn_Dt )
-         ENDIF
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -608,5 +621,5 @@
             DO jj = j1,j2
                DO ji = i1+1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb_a) * rn_sponge_dyn * fspt(ji,jj)
+                  zbtr = rn_sponge_dyn * r1_Dt * fspt(ji,jj) / e3t(ji,jj,jk,Kbb_a)
                   hdivdiff(ji,jj,jk) = (  e2u(ji  ,jj)*e3u(ji  ,jj,jk,Kbb_a) * ubdiff(ji  ,jj,jk) &
                                      &   -e2u(ji-1,jj)*e3u(ji-1,jj,jk,Kbb_a) * ubdiff(ji-1,jj,jk) ) * zbtr
@@ -616,5 +629,5 @@
             DO jj = j1,j2-1
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * e3f(ji,jj,jk) * rn_sponge_dyn * fspf(ji,jj)
+                  zbtr = rn_sponge_dyn * r1_Dt * fspf(ji,jj) * e3f(ji,jj,jk) 
                   rotdiff(ji,jj,jk) = ( -e1u(ji,jj+1) * ubdiff(ji,jj+1,jk)   &
                                     &   +e1u(ji,jj  ) * ubdiff(ji,jj  ,jk) ) * fmask(ji,jj,jk) * zbtr 
@@ -633,5 +646,5 @@
                      zua = - ( ze2u - rotdiff (ji,jj-1,jk) ) / ( e2u(ji,jj) * e3u(ji,jj,jk,Kmm_a) )   &
                          & + ( hdivdiff(ji+1,jj,jk) - ze1v ) * r1_e1u(ji,jj) & 
-                         & - ztrelax  * fspu(ji,jj) * ubdiff(ji,jj,jk)
+                         & - rn_trelax_dyn * r1_Dt * fspu(ji,jj) * ubdiff(ji,jj,jk)
 
                      ! add it to the general momentum trends
@@ -646,4 +659,5 @@
 
          jmax = j2-1
+        ! IF (lk_north) jmax = MIN(jmax,nlcj-nbghostcells-2)   ! North
          IF ((nbondj == 1).OR.(nbondj == 2)) jmax = MIN(jmax,nlcj-nbghostcells-2)   ! North
 
@@ -684,5 +698,5 @@
       !
       INTEGER  ::   ji, jj, jk, imax
-      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr, zhtot, ztrelax
+      REAL(wp) ::   ze2u, ze1v, zua, zva, zbtr, zhtot
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: vbdiff
       REAL(wp), DIMENSION(i1:i2,j1:j2,1:jpk) :: rotdiff, hdivdiff
@@ -771,8 +785,4 @@
          vbdiff(i1:i2,j1:j2,:) = (vv(i1:i2,j1:j2,:,Kbb_a) - tabres(i1:i2,j1:j2,:,1))*vmask(i1:i2,j1:j2,:)
 # endif
-         !* set relaxation time scale
-         IF( l_1st_euler .AND. lk_agrif_fstep ) THEN   ;   ztrelax =   rn_trelax_dyn  / (        rn_Dt )
-         ELSE                                          ;   ztrelax =   rn_trelax_dyn  / (2._wp * rn_Dt )
-         ENDIF
          !
          DO jk = 1, jpkm1                                 ! Horizontal slab
@@ -784,5 +794,5 @@
             DO jj = j1+1,j2
                DO ji = i1,i2   ! vector opt.
-                  zbtr = r1_e1e2t(ji,jj) / e3t(ji,jj,jk,Kbb_a) * rn_sponge_dyn * fspt(ji,jj)
+                  zbtr = rn_sponge_dyn * r1_Dt * fspt(ji,jj) / e3t(ji,jj,jk,Kbb_a)
                   hdivdiff(ji,jj,jk) = ( e1v(ji,jj  ) * e3v(ji,jj  ,jk,Kbb_a) * vbdiff(ji,jj  ,jk)  &
                                      &  -e1v(ji,jj-1) * e3v(ji,jj-1,jk,Kbb_a) * vbdiff(ji,jj-1,jk)  ) * zbtr
@@ -791,5 +801,5 @@
             DO jj = j1,j2
                DO ji = i1,i2-1   ! vector opt.
-                  zbtr = r1_e1e2f(ji,jj) * e3f(ji,jj,jk) * rn_sponge_dyn * fspf(ji,jj)
+                  zbtr = rn_sponge_dyn * r1_Dt * fspf(ji,jj) * e3f(ji,jj,jk) 
                   rotdiff(ji,jj,jk) = ( e2v(ji+1,jj) * vbdiff(ji+1,jj,jk) & 
                                     &  -e2v(ji  ,jj) * vbdiff(ji  ,jj,jk)  ) * fmask(ji,jj,jk) * zbtr
@@ -802,4 +812,5 @@
 
          imax = i2 - 1
+      !   IF(lk_east) imax = MIN(imax,nlci-nbghostcells-2)   ! East
          IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-nbghostcells-2)   ! East
 
@@ -808,5 +819,5 @@
                IF( .NOT. tabspongedone_u(ji,jj) ) THEN
                   DO jk = 1, jpkm1
-                     uu(ji,jj,jk,Krhs_a) = uu(ji,jj,jk,Krhs_a)                                                               &
+                     uu(ji,jj,jk,Krhs_a) = uu(ji,jj,jk,Krhs_a)                                                     &
                         & - ( rotdiff (ji  ,jj,jk) - rotdiff (ji,jj-1,jk)) / ( e2u(ji,jj) * e3u(ji,jj,jk,Kmm_a) )  &
                         & + ( hdivdiff(ji+1,jj,jk) - hdivdiff(ji,jj  ,jk)) * r1_e1u(ji,jj)
@@ -822,8 +833,8 @@
                IF( .NOT. tabspongedone_v(ji,jj) ) THEN
                   DO jk = 1, jpkm1
-                     vv(ji,jj,jk,Krhs_a) = vv(ji,jj,jk,Krhs_a)                                                                  &
+                     vv(ji,jj,jk,Krhs_a) = vv(ji,jj,jk,Krhs_a)                                                        &
                         &  + ( rotdiff (ji,jj  ,jk) - rotdiff (ji-1,jj,jk) ) / ( e1v(ji,jj) * e3v(ji,jj,jk,Kmm_a) )   &
-                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)                      &
-                        &  - ztrelax * fspv(ji,jj) * vbdiff(ji,jj,jk)
+                        &  + ( hdivdiff(ji,jj+1,jk) - hdivdiff(ji  ,jj,jk) ) * r1_e2v(ji,jj)                          &
+                        &  - rn_trelax_dyn * r1_Dt * fspv(ji,jj) * vbdiff(ji,jj,jk)
                   END DO
                ENDIF
