Index: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/LBC/lbcnfd.F90
===================================================================
--- NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/LBC/lbcnfd.F90	(revision 14197)
+++ NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/OCE/LBC/lbcnfd.F90	(revision 14644)
@@ -21,49 +21,25 @@
    USE in_out_manager ! I/O manager
    USE lib_mpp        ! MPP library
+#if ! defined key_mpi_off
+   USE MPI
+#endif
 
    IMPLICIT NONE
    PRIVATE
 
-   INTERFACE lbc_nfd
-      MODULE PROCEDURE   lbc_nfd_2d_sp    , lbc_nfd_3d_sp    , lbc_nfd_4d_sp
-      MODULE PROCEDURE   lbc_nfd_2d_ptr_sp, lbc_nfd_3d_ptr_sp, lbc_nfd_4d_ptr_sp
-      MODULE PROCEDURE   lbc_nfd_2d_ext_sp
-      MODULE PROCEDURE   lbc_nfd_2d_dp    , lbc_nfd_3d_dp    , lbc_nfd_4d_dp
-      MODULE PROCEDURE   lbc_nfd_2d_ptr_dp, lbc_nfd_3d_ptr_dp, lbc_nfd_4d_ptr_dp
-      MODULE PROCEDURE   lbc_nfd_2d_ext_dp
-   END INTERFACE
-   !
-   INTERFACE lbc_nfd_nogather
-!                        ! Currently only 4d array version is needed
-     MODULE PROCEDURE   lbc_nfd_nogather_2d_sp    , lbc_nfd_nogather_3d_sp
-     MODULE PROCEDURE   lbc_nfd_nogather_4d_sp
-     MODULE PROCEDURE   lbc_nfd_nogather_2d_ptr_sp, lbc_nfd_nogather_3d_ptr_sp
-     MODULE PROCEDURE   lbc_nfd_nogather_2d_dp    , lbc_nfd_nogather_3d_dp
-     MODULE PROCEDURE   lbc_nfd_nogather_4d_dp
-     MODULE PROCEDURE   lbc_nfd_nogather_2d_ptr_dp, lbc_nfd_nogather_3d_ptr_dp
-!     MODULE PROCEDURE   lbc_nfd_nogather_4d_ptr
+   INTERFACE lbc_nfd            ! called by mpp_nfd, lbc_lnk_pt2pt or lbc_lnk_neicoll
+      MODULE PROCEDURE   lbc_nfd_sp, lbc_nfd_ext_sp
+      MODULE PROCEDURE   lbc_nfd_dp, lbc_nfd_ext_dp
    END INTERFACE
 
-   TYPE, PUBLIC ::   PTR_2D_dp   !: array of 2D pointers (also used in lib_mpp)
-      REAL(dp), DIMENSION (:,:)    , POINTER ::   pt2d
-   END TYPE PTR_2D_dp
-   TYPE, PUBLIC ::   PTR_3D_dp   !: array of 3D pointers (also used in lib_mpp)
-      REAL(dp), DIMENSION (:,:,:)  , POINTER ::   pt3d
-   END TYPE PTR_3D_dp
-   TYPE, PUBLIC ::   PTR_4D_dp   !: array of 4D pointers (also used in lib_mpp)
-      REAL(dp), DIMENSION (:,:,:,:), POINTER ::   pt4d
-   END TYPE PTR_4D_dp
+   INTERFACE mpp_nfd            ! called by lbc_lnk_pt2pt or lbc_lnk_neicoll
+      MODULE PROCEDURE   mpp_nfd_sp, mpp_nfd_dp
+   END INTERFACE
 
-   TYPE, PUBLIC ::   PTR_2D_sp   !: array of 2D pointers (also used in lib_mpp)
-      REAL(sp), DIMENSION (:,:)    , POINTER ::   pt2d
-   END TYPE PTR_2D_sp
-   TYPE, PUBLIC ::   PTR_3D_sp   !: array of 3D pointers (also used in lib_mpp)
-      REAL(sp), DIMENSION (:,:,:)  , POINTER ::   pt3d
-   END TYPE PTR_3D_sp
-   TYPE, PUBLIC ::   PTR_4D_sp   !: array of 4D pointers (also used in lib_mpp)
-      REAL(sp), DIMENSION (:,:,:,:), POINTER ::   pt4d
-   END TYPE PTR_4D_sp
-
-
+   INTERFACE lbc_nfd_nogather   ! called by mpp_nfd
+      MODULE PROCEDURE   lbc_nfd_nogather_sp, lbc_nfd_nogather_dp
+   END INTERFACE
+   
+   PUBLIC   mpp_nfd            ! mpi north fold conditions
    PUBLIC   lbc_nfd            ! north fold conditions
    PUBLIC   lbc_nfd_nogather   ! north fold conditions (no allgather case)
@@ -82,5 +58,7 @@
 
    !!----------------------------------------------------------------------
-   !!                   ***  routine lbc_nfd_(2,3,4)d  ***
+   !!                   ***  routine lbc_nfd_[sd]p  ***
+   !!               ***  routine lbc_nfd_nogather_[sd]p  ***
+   !!                   ***  routine lbc_nfd_ext_[sd]p  ***
    !!----------------------------------------------------------------------
    !!
@@ -95,191 +73,47 @@
    !                       !==  SINGLE PRECISION VERSIONS
    !
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define SINGLE_PRECISION
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_2d_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_2d_ptr_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  2D array with extra haloes  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_2d_ext_sp
-#     include "lbc_nfd_ext_generic.h90"
-#     undef ROUTINE_NFD
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_NFD           lbc_nfd_3d_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_3d_ptr_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_NFD           lbc_nfd_4d_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_4d_ptr_sp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_4d
-   !
-   !  lbc_nfd_nogather routines
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_nogather_2d_sp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_nogather_2d_ptr_sp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_NFD           lbc_nfd_nogather_3d_sp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_nogather_3d_ptr_sp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_NFD           lbc_nfd_nogather_4d_sp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-!#     define MULTI
-!#     define ROUTINE_NFD           lbc_nfd_nogather_4d_ptr
-!#     include "lbc_nfd_nogather_generic.h90"
-!#     undef ROUTINE_NFD
-!#     undef MULTI
-#  undef DIM_4d
-#  undef SINGLE_PRECISION
-
-   !!----------------------------------------------------------------------
+#define PRECISION sp
+#  include "lbc_nfd_generic.h90"
+#  include "lbc_nfd_nogather_generic.h90"
+#  include "lbc_nfd_ext_generic.h90"
+#undef PRECISION
    !
    !                       !==  DOUBLE PRECISION VERSIONS
    !
+#define PRECISION dp
+#  include "lbc_nfd_generic.h90"
+#  include "lbc_nfd_nogather_generic.h90"
+#  include "lbc_nfd_ext_generic.h90"
+#undef PRECISION
+
+   !!======================================================================
    !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_2d_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_2d_ptr_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  2D array with extra haloes  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_2d_ext_dp
-#     include "lbc_nfd_ext_generic.h90"
-#     undef ROUTINE_NFD
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_NFD           lbc_nfd_3d_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_3d_ptr_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_NFD           lbc_nfd_4d_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_4d_ptr_dp
-#     include "lbc_nfd_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_4d
-   !
-   !  lbc_nfd_nogather routines
-   !
-   !                       !==  2D array and array of 2D pointer  ==!
-   !
-#  define DIM_2d
-#     define ROUTINE_NFD           lbc_nfd_nogather_2d_dp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_nogather_2d_ptr_dp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_2d
-   !
-   !                       !==  3D array and array of 3D pointer  ==!
-   !
-#  define DIM_3d
-#     define ROUTINE_NFD           lbc_nfd_nogather_3d_dp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     define MULTI
-#     define ROUTINE_NFD           lbc_nfd_nogather_3d_ptr_dp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-#     undef MULTI
-#  undef DIM_3d
-   !
-   !                       !==  4D array and array of 4D pointer  ==!
-   !
-#  define DIM_4d
-#     define ROUTINE_NFD           lbc_nfd_nogather_4d_dp
-#     include "lbc_nfd_nogather_generic.h90"
-#     undef ROUTINE_NFD
-!#     define MULTI
-!#     define ROUTINE_NFD           lbc_nfd_nogather_4d_ptr
-!#     include "lbc_nfd_nogather_generic.h90"
-!#     undef ROUTINE_NFD
-!#     undef MULTI
-#  undef DIM_4d
-
    !!----------------------------------------------------------------------
-
-
+   !!                   ***  routine mpp_nfd_[sd]p  ***
+   !!
+   !!   * Argument : dummy argument use in mpp_nfd_... routines
+   !!                ptab      :   pointer of arrays on which the boundary condition is applied
+   !!                cd_nat    :   nature of array grid-points
+   !!                psgn      :   sign used across the north fold boundary
+   !!                kfld      :   optional, number of pt3d arrays
+   !!                kfillmode :   optional, method to be use to fill the halos (see jpfill* variables)
+   !!                pfillval  :   optional, background value (used with jpfillcopy)
+   !!----------------------------------------------------------------------
+   !!
+   !!   ----   SINGLE PRECISION VERSIONS
+   !!
+#define PRECISION sp
+#  define MPI_TYPE MPI_REAL
+#  include "mpp_nfd_generic.h90"
+#  undef MPI_TYPE
+#undef PRECISION
+   !!
+   !!   ----   DOUBLE PRECISION VERSIONS
+   !!
+#define PRECISION dp
+#  define MPI_TYPE MPI_DOUBLE_PRECISION
+#  include "mpp_nfd_generic.h90"
+#  undef MPI_TYPE
+#undef PRECISION
 
    !!======================================================================
