Bug for 1D tide forcing in NEMO 4.2.2

Hi,

For the case of using 1D tidal forcing for the open boundaries, where we have a Flather type 3 boundary (tides plus external forcing) for u2d and a FRS type bdy for u3d, and where we also have ln_full_vel=T, we get a crash when loading the tidal harmonics into td%u0 in bdytides.F90. We found this during porting from NEMO 3.6 to 4.2.2

I think the problem is that the size of td%u0 and td%v0 is too large (size nblen, the bdy length times number of relaxation rows), which does not match the size of the 1D harmonic data (just the bdy length). The crash occurs at “td%u0(:,itide,1) = dta_read(1:isz,1,1)”.

Including a tentative patch below that fixes it enough to be able to run — it adjusts so we attempt to populate only the first nblenrim worth of entries in td%u0. I suspect it’s possible to do a better patch here (eg allocate the size of td%u0 to match the size of the 1D bdy length) but I’ve not done so

Subject: [PATCH] Fix for bdytides when using 1D tide files

---
 src/OCE/BDY/bdytides.F90 | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/OCE/BDY/bdytides.F90 b/src/OCE/BDY/bdytides.F90
index 12250aa..aaadb05 100644
--- a/src/OCE/BDY/bdytides.F90
+++ b/src/OCE/BDY/bdytides.F90
@@ -138,16 +138,22 @@ CONTAINS
             IF( ASSOCIATED(dta%ssh) ) THEN   ! we use bdy ssh on this mpi subdomain
                isz = SIZE(dta%ssh)
                ALLOCATE( td%ssh0( isz, nb_harmo, 2 ), td%ssh( isz, nb_harmo, 2 ), dta_bdy_s(ib_bdy)%ssh( isz ) )
+               td%ssh0(:,:,:) = 0._wp
+               td%ssh(:,:,:) = 0._wp
                dta_bdy_s(ib_bdy)%ssh(:) = 0._wp   ! needed?
             ENDIF
             IF( ASSOCIATED(dta%u2d) ) THEN   ! we use bdy u2d on this mpi subdomain
                isz = SIZE(dta%u2d)
                ALLOCATE( td%u0  ( isz, nb_harmo, 2 ), td%u  ( isz, nb_harmo, 2 ), dta_bdy_s(ib_bdy)%u2d( isz ) )
+               td%u0(:,:,:) = 0._wp
+               td%u(:,:,:) = 0._wp
                dta_bdy_s(ib_bdy)%u2d(:) = 0._wp   ! needed?
             ENDIF
             IF( ASSOCIATED(dta%v2d) ) THEN   ! we use bdy v2d on this mpi subdomain
                isz = SIZE(dta%v2d)
                ALLOCATE( td%v0  ( isz, nb_harmo, 2 ), td%v  ( isz, nb_harmo, 2 ), dta_bdy_s(ib_bdy)%v2d( isz ) )
+               td%v0(:,:,:) = 0._wp
+               td%v(:,:,:) = 0._wp
                dta_bdy_s(ib_bdy)%v2d(:) = 0._wp   ! needed?
             ENDIF
 
@@ -239,24 +245,34 @@ CONTAINS
                   ENDIF
                   !                                                              ! U fields
                   IF( ASSOCIATED(dta%u2d) ) THEN   ! we use bdy u2d on this mpi subdomain
-                     isz = SIZE(dta%u2d)
+                     IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
+                        isz = SIZE(dta%u2d)
+                     ELSE
+                        igrd = 2
+                        isz = idx_bdy(ib_bdy)%nblenrim(igrd)
+                     ENDIF
                      clfile = TRIM(filtide)//TRIM(tide_harmonics(itide)%cname_tide)//'_grid_U.nc'
                      CALL iom_open( clfile, inum )
                      CALL fld_map( inum, 'u1', dta_read(1:isz,1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,2) )
-                     td%u0(:,itide,1) = dta_read(1:isz,1,1)
+                     td%u0(1:isz,itide,1) = dta_read(1:isz,1,1)
                      CALL fld_map( inum, 'u2', dta_read(1:isz,1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,2) )
-                     td%u0(:,itide,2) = dta_read(1:isz,1,1)
+                     td%u0(1:isz,itide,2) = dta_read(1:isz,1,1)
                      CALL iom_close( inum )
                   ENDIF
                   !                                                              ! V fields
                   IF( ASSOCIATED(dta%v2d) ) THEN   ! we use bdy v2d on this mpi subdomain
-                     isz = SIZE(dta%v2d)
+                     IF( cn_dyn2d(ib_bdy) == 'frs' ) THEN
+                        isz = SIZE(dta%v2d)
+                     ELSE
+                        igrd = 3
+                        isz = idx_bdy(ib_bdy)%nblenrim(igrd)
+                     ENDIF
                      clfile = TRIM(filtide)//TRIM(tide_harmonics(itide)%cname_tide)//'_grid_V.nc'
                      CALL iom_open( clfile, inum )
                      CALL fld_map( inum, 'v1', dta_read(1:isz,1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,3) )
-                     td%v0(:,itide,1) = dta_read(1:isz,1,1)
+                     td%v0(1:isz,itide,1) = dta_read(1:isz,1,1)
                      CALL fld_map( inum, 'v2', dta_read(1:isz,1:1,1:1) , 1, idx_bdy(ib_bdy)%nbmap(:,3) )
-                     td%v0(:,itide,2) = dta_read(1:isz,1,1)
+                     td%v0(1:isz,itide,2) = dta_read(1:isz,1,1)
                      CALL iom_close( inum )
                   ENDIF
                   !
@@ -446,7 +462,7 @@ CONTAINS
          !
       ENDIF
       !
-      IF( ASSOCIATED(td%v0) ) THEN   ! V grid. we use bdy u2d on this mpi subdomain
+      IF( ASSOCIATED(td%v0) ) THEN   ! V grid. we use bdy v2d on this mpi subdomain
          !
          isz = SIZE( td%v0, dim = 1 )
          ALLOCATE( mod_tide(isz), phi_tide(isz) )
--