Index: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/NST/agrif_oce_interp.F90
===================================================================
--- NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/NST/agrif_oce_interp.F90	(revision 14200)
+++ NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/NST/agrif_oce_interp.F90	(revision 14644)
@@ -2,5 +2,5 @@
    !!======================================================================
    !!                   ***  MODULE  agrif_oce_interp  ***
-   !! AGRIF: interpolation package for the ocean dynamics (OPA)
+   !! AGRIF: interpolation package for the ocean dynamics (OCE)
    !!======================================================================
    !! History :  2.0  !  2002-06  (L. Debreu)  Original cade
@@ -109,5 +109,5 @@
       vv(:,:,:,Kbb) = vv(:,:,:,Kbb) * vmask(:,:,:) 
 
-      CALL lbc_lnk_multi( 'agrif_istate_oce', uu(:,:,:  ,Kbb), 'U', -1.0_wp , vv(:,:,:,Kbb), 'V', -1.0_wp )
+      CALL lbc_lnk( 'agrif_istate_oce', uu(:,:,:  ,Kbb), 'U', -1.0_wp , vv(:,:,:,Kbb), 'V', -1.0_wp )
       CALL lbc_lnk( 'agrif_istate_oce', ts(:,:,:,:,Kbb), 'T',  1.0_wp )
 
@@ -863,35 +863,35 @@
                   ! Build vertical grids:
                   N_in = mbkt_parent(ji,jj)
-                  ! Input grid (account for partial cells if any):
-                  DO jk=1,N_in
-                     z_in(jk) = ptab(ji,jj,jk,n2) - ptab(ji,jj,k2,n2)
-                     tabin(jk,1:jpts) = ptab(ji,jj,jk,1:jpts)
-                  END DO
+                  N_out = mbkt(ji,jj)
+                  IF (N_in*N_out > 0) THEN
+                     ! Input grid (account for partial cells if any):
+                     DO jk=1,N_in
+                        z_in(jk) = ptab(ji,jj,jk,n2) - ptab(ji,jj,k2,n2)
+                        tabin(jk,1:jpts) = ptab(ji,jj,jk,1:jpts)
+                     END DO
                   
-                  ! Intermediate grid:
-                  IF ( l_vremap ) THEN
-                     DO jk = 1, N_in
-                        h_in_i(jk) = e3t0_parent(ji,jj,jk) * & 
-                          &       (1._wp + ptab(ji,jj,k2,n2)/(ht0_parent(ji,jj)*ssmask(ji,jj) + 1._wp - ssmask(ji,jj)))
+                     ! Intermediate grid:
+                     IF ( l_vremap ) THEN
+                        DO jk = 1, N_in
+                           h_in_i(jk) = e3t0_parent(ji,jj,jk) * & 
+                             &       (1._wp + ptab(ji,jj,k2,n2)/(ht0_parent(ji,jj)*ssmask(ji,jj) + 1._wp - ssmask(ji,jj)))
+                        END DO
+                        z_in_i(1) = 0.5_wp * h_in_i(1)
+                        DO jk=2,N_in
+                           z_in_i(jk) = z_in_i(jk-1) + 0.5_wp * ( h_in_i(jk) + h_in_i(jk-1) )
+                        END DO
+                        z_in_i(1:N_in) = z_in_i(1:N_in)  - ptab(ji,jj,k2,n2)
+                     ENDIF                              
+
+                     ! Output (Child) grid:
+                     DO jk=1,N_out
+                        h_out(jk) = e3t(ji,jj,jk,Krhs_a)
                      END DO
-                     z_in_i(1) = 0.5_wp * h_in_i(1)
-                     DO jk=2,N_in
-                        z_in_i(jk) = z_in_i(jk-1) + 0.5_wp * ( h_in_i(jk) + h_in_i(jk-1) )
+                     z_out(1) = 0.5_wp * h_out(1)
+                     DO jk=2,N_out
+                        z_out(jk) = z_out(jk-1) + 0.5_wp * ( h_out(jk)+h_out(jk-1) )
                      END DO
-                     z_in_i(1:N_in) = z_in_i(1:N_in)  - ptab(ji,jj,k2,n2)
-                  ENDIF                              
-
-                  ! Output (Child) grid:
-                  N_out = mbkt(ji,jj)
-                  DO jk=1,N_out
-                     h_out(jk) = e3t(ji,jj,jk,Krhs_a)
-                  END DO
-                  z_out(1) = 0.5_wp * h_out(1)
-                  DO jk=2,N_out
-                     z_out(jk) = z_out(jk-1) + 0.5_wp * ( h_out(jk)+h_out(jk-1) )
-                  END DO
-                  IF (.NOT.ln_linssh) z_out(1:N_out) = z_out(1:N_out)  - ssh(ji,jj,Krhs_a)
-
-                  IF (N_in*N_out > 0) THEN
+                     IF (.NOT.ln_linssh) z_out(1:N_out) = z_out(1:N_out)  - ssh(ji,jj,Krhs_a)
+
                      IF( l_ini_child ) THEN
                         CALL remap_linear(tabin(1:N_in,1:jpts),z_in(1:N_in),ts(ji,jj,1:N_out,1:jpts,Krhs_a),              &
@@ -1040,50 +1040,48 @@
                   uu(ji,jj,:,Krhs_a) = 0._wp
                   N_in = mbku_parent(ji,jj)
-                  zhtot = 0._wp
-                  DO jk=1,N_in
-                     !IF (jk==N_in) THEN
-                     !   h_in(jk) = hu0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
-                     !ELSE
-                     !   h_in(jk) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
-                     !ENDIF
-                     IF ( l_vremap ) THEN
-                        h_in(jk) = e3u0_parent(ji,jj,jk) 
-                     ELSE
-                        IF (jk==N_in) THEN
-                           h_in(jk) = hu0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                  N_out = mbku(ji,jj)
+                  IF (N_in*N_out > 0) THEN
+                     zhtot = 0._wp
+                     DO jk=1,N_in
+                        !IF (jk==N_in) THEN
+                        !   h_in(jk) = hu0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                        !ELSE
+                        !   h_in(jk) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
+                        !ENDIF
+                        IF ( l_vremap ) THEN
+                           h_in(jk) = e3u0_parent(ji,jj,jk) 
                         ELSE
-                           h_in(jk) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
+                           IF (jk==N_in) THEN
+                              h_in(jk) = hu0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                           ELSE
+                              h_in(jk) = ptab(ji,jj,jk,2)/(e2u(ji,jj)*zrhoy) 
+                           ENDIF
                         ENDIF
-                     ENDIF
-                     zhtot = zhtot + h_in(jk)
-                     IF( h_in(jk) .GT. 0. ) THEN
-                     tabin(jk) = ptab(ji,jj,jk,1)/(e2u(ji,jj)*zrhoy*h_in(jk))
-                     ELSE
-                     tabin(jk) = 0.
-                     ENDIF
-                 END DO
-                 z_in(1) = 0.5_wp * h_in(1) - zhtot + hu0_parent(ji,jj) 
-                 DO jk=2,N_in
-                    z_in(jk) = z_in(jk-1) + 0.5_wp * (h_in(jk)+h_in(jk-1))
-                 END DO
+                        zhtot = zhtot + h_in(jk)
+                        IF( h_in(jk) .GT. 0. ) THEN
+                           tabin(jk) = ptab(ji,jj,jk,1)/(e2u(ji,jj)*zrhoy*h_in(jk))
+                        ELSE
+                           tabin(jk) = 0.
+                        ENDIF
+                    END DO
+                    z_in(1) = 0.5_wp * h_in(1) - zhtot + hu0_parent(ji,jj) 
+                    DO jk=2,N_in
+                       z_in(jk) = z_in(jk-1) + 0.5_wp * (h_in(jk)+h_in(jk-1))
+                    END DO
                      
-                 N_out = 0
-                 DO jk=1,jpk
-                    IF (umask(ji,jj,jk) == 0) EXIT
-                    N_out = N_out + 1
-                    h_out(N_out) = e3u(ji,jj,jk,Krhs_a)
-                 END DO
-
-                 z_out(1) = 0.5_wp * h_out(1) - SUM(h_out(1:N_out)) + hu_0(ji,jj)
-                 DO jk=2,N_out
-                    z_out(jk) = z_out(jk-1) + 0.5_wp * (h_out(jk-1) + h_out(jk)) 
-                 END DO  
-
-                 IF (N_in*N_out > 0) THEN
-                     IF( l_ini_child ) THEN
-                        CALL remap_linear       (tabin(1:N_in),z_in(1:N_in),uu(ji,jj,1:N_out,Krhs_a),z_out(1:N_out),N_in,N_out,1)
-                     ELSE
-                        CALL reconstructandremap(tabin(1:N_in),h_in(1:N_in),uu(ji,jj,1:N_out,Krhs_a),h_out(1:N_out),N_in,N_out,1)
-                     ENDIF   
+                    DO jk=1, N_out
+                       h_out(jk) = e3u(ji,jj,jk,Krhs_a)
+                    END DO
+
+                    z_out(1) = 0.5_wp * h_out(1) - SUM(h_out(1:N_out)) + hu_0(ji,jj)
+                    DO jk=2,N_out
+                       z_out(jk) = z_out(jk-1) + 0.5_wp * (h_out(jk-1) + h_out(jk)) 
+                    END DO  
+
+                    IF( l_ini_child ) THEN
+                       CALL remap_linear       (tabin(1:N_in),z_in(1:N_in),uu(ji,jj,1:N_out,Krhs_a),z_out(1:N_out),N_in,N_out,1)
+                    ELSE
+                       CALL reconstructandremap(tabin(1:N_in),h_in(1:N_in),uu(ji,jj,1:N_out,Krhs_a),h_out(1:N_out),N_in,N_out,1)
+                    ENDIF   
                  ENDIF
                END DO
@@ -1171,46 +1169,45 @@
                   vv(ji,jj,:,Krhs_a) = 0._wp
                   N_in = mbkv_parent(ji,jj)
-                  zhtot = 0._wp
-                  DO jk=1,N_in
-                     !IF (jk==N_in) THEN
-                     !   h_in(jk) = hv0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
-                     !ELSE
-                     !   h_in(jk) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox) 
-                     !ENDIF
-                     IF (l_vremap) THEN
-                        h_in(jk) = e3v0_parent(ji,jj,jk)
-                     ELSE
-                        IF (jk==N_in) THEN
-                           h_in(jk) = hv0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                  N_out = mbkv(ji,jj)
+
+                  IF (N_in*N_out > 0) THEN
+                     zhtot = 0._wp
+                     DO jk=1,N_in
+                        !IF (jk==N_in) THEN
+                        !   h_in(jk) = hv0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                        !ELSE
+                        !   h_in(jk) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox) 
+                        !ENDIF
+                        IF (l_vremap) THEN
+                           h_in(jk) = e3v0_parent(ji,jj,jk)
                         ELSE
-                           h_in(jk) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox) 
+                           IF (jk==N_in) THEN
+                              h_in(jk) = hv0_parent(ji,jj) + ptab(ji,jj,k2,2) - zhtot
+                           ELSE
+                              h_in(jk) = ptab(ji,jj,jk,2)/(e1v(ji,jj)*zrhox) 
+                           ENDIF
                         ENDIF
-                     ENDIF
-                     zhtot = zhtot + h_in(jk)
-                     IF( h_in(jk) .GT. 0. ) THEN
-                       tabin(jk) = ptab(ji,jj,jk,1)/(e1v(ji,jj)*zrhox*h_in(jk))
-                     ELSE
-                       tabin(jk)  = 0.
-                     ENDIF 
-                  END DO
-
-                  z_in(1) = 0.5_wp * h_in(1) - zhtot + hv0_parent(ji,jj)
-                  DO jk=2,N_in
-                     z_in(jk) = z_in(jk-1) + 0.5_wp * (h_in(jk-1)+h_in(jk))
-                  END DO
-
-                  N_out = 0
-                  DO jk=1,jpk
-                     IF (vmask(ji,jj,jk) == 0) EXIT
-                     N_out = N_out + 1
-                     h_out(N_out) = e3v(ji,jj,jk,Krhs_a)
-                  END DO
-
-                  z_out(1) = 0.5_wp * h_out(1) - SUM(h_out(1:N_out)) + hv_0(ji,jj)
-                  DO jk=2,N_out
-                     z_out(jk) = z_out(jk-1) + 0.5_wp * (h_out(jk-1)+h_out(jk))
-                  END DO
+                        zhtot = zhtot + h_in(jk)
+                        IF( h_in(jk) .GT. 0. ) THEN
+                          tabin(jk) = ptab(ji,jj,jk,1)/(e1v(ji,jj)*zrhox*h_in(jk))
+                        ELSE
+                          tabin(jk)  = 0.
+                        ENDIF 
+                     END DO
+
+                     z_in(1) = 0.5_wp * h_in(1) - zhtot + hv0_parent(ji,jj)
+                     DO jk=2,N_in
+                        z_in(jk) = z_in(jk-1) + 0.5_wp * (h_in(jk-1)+h_in(jk))
+                     END DO
+
+                     DO jk=1,N_out
+                        h_out(jk) = e3v(ji,jj,jk,Krhs_a)
+                     END DO
+
+                     z_out(1) = 0.5_wp * h_out(1) - SUM(h_out(1:N_out)) + hv_0(ji,jj)
+                     DO jk=2,N_out
+                        z_out(jk) = z_out(jk-1) + 0.5_wp * (h_out(jk-1)+h_out(jk))
+                     END DO
  
-                  IF (N_in*N_out > 0) THEN
                      IF( l_ini_child ) THEN
                         CALL remap_linear       (tabin(1:N_in),z_in(1:N_in),vv(ji,jj,1:N_out,Krhs_a),z_out(1:N_out),N_in,N_out,1)
@@ -1560,5 +1557,5 @@
                      &                 ptab(ji,jj,jk), tmask(ji,jj,jk) * e3t_0(ji,jj,jk), &
                      &                 mig0(ji), mjg0(jj), jk
-                !     kindic_agr = kindic_agr + 1
+                     kindic_agr = kindic_agr + 1
                   ENDIF
                END DO
@@ -1703,24 +1700,13 @@
 
          IF( l_vremap ) THEN
-            ! Interpolate thicknesses
+            ! Interpolate interfaces 
             ! Warning: these are masked, hence extrapolated prior interpolation.
             DO jk=k1,k2
                DO jj=j1,j2
                   DO ji=i1,i2
-                      ptab(ji,jj,jk,2) = tmask(ji,jj,jk) * e3t(ji,jj,jk,Kmm_a)
+                      ptab(ji,jj,jk,2) = tmask(ji,jj,jk) * gdepw(ji,jj,jk,Kmm_a)
                   END DO
                END DO
             END DO
-
-            ! Extrapolate thicknesses in partial bottom cells:
-            ! Set them to Agrif_SpecialValue (0.). Correct bottom thicknesses are retrieved later on
-            IF (ln_zps) THEN
-               DO jj=j1,j2
-                  DO ji=i1,i2
-                      jk = mbkt(ji,jj)
-                      ptab(ji,jj,jk,2) = 0._wp
-                  END DO
-               END DO           
-            END IF
         
            ! Save ssh at last level:
@@ -1736,20 +1722,20 @@
          IF( l_vremap ) THEN
             IF (ln_linssh) ptab(i1:i2,j1:j2,k2,2) = 0._wp 
-            avm_k(i1:i2,j1:j2,k1:k2) = 0._wp
+            avm_k(i1:i2,j1:j2,1:jpkm1) = 0._wp
                
             DO jj = j1, j2
                DO ji =i1, i2
                   N_in = mbkt_parent(ji,jj)
-                  IF ( tmask(ji,jj,1) == 0._wp) N_in = 0
-                  z_in(N_in+1) = ht0_parent(ji,jj) + ptab(ji,jj,k2,2)
-                  DO jk = N_in, 1, -1  ! Parent vertical grid               
-                        z_in(jk) = z_in(jk+1) - ptab(ji,jj,jk,2)
-                       tabin(jk) = ptab(ji,jj,jk,1)
-                  END DO
-                  N_out = mbkt(ji,jj) 
-                  DO jk = 1, N_out        ! Child vertical grid
-                     z_out(jk) = gdepw(ji,jj,jk,Kmm_a)
-                  END DO
+                  N_out = mbkt(ji,jj)
                   IF (N_in*N_out > 0) THEN
+                     DO jk = 1, N_in  ! Parent vertical grid               
+                        z_in(jk)  = ptab(ji,jj,jk,2) - ptab(ji,jj,k2,2)
+                        tabin(jk) = ptab(ji,jj,jk,1)
+                     END DO
+                     DO jk = 1, N_out        ! Child vertical grid
+                        z_out(jk) = gdepw(ji,jj,jk,Kmm_a) - ssh(ji,jj,Kmm_a)
+                     END DO
+                     IF (.NOT.ln_linssh) z_out(1:N_out) = z_out(1:N_out)  - ssh(ji,jj,Kmm_a)
+
                      CALL remap_linear(tabin(1:N_in),z_in(1:N_in),avm_k(ji,jj,1:N_out),z_out(1:N_out),N_in,N_out,1)
                   ENDIF
@@ -1757,5 +1743,5 @@
             END DO
          ELSE
-            avm_k(i1:i2,j1:j2,k1:k2) = ptab (i1:i2,j1:j2,k1:k2,1)
+            avm_k(i1:i2,j1:j2,1:jpkm1) = ptab (i1:i2,j1:j2,1:jpkm1,1)
          ENDIF
       ENDIF
