From 50520669d990262d500796765f58670fe6f4cfab Mon Sep 17 00:00:00 2001
From: Sebastien Masson <sebastien.masson@locean.ipsl.fr>
Date: Tue, 1 Mar 2022 08:27:46 +0000
Subject: [PATCH] Resolve "bug in the init of the no gather NP folding"

---
 arch/CNRS/arch-X64_IRENE.fcm           |  2 +-
 arch/CNRS/arch-X64_IRENE_DEBUG.fcm     |  2 +-
 arch/CNRS/arch-X64_IRENE_GCC.fcm       |  2 +-
 arch/CNRS/arch-X64_IRENE_GCC_DEBUG.fcm |  2 +-
 arch/CNRS/arch-X64_JEANZAY.fcm         |  2 +-
 arch/CNRS/arch-X64_JEANZAY_DEBUG.fcm   |  2 +-
 arch/arch-linux_gfortran.fcm           | 23 +++++++++++------------
 arch/arch-osx_gfortran.fcm             |  2 +-
 arch/arch-osx_gfortran_debug.fcm       |  2 +-
 src/OCE/LBC/mpp_nfd_generic.h90        |  2 +-
 src/OCE/LBC/mppini.F90                 | 10 ++++++++--
 11 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/arch/CNRS/arch-X64_IRENE.fcm b/arch/CNRS/arch-X64_IRENE.fcm
index 90da9ea3c..b96db19b0 100644
--- a/arch/CNRS/arch-X64_IRENE.fcm
+++ b/arch/CNRS/arch-X64_IRENE.fcm
@@ -30,7 +30,7 @@
 #  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
 #  - fcm variables are starting with a % (and not a $)
 #
-%XIOS_HOME           $CCCWORKDIR/xios-2.5
+%XIOS_HOME           $CCCWORKDIR/xios-trunk
 %OASIS_HOME          $CCCWORKDIR/now/models/oa3mct
 
 %NCDF_INC            -I$NETCDFFORTRAN_INCDIR -I$NETCDF_INCDIR
diff --git a/arch/CNRS/arch-X64_IRENE_DEBUG.fcm b/arch/CNRS/arch-X64_IRENE_DEBUG.fcm
index 39a1eb164..0db4df2dd 100644
--- a/arch/CNRS/arch-X64_IRENE_DEBUG.fcm
+++ b/arch/CNRS/arch-X64_IRENE_DEBUG.fcm
@@ -30,7 +30,7 @@
 #  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
 #  - fcm variables are starting with a % (and not a $)
 #
-%XIOS_HOME           $CCCWORKDIR/xios-2.5
+%XIOS_HOME           $CCCWORKDIR/xios-trunk
 %OASIS_HOME          $CCCWORKDIR/now/models/oa3mct
 
 %NCDF_INC            -I$NETCDFFORTRAN_INCDIR -I$NETCDF_INCDIR
diff --git a/arch/CNRS/arch-X64_IRENE_GCC.fcm b/arch/CNRS/arch-X64_IRENE_GCC.fcm
index 28ea15570..6d27c5fa3 100644
--- a/arch/CNRS/arch-X64_IRENE_GCC.fcm
+++ b/arch/CNRS/arch-X64_IRENE_GCC.fcm
@@ -16,7 +16,7 @@
 #  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
 #  - fcm variables are starting with a % (and not a $)
 #
-%XIOS_HOME           $CCCWORKDIR/xios-2.5_gcc
+%XIOS_HOME           $CCCWORKDIR/xios-trunk_gcc
 %OASIS_HOME          $CCCWORKDIR/now/models/oa3mct
 
 %NCDF_INC            -I$NETCDFFORTRAN_INCDIR -I$NETCDF_INCDIR
diff --git a/arch/CNRS/arch-X64_IRENE_GCC_DEBUG.fcm b/arch/CNRS/arch-X64_IRENE_GCC_DEBUG.fcm
index 2385fd421..f83799fcc 100644
--- a/arch/CNRS/arch-X64_IRENE_GCC_DEBUG.fcm
+++ b/arch/CNRS/arch-X64_IRENE_GCC_DEBUG.fcm
@@ -16,7 +16,7 @@
 #  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
 #  - fcm variables are starting with a % (and not a $)
 #
-%XIOS_HOME           $CCCWORKDIR/xios-2.5_gcc
+%XIOS_HOME           $CCCWORKDIR/xios-trunk_gcc
 %OASIS_HOME          $CCCWORKDIR/now/models/oa3mct
 
 %NCDF_INC            -I$NETCDFFORTRAN_INCDIR -I$NETCDF_INCDIR
diff --git a/arch/CNRS/arch-X64_JEANZAY.fcm b/arch/CNRS/arch-X64_JEANZAY.fcm
index 3cac8f888..e6e7ee1d0 100644
--- a/arch/CNRS/arch-X64_JEANZAY.fcm
+++ b/arch/CNRS/arch-X64_JEANZAY.fcm
@@ -36,7 +36,7 @@
 #---------------------------------------------------------------------------------------------
 #
 #
-%XIOS_HOME           $WORK/xios-2.5
+%XIOS_HOME           $WORK/xios-trunk
 %OASIS_HOME          
 
 %NCDF_INC            
diff --git a/arch/CNRS/arch-X64_JEANZAY_DEBUG.fcm b/arch/CNRS/arch-X64_JEANZAY_DEBUG.fcm
index 6c8fa5002..727cabff5 100644
--- a/arch/CNRS/arch-X64_JEANZAY_DEBUG.fcm
+++ b/arch/CNRS/arch-X64_JEANZAY_DEBUG.fcm
@@ -36,7 +36,7 @@
 #---------------------------------------------------------------------------------------------
 #
 #
-%XIOS_HOME           $WORK/xios-2.5
+%XIOS_HOME           $WORK/xios-trunk
 %OASIS_HOME          
 
 %NCDF_INC            
diff --git a/arch/arch-linux_gfortran.fcm b/arch/arch-linux_gfortran.fcm
index daab41c21..39327645b 100644
--- a/arch/arch-linux_gfortran.fcm
+++ b/arch/arch-linux_gfortran.fcm
@@ -30,32 +30,31 @@
 #  - unix variables "$..." are accpeted and will be evaluated before calling fcm.
 #  - fcm variables are starting with a % (and not a $)
 #
-%NCDF_HOME           /usr/local/netcdf
-%HDF5_HOME           /usr/local/hdf5
-%XIOS_HOME           $HOME/xios-2.5
-%OASIS_HOME          /not/defined
+#%HDF5_HOME           $HOME/MODNUM/util/hdf5-1.8.13
+#%NCDF_C_HOME         $HOME/MODNUM/util/netcdf-c-4.3.3.1
+#%NCDF_F_HOME         $HOME/MODNUM/util/netcdf-fortran-4.4.2
+#%XIOS_HOME           $HOME/MODNUM/xios-trunk
 
-%NCDF_INC            -I%NCDF_HOME/include -I%HDF5_HOME/include
-%NCDF_LIB            -L%NCDF_HOME/lib -lnetcdff -lnetcdf
+%NCDF_INC            -I%NCDF_F_HOME/include -I%NCDF_C_HOME/include -I%HDF5_HOME/include
+%NCDF_LIB            -L%NCDF_F_HOME/lib -lnetcdff -L%NCDF_C_HOME/lib -lnetcdf
 %XIOS_INC            -I%XIOS_HOME/inc 
-%XIOS_LIB            -L%XIOS_HOME/lib -lxios -L/usr/lib/gcc/x86_64-linux-gnu/5 -lstdc++
+%XIOS_LIB            -L%XIOS_HOME/lib -lxios -lstdc++ 
 
 %OASIS_INC           -I%OASIS_HOME/build/lib/mct -I%OASIS_HOME/build/lib/psmile.MPI1
 %OASIS_LIB           -L%OASIS_HOME/lib -lpsmile.MPI1 -lmct -lmpeu -lscrip
 
 %CPP	             cpp -Dkey_nosignedzero 
-%FC	             /usr/bin/mpif90 -c -cpp 
+%FC	             mpif90 -c -cpp
 %FCFLAGS             -fdefault-real-8 -O3 -funroll-all-loops -fcray-pointer -ffree-line-length-none
 %FFLAGS              %FCFLAGS
-#%LD                  /usr/bin/mpif90 -Wl,-rpath=$HOME/INSTALL/lib:/usr/lib
-%LD                  /usr/bin/mpif90
+%LD                  mpif90
 %LDFLAGS             
 %FPPFLAGS            -P -C -traditional
 %AR                  ar
 %ARFLAGS             rs
 %MK                  make
-%USER_INC            %XIOS_INC %OASIS_INC %NCDF_INC
-%USER_LIB            %XIOS_LIB %OASIS_LIB %NCDF_LIB
+%USER_INC            %XIOS_INC %NCDF_INC
+%USER_LIB            %XIOS_LIB %NCDF_LIB
 
 %CC                  cc
 %CFLAGS              -O0
diff --git a/arch/arch-osx_gfortran.fcm b/arch/arch-osx_gfortran.fcm
index 496493e25..081c8d945 100644
--- a/arch/arch-osx_gfortran.fcm
+++ b/arch/arch-osx_gfortran.fcm
@@ -23,7 +23,7 @@
 #
 %NCDF_HOME           /opt/local
 %HDF5_HOME           /opt/local
-%XIOS_HOME           /Users/$( whoami )/xios-2.5
+%XIOS_HOME           /Users/$( whoami )/xios-trunk
 %OASIS_HOME          /not/defined
 
 %NCDF_INC            -I%NCDF_HOME/include -I%HDF5_HOME/include
diff --git a/arch/arch-osx_gfortran_debug.fcm b/arch/arch-osx_gfortran_debug.fcm
index d7985ada6..0d0773060 100644
--- a/arch/arch-osx_gfortran_debug.fcm
+++ b/arch/arch-osx_gfortran_debug.fcm
@@ -24,7 +24,7 @@
 #
 %NCDF_HOME           /opt/local
 %HDF5_HOME           /opt/local
-%XIOS_HOME           /Users/$( whoami )/xios-2.5
+%XIOS_HOME           /Users/$( whoami )/xios-trunk
 %OASIS_HOME          /not/defined
 
 %NCDF_INC            -I%NCDF_HOME/include -I%HDF5_HOME/include
diff --git a/src/OCE/LBC/mpp_nfd_generic.h90 b/src/OCE/LBC/mpp_nfd_generic.h90
index d13c71ae9..fd45035fe 100644
--- a/src/OCE/LBC/mpp_nfd_generic.h90
+++ b/src/OCE/LBC/mpp_nfd_generic.h90
@@ -213,7 +213,7 @@
                IF( c_NFtype == 'F' .AND. iig == 1 ) THEN
                   ij1 = jpj - khls     ! j-index in the receiving array
                   ij2 = 1              ! only 1 line in the buffer
-                  DO ji = mi0(khls), mi1(khls)
+                  DO ji = mi0(khls), mi1(khls)               ! change because of EW periodicity as we also change jpiglo-khls
                      iib = nfd_jisnd(mi0(       khls),iig)   ! i-index in the buffer
                      iin = nfd_rksnd(mi0(       khls),iig)   ! neigbhour-index in the buffer
                      IF( nfd_rknei(iin) == -1 .AND. kfillmode == jpfillnothing )   CYCLE
diff --git a/src/OCE/LBC/mppini.F90 b/src/OCE/LBC/mppini.F90
index 4cbfe0f48..31efed848 100644
--- a/src/OCE/LBC/mppini.F90
+++ b/src/OCE/LBC/mppini.F90
@@ -1292,6 +1292,7 @@ ENDIF
       REAL(wp), DIMENSION(jpi,jpj,2,4) ::   zinfo
       INTEGER , DIMENSION(10) ::   irknei ! too many elements but safe...
       INTEGER                 ::   ji, jj, jg, jn   ! dummy loop indices
+      INTEGER                 ::   iitmp
       LOGICAL                 ::   lnew
       !!----------------------------------------------------------------------
       !
@@ -1361,8 +1362,13 @@ ENDIF
             ALLOCATE( nfd_rknei(nfd_nbnei) )
             nfd_rknei(:) = irknei(1:nfd_nbnei)
             ! re-number nfd_rksnd according to the indexes of nfd_rknei
-            DO jn = 1, nfd_nbnei
-               WHERE( nfd_rksnd == nfd_rknei(jn) )   nfd_rksnd = jn
+            DO jg = 1, 4
+               DO ji = 1, jpi
+                  iitmp = nfd_rksnd(ji,jg)   ! must store a copy of nfd_rksnd(ji,jg) to make sure we don't change it twice
+                  DO jn = 1, nfd_nbnei
+                     IF( iitmp == nfd_rknei(jn) )   nfd_rksnd(ji,jg) = jn
+                  END DO
+               END DO
             END DO
             
             IF( ldwrtlay ) THEN
-- 
GitLab