Index: NEMO/branches/2020/dev_r12527_Gurvan_ShallowWater/src/OCE/BDY/bdydta.F90
===================================================================
--- NEMO/branches/2020/dev_r12527_Gurvan_ShallowWater/src/OCE/BDY/bdydta.F90	(revision 12529)
+++ NEMO/branches/2020/dev_r12527_Gurvan_ShallowWater/src/OCE/BDY/bdydta.F90	(revision 13151)
@@ -70,4 +70,5 @@
    !! * Substitutions
 #  include "do_loop_substitute.h90"
+#  include "domzgr_substitute.h90"
    !!----------------------------------------------------------------------
    !! NEMO/OCE 4.0 , NEMO Consortium (2018)
@@ -92,5 +93,4 @@
       INTEGER ::  ii, ij, ik, igrd, ipl               ! local integers
       INTEGER,   DIMENSION(jpbgrd)     ::   ilen1 
-      INTEGER,   DIMENSION(:), POINTER ::   nblen, nblenrim  ! short cuts
       TYPE(OBC_DATA)         , POINTER ::   dta_alias        ! short cut
       TYPE(FLD), DIMENSION(:), POINTER ::   bf_alias
@@ -108,12 +108,8 @@
          DO jbdy = 1, nb_bdy
             !
-            nblen    => idx_bdy(jbdy)%nblen
-            nblenrim => idx_bdy(jbdy)%nblenrim
-            !
             IF( nn_dyn2d_dta(jbdy) == 0 ) THEN 
-               ilen1(:) = nblen(:)
                IF( dta_bdy(jbdy)%lneed_ssh ) THEN 
                   igrd = 1
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblenrim(igrd)   ! ssh is allocated and used only on the rim
                      ii = idx_bdy(jbdy)%nbi(ib,igrd)
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
@@ -121,7 +117,7 @@
                   END DO
                ENDIF
-               IF( dta_bdy(jbdy)%lneed_dyn2d) THEN 
+               IF( dta_bdy(jbdy)%lneed_dyn2d .AND. ASSOCIATED(dta_bdy(jbdy)%u2d) ) THEN   ! no SIZE with a unassociated pointer
                   igrd = 2
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, SIZE(dta_bdy(jbdy)%u2d)   ! u2d is used only on the rim except if ln_full_vel = T, see bdy_dta_init
                      ii = idx_bdy(jbdy)%nbi(ib,igrd)
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
@@ -129,5 +125,5 @@
                   END DO
                   igrd = 3
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, SIZE(dta_bdy(jbdy)%v2d)   ! v2d is used only on the rim except if ln_full_vel = T, see bdy_dta_init
                      ii = idx_bdy(jbdy)%nbi(ib,igrd)
                      ij = idx_bdy(jbdy)%nbj(ib,igrd)
@@ -138,8 +134,7 @@
             !
             IF( nn_dyn3d_dta(jbdy) == 0 ) THEN 
-               ilen1(:) = nblen(:)
                IF( dta_bdy(jbdy)%lneed_dyn3d ) THEN 
                   igrd = 2 
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                      DO ik = 1, jpkm1
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
@@ -149,5 +144,5 @@
                   END DO
                   igrd = 3 
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                      DO ik = 1, jpkm1
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
@@ -160,8 +155,7 @@
 
             IF( nn_tra_dta(jbdy) == 0 ) THEN 
-               ilen1(:) = nblen(:)
                IF( dta_bdy(jbdy)%lneed_tra ) THEN
                   igrd = 1 
-                  DO ib = 1, ilen1(igrd)
+                  DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                      DO ik = 1, jpkm1
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
@@ -176,9 +170,8 @@
 #if defined key_si3
             IF( nn_ice_dta(jbdy) == 0 ) THEN    ! set ice to initial values
-               ilen1(:) = nblen(:)
                IF( dta_bdy(jbdy)%lneed_ice ) THEN
                   igrd = 1   
                   DO jl = 1, jpl
-                     DO ib = 1, ilen1(igrd)
+                     DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                         ii = idx_bdy(jbdy)%nbi(ib,igrd)
                         ij = idx_bdy(jbdy)%nbj(ib,igrd)
@@ -236,7 +229,7 @@
          ! tidal harmonic forcing ONLY: initialise arrays
          IF( nn_dyn2d_dta(jbdy) == 2 ) THEN   ! we did not read ssh, u/v2d 
-            IF( dta_alias%lneed_ssh   ) dta_alias%ssh(:) = 0._wp
-            IF( dta_alias%lneed_dyn2d ) dta_alias%u2d(:) = 0._wp
-            IF( dta_alias%lneed_dyn2d ) dta_alias%v2d(:) = 0._wp
+            IF( dta_alias%lneed_ssh   .AND. ASSOCIATED(dta_alias%ssh) ) dta_alias%ssh(:) = 0._wp
+            IF( dta_alias%lneed_dyn2d .AND. ASSOCIATED(dta_alias%u2d) ) dta_alias%u2d(:) = 0._wp
+            IF( dta_alias%lneed_dyn2d .AND. ASSOCIATED(dta_alias%v2d) ) dta_alias%v2d(:) = 0._wp
          ENDIF
 
@@ -245,10 +238,11 @@
             !
             igrd = 2                       ! zonal velocity
-            dta_alias%u2d(:) = 0._wp       ! compute barotrope zonal velocity and put it in u2d
             DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                ii   = idx_bdy(jbdy)%nbi(ib,igrd)
                ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               dta_alias%u2d(ib) = 0._wp   ! compute barotrope zonal velocity and put it in u2d
                DO ik = 1, jpkm1
-                  dta_alias%u2d(ib) = dta_alias%u2d(ib) + e3u(ii,ij,ik,Kmm) * umask(ii,ij,ik) * dta_alias%u3d(ib,ik)
+                  dta_alias%u2d(ib) = dta_alias%u2d(ib)   &
+                     &              + e3u(ii,ij,ik,Kmm) * umask(ii,ij,ik) * dta_alias%u3d(ib,ik)
                END DO
                dta_alias%u2d(ib) =  dta_alias%u2d(ib) * r1_hu(ii,ij,Kmm)
@@ -258,10 +252,11 @@
             END DO
             igrd = 3                       ! meridional velocity
-            dta_alias%v2d(:) = 0._wp       ! compute barotrope meridional velocity and put it in v2d
             DO ib = 1, idx_bdy(jbdy)%nblen(igrd)
                ii   = idx_bdy(jbdy)%nbi(ib,igrd)
                ij   = idx_bdy(jbdy)%nbj(ib,igrd)
+               dta_alias%v2d(ib) = 0._wp   ! compute barotrope meridional velocity and put it in v2d
                DO ik = 1, jpkm1
-                  dta_alias%v2d(ib) = dta_alias%v2d(ib) + e3v(ii,ij,ik,Kmm) * vmask(ii,ij,ik) * dta_alias%v3d(ib,ik)
+                  dta_alias%v2d(ib) = dta_alias%v2d(ib)   &
+                     &              + e3v(ii,ij,ik,Kmm) * vmask(ii,ij,ik) * dta_alias%v3d(ib,ik)
                END DO
                dta_alias%v2d(ib) =  dta_alias%v2d(ib) * r1_hv(ii,ij,Kmm)
@@ -283,5 +278,5 @@
 
 #if defined key_si3
-         IF( dta_alias%lneed_ice ) THEN
+         IF( dta_alias%lneed_ice .AND. idx_bdy(jbdy)%nblen(1) > 0 ) THEN
             ! fill temperature and salinity arrays
             IF( TRIM(bf_alias(jp_bdyt_i)%clrootname) == 'NOT USED' )   bf_alias(jp_bdyt_i)%fnow(:,1,:) = rice_tem (jbdy)
@@ -338,8 +333,6 @@
             DO jbdy = 1, nb_bdy      ! Tidal component added in ts loop
                IF ( nn_dyn2d_dta(jbdy) .GE. 2 ) THEN
-                  nblen => idx_bdy(jbdy)%nblen
-                  nblenrim => idx_bdy(jbdy)%nblenrim
-                  IF( cn_dyn2d(jbdy) == 'frs' ) THEN   ;   ilen1(:)=nblen(:)
-                  ELSE                                 ;   ilen1(:)=nblenrim(:)
+                  IF( cn_dyn2d(jbdy) == 'frs' ) THEN   ;   ilen1(:)=idx_bdy(jbdy)%nblen(:)
+                  ELSE                                 ;   ilen1(:)=idx_bdy(jbdy)%nblenrim(:)
                   ENDIF
                   IF ( dta_bdy(jbdy)%lneed_ssh   ) dta_bdy_s(jbdy)%ssh(1:ilen1(1)) = dta_bdy(jbdy)%ssh(1:ilen1(1))
