Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/AA_make
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/AA_make	(revision 5878)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/AA_make	(revision 5879)
@@ -14,4 +14,7 @@
 	$(M_K) ORCA2LIM2xLMD9695-L39
 
+PALEOIPSLCM5A2-VLR :    
+	$(M_K) ORCA2LIM2xLMD9695-L39xPALEO
+
 IPSLCM5A2-LR :
 	$(M_K) ORCA2LIM2xLMD144142-L39
@@ -19,4 +22,9 @@
 ORCA2LIM2xLMD9695-L39 : libioipsl oasis3-mct xios liborchidee orca2lim2 lmdz96x95x39 verif
 	echo "ORCA2LIM2xLMD9695-L39" >.resol
+	echo "RESOL_ATM_3D=96x95x39" >>.resol
+	echo "$(LIB_MPI)" >.libmpi
+
+ORCA2LIM2xLMD9695-L39xPALEO : libioipsl oasis3-mct xios liborchidee paleorca2lim2 paleolmdz96x95x39 verif
+	echo "ORCA2LIM2xLMD9695-L39xPALEO" >.resol
 	echo "RESOL_ATM_3D=96x95x39" >>.resol
 	echo "$(LIB_MPI)" >.libmpi
@@ -39,4 +47,7 @@
 	$(M_K) lmdz RESOL_LMDZ=96x95x39
 
+paleolmdz96x95x39:
+	$(M_K) paleolmdz RESOL_LMDZ=96x95x39
+
 lmdz144x142x39:
 	$(M_K) lmdz RESOL_LMDZ=144x142x39
@@ -46,9 +57,16 @@
 	(cd ../../modeles/LMDZ ; ./makelmdz_fcm -d $(RESOL_LMDZ) -mem -cosp false -v true -parallel mpi_omp -io xios -c OMCT -job 8 -arch $(FCM_ARCH) gcm  ; mv bin/gcm_$(RESOL_LMDZ)_phylmd_para_mem_orch_couple.e ../../bin/gcm.e ; )
 
+paleolmdz: ../../modeles/LMDZ
+	(cd ../../modeles/LMDZ; ./makelmdz_fcm -d $(RESOL_LMDZ) -arch $(FCM_ARCH) -j 8 ce0l ; cp bin/ce0l_$(RESOL_LMDZ)_phylmd_seq.e ../../bin/create_etat0_limit.e ; )
+	(cd ../../modeles/LMDZ ; cp ${MYSRC_DIR}/SOURCES/LMDZ/PALEO/fonte_neige_mod.F90 libf/phylmd/. ; cp ${MYSRC_DIR}/SOURCES/LMDZ/PALEO/hydrol.F90 libf/phylmd/. ; cp ${MYSRC_DIR}/SOURCES/LMDZ/PALEO/surf_landice_mod.F90 libf/phylmd/. ; ./makelmdz_fcm -d $(RESOL_LMDZ) -mem -cosp false -v true -parallel mpi_omp -io xios -c OMCT -job 8 -arch $(FCM_ARCH) gcm  ; mv bin/gcm_$(RESOL_LMDZ)_phylmd_para_mem_orch_couple.e ../../bin/gcm.e ; )
+
 xios: ../../modeles/XIOS
 	(cd ../../modeles/XIOS; ./make_xios --arch $(FCM_ARCH) --prod --use_oasis oasis3_mct --job 8 ; cp bin/xios_server.exe ../../bin/. ; )
 
 orca2lim2:  ../../modeles/NEMOGCM/CONFIG
-	(cd ../../modeles/NEMOGCM/CONFIG; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/arch-${FCM_ARCH}.fcm ../ARCH/. ; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/*.cfg ../TOOLS/COMPILE/. ; ./makenemo -m ${FCM_ARCH} -n ORCA2_LIM_PISCES -e "$(MYSRC_DIR)/SOURCES/NEMO" -j16 add_key "key_lim2_vp key_oasis3 key_diahth key_diaar5 key_xios2" del_key "key_nosignedzero " ; cp ORCA2_LIM_PISCES/BLD/bin/nemo.exe ../../../bin/opa ; )
+	(cd ../../modeles/NEMOGCM/CONFIG; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/arch-${FCM_ARCH}.fcm ../ARCH/. ; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/*.cfg ../TOOLS/COMPILE/. ; ./makenemo -m ${FCM_ARCH} -n ORCA2_LIM_PISCES -e "$(MYSRC_DIR)/SOURCES/NEMO/STANDARD" -j16 add_key "key_lim2_vp key_oasis3 key_diahth key_diaar5 key_xios2" del_key "key_nosignedzero " ; cp ORCA2_LIM_PISCES/BLD/bin/nemo.exe ../../../bin/opa ; )
+
+paleorca2lim2:  ../../modeles/NEMOGCM/CONFIG
+	(cd ../../modeles/NEMOGCM/CONFIG; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/arch-${FCM_ARCH}.fcm ../ARCH/. ; cp ../../../config/IPSLCM5A2/SOURCES/NEMO/PALEO/*.cfg ../TOOLS/COMPILE/. ; ./makenemo -m ${FCM_ARCH} -n ORCA2_LIM_PISCES -e "$(MYSRC_DIR)/SOURCES/NEMO/PALEO" -j16 add_key "key_lim2_vp key_oasis3 key_diahth key_diaar5 key_xios2" del_key "key_nosignedzero " ; cp ORCA2_LIM_PISCES/BLD/bin/nemo.exe ../../../bin/opa ; )
 
 verif: ../../bin
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lim2.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lim2.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lim2.card	(revision 5879)
@@ -0,0 +1,51 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+
+[InitialStateFiles]
+List=	()
+
+[BoundaryFiles]
+List=	()
+ListNonDel= ()
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=	(${MODIPSL}/modeles/NEMOGCM/CONFIG/SHARED/namelist_ice_lim2_ref, namelist_ice_ref), \
+        (${SUBMIT_DIR}/PARAM/field_def_nemo-lim2.xml, field_def_nemo-lim.xml), \
+        (${SUBMIT_DIR}/PARAM/file_def_nemo-lim2_paleo.xml, file_def_nemo-lim.xml), \
+        (${SUBMIT_DIR}/PARAM/namelist_lim2_${RESOL_OCE}_cfg, namelist_ice_cfg)
+
+[RestartFiles]
+List=	(${config_UserChoices_JobName}_${NEMO_END}_restart_ice.nc, restart_icemod.nc, restart_ice_in.nc)
+
+[OutputText]
+List=   (namelist_ice)
+
+[OutputFiles]
+List=   (${config_UserChoices_JobName}_1m_icemod.nc, ${R_OUT_ICE_O_M}/${PREFIX}_1M_icemod.nc, Post_1M_icemod ), \
+        (${config_UserChoices_JobName}_1d_icemod.nc, ${R_OUT_ICE_O_D}/${PREFIX}_1D_icemod.nc, NONE )
+
+[Post_1M_icemod]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_counter_bounds)
+TimeSeriesVars2D = (ice_pres, sic)
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=ON
+
+[Post_1D_icemod]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_counter_bounds)
+TimeSeriesVars2D = (iicethic, iicevelu, iicevelv, ileadfra)
+ChunckJob2D = 200Y
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lmdz.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lmdz.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/lmdz.card	(revision 5879)
@@ -0,0 +1,217 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+# Physics package to use :
+# LMDZ_Physics=AP for standard/old physics(defalut), can be used with LMDZ4_AR5 or LMDZ5/trunk sources
+# LMDZ_Physics=NPv3.2 for new physics, to be used with LMDZ5/trunk revision 1554 or later
+#LMDZ_Physics=AP
+LMDZ_Physics=AP
+
+# Set ConfType to choose parameters for aerosols, solar and green house gazes.
+# The parameter file PARAM/config.def_$ConfType will be used.
+# ConfType=preind/actuel/annuel
+ConfType=preind
+
+# Set pmagic in config.def
+pmagic=0.0
+
+# manage radiative aerosol effect and ozone
+flag_aerosol=6
+ok_ade=y
+ok_aie=y
+aerosol_couple=n
+read_climoz=2
+ok_cdnc=y
+
+# ByPass_hgardfou_teta=y : modify teta_ parameters for following CumulPeriod only
+ByPass_hgardfou_teta=n
+
+# ByPass_hgardfou_mats=y : set parameter purmats=y for following CumulPeriod only
+ByPass_hgardfou_mats=n
+
+# Set OutLevel to choose the level of output for LMDZ
+# OutLevel=low/medium/high
+OutLevel=low
+
+# Set COSP activation and Outputs frequency (monthly, daily, HF) = y/n
+LMDZ_COSP_OK=n
+LMDZ_COSP_monthly=n
+LMDZ_COSP_daily=n
+LMDZ_COSP_hf=n
+
+# Set NMC Outputs frequency (monthly, daily, HF) = y/n
+LMDZ_NMC_monthly=n
+LMDZ_NMC_daily=n
+LMDZ_NMC_hf=n
+
+[InitialStateFiles]
+List=  (${R_IN}/ATM/IPSLCM6/${config_UserChoices_ORCA_version}xLMD${RESOL_ATM_XY}/start_${config_UserChoices_ORCA_version}xLMD${RESOL_ATM_3D}.nc   , start.nc       ), \
+       (${R_IN}/ATM/IPSLCM6/${config_UserChoices_ORCA_version}xLMD${RESOL_ATM_XY}/startphy_${config_UserChoices_ORCA_version}xLMD${RESOL_ATM_3D}.nc, startphy.nc    )
+
+[BoundaryFiles]
+List=   ()
+# With AR5 aerosols (including ASSO4M(=SO4), CSSO4M, AIBCM, ASBCM, AIPOMM, ASPOMM, ASSSM, CSSSM, SSSSM, CIDUSTM)
+# With AR5 ozone(tropo + strato from LMDZOR-INCA-REPROBUS simulations)
+ListNonDel= (${R_IN}/ATM/${RESOL_ATM}/AR5/HISTORIQUE/aerosols_11YearsClim_1855_v5.nc, aerosols.nat.nc),\
+            (${R_IN}/ATM/${RESOL_ATM}/AR5/HISTORIQUE/climoz_LMDZ_1855_v2.nc, climoz_LMDZ.nc)
+
+[SmoothFiles]
+List=   ()
+
+[ParametersFiles]
+List=   (${SUBMIT_DIR}/PARAM/physiq.def_${LMDZ_Physics}, physiq.def),       \
+        (${SUBMIT_DIR}/PARAM/gcm.def_${RESOL_ATM_XY},    gcm.def),          \
+        (${SUBMIT_DIR}/PARAM/vert.def_L${RESOL_ATM_Z},   vert.def),         \
+        (${MODIPSL}/modeles/LMDZ/DefLists/cosp_input_nl.txt,   .),          \
+        (${MODIPSL}/modeles/LMDZ/DefLists/cosp_output_nl.txt,  .),          \
+        (${SUBMIT_DIR}/PARAM/config.def_${ConfType},  config.def),          \
+        (${SUBMIT_DIR}/PARAM/guide.def, .),                                 \
+        (${SUBMIT_DIR}/PARAM/run.def, .),                                   \
+        (${SUBMIT_DIR}/PARAM/traceur.def, .),                               \
+        (${SUBMIT_DIR}/PARAM/iodef.xml, . ),                                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/context_lmdz.xml, . ),            \
+        (${MODIPSL}/modeles/LMDZ/DefLists/field_def_lmdz.xml, . ),          \
+        (${SUBMIT_DIR}/PARAM/file_def_histmth_lmdz_paleo.xml, file_def_histmth_lmdz.xml ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histmthCOSP_lmdz.xml, .),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histmthNMC_lmdz.xml, . ),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histday_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histdayCOSP_lmdz.xml, .),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histdayNMC_lmdz.xml, . ),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhf_lmdz.xml, . ),                 \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhfCOSP_lmdz.xml, .),              \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhfNMC_lmdz.xml, . ),              \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histstn_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histins_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histLES_lmdz.xml, . )
+
+
+
+[RestartFiles]
+List=   (restart.nc, restart.nc, start.nc), \
+        (restartphy.nc, restartphy.nc,  startphy.nc)
+
+[OutputText]
+List=   (physiq.def, gcm.def, run.def, traceur.def, guide.def, config.def, vert.def, used_run.def, iodef.xml, context_lmdz.xml, field_def_lmdz.xml, file_def_*lmdz.xml, debug.01, lmdz.prt, out_lmdz.x.err, out_lmdz.x.out)
+
+[OutputFiles]
+List=   (histmth.nc,       ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmth.nc,       Post_1M_histmth),       \
+        (histmthCOSP.nc,   ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmthCOSP.nc,   NONE),                  \
+        (histmthNMC.nc,    ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmthNMC.nc,    NONE),                  \
+        (paramLMDZ_phy.nc, ${R_OUT_ATM_O_M}/${PREFIX}_1M_paramLMDZ_phy.nc, NONE),                  \
+        (histday.nc,       ${R_OUT_ATM_O_D}/${PREFIX}_1D_histday.nc,       NONE),                  \
+        (histdayCOSP.nc,   ${R_OUT_ATM_O_D}/${PREFIX}_1D_histdayCOSP.nc,   NONE),                  \
+        (histdayNMC.nc,    ${R_OUT_ATM_O_D}/${PREFIX}_1D_histdayNMC.nc,    NONE),                  \
+        (histhf.nc,        ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhf.nc,        NONE),                  \
+        (histhfCOSP.nc,    ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhfCOSP.nc,    NONE),                  \
+        (histhfNMC.nc,     ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhfNMC.nc,     NONE),                  \
+        (histhf3h.nc,      ${R_OUT_ATM_O_H}/${PREFIX}_3H_histhf3h.nc,      NONE),                  \
+        (histhf3hm.nc,     ${R_OUT_ATM_O_H}/${PREFIX}_3H_histhf3hm.nc,     NONE)
+
+[Post_1M_histmth]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds, aire)
+TimeSeriesVars2D = (bils, cldh, cldl, cldm, cldq, cldt, evap, flat, iwp, lwp, LWdnSFC, LWdnSFCclr, LWupSFCclr, LWdn200, LWdn200clr, LWup200, LWup200clr, precip, prw, pluc, psol, q2m, rh2m, sens, sicf, slp, snow, soll0, soll, sols0, sols, SWdnSFC, SWupSFC, SWup200, SWdnTOA, SWupTOA, SWdn200, SWdnSFCclr, SWupSFCclr, SWupTOAclr, t2m, t2m_max, t2m_min, taux, taux_ter, taux_sic, taux_lic, taux_oce, tauy, tauy_ter, tauy_sic, tauy_lic, tauy_oce, lat_ter, lat_sic, lat_lic, lat_oce, nettop, pbase, ptop, topl0, topl, tops0, tops, topswad, topswai, tsol, tsol_ter, tsol_lic, tsol_oce, tsol_sic , u10m, u500, v10m, v500, w500, pourc_ter, pourc_oce, pourc_sic, pourc_lic, wind10m, swtoacf_zero, swsrfcf_zero)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (upwd, lwcon, iwcon, lcc3dcon, lcc3dstra, temp, theta, ovap, ovapinit, geop, vitu, vitv, vitw, pres, rneb, rnebcon, rhum, mc, mcd)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_histmthCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, pressure2, height, sza, time_counter, time_centered, time_centered_bounds, aire)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso, tclisccp, albisccp, ctpisccp)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, clisccp2_c01, clisccp2_c02, clisccp2_c03, clisccp2_c04, clisccp2_c05, clisccp2_c06, clisccp2_c07, parasol_refl)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1M_histmthNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, tro3, zg, hus, hur, ua, va, wap)
+ChunckJob3D = NONE
+Seasonal=ON
+
+[Post_1M_paramLMDZ_phy]
+Patches=()
+GatherWithInternal = (lon, lat, time_counter, time_counter_bnds)
+TimeSeriesVars2D =(R_ecc,  R_peri, R_incl, solaire, co2_ppm, CH4_ppb, N2O_ppb, CFC11_ppt, CFC12_ppt)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1D_histday]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (bils, cldh, cldl, cldm, cldq, cldt, evap, flat, precip, pluc, plul, prw, psol, q2m, sens, sicf, slp, soll, sols, snow, SWdnSFC, t2m, t2m_max, t2m_min, topl, tops, tsol, u10m, v10m, wind10m, wind10max)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (lwcon, iwcon, mc, rhum, rneb, temp, theta, ovap, geop, vitu, vitv, vitw, pres, paprs)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_histdayCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, pressure2, height, sza, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso, tclisccp, albisccp, ctpisccp)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, clisccp2_c01, clisccp2_c02, clisccp2_c03, clisccp2_c04, clisccp2_c05, clisccp2_c06, clisccp2_c07, parasol_refl)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_histdayNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, zg, hus, hur, ua, va, wap)
+ChunckJob3D = 10Y
+Seasonal=OFF
+
+[Post_HF_histhf]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cldt, psol, q2m, slp, precip, pluc, plul, t2m, tsol, u10m, v10m)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (temp, theta, ovap, vitu, vitv)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_HF_histhfCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, height, sza, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, parasol_refl, cfad_lidarsr532_c01, cfad_lidarsr532_c02, cfad_lidarsr532_c03, cfad_lidarsr532_c04, cfad_lidarsr532_c05, cfad_lidarsr532_c06, cfad_lidarsr532_c07, cfad_lidarsr532_c08, cfad_lidarsr532_c09, cfad_lidarsr532_c10, cfad_lidarsr532_c11, cfad_lidarsr532_c12, cfad_lidarsr532_c13, cfad_lidarsr532_c14, cfad_lidarsr532_c15)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_HF_histhfNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, zg, hus, hur, ua, va, wap)
+ChunckJob3D = 10Y
+Seasonal=OFF
+
+[Post_3H_histhf3hm]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (flat, precip, pluc, snow, topl, topl0, SWupTOA, SWupTOAclr, SWdnTOA, SWupSFC, SWupSFCclr, SWdnSFC, SWdnSFCclr, LWupSFC, LWupSFCclr, LWdnSFC, LWdnSFCclr, bils, bils_tke, bils_diss, bils_ec, bils_kinetic, bils_enthalp, bils_latent, sens, cldt, zmax_th)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_3H_histhf3h]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (phis, tsol, t2m, q2m, ustar, u10m, v10m, psol)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/oasis.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/oasis.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/oasis.card	(revision 5879)
@@ -0,0 +1,136 @@
+[Compatibility] 
+libIGCM=1.0 
+ 	 
+[UserChoices]
+OutputMode=n
+FreqCoupling=86400
+Lucia=n
+
+[InitialStateFiles]
+List=	(${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/flxat.nc, flxat.nc), \
+        (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/sstoc.nc, sstoc.nc)
+
+[BoundaryFiles]
+List=	()
+ListNonDel= (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/grids_v3.nc, grids.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/masks_v3.nc, masks.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/areas_v3.nc, areas.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/rmp_torc_to_tlmd_MOSAIC_v3.nc, rmp_torc_to_tlmd_MOSAIC.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/rmp_tlmd_to_torc_MOSAIC_v3.nc, rmp_tlmd_to_torc_MOSAIC.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/rmp_tlmd_to_torc_MOSAIC_calvin_v3.nc, rmp_tlmd_to_torc_MOSAIC_calvin.nc),\
+	    (${R_IN}/CPL/IPSLCM6/${config_UserChoices_ORCA_version}x${RESOL_ATM}/rmp_tlmd_to_torc_MOSAIC_rivflu_v3.nc, rmp_tlmd_to_torc_MOSAIC_rivflu.nc)
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=	(${SUBMIT_DIR}/PARAM/namcouple_${RESOL_CPL}, namcouple)
+
+[RestartFiles]
+List=	(flxat.nc, flxat.nc, flxat.nc),\
+	(sstoc.nc, sstoc.nc, sstoc.nc)
+
+[OutputText]
+List=   (namcouple, nout.000000, lucia, oasis_balance.eps)
+
+[OutputFiles]
+List=   (SISUTESW_LMDZ_01.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_SISUTESW.nc,    NONE),\
+    (SIICECOV_LMDZ_02.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_SIICECOV.nc,    NONE),\
+    (SIICTEMW_LMDZ_03.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_SIICTEMW.nc,    NONE),\
+    (SIICEALW_LMDZ_04.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_SIICEALW.nc,    NONE),\
+    (CURRENTX_LMDZ_05.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_CURRENTX.nc,    NONE),\
+    (CURRENTY_LMDZ_06.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_CURRENTY.nc,    NONE),\
+    (CURRENTZ_LMDZ_07.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_CURRENTZ.nc,    NONE),\
+    (COTAUXXU_LMDZ_08.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUXXU.nc,    NONE),\
+    (COTAUYYU_LMDZ_09.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUYYU.nc,    NONE),\
+    (COTAUZZU_LMDZ_10.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUZZU.nc,    NONE),\
+    (COTAUXXV_LMDZ_11.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUXXV.nc,    NONE),\
+    (COTAUYYV_LMDZ_12.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUYYV.nc,    NONE),\
+    (COTAUZZV_LMDZ_13.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTAUZZV.nc,    NONE),\
+    (COWINDSP_LMDZ_14.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COWINDSP.nc,    NONE),\
+    (COTOTRAI_LMDZ_15.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTOTRAI.nc,    NONE),\
+    (COTOTSNO_LMDZ_16.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTOTSNO.nc,    NONE),\
+    (COTOTEVA_LMDZ_17.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COTOTEVA.nc,    NONE),\
+    (COICEVAP_LMDZ_18.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COICEVAP.nc,    NONE),\
+    (COQSRMIX_LMDZ_19.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COQSRMIX.nc,    NONE),\
+    (COQNSMIX_LMDZ_20.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COQNSMIX.nc,    NONE),\
+    (COSHFICE_LMDZ_21.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COSHFICE.nc,    NONE),\
+    (CONSFICE_LMDZ_22.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_CONSFICE.nc,    NONE),\
+    (CODFLXDT_LMDZ_23.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_CODFLXDT.nc,    NONE),\
+    (COCALVIN_LMDZ_24.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COCALVIN.nc,    NONE),\
+    (COLIQRUN_LMDZ_25.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_COLIQRUN.nc,    NONE),\
+    (O_SSTSST_oceanx_01.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_SSTSST.nc,    NONE),\
+    (OIceFrc_oceanx_02.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OIceFrac.nc,    NONE),\
+    (O_TepIce_oceanx_03.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_TepIce.nc,    NONE),\
+    (O_AlbIce_oceanx_04.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_AlbIce.nc,    NONE),\
+    (O_OCurx1_oceanx_05.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OCurx1.nc,    NONE),\
+    (O_OCury1_oceanx_06.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OCury1.nc,    NONE),\
+    (O_OCurz1_oceanx_07.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OCurz1.nc,    NONE),\
+    (O_OTaux1_oceanx_08.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTaux1.nc,    NONE),\
+    (O_OTauy1_oceanx_09.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTauy1.nc,    NONE),\
+    (O_OTauz1_oceanx_10.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTauz1.nc,    NONE),\
+    (O_OTaux2_oceanx_11.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTaux2.nc,    NONE),\
+    (O_OTauy2_oceanx_12.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTauy2.nc,    NONE),\
+    (O_OTauz2_oceanx_13.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_OTauz2.nc,    NONE),\
+    (O_Wind10_oceanx_14.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_Wind10.nc,    NONE),\
+    (OTotRain_oceanx_15.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OTotRain.nc,    NONE),\
+    (OTotSnow_oceanx_16.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OTotSnow.nc,    NONE),\
+    (OTotEvap_oceanx_17.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OTotEvap.nc,    NONE),\
+    (OIceEvap_oceanx_18.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OIceEvap.nc,    NONE),\
+    (O_QsrMix_oceanx_19.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_QsrMix.nc,    NONE),\
+    (O_QnsMix_oceanx_20.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_QnsMix.nc,    NONE),\
+    (O_QsrIce_oceanx_21.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_QsrIce.nc,    NONE),\
+    (O_QnsIce_oceanx_22.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_QnsIce.nc,    NONE),\
+    (O_dQnsdT_oceanx_23.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_dQnsdT.nc,    NONE),\
+    (OCalving_oceanx_24.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_OCalving.nc,    NONE),\
+    (O_Runoff_oceanx_25.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_O_Runoff.nc,    NONE),\
+    (TEMPO_1D_cpl_atm.nc,    ${R_OUT_CPL_O_D}/${PREFIX}_1D_cpl_atm.nc , NONE), \
+    (TEMPO_1D_cpl_oce.nc,    ${R_OUT_CPL_O_D}/${PREFIX}_1D_cpl_oce.nc , NONE), \
+    (TEMPO_1M_cpl_atm.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_1M_cpl_atm.nc , NONE), \
+    (TEMPO_1M_cpl_oce.nc,    ${R_OUT_CPL_O_M}/${PREFIX}_1M_cpl_oce.nc , NONE)
+
+[Post_ncks_cdo]
+Patches = (Patch_20140801_ncks_cdo)
+GatherWithInternal = ()
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1D_cpl_atm]
+Patches = (Patch_20091119_put_out)
+GatherWithInternal = ()
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1D_cpl_oce]
+Patches = (Patch_20091119_put_out)
+GatherWithInternal = ()
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1M_cpl_atm]
+Patches = (Patch_20091119_put_out)
+GatherWithInternal = (lon, lat, time)
+TimeSeriesVars2D = (SIICEALW, SIICECOV, SISUTESW, COCALVIN, COICEVAP, COLIQRUN, CONSFICE, COQNSMIX, COQSRMIX, COSHFICE, COTOTEVA, COTOTRAI, COTOTSNO)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1M_cpl_oce]
+Patches = (Patch_20091119_put_out)
+GatherWithInternal = (lon, lat, time)
+TimeSeriesVars2D = (OCalving, OIceEvap, OIceFrac, OTotEvap, OTotRain, OTotSnow, O_AlbIce, O_QnsIce, O_QnsMix, O_QsrIce, O_QsrMix, O_Runoff)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/opa9.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/opa9.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/opa9.card	(revision 5879)
@@ -0,0 +1,213 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+ORCA_version=${config_UserChoices_ORCA_version:-ORCA2.3}
+mesh_mask= y
+
+[InitialStateFiles]
+List=	()
+
+[BoundaryFiles]
+List=	()
+ListNonDel= (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/coordinates.nc                          , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/bathy_meter.nc                          , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/ahmcoef.nc                              , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/runoffs_ORCA2_depths.nc                 , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_1m_potential_temperature_nomask.nc , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/geothermal_heating.nc                   , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_1m_salinity_nomask.nc              , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/sss_data.nc                             , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/sst_data.nc                             , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/chlorophyll_surface.nc                  , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/K1rowdrg.nc                             , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/M2rowdrg.nc                             , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/mask_itf.nc                             , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/sali_ref_clim_monthly.nc                , .), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/subbasins.nc                            , .)
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=   (${MODIPSL}/modeles/NEMOGCM/CONFIG/SHARED/namelist_ref , namelist_ref        ), \
+        (${SUBMIT_DIR}/PARAM/field_def_nemo-opa.xml            , field_def_nemo-opa.xml  ), \
+        (${SUBMIT_DIR}/PARAM/domain_def_nemo.xml               , domain_def_nemo.xml ), \
+        (${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg_paleo   , namelist_cfg        ), \
+        (${SUBMIT_DIR}/PARAM/context_nemo.xml                  , context_nemo.xml    ), \
+        (${SUBMIT_DIR}/PARAM/file_def_nemo-opa_paleo.xml       , file_def_nemo-opa.xml   )
+
+   
+
+[RestartFiles]
+List=	(${config_UserChoices_JobName}_${NEMO_END}_restart.nc,  restart.nc, restartopa.nc)
+
+[OutputText]
+List=   (ocean.output, solver.stat, namelist, output.namelist.*, context_nemo.xml, field_def_nemo.xml, domain_def_nemo.xml, out_opa.xx.out, out_opa.xx.err)
+
+[OutputFiles]
+List=   (${config_UserChoices_JobName}_1y_scalar.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_scalar.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1y_grid_T.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_grid_T.nc    , Post_1Y_grid_T),\
+        (${config_UserChoices_JobName}_1y_grid_U.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_grid_U.nc    , Post_1Y_grid_U),\
+        (${config_UserChoices_JobName}_1y_grid_V.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_grid_V.nc    , Post_1Y_grid_V),\
+        (${config_UserChoices_JobName}_1y_grid_W.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_grid_W.nc    , Post_1Y_grid_W),\
+        (${config_UserChoices_JobName}_1y_diaptr.nc , ${R_OUT_OCE_O_Y}/${PREFIX}_1Y_diaptr.nc    , Post_1Y_diaptr),\
+        (${config_UserChoices_JobName}_1m_scalar.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_scalar.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1m_grid_T.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_grid_T.nc    , Post_1M_grid_T),\
+        (${config_UserChoices_JobName}_1m_grid_U.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_grid_U.nc    , Post_1M_grid_U),\
+        (${config_UserChoices_JobName}_1m_grid_V.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_grid_V.nc    , Post_1M_grid_V),\
+        (${config_UserChoices_JobName}_1m_grid_W.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_grid_W.nc    , Post_1M_grid_W),\
+        (${config_UserChoices_JobName}_1m_diaptr.nc , ${R_OUT_OCE_O_M}/${PREFIX}_1M_diaptr.nc    , Post_1M_diaptr),\
+        (${config_UserChoices_JobName}_1d_grid_T.nc , ${R_OUT_OCE_O_D}/${PREFIX}_1D_grid_T.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1d_grid_U.nc , ${R_OUT_OCE_O_D}/${PREFIX}_1D_grid_U.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1d_grid_W.nc , ${R_OUT_OCE_O_D}/${PREFIX}_1D_grid_W.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1d_SBC.nc    , ${R_OUT_OCE_O_D}/${PREFIX}_1D_SBC.nc       , NONE          ),\
+        (${config_UserChoices_JobName}_1d_diaptr.nc , ${R_OUT_OCE_O_D}/${PREFIX}_1D_diaptr.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1d_scalar.nc , ${R_OUT_OCE_O_D}/${PREFIX}_1D_scalar.nc    , NONE          ),\
+        (${config_UserChoices_JobName}_1d_SBC_scalar, ${R_OUT_OCE_O_D}/${PREFIX}_1D_SBC_scalar.nc, NONE          ),\
+        (mesh_mask.nc    , ${R_OUT_OCE_O}/${config_UserChoices_JobName}_mesh_mask.nc                       , NONE),\
+        (runoffs.nc      , ${R_OUT_OCE_O}/${config_UserChoices_JobName}_runoffs.nc                         , NONE),\
+	    (damping.coeff.nc, ${R_OUT_OCE_O_D}/${PREFIX}_damping.coeff.nc                                     , NONE),\
+        (output.abort.nc , ${R_OUT_OCE_D}/${PREFIX}_output.abort.nc                                        , NONE),\
+        (output.init.nc  , ${R_OUT_OCE_O_I}/${config_UserChoices_JobName}_${PeriodDateBegin}_output.init.nc, NONE)
+
+# Monthly analysis
+
+[Post_1M_scalar]
+Patches = ()
+GatherWithInternal = (time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1M_grid_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, deptht, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (zos, tos, sos, omlmax, mldkz5, mldr10_1, nshfls, rsntds, friver, hc300, wfo, siconc)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (e3t, thetao, so, rhopoto)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_grid_U]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthu, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (tauuo, sozohetr, sozohetr_eiv, sozohetr_diff, sozosatr)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (e3u, uo, uo_eiv, uocetr_eff)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_grid_V]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthv, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (tauvo, somehetr, somehetr_eiv, somehetr_diff, somesatr)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (e3v, vo, vo_eiv, vocetr_eff)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_grid_W]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthw, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ( )
+ChunckJob2D = NONE
+TimeSeriesVars3D = (e3w, wo, wo_eiv, wocetr_eff)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_diaptr]
+Patches = ()
+GatherWithInternal = (nav_lat, deptht, depthw, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (zomsfglo, zomsfatl, zomsfpac, zomsfind, zomsfipc, zotemglo, zotematl, zotempac, zotemind, zotemipc, zosalglo, zosalatl, zosalpac, zosalind, zosalipc, zosrfglo, zosrfatl, zosrfpac, zosrfind, zosrfipc, sophtadv, sophtldf, sopstadv, sopstldf)
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=ON
+
+# Daily analysis
+
+[Post_1D_grid_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, deptht, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (tos, tosstd, sos, zos, zosstd, sstdcy, mldr10_1, mldr10_1dcy, mldkz5)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_grid_U]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthu, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = 100Y
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_grid_V]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthv, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = 200Y
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
+
+## Yearly analysis
+
+[Post_1Y_scalar]
+Patches = ()
+GatherWithInternal = (time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1Y_grid_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, deptht, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ( )
+ChunckJob2D = NONE
+TimeSeriesVars3D = (thetao, so, rhopoto)
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1Y_grid_U]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthu, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (sozohetr, sozosatr)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (uocetr_eff)
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1Y_grid_V]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthv, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (somehetr, somesatr)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (vocetr_eff)
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1Y_grid_W]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, depthw, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ( )
+ChunckJob2D = NONE
+TimeSeriesVars3D = ( )
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1Y_diaptr]
+Patches = ()
+GatherWithInternal = (nav_lat, deptht, depthw, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (zomsfglo, zomsfatl, zotemglo, zotematl, zotempac, zosalglo, zosalatl, zosalpac, zosrfglo, zosrfatl, zosrfpac)
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/orchidee.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/orchidee.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/orchidee.card	(revision 5879)
@@ -0,0 +1,59 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+# The variable DefSuffix gives the suffix of the orchidee.def file to be used.
+# By default the file orchidee.def_Choi will be selected.
+# Sef DefSuffix=Choi (default) to activate default 2-layer Choisnel hydrology
+# Set DefSuffix=CWRR to activate 11-layer CWRR hydrology
+DefSuffix=Choi
+
+VEGET_UPDATE=0Y
+
+[InitialStateFiles]
+List=	(${R_IN}/SRF/soils_param.nc,        . ), \
+	    (${R_IN}/SRF/routing.nc,            . ), \
+	    (${R_IN}/SRF/PFTmap_1850to2005_AR5_LUHa.rc2/PFTmap_IPCC_1850.nc, PFTmap.nc), \
+        (${R_IN}/SRF/cartepente2d_15min.nc, .)
+
+[BoundaryFiles]
+List= ()
+ListNonDel= ()
+
+[SmoothFiles]
+List= ()
+
+[ParametersFiles]
+List=	(${SUBMIT_DIR}/PARAM/orchidee.def_${DefSuffix}             , orchidee.def), \
+        (${SUBMIT_DIR}/PARAM/file_def_orchidee_paleo.xml           , file_def_orchidee.xml), \
+	    (${MODIPSL}/modeles/ORCHIDEE/src_xml/context_orchidee.xml  , .), \
+	    (${MODIPSL}/modeles/ORCHIDEE/src_xml/field_def_orchidee.xml, .) 
+
+[RestartFiles]
+List=	(sechiba_rest_out.nc, sechiba_rest.nc, sechiba_rest_in.nc)
+
+[OutputText]
+List=   (out_orchidee, orchidee.def, used_orchidee.def, iodef.xml, context_orchidee.xml, field_def_orchidee.xml, file_def_orchidee.xml, river_desc.nc)
+
+[OutputFiles]
+List=   (sechiba_history.nc,   ${R_OUT_SRF_O_M}/${PREFIX}_1M_sechiba_history.nc, Post_1M_sechiba_history), \
+        (sechiba_out_2.nc  ,   ${R_OUT_SRF_O_H}/${PREFIX}_HF_sechiba_out_2.nc  , NONE)
+
+[Post_1M_sechiba_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, Contfrac, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (nobiofrac, evap, fluxlat, fluxsens, netrad, qair, rain, runoff, snow, snownobio, snowf, subli, tair, temp_sol, tsol_max, tsol_min, drainage, mrso, mrros, mrro, prveg, tran, riverflow, coastalflow)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (lai, maxvegetfrac, vegetfrac)
+ChunckJob3D = NONE
+Seasonal = ON
+
+[Post_HF_sechiba_out_2]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, Contfrac, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (mrsos, mrro)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (ptn)
+ChunckJob3D = 10Y
+Seasonal = OFF
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/pisces.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/pisces.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/pisces.card	(revision 5879)
@@ -0,0 +1,108 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+DBIO_ENABLE=y
+
+[InitialStateFiles]
+List= ()
+
+[BoundaryFiles]
+List=	()
+
+ListNonDel= (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_DIC_nomask.nc     , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_Alkalini_nomask.nc, . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_O2_nomask.nc      , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_NO3_nomask.nc     , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_PO4_nomask.nc     , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_Si_nomask.nc      , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_DOC_nomask.nc     , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/data_Fer_nomask.nc     , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/dust.orca.nc           , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/bathy.orca_v1.nc       , bathy.orca.nc), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/river.orca.nc          , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/ndeposition.orca.nc    , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/par.orca.nc            , . ), \
+            (${R_IN}/OCE/IPSLCM6/${opa9_UserChoices_ORCA_version}/solubility.orca.nc    , . )
+
+[SmoothFiles]
+List=  ()
+
+[ParametersFiles]
+List=	(${MODIPSL}/modeles/NEMOGCM/CONFIG/SHARED/namelist_top_ref   , namelist_top_ref         ), \
+     	(${SUBMIT_DIR}/PARAM/namelist_top_${RESOL_OCE}_cfg     , namelist_top_cfg         ), \
+        (${MODIPSL}/modeles/NEMOGCM/CONFIG/SHARED/namelist_pisces_ref, namelist_pisces_ref      ), \
+        (${SUBMIT_DIR}/PARAM/namelist_pisces_${RESOL_OCE}_cfg  , namelist_pisces_cfg      ), \
+        (${SUBMIT_DIR}/PARAM/file_def_nemo-pisces_paleo.xml          , file_def_nemo-pisces.xml ), \
+        (${SUBMIT_DIR}/PARAM/field_def_nemo-pisces.xml         , field_def_nemo-pisces.xml)
+        
+
+[RestartFiles]
+List=	(${config_UserChoices_JobName}_${NEMO_END}_restart_trc.nc,  restart_trc.nc, restart_trc.nc)
+
+[OutputText]
+List=   (namelist_top_ref, namelist_cfg, namelist_pisces_ref, namelist_pisces_cfg)
+
+[OutputFiles]
+List=   (${config_UserChoices_JobName}_1y_ptrc_T.nc        , ${R_OUT_MBG_O_Y}/${PREFIX}_1Y_ptrc_T.nc    , Post_1Y_ptrc_T   ) , \
+        (${config_UserChoices_JobName}_1y_diad_T.nc        , ${R_OUT_MBG_O_Y}/${PREFIX}_1Y_diad_T.nc    , Post_1Y_diad_T   ) , \
+	(${config_UserChoices_JobName}_1m_PISCES_scalar.nc     , ${R_OUT_MBG_O_M}/${PREFIX}_1M_PISCES_scalar.nc , NONE         ) , \
+        (${config_UserChoices_JobName}_1m_ptrc_T.nc        , ${R_OUT_MBG_O_M}/${PREFIX}_1M_ptrc_T.nc    , Post_1M_ptrc_T   ) , \
+        (${config_UserChoices_JobName}_1m_diad_T.nc        , ${R_OUT_MBG_O_M}/${PREFIX}_1M_diad_T.nc    , Post_1M_diad_T   ) , \
+	(${config_UserChoices_JobName}_1d_PISCES_scalar.nc     , ${R_OUT_MBG_O_M}/${PREFIX}_1D_PISCES_scalar.nc , NONE)
+
+
+
+[Post_1D_PISCES_scalar]
+Patches = ()
+GatherWithInternal = (time_counter, time_instant, time_instant_bounds)
+TimeSeriesVars2D = (pno3tot, ppo4tot, psiltot, palktot, pfertot, tcflx, tcflxcum, tcexp, tintpp, tnfix, tdenit)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1M_PISCES_scalar]
+Patches = ()
+GatherWithInternal = (time_counter, time_instant, time_instant_bounds)
+TimeSeriesVars2D = (pno3tot, ppo4tot, psiltot, palktot, pfertot, tcflx, tcflxcum, tcexp, tintpp, tnfix, tdenit)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = 50Y
+Seasonal=OFF
+
+[Post_1M_ptrc_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (Alkalini, NCHL, DCHL, DIC, Fer, NO3, O2, PO4, Si)
+ChunckJob3D = 50Y
+Seasonal=ON
+
+[Post_1M_diad_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (Cflx, Dpco2, EPC100, INTPP)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (PAR, TPP)
+ChunckJob3D = 50Y
+Seasonal=ON
+
+[Post_1Y_ptrc_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = OFF
+TimeSeriesVars3D = (Alkalini, NCHL, DCHL, DIC, Fer, NO3, O2, PO4, Si )
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1Y_diad_T]
+Patches = ()
+GatherWithInternal = (nav_lon, nav_lat, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (Cflx, Dpco2, EPC100, Heup,  Nfix)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (PAR, TPP)
+ChunckJob3D = 50Y
+Seasonal=OFF
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/stomate.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/stomate.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/stomate.card	(revision 5879)
@@ -0,0 +1,46 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+
+[InitialStateFiles]
+List=   ()
+
+[BoundaryFiles]
+List=   ()
+ListNonDel= ()
+
+[SmoothFiles]
+List=   ()
+
+[ParametersFiles]
+List=   ()
+
+[RestartFiles]
+# List restart that have to be saved/restored each loop (file out, saved, and in) :
+List=   (stomate_rest_out.nc, stomate_rest.nc, stomate_rest_in.nc)
+
+[OutputText]
+List=   ()
+
+[OutputFiles]
+List=   (stomate_history.nc,      ${R_OUT_SBG_O_M}/${PREFIX}_1M_stomate_history.nc, NONE),\
+        (stomate_ipcc_history.nc, NONE                                            , NONE)
+
+[Post_1M_stomate_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (T2M_MONTH,CONTFRAC,RESOLUTION_X,RESOLUTION_Y,CONVFLUX,CFLUX_PROD10,CFLUX_PROD100,HARVEST_ABOVE)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (LAI,VEGET_MAX,NPP,GPP,HET_RESP,MAINT_RESP,GROWTH_RESP,AGE,HEIGHT,TOTAL_M,TOTAL_BM_LITTER,TOTAL_SOIL_CARB,CO2_FIRE,TOTAL_TURN)
+ChunckJob3D = NONE
+Seasonal = ON
+
+[Post_1M_stomate_ipcc_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, CONTFRAC, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cVeg, cLitter, cSoil, cProduct, lai, gpp, ra, npp, rh, fFire, fHarvest, fLuc, nbp, fVegLitter, fLitterSoil, cLeaf, cWood, cRoot, cMisc, cLitterAbove, cLitterBelow, cSoilFast, cSoilMedium, cSoilSlow, landCoverFrac, treeFracPrimDec, treeFracPrimEver, c3PftFrac, c4PftFrac, rGrowth, rMaint, nppLeaf, nppWood, nppRoot, nep)
+ChunckJob2D = NONE
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal = ON
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/xios.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/xios.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/COMP/xios.card	(revision 5879)
@@ -0,0 +1,29 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+
+[InitialStateFiles]
+List=	()
+
+[BoundaryFiles]
+List=	()
+ListNonDel= ()
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=	()
+
+[RestartFiles]
+List=	(NONE)
+
+[OutputText]
+List=   (out_xios.x.err.*, out_xios.x.out.*)
+
+[OutputFiles]
+List=   ()
+
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/config.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/config.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/IPSLCM/paleo/config.card	(revision 5879)
@@ -0,0 +1,196 @@
+#
+# This is config.card file for IPSLCM6 configuration
+#
+#========================================================================
+#D-- Compatibility -
+[Compatibility]
+libIGCM=1.0
+#D-- UserChoices -
+[UserChoices]
+#===========================
+JobName=PALEO01
+#----- Short Name of Experiment
+ExperimentName=paleo
+#----- DEVT TEST PROD
+SpaceName=PROD
+LongName="IPSLCM5A2 paleo configuration on IRENE. Runs with the following config on IRENE-SKL: 47 MPI processes and 8 OMP for LMDZ and 60 MPI for NEMO"
+TagName=IPSLCM5A2
+#D- Choice of experiment in EXPERIMENTS directory
+ExpType=IPSLCM/paleo
+#============================
+#-- leap, noleap, 360d
+CalendarType=360d
+#-- Experiment dates : Beginning and ending
+#-- "YYYY-MM-DD"
+DateBegin=0001-01-01
+DateEnd=3000-12-30
+#============================
+ORCA_version=ORCA2.3
+#============================
+#-- 1Y, 1M, 5D, 1D Period Length of one trunk of simulation
+PeriodLength=1Y
+
+#========================================================================
+#D-- Restarts -
+[Restarts]
+#D- by default: config.card describes no restart for all components
+#D-             ie start from Levitus or limit files
+#D- If you want to restart all components from the same simulation,
+#D-      put OveRule flag to 'y' and set the next 3 parameters
+OverRule=n
+#D- Last day of the experience used as restart for all components
+RestartDate=5009-12-31
+#D- Define restart simulation name for all components
+RestartJobName=CM5A2.1.pi.debug
+#D- Path Server Group Login
+RestartPath=${R_IN}/RESTART/IPSLCM5A2/PROD/piControl
+
+#========================================================================
+#D-- ATM -
+[ATM]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+# Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- OCE -
+[OCE]
+WriteFrequency="1M 1Y"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- ICE -
+[ICE]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- MBG -
+[MBG]
+WriteFrequency="1M 1Y"
+Restart= n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- SRF -
+[SRF]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+# Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- SBG - STOMATE
+[SBG]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+# Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- CPL -
+[CPL]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+# Last day of the experience used as restart for this component if Restart=y
+RestartDate=1859-12-31
+#D- Define restart simulation name for all components
+RestartJobName=O1T09V06
+#D- Path Server Group Login
+RestartPath=/ccc/store/cont003/dsm/p86mart/IGCM_OUT/IPSLCM6/DEVT/piControl
+
+#========================================================================
+#D-- IOS -
+[IOS]
+WriteFrequency=""
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=
+# Define restart simulation name for this component
+RestartJobName=
+RestartPath=
+
+#========================================================================
+#D-- ListOfComponents -
+[ListOfComponents]
+#D- For each component, Name of component, Tag of component
+ATM= (lmdz, LMDZ4-dev)
+SRF= (orchidee, ORCHIDEE_1_9_5)
+SBG= (stomate, ORCHIDEE_1_9_5)
+OCE= (opa9, CMIP5_IPSL)
+ICE= (lim2, CMIP5_IPSL)
+MBG= (pisces, CMIP5_IPSL)
+CPL= (oasis, OASIS3-MCT)
+IOS= (xios, XIOS)
+
+#========================================================================
+#D-- Executable -
+[Executable]
+#D- For each component, Real name of executable, Name of executable for oasis
+ATM= (gcm.e, lmdz.x, 47MPI, 8OMP)
+SRF= ("" ,"" )
+SBG= ("" ,"" )
+OCE= (opa, opa.xx, 60MPI)
+ICE= ("" ,"" )
+MBG= ("" ,"" )
+CPL= ("", "" )
+IOS= (xios_server.exe, xios.x, 1MPI)
+
+#========================================================================
+#D-- Post -
+[Post]
+ParserXIOS=FALSE
+#D- Do we rebuild parallel output, this flag determines
+#D- frequency of rebuild submission (use NONE for DRYRUN=3)
+RebuildFrequency=NONE
+#D- Do we pack restart and debug txt files, this flag determines
+#D- frequency of pack submission (use NONE for DRYRUN=3)
+PackFrequency=10Y
+#D- If you want to produce time series, this flag determines
+#D- frequency of post-processing submission (NONE if you don't want)
+TimeSeriesFrequency=50Y
+#D- If you want to produce seasonal average, this flag determines
+#D- the period of this average (NONE if you don't want)
+SeasonalFrequency=100Y
+#D- Offset for seasonal average first start dates ; same unit as SeasonalFrequency
+#D- Usefull if you do not want to consider the first X simulation's years
+SeasonalFrequencyOffset=0
+
+#========================================================================
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/lmdz.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/lmdz.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/lmdz.card	(revision 5879)
@@ -0,0 +1,221 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+# Physics package to use :
+# LMDZ_Physics=AP for standard/old physics(defalut), can be used with LMDZ4_AR5 or LMDZ5/trunk sources
+# LMDZ_Physics=NPv3.2 for an early version of the new physics, to be used with LMDZ5/trunk revision 1554 or later
+# LMDZ_Physics=NPv5.4 for new physics to be used with LMDZ5/trunk revision 2449 or later
+LMDZ_Physics=AP
+
+# Set the variable CREATE needed further below to find the initial and boundary condition files.
+CREATE=ELC-${RESOL_ATM_3D}
+
+# Set ConfType to choose parameters for aerosols, solar and green house gazes.
+# The parameter file PARAM/config.def_$ConfType will be used.
+# ConfType=preind/actuel/annuel
+ConfType=preind
+
+# Manage radiative aerosol effect and ozone
+flag_aerosol=6
+ok_ade=y
+ok_aie=y
+aerosol_couple=n
+read_climoz=2
+ok_cdnc=y
+
+# ByPass_hgardfou_teta=y : modify teta_ parameters for following CumulPeriod only
+ByPass_hgardfou_teta=n
+
+# ByPass_hgardfou_mats=y : set parameter purmats=y for following CumulPeriod only
+ByPass_hgardfou_mats=n
+
+# Set OutLevel to choose the level of output for LMDZ. 
+# OutLevel=low/medium/high
+OutLevel=low
+
+# COSP activation and choose of output frequency for COSP (monthly, daily, HF) = y/n
+LMDZ_COSP_OK=n
+LMDZ_COSP_monthly=n
+LMDZ_COSP_daily=n
+LMDZ_COSP_hf=n
+
+# Set NMC output frequency (monthly, daily, HF) = y/n
+LMDZ_NMC_monthly=n
+LMDZ_NMC_daily=n
+LMDZ_NMC_hf=n
+
+# Nugding : ok_guide=y/n
+# If ok_guide=y, add nudging files(u.nc, v.nc, hur.nc,...) in BoundaryFiles section below.
+ok_guide=n
+
+[InitialStateFiles]
+List=	(${ARCHIVE}/IGCM_OUT/LMDZ/${CREATE}/ATM/Output/Restart/${CREATE}_clim_start.nc,    start.nc),\
+        (${ARCHIVE}/IGCM_OUT/LMDZ/${CREATE}/ATM/Output/Restart/${CREATE}_clim_startphy.nc, startphy.nc) 
+
+[BoundaryFiles]
+List=()
+ListNonDel= (${ARCHIVE}/IGCM_OUT/LMDZ/${CREATE}/ATM/Output/Boundary/${CREATE}_clim_limit.nc, limit.nc),\
+            (${R_IN}/ATM/${RESOL_ATM}/AR5/HISTORIQUE/aerosols_11YearsClim_1855_v5.nc, aerosols1980.nc),\
+            (${R_IN}/ATM/${RESOL_ATM}/AR5/HISTORIQUE/aerosols_11YearsClim_1855_v5.nc, aerosols.nat.nc), \
+            (${R_IN}/ATM/${RESOL_ATM}/AR5/HISTORIQUE/climoz_LMDZ_1855_v2.nc, climoz_LMDZ.nc)
+
+[SmoothFiles]
+List=()
+
+[ParametersFiles]
+List=   (${SUBMIT_DIR}/PARAM/physiq.def_${LMDZ_Physics}, physiq.def),       \
+        (${SUBMIT_DIR}/PARAM/gcm.def_${RESOL_ATM_XY},    gcm.def),          \
+        (${SUBMIT_DIR}/PARAM/vert.def_L${RESOL_ATM_Z},   vert.def),         \
+        (${MODIPSL}/modeles/LMDZ/DefLists/cosp_input_nl.txt, .),            \
+        (${MODIPSL}/modeles/LMDZ/DefLists/cosp_output_nl.txt, .),           \
+        (${SUBMIT_DIR}/PARAM/config.def_${ConfType},  config.def),          \
+        (${SUBMIT_DIR}/PARAM/guide.def, .),                                 \
+        (${SUBMIT_DIR}/PARAM/run.def, .),                                   \
+        (${SUBMIT_DIR}/PARAM/traceur.def, .),                               \
+        (${SUBMIT_DIR}/PARAM/iodef.xml, . ),                                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/context_lmdz.xml, . ),            \
+        (${MODIPSL}/modeles/LMDZ/DefLists/field_def_lmdz.xml, . ),          \
+        (${SUBMIT_DIR}/PARAM/file_def_histmth_lmdz_paleo.xml, file_def_histmth_lmdz.xml ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histmthCOSP_lmdz.xml, .),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histmthNMC_lmdz.xml, . ),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histday_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histdayCOSP_lmdz.xml, .),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histdayNMC_lmdz.xml, . ),             \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhf_lmdz.xml, . ),                 \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhfCOSP_lmdz.xml, .),              \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histhfNMC_lmdz.xml, . ),              \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histstn_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histins_lmdz.xml, . ),                \
+        (${MODIPSL}/modeles/LMDZ/DefLists/file_def_histLES_lmdz.xml, . )
+
+
+
+[RestartFiles]
+List=   (restart.nc, restart.nc, start.nc), \
+        (restartphy.nc, restartphy.nc,  startphy.nc)
+
+[OutputText]
+List=   (physiq.def, gcm.def, run.def, traceur.def, guide.def, config.def, vert.def, used_run.def, iodef.xml, context_lmdz.xml, field_def_lmdz.xml, file_def_*lmdz.xml, debug.01, lmdz.prt,out_lmdz.x.err, out_lmdz.x.out)
+
+[OutputFiles]
+List=   (histmth.nc,       ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmth.nc,       Post_1M_histmth),       \
+        (histmthCOSP.nc,   ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmthCOSP.nc,   NONE),                  \
+        (histmthNMC.nc,    ${R_OUT_ATM_O_M}/${PREFIX}_1M_histmthNMC.nc,    NONE),    \
+        (paramLMDZ_phy.nc, ${R_OUT_ATM_O_M}/${PREFIX}_1M_paramLMDZ_phy.nc, NONE), \
+        (histday.nc,       ${R_OUT_ATM_O_D}/${PREFIX}_1D_histday.nc,       NONE),                  \
+        (histdayCOSP.nc,   ${R_OUT_ATM_O_D}/${PREFIX}_1D_histdayCOSP.nc,   NONE),                  \
+        (histdayNMC.nc,    ${R_OUT_ATM_O_D}/${PREFIX}_1D_histdayNMC.nc,    NONE),                  \
+        (histhf.nc,        ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhf.nc,        NONE),                  \
+        (histhfCOSP.nc,    ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhfCOSP.nc,    NONE),                  \
+        (histhfNMC.nc,     ${R_OUT_ATM_O_H}/${PREFIX}_HF_histhfNMC.nc,     NONE),                  \
+        (histhf3h.nc,      ${R_OUT_ATM_O_H}/${PREFIX}_3H_histhf3h.nc,      NONE),                  \
+        (histhf3hm.nc,     ${R_OUT_ATM_O_H}/${PREFIX}_3H_histhf3hm.nc,     NONE)
+
+[Post_1M_histmth]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds, aire)
+TimeSeriesVars2D = (bils, cldh, cldl, cldm, cldq, cldt, evap, flat, iwp, lwp, LWdnSFC, LWdnSFCclr, LWupSFCclr, LWdn200, LWdn200clr, LWup200, LWup200clr, precip, prw, pluc, psol, q2m, rh2m, sens, sicf, slp, snow, soll0, soll, sols0, sols, SWdnSFC, SWupSFC, SWup200, SWdnTOA, SWupTOA, SWdn200, SWdnSFCclr, SWupSFCclr, SWupTOAclr, t2m, t2m_max, t2m_min, taux, taux_ter, taux_sic, taux_lic, taux_oce, tauy, tauy_ter, tauy_sic, tauy_lic, tauy_oce, lat_ter, lat_sic, lat_lic, lat_oce, nettop, pbase, ptop, topl0, topl, tops0, tops, topswad, topswai, tsol, tsol_ter, tsol_lic, tsol_oce, tsol_sic , u10m, u500, v10m, v500, w500, pourc_ter, pourc_oce, pourc_sic, pourc_lic, wind10m, swtoacf_zero, swsrfcf_zero)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (upwd, lwcon, iwcon, lcc3dcon, lcc3dstra, temp, theta, ovap, ovapinit, geop, vitu, vitv, vitw, pres, rneb, rnebcon, rhum, mc, mcd)
+ChunckJob3D = 100Y
+Seasonal=ON
+
+[Post_1M_histmthCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, pressure2, height, sza, time_counter, time_centered, time_centered_bounds, aire)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso, tclisccp, albisccp, ctpisccp)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, clisccp2_c01, clisccp2_c02, clisccp2_c03, clisccp2_c04, clisccp2_c05, clisccp2_c06, clisccp2_c07, parasol_refl)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1M_histmthNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, tro3, zg, hus, hur, ua, va, wap)
+ChunckJob3D = NONE
+Seasonal=ON
+
+[Post_1M_paramLMDZ_phy]
+Patches=()
+GatherWithInternal = (lon, lat, time_counter, time_counter_bnds)
+TimeSeriesVars2D =(R_ecc,  R_peri, R_incl, solaire, co2_ppm, CH4_ppb, N2O_ppb, CFC11_ppt, CFC12_ppt)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = NONE
+Seasonal=OFF
+
+[Post_1D_histday]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (bils, cldh, cldl, cldm, cldq, cldt, evap, flat, precip, pluc, plul, prw, psol, q2m, sens, sicf, slp, soll, sols, snow, SWdnSFC, t2m, t2m_max, t2m_min, topl, tops, tsol, u10m, v10m, wind10m, wind10max)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (lwcon, iwcon, mc, rhum, rneb, temp, theta, ovap, geop, vitu, vitv, vitw, pres, paprs)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_histdayCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, pressure2, height, sza, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso, tclisccp, albisccp, ctpisccp)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, clisccp2_c01, clisccp2_c02, clisccp2_c03, clisccp2_c04, clisccp2_c05, clisccp2_c06, clisccp2_c07, parasol_refl)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_1D_histdayNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, zg, hus, hur, ua, va, wap)
+ChunckJob3D = 10Y
+Seasonal=OFF
+
+[Post_HF_histhf]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cldt, psol, q2m, slp, precip, pluc, plul, t2m, tsol, u10m, v10m)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (temp, theta, ovap, vitu, vitv)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_HF_histhfCOSP]
+Patches = ()
+GatherWithInternal = (lon, lat, height, sza, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cllcalipso, clmcalipso, clhcalipso, cltcalipso)
+ChunckJob2D = OFF
+TimeSeriesVars3D = (clcalipso, parasol_refl, cfad_lidarsr532_c01, cfad_lidarsr532_c02, cfad_lidarsr532_c03, cfad_lidarsr532_c04, cfad_lidarsr532_c05, cfad_lidarsr532_c06, cfad_lidarsr532_c07, cfad_lidarsr532_c08, cfad_lidarsr532_c09, cfad_lidarsr532_c10, cfad_lidarsr532_c11, cfad_lidarsr532_c12, cfad_lidarsr532_c13, cfad_lidarsr532_c14, cfad_lidarsr532_c15)
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_HF_histhfNMC]
+Patches = ()
+GatherWithInternal = (lon, lat, plev, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = ()
+ChunckJob2D = NONE
+TimeSeriesVars3D = (ta, zg, hus, hur, ua, va, wap)
+ChunckJob3D = 10Y
+Seasonal=OFF
+
+[Post_3H_histhf3hm]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (flat, precip, pluc, snow, topl, topl0, SWupTOA, SWupTOAclr, SWdnTOA, SWupSFC, SWupSFCclr, SWdnSFC, SWdnSFCclr, LWupSFC, LWupSFCclr, LWdnSFC, LWdnSFCclr, bils, bils_tke, bils_diss, bils_ec, bils_kinetic, bils_enthalp, bils_latent, sens, cldt, zmax_th)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
+
+[Post_3H_histhf3h]
+Patches= ()
+GatherWithInternal = (lon, lat, presnivs, time_counter, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (phis, tsol, t2m, q2m, ustar, u10m, v10m, psol)
+ChunckJob2D = OFF
+TimeSeriesVars3D = ()
+ChunckJob3D = OFF
+Seasonal=OFF
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/orchidee.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/orchidee.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/orchidee.card	(revision 5879)
@@ -0,0 +1,59 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+# The variable DefSuffix gives the suffix of the orchidee.def file to be used.
+# By default the file orchidee.def_Choi will be selected.
+# Sef DefSuffix=Choi (default) to activate default 2-layer Choisnel hydrology
+# Set DefSuffix=CWRR to activate 11-layer CWRR hydrology
+DefSuffix=Choi
+
+VEGET_UPDATE=0Y
+
+[InitialStateFiles]
+List=	(${R_IN}/SRF/soils_param.nc,        . ), \
+    	(${R_IN}/SRF/routing.nc,            . ), \
+        (${R_IN}/SRF/PFTmap_1850to2005_AR5_LUHa.rc2/PFTmap_IPCC_2000.nc, PFTmap.nc), \
+        (${R_IN}/SRF/cartepente2d_15min.nc, .)
+
+[BoundaryFiles]
+List= ()
+ListNonDel= ()
+
+[SmoothFiles]
+List= ()
+
+[ParametersFiles]
+List=	(${SUBMIT_DIR}/PARAM/orchidee.def_${DefSuffix}             , orchidee.def)   ,\
+        (${SUBMIT_DIR}/PARAM/file_def_orchidee_paleo.xml           , file_def_orchidee.xml), \
+        (${MODIPSL}/modeles/ORCHIDEE/src_xml/context_orchidee.xml  , .)   ,\
+        (${MODIPSL}/modeles/ORCHIDEE/src_xml/field_def_orchidee.xml, .)
+
+[RestartFiles]
+List=	(sechiba_rest_out.nc, sechiba_rest.nc, sechiba_rest_in.nc)
+
+[OutputText]
+List=   (out_orchidee, orchidee.def, used_orchidee.def, iodef.xml, context_orchidee.xml, field_def_orchidee.xml, file_def_orchidee.xml, river_desc.nc)
+
+[OutputFiles]
+List=   (sechiba_history.nc,   ${R_OUT_SRF_O_M}/${PREFIX}_1M_sechiba_history.nc, Post_1M_sechiba_history), \
+        (sechiba_out_2.nc,     ${R_OUT_SRF_O_H}/${PREFIX}_HF_sechiba_out_2.nc,   NONE)
+
+[Post_1M_sechiba_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, Contfrac, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (nobiofrac, evap, fluxlat, fluxsens, netrad, qair, rain, runoff, snow, snownobio, snowf, subli, tair, temp_sol, tsol_max, tsol_min, drainage, mrso, mrros, mrro, prveg, tran, riverflow, coastalflow)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (lai, maxvegetfrac, vegetfrac)
+ChunckJob3D = NONE
+Seasonal = ON
+
+[Post_HF_sechiba_out_2]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, Contfrac, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (mrsos, mrro)
+ChunckJob2D = 50Y
+TimeSeriesVars3D = (ptn)
+ChunckJob3D = 10Y
+Seasonal = OFF
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/stomate.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/stomate.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/stomate.card	(revision 5879)
@@ -0,0 +1,46 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+
+[InitialStateFiles]
+List=   ()
+
+[BoundaryFiles]
+List=	()
+ListNonDel= ()
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=   ()
+
+[RestartFiles]
+List=	(stomate_rest_out.nc, stomate_rest.nc, stomate_rest_in.nc)
+
+[OutputText]
+List=   ()
+
+[OutputFiles]
+List=   (stomate_history.nc,      ${R_OUT_SBG_O_M}/${PREFIX}_1M_stomate_history.nc,      NONE),    \
+        (stomate_ipcc_history.nc, ${R_OUT_SBG_O_M}/${PREFIX}_1M_stomate_ipcc_history.nc, NONE)
+
+[Post_1M_stomate_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (T2M_MONTH,CONTFRAC,RESOLUTION_X,RESOLUTION_Y,CONVFLUX,CFLUX_PROD10,CFLUX_PROD100,HARVEST_ABOVE)
+ChunckJob2D = NONE
+TimeSeriesVars3D = (LAI,VEGET_MAX,NPP,GPP,HET_RESP,MAINT_RESP,GROWTH_RESP,AGE,HEIGHT,TOTAL_M,TOTAL_BM_LITTER,TOTAL_SOIL_CARB,CO2_FIRE,TOTAL_TURN)
+ChunckJob3D = NONE
+Seasonal=ON
+
+[Post_1M_stomate_ipcc_history]
+Patches = ()
+GatherWithInternal = (lon, lat, time_counter, Areas, CONTFRAC, time_centered, time_centered_bounds)
+TimeSeriesVars2D = (cVeg, cLitter, cSoil, cProduct, lai, gpp, ra, npp, rh, fFire, fHarvest, fLuc, nbp, fVegLitter, fLitterSoil, cLeaf, cWood, cRoot, cMisc, cLitterAbove, cLitterBelow, cSoilFast, cSoilMedium, cSoilSlow, landCoverFrac, treeFracPrimDec, treeFracPrimEver, c3PftFrac, c4PftFrac, rGrowth, rMaint, nppLeaf, nppWood, nppRoot, nep)
+ChunckJob2D = NONE
+TimeSeriesVars3D=()
+ChunckJob3D = NONE
+Seasonal=ON
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/xios.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/xios.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/COMP/xios.card	(revision 5879)
@@ -0,0 +1,29 @@
+[Compatibility]
+libIGCM=1.0
+
+[UserChoices]
+
+[InitialStateFiles]
+List=	()
+
+[BoundaryFiles]
+List=	()
+ListNonDel= ()
+
+[SmoothFiles]
+List=	()
+
+[ParametersFiles]
+List=	()
+
+[RestartFiles]
+List=	(NONE)
+
+[OutputText]
+List=   (xios_client_*,out_xios.x.err.*, out_xios.x.out.*)
+
+[OutputFiles]
+List=   ()
+
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/config.card
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/config.card	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/EXPERIMENTS/LMDZOR/paleo/config.card	(revision 5879)
@@ -0,0 +1,127 @@
+# $Id$
+#========================================================================
+#D-- Compatibility -
+[Compatibility]
+libIGCM=1.0
+#D-- UserChoices -
+[UserChoices]
+#============================
+JobName=LMDZOR01
+#----- Short Name of Experiment
+ExperimentName=clim
+#----- DEVT TEST PROD
+SpaceName=PROD
+LongName="LMDZOR paleo configuratio on Irene."
+TagName=LMDZOR
+#D- Choice of experiment in EXPERIEMENTS directory
+ExpType=LMDZOR/paleo
+#============================
+#-- leap, noleap, 360d
+CalendarType=360d
+#-- Begin and end of job 
+#-- "YYYY-MM-DD"
+DateBegin=0001-01-01
+DateEnd=0001-12-30
+#============================
+#-- 1Y, 1M, 5D, 1D Period Length for one execution
+PeriodLength=1Y
+
+#========================================================================
+#D-- ListOfComponents -
+[ListOfComponents]
+#D- For each component, Name of component, Tag of component
+ATM= (lmdz, LMDZ)
+SRF= (orchidee, ORCHIDEE)
+SBG= (stomate, ORCHIDEE)
+IOS= (xios, XIOS)
+
+#========================================================================
+#D-- Executable -
+[Executable]
+#D- For each component: Real name of executable, Name of executable in the run directory 
+ATM= (gcm.e, lmdz.x, 31MPI, 1OMP)
+SRF= ("", "")
+SBG= ("", "")
+IOS= (xios_server.exe, xios.x, 1MPI)
+
+#========================================================================
+#D-- Restarts -
+[Restarts]
+#D- by default: config.card describes no restart for all components 
+#D-             ie start from Levitus or limit files
+#D- If you want to restart all components from the same simulation,
+#D-      put OveRule flag to 'y' and set the next 3 parameters
+OverRule=n
+#D- Last day of the experience used as restart for all components
+RestartDate=2000-01-31
+#D- Define restart simulation name for all components
+RestartJobName=EXP00
+#D- Path Server Group Login
+RestartPath=${ARCHIVE}/IGCM_OUT/LMDZOR/DEVT/amip
+
+#========================================================================
+#D-- ATM -
+[ATM]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart=n
+# Last day of the experience used as restart for this component if Restart=y
+RestartDate=2000-01-31
+# Define restart simulation name for this component
+RestartJobName=LMDZOR01
+RestartPath=${ARCHIVE}/IGCM_OUT/LMDZOR/DEVT/amip
+
+#========================================================================
+#D-- SRF -
+[SRF]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart=n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=2000-01-31
+# Define restart simulation name for this component
+RestartJobName=EXP00
+RestartPath=${ARCHIVE}/IGCM_OUT/LMDZOR/DEVT/amip
+
+#========================================================================
+#D-- SBG - STOMATE
+[SBG]
+WriteFrequency="1M"
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart=n
+#-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=2000-01-31
+# Define restart simulation name for this component
+RestartJobName=EXP00
+RestartPath=${ARCHIVE}/IGCM_OUT/LMDZOR/DEVT/amip
+
+#========================================================================
+#D-- IOS -
+[IOS]
+WriteFrequency=""
+# If config_Restarts_OverRule == 'n' next 4 params are read
+Restart= n
+##-- Last day of the experience used as restart for this component if Restart=y
+RestartDate=
+# Define restart simulation name for this component
+RestartJobName=
+RestartPath=
+
+#========================================================================
+#D-- Post -
+[Post]
+#D- RebuildFrequency determines the frequency of rebuild submission
+RebuildFrequency=NONE
+#D- PackFrequency determines the frequency of pack submission
+PackFrequency=1Y
+#D- TimeSeriesFreqency determines the frequency of post-processing submission
+#D- Set NONE to deactivate the creation of all time series 
+TimeSeriesFrequency=10Y
+#D- SeasonalFrequency determines the length for each seasonal average
+#D- Set NONE to deactivate the creation of all seasonal avereage
+SeasonalFrequency=10Y
+#D- Offset for seasonal average first start dates ; same unit as SeasonalFrequency
+#D- Usefull if you do not want to consider the first X simulation's years
+SeasonalFrequencyOffset=0
+
+#========================================================================
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/DRIVER/opa9.driver
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/DRIVER/opa9.driver	(revision 5878)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/DRIVER/opa9.driver	(revision 5879)
@@ -26,5 +26,10 @@
     supergrep () { grep "^ *$1 *=" $2 | sed -e "s% *\!.*%%" -e "s%^ *$1 *=%%" ; }
     ##--Variables used by OPA --
-    NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
+    ISPALEO=${config_UserChoices_ExpType##*/}
+    if [ "${ISPALEO}" = "paleo" ] ; then
+        NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg_paleo
+    else
+        NAMELIST_OPA_CFG=${SUBMIT_DIR}/PARAM/namelist_${RESOL_OCE}_cfg
+    fi
     IGCM_debug_Print 1 "namelist_cfg : ${NAMELIST_OPA_CFG}"
     if [ ! -r ${NAMELIST_OPA_CFG} ] ; then
@@ -38,6 +43,17 @@
     # OPA_NN_FSBC=$(   supergrep nn_fsbc       namelist_cfg )
     (( OPA_NPDT_DAY   =  86400 / OPA_RDT        ))
-    (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
+    #(( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     ))
     (( OPA_RDT_SBC    =  OPA_RDT * OPA_NN_FSBC ))
+    # nleapy configuration
+    case ${config_UserChoices_CalendarType} in
+        ( leap|gregorian) OPA_NLEAPY=1
+                          (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     )) ;;
+        ( noleap        ) OPA_NLEAPY=0
+                          (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 365     )) ;;
+        ( 360d          ) OPA_NLEAPY=30
+                          (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 360     )) ;;
+        ( *             ) OPA_NLEAPY=30
+                          (( OPA_NPDT_YEAR  =  OPA_NPDT_DAY * 360     )) ;;
+    esac
  
     # Period Length In Days between DateBegin and first day of calendar 0001 01 01
@@ -144,12 +160,4 @@
     fi
 
-    # nleapy configuration
-    case ${config_UserChoices_CalendarType} in
-        ( leap|gregorian) OPA_NLEAPY=1  ;;
-        ( noleap        ) OPA_NLEAPY=0  ;;
-        ( 360d          ) OPA_NLEAPY=30 ;;
-        ( *             ) OPA_NLEAPY=30 ;;
-    esac
-
     if ( [ "${opa9_UserChoices_Reproducibility_after_restart}" = "y" ] ) ; then
         ##-- choose the right restart file
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_histmth_lmdz_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_histmth_lmdz_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_histmth_lmdz_paleo.xml	(revision 5879)
@@ -0,0 +1,533 @@
+<!-- This file corresponds to the LMDZ5 testing rev 2314. It might not be compatible  -->
+<!-- with older or newer revisions of LMDZ source code.                               -->
+
+<file_definition>
+        <file_group id="defile">
+        <file id="histmth" name="histmth" output_freq="1mo" output_level="2"  enabled="_AUTO_">
+
+            <!-- VARS 1D -->
+<!--            <field_group operation="once">  -->
+<!--              <field field_ref="Ap" level="1" />  -->
+<!--              <field field_ref="Bp" level="1" />  -->
+<!--              <field field_ref="Alt" level="1" />  -->
+<!--            </field_group>  -->
+        
+            <!-- VARS 2D -->
+            <field_group operation="average" freq_op="1ts">
+                <field field_ref="phis"         level="1" />
+                <field field_ref="aire"         level="1"   operation="once"/>
+                <field field_ref="contfracATM"  level="10"  operation="once"/>
+                <field field_ref="contfracOR"   level="10" />
+                <field field_ref="aireTER"      level="10" />
+                <field field_ref="flat"         level="5" />
+                <field field_ref="slp"          level="1" />
+                <field field_ref="tsol"         level="1" />
+                <field field_ref="t2m"          level="1" />
+                <field field_ref="t2m_min" level="1" operation="minimum" />
+                <field field_ref="t2m_max" level="1" operation="maximum" />
+                <field field_ref="t2m_ter" level="10" />
+                <field field_ref="t2m_lic" level="10" />
+                <field field_ref="t2m_oce" level="10" />
+                <field field_ref="t2m_sic" level="10" />
+                <field field_ref="gusts" level="1" />
+                <field field_ref="wind10m" level="1" />
+                <field field_ref="wind10max" level="1" operation="maximum" />
+                <field field_ref="sicf"      level="1" />
+                <field field_ref="q2m"       level="1" />
+                <field field_ref="ustar"     level="1" />
+                <field field_ref="u10m"      level="1" />
+                <field field_ref="v10m"      level="1" />
+                <field field_ref="psol"      level="1" />
+                <field field_ref="qsurf"     level="1" />
+                <field field_ref="ustar_ter" level="10" />
+                <field field_ref="ustar_lic" level="10" />
+                <field field_ref="ustar_oce" level="10" />
+                <field field_ref="ustar_sic" level="10" />
+                <field field_ref="wstar_ter" level="10" />
+                <field field_ref="wstar_lic" level="10" />
+                <field field_ref="wstar_oce" level="10" />
+                <field field_ref="wstar_sic" level="10" />
+                <field field_ref="wstar"    level="5" />
+                <field field_ref="u10m_ter" level="10" />
+                <field field_ref="u10m_lic" level="10" />
+                <field field_ref="u10m_oce" level="10" />
+                <field field_ref="u10m_sic" level="10" />
+                <field field_ref="v10m_ter" level="10" />
+                <field field_ref="v10m_lic" level="10" />
+                <field field_ref="v10m_oce" level="10" />
+                <field field_ref="v10m_sic" level="10" />
+                <field field_ref="qsol"     level="1" />
+                <field field_ref="ndayrain" level="1" operation="instant" />
+                <field field_ref="precip"   level="1" />
+                <field field_ref="plul"     level="1" />
+                <field field_ref="pluc"     level="1" />
+                <field field_ref="snow"     level="1" />
+                <field field_ref="evap"     level="1" />
+                <field field_ref="evap_ter" level="1" />
+                <field field_ref="evap_lic" level="1" />
+                <field field_ref="evap_oce" level="1" />
+                <field field_ref="evap_sic" level="1" />
+                <field field_ref="msnow"    level="1" />
+                <field field_ref="fsnow"    level="1" />
+                <field field_ref="tops"     level="1" />
+                <field field_ref="tops0"    level="1" />
+                <field field_ref="topl"     level="1" />
+                <field field_ref="topl0"    level="1" />
+                <field field_ref="SWupTOA"  level="1" />
+                <field field_ref="SWupTOAclr"   level="1" />
+                <field field_ref="SWdnTOA"      level="1" />
+                <field field_ref="SWdnTOAclr"   level="1" />
+                <field field_ref="nettop"       level="1" />
+                <field field_ref="SWup200"      level="1" />
+                <field field_ref="SWup200clr"   level="1" />
+                <field field_ref="SWdn200"      level="1" />
+                <field field_ref="SWdn200clr"   level="1" />
+                <field field_ref="LWup200"      level="1" />
+                <field field_ref="LWup200clr"   level="1" />
+                <field field_ref="LWdn200"      level="1" />
+                <field field_ref="LWdn200clr"   level="1" />
+                <field field_ref="sols"  level="1" />
+                <field field_ref="sols0" level="1" />
+                <field field_ref="soll" level="1" />
+                <field field_ref="soll0" level="1" />
+                <field field_ref="radsol" level="1" />
+                <field field_ref="SWupSFC" level="1" />
+                <field field_ref="SWupSFCclr" level="1" />
+                <field field_ref="SWdnSFC" level="1" />
+                <field field_ref="SWdnSFCclr" level="1" />
+                <field field_ref="LWupSFC" level="1" />
+                <field field_ref="LWupSFCclr" level="1" />
+                <field field_ref="LWdnSFC" level="1" />
+                <field field_ref="LWdnSFCclr" level="1" />
+                <field field_ref="bils" level="1" />
+                <field field_ref="bils_tke" level="1" />
+                <field field_ref="bils_diss" level="1" />
+                <field field_ref="bils_ec" level="1" />
+                <field field_ref="bils_kinetic" level="1" />
+                <field field_ref="bils_enthalp" level="1" />
+                <field field_ref="bils_latent" level="1" />
+                <field field_ref="sens" level="1" />
+                <field field_ref="fder" level="1" />
+                <field field_ref="ffonte" level="1" />
+                <field field_ref="fqcalving" level="1" />
+                <field field_ref="fqfonte" level="1" />
+                <field field_ref="taux" level="1" />
+                <field field_ref="tauy" level="1" />
+                <field field_ref="taux_ter" level="1" />
+                <field field_ref="taux_lic" level="1" />
+                <field field_ref="taux_oce" level="1" />
+                <field field_ref="taux_sic" level="1" />
+                <field field_ref="tauy_ter" level="1" />
+                <field field_ref="tauy_lic" level="1" />
+                <field field_ref="tauy_oce" level="1" />
+                <field field_ref="tauy_sic" level="1" />
+                <field field_ref="pourc_ter" level="1" />
+                <field field_ref="pourc_lic" level="1" />
+                <field field_ref="pourc_oce" level="1" />
+                <field field_ref="pourc_sic" level="1" />
+                <field field_ref="fract_ter" level="1" />
+                <field field_ref="fract_lic" level="1" />
+                <field field_ref="fract_oce" level="1" />
+                <field field_ref="fract_sic" level="1" />
+                <field field_ref="tsol_ter" level="1" />
+                <field field_ref="tsol_lic" level="1" />
+                <field field_ref="tsol_oce" level="1" />
+                <field field_ref="tsol_sic" level="1" />
+                <field field_ref="evappot_ter" level="6" />
+                <field field_ref="evappot_lic" level="6" />
+                <field field_ref="evappot_oce" level="6" />
+                <field field_ref="evappot_sic" level="6" />
+                <field field_ref="sens_ter" level="1" />
+                <field field_ref="sens_lic" level="1" />
+                <field field_ref="sens_oce" level="1" />
+                <field field_ref="sens_sic" level="1" />
+                <field field_ref="lat_ter" level="1" />
+                <field field_ref="lat_lic" level="1" />
+                <field field_ref="lat_oce" level="1" />
+                <field field_ref="lat_sic" level="1" />
+                <field field_ref="flw_ter" level="1" />
+                <field field_ref="flw_lic" level="1" />
+                <field field_ref="flw_oce" level="1" />
+                <field field_ref="flw_sic" level="1" />
+                <field field_ref="fsw_ter" level="1" />
+                <field field_ref="fsw_lic" level="1" />
+                <field field_ref="fsw_oce" level="1" />
+                <field field_ref="fsw_sic" level="1" />
+                <field field_ref="wbils_ter" level="1" />
+                <field field_ref="wbils_lic" level="1" />
+                <field field_ref="wbils_oce" level="1" />
+                <field field_ref="wbils_sic" level="1" />
+                <field field_ref="wbilo_ter" level="1" />
+                <field field_ref="wbilo_lic" level="1" />
+                <field field_ref="wbilo_oce" level="1" />
+                <field field_ref="wbilo_sic" level="1" />
+                <field field_ref="cdrm" level="1" />
+                <field field_ref="cdrh" level="1" />
+                <field field_ref="cldl" level="1" />
+                <field field_ref="cldm" level="1" />
+                <field field_ref="cldh" level="1" />
+                <field field_ref="cldt" level="1" />
+                <field field_ref="cldq" level="1" />
+                <field field_ref="lwp" level="1" />
+                <field field_ref="iwp" level="1" />
+                <field field_ref="ue" level="1" />
+                <field field_ref="ve" level="1" />
+                <field field_ref="uq" level="1" />
+                <field field_ref="vq" level="1" />
+                <field field_ref="cape" level="1" />
+                <field field_ref="pbase" level="1" />
+                <field field_ref="ptop" level="1" />
+                <field field_ref="fbase" level="1" />
+                <field field_ref="plcl" level="1" />
+                <field field_ref="plfc" level="1" />
+                <field field_ref="wbeff" level="1" />
+                <field field_ref="prw" level="1" />
+                <field field_ref="s_pblh" level="1" />
+                <field field_ref="s_pblt" level="1" />
+                <field field_ref="s_lcl" level="1" />
+                <field field_ref="s_therm" level="6" />
+                <field field_ref="slab_bils_oce" level="6" />
+                <field field_ref="ale_bl" level="6" />
+                <field field_ref="alp_bl" level="6" />
+                <field field_ref="ale_wk" level="6" />
+                <field field_ref="alp_wk" level="6" />
+                <field field_ref="ale" level="6" />
+                <field field_ref="alp" level="6" />
+                <field field_ref="cin" level="6" />
+                <field field_ref="wape" level="6" />
+                <field field_ref="n2" level="6" />
+                <field field_ref="s2" level="6" />
+                <field field_ref="proba_notrig" level="6" />
+                <field field_ref="random_notrig" level="6" />
+                <field field_ref="ale_bl_stat" level="6" />
+                <field field_ref="ale_bl_trig" level="6" />
+                <field field_ref="alp_bl_det" level="6" />
+                <field field_ref="alp_bl_fluct_m" level="6" />
+                <field field_ref="alp_bl_fluct_tke" level="6" />
+                <field field_ref="alp_bl_conv" level="6" />
+                <field field_ref="alp_bl_stat" level="6" />
+
+                <field_group operation="average" freq_op="1ts" detect_missing_value=".true.">
+                    <field field_ref="u850" level="1" />
+                    <field field_ref="u700" level="1" />
+                    <field field_ref="u500" level="1" />
+                    <field field_ref="u200" level="1" />
+                    <field field_ref="u100" level="1" />
+                    <field field_ref="u50" level="1" />
+                    <field field_ref="u10" level="1" />
+                    <field field_ref="v850" level="1" />
+                    <field field_ref="v700" level="1" />
+                    <field field_ref="v500" level="1" />
+                    <field field_ref="v200" level="1" />
+                    <field field_ref="v100" level="1" />
+                    <field field_ref="v50" level="1" />
+                    <field field_ref="v10" level="1" />
+                    <field field_ref="w850" level="1" />
+                    <field field_ref="w700" level="1" />
+                    <field field_ref="w500" level="1" />
+                    <field field_ref="w200" level="1" />
+                    <field field_ref="w100" level="1" />
+                    <field field_ref="w50" level="1" />
+                    <field field_ref="w10" level="1" />
+                    <field field_ref="t850" level="1" />
+                    <field field_ref="t700" level="1" />
+                    <field field_ref="t500" level="1" />
+                    <field field_ref="t200" level="1" />
+                    <field field_ref="t100" level="1" />
+                    <field field_ref="t50" level="1" />
+                    <field field_ref="t10" level="1" />
+                    <field field_ref="q850" level="1" />
+                    <field field_ref="q700" level="1" />
+                    <field field_ref="q500" level="1" />
+                    <field field_ref="q200" level="1" />
+                    <field field_ref="q100" level="1" />
+                    <field field_ref="q50" level="1" />
+                    <field field_ref="q10" level="1" />
+                    <field field_ref="z850" level="1" />
+                    <field field_ref="z700" level="1" />
+                    <field field_ref="z500" level="1" />
+                    <field field_ref="z200" level="1" />
+                    <field field_ref="z100" level="1" />
+                    <field field_ref="z50" level="1" />
+                    <field field_ref="z10" level="1" />
+                </field_group>
+
+                <field field_ref="t_oce_sic" level="1" />
+                <field field_ref="weakinv" level="10" />
+                <field field_ref="dthmin" level="10" />
+                <field field_ref="u10_ter" level="10" />
+                <field field_ref="u10_lic" level="10" />
+                <field field_ref="u10_oce" level="10" />
+                <field field_ref="u10_sic" level="10" />
+                <field field_ref="v10_ter" level="10" />
+                <field field_ref="v10_lic" level="10" />
+                <field field_ref="v10_oce" level="10" />
+                <field field_ref="v10_sic" level="10" />
+                <field field_ref="rh2m" level="2" />
+                <field field_ref="rh2m_min" level="10" operation="minimum" />
+                <field field_ref="rh2m_max" level="10" operation="maximum" />
+                <field field_ref="qsat2m" level="10" />
+                <field field_ref="tpot" level="10" />
+                <field field_ref="tpote" level="10" />
+                <field field_ref="tke" level="4" />
+                <field field_ref="tke_ter" level="10" />
+                <field field_ref="tke_lic" level="10" />
+                <field field_ref="tke_oce" level="10" />
+                <field field_ref="tke_sic" level="10" />
+                <field field_ref="tke_max_ter" level="10" operation="maximum" />
+                <field field_ref="tke_max_lic" level="10" operation="maximum" />
+                <field field_ref="tke_max_oce" level="10" operation="maximum" />
+                <field field_ref="tke_max_sic" level="10" operation="maximum" />
+                <field field_ref="SWnetOR" level="10" />
+                <field field_ref="SWdownOR" level="10" />
+                <field field_ref="LWdownOR" level="10" />
+                <field field_ref="snowl" level="10" />
+                <field field_ref="cape_max" level="10" operation="maximum" />
+                <field field_ref="solldown" level="10" />
+                <field field_ref="dtsvdfo" level="10" />
+                <field field_ref="dtsvdft" level="10" />
+                <field field_ref="dtsvdfg" level="10" />
+                <field field_ref="dtsvdfi" level="10" />
+                <field field_ref="rugs" level="10" />
+                <field field_ref="z0m" level="10" />
+                <field field_ref="z0h" level="10" />
+                <field field_ref="topswad" level="6" />
+                <field field_ref="topswad0" level="6" />
+                <field field_ref="topswai" level="6" />
+                <field field_ref="solswad" level="6" />
+                <field field_ref="solswad0" level="6" />
+                <field field_ref="solswai" level="6" />
+                <field field_ref="OD550_ASBCM" level="6" />
+                <field field_ref="OD550_ASPOMM" level="6" />
+                <field field_ref="OD550_ASSO4M" level="6" />
+                <field field_ref="OD550_CSSO4M" level="6" />
+                <field field_ref="OD550_SSSSM" level="6" />
+                <field field_ref="OD550_ASSSM" level="6" />
+                <field field_ref="OD550_CSSSM" level="6" />
+                <field field_ref="OD550_CIDUSTM" level="6" />
+                <field field_ref="OD550_AIBCM" level="6" />
+                <field field_ref="OD550_AIPOMM" level="6" />
+                <field field_ref="OD550_STRAT" level="6" />
+                <field field_ref="od550aer" level="6" />
+                <field field_ref="od865aer" level="6" />
+                <field field_ref="absvisaer" level="6" />
+                <field field_ref="od550lt1aer" level="6" />
+                <field field_ref="sconcso4" level="6" />
+                <field field_ref="sconcoa" level="6" />
+                <field field_ref="sconcbc" level="6" />
+                <field field_ref="sconcss" level="6" />
+                <field field_ref="sconcdust" level="6" />
+                <field field_ref="loadso4" level="6" />
+                <field field_ref="loadoa" level="6" />
+                <field field_ref="loadbc" level="6" />
+                <field field_ref="loadss" level="6" />
+                <field field_ref="loaddust" level="6" />
+                <field field_ref="swtoaas_nat" level="6" />
+                <field field_ref="swsrfas_nat" level="6" />
+                <field field_ref="swtoacs_nat" level="6" />
+                <field field_ref="swsrfcs_nat" level="6" />
+                <field field_ref="swtoaas_ant" level="6" />
+                <field field_ref="swsrfas_ant" level="6" />
+                <field field_ref="swtoacs_ant" level="6" />
+                <field field_ref="swsrfcs_ant" level="6" />
+                <field field_ref="swtoacf_nat" level="6" />
+                <field field_ref="swsrfcf_nat" level="6" />
+                <field field_ref="swtoacf_ant" level="6" />
+                <field field_ref="swsrfcf_ant" level="6" />
+                <field field_ref="swtoacf_zero" level="6" />
+                <field field_ref="swsrfcf_zero" level="6" />
+                <field field_ref="cldncl" level="2" />
+                <field field_ref="reffclwtop" level="2" />
+                <field field_ref="cldnvi" level="2" />
+                <field field_ref="lcc" level="2" />
+                <field field_ref="wvapp" level="6" />
+                <field field_ref="ozone_daylight" level="2" />
+                <field field_ref="albe_ter" level="3" />
+                <field field_ref="albe_lic" level="3" />
+                <field field_ref="albe_oce" level="3" />
+                <field field_ref="albe_sic" level="3" />
+                <field field_ref="ages_ter" level="10" />
+                <field field_ref="ages_lic" level="6" />
+                <field field_ref="ages_oce" level="10" />
+                <field field_ref="ages_sic" level="6" />
+                <field field_ref="snow_ter" level="10" />
+                <field field_ref="snow_lic" level="6" />
+                <field field_ref="snow_oce" level="10" />
+                <field field_ref="snow_sic" level="6" />
+                <field field_ref="rugs_ter" level="3" />
+                <field field_ref="rugs_lic" level="3" />
+                <field field_ref="rugs_oce" level="3" />
+                <field field_ref="rugs_sic" level="3" />
+                <field field_ref="z0m_ter" level="6" />
+                <field field_ref="z0m_lic" level="6" />
+                <field field_ref="z0m_oce" level="6" />
+                <field field_ref="z0m_sic" level="6" />
+                <field field_ref="z0h_ter" level="6" />
+                <field field_ref="z0h_lic" level="6" />
+                <field field_ref="z0h_oce" level="6" />
+                <field field_ref="z0h_sic" level="6" />
+                <field field_ref="alb1" level="3" />
+                <field field_ref="alb2" level="3" />
+                <field field_ref="ftime_con" level="4" operation="instant" />
+                <field field_ref="wake_h" level="6" />
+                <field field_ref="wake_s" level="6" />
+                <field field_ref="plulth" level="10" />
+                <field field_ref="plulst" level="10" />
+                <field field_ref="lmaxth" level="10" />
+                <field field_ref="ftime_th" level="4" />
+                <field field_ref="f0_th" level="6" />
+                <field field_ref="zmax_th" level="6" />
+                <field field_ref="rsut4co2" level="6" />
+                <field field_ref="rlut4co2" level="6" />
+                <field field_ref="rsutcs4co2" level="6" />
+                <field field_ref="rlutcs4co2" level="6" />
+            </field_group>
+
+            <!-- VARS 3D -->
+            <field_group operation="average" freq_op="1ts" grid_ref="grid_glo_presnivs">
+                <field field_ref="cldtau" level="4" />
+                <field field_ref="cldemi" level="4" />
+                <field field_ref="tke_max" level="4" operation="maximum" />
+                <field field_ref="kz" level="4" />
+                <field field_ref="kz_max" level="4" operation="maximum" />
+                <field field_ref="concso4" level="2" />
+                <field field_ref="concoa" level="2" />
+                <field field_ref="concbc" level="2" />
+                <field field_ref="concss" level="2" />
+                <field field_ref="concdust" level="2" />
+                <field field_ref="ec550aer" level="2" />
+                <field field_ref="lwcon" level="2" />
+                <field field_ref="iwcon" level="2" />
+                <field field_ref="temp" level="2" />
+                <field field_ref="theta" level="2" />
+                <field field_ref="ovap" level="2" />
+                <field field_ref="ovapinit" level="2" />
+                <field field_ref="oliq" level="2" />
+                <field field_ref="geop" level="2" />
+                <field field_ref="vitu" level="2" />
+                <field field_ref="vitv" level="2" />
+                <field field_ref="vitw" level="2" />
+                <field field_ref="pres" level="2" />
+                <field field_ref="paprs" level="2" />
+                <field field_ref="mass" level="2" />
+                <field field_ref="zfull" level="2" />
+                <field field_ref="zhalf" level="2" />
+                <field field_ref="rneb" level="2" />
+                <field field_ref="rnebcon" level="2" />
+                <field field_ref="rnebls" level="2" />
+                <field field_ref="rhum" level="2" />
+                <field field_ref="ozone" level="2" />
+                <field field_ref="upwd" level="2" />
+                <field field_ref="dtphy" level="2" />
+                <field field_ref="dqphy" level="2" />
+                <field field_ref="pr_con_l" level="2" />
+                <field field_ref="pr_con_i" level="2" />
+                <field field_ref="pr_lsc_l" level="2" />
+                <field field_ref="pr_lsc_i" level="2" />
+                <field field_ref="re" level="5" />
+                <field field_ref="fl" level="5" />
+                <field field_ref="scdnc" level="2" />
+                <field field_ref="reffclws" level="2" />
+                <field field_ref="reffclwc" level="2" />
+                <field field_ref="lcc3d" level="2" />
+                <field field_ref="lcc3dcon" level="2" />
+                <field field_ref="lcc3dstra" level="2" />
+                <field field_ref="clwcon" level="4" />
+                <field field_ref="Ma" level="6" />
+                <field field_ref="dnwd" level="6" />
+                <field field_ref="dnwd0" level="6" />
+                <field field_ref="mc" level="6" />
+                <field field_ref="dtdyn" level="6" />
+                <field field_ref="dqdyn" level="6" />
+                <field field_ref="dudyn" level="6" />
+                <field field_ref="dvdyn" level="6" />
+                <field field_ref="dtcon" level="6" />
+                <field field_ref="ducon" level="6" />
+                <field field_ref="dvcon" level="6" />
+                <field field_ref="dqcon" level="6" />
+                <field field_ref="dtwak" level="6" />
+                <field field_ref="dqwak" level="6" />
+                <field field_ref="wake_deltat" level="6" />
+                <field field_ref="wake_deltaq" level="6" />
+                <field field_ref="wake_omg" level="6" />
+                <field field_ref="wdtrainA" level="6" />
+                <field field_ref="wdtrainM" level="6" />
+                <field field_ref="Vprecip" level="10" />
+                <field field_ref="ftd" level="6" />
+                <field field_ref="fqd" level="6" />
+                <field field_ref="dtlsc" level="6" />
+                <field field_ref="dtlschr" level="6" />
+                <field field_ref="dqlsc" level="6" />
+                <field field_ref="beta_prec" level="6" />
+                <field field_ref="dtvdf" level="6" />
+                <field field_ref="dtdis" level="6" />
+                <field field_ref="dqvdf" level="6" />
+                <field field_ref="dteva" level="6" />
+                <field field_ref="dqeva" level="6" />
+                <field field_ref="dqlscth" level="10" />
+                <field field_ref="dqlscst" level="10" />
+                <field field_ref="dtlscth" level="10" />
+                <field field_ref="dtlscst" level="10" />
+                <field field_ref="ptconvth" level="10" />
+                <field field_ref="ptconv" level="6" />
+                <field field_ref="ratqs" level="6" />
+                <field field_ref="dtthe" level="6" />
+                <field field_ref="f_th" level="6" />
+                <field field_ref="e_th" level="6" />
+                <field field_ref="w_th" level="6" />
+                <field field_ref="lambda_th" level="10" />
+                <field field_ref="q_th" level="6" />
+                <field field_ref="a_th" level="6" />
+                <field field_ref="d_th" level="6" />
+                <field field_ref="dqthe" level="6" />
+                <field field_ref="dtajs" level="6" />
+                <field field_ref="dqajs" level="6" />
+                <field field_ref="dtswr" level="6" />
+                <field field_ref="dtsw0" level="6" />
+                <field field_ref="dtlwr" level="6" />
+                <field field_ref="dtlw0" level="6" />
+                <field field_ref="dtec"  level="6" />
+                <field field_ref="duvdf" level="6" />
+                <field field_ref="dvvdf" level="6" />
+                <field field_ref="duoro" level="6" />
+                <field field_ref="dvoro" level="6" />
+                <field field_ref="dulif" level="6" />
+                <field field_ref="dvlif" level="6" />
+                <field field_ref="dtoro" level="6" />
+                <field field_ref="dtlif" level="6" />
+                <field field_ref="dthin" level="6" />
+                <field field_ref="rsu" level="6" />
+                <field field_ref="rsd" level="6" />
+                <field field_ref="rlu" level="6" />
+                <field field_ref="rld" level="6" />
+                <field field_ref="rsucs" level="6" />
+                <field field_ref="rsdcs" level="6" />
+                <field field_ref="rlucs" level="6" />
+                <field field_ref="rldcs" level="6" />
+                <field field_ref="tnt"  level="6" />
+                <field field_ref="tntc" level="6" />
+                <field field_ref="tntr" level="6" />
+                <field field_ref="tntscpbl" level="6" />
+                <field field_ref="tnhus"    level="6" />
+                <field field_ref="tnhusc"   level="6" />
+                <field field_ref="tnhusscpbl" level="6" />
+                <field field_ref="evu" level="6" />
+                <field field_ref="h2o" level="6" />
+                <field field_ref="mcd" level="6" />
+                <field field_ref="dmc" level="6" />
+                <field field_ref="ref_liq" level="6" />
+                <field field_ref="ref_ice" level="6" />
+                <field field_ref="rsu4co2" level="6" />
+                <field field_ref="rlu4co2" level="6" />
+                <field field_ref="rsucs4co2" level="6" />
+                <field field_ref="rlucs4co2" level="6" />
+                <field field_ref="rsd4co2" level="6" />
+                <field field_ref="rld4co2" level="6" />
+                <field field_ref="rsdcs4co2" level="6" />
+                <field field_ref="rldcs4co2" level="6" />
+            </field_group>
+        </file>
+
+        </file_group>
+    </file_definition>
+   
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-lim2_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-lim2_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-lim2_paleo.xml	(revision 5879)
@@ -0,0 +1,80 @@
+<?xml version="1.0"?>
+    <!-- $id$ -->
+    
+ <!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files for lim3                                =
+=                                         put the variables you want...                                    =
+============================================================================================================
+  -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->        
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   	
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   	
+
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled="_AUTO_"> <!-- real monthly files -->
+
+	<file id="file16" name_suffix="_icemod" description="ice variables" enabled=".TRUE." >
+
+	  <field field_ref="ice_pres" />
+	  <field field_ref="ice_cover"    name="sic"       long_name="sea_ice_area_fraction"                                           />
+	  <field field_ref="icethic_cea"  name="iicethic"       long_name="sea_ice_thickness"                                               />
+	  <field field_ref="snowthic_cea" name="isnowthi"       long_name="surface_snow_thickness"                                          />
+	  <!-- snc : surface_snow_area_fraction : same as sic -->
+	  <field field_ref="icealb_cea"   name="ialb"      long_name="Bare Sea Ice Albedo"                                             />
+	  <!-- ssi : Sea Ice Salinity : cte = sice = 6, expect in baltic sea = 2 -->
+	  <field field_ref="ist_cea"      name="tsice"     long_name="Surface Temperature of Sea Ice"                                  />
+	  <!-- tsnint : Temperature at Interface Between Sea Ice and Snow : not available -->
+	  <!-- pr : Surface Rainfall Rate into the Sea Ice Portion of the Grid Cell = 0 -->
+	  <field field_ref="snow_ai_cea"  name="prsn"      long_name="Surface Snowfall Rate into the Sea Ice Portion of the Grid Cell" />
+	  <!-- ageice   : Age of Sea Ice : not available ??? -->
+	  <!-- grFrazil : Frazil Sea Ice Growth (Leads) Rate ??? -->
+	  <!-- grCongel : Congelation Sea Ice Growth Rate ??? -->
+	  <!-- field field_ref="licepro_cea"  name="grLateral" long_name="Lateral Sea Ice Growth Rate"                                  -->
+	  <field field_ref="sntoice_cea"  name="snoToIce"  long_name="Snow-Ice Formation Rate"                                         />
+	  <field field_ref="snowmel_cea"  name="snomelt"   long_name="Snow Melt Rate"                                                  />
+	  <field field_ref="ticemel_cea"  name="tmelt"     long_name="Rate of Melt at Upper Surface of Sea Ice"                        />
+	  <field field_ref="bicemel_cea"  name="bmelt"     long_name="Rate of Melt at Sea Ice Base"                                    />
+	  <!-- hcice  : Sea Ice Total Heat Content ??? -->
+	  <field field_ref="qsr_ai_cea"   name="rsdssi"    long_name="surface_downwelling_shortwave_flux_in_air"                       />
+	  <!-- rsussi : surface_upwelling_shortwave_flux_in_air ??? -->
+	  <!-- rldssi : surface_downwelling_longwave_flux_in_air ??? -->
+	  <!-- rlussi : surface_upwelling_longwave_flux_in_air ??? -->
+	  <!-- hfssi  : surface_upward_sensible_heat_flux ??? -->
+	  <!-- hflssi : surface_upward_latent_heat_flux ??? -->
+	  <field field_ref="subl_ai_cea"  name="sblsi"     long_name="surface_snow_and_ice_sublimation_flux"                           />
+	  <!-- field field_ref="u_imasstr"    name="transix"   long_name="Eastward Sea Ice Transport"                                   -->
+	  <!-- field field_ref="v_imasstr"    name="transiy"   long_name="Northward Sea Ice Transport"                                  -->
+      <!-- field field_ref="fram_trans"   name="transifs"  long_name="Sea Ice Mass Transport Through Fram Strait"                   -->
+	  <!-- field field_ref="utau_ice"     name="strairx"   long_name="Eastward Atmospheric Stress On Sea Ice"                       -->
+	  <!-- field field_ref="vtau_ice"     name="strairy"   long_name="Northward Atmospheric Stress On Sea Ice"                      -->
+	  <!-- strocnx : Eastward Ocean Stress On Sea Ice ??? -->
+	  <!-- strocny : Northward Ocean Stress On Sea Ice ??? -->
+	  <!-- streng  : Compressive Sea Ice Strength ??? -->
+	  <!-- divice  : Strain Rate Divergence of Sea Ice ??? -->
+	  <!-- shrice  : Strain Rate Shear of Sea Ice ??? -->
+	  <!-- ridgice : Sea Ice Ridging Rate ??? -->
+
+	</file>
+
+      </file_group>
+
+
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled=".TRUE."/> <!-- real yearly files -->
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-opa_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-opa_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-opa_paleo.xml	(revision 5879)
@@ -0,0 +1,556 @@
+<?xml version="1.0"?>
+
+<!--
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own filesfor ocean dynamics context                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+   
+    <file_definition type="one_file" name="@expname@_@freq@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+    
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled="_AUTO_">  <!-- 5d files -->   
+	
+        <file id="file1" name_suffix="_grid_T" description="ocean T grid variables" >
+	  <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+	  <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+	  <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+	  <field field_ref="sst"          name="tosstd"   long_name="sea_surface_temperature_standard_deviation"         operation="average" freq_op="1d" > sqrt( @sst2 - @sst * @sst ) </field>
+	  <field field_ref="ssh"          name="zosstd"   long_name="sea_surface_height_above_geoid_standard_deviation"  operation="average" freq_op="1d" > sqrt( @ssh2 - @ssh * @ssh ) </field>
+	  <field field_ref="sst"          name="sstdcy"   long_name="amplitude of sst diurnal cycle" operation="average" freq_op="1d" > @sstmax - @sstmin </field>
+	  <field field_ref="mldr10_1"     />
+	  <field field_ref="mldr10_1"     name="mldr10_1dcy"  long_name="amplitude of mldr10_1 diurnal cycle" operation="average" freq_op="1d" > @mldr10_1max - @mldr10_1min </field>
+	</file>
+       
+        <file id="file2" name_suffix="_scalar" description="scalar variables" >
+           <field field_ref="voltot"      grid_ref="grid_1point"     name="scvoltot"  />
+           <field field_ref="sshtot"      grid_ref="grid_1point"     name="scsshtot"  />
+           <field field_ref="sshsteric"   grid_ref="grid_1point"   name="scsshste"  />
+           <field field_ref="sshthster"   grid_ref="grid_1point"   name="scsshtst"  />
+           <field field_ref="masstot"     grid_ref="grid_1point"   name="scmastot"  />
+           <field field_ref="temptot"     grid_ref="grid_1point"   name="sctemtot"  />
+           <field field_ref="saltot"      grid_ref="grid_1point"   name="scsaltot"  />
+
+          <field field_ref="bgtemper"     grid_ref="grid_1point" name="bgtemper"    />
+          <field field_ref="bgsaline"     grid_ref="grid_1point" name="bgsaline"    />
+          <field field_ref="bgheatco"     grid_ref="grid_1point" name="bgheatco"    />
+          <field field_ref="bgsaltco"     grid_ref="grid_1point" name="bgsaltco"    />
+          <field field_ref="bgvolssh"     grid_ref="grid_1point" name="bgvolssh"    /> 
+          <field field_ref="bgvole3t"     grid_ref="grid_1point" name="bgvole3t"    />
+          <field field_ref="bgfrcvol"     grid_ref="grid_1point" name="bgfrcvol"    />
+          <field field_ref="bgfrctem"     grid_ref="grid_1point" name="bgfrctem"    />
+          <field field_ref="bgfrcsal"     grid_ref="grid_1point" name="bgfrcsal"    />
+	</file>
+
+        <file id="file3" name_suffix="_SBC_scalar" description="scalar variables" >
+      <field field_ref="ibgvoltot"  grid_ref="grid_1point"  name="ibgvoltot"   />
+      <field field_ref="sbgvoltot"  grid_ref="grid_1point"  name="sbgvoltot"   />
+      <field field_ref="ibgarea"    grid_ref="grid_1point"  name="ibgarea"     />
+      <field field_ref="ibgsaline"  grid_ref="grid_1point"  name="ibgsaline"   />
+      <field field_ref="ibgtemper"  grid_ref="grid_1point"  name="ibgtemper"   />
+      <field field_ref="ibgheatco"  grid_ref="grid_1point"  name="ibgheatco"   />
+      <field field_ref="sbgheatco"  grid_ref="grid_1point"  name="sbgheatco"   />
+      <field field_ref="ibgsaltco"  grid_ref="grid_1point"  name="ibgsaltco"   />
+      
+      <field field_ref="ibgvfx"     grid_ref="grid_1point"  name="ibgvfx"      />
+      <field field_ref="ibgvfxbog"  grid_ref="grid_1point"  name="ibgvfxbog"      />
+      <field field_ref="ibgvfxopw"  grid_ref="grid_1point"  name="ibgvfxopw"      />
+      <field field_ref="ibgvfxsni"  grid_ref="grid_1point"  name="ibgvfxsni"      />
+      <field field_ref="ibgvfxdyn"  grid_ref="grid_1point"  name="ibgvfxdyn"      />
+      <field field_ref="ibgvfxbom"  grid_ref="grid_1point"  name="ibgvfxbom"      />
+      <field field_ref="ibgvfxsum"  grid_ref="grid_1point"  name="ibgvfxsum"      />
+      <field field_ref="ibgvfxres"  grid_ref="grid_1point"  name="ibgvfxres"      />
+      <field field_ref="ibgvfxspr"  grid_ref="grid_1point"  name="ibgvfxspr"      />
+      <field field_ref="ibgvfxsnw"  grid_ref="grid_1point"  name="ibgvfxsnw"      />
+      <field field_ref="ibgvfxsub"  grid_ref="grid_1point"  name="ibgvfxsub"      />
+      
+      <field field_ref="ibgsfx"     grid_ref="grid_1point"  name="ibgsfx"     />
+      <field field_ref="ibgsfxbri"  grid_ref="grid_1point"  name="ibgsfxbri"    />
+      <field field_ref="ibgsfxdyn"  grid_ref="grid_1point"  name="ibgsfxdyn" />
+      <field field_ref="ibgsfxres"  grid_ref="grid_1point"  name="ibgsfxres" />
+      <field field_ref="ibgsfxbog"  grid_ref="grid_1point"  name="ibgsfxbog"      />
+      <field field_ref="ibgsfxopw"  grid_ref="grid_1point"  name="ibgsfxopw"      />
+      <field field_ref="ibgsfxsni"  grid_ref="grid_1point"  name="ibgsfxsni"      />
+      <field field_ref="ibgsfxbom"  grid_ref="grid_1point"  name="ibgsfxbom"      />
+      <field field_ref="ibgsfxsum"  grid_ref="grid_1point"  name="ibgsfxsum"      />
+      
+      <field field_ref="ibghfxdhc"  grid_ref="grid_1point"  name="ibghfxdhc"    />
+      <field field_ref="ibghfxspr"  grid_ref="grid_1point"  name="ibghfxspr"    />
+      
+      <field field_ref="ibghfxres"   grid_ref="grid_1point" name="ibghfxres"    />
+      <field field_ref="ibghfxsub"   grid_ref="grid_1point" name="ibghfxsub"    />
+      <field field_ref="ibghfxdyn"   grid_ref="grid_1point" name="ibghfxdyn"    />
+      <field field_ref="ibghfxthd"   grid_ref="grid_1point" name="ibghfxthd"    />
+      <field field_ref="ibghfxsum"   grid_ref="grid_1point" name="ibghfxsum"    />
+      <field field_ref="ibghfxbom"   grid_ref="grid_1point" name="ibghfxbom"    />
+      <field field_ref="ibghfxbog"   grid_ref="grid_1point" name="ibghfxbog"    />
+      <field field_ref="ibghfxdif"   grid_ref="grid_1point" name="ibghfxdif"    />
+      <field field_ref="ibghfxopw"   grid_ref="grid_1point" name="ibghfxopw"    />
+      <field field_ref="ibghfxout"   grid_ref="grid_1point" name="ibghfxout"    />
+      <field field_ref="ibghfxin"   grid_ref="grid_1point"  name="ibghfxin"     />
+      <field field_ref="ibghfxsnw"   grid_ref="grid_1point" name="ibghfxsnw"    />
+      
+      <field field_ref="ibgfrcvol"   grid_ref="grid_1point" name="ibgfrcvol"   />
+      <field field_ref="ibgfrcsfx"   grid_ref="grid_1point" name="ibgfrcsfx"  />
+      <field field_ref="ibgvolgrm"   grid_ref="grid_1point" name="ibgvolgrm"    />
+      
+        </file>
+
+	<file id="file4" name_suffix="_SBC" description="surface fluxes variables" > <!-- time step automaticaly defined based on nn_fsbc -->
+	  <field field_ref="qsr_oce"       name="qsr_oce"  long_name="downward shortwave flux at ocean surface"           />
+	  <field field_ref="qns_oce"       name="qns_oce"  long_name="downward non solar flux at ocean surface"           />
+	  <field field_ref="qsr_ice"       name="qsr_ice"  long_name="downward shortwave flux at ice surface"           />
+	  <field field_ref="qns_ice"       name="qns_ice"  long_name="downward non solar flux at ice surface"           />
+	  <field field_ref="qtr_ice"       name="qtr_ice"  long_name="shortwave flux transmitted thru the ice"           />
+	  <field field_ref="taum"          name="taum" />
+	  <field field_ref="wspd"          name="windsp"  />
+	  <field field_ref="precip"        name="precip" />
+	  <!-- For heat conservation checking -->
+	  <field field_ref="qt_oce"        name="qt_oce"   long_name="downward total flux at ocean surface"           />
+	  <field field_ref="qemp_oce"      name="qemp_oce" long_name="Downward Heat Flux from E-P over open ocean"           />
+	  <field field_ref="qt_ice"        name="qt_ice"   long_name="downward total flux at ice surface"           />
+	  <field field_ref="qemp_ice"      name="qemp_ice" long_name="Downward Heat Flux from E-P over ice"           />
+	  <field field_ref="hflx_rain_cea" name="hflx_rain_cea"      />
+	  <field field_ref="hflx_evap_cea" name="hflx_evap_cea"      />
+	  <field field_ref="hflx_snow_cea" name="hflx_snow_cea"      />
+	  <field field_ref="hflx_cal_cea"  name="hflx_cal_cea"      />
+	  <!-- For freshwater conservation checking -->
+	  <field field_ref="empmr"         name="wfo"      long_name="water_flux_into_sea_water"                     />
+	  <field field_ref="emp_oce"       name="emp_oce"                      />
+	  <field field_ref="emp_ice"       name="emp_ice"                      />
+          <field field_ref="runoffs"       name="friver"   long_name="water_flux_into_sea_water_from_rivers"                   level="1" />
+	  <field field_ref="calving_cea"   name="calving" />
+	  <field field_ref="vfxice"        name="vfxice" />
+	  <field field_ref="vfxsnw"        name="vfxsnw" />
+	  <field field_ref="vfxsub"        name="vfxsub" />
+	  <field field_ref="vfxspr"        name="vfxspr" />
+	  <field field_ref="rain"          name="rain"      />
+	  <field field_ref="snow_ao_cea"   name="snow_ao_cea"      />
+	  <field field_ref="snow_ai_cea"   name="snow_ai_cea"      />
+	  <field field_ref="evap_ao_cea"   name="evap_ao_cea"      />
+	  <field field_ref="subl_ai_cea"   name="subl_ai_cea"      />
+	  <!-- For salt conservation checking -->
+          <field field_ref="saltflx"      name="sosflxdo"  />
+	  <!-- ice and snow -->
+	  <field field_ref="snowpre"      />
+	  <field field_ref="utau_ice"         name="utau_ice" />
+	  <field field_ref="vtau_ice"         name="vtau_ice" />
+	</file>
+
+      </file_group> 
+
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   
+	
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled="_AUTO_"> <!-- real monthly files -->
+
+        <file id="file5" name_suffix="_grid_T" >
+	  <field field_ref="e3t" long_name="T-cell thickness" />
+          <!-- pso : sea_water_pressure_at_sea_water_surface = 0 -->
+          <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                              level="1" />
+          <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                                 level="1" />
+          <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                                 />
+          <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"                    level="2" />
+          <field field_ref="ssh2"         name="zossq"    long_name="square_of_sea_surface_height_above_geoid"             level="2" />
+          <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"   operation="average" freq_op="1mo" > @toce_e3t / @e3t </field>      
+          <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                operation="average" freq_op="1mo" > @soce_e3t / @e3t </field>       
+          <field field_ref="rhop"         name="rhopoto"  long_name="sea_water_potential_density"                          level="2" />
+          <field field_ref="heatc"        name="heatc"         level="2" />
+          <field field_ref="saltc"        name="saltc"         level="2" />
+          <field field_ref="botpres"      name="pbo"      long_name="Pressure_at_sea_floor"                                          />
+          <!-- no agessc : sea_water_age_since_surface_contact -->
+          <!-- no cfc11  : moles_per_unit_mass_of_cfc11_in_sea_water -->
+          <!-- msftbarot : ocean_barotropic_mass_streamfunction : offline -->
+          <!-- mlotst    :           ocean_mixed_layer_thickness_defined_by_sigma_t : must be done offline -->
+          <!-- mlotstsq  : square_of_ocean_mixed_layer_thickness_defined_by_sigma_t : must be done offline -->
+          <field field_ref="mldkz5"       name="omlmax"   long_name="ocean_mixed_layer_thickness_defined_by_mixing_scheme" level="2" operation="maximum" />
+          <field field_ref="mldkz5"       name="mldkz5"   level="2"  />
+          <field field_ref="mldr10_1"     name="mldr10_1" level="2" />
+          <field field_ref="mldr10_1max"  name="mldr10_1max"  long_name="max of Mixed Layer Depth 0.01 ref.10m"              operation="maximum" />
+          <!-- wfonocorr : water_flux_into_sea_water_without_flux_correction : emp - erp -->
+          <!-- No restoring term in coupled mode paleo?
+          <field field_ref="qrp"           name="hfcorr"      long_name="heat_flux_correction"                                level="1" />
+          <field field_ref="erp"          name="wfcorr"   long_name="water_flux_correction"                                   level="1" />  usually = 0        -->
+          <field field_ref="qt"           name="tohfls"      long_name="surface_net_downward_total_heat_flux"                                         level="1" />
+          <field field_ref="qns"           name="nshfls"      long_name="surface_net_downward_non_solar_flux"                                         level="1" />
+          <field field_ref="qsr"           name="rsntds"      long_name="surface_net_downward_shortwave_flux"                                         level="1" />
+          <field field_ref="qsr3d"         name="rsds"        long_name="downwelling_shortwave_flux_in_sea_water"                                     level="1" />
+      <!-- next variables available with key_diahth -->
+      <field field_ref="mlddzt"        level="1" />
+      <field field_ref="mldr10_3"      level="1" />
+      <field field_ref="mldr0_1"       level="1" />
+      <field field_ref="mldr0_3"       level="1" />
+      <field field_ref="mld_dt02"      level="1" />
+      <field field_ref="topthdep"      level="1" />
+      <field field_ref="pycndep"       level="1" />
+      <field field_ref="BLT"           level="1" />
+      <field field_ref="tinv"          level="1" />
+      <field field_ref="depti"         level="1" />
+      <!-- <field field_ref="20d"           level="1" /> -->
+      <!-- <field field_ref="28d"           level="1" /> -->
+      <field field_ref="hc300"         level="1" />
+      <!-- next variables are additional for PISCES offline-->
+      <field field_ref="hdiv"         name="hdivtr"   long_name="horizontal divergence transport"      operation="average" freq_op="1mo" > @hdiv * @e3t </field>
+      <field field_ref="eken"         name="eken"  />
+      <field field_ref="wspd"         name="windsp"  />
+      <field field_ref="taum"         name="taum"  />
+      <field field_ref="empbmr"       name="wfob"     long_name="water_flux_into_sea_water at prev time-step"    />
+      <field field_ref="fmmflx"       name="fmmflx"  />
+      <field field_ref="ice_cover"    name="siconc"  />
+      <!-- For heat conservation checking -->
+      <!-- Defined in LIM3... 
+      <field field_ref="qt_oce"        name="qt_oce"   long_name="downward total flux at ocean surface"        />
+      <field field_ref="qemp_oce"      name="qemp_oce" long_name="Downward Heat Flux from E-P over open ocean" />
+	  <field field_ref="qt_ice"        name="qt_ice"   long_name="downward total flux at ice surface"           />
+      <field field_ref="qemp_ice"      name="qemp_ice" long_name="Downward Heat Flux from E-P over ice"           />   -->
+	  <field field_ref="hflx_rain_cea" name="hflx_rain_cea"      />
+	  <field field_ref="hflx_evap_cea" name="hflx_evap_cea"      />
+	  <field field_ref="hflx_snow_cea" name="hflx_snow_cea"      />
+	  <field field_ref="hflx_cal_cea"  name="hflx_cal_cea"      />
+	  <!-- For freshwater conservation checking -->
+	  <field field_ref="empmr"         name="wfo"      long_name="water_flux_into_sea_water"                     />
+      <!-- DEFINED in LIM3...
+	  <field field_ref="emp_oce"       name="emp_oce"                      />
+      <field field_ref="emp_ice"       name="emp_ice"                      />    -->
+      <field field_ref="runoffs"       name="friver"   long_name="water_flux_into_sea_water_from_rivers"                   level="1" />
+      <field field_ref="calving_cea"   name="calving" />
+      <!-- DEFINED in LIM3...
+	  <field field_ref="vfxice"        name="vfxice" />
+	  <field field_ref="vfxsnw"        name="vfxsnw" />
+	  <field field_ref="vfxsub"        name="vfxsub" />
+      <field field_ref="vfxspr"        name="vfxspr" />  -->
+	  <field field_ref="rain"          name="rain"      />
+      <field field_ref="snowpre"       name="snowpre"/>
+	  <field field_ref="snow_ao_cea"   name="snow_ao_cea"      />
+	  <field field_ref="snow_ai_cea"   name="snow_ai_cea"      />
+	  <field field_ref="evap_ao_cea"   name="evap_ao_cea"      />
+	  <field field_ref="subl_ai_cea"   name="subl_ai_cea"      />
+	  <!-- For salt conservation checking -->
+          <field field_ref="saltflx"      name="sosflxdo"  />
+        </file>
+
+	<file id="file6" name_suffix="_grid_U" description="ocean U grid variables" >
+	  <field field_ref="e3u"  />
+	  <field field_ref="ssu"          name="uos"     long_name="sea_surface_x_velocity"    />
+	  <field field_ref="uoce"         name="uo"      long_name="sea_water_x_velocity" operation="average" freq_op="1mo" > @uoce_e3u / @e3u </field>
+	  <field field_ref="uoce_eiv"     name="uo_eiv"  />
+	  <field field_ref="uocet"        name="uocet"  />
+	  <field field_ref="uoces"        name="uoces"  />
+	  <field field_ref="utau"         name="tauuo"   long_name="surface_downward_x_stress" />
+      <field field_ref="uocetr_eff"   name="uocetr_eff"  />
+      <field field_ref="sbu"          name="sbu"  />
+      <field field_ref="ahu_bbl"      name="ahu_bbl" />
+      <!-- available with key_diaar5 -->
+      <field field_ref="u_masstr"     name="vozomatr"  />
+      <field field_ref="u_heattr"     name="sozohetr"  />
+      <field field_ref="u_salttr"     name="sozosatr"  />
+      <field field_ref="ueiv_heattr"  name="sozohetr_eiv"  />
+      <field field_ref="udiff_heattr" name="sozohetr_diff"  />
+	</file>
+	
+	<file id="file7" name_suffix="_grid_V" description="ocean V grid variables" >
+	  <field field_ref="e3v"  />
+	  <field field_ref="ssv"          name="vos"     long_name="sea_surface_y_velocity"    />
+	  <field field_ref="voce"         name="vo"      long_name="sea_water_y_velocity" operation="average" freq_op="1mo" > @voce_e3v / @e3v </field>
+	  <field field_ref="voce_eiv"     name="vo_eiv"  />
+	  <field field_ref="vocet"        name="vocet"  />
+	  <field field_ref="voces"        name="voces"  />
+	  <field field_ref="vtau"         name="tauvo"   long_name="surface_downward_y_stress" />
+      <field field_ref="vocetr_eff"   name="vocetr_eff"  />
+      <field field_ref="sbv"          name="sbv"  />
+      <field field_ref="ahv_bbl"      name="ahv_bbl" />
+      <!-- available with key_diaar5 -->
+      <field field_ref="v_masstr"       name="vomematr"  />
+      <field field_ref="v_heattr"       name="somehetr"  />
+      <field field_ref="v_salttr"       name="somesatr"  />
+      <field field_ref="veiv_heattr"    name="somehetr_eiv"  />
+      <field field_ref="vdiff_heattr"   name="somehetr_diff"  />
+	</file>
+	
+	<file id="file8" name_suffix="_grid_W" description="ocean W grid variables" >
+	  <field field_ref="e3w"  />
+	  <field field_ref="woce"         name="wo"     />
+	  <field field_ref="woce_eiv"     name="woce_eiv"     />
+	  <field field_ref="wocetr_eff"   name="wocetr_eff"  />
+	  <field field_ref="avt"          name="difvho"  long_name="ocean_vertical_heat_diffusivity" />
+	  <field field_ref="logavt"       name="difvholog"  long_name="logarithm_of_ocean_vertical_heat_diffusivity" />
+	  <field field_ref="w_masstr"     name="vovematr"  />
+      <!-- field field_ref="logavs"       name="difvsolog"  long_name="ocean_vertical_salt_diffusivity" operation="average" freq_op="1mo" > exp( @logavs ) </field> -->
+      <field field_ref="avs"          name="difvso"  long_name="ocean_vertical_salt_diffusivity" /> 
+      <field field_ref="logavs"       name="difvsolog"  long_name="logarithm_of_ocean_vertical_salt_diffusivity" />
+      <field field_ref="bn2"          name="bn2"  />
+      <field field_ref="av_tide"      name="av_tide"  />
+      <field field_ref="aht2d"        name="ahtt"   />
+      <field field_ref="aht2d_eiv"    name="aeiv"   />
+	</file>
+
+	<file id="file9" name_suffix="_scalar" description="scalar variables" enabled=".true." >
+      <field field_ref="voltot"   grid_ref="grid_1point"    name="scvoltot"  />
+      <field field_ref="sshtot"   grid_ref="grid_1point"    name="scsshtot"  />
+      <field field_ref="sshsteric" grid_ref="grid_1point"   name="scsshste"  />
+      <field field_ref="sshthster" grid_ref="grid_1point"   name="scsshtst"  />
+      <field field_ref="masstot"    grid_ref="grid_1point"  name="scmastot"  />
+      <field field_ref="temptot"   grid_ref="grid_1point"   name="sctemtot"  />
+      <field field_ref="saltot"    grid_ref="grid_1point"   name="scsaltot"  />
+
+      <!-- field field_ref="bgtemper"   grid_ref="grid_1point"  name="bgtemper"    />
+      <field field_ref="bgsaline"   grid_ref="grid_1point"  name="bgsaline"    />
+      <field field_ref="bgheatco"   grid_ref="grid_1point"  name="bgheatco"    />
+      <field field_ref="bgsaltco"   grid_ref="grid_1point"  name="bgsaltco"    />
+      <field field_ref="bgvolssh"   grid_ref="grid_1point"  name="bgvolssh"    /> 
+      <field field_ref="bgvole3t"   grid_ref="grid_1point"  name="bgvole3t"    />
+      <field field_ref="bgfrcvol"   grid_ref="grid_1point"  name="bgfrcvol"    />
+      <field field_ref="bgfrctem"   grid_ref="grid_1point"  name="bgfrctem"    />
+      <field field_ref="bgfrcsal"   grid_ref="grid_1point"  name="bgfrcsal"    />
+
+      <field field_ref="ibgvoltot"  grid_ref="grid_1point"  name="ibgvoltot"   />
+      <field field_ref="sbgvoltot"  grid_ref="grid_1point"  name="sbgvoltot"   />
+      <field field_ref="ibgarea"    grid_ref="grid_1point"  name="ibgarea"     />
+      <field field_ref="ibgsaline"  grid_ref="grid_1point"  name="ibgsaline"   />
+      <field field_ref="ibgtemper"  grid_ref="grid_1point"  name="ibgtemper"   />
+      <field field_ref="ibgheatco"  grid_ref="grid_1point"  name="ibgheatco"   />
+      <field field_ref="sbgheatco"   grid_ref="grid_1point" name="sbgheatco"   />
+      <field field_ref="ibgsaltco"   grid_ref="grid_1point" name="ibgsaltco"   />
+
+      <field field_ref="ibgvfx"     grid_ref="grid_1point"  name="ibgvfx"      />
+      <field field_ref="ibgvfxbog"  grid_ref="grid_1point"  name="ibgvfxbog"      />
+      <field field_ref="ibgvfxopw"  grid_ref="grid_1point"  name="ibgvfxopw"      />
+      <field field_ref="ibgvfxsni"  grid_ref="grid_1point"  name="ibgvfxsni"      />
+      <field field_ref="ibgvfxdyn"  grid_ref="grid_1point"  name="ibgvfxdyn"      />
+      <field field_ref="ibgvfxbom"  grid_ref="grid_1point"  name="ibgvfxbom"      />
+      <field field_ref="ibgvfxsum"  grid_ref="grid_1point"  name="ibgvfxsum"      />
+      <field field_ref="ibgvfxres"  grid_ref="grid_1point"  name="ibgvfxres"      />
+      <field field_ref="ibgvfxspr"  grid_ref="grid_1point"  name="ibgvfxspr"      />
+      <field field_ref="ibgvfxsnw"  grid_ref="grid_1point"  name="ibgvfxsnw"      />
+      <field field_ref="ibgvfxsub"  grid_ref="grid_1point"  name="ibgvfxsub"      />
+
+      <field field_ref="ibgsfx"     grid_ref="grid_1point"  name="ibgsfx"     />
+      <field field_ref="ibgsfxbri"   grid_ref="grid_1point" name="ibgsfxbri"    />
+      <field field_ref="ibgsfxdyn"   grid_ref="grid_1point" name="ibgsfxdyn" />
+      <field field_ref="ibgsfxres"  grid_ref="grid_1point"  name="ibgsfxres" />
+      <field field_ref="ibgsfxbog"  grid_ref="grid_1point"  name="ibgsfxbog"      />
+      <field field_ref="ibgsfxopw"  grid_ref="grid_1point"  name="ibgsfxopw"      />
+      <field field_ref="ibgsfxsni"  grid_ref="grid_1point"  name="ibgsfxsni"      />
+      <field field_ref="ibgsfxbom"  grid_ref="grid_1point"  name="ibgsfxbom"      />
+      <field field_ref="ibgsfxsum"  grid_ref="grid_1point"  name="ibgsfxsum"      />
+
+      <field field_ref="ibghfxdhc"  grid_ref="grid_1point"  name="ibghfxdhc"    />
+      <field field_ref="ibghfxspr"  grid_ref="grid_1point"  name="ibghfxspr"    />
+
+      <field field_ref="ibghfxres" grid_ref="grid_1point"   name="ibghfxres"    />
+      <field field_ref="ibghfxsub"  grid_ref="grid_1point"  name="ibghfxsub"    />
+      <field field_ref="ibghfxdyn"  grid_ref="grid_1point"  name="ibghfxdyn"    />
+      <field field_ref="ibghfxthd"  grid_ref="grid_1point"   name="ibghfxthd"    />
+      <field field_ref="ibghfxsum"  grid_ref="grid_1point"   name="ibghfxsum"    />
+      <field field_ref="ibghfxbom"  grid_ref="grid_1point"   name="ibghfxbom"    />
+      <field field_ref="ibghfxbog"  grid_ref="grid_1point"   name="ibghfxbog"    />
+      <field field_ref="ibghfxdif"  grid_ref="grid_1point"   name="ibghfxdif"    />
+      <field field_ref="ibghfxopw"  grid_ref="grid_1point"   name="ibghfxopw"    />
+      <field field_ref="ibghfxout"  grid_ref="grid_1point"   name="ibghfxout"    />
+      <field field_ref="ibghfxin"   grid_ref="grid_1point"  name="ibghfxin"    />
+      <field field_ref="ibghfxsnw"  grid_ref="grid_1point"   name="ibghfxsnw"    />
+
+      <field field_ref="ibgfrcvol"   grid_ref="grid_1point"  name="ibgfrcvol"   />
+      <field field_ref="ibgfrcsfx"   grid_ref="grid_1point"  name="ibgfrcsfx"  />
+      <field field_ref="ibgvolgrm"   grid_ref="grid_1point"  name="ibgvolgrm"    -->
+
+        </file>
+
+	<file id="file10" name_suffix="_diaptr" description="diaptr variables" enabled=".true." >
+	  <field field_ref="zomsfglo"          name="zomsfglo"  grid_ref="grid_ptr_W_3D" />
+          <field field_ref="zomsfatl"          name="zomsfatl"  grid_ref="grid_ptr_W_3D" />
+          <field field_ref="zomsfpac"          name="zomsfpac"  grid_ref="grid_ptr_W_3D" />
+          <field field_ref="zomsfind"          name="zomsfind"  grid_ref="grid_ptr_W_3D" />
+          <field field_ref="zomsfipc"          name="zomsfipc"  grid_ref="grid_ptr_W_3D" />
+          <field field_ref="zotemglo"          name="zotemglo"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zotematl"          name="zotematl"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zotempac"          name="zotempac"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zotemind"          name="zotemind"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zotemipc"          name="zotemipc"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosalglo"          name="zosalglo"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosalatl"          name="zosalatl"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosalpac"          name="zosalpac"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosalind"          name="zosalind"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosalipc"          name="zosalipc"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosrfglo"          name="zosrfglo"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosrfatl"          name="zosrfatl"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosrfpac"          name="zosrfpac"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosrfind"          name="zosrfind"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="zosrfipc"          name="zosrfipc"  grid_ref="grid_ptr_T_3D" />
+          <field field_ref="sophtadv"          name="sophtadv"  grid_ref="grid_ptr_T_2D" />
+          <field field_ref="sophtldf"          name="sophtldf"  grid_ref="grid_ptr_T_2D" />
+          <field field_ref="sopstadv"          name="sopstadv"  grid_ref="grid_ptr_T_2D" />
+          <field field_ref="sopstldf"          name="sopstldf"  grid_ref="grid_ptr_T_2D" />
+        </file>
+
+      </file_group>
+
+
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled="_AUTO_"> <!-- real yearly files -->
+
+    <file id="file11" name_suffix="_grid_T" description="ocean T grid variables" >
+      <field field_ref="e3t"  />
+      <field field_ref="sst"          name="tos"      long_name="sea_surface_temperature"                       />
+      <field field_ref="sss"          name="sos"      long_name="sea_surface_salinity"                          />
+      <field field_ref="ssh"          name="zos"      long_name="sea_surface_height_above_geoid"                />
+      <field field_ref="toce"         name="thetao"   long_name="sea_water_potential_temperature"      operation="average" freq_op="1y" > @toce_e3t / @e3t </field>        
+      <field field_ref="soce"         name="so"       long_name="sea_water_salinity"                   operation="average" freq_op="1y" > @soce_e3t / @e3t </field>         
+      <field field_ref="sst2"         name="tossq"    long_name="square_of_sea_surface_temperature"             />
+      <field field_ref="ssh2"         name="zossq"    long_name="square_of_sea_surface_height_above_geoid"      />
+      <field field_ref="rhop"         name="rhopoto"  long_name="sea_water_potential_density"                          level="2" />
+      <field field_ref="heatc"        name="heatc"         level="2" />
+      <field field_ref="saltc"        name="saltc"         level="2" />
+      <field field_ref="mldr10_1"     />
+      <field field_ref="mldkz5"       name="omlmax"   long_name="ocean_mixed_layer_thickness_defined_by_mixing_scheme" level="2" operation="maximum" />
+      <!-- field field_ref="erp"          name="wfcorr"   long_name="water_flux_correction"                                   level="1" /> usually = 0 -->
+      <field field_ref="qns"          name="nshfls"      long_name="surface_net_downward_non_solar_flux"                                         level="1" />
+      <field field_ref="qsr"          name="rsntds"      long_name="surface_net_downward_shortwave_flux"                                         level="1" />
+      <field field_ref="qsr3d"        name="rsds"        long_name="downwelling_shortwave_flux_in_sea_water"                                     level="1" />
+      <field field_ref="qt"           name="tohfls"   long_name="surface_net_downward_total_heat_flux"          />
+      <field field_ref="taum"         name="taum" />
+      <field field_ref="wspd"         name="windsp"  />
+      <!-- field field_ref="precip"       name="soprecip" />    -->
+      <!-- available with ln_blk_clio or ln_blk_core -->
+      <!-- field field_ref="qns_oce"      name="sonshdoo"  />
+      <field field_ref="qlw_oce"      name="solwhdoo"  />
+      <field field_ref="qsb_oce"      name="sosehdoo"  />
+      <field field_ref="qla_oce"      name="solahdoo"  />
+      <field field_ref="taum_oce"     name="sowndsto"  /> -->
+      <!-- ice and snow -->
+      <field field_ref="snowpre"      name="snowpre"/>
+      <!-- field field_ref="utau_ice"     name="iicestru" />
+      <field field_ref="vtau_ice"     name="iicestrv" />   -->
+	  <!-- For heat conservation checking -->
+	  <!-- field field_ref="qt_oce"        name="qt_oce"   long_name="downward total flux at ocean surface"           />
+	  <field field_ref="qemp_oce"      name="qemp_oce" long_name="Downward Heat Flux from E-P over open ocean"           />
+	  <field field_ref="qt_ice"        name="qt_ice"   long_name="downward total flux at ice surface"           />
+      <field field_ref="qemp_ice"      name="qemp_ice" long_name="Downward Heat Flux from E-P over ice"           />  -->
+	  <field field_ref="hflx_rain_cea" name="hflx_rain_cea"      />
+	  <field field_ref="hflx_evap_cea" name="hflx_evap_cea"      />
+	  <field field_ref="hflx_snow_cea" name="hflx_snow_cea"      />
+	  <field field_ref="hflx_cal_cea"  name="hflx_cal_cea"      />
+	  <!-- For freshwater conservation checking -->
+	  <field field_ref="empmr"         name="wfo"      long_name="water_flux_into_sea_water"                     />
+	  <!-- field field_ref="emp_oce"       name="emp_oce"                      />
+      <field field_ref="emp_ice"       name="emp_ice"                      />  -->
+      <field field_ref="runoffs"       name="friver"   long_name="water_flux_into_sea_water_from_rivers"                   level="1" />
+	  <field field_ref="calving_cea"   name="calving" />
+	  <!-- field field_ref="vfxice"        name="vfxice" />
+	  <field field_ref="vfxsnw"        name="vfxsnw" />
+	  <field field_ref="vfxsub"        name="vfxsub" />
+      <field field_ref="vfxspr"        name="vfxspr" />  -->
+	  <field field_ref="rain"          name="rain"      />
+	  <field field_ref="snow_ao_cea"   name="snow_ao_cea"      />
+	  <field field_ref="snow_ai_cea"   name="snow_ai_cea"      />
+	  <field field_ref="evap_ao_cea"   name="evap_ao_cea"      />
+	  <field field_ref="subl_ai_cea"   name="subl_ai_cea"      />
+	  <!-- For salt conservation checking -->
+          <field field_ref="saltflx"      name="sosflxdo"  />
+    </file>
+
+    <file id="file12" name_suffix="_grid_U" description="ocean U grid variables" >
+      <field field_ref="e3u"  />
+      <field field_ref="ssu"          name="uos"     long_name="sea_surface_x_velocity"    />
+      <field field_ref="uoce"         name="uo"      long_name="sea_water_x_velocity"      operation="average" freq_op="1y" > @uoce_e3u / @e3u </field> 
+      <field field_ref="uoce_eiv"     name="uo_eiv"  />
+      <field field_ref="uocet"        name="uocet"  />
+      <field field_ref="uoces"        name="uoces"  />
+      <field field_ref="utau"         name="tauuo"   long_name="surface_downward_x_stress" />
+      <field field_ref="uocetr_eff"   name="uocetr_eff"  />
+      <field field_ref="u_masstr"     name="vozomatr"  />
+      <field field_ref="u_heattr"     name="sozohetr"  />
+      <field field_ref="u_salttr"     name="sozosatr"  />
+      <field field_ref="ueiv_heattr"  name="sozohetr_eiv"  />
+      <field field_ref="udiff_heattr" name="sozohetr_diff"  />
+    </file>
+
+    <file id="file13" name_suffix="_grid_V" description="ocean V grid variables" >
+      <field field_ref="e3v"  />
+      <field field_ref="ssv"          name="vos"     long_name="sea_surface_y_velocity"    />
+      <field field_ref="voce"         name="vo"      long_name="sea_water_y_velocity"     operation="average" freq_op="1y" > @voce_e3v / @e3v </field>
+      <field field_ref="voce_eiv"     name="vo_eiv"  />
+      <field field_ref="vocet"        name="vocet"  />
+      <field field_ref="voces"        name="voces"  />
+      <field field_ref="vtau"         name="tauvo"   long_name="surface_downward_y_stress" />
+      <field field_ref="vocetr_eff"   name="vocetr_eff"  />
+      <field field_ref="v_masstr"       name="vomematr"  />
+      <field field_ref="v_heattr"       name="somehetr"  />
+      <field field_ref="v_salttr"       name="somesatr"  />
+      <field field_ref="veiv_heattr"    name="somehetr_eiv"  />
+      <field field_ref="vdiff_heattr"   name="somehetr_diff"  />
+    </file>
+
+    <file id="file14" name_suffix="_grid_W" description="ocean W grid variables" >
+      <field field_ref="e3w"  />
+      <field field_ref="woce"         name="wo"      long_name="ocean vertical velocity"         />
+      <field field_ref="woce_eiv"     name="woce_eiv"     />
+      <field field_ref="wocetr_eff"   name="wocetr_eff"  />
+      <field field_ref="avt"          name="difvho"     long_name="ocean_vertical_heat_diffusivity" />
+      <field field_ref="logavt"       name="difvholog"  long_name="logarithm_of_ocean_vertical_heat_diffusivity" />
+      <field field_ref="avs"          name="difvso"  long_name="ocean_vertical_salt_diffusivity" />
+      <field field_ref="logavs"       name="difvsolog"  long_name="logarithm_of_ocean_vertical_salt_diffusivity" />
+      <field field_ref="w_masstr"     name="vovematr"  />
+      <field field_ref="bn2"          name="bn2"  />
+      <field field_ref="av_tide"      name="av_tide"  />
+      <field field_ref="aht2d"        name="ahtt"   />
+      <field field_ref="aht2d_eiv"    name="aeiv"   />
+      <!-- field field_ref="avt_evd"      name="avt_evd"    />
+      <field field_ref="av_wave"      name="av_wave"    />
+      <field field_ref="bflx_tmx"     name="bflx_tmx"   />
+      <field field_ref="pcmap_tmx"    name="pcmap_tmx"  />
+      <field field_ref="emix_tmx"     name="emix_tmx"   />
+      <field field_ref="av_ratio"     name="av_ratio"   />  -->
+    </file>
+
+    <file id="file15" name_suffix="_scalar" description="scalar variables" enabled=".true." >
+      <field field_ref="voltot"    grid_ref="grid_1point"    name="scvoltot"  />
+      <field field_ref="sshtot"    grid_ref="grid_1point"    name="scsshtot"  />
+      <field field_ref="sshsteric" grid_ref="grid_1point"    name="scsshste"  />
+      <field field_ref="sshthster" grid_ref="grid_1point"    name="scsshtst"  />
+      <field field_ref="masstot"   grid_ref="grid_1point"    name="scmastot"  />
+      <field field_ref="temptot"   grid_ref="grid_1point"    name="sctemtot"  />
+      <field field_ref="saltot"    grid_ref="grid_1point"    name="scsaltot"  />
+    </file>   
+
+    <file id="file16" name_suffix="_diaptr" description="diaptr variables" enabled=".TRUE." >
+      <field field_ref="zotemglo" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zosalglo" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zosrfglo" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zomsfglo" grid_ref="grid_ptr_W_3D"  />
+      <field field_ref="zotematl" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zosalatl" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zosrfatl" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zomsfatl" grid_ref="grid_ptr_W_3D"  />
+      <field field_ref="zotempac" grid_ref="grid_ptr_T_3D"   />
+      <field field_ref="zosalpac" grid_ref="grid_ptr_T_3D"  />
+      <field field_ref="zosrfpac" grid_ref="grid_ptr_T_3D"  />
+
+    </file>   
+   </file_group>
+
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+    
+
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_paleo.xml	(revision 5879)
@@ -0,0 +1,236 @@
+    <!-- $id$ -->
+    
+    <!-- 
+
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files ocean biogeochemistry                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@" sync_freq="1d" min_digits="4">
+    
+      <file_group id="1ts" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+
+      <file_group id="2h" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+
+      <file_group id="3h" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+
+      <file_group id="4h" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+
+      <file_group id="6h" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+    
+      <file_group id="1d" output_freq="1d"  output_level="10" enabled="_AUTO_">  <!-- 5d files -->   
+
+        <file id="file17" name_suffix="_PISCES_scalar" description="pisces sms variables" >
+          <!-- CARE: the conversion s->yr requires multiplyiong by 360 instead of 365 because we run with 360d -->
+          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  operation="instant" > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  operation="instant" > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  operation="instant" > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  operation="instant" > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" operation="instant" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group> 
+
+      <file_group id="5d" output_freq="5d"  output_level="10" enabled=".TRUE."/>  <!-- 5d files -->   
+	
+      <file_group id="1m" output_freq="1mo" output_level="10" enabled="_AUTO_"> <!-- real monthly files -->
+
+ 
+       <file id="file18" name_suffix="_ptrc_T" description="pisces sms variables" enabled=".TRUE.">
+          <field field_ref="DIC"       name="DIC"      operation="average" freq_op="1mo" > @DIC_E3T / @e3t </field>
+          <field field_ref="Alkalini"  name="Alkalini" operation="average" freq_op="1mo" > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"        name="O2"       operation="average" freq_op="1mo" > @O2_E3T / @e3t </field>
+          <field field_ref="CaCO3"     name="CaCO3"    operation="average" freq_op="1mo" > @CaCO3_E3T / @e3t </field>
+          <field field_ref="PO4"       name="PO4"      operation="average" freq_op="1mo" > @PO4_E3T / @e3t </field>
+          <field field_ref="POC"       name="POC"      operation="average" freq_op="1mo" > @POC_E3T / @e3t </field>
+          <field field_ref="Si"        name="Si"       operation="average" freq_op="1mo" > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"       name="PHY"      operation="average" freq_op="1mo" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"       name="ZOO"      operation="average" freq_op="1mo" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"       name="DOC"      operation="average" freq_op="1mo" > @DOC_E3T / @e3t </field>
+          <field field_ref="PHY2"      name="PHY2"     operation="average" freq_op="1mo" > @PHY2_E3T / @e3t </field>
+          <field field_ref="ZOO2"      name="ZOO2"     operation="average" freq_op="1mo" > @ZOO2_E3T / @e3t </field>
+          <field field_ref="DSi"       name="DSi"      operation="average" freq_op="1mo" > @DSi_E3T / @e3t </field>
+          <field field_ref="Fer"       name="Fer"      operation="average" freq_op="1mo" > @Fer_E3T / @e3t </field>
+          <field field_ref="BFe"       name="BFe"      operation="average" freq_op="1mo" > @BFe_E3T / @e3t </field>
+          <field field_ref="GOC"       name="GOC"      operation="average" freq_op="1mo" > @GOC_E3T / @e3t </field>
+          <field field_ref="SFe"       name="SFe"      operation="average" freq_op="1mo" > @SFe_E3T / @e3t </field>
+          <field field_ref="DFe"       name="DFe"      operation="average" freq_op="1mo" > @DFe_E3T / @e3t </field>
+          <field field_ref="GSi"       name="GSi"      operation="average" freq_op="1mo" > @GSi_E3T / @e3t </field>
+          <field field_ref="NFe"       name="NFe"      operation="average" freq_op="1mo" > @NFe_E3T / @e3t </field>
+          <field field_ref="NCHL"      name="NCHL"     operation="average" freq_op="1mo" > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"      name="DCHL"     operation="average" freq_op="1mo" > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"       name="NO3"      operation="average" freq_op="1mo" > @NO3_E3T / @e3t </field>
+          <field field_ref="NH4"       name="NH4"      operation="average" freq_op="1mo" > @NH4_E3T / @e3t </field>
+    </file>
+
+   <file id="file19" name_suffix="_diad_T" description="additional pisces diagnostics" enabled=".TRUE." >
+       <field field_ref="PH"         name="PH"        />
+       <field field_ref="CO3"        name="CO3"       />
+       <field field_ref="CO3sat"     name="CO3sat"    />
+       <field field_ref="PAR"        name="PAR"       />
+       <field field_ref="PARDM"      name="PARDM"     />
+       <field field_ref="PPPHY"      name="PPPHY"     />
+       <field field_ref="PPPHY2"     name="PPPHY2"    />
+       <field field_ref="PPNEWN"     name="PPNEWN"    />
+       <field field_ref="PPNEWD"     name="PPNEWD"    />
+       <field field_ref="xfracal"    name="xfracal"   />
+       <field field_ref="PCAL"       name="PCAL"      />
+       <field field_ref="DCAL"       name="DCAL"      />
+       <field field_ref="REMIN"      name="REMIN"     />
+       <field field_ref="DENIT"      name="DENIT"     />
+       <field field_ref="Nfix"       name="Nfix"      />
+       <field field_ref="LNnut"      name="LNnut"     />
+       <field field_ref="LDnut"      name="LDnut"     />
+       <field field_ref="LNFe"       name="LNFe"      />
+       <field field_ref="LDFe"       name="LDFe"      />
+       <field field_ref="LNlight"    name="LNlight"   />
+       <field field_ref="LDlight"    name="LDlight"   />
+       <field field_ref="EPC100"     name="EPC100"    />
+       <field field_ref="EPFE100"    name="EPFE100"   />
+       <field field_ref="EPSI100"    name="EPSI100"   />
+       <field field_ref="EPCAL100"   name="EPCAL100"  />
+       <field field_ref="EXPC"       name="EXPC"      />
+       <field field_ref="EXPFE"      name="EXPFE"     />
+       <field field_ref="EXPSI"      name="EXPSI"     />
+       <field field_ref="EXPCAL"     name="EXPCAL"    />
+       <field field_ref="Cflx"       name="Cflx"      />
+       <field field_ref="Oflx"       name="Oflx"      />
+       <field field_ref="Dpco2"      name="Dpco2"     />
+       <field field_ref="Dpo2"       name="Dpo2"      />
+       <field field_ref="Heup"       name="Heup"      />
+       <field field_ref="Irondep"    name="Irondep"   />
+       <field field_ref="Ironsed"    name="Ironsed"   />
+       <field field_ref="TPP"        name="TPP"       />
+       <field field_ref="TPNEW"      name="TPNEW"     />
+       <field field_ref="INTDIC"     name="INTDIC"    />
+       <field field_ref="O2MIN"      name="O2MIN"     />
+       <field field_ref="ZO2MIN"     name="ZO2MIN"    />
+       <field field_ref="INTNFIX"    name="INTNFIX"   />
+       <field field_ref="INTPPPHY"   name="INTPPPHY"  />
+       <field field_ref="INTPPPHY2"  name="INTPPPHY2" />
+       <field field_ref="INTPP"      name="INTPP"     />
+       <field field_ref="INTPNEW"    name="INTPNEW"   />
+    </file>
+
+
+    <file id="file20" name_suffix="_PISCES_scalar" description="pisces sms variables" enabled=".TRUE.">
+          <!-- CARE: the conversion s->yr requires multiplyiong by 360 instead of 365 because we run with 360d -->
+          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tdenit * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" > tnfix * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcflx * -1. * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tcexp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" > tintpp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  operation="instant" > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  operation="instant" > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  operation="instant" > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  operation="instant" > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" operation="instant" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group>
+
+
+      <file_group id="2m" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+
+      <file_group id="1y"  output_freq="1y" output_level="10" enabled="_AUTO_"> <!-- real yearly files -->
+
+ 
+       <file id="file21" name_suffix="_ptrc_T" description="pisces sms variables" enabled=".TRUE.">
+          <field field_ref="DIC"       name="DIC"      operation="average" freq_op="1y" > @DIC_E3T / @e3t </field>
+          <field field_ref="Alkalini"  name="Alkalini" operation="average" freq_op="1y" > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"        name="O2"       operation="average" freq_op="1y" > @O2_E3T / @e3t </field>
+          <field field_ref="CaCO3"     name="CaCO3"    operation="average" freq_op="1y" > @CaCO3_E3T / @e3t </field>
+          <field field_ref="PO4"       name="PO4"      operation="average" freq_op="1y" > @PO4_E3T / @e3t </field>
+          <field field_ref="POC"       name="POC"      operation="average" freq_op="1y" > @POC_E3T / @e3t </field>
+          <field field_ref="Si"        name="Si"       operation="average" freq_op="1y" > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"       name="PHY"      operation="average" freq_op="1y" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"       name="ZOO"      operation="average" freq_op="1y" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"       name="DOC"      operation="average" freq_op="1y" > @DOC_E3T / @e3t </field>
+          <field field_ref="PHY2"      name="PHY2"     operation="average" freq_op="1y" > @PHY2_E3T / @e3t </field>
+          <field field_ref="ZOO2"      name="ZOO2"     operation="average" freq_op="1y" > @ZOO2_E3T / @e3t </field>
+          <field field_ref="DSi"       name="DSi"      operation="average" freq_op="1y" > @DSi_E3T / @e3t </field>
+          <field field_ref="Fer"       name="Fer"      operation="average" freq_op="1y" > @Fer_E3T / @e3t </field>
+          <field field_ref="BFe"       name="BFe"      operation="average" freq_op="1y" > @BFe_E3T / @e3t </field>
+          <field field_ref="GOC"       name="GOC"      operation="average" freq_op="1y" > @GOC_E3T / @e3t </field>
+          <field field_ref="SFe"       name="SFe"      operation="average" freq_op="1y" > @SFe_E3T / @e3t </field>
+          <field field_ref="DFe"       name="DFe"      operation="average" freq_op="1y" > @DFe_E3T / @e3t </field>
+          <field field_ref="GSi"       name="GSi"      operation="average" freq_op="1y" > @GSi_E3T / @e3t </field>
+          <field field_ref="NFe"       name="NFe"      operation="average" freq_op="1y" > @NFe_E3T / @e3t </field>
+          <field field_ref="NCHL"      name="NCHL"     operation="average" freq_op="1y" > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"      name="DCHL"     operation="average" freq_op="1y" > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"       name="NO3"      operation="average" freq_op="1y" > @NO3_E3T / @e3t </field>
+          <field field_ref="NH4"       name="NH4"      operation="average" freq_op="1y" > @NH4_E3T / @e3t </field>
+    </file>
+
+   <file id="file22" name_suffix="_diad_T" description="additional pisces diagnostics" enabled=".TRUE." >
+       <field field_ref="PH"         name="PH"        />
+       <field field_ref="CO3"        name="CO3"       />
+       <field field_ref="CO3sat"     name="CO3sat"    />
+       <field field_ref="PAR"        name="PAR"       />
+       <field field_ref="PARDM"      name="PARDM"     />
+       <field field_ref="PPPHY"      name="PPPHY"     />
+       <field field_ref="PPPHY2"     name="PPPHY2"    />
+       <field field_ref="PPNEWN"     name="PPNEWN"    />
+       <field field_ref="PPNEWD"     name="PPNEWD"    />
+       <field field_ref="xfracal"    name="xfracal"   />
+       <field field_ref="PCAL"       name="PCAL"      />
+       <field field_ref="DCAL"       name="DCAL"      />
+       <field field_ref="REMIN"      name="REMIN"     />
+       <field field_ref="DENIT"      name="DENIT"     />
+       <field field_ref="Nfix"       name="Nfix"      />
+       <field field_ref="LNnut"      name="LNnut"     />
+       <field field_ref="LDnut"      name="LDnut"     />
+       <field field_ref="LNFe"       name="LNFe"      />
+       <field field_ref="LDFe"       name="LDFe"      />
+       <field field_ref="LNlight"    name="LNlight"   />
+       <field field_ref="LDlight"    name="LDlight"   />
+       <field field_ref="EPC100"     name="EPC100"    />
+       <field field_ref="EPFE100"    name="EPFE100"   />
+       <field field_ref="EPSI100"    name="EPSI100"   />
+       <field field_ref="EPCAL100"   name="EPCAL100"  />
+       <field field_ref="EXPC"       name="EXPC"      />
+       <field field_ref="EXPFE"      name="EXPFE"     />
+       <field field_ref="EXPSI"      name="EXPSI"     />
+       <field field_ref="EXPCAL"     name="EXPCAL"    />
+       <field field_ref="Cflx"       name="Cflx"      />
+       <field field_ref="Oflx"       name="Oflx"      />
+       <field field_ref="Dpco2"      name="Dpco2"     />
+       <field field_ref="Dpo2"       name="Dpo2"      />
+       <field field_ref="Heup"       name="Heup"      />
+       <field field_ref="Irondep"    name="Irondep"   />
+       <field field_ref="Ironsed"    name="Ironsed"   />
+       <field field_ref="TPP"        name="TPP"       />
+       <field field_ref="TPNEW"      name="TPNEW"     />
+       <field field_ref="INTDIC"     name="INTDIC"    />
+       <field field_ref="O2MIN"      name="O2MIN"     />
+       <field field_ref="ZO2MIN"     name="ZO2MIN"    />
+       <field field_ref="INTNFIX"    name="INTNFIX"   />
+       <field field_ref="INTPPPHY"   name="INTPPPHY"  />
+       <field field_ref="INTPPPHY2"  name="INTPPPHY2" />
+       <field field_ref="INTPP"      name="INTPP"     />
+       <field field_ref="INTPNEW"    name="INTPNEW"   />
+    </file>
+
+      </file_group>
+
+      <file_group id="2y"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_rivers_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_rivers_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_nemo-pisces_rivers_paleo.xml	(revision 5879)
@@ -0,0 +1,251 @@
+    <!-- $id$ -->
+    
+    <!-- 
+
+============================================================================================================
+=                                           output files definition                                        =
+=                                            Define your own files ocean biogeochemistry                                         =
+=                                         put the variables you want...                                    =
+============================================================================================================
+    -->
+    
+    <file_definition type="one_file" name="@expname@_@freq@" sync_freq="1d" min_digits="4" >
+    
+      <file_group id="1ts_pis" output_freq="1ts"  output_level="10" enabled=".TRUE."/> <!-- 1 time step files -->
+
+      <file_group id="1h_pis" output_freq="1h"  output_level="10" enabled=".TRUE."/> <!-- 1h files -->
+
+      <file_group id="2h_pis" output_freq="2h"  output_level="10" enabled=".TRUE."/> <!-- 2h files -->
+
+      <file_group id="3h_pis" output_freq="3h"  output_level="10" enabled=".TRUE."/> <!-- 3h files -->     
+
+      <file_group id="4h_pis" output_freq="4h"  output_level="10" enabled=".TRUE."/> <!-- 4h files -->
+
+      <file_group id="6h_pis" output_freq="6h"  output_level="10" enabled=".TRUE."/> <!-- 6h files -->     
+    
+      <file_group id="1d_pis" output_freq="1d"  output_level="_AUTO_" enabled="_AUTO_" >  <!-- 1d files -->   
+
+        <file id="file17" name_suffix="_bioscalar" description="pisces sms variables" >
+          <!-- CARE: the conversion s->yr requires multiplyiong by 360 instead of 365 because we run with 360d in paleo -->
+          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="2" > tdenit * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="2" > tnfix * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tcflx * -1. * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" level="2" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tcexp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tintpp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  operation="instant" level="2" > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  operation="instant" level="2" > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="2" > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="2" > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" operation="instant" level="2" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group> 
+
+      <file_group id="5d_pis" output_freq="5d"  output_level="_AUTO_" enabled="_AUTO_" >  <!-- 5d files -->   
+
+       <file id="file24" name_suffix="_bioscalar" description="pisces sms variables" >
+          <!-- CARE: the conversion s->yr requires multiplyiong by 360 instead of 365 because we run with 360d in paleo -->
+          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="2" > tdenit * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="2" > tnfix * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tcflx * -1. * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" level="2" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tcexp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="2" > tintpp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  operation="instant" level="2" > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  operation="instant" level="2" > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="2" > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="2" > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" operation="instant" level="2" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group> 
+
+	
+      <file_group id="1m_pis" output_freq="1mo" output_level="_AUTO_" enabled="_AUTO_" > <!-- real monthly files -->
+
+
+        <file id="file18" name_suffix="_ptrc_T" description="pisces sms variables" >
+          <field field_ref="DIC"       name="DIC"      operation="average" freq_op="1mo" level="2" > @DIC_E3T / @e3t </field>
+          <field field_ref="Alkalini"  name="Alkalini" operation="average" freq_op="1mo" level="2" > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"        name="O2"       operation="average" freq_op="1mo" level="2" > @O2_E3T / @e3t </field>
+          <field field_ref="CaCO3"     name="CaCO3"    operation="average" freq_op="1mo" level="2" > @CaCO3_E3T / @e3t </field>
+          <field field_ref="PO4"       name="PO4"      operation="average" freq_op="1mo" level="2" > @PO4_E3T / @e3t </field>
+          <field field_ref="POC"       name="POC"      operation="average" freq_op="1mo" level="2" > @POC_E3T / @e3t </field>
+          <field field_ref="Si"        name="Si"       operation="average" freq_op="1mo" level="2" > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"       name="PHY"      operation="average" freq_op="1mo" level="2" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"       name="ZOO"      operation="average" freq_op="1mo" level="2" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"       name="DOC"      operation="average" freq_op="1mo" level="2" > @DOC_E3T / @e3t </field>
+          <field field_ref="PHY2"      name="PHY2"     operation="average" freq_op="1mo" level="2" > @PHY2_E3T / @e3t </field>
+          <field field_ref="ZOO2"      name="ZOO2"     operation="average" freq_op="1mo" level="2" > @ZOO2_E3T / @e3t </field>
+          <field field_ref="DSi"       name="DSi"      operation="average" freq_op="1mo" level="2" > @DSi_E3T / @e3t </field>
+          <field field_ref="Fer"       name="Fer"      operation="average" freq_op="1mo" level="2" > @Fer_E3T / @e3t </field>
+          <field field_ref="BFe"       name="BFe"      operation="average" freq_op="1mo" level="2" > @BFe_E3T / @e3t </field>
+          <field field_ref="GOC"       name="GOC"      operation="average" freq_op="1mo" level="2" > @GOC_E3T / @e3t </field>
+          <field field_ref="SFe"       name="SFe"      operation="average" freq_op="1mo" level="2" > @SFe_E3T / @e3t </field>
+          <field field_ref="DFe"       name="DFe"      operation="average" freq_op="1mo" level="2" > @DFe_E3T / @e3t </field>
+          <field field_ref="GSi"       name="GSi"      operation="average" freq_op="1mo" level="2" > @GSi_E3T / @e3t </field>
+          <field field_ref="NFe"       name="NFe"      operation="average" freq_op="1mo" level="2" > @NFe_E3T / @e3t </field>
+          <field field_ref="NCHL"      name="NCHL"     operation="average" freq_op="1mo" level="2" > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"      name="DCHL"     operation="average" freq_op="1mo" level="2" > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"       name="NO3"      operation="average" freq_op="1mo" level="2" > @NO3_E3T / @e3t </field>
+          <field field_ref="NH4"       name="NH4"      operation="average" freq_op="1mo" level="2" > @NH4_E3T / @e3t </field>
+       </file>
+
+
+
+       <file id="file19" name_suffix="_diad_T" description="additional pisces diagnostics" >
+
+        <field field_ref="PH"         name="PH"       level="2" />
+        <field field_ref="CO3"        name="CO3"      level="2" />
+        <field field_ref="CO3sat"     name="CO3sat"   level="2" />
+        <field field_ref="PAR"        name="PAR"      level="2" />
+        <field field_ref="PCAL"       name="PCAL"     level="2" />
+        <field field_ref="Cflx"       name="Cflx"     level="2" />
+        <field field_ref="Oflx"       name="Oflx"     level="2" />
+        <field field_ref="Dpco2"      name="Dpco2"    level="2" />
+        <field field_ref="Dpo2"       name="Dpo2"     level="2" />
+        <field field_ref="Heup"       name="Heup"     level="2" />
+        <field field_ref="Irondep"    name="Irondep"  level="2" />
+        <field field_ref="Ironsed"    name="Ironsed"  level="2" />
+        <field field_ref="Nfix"       name="Nfix"     level="2" />
+        <field field_ref="LNnut"      name="LNnut"    level="2" />
+        <field field_ref="LDnut"      name="LDnut"    level="2" />
+        <field field_ref="LNFe"       name="LNFe"     level="2" />
+        <field field_ref="LDFe"       name="LDFe"     level="2" />
+        <field field_ref="LNlight"    name="LNlight"  level="2" />
+        <field field_ref="LDlight"    name="LDlight"  level="2" />
+        <field field_ref="TPP"        name="TPP"      level="2" />
+        <field field_ref="INTPP"      name="INTPP"    level="2" />
+        <field field_ref="INTPNEW"    name="INTPNEW"  level="2" />
+        <field field_ref="TPNEW"      name="TPNEW"    level="2" />
+        <field field_ref="EPC100"     name="EPC100"   level="2" />
+        <field field_ref="EPFE100"    name="EPFE100"  level="2" />
+        <field field_ref="EPSI100"    name="EPSI100"  level="2" />
+        <field field_ref="EPCAL100"   name="EPCAL100" level="2" />
+        <field field_ref="xfracal"    name="xfracal"  level="2" />
+        <field field_ref="ALKriv"     name="ALKriv"   level="2" />
+        <field field_ref="DICriv"     name="DICriv"   level="2" />
+        <field field_ref="DINriv"     name="DINriv"   level="2" />
+        <field field_ref="DIPriv"     name="DIPriv"   level="2" />
+        <field field_ref="DSIriv"     name="DSIriv"   level="2" />
+        <field field_ref="rnfmsk"     name="rnfmsk"   level="2" />
+        <field field_ref="runoff"     name="runoff"   level="2" />
+        <field field_ref="h_rnf"      name="h_rnf"    level="2" />
+        <field field_ref="area_T"     name="area_T"   level="2" />
+
+       </file>
+       
+       <file id="file20" name_suffix="_bioscalar" description="pisces sms variables" >
+          <!-- CARE: the conversion s->yr requires multiplyiong by 360 instead of 365 because we run with 360d in paleo -->
+          <field field_ref="tdenit"   name="tdenit"   grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="1" > tdenit * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tnfix"    name="tnfix"    grid_ref="grid_1point" unit="TgN/yr" operation="instant" level="1" > tnfix * 14. * 86400. * 360. / 1e12 </field>
+          <field field_ref="tcflx"    name="tcflx"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="1" > tcflx * -1. * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tcflxcum" name="tcflxcum" grid_ref="grid_1point" unit="PgC"    operation="instant" level="1" > tcflxcum * -1. * 12. / 1e15 </field>
+          <field field_ref="tcexp"    name="tcexp"    grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="1" > tcexp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="tintpp"   name="tintpp"   grid_ref="grid_1point" unit="PgC/yr" operation="instant" level="1" > tintpp * 12. * 86400. * 360. / 1e15 </field>
+          <field field_ref="pno3tot"  name="pno3tot"  grid_ref="grid_1point" unit="umolN"  operation="instant" level="1" > pno3tot * 16. / 122. * 1e6 </field>
+          <field field_ref="ppo4tot"  name="ppo4tot"  grid_ref="grid_1point" unit="umolP"  operation="instant" level="1" > ppo4tot * 1. / 122. * 1e6 </field>
+          <field field_ref="psiltot"  name="psiltot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="1" > psiltot * 1e6  </field>
+          <field field_ref="palktot"  name="palktot"  grid_ref="grid_1point" unit="umolC"  operation="instant" level="1" > palktot * 1e6  </field>
+          <field field_ref="pfertot"  name="pfertot"  grid_ref="grid_1point" unit="nmolFe" operation="instant" level="1" > pfertot * 1e9  </field>
+        </file>
+
+      </file_group>
+
+
+      <file_group id="2m_pis" output_freq="2mo" output_level="10" enabled=".TRUE."/> <!-- real 2m files -->
+      <file_group id="3m_pis" output_freq="3mo" output_level="10" enabled=".TRUE."/> <!-- real 3m files -->
+      <file_group id="4m_pis" output_freq="4mo" output_level="10" enabled=".TRUE."/> <!-- real 4m files -->
+      <file_group id="6m_pis" output_freq="6mo" output_level="10" enabled=".TRUE."/> <!-- real 6m files -->
+
+      <file_group id="1y_pis"  output_freq="1y" output_level="_AUTO_" enabled="_AUTO_"> <!-- real yearly files -->
+
+ 
+       <file id="file21" name_suffix="_ptrc_T" description="pisces sms variables" >
+          <field field_ref="DIC"       name="DIC"      operation="average" freq_op="1y" level="1"  > @DIC_E3T / @e3t </field>
+          <field field_ref="Alkalini"  name="Alkalini" operation="average" freq_op="1y" level="1"  > @Alkalini_E3T / @e3t </field>
+          <field field_ref="O2"        name="O2"       operation="average" freq_op="1y" level="1"  > @O2_E3T / @e3t </field>
+          <field field_ref="CaCO3"     name="CaCO3"    operation="average" freq_op="1y" level="2" > @CaCO3_E3T / @e3t </field>
+          <field field_ref="PO4"       name="PO4"      operation="average" freq_op="1y" level="1"  > @PO4_E3T / @e3t </field>
+          <field field_ref="POC"       name="POC"      operation="average" freq_op="1y" level="1"  > @POC_E3T / @e3t </field>
+          <field field_ref="Si"        name="Si"       operation="average" freq_op="1y" level="1"  > @Si_E3T / @e3t </field>
+          <field field_ref="PHY"       name="PHY"      operation="average" freq_op="1y" level="2" > @PHY_E3T / @e3t </field>
+          <field field_ref="ZOO"       name="ZOO"      operation="average" freq_op="1y" level="2" > @ZOO_E3T / @e3t </field>
+          <field field_ref="DOC"       name="DOC"      operation="average" freq_op="1y" level="2" > @DOC_E3T / @e3t </field>
+          <field field_ref="PHY2"      name="PHY2"     operation="average" freq_op="1y" level="2" > @PHY2_E3T / @e3t </field>
+          <field field_ref="ZOO2"      name="ZOO2"     operation="average" freq_op="1y" level="2" > @ZOO2_E3T / @e3t </field>
+          <field field_ref="DSi"       name="DSi"      operation="average" freq_op="1y" level="2" > @DSi_E3T / @e3t </field>
+          <field field_ref="Fer"       name="Fer"      operation="average" freq_op="1y" level="1"  > @Fer_E3T / @e3t </field>
+          <field field_ref="BFe"       name="BFe"      operation="average" freq_op="1y" level="2" > @BFe_E3T / @e3t </field>
+          <field field_ref="GOC"       name="GOC"      operation="average" freq_op="1y" level="1"  > @GOC_E3T / @e3t </field>
+          <field field_ref="SFe"       name="SFe"      operation="average" freq_op="1y" level="2" > @SFe_E3T / @e3t </field>
+          <field field_ref="DFe"       name="DFe"      operation="average" freq_op="1y" level="2" > @DFe_E3T / @e3t </field>
+          <field field_ref="GSi"       name="GSi"      operation="average" freq_op="1y" level="2" > @GSi_E3T / @e3t </field>
+          <field field_ref="NFe"       name="NFe"      operation="average" freq_op="1y" level="2" > @NFe_E3T / @e3t </field>
+          <field field_ref="NCHL"      name="NCHL"     operation="average" freq_op="1y" level="1"  > @NCHL_E3T / @e3t </field>
+          <field field_ref="DCHL"      name="DCHL"     operation="average" freq_op="1y" level="1"  > @DCHL_E3T / @e3t </field>
+          <field field_ref="NO3"       name="NO3"      operation="average" freq_op="1y" level="1"  > @NO3_E3T / @e3t </field>
+          <field field_ref="NH4"       name="NH4"      operation="average" freq_op="1y" level="2" > @NH4_E3T / @e3t </field>
+       </file>
+
+      <file id="file22" name_suffix="_diad_T" description="additional pisces diagnostics"  >
+
+        <field field_ref="PH"         name="PH"       level="2" />
+        <field field_ref="CO3"        name="CO3"      level="2" />
+        <field field_ref="CO3sat"     name="CO3sat"   level="2" />
+        <field field_ref="PAR"        name="PAR"      level="2" />
+        <field field_ref="PCAL"       name="PCAL"     level="2"  />
+        <field field_ref="Cflx"       name="Cflx"     level="1"  />
+        <field field_ref="Oflx"       name="Oflx"     level="2"  />
+        <field field_ref="Dpco2"      name="Dpco2"    level="1"   />
+        <field field_ref="Dpo2"       name="Dpo2"     level="2"  />
+        <field field_ref="Heup"       name="Heup"     level="1" />
+        <field field_ref="Irondep"    name="Irondep"  level="2" />
+        <field field_ref="Ironsed"    name="Ironsed"  level="2" />
+        <field field_ref="Nfix"       name="Nfix"     level="1" />
+        <field field_ref="LNnut"      name="LNnut"    level="2" />
+        <field field_ref="LDnut"      name="LDnut"    level="2" />
+        <field field_ref="LNFe"       name="LNFe"     level="2" />
+        <field field_ref="LDFe"       name="LDFe"     level="2" />
+        <field field_ref="LNlight"    name="LNlight"  level="2"  />
+        <field field_ref="LDlight"    name="LDlight"  level="2"  />
+        <field field_ref="TPP"        name="TPP"      level="1" />
+        <field field_ref="INTPP"      name="INTPP"    level="1" />
+        <field field_ref="INTPNEW"    name="INTPNEW"  level="2"  />
+        <field field_ref="TPNEW"      name="TPNEW"    level="2" />
+        <field field_ref="EPC100"     name="EPC100"   level="1" />
+        <field field_ref="EPFE100"    name="EPFE100"  level="1"  />
+        <field field_ref="EPSI100"    name="EPSI100"  level="1"  />
+        <field field_ref="EPCAL100"   name="EPCAL100" level="1"  />
+        <field field_ref="xfracal"    name="xfracal"  level="2" />
+        <field field_ref="ALKriv"     name="ALKriv"   level="2" />
+        <field field_ref="DICriv"     name="DICriv"   level="2" />
+        <field field_ref="DINriv"     name="DINriv"   level="2" />
+        <field field_ref="DIPriv"     name="DIPriv"   level="2" />
+        <field field_ref="DSIriv"     name="DSIriv"   level="2" />
+
+      </file>
+
+       <file id="file23" name_suffix="_inerttrc" description="Inert tracer" >
+          <field field_ref="Age"         name="Age"      operation="average" freq_op="1y" level="1"  > @Age_E3T / @e3t </field>
+          <field field_ref="CFC11"       name="CFC11"    operation="average" freq_op="1y" level="2"  > @CFC11_E3T / @e3t </field>
+          <field field_ref="CFC12"       name="CFC12"    operation="average" freq_op="1y" level="1"  > @CFC12_E3T / @e3t </field>
+          <field field_ref="SF6"         name="SF6"      operation="average" freq_op="1y" level="2"  > @SF6_E3T / @e3t </field>
+          <field field_ref="qtr_CFC11"   name="qtrCFC11"  level="2"   />
+          <field field_ref="qint_CFC11"  name="qintCFC11" level="2"   />
+          <field field_ref="qtr_CFC12"   name="qtrCFC12"  level="1"   />
+          <field field_ref="qint_CFC12"  name="qintCFC12" level="1"   />
+          <field field_ref="qtr_SF6"     name="qtrSF6"    level="2"   />
+          <field field_ref="qint_SF6"    name="qintSF6"   level="2"   />
+      </file>
+
+
+      </file_group>
+
+      <file_group id="2y_pis"  output_freq="2y" output_level="10" enabled=".TRUE."/> <!-- real 2y files -->
+      <file_group id="5y_pis"  output_freq="5y" output_level="10" enabled=".TRUE."/> <!-- real 5y files -->
+      <file_group id="10y_pis" output_freq="10y" output_level="10" enabled=".TRUE."/> <!-- real 10y files -->
+
+   </file_definition>
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_orchidee_paleo.xml
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_orchidee_paleo.xml	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/file_def_orchidee_paleo.xml	(revision 5879)
@@ -0,0 +1,768 @@
+<!-- =========================================================================================================== -->
+<!-- file_def_orchidee.xml : Definition of output files                                                          -->
+
+<!-- Definition of variables or groups included in the different files                                           -->
+<!-- Change this file by adding the files and/or variables you want to produce                                   -->
+<!-- Only variables and groups existing in field_def_orchidee.xml can be used                                    -->
+
+<!-- Note: The keyword _AUTO_ will be changed by the drivers using libIGCM configurations. It can also be        -->
+<!-- changed manually. For example instead of _AUTO_ set :  enabled=".TRUE." or enabled=".FALSE."                -->
+<!-- output_freq="1mo" for monthly, output_freq="1d" for daily, output_freq="10800s" for 3-hour output frequency -->
+<!-- =========================================================================================================== -->
+
+<file_definition type="one_file" par_access="collective" enabled=".TRUE." min_digits="4">
+
+  <!-- Definition of files with sechiba diagnostics -->
+
+  <!-- Sechiba file 1 -->
+  <!-- output_level="11" -->
+  <file id="sechiba1" name="sechiba_history" output_level="5" output_freq="_AUTO_" enabled="_AUTO_">
+    <!-- level 1 -->
+    <field field_ref="areas" level="1"/>
+    <field field_ref="LandPoints" level="20"/>
+    <field field_ref="contfrac" level="1"/>
+    <field field_ref="vevapp_day" level="1"/>
+    <field field_ref="coastalflow" level="1"/>
+    <field field_ref="riverflow" level="1"/>
+    <field field_ref="temp_sol_new_C" level="1"/>
+    <field field_ref="precip_rain" level="1" name="rain" unit="mm/d" > precip_rain*86400  </field>
+    <field field_ref="precip_snow" level="1" name="snowf" unit="mm/d" > precip_snow*86400  </field>
+    <field field_ref="netrad" level="1"/>
+    <field field_ref="lai" level="1"/>
+    <field field_ref="reinf_slope" level="1"/>
+    <field field_ref="njsc" level="1"/>
+    <field field_ref="basinmap" level="1"/>
+    <field field_ref="nbrivers" level="1"/>
+    <field field_ref="npp" level="1"/>
+    <field field_ref="wtd" level="1"/>
+    <field field_ref="tws" level="1"/>
+    <!-- level 2 -->
+    <field field_ref="vevapsno" name="subli" level="2" unit="mm/d" > this*86400  </field>
+    <field field_ref="runoff" name="runoff" level="2" unit="mm/d" > runoff*86400  </field>
+    <field field_ref="drainage" name="drainage" level="2" unit="mm/d" > drainage*86400  </field>
+    <field field_ref="riversret" level="2"/>
+    <field field_ref="hydrographs" level="2"/>
+    <field field_ref="evapnu" level="2"/>
+    <field field_ref="evapnu_soil" level="2"/>
+    <field field_ref="drainage_soil" level="2"/>
+    <field field_ref="transpir_soil" level="2"/>
+    <field field_ref="runoff_soil" level="2"/>
+    <field field_ref="temp_air" level="2"/>
+    <field field_ref="qair" level="2"/>
+    <field field_ref="q2m" level="2"/>
+    <field field_ref="t2m" level="2"/>
+    <field field_ref="albedo_vis" level="2"/>
+    <field field_ref="albedo_nir" level="2"/>
+    <field field_ref="soilalb_vis" level="2"/>
+    <field field_ref="soilalb_nir" level="2"/>
+    <field field_ref="vegalb_vis" level="2"/>
+    <field field_ref="vegalb_nir" level="2"/>
+    <field field_ref="z0h" level="2"/>
+    <field field_ref="z0m" level="2"/>
+    <field field_ref="roughheight" level="2"/>
+    <field field_ref="transpir" level="2"/>
+    <field field_ref="inter" level="2"/>
+    <!-- for water budget control -->
+    <field field_ref="delsoilmoist_daily" level="1" />
+    <field field_ref="delintercept_daily" level="1" />
+    <field field_ref="delswe_daily" level="1" />
+    <field field_ref="delfastr_daily" level="1" />
+    <field field_ref="delslowr_daily" level="1" />
+    <field field_ref="delstreamr_daily" level="1" />
+    <field field_ref="dellaker_daily" level="1" />
+    <field field_ref="delpondr_daily" level="1" />
+    <field field_ref="delfloodr_daily" level="1" />
+    <field field_ref="delstock_routing" level="1" />
+    <field field_ref="evapflo" level="2"/>
+
+    <field field_ref="undermcr" level="2"/>
+    <field field_ref="ru_corr" level="2"/>
+    <field field_ref="ru_corr2" level="2"/>
+    <field field_ref="dr_corr" level="2"/>
+    <field field_ref="dr_force" level="2"/>
+    <field field_ref="ru_infilt" level="2"/>
+    <field field_ref="qinfilt" level="2"/>
+    <field field_ref="dr_corrnum" level="2"/>
+    <!-- level 3 -->
+    <field field_ref="tsol_max" level="3"/>
+    <field field_ref="tsol_min" level="3"/>
+    <field field_ref="fluxsens" level="3"/>
+    <field field_ref="fluxlat" level="3"/>
+    <field field_ref="snow" level="3"/>
+    
+    <field field_ref="snowage" level="3"/>
+    <field field_ref="snownobio" level="3"/>
+    <field field_ref="snownobioage" level="3"/>
+    <field field_ref="vegetfrac" level="3"/>
+    <field field_ref="maxvegetfrac" level="3"/>
+    <field field_ref="tot_bare_soil" level="3"/>
+    <field field_ref="nobiofrac" level="3"/>
+    <field field_ref="reinfiltration" level="3"/>
+    <field field_ref="frac_bare" level="3"/>
+    <field field_ref="soiltile" level="3"/>
+    <field field_ref="mc" level="3"/>
+    <field field_ref="kfact_root" level="3"/>
+    <field field_ref="vegetmax_soil" level="3"/>
+    <field field_ref="check_infilt" level="3"/>
+    <field field_ref="check_tr" level="3"/>
+    <field field_ref="check_over" level="3"/>
+    <field field_ref="check_under" level="3"/>
+
+    <!-- level 4 -->
+    <field field_ref="dss" level="4"/>
+    <field field_ref="gqsb" level="4"/>
+    <field field_ref="bqsb" level="4"/>
+    <field field_ref="humtot" level="4"/>
+    <field field_ref="tmc" level="4"/>
+    <field field_ref="qsintveg" level="4"/>
+    <field field_ref="rstruct" level="4"/>
+    <field field_ref="gpp" level="4"/>
+    <field field_ref="nee" level="4"/>
+    <field field_ref="maint_resp" level="4"/>
+    <field field_ref="hetero_resp" level="4"/>
+    <field field_ref="growth_resp" level="4"/>
+    <field field_ref="precisol" level="4"/>
+    <field field_ref="drysoil_frac" level="4"/>
+    <field field_ref="evapot" level="4"/>
+    <field field_ref="evapot_corr" level="4"/>
+    <!-- level 5 -->
+    <field field_ref="swnet" level="5"/>
+    <field field_ref="swdown" level="5"/>
+    <field field_ref="lwdown" level="5"/>
+    <field field_ref="lwnet" level="5"/>
+    <field field_ref="diffevap" level="5"/>
+    <field field_ref="temp_hydro" level="5"/>
+    <field field_ref="snowmelt" level="5"/>
+    <field field_ref="tot_melt" level="5"/>
+    <field field_ref="snowmelt_from_maxmass" level="5"/>
+    <field field_ref="soilcap" level="5"/>
+    <!-- level 6 -->
+    <field field_ref="twbr" level="6"/>
+    <field field_ref="ptn" level="6"/>
+    <!-- level 7 -->
+    <field field_ref="fastr" level="7"/>
+    <field field_ref="slowr" level="7"/>
+    <field field_ref="streamr" level="7"/>
+    <field field_ref="laker" level="7"/>
+    <field field_ref="lake_overflow" level="7"/>
+    <field field_ref="mask_coast" level="7"/>
+    <!-- level 8 -->
+    <field field_ref="wbr_fast" level="8"/>
+    <field field_ref="wbr_slow" level="8"/>
+    <field field_ref="wbr_stream" level="8"/>
+    <field field_ref="wbr_lake" level="8"/>
+    <field field_ref="pondr" level="8"/>
+    <field field_ref="swampmap" level="8"/>
+    <field field_ref="irrigation" name="irrigation" level="8" unit="mm/d" > this*86400  </field>
+    <field field_ref="netirrig" name="netirrig" level="8" unit="mm/d" > this*86400  </field>
+    <field field_ref="irrigmap" level="8"/>
+    <field field_ref="floodmap" level="8"/>
+    <field field_ref="floodh" level="8"/>
+    <field field_ref="floodr" level="8"/>
+    <field field_ref="floodout" level="8"/>
+    <field field_ref="k_litt" level="8"/>
+    <field field_ref="beta" level="8"/>
+    <field field_ref="raero" level="8"/>
+    <field field_ref="q_cdrag" level="8"/>
+    <field field_ref="wind" level="8"/>
+    <field field_ref="qsatt" level="8"/>
+    <field field_ref="vbeta1" level="8"/>
+    <field field_ref="vbeta4" level="8"/>
+    <field field_ref="vbeta5" level="8"/>
+    <field field_ref="gsmean" level="8"/>
+    <field field_ref="humrel" level="8"/>
+    <!-- level 10 -->
+    <field field_ref="cimean" level="10"/>
+    <field field_ref="vbeta3" level="10"/>
+    <field field_ref="rveget" level="10"/>
+    <field field_ref="rsol" level="10"/>
+    <field field_ref="vbeta2" level="10"/>
+    <field field_ref="qsintmax" level="10"/>
+    <!-- level 11 -->
+    <field field_ref="humtot_top" level="11"/>
+    <field field_ref="humtot" name="mrso" level="11"/>
+    <field field_ref="runoff" name="mrros" level="11"/>
+    <field field_ref="mrro" level="11"/>
+    <field field_ref="prveg" level="11"/>
+    <field field_ref="evspsblveg" level="11"/>
+    <field field_ref="evspsblsoi" level="11"/>
+    <field field_ref="tran" level="11"/>
+    <field field_ref="treeFrac" level="11"/>
+    <field field_ref="grassFrac" level="11"/>
+    <field field_ref="cropFrac" level="11"/>
+    <field field_ref="baresoilFrac" level="11"/>
+    <field field_ref="residualFrac" level="11"/>
+    <field field_ref="PAR" level="11"/>
+    <field field_ref="PARsun" level="11"/>
+    <field field_ref="PARsh" level="11"/>
+    <field field_ref="laisun" level="11"/>
+    <field field_ref="laish" level="11"/>
+    <field field_ref="PARsuntab" level="11"/>
+    <field field_ref="PARshtab" level="11"/>
+    <field field_ref="coszang" level="11"/>
+    <field field_ref="PARdf" level="11"/>
+    <field field_ref="PARdr" level="11"/>
+    <field field_ref="flx_fertil_no" level="11"/>
+    <field field_ref="CRF" level="11"/>
+    <field field_ref="flx_co2_bbg_year" level="11"/>
+    <field field_ref="N_qt_WRICE_year" level="11"/>
+    <field field_ref="N_qt_OTHER_year" level="11"/>
+    <field field_ref="flx_iso" level="11"/>
+    <field field_ref="flx_mono" level="11"/>
+    <field field_ref="flx_ORVOC" level="11"/>
+    <field field_ref="flx_MBO" level="11"/>
+    <field field_ref="flx_methanol" level="11"/>
+    <field field_ref="flx_acetone" level="11"/>
+    <field field_ref="flx_acetal" level="11"/>
+    <field field_ref="flx_formal" level="11"/>
+    <field field_ref="flx_acetic" level="11"/>
+    <field field_ref="flx_formic" level="11"/>
+    <field field_ref="flx_no_soil" level="11"/>
+    <field field_ref="flx_no" level="11"/>
+    <field field_ref="pb" level="11"/>
+    <field field_ref="slowflow" level="11"/>
+    <field field_ref="qsintveg_tot" level="11"/>
+    <field field_ref="LAImean" level="11"/>
+    <field field_ref="mcs" level="11"/>
+    <field field_ref="nroot" level="11"/>
+    <field field_ref="dh" level="11"/>
+    <field field_ref="water2infilt" level="11"/>
+    <field field_ref="flx_apinen"  level="11" />
+    <field field_ref="flx_bpinen"  level="11" />
+    <field field_ref="flx_limonen" level="11" />
+    <field field_ref="flx_myrcen"  level="11" />
+    <field field_ref="flx_sabinen" level="11" />
+    <field field_ref="flx_camphen" level="11" />
+    <field field_ref="flx_3caren"  level="11" />
+    <field field_ref="flx_tbocimen" level="11"/>
+    <field field_ref="flx_othermono" level="11"/>
+    <field field_ref="flx_sesquiter" level="11"/>
+    <field field_ref="fco2" level="11"/>
+    <field field_ref="cim" level="11"/>
+    <field field_ref="kk_moy" level="11"/>
+    <field field_ref="profil_froz_hydro" level="11"/>
+    <field field_ref="profil_froz_hydro_ns" level="11"/>
+    <field field_ref="pkappa"  level="11"/>
+    <field field_ref="pkappa_snow" level="11"/>
+    <field field_ref="pcapa"  level="11"/>
+    <field field_ref="pcapa_snow"  level="11"/>
+    <field field_ref="snowtemp"  level="11"/>
+    <field field_ref="snowliq"  level="11"/>
+    <field field_ref="snowdz"  level="11"/>
+    <field field_ref="snowrho"  level="11"/>
+    <field field_ref="snowheat"  level="11"/>
+    <field field_ref="snowgrain"  level="11"/>
+    <field field_ref="asoilcol"  level="11"/>
+    <field field_ref="aalb_bg"  level="11"/>
+    <field field_ref="atext"  level="11"/>
+    <field field_ref="areftemp"  level="11"/>
+    <field field_ref="alaimap"  level="11"/>
+    <field field_ref="aslope"  level="11"/>
+    <field field_ref="aveget"  level="11"/>
+    <field field_ref="aveget5k"  level="11"/>
+    <field field_ref="achem_wrice"  level="11"/>
+    <field field_ref="achem_other"  level="11"/>
+    <field field_ref="achem_co2"  level="11"/>
+    <field field_ref="frac_snow"  level="11"/>
+    <field field_ref="lake_overflow_coast" level="7"/>
+    <field field_ref="frac_snow_veg"  level="12"/>
+    <field field_ref="frac_snow_nobio"  level="12"/>
+  </file>
+
+
+  <!-- Sechiba file 2 -->
+  <file id="sechiba2" name="sechiba_out_2" output_level="2" output_freq="10800s" enabled="_AUTO_">
+    <!-- level 1 -->
+    <field field_ref="areas" level="1"/>
+    <field field_ref="LandPoints" level="20"/>
+    <field field_ref="contfrac" level="1"/>
+    <field field_ref="humtot_top" level="1"/>
+    <field field_ref="mrro" level="1"/>
+    <field field_ref="ptn" level="1"/>
+    <field field_ref="wtd" level="1"/>
+    <field field_ref="tws" level="1"/>
+
+    <!-- level 2 -->
+    <field field_ref="q_cdrag" level="2"/>
+    <field field_ref="soilalb_vis" level="2"/>
+    <field field_ref="soilalb_nir" level="2"/>
+    <field field_ref="vegalb_vis" level="2"/>
+    <field field_ref="vegalb_nir" level="2"/>
+    <field field_ref="z0m" level="2"/>
+    <field field_ref="z0h" level="2"/>
+    <field field_ref="coastalflow" level="2"/>
+    <field field_ref="riverflow" level="2"/>
+    <field field_ref="tsol_rad" level="2"/>
+    <field field_ref="vevapnu" level="2"/>
+    <field field_ref="temp_sol_new_C" level="2"/>
+    <field field_ref="qsurf" level="2"/>
+    <field field_ref="fluxsens" level="2"/>
+    <field field_ref="fluxlat" level="2"/>
+    <field field_ref="emis" level="2"/>
+    <field field_ref="riversret" level="2"/>
+    <field field_ref="hydrographs" level="2"/>
+    <field field_ref="undermcr" level="2"/>
+    <field field_ref="ru_corr" level="2"/>
+    <field field_ref="ru_corr2" level="2"/>
+    <field field_ref="dr_corr" level="2"/>
+    <field field_ref="dr_force" level="2"/>
+    <field field_ref="ru_infilt" level="2"/>
+    <field field_ref="qinfilt" level="2"/>
+    <field field_ref="dr_corrnum" level="2"/>
+    <!-- level 3 -->
+    <field field_ref="vevapp_day" level="3"/>
+    <field field_ref="precip_rain" level="3" name="rain" unit="mm/d" > precip_rain*86400  </field>
+    <field field_ref="precip_snow" level="3" name="snowf" unit="mm/d" > precip_snow*86400  </field>
+    <field field_ref="netrad" level="3"/>
+    <field field_ref="lai" level="3"/>
+    <field field_ref="basinmap" level="3"/>
+    <field field_ref="nbrivers" level="3"/>
+    <field field_ref="mc" level="3"/>
+    <field field_ref="check_infilt" level="3"/>
+    <field field_ref="check_tr" level="3"/>
+    <field field_ref="check_over" level="3"/>
+    <field field_ref="check_under" level="3"/>
+    
+
+    <!-- level 4 -->
+    <field field_ref="vevapsno" name="subli" level="4" unit="mm/d" > this*86400  </field>
+    <field field_ref="runoff" name="runoff" level="4" unit="mm/d" > runoff*86400  </field>
+    <field field_ref="drainage" name="drainage" level="4" unit="mm/d" > drainage*86400  </field>
+    <field field_ref="temp_air" level="4"/>
+    <field field_ref="qair" level="4"/>
+    <field field_ref="q2m" level="4"/>
+    <field field_ref="t2m" level="4"/>
+    <field field_ref="albedo_vis" level="4"/>
+    <field field_ref="albedo_nir" level="4"/>
+    <field field_ref="roughheight" level="4"/>
+    <field field_ref="transpir" level="4"/>
+    <field field_ref="inter" level="4"/>
+    <field field_ref="evapnu_soil" level="4"/>
+    <field field_ref="drainage_soil" level="4"/>
+    <field field_ref="transpir_soil" level="4"/>
+    <field field_ref="runoff_soil" level="4"/>
+    <!-- level 5 -->
+    <field field_ref="tsol_max" level="5"/>
+    <field field_ref="tsol_min" level="5"/>
+    <field field_ref="snow" level="5"/>
+    <field field_ref="snowage" level="5"/>
+    <field field_ref="snownobio" level="5"/>
+    <field field_ref="snownobioage" level="5"/>
+    <field field_ref="snowmelt" level="5"/>
+    <field field_ref="tot_melt" level="5"/>
+    <field field_ref="snowmelt_from_maxmass" level="5"/>
+    <field field_ref="soilcap" level="5"/>
+    <field field_ref="vegetfrac" level="5"/>
+    <field field_ref="maxvegetfrac" level="5"/>
+    <field field_ref="nobiofrac" level="5"/>
+    <field field_ref="kfact_root" level="5"/>
+    <field field_ref="vegetmax_soil" level="5"/>
+    <field field_ref="temp_hydro"  level="5"/>
+    <!-- level 6 -->
+    <field field_ref="dss" level="6"/>
+    <field field_ref="gqsb" level="6"/>
+    <field field_ref="bqsb" level="6"/>
+    <field field_ref="humtot" level="6"/>
+    <field field_ref="tmc" level="6"/>
+    <field field_ref="qsintveg" level="6"/>
+    <field field_ref="rstruct" level="6"/>
+    <field field_ref="gpp" level="6"/>
+    <field field_ref="nee" level="6"/>
+    <field field_ref="maint_resp" level="6"/>
+    <field field_ref="hetero_resp" level="6"/>
+    <field field_ref="growth_resp" level="6"/>
+    <field field_ref="npp" level="6"/>
+    <field field_ref="precisol" level="6"/>
+    <field field_ref="drysoil_frac" level="6"/>
+    <field field_ref="evapot" level="6"/>
+    <field field_ref="evapot_corr" level="6"/>
+    <field field_ref="twbr" level="6"/>
+    <!-- level 7 -->
+    <field field_ref="swnet" level="7"/>
+    <field field_ref="swdown" level="7"/>
+    <field field_ref="lwdown" level="7"/>
+    <field field_ref="lwnet" level="7"/>
+    <field field_ref="diffevap" level="7"/>
+    <!-- level 8 -->
+    <field field_ref="fastr" level="8"/>
+    <field field_ref="slowr" level="8"/>
+    <field field_ref="streamr" level="8"/>
+    <field field_ref="floodr" level="8"/>
+    <field field_ref="floodh" level="8"/>
+    <field field_ref="pondr" level="8"/>
+    <field field_ref="laker" level="8"/>
+    <field field_ref="irrigation" name="irrigation" level="8" unit="mm/d" > this*86400  </field>
+    <field field_ref="netirrig" name="netirrig" level="8" unit="mm/d" > this*86400  </field>
+    <field field_ref="irrigmap" level="8"/>
+    <field field_ref="floodmap" level="8"/>
+    <field field_ref="swampmap" level="8"/>
+
+    <!-- for water budget control -->
+    <!-- Note! The _daily variables need an output frequency of at least one day -->
+    <field field_ref="delsoilmoist_daily" level="8" />
+    <field field_ref="delintercept_daily" level="8" />
+    <field field_ref="delswe_daily" level="8" />
+    <field field_ref="delfastr_daily" level="8" />
+    <field field_ref="delslowr_daily" level="8" />
+    <field field_ref="delstreamr_daily" level="8" />
+    <field field_ref="dellaker_daily" level="8" />
+    <field field_ref="delpondr_daily" level="8" />
+    <field field_ref="delfloodr_daily" level="8" />
+    <field field_ref="delstock_routing" level="8" />
+    <field field_ref="evapnu" level="8"/>
+    <field field_ref="evapflo" level="8"/>
+
+    <!-- level 9 -->
+    <field field_ref="beta" level="9"/>
+    <field field_ref="raero" level="9"/>
+    <field field_ref="wind" level="9"/>
+    <field field_ref="qsatt" level="9"/>
+    <field field_ref="vbeta1" level="9"/>
+    <field field_ref="vbeta4" level="9"/>
+    <field field_ref="gsmean" level="9"/>
+    <field field_ref="vbeta5" level="9"/>
+    <field field_ref="reinf_slope" level="9"/>
+    <field field_ref="njsc" level="9"/>
+    <field field_ref="humrel" level="9"/>
+    <!-- level 10 -->
+    <field field_ref="cimean" level="10"/>
+    <field field_ref="vbeta3" level="10"/>
+    <field field_ref="rveget" level="10"/>
+    <field field_ref="rsol" level="10"/>
+    <field field_ref="vbeta2" level="10"/>
+    <field field_ref="qsintmax" level="10"/>
+    <field field_ref="PAR" level="10"/>
+    <field field_ref="PARsun" level="10"/>
+    <field field_ref="PARsh" level="10"/>
+    <field field_ref="laisun" level="10"/>
+    <field field_ref="laish" level="10"/>
+    <field field_ref="PARsuntab" level="10"/>
+    <field field_ref="PARshtab" level="10"/>
+    <field field_ref="coszang" level="10"/>
+    <field field_ref="PARdf" level="10"/>
+    <field field_ref="PARdr" level="10"/>
+    <field field_ref="flx_fertil_no" level="10"/>
+    <field field_ref="CRF" level="10"/>
+    <field field_ref="flx_co2_bbg_year" level="10"/>
+    <field field_ref="N_qt_WRICE_year" level="10"/>
+    <field field_ref="N_qt_OTHER_year" level="10"/>
+    <field field_ref="flx_iso" level="10"/>
+    <field field_ref="flx_mono" level="10"/>
+    <field field_ref="flx_ORVOC" level="10"/>
+    <field field_ref="flx_MBO" level="10"/>
+    <field field_ref="flx_methanol" level="10"/>
+    <field field_ref="flx_acetone" level="10"/>
+    <field field_ref="flx_acetal" level="10"/>
+    <field field_ref="flx_formal" level="10"/>
+    <field field_ref="flx_acetic" level="10"/>
+    <field field_ref="flx_formic" level="10"/>
+    <field field_ref="flx_no_soil" level="10"/>
+    <field field_ref="flx_no" level="10"/>
+    <field field_ref="pb" level="11"/>
+    <field field_ref="slowflow" level="11"/>
+    <field field_ref="qsintveg_tot" level="11"/>
+    <field field_ref="LAImean" level="11"/>
+    <field field_ref="mcs" level="11"/>
+    <field field_ref="nroot" level="11"/>
+    <field field_ref="dh" level="11"/>
+    <field field_ref="water2infilt" level="11"/>
+    <field field_ref="kk_moy" level="11"/>
+    <field field_ref="profil_froz_hydro" level="11"/>
+    <field field_ref="profil_froz_hydro_ns" level="11"/>
+    <field field_ref="pkappa"  level="11"/>
+    <field field_ref="pkappa_snow" level="11"/>
+    <field field_ref="pcapa"  level="11"/>
+    <field field_ref="pcapa_snow"  level="11"/>
+    <field field_ref="snowtemp"  level="11"/>
+    <field field_ref="snowliq"  level="11"/>
+    <field field_ref="snowdz"  level="11"/>
+    <field field_ref="snowrho"  level="11"/>
+    <field field_ref="snowheat"  level="11"/>
+    <field field_ref="snowgrain"  level="11"/>
+
+  </file>
+
+  <!-- Sechiba alma file 1 -->
+  <file id="sechiba1_alma" name="sechiba_history_alma" output_level="10" output_freq="1mo" enabled=".FALSE.">
+    <field field_ref="areas" level="1"/>
+    <field field_ref="LandPoints" level="20"/>
+    <field field_ref="contfrac" level="1"/>
+    <field field_ref="soilflx" level="1"/>
+    <field field_ref="Qv" level="1"/>
+    <field field_ref="runoff" name="Qs" level="1"/>
+    <field field_ref="drainage" name="Qsb" level="1"/>
+    <field field_ref="coastalflow" name="CoastalFlow" level="1"/>
+    <field field_ref="riverflow" name="RiverFlow" level="1"/>
+    <field field_ref="surfheat_incr" level="1"/>
+    <field field_ref="coldcont_incr" level="1"/>
+    <field field_ref="fluxsens" name="Qh" level="1"/>
+    <field field_ref="fluxlat" name="Qle" level="1"/>
+    <field field_ref="lwnet" name="LWnet" level="1"/>
+    <field field_ref="swnet" name="SWnet" level="1"/>
+    <field field_ref="precip_rain" name="Rainf" level="1"/>
+    <field field_ref="precip_snow" name="Snowf" level="1"/>
+    <field field_ref="vevapp" name="Evap" level="1"/>
+    <field field_ref="tot_melt" name="Qsm" level="1"/>
+    <field field_ref="irrigation" name="Qirrig" level="1"/>
+    <field field_ref="netirrig" name="Qirrig_req" long_name="Irrigation requirement" level="1"/>
+    <field field_ref="temp_sol_new" level="1"/>
+    <field field_ref="PotSurfT" level="1"/>
+    <field field_ref="albedo_glob" level="1"/>
+    <field field_ref="SurfStor" level="1"/>
+    <field field_ref="snow" name="SWE" long_name="Snow Water Equivalent" level="1"/>
+    <field field_ref="soilwet" level="1"/>
+    <field field_ref="evapot_corr" name="PotEvap" long_name="Potential evapotranspiration" unit="kg/m^2/s" level="1"/>
+    <field field_ref="evapot" name="PotEvapOld" long_name="Potential evapotranspiration old method" unit="kg/m^2/s" level="1"/>
+    <field field_ref="ECanop" level="1"/>
+    <field field_ref="TVeg" level="1"/>
+    <field field_ref="vevapsno" name="SubSnow" level="1"/>
+    <field field_ref="irrigmap" name="IrrigationMap" level="1"/>
+    <field field_ref="floodmap" name="FloodplainsMap" level="1"/>
+    <field field_ref="swampmap" name="SwampMap" level="1"/>
+    <field field_ref="hydrographs" name="Dis" level="1"/>
+    <field field_ref="gpp" name="GPP" level="1"/>
+    <field field_ref="nee" name="NEE" level="1"/>
+    <field field_ref="maint_resp" level="1"/>
+    <field field_ref="hetero_resp" level="1"/>
+    <field field_ref="growth_resp" level="1"/>
+    <field field_ref="npp" level="1"/>
+    <field field_ref="z0m" name="Z0m" long_name="Roughness height for momentum" level="1"/>
+    <field field_ref="z0h" name="Z0h" long_name="Roughness height for heat" level="1"/>
+    <field field_ref="roughheight" name="EffectHeight" long_name="Effective displacement height (h-d)" level="1"/>
+    <field field_ref="delsoilmoist" level="1"/>
+    <field field_ref="delintercept" level="1"/>
+    <field field_ref="delswe" level="1"/>
+    <field field_ref="vevapnu_alma" level="1"/>
+    <field field_ref="evapflo_alma" level="1"/>
+    <field field_ref="ACond" level="1"/>
+    <field field_ref="temp_air" name="Tair" level="2"/>
+    <field field_ref="qair" name="Qair" level="2"/>
+    <field field_ref="Qf" level="2"/>
+    <field field_ref="vegetfrac" level="3"/>
+    <field field_ref="maxvegetfrac" level="3"/>
+    <field field_ref="nobiofrac" level="3"/>
+    <field field_ref="soilmoist" level="7"/>
+    <field field_ref="humtot" name="RootMoist" long_name="Root zone soil water" level="1"/>
+    <field field_ref="ptn" name="SoilTemp" level="7"/>
+    <field field_ref="vbeta1" name="SnowFrac" level="7"/>
+    <field field_ref="albedo_snow" level="7"/>
+    <field field_ref="snowdz" name="SnowDepth" level="7"/>
+    <field field_ref="temp_sol_new" name="RadT" level="1"/>
+    <field field_ref="twbr" level="1"/>
+  </file>
+
+  <!-- Sechiba alma file 2 -->
+  <file id="sechiba2_alma" name="sechiba_out_2_alma" output_level="10" output_freq="1d" enabled=".FALSE.">
+    <field field_ref="areas" level="1"/>
+    <field field_ref="LandPoints" level="20"/>
+    <field field_ref="contfrac" level="1"/>
+    <field field_ref="soilflx" level="1"/>
+    <field field_ref="Qv" level="1"/>
+    <field field_ref="runoff" name="Qs" level="1"/>
+    <field field_ref="drainage" name="Qsb" level="1"/>
+    <field field_ref="coastalflow" name="CoastalFlow" level="1"/>
+    <field field_ref="riverflow" name="RiverFlow" level="1"/>
+    <field field_ref="surfheat_incr" level="1"/>
+    <field field_ref="coldcont_incr" level="1"/>
+    <field field_ref="fluxsens" name="Qh" level="1"/>
+    <field field_ref="fluxlat" name="Qle" level="1"/>
+    <field field_ref="lwnet" name="LWnet" level="1"/>
+    <field field_ref="swnet" name="SWnet" level="1"/>
+    <field field_ref="precip_rain" name="Rainf" level="1"/>
+    <field field_ref="precip_snow" name="Snowf" level="1"/>
+    <field field_ref="vevapp" name="Evap" level="1"/>
+    <field field_ref="tot_melt" name="Qsm" level="1"/>
+    <field field_ref="irrigation" name="Qirrig" level="1"/>
+    <field field_ref="netirrig" name="Qirrig_req" long_name="Irrigation requirement" level="1"/>
+    <field field_ref="temp_sol_new" level="1"/>
+    <field field_ref="albedo_glob" level="1"/>
+    <field field_ref="SurfStor" level="1"/>
+    <field field_ref="snow" name="SWE" long_name="Snow Water Equivalent" level="1"/>
+    <field field_ref="soilwet" level="1"/>
+    <field field_ref="ECanop" level="1"/>
+    <field field_ref="TVeg" level="1"/>
+    <field field_ref="vevapsno" name="SubSnow" level="1"/>
+    <field field_ref="irrigmap" name="IrrigationMap" level="1"/>
+    <field field_ref="floodmap" name="FloodplainsMap" level="1"/>
+    <field field_ref="swampmap" name="SwampMap" level="1"/>
+    <field field_ref="hydrographs" name="Dis" level="1"/>
+    <field field_ref="gpp" name="GPP" level="1"/>
+    <field field_ref="nee" name="NEE" level="1"/>
+    <field field_ref="maint_resp" level="1"/>
+    <field field_ref="hetero_resp" level="1"/>
+    <field field_ref="growth_resp" level="1"/>
+    <field field_ref="npp" level="1"/>
+    <field field_ref="delsoilmoist" level="1"/>
+    <field field_ref="delintercept" level="1"/>
+    <field field_ref="delswe" level="1"/>
+    <field field_ref="vevapnu_alma" level="1"/>
+    <field field_ref="evapflo_alma" level="1"/>
+    <field field_ref="ACond" level="1"/>
+    <field field_ref="soilmoist" level="7"/>
+    <field field_ref="humtot" name="RootMoist" long_name="Root zone soil water" level="1"/>
+    <field field_ref="ptn" name="SoilTemp" level="7"/>
+    <field field_ref="vbeta1" name="SnowFrac" level="7"/>
+    <field field_ref="albedo_snow" level="7"/>
+    <field field_ref="snowdz" name="SnowDepth" level="7"/>
+    <field field_ref="Qf" level="2"/>
+    <field field_ref="vegetfrac" level="3"/>
+    <field field_ref="maxvegetfrac" level="3"/>
+    <field field_ref="nobiofrac" level="3"/>
+    <field field_ref="temp_sol_new" name="RadT" level="5"/>
+  </file>
+
+  <!-- Definition of files with stomate diagnostics -->
+  <!-- Stomate file 1 -->
+  <!-- output_level="10"-->
+  <file id="stomate1" name="stomate_history" output_level="1" output_freq="_AUTO_" enabled="_AUTO_">
+    <!-- level 1 -->
+    <field field_ref="RESOLUTION_X" level="1"/>
+    <field field_ref="RESOLUTION_Y" level="1"/>
+    <field field_ref="CONTFRAC_STOMATE" level="1"/>
+    <field field_ref="areas" level="1"/>
+    <field field_ref="T2M_MONTH" level="1"/>
+    <field field_ref="T2M_WEEK" level="1"/>
+    <field field_ref="firefrac" level="1"/>
+    <field field_ref="CO2_FIRE" level="1"/>
+    <field field_ref="CO2_TAKEN" level="1"/>
+    <field field_ref="LAI" level="1"/>
+    <field field_ref="VEGET_MAX" level="1"/>
+    <field field_ref="NPP_STOMATE" level="1"/>
+    <field field_ref="GPP" level="1"/>
+    <!-- level 2 -->
+    <field field_ref="LEAF_M" level="2"/>
+    <field field_ref="SAP_M_AB" level="2"/>
+    <field field_ref="SAP_M_BE" level="2"/>
+    <field field_ref="HEART_M_AB" level="2"/>
+    <field field_ref="HEART_M_BE" level="2"/>
+    <field field_ref="ROOT_M" level="2"/>
+    <field field_ref="FRUIT_M" level="2"/>
+    <field field_ref="RESERVE_M" level="2"/>
+    <field field_ref="MAINT_RESP" level="2"/>
+    <field field_ref="GROWTH_RESP" level="2"/>
+    <!-- level 3 -->
+    <field field_ref="IND" level="3"/>
+    <field field_ref="ADAPTATION" level="3"/>
+    <field field_ref="REGENERATION" level="3"/>
+    <field field_ref="CN_IND" level="3"/>
+    <field field_ref="WOODMASS_IND" level="3"/>
+    <field field_ref="MOISTRESS" level="3"/>
+    <field field_ref="HET_RESP" level="3"/>
+    <!-- level 4 -->
+    <field field_ref="SAP_AB_TURN" level="4"/>
+    <field field_ref="ROOT_TURN" level="4"/>
+    <field field_ref="FRUIT_TURN" level="4"/>
+    <field field_ref="TOTAL_BM_LITTER" level="4"/>
+    <field field_ref="LEAF_BM_LITTER" level="4"/>
+    <field field_ref="SAP_AB_BM_LITTER" level="4"/>
+    <field field_ref="SAP_BE_BM_LITTER" level="4"/>
+    <field field_ref="HEART_AB_BM_LITTER" level="4"/>
+    <field field_ref="HEART_BE_BM_LITTER" level="4"/>
+    <field field_ref="ROOT_BM_LITTER" level="4"/>
+    <field field_ref="FRUIT_BM_LITTER" level="4"/>
+    <field field_ref="RESERVE_BM_LITTER" level="4"/>
+    <field field_ref="TOTAL_M" level="4"/>
+    <field field_ref="TOTAL_TURN" level="4"/>
+    <field field_ref="LEAF_TURN" level="4"/>
+    <!-- level 5 -->
+    <field field_ref="LITTER_STR_AB" level="5"/>
+    <field field_ref="LITTER_MET_AB" level="5"/>
+    <field field_ref="LITTER_STR_BE" level="5"/>
+    <field field_ref="LITTER_MET_BE" level="5"/>
+    <field field_ref="DEADLEAF_COVER" level="5"/>
+    <field field_ref="TOTAL_SOIL_CARB" level="5"/>
+    <field field_ref="CARBON_ACTIVE" level="5"/>
+    <field field_ref="CARBON_SLOW" level="5"/>
+    <field field_ref="CARBON_PASSIVE" level="5"/>
+    <field field_ref="LITTERHUM" level="5"/>
+    <field field_ref="BM_ALLOC_LEAF" level="5"/>
+    <field field_ref="BM_ALLOC_SAP_AB" level="5"/>
+    <field field_ref="BM_ALLOC_SAP_BE" level="5"/>
+    <field field_ref="BM_ALLOC_ROOT" level="5"/>
+    <field field_ref="BM_ALLOC_FRUIT" level="5"/>
+    <field field_ref="BM_ALLOC_RES" level="5"/>
+    <field field_ref="HERBIVORES" level="5"/>
+    <field field_ref="TURNOVER_TIME" level="5"/>
+    <field field_ref="PROD10" level="5"/>
+    <field field_ref="FLUX10" level="5"/>
+    <field field_ref="PROD100" level="5"/>
+    <field field_ref="FLUX100" level="5"/>
+    <field field_ref="CONVFLUX" level="5"/>
+    <field field_ref="CFLUX_PROD10" level="5"/>
+    <field field_ref="CFLUX_PROD100" level="5"/>
+    <field field_ref="HARVEST_ABOVE" level="5"/>
+    <!-- level 6 -->
+    <field field_ref="VCMAX" level="6"/>
+    <field field_ref="LEAF_AGE" level="6"/>
+    <field field_ref="mortality" level="6"/>
+    <field field_ref="firedeath" level="6"/>
+    <field field_ref="IND_ESTAB" level="6"/>
+    <field field_ref="ESTABTREE" level="6"/>
+    <field field_ref="ESTABGRASS" level="6"/>
+    <field field_ref="light_death" level="6"/>
+    <!-- level 7 -->
+    <field field_ref="AGE" level="7"/>
+    <field field_ref="HEIGHT" level="7"/>
+    <!-- level 9 -->
+    <field field_ref="WHEN_GROWTHINIT" level="9"/>
+    <field field_ref="PFTPRESENT" level="9"/>
+    <field field_ref="GDD_MIDWINTER" level="9"/>
+    <field field_ref="GDD_M5_DORMANCE" level="9"/>
+    <field field_ref="NCD_DORMANCE" level="9"/>
+    <field field_ref="ALLOW_INITPHENO" level="9"/>
+    <field field_ref="BEGIN_LEAVES" level="9"/>
+    <field field_ref="t2m_longterm" level="9"/>
+    <field field_ref="TSEASON"  level="9"/>
+    <field field_ref="TMIN_SPRING_TIME" level="9"/>
+    <field field_ref="ONSET_DATE" level="9"/>
+    <field field_ref="FPC_MAX" level="9"/>
+    <field field_ref="MAXFPC_LASTYEAR" level="9"/>
+    <!-- level 10 -->
+    <field field_ref="FIREINDEX" level="10"/>
+  </file>
+
+  <!-- Stomate file 2 -->
+  <file id="stomate2" name="stomate_ipcc_history" output_level="1" output_freq="_AUTO_" enabled="_AUTO_">
+    <!-- level 1 -->
+    <field field_ref="RESOLUTION_X" level="1"/>
+    <field field_ref="RESOLUTION_Y" level="1"/>
+    <field field_ref="CONTFRAC_STOMATE" level="1"/>
+    <field field_ref="areas" level="1"/>
+    <field field_ref="cVeg" level="1"/>
+    <field field_ref="cLitter" level="1"/>
+    <field field_ref="cSoil" level="1"/>
+    <field field_ref="cProduct" level="1"/>
+    <field field_ref="cMassVariation" level="1"/>
+    <field field_ref="lai_ipcc" level="1"/>
+    <field field_ref="gpp_ipcc" level="1"/>
+    <field field_ref="ra" level="1"/>
+    <field field_ref="npp_ipcc" level="1"/>
+    <field field_ref="rh" level="1"/>
+    <field field_ref="fFire" level="1"/>
+    <field field_ref="fHarvest" level="1"/>
+    <field field_ref="fLuc" level="1"/>
+    <field field_ref="nbp" level="1"/>
+    <field field_ref="fVegLitter" level="1"/>
+    <field field_ref="fLitterSoil" level="1"/>
+    <field field_ref="cLeaf" level="1"/>
+    <field field_ref="cWood" level="1"/>
+    <field field_ref="cRoot" level="1"/>
+    <field field_ref="cMisc" level="1"/>
+    <field field_ref="cLitterAbove" level="1"/>
+    <field field_ref="cLitterBelow" level="1"/>
+    <field field_ref="cSoilFast" level="1"/>
+    <field field_ref="cSoilMedium" level="1"/>
+    <field field_ref="cSoilSlow" level="1"/>
+    <field field_ref="landCoverFrac" level="1"/>
+    <field field_ref="treeFracPrimDec" level="1"/>
+    <field field_ref="treeFracPrimEver" level="1"/>
+    <field field_ref="c3PftFrac" level="1"/>
+    <field field_ref="c4PftFrac" level="1"/>
+    <field field_ref="rGrowth" level="1"/>
+    <field field_ref="rMaint" level="1"/>
+    <field field_ref="nppLeaf" level="1"/>
+    <field field_ref="nppWood" level="1"/>
+    <field field_ref="nppRoot" level="1"/>
+    <field field_ref="nep" level="1"/>
+  </file>
+</file_definition>
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/gcm.def_96x95
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/gcm.def_96x95	(revision 5878)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/gcm.def_96x95	(revision 5879)
@@ -1,5 +1,5 @@
 ## $Id$
 ## nombre de pas par jour (multiple de iperiod) ( ici pour  dt = 1 min )      
-day_step=480
+day_step=720
 ## periode pour le pas Matsuno (en pas)
 iperiod=5
@@ -26,5 +26,5 @@
 ## periode de la physique (en pas)                                       
 ## iphysiq est modifie pour la nouvelle physique par le lmdz.driver pour les autres cas le valeur par defaut est utilise
-iphysiq=_AUTO_ : DEFAULT = 10
+iphysiq=_AUTO_ : DEFAULT = 15
 ## longitude en degres du centre du zoom                                 
 clon=0.
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_ORCA2_cfg_paleo
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_ORCA2_cfg_paleo	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_ORCA2_cfg_paleo	(revision 5879)
@@ -0,0 +1,316 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! NEMO/OPA  Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_ref
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!
+!-----------------------------------------------------------------------
+&namrun        !   parameters of the run
+!-----------------------------------------------------------------------
+   cn_exp      = _AUTOBLOCKER_    !  Experience name
+   nn_it000    = _AUTOBLOCKER_    !  First time step
+   nn_itend    = _AUTOBLOCKER_    !  Last  time step
+   nn_date0    = _AUTOBLOCKER_    !  Date at nit_0000 (format yyyymmdd) used if ln_rstart=F or (ln_rstart=T and nn_rstctl=0 or 1)
+   nn_leapy    = _AUTOBLOCKER_    !  Leap year calendar (1) or not (0)
+   ln_rstart   = _AUTOBLOCKER_    !  start from rest (F) or from a restart file (T)
+   nn_rstctl   = _AUTOBLOCKER_    !  Restart control => activated only if ln_rstart = T
+                           !    = 0 nn_date0 read in namelist ; nn_it000 : read in namelist
+                           !    = 1 nn_date0 read in namelist ; nn_it000 : check consistancy between namelist and restart
+                           !    = 2 nn_date0 read in restart  ; nn_it000 : check consistancy between namelist and restart
+   cn_ocerst_in  = "restartopa"   !  Suffix of ocean restart name (input)
+   cn_ocerst_indir = "."       !  directory from which to read input ocean restarts
+   cn_ocerst_out = "restart"      !  Suffix of ocean restart name (output)
+   cn_ocerst_outdir = "."      !  directory in which to write output ocean restarts
+   nn_istate   =       0   !  Output the initial state (1) or not (0)
+   nn_stock    =  _AUTOBLOCKER_   !  Frequency of creation of a restart file (modulo referenced to 1)
+   nn_write    =    5475   !  Requency of write in the output file   (modulo referenced to nn_it000)
+   ln_mskland  = .true.    !  Masks land points in NetCDF outputs
+   ln_dimgnnn  = .false.   !  DIMG file format: 1 file for all processors (F) or by processor (T)
+   ln_cfmeta   = .true.   !  output additional data to netCDF files required for compliance with the CF metadata standard
+   ln_clobber  = .true.    !  clobber (overwrite) an existing file
+   nn_chunksz  =       0   !  chunksize (bytes) for NetCDF file (works only with iom_nf90 routines)
+/
+!-----------------------------------------------------------------------
+&namcfg        !   parameters of the configuration
+!-----------------------------------------------------------------------
+   cp_cfg      =  "paleorca"               !  name of the configuration
+   jp_cfg      =       2               !  resolution of the configuration
+   jpidta      =     182               !  1st lateral dimension ( >= jpi )
+   jpjdta      =     149               !  2nd    "         "    ( >= jpj )
+   jpkdta      =      31               !  number of levels      ( >= jpk )
+   jpiglo      =     182               !  1st dimension of global domain --> i =jpidta
+   jpjglo      =     149               !  2nd    -                  -    --> j  =jpjdta
+   jpizoom     =       1               !  left bottom (i,j) indices of the zoom
+   jpjzoom     =       1               !  in data domain indices
+   jperio      =       6               !  lateral cond. type (between 0 and 6)
+/
+!-----------------------------------------------------------------------
+&namzgr        !   vertical coordinate
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdom        !   space and time domain (bathymetry, mesh, timestep)
+!-----------------------------------------------------------------------
+   nn_msh      =    _AUTO_ !  AUTO - create (=1) a mesh file or not (=0)
+   rn_rdt      = 4800.     !  time step for the dynamics (and tracer if nn_acc=0)
+   nn_closea    =   0      !  remove (=0) or keep (=1) closed seas and lakes (ORCA)
+   !
+   jphgr_msh   =       0               !  type of horizontal mesh
+   ppglam0     =  999999.0             !  longitude of first raw and column T-point (jphgr_msh = 1)
+   ppgphi0     =  999999.0             ! latitude  of first raw and column T-point (jphgr_msh = 1)
+   ppe1_deg    =  999999.0             !  zonal      grid-spacing (degrees)
+   ppe2_deg    =  999999.0             !  meridional grid-spacing (degrees)
+   ppe1_m      =  999999.0             !  zonal      grid-spacing (degrees)
+   ppe2_m      =  999999.0             !  meridional grid-spacing (degrees)
+   ppsur       =   -4762.96143546300   !  ORCA r4, r2 and r05 coefficients
+   ppa0        =     255.58049070440   ! (default coefficients)
+   ppa1        =     245.58132232490   !
+   ppkth       =      21.43336197938   !
+   ppacr       =       3.0             !
+   ppdzmin     =  999999.              !  Minimum vertical spacing
+   pphmax      =  999999.              !  Maximum depth
+   ldbletanh   =  .FALSE.              !  Use/do not use double tanf function for vertical coordinates
+   ppa2        =  999999.              !  Double tanh function parameters
+   ppkth2      =  999999.              !
+   ppacr2      =  999999.              !
+/
+!-----------------------------------------------------------------------
+&namsplit      !   time splitting parameters                            ("key_dynspg_ts")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namcrs        !   Grid coarsening for dynamics output and/or
+               !   passive tracer coarsened online simulations
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtsd    !   data : Temperature  & Salinity
+!-----------------------------------------------------------------------
+   ln_tsd_init   = .true.   !  Initialisation of ocean T & S with T &S input data (T) or not (F)
+   ln_tsd_tradmp = .false.  !  damping of ocean T & S toward T &S input data (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namsbc        !   Surface Boundary Condition (surface module)
+!-----------------------------------------------------------------------
+   nn_fsbc     = 5         !  frequency of surface boundary condition computation
+                           !     (also = the frequency of sea-ice model call)
+   ln_blk_clio = .false.   !  CLIO bulk formulation                     (T => fill namsbc_clio)
+   ln_blk_core = .false.   !  CORE bulk formulation                     (T => fill namsbc_core)
+   ln_blk_mfs  = .false.   !  MFS bulk formulation                      (T => fill namsbc_mfs )
+   ln_cpl      = .true.    !  atmosphere coupled   formulation          ( requires key_oasis3 )
+   ln_mixcpl   = .false.   !  forced-coupled mixed formulation          ( requires key_oasis3 )
+   ln_apr_dyn  = .false.   !  Patm gradient added in ocean & ice Eqs.   (T => fill namsbc_apr )
+   nn_ice      = 2         !  =0 no ice boundary condition   ,
+                           !  =1 use observed ice-cover      ,
+                           !  =2 ice-model used                         ("key_lim3" or "key_lim2")
+   nn_ice_embd = 0         !  AUTO - 
+                           !  =0 levitating ice (no mass exchange, concentration/dilution effect)
+                           !  =1 levitating ice with mass and salt exchange but no presure effect
+                           !  =2 embedded sea-ice (full salt and mass exchanges and pressure)
+   ln_dm2dc    = .false.   !  daily mean to diurnal cycle on short wave
+   ln_rnf      = .false.   !  runoffs                                   (T => fill namsbc_rnf)
+   ln_ssr      = .false.   !  Sea Surface Restoring on T and/or S       (T => fill namsbc_ssr)
+   nn_fwb      = 0         !  FreshWater Budget: =0 unchecked
+                           !     =1 global mean of e-p-r set to zero at each time step
+                           !     =2 annual global mean of e-p-r set to zero
+                           !     =3 global emp set to zero and spread out over erp area
+   ln_wave = .false.       !  Activate coupling with wave (either Stokes Drift or Drag coefficient, or both)  (T => fill namsbc_wave)
+   ln_cdgw = .false.       !  Neutral drag coefficient read from wave model (T => fill namsbc_wave)
+   ln_sdw  = .false.       !  Computation of 3D stokes drift                (T => fill namsbc_wave)
+/
+!-----------------------------------------------------------------------
+&namsbc_core   !   namsbc_core  CORE bulk formulae
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_qsr    !   penetrative solar radiation
+!-----------------------------------------------------------------------
+!              !  file name  ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !             !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_chl      = 'chlorophyll_surface.nc',        -1         , 'CHLA'    ,   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+
+   nn_chldta = 0
+/
+!-----------------------------------------------------------------------
+&namsbc_rnf    !   runoffs namelist surface boundary condition
+!-----------------------------------------------------------------------
+!              !  file name           ! frequency (hours) ! variable  ! time interp. !  clim  ! 'yearly'/ ! weights  ! rotation ! land/sea mask !
+!              !                      !  (if <0  months)  !   name    !   (logical)  !  (T/F) ! 'monthly' ! filename ! pairing  ! filename      !
+   sn_rnf      = 'ORCA_R2_runoff_clim_v1.0_nomask',        -1         , 'sorunoff',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_cnf      = 'ORCA_R2_runoff_clim_v1.0_nomask',         0         , 'socoeff' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+   sn_s_rnf    = 'runoffs'                        ,        24         , 'rosaline',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_t_rnf    = 'runoffs'                        ,        24         , 'rotemper',   .true.     , .true. , 'yearly'  , ''       , ''       , ''
+   sn_dep_rnf  = 'runoffs_ORCA2_depths.nc'        ,         0         , 'rodepth' ,   .false.    , .true. , 'yearly'  , ''       , ''       , ''
+
+   ln_rnf_mouth = .false.    !  specific treatment at rivers mouths
+   ln_rnf_depth = .true.     !  read in depth information for runoff
+   ln_rnf_tem   = .false.    !  read in temperature information for runoff
+   ln_rnf_sal   = .false.    !  read in salinity information for runoff
+   ln_rnf_depth_ini = .true. !  compute depth at initialisation from runoff file
+   rn_rnf_max   = 0.05       !  max value of the runoff climatology over global domain ( if ln_rnf_depth_ini = .true )
+   rn_dep_max = 150.         !  depth over which runoffs is spread ( ln_rnf_depth_ini = .true )
+   nn_rnf_depth_file = _AUTO_     ! create (=1) a runoff depth file or not (=0)
+/
+!-----------------------------------------------------------------------
+&namsbc_ssr    !   surface boundary condition : sea surface restoring
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsbc_alb    !   albedo parameters
+!-----------------------------------------------------------------------
+   nn_ice_alb  =    0   !  parameterization of ice/snow albedo
+                        !     0: Shine & Henderson-Sellers (JGR 1985)
+                        !     1: "home made" based on Brandt et al. (J. Climate 2005)
+                        !                         and Grenfell & Perovich (JGR 2004)
+   rn_albice   =  0.5   !  albedo of bare puddled ice (values from 0.49 to 0.58)
+                        !     0.53 (default) => if nn_ice_alb=0
+                        !     0.50 (default) => if nn_ice_alb=1
+/
+!-----------------------------------------------------------------------
+&namsbc_cpl    !   coupling parameters
+!-----------------------------------------------------------------------
+!                    !     description       !  multiple  !    vector   !      vector          ! vector !
+!                    !                       ! categories !  reference  !    orientation       ! grids  !
+! send
+sn_snd_temp   =       'weighted oce and ice' ,    'no'    ,     ''      ,         ''           ,   ''
+sn_snd_alb    =       'weighted ice'         ,    'no'    ,     ''      ,         ''           ,   ''
+sn_snd_thick  =       'none'                 ,    'no'    ,     ''      ,         ''           ,   ''
+sn_snd_crt    =       'mixed oce-ice'        ,    'no'    , 'cartesian' , 'eastward-northward' ,  'T'
+sn_snd_co2    =       'none'              ,    'no'    ,     ''      ,         ''           ,   ''
+! receive
+sn_rcv_w10m   =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_taumod =       'none'                 ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_tau    =       'mixed oce-ice'        ,    'no'    , 'cartesian' , 'eastward-northward',  'U,V'
+sn_rcv_dqnsdt =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_qsr    =       'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_qns    =       'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_emp    =       'conservative'         ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_rnf    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_cal    =       'coupled'              ,    'no'    ,     ''      ,         ''          ,   ''
+sn_rcv_co2    =       'none'              ,    'no'    ,     ''      ,         ''          ,   ''
+/
+/
+!-----------------------------------------------------------------------
+&namberg       !   iceberg parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namlbc        !   lateral momentum boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namcla        !   cross land advection
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambfr        !   bottom friction
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbc        !   bottom temperature boundary condition
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nambbl        !   bottom boundary layer scheme
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nameos        !   ocean physical parameters
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv    !   advection scheme for tracer
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_adv_mle !  mixed layer eddy parametrisation (Fox-Kemper param)
+!-----------------------------------------------------------------------
+/
+!----------------------------------------------------------------------------------
+&namtra_ldf    !   lateral diffusion scheme for tracers
+!----------------------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namtra_dmp    !   tracer: T & S newtonian damping
+!-----------------------------------------------------------------------
+   ln_tradmp   =  .false.  !  add a damping termn (T) or not (F)
+/
+!-----------------------------------------------------------------------
+&namdyn_adv    !   formulation of the momentum advection
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_vor    !   option of physics/algorithm (not control by CPP keys)
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_hpg    !   Hydrostatic pressure gradient option
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_ldf    !   lateral diffusion on momentum
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf        !   vertical physics
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tke    !   turbulent eddy kinetic dependent vertical diffusion  ("key_zdftke")
+!-----------------------------------------------------------------------
+   rn_ebb      =  67.83    !  coef. of the surface input of tke (=67.83 suggested when ln_mxl0=T)
+   rn_mxl0     =   0.01    !  surface  buoyancy lenght scale minimum value
+   nn_etau     =   0       !  penetration of tke below the mixed layer (ML) due to internal & intertial waves
+                           !        = 0 no penetration
+                           !        = 1 add a tke source below the ML
+                           !        = 2 add a tke source just at the base of the ML
+                           !        = 3 as = 1 applied on HF part of the stress    ("key_coupled")
+/
+!-----------------------------------------------------------------------
+&namzdf_ddm    !   double diffusive mixing parameterization             ("key_zdfddm")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namzdf_tmx    !   tidal mixing parameterization                        ("key_zdftmx")
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namsol        !   elliptic solver / island / free surface
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&nammpp        !   Massively Parallel Processing                        ("key_mpp_mpi)
+!-----------------------------------------------------------------------
+   cn_mpi_send =  'I'      !  mpi send/recieve type   ='S', 'B', or 'I' for standard send,
+                           !  buffer blocking send or immediate non-blocking sends, resp.
+   nn_buffer   =   0       !  size in bytes of exported buffer ('B' case), 0 no exportation
+   ln_nnogather=  .false.  !  activate code to avoid mpi_allgather use at the northfold
+   jpni        =   4       !  jpni   number of processors following i (set automatically if < 1)
+   jpnj        =  15       !  jpnj   number of processors following j (set automatically if < 1)
+   jpnij       =  60       !  jpnij  number of local domains (set automatically if < 1)
+/
+!-----------------------------------------------------------------------
+&namctl        !   Control prints & Benchmark
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namptr       !   Poleward Transport Diagnostic
+!-----------------------------------------------------------------------
+   ln_diaptr  = .true.     !  Poleward heat and salt transport (T) or not (F)
+   ln_subbas  = .true.     !  Atlantic/Pacific/Indian basins computation (T) or not
+                           !  (orca configuration only, need input basins mask file named "subbasins.nc"
+/
+!-----------------------------------------------------------------------
+&nam_asminc   !   assimilation increments                               ('key_asminc')
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namhsb       !  Heat and salt budgets
+!-----------------------------------------------------------------------
+/
+!-----------------------------------------------------------------------
+&namdyn_nept  !   Neptune effect (simplified: lateral and vertical diffusions removed)
+!-----------------------------------------------------------------------
+/
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_pisces_ORCA2_cfg_paleo
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_pisces_ORCA2_cfg_paleo	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/GENERAL/PARAM/namelist_pisces_ORCA2_cfg_paleo	(revision 5879)
@@ -0,0 +1,66 @@
+!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!! PISCES  :   Configuration namelist : used to overwrite defaults values defined in SHARED/namelist_pis_ref
+!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisext     !   air-sea exchange
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+   ln_co2int  =  .false.        ! AUTO - read atm pco2 from a file (T) or constant (F)
+   atcco2     = 0.36886500E+03  ! AUTO - atmospheric pCO2
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisatm     !  Atmospheric pressure 
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisbio     !   biological parameters
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampislim     !   parameters for nutrient limitations
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisopt     !   parameters for optics
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/ 
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisprod     !   parameters for phytoplankton growth
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampismort     !   parameters for phytoplankton sinks
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampismes     !   parameters for mesozooplankton
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampiszoo     !   parameters for microzooplankton
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisfer     !   parameters for iron chemistry
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/  
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisrem     !   parameters for remineralization
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampiscal     !   parameters for Calcite chemistry
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampissbc     !   parameters for inputs deposition
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampisdmp     !  Damping 
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+   nn_pisdmp   =  _AUTO_: DEFAULT=8760       !  Frequency of Relaxation
+/
+!'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
+&nampismass     !  Mass conservation
+!,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
+/
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/fonte_neige_mod.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/fonte_neige_mod.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/fonte_neige_mod.F90	(revision 5879)
@@ -0,0 +1,373 @@
+!
+! $Header$
+!
+MODULE fonte_neige_mod
+!
+! This module will treat the process of snow, melting, accumulating, calving, in 
+! case of simplified soil model.
+!
+!****************************************************************************************
+  USE dimphy, ONLY : klon
+  USE indice_sol_mod
+
+  IMPLICIT NONE
+  SAVE
+
+! run_off_ter and run_off_lic are the runoff at the compressed grid knon for 
+! land and land-ice respectively
+! Note: run_off_lic is used in mod_landice and therfore not private
+  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE    :: run_off_ter
+  !$OMP THREADPRIVATE(run_off_ter)
+  REAL, ALLOCATABLE, DIMENSION(:)             :: run_off_lic
+  !$OMP THREADPRIVATE(run_off_lic)
+
+! run_off_lic_0 is the runoff at land-ice a time-step earlier, on the global 1D array grid
+  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE    :: run_off_lic_0
+  !$OMP THREADPRIVATE(run_off_lic_0)
+  
+  REAL, PRIVATE                               :: tau_calv  
+  !$OMP THREADPRIVATE(tau_calv)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: ffonte_global
+  !$OMP THREADPRIVATE(ffonte_global)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: fqfonte_global
+  !$OMP THREADPRIVATE(fqfonte_global)
+  REAL, ALLOCATABLE, DIMENSION(:,:), PRIVATE  :: fqcalving_global
+  !$OMP THREADPRIVATE(fqcalving_global)
+  REAL, ALLOCATABLE, DIMENSION(:), PRIVATE  :: runofflic_global
+  !$OMP THREADPRIVATE(runofflic_global)
+
+CONTAINS
+!
+!****************************************************************************************
+!
+  SUBROUTINE fonte_neige_init(restart_runoff)
+
+! This subroutine allocates and initialize variables in the module. 
+! The variable run_off_lic_0 is initialized to the field read from
+! restart file. The other variables are initialized to zero.
+!
+!****************************************************************************************
+! Input argument
+    REAL, DIMENSION(klon), INTENT(IN) :: restart_runoff 
+
+! Local variables
+    INTEGER                           :: error
+    CHARACTER (len = 80)              :: abort_message 
+    CHARACTER (len = 20)              :: modname = 'fonte_neige_init'
+
+
+!****************************************************************************************
+! Allocate run-off at landice and initilize with field read from restart
+!
+!****************************************************************************************
+
+    ALLOCATE(run_off_lic_0(klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation run_off_lic'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    run_off_lic_0(:) = restart_runoff(:) 
+
+!****************************************************************************************
+! Allocate other variables and initilize to zero
+!
+!****************************************************************************************
+    ALLOCATE(run_off_ter(klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation run_off_ter'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    run_off_ter(:) = 0.
+    
+    ALLOCATE(run_off_lic(klon), stat = error)
+    IF (error /= 0) THEN
+       abort_message='Pb allocation run_off_lic'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    run_off_lic(:) = 0.
+    
+    ALLOCATE(ffonte_global(klon,nbsrf))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation ffonte_global'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    ffonte_global(:,:) = 0.0
+
+    ALLOCATE(fqfonte_global(klon,nbsrf))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation fqfonte_global'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    fqfonte_global(:,:) = 0.0
+
+    ALLOCATE(fqcalving_global(klon,nbsrf))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation fqcalving_global'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    fqcalving_global(:,:) = 0.0
+
+    ALLOCATE(runofflic_global(klon))
+    IF (error /= 0) THEN
+       abort_message='Pb allocation runofflic_global'
+       CALL abort_physic(modname,abort_message,1)
+    ENDIF
+    runofflic_global(:) = 0.0
+
+!****************************************************************************************
+! Read tau_calv
+!
+!****************************************************************************************
+    CALL conf_interface(tau_calv)
+
+
+  END SUBROUTINE fonte_neige_init
+!
+!****************************************************************************************
+!
+  SUBROUTINE fonte_neige( knon, nisurf, knindex, dtime, &
+       tsurf, precip_rain, precip_snow, &
+       snow, qsol, tsurf_new, evap)
+
+  USE indice_sol_mod
+        
+! Routine de traitement de la fonte de la neige dans le cas du traitement
+! de sol simplifie!
+! LF 03/2001
+! input:
+!   knon         nombre de points a traiter
+!   nisurf       surface a traiter
+!   knindex      index des mailles valables pour surface a traiter
+!   dtime        
+!   tsurf        temperature de surface
+!   precip_rain  precipitations liquides
+!   precip_snow  precipitations solides
+!
+! input/output:
+!   snow         champs hauteur de neige
+!   qsol         hauteur d'eau contenu dans le sol
+!   tsurf_new    temperature au sol
+!   evap
+!
+  INCLUDE "YOETHF.h"
+  INCLUDE "YOMCST.h"
+  INCLUDE "FCTTRE.h"
+  INCLUDE "clesphys.h"
+
+! Input variables
+!****************************************************************************************
+    INTEGER, INTENT(IN)                  :: knon
+    INTEGER, INTENT(IN)                  :: nisurf
+    INTEGER, DIMENSION(klon), INTENT(IN) :: knindex
+    REAL   , INTENT(IN)                  :: dtime
+    REAL, DIMENSION(klon), INTENT(IN)    :: tsurf
+    REAL, DIMENSION(klon), INTENT(IN)    :: precip_rain
+    REAL, DIMENSION(klon), INTENT(IN)    :: precip_snow
+    
+! Input/Output variables
+!****************************************************************************************
+
+    REAL, DIMENSION(klon), INTENT(INOUT) :: snow
+    REAL, DIMENSION(klon), INTENT(INOUT) :: qsol
+    REAL, DIMENSION(klon), INTENT(INOUT) :: tsurf_new
+    REAL, DIMENSION(klon), INTENT(INOUT) :: evap
+
+! Local variables
+!****************************************************************************************
+
+    INTEGER               :: i, j
+    REAL                  :: fq_fonte
+    REAL                  :: coeff_rel
+    REAL, PARAMETER       :: snow_max=3000.
+    REAL, PARAMETER       :: max_eau_sol = 150.0
+!! PB temporaire en attendant mieux pour le modele de neige
+! REAL, parameter :: chasno = RLMLT/(2.3867E+06*0.15)
+    REAL, PARAMETER       :: chasno = 3.334E+05/(2.3867E+06*0.15)
+!IM cf JLD/ GKtest
+    REAL, PARAMETER       :: chaice = 3.334E+05/(2.3867E+06*0.15)
+! fin GKtest
+    REAL, DIMENSION(klon) :: ffonte
+    REAL, DIMENSION(klon) :: fqcalving, fqfonte
+    REAL, DIMENSION(klon) :: d_ts
+    REAL, DIMENSION(klon) :: bil_eau_s, snow_evap
+
+    LOGICAL               :: neige_fond
+
+!****************************************************************************************
+! Start calculation
+! - Initialization
+!
+!****************************************************************************************
+    coeff_rel = dtime/(tau_calv * rday)
+    
+    bil_eau_s(:) = 0.
+
+!****************************************************************************************
+! - Increment snow due to precipitation and evaporation
+! - Calculate the water balance due to precipitation and evaporation (bil_eau_s)
+!
+!****************************************************************************************
+    WHERE (precip_snow > 0.) 
+       snow = snow + (precip_snow * dtime)
+    END WHERE
+
+    snow_evap = 0.
+    WHERE (evap > 0. ) 
+       snow_evap = MIN (snow / dtime, evap) 
+       snow = snow - snow_evap * dtime
+       snow = MAX(0.0, snow)
+    END WHERE
+    
+    bil_eau_s(:) = (precip_rain(:) * dtime) - (evap(:) - snow_evap(:)) * dtime
+
+
+!****************************************************************************************
+! - Calculate melting snow
+! - Calculate calving and decrement snow, if there are to much snow
+! - Update temperature at surface
+!
+!****************************************************************************************
+
+    ffonte(:) = 0.0
+    fqcalving(:) = 0.0
+    fqfonte(:) = 0.0
+    DO i = 1, knon
+       ! Y'a-t-il fonte de neige?
+       neige_fond = ((snow(i) > epsfra .OR. nisurf == is_sic .OR. nisurf == is_lic) &
+            .AND. tsurf_new(i) >= RTT)
+       IF (neige_fond) THEN
+          fq_fonte     = MIN( MAX((tsurf_new(i)-RTT )/chasno,0.0),snow(i))
+          ffonte(i)    = fq_fonte * RLMLT/dtime
+          fqfonte(i)   = fq_fonte/dtime
+          snow(i)      = MAX(0., snow(i) - fq_fonte)
+          bil_eau_s(i) = bil_eau_s(i) + fq_fonte 
+          tsurf_new(i) = tsurf_new(i) - fq_fonte * chasno  
+
+!IM cf JLD OK     
+!IM cf JLD/ GKtest fonte aussi pour la glace
+! Modif for simulations with no land ice. Because we have a landice point
+! on the South Pole (otherwise ORCHIDEE crashes), we alter some of the
+! properties to simulate a bare soil point even though it is land ice.
+! (ie comment line below) -- JBL 08.02.2017
+          !IF (nisurf == is_sic .OR. nisurf == is_lic ) THEN
+          IF (nisurf == is_sic ) THEN
+             fq_fonte = MAX((tsurf_new(i)-RTT )/chaice,0.0)
+             ffonte(i) = ffonte(i) + fq_fonte * RLMLT/dtime
+             IF ( ok_lic_melt ) THEN
+                fqfonte(i) = fqfonte(i) + fq_fonte/dtime
+                bil_eau_s(i) = bil_eau_s(i) + fq_fonte
+             ENDIF
+             tsurf_new(i) = RTT
+          ENDIF
+          d_ts(i) = tsurf_new(i) - tsurf(i)
+       ENDIF
+
+       ! s'il y a une hauteur trop importante de neige, elle s'coule
+       fqcalving(i) = MAX(0., snow(i) - snow_max)/dtime
+       snow(i)=MIN(snow(i),snow_max)
+    END DO
+
+
+    IF (nisurf == is_ter) THEN
+       DO i = 1, knon
+          qsol(i) = qsol(i) + bil_eau_s(i)
+          run_off_ter(i) = run_off_ter(i) + MAX(qsol(i) - max_eau_sol, 0.0)
+          qsol(i) = MIN(qsol(i), max_eau_sol) 
+       END DO
+    ELSE IF (nisurf == is_lic) THEN
+       DO i = 1, knon
+          j = knindex(i)
+          run_off_lic(i)   = (coeff_rel *  fqcalving(i)) + &
+               (1. - coeff_rel) * run_off_lic_0(j)
+          run_off_lic_0(j) = run_off_lic(i)
+          run_off_lic(i)   = run_off_lic(i) + fqfonte(i) + precip_rain(i)
+       END DO
+    ENDIF
+    
+!****************************************************************************************
+! Save ffonte, fqfonte and fqcalving in global arrays for each 
+! sub-surface separately
+!
+!****************************************************************************************
+    DO i = 1, knon
+       ffonte_global(knindex(i),nisurf)    = ffonte(i)
+       fqfonte_global(knindex(i),nisurf)   = fqfonte(i)
+       fqcalving_global(knindex(i),nisurf) = fqcalving(i)
+    ENDDO
+
+    IF (nisurf == is_lic) THEN
+    DO i = 1, knon
+       runofflic_global(knindex(i)) = run_off_lic(i)
+    ENDDO
+    ENDIF
+
+  END SUBROUTINE fonte_neige
+!
+!****************************************************************************************
+!
+  SUBROUTINE fonte_neige_final(restart_runoff)
+!
+! This subroutine returns run_off_lic_0 for later writing to restart file.
+!
+!****************************************************************************************
+    REAL, DIMENSION(klon), INTENT(OUT) :: restart_runoff
+
+!****************************************************************************************
+! Set the output variables
+    restart_runoff(:) = run_off_lic_0(:)
+
+! Deallocation of all varaibles in the module
+!   DEALLOCATE(run_off_lic_0, run_off_ter, run_off_lic, ffonte_global, &
+!        fqfonte_global, fqcalving_global)
+
+    IF (ALLOCATED(run_off_lic_0)) DEALLOCATE(run_off_lic_0)
+    IF (ALLOCATED(run_off_ter)) DEALLOCATE(run_off_ter)
+    IF (ALLOCATED(run_off_lic)) DEALLOCATE(run_off_lic)
+    IF (ALLOCATED(ffonte_global)) DEALLOCATE(ffonte_global)
+    IF (ALLOCATED(fqfonte_global)) DEALLOCATE(fqfonte_global)
+    IF (ALLOCATED(fqcalving_global)) DEALLOCATE(fqcalving_global)
+    IF (ALLOCATED(runofflic_global)) DEALLOCATE(runofflic_global)
+
+  END SUBROUTINE fonte_neige_final
+!
+!****************************************************************************************
+!
+  SUBROUTINE fonte_neige_get_vars(pctsrf, fqcalving_out, &
+       fqfonte_out, ffonte_out, run_off_lic_out)
+
+
+! Cumulate ffonte, fqfonte and fqcalving respectively for
+! all type of surfaces according to their fraction.
+!
+! This routine is called from physiq.F before histwrite.
+!****************************************************************************************
+
+  USE indice_sol_mod
+
+    REAL, DIMENSION(klon,nbsrf), INTENT(IN) :: pctsrf
+
+    REAL, DIMENSION(klon), INTENT(OUT)      :: fqcalving_out
+    REAL, DIMENSION(klon), INTENT(OUT)      :: fqfonte_out
+    REAL, DIMENSION(klon), INTENT(OUT)      :: ffonte_out
+    REAL, DIMENSION(klon), INTENT(OUT)      :: run_off_lic_out
+
+    INTEGER   :: nisurf
+!****************************************************************************************
+
+    ffonte_out(:)    = 0.0
+    fqfonte_out(:)   = 0.0
+    fqcalving_out(:) = 0.0
+
+    DO nisurf = 1, nbsrf
+       ffonte_out(:) = ffonte_out(:) + ffonte_global(:,nisurf)*pctsrf(:,nisurf)
+       fqfonte_out(:) = fqfonte_out(:) + fqfonte_global(:,nisurf)*pctsrf(:,nisurf)
+       fqcalving_out(:) = fqcalving_out(:) + fqcalving_global(:,nisurf)*pctsrf(:,nisurf)
+    ENDDO
+
+    run_off_lic_out(:)=runofflic_global(:)
+
+  END SUBROUTINE fonte_neige_get_vars
+!
+!****************************************************************************************
+!
+END MODULE fonte_neige_mod
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/hydrol.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/hydrol.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/hydrol.F90	(revision 5879)
@@ -0,0 +1,123 @@
+
+! $Header$
+
+
+
+SUBROUTINE hydrol(dtime, pctsrf, rain_fall, snow_fall, evap, agesno, tsol, &
+    qsol, snow, runoff)
+  USE dimphy
+  USE indice_sol_mod
+
+  IMPLICIT NONE
+  ! ======================================================================
+  ! Auteur(s): Z.X. Li (LMD/CNRS)
+  ! date: 19940414
+  ! ======================================================================
+
+  ! Traitement de l'hydrologie du sol
+  ! ---------------------------------
+  ! rain_fall: taux de pluie
+  ! snow_fall: taux de neige
+  ! agesno: age de la neige
+  ! evap: taux d'evaporation
+  ! tsol: temperature du sol
+  ! qsol: humidite du sol
+  ! snow: couverture neigeuse
+
+  include "YOMCST.h"
+
+  REAL chasno ! epaisseur du sol: 0.15 m
+  PARAMETER (chasno=3.334E+05/(2.3867E+06*0.15))
+  REAL mx_eau_sol
+  PARAMETER (mx_eau_sol=150.0)
+
+  REAL dtime
+  REAL pctsrf(klon, nbsrf)
+  REAL snow(klon, nbsrf), tsol(klon, nbsrf), qsol(klon, nbsrf)
+  REAL snow_fall(klon), rain_fall(klon), evap(klon)
+  REAL runoff(klon), agesno(klon)
+
+  INTEGER i, is
+  REAL subli, fsno
+  ! -----------------------------------------------------------------------
+  DO i = 1, klon
+
+    runoff(i) = 0.0
+
+    is = is_ter
+    snow(i, is) = snow(i, is) + snow_fall(i)*dtime*pctsrf(i, is)
+    IF (pctsrf(i,is)>epsfra) THEN
+      subli = min(evap(i)*dtime, snow(i,is))
+      snow(i, is) = snow(i, is) - subli
+      fsno = min(max((tsol(i,is)-rtt)/chasno,0.0), snow(i,is))
+      snow(i, is) = snow(i, is) - fsno
+      tsol(i, is) = tsol(i, is) - fsno*chasno
+      qsol(i, is) = qsol(i, is) + (rain_fall(i)-evap(i))*dtime + subli + fsno
+      qsol(i, is) = max(qsol(i,is), 0.0)
+      runoff(i) = runoff(i) + max(qsol(i,is)-mx_eau_sol, 0.0)*pctsrf(i, is)
+      qsol(i, is) = min(qsol(i,is), mx_eau_sol)
+      ! cc         ELSE
+      ! cc            snow(i,is) = 0.0
+      ! cc            qsol(i,is) = 0.0
+      ! cc            tsol(i,is) = 0.0
+    END IF
+
+    is = is_lic
+    snow(i, is) = snow(i, is) + snow_fall(i)*dtime*pctsrf(i, is)
+    IF (pctsrf(i,is)>epsfra) THEN
+      subli = min(evap(i)*dtime, snow(i,is))
+      snow(i, is) = snow(i, is) - subli
+      fsno = min(max((tsol(i,is)-rtt)/chasno,0.0), snow(i,is))
+      snow(i, is) = snow(i, is) - fsno
+      tsol(i, is) = tsol(i, is) - fsno*chasno
+      qsol(i, is) = qsol(i, is) + (rain_fall(i)-evap(i))*dtime + subli + fsno
+      qsol(i, is) = max(qsol(i,is), 0.0)
+      runoff(i) = runoff(i) + max(qsol(i,is)-mx_eau_sol, 0.0)*pctsrf(i, is)
+      qsol(i, is) = min(qsol(i,is), mx_eau_sol)
+      ! je limite la temperature a RTT-1.8 (il faudrait aussi prendre l'eau
+      ! de
+      ! la fonte) (Laurent Li, le 14mars98):
+      ! IM cf GK   tsol(i,is) = MIN(tsol(i,is),RTT-1.8)
+      ! IM cf GK : la glace fond a 0C, non pas a -1.8
+      ! 
+      ! Modif for simulations with no land ice. Because we have a landice point
+      ! on the South Pole (otherwise ORCHIDEE crashes), we alter some of the
+      ! properties to simulate a bare soil point even though it is land ice.
+      ! (ie comment line below) -- JBL 08.02.2017
+      ! tsol(i, is) = min(tsol(i,is), rtt)
+
+      ! cc         ELSE
+      ! cc            snow(i,is) = 0.0
+      ! cc            qsol(i,is) = 0.0
+      ! cc            tsol(i,is) = 0.0
+    END IF
+
+    is = is_sic
+    qsol(i, is) = 0.0
+    snow(i, is) = snow(i, is) + snow_fall(i)*dtime*pctsrf(i, is)
+    IF (pctsrf(i,is)>epsfra) THEN
+      subli = min(evap(i)*dtime, snow(i,is))
+      snow(i, is) = snow(i, is) - subli
+      fsno = min(max((tsol(i,is)-rtt)/chasno,0.0), snow(i,is))
+      snow(i, is) = snow(i, is) - fsno
+      tsol(i, is) = tsol(i, is) - fsno*chasno
+      ! je limite la temperature a RTT-1.8 (il faudrait aussi prendre l'eau
+      ! de
+      ! la fonte) (Laurent Li, le 14mars98):
+      ! IM cf GK   tsol(i,is) = MIN(tsol(i,is),RTT-1.8)
+      ! IM cf GK : la glace fond a 0C, non pas a -1.8
+      tsol(i, is) = min(tsol(i,is), rtt)
+
+      ! cc         ELSE
+      ! cc            snow(i,is) = 0.0
+      ! cc            tsol(i,is) = 0.0
+    END IF
+
+    agesno(i) = (agesno(i)+(1.-agesno(i)/50.)*dtime/86400.)* &
+      exp(-1.*max(0.0,snow_fall(i))*dtime/0.3)
+    agesno(i) = max(agesno(i), 0.0)
+
+  END DO
+
+  RETURN
+END SUBROUTINE hydrol
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/surf_landice_mod.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/surf_landice_mod.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/LMDZ/PALEO/surf_landice_mod.F90	(revision 5879)
@@ -0,0 +1,366 @@
+!
+MODULE surf_landice_mod
+  
+  IMPLICIT NONE
+
+CONTAINS
+!
+!****************************************************************************************
+!
+  SUBROUTINE surf_landice(itime, dtime, knon, knindex, &
+       rlon, rlat, debut, lafin, &
+       rmu0, lwdownm, albedo, pphi1, &
+       swnet, lwnet, tsurf, p1lay, &
+       cdragh, cdragm, precip_rain, precip_snow, temp_air, spechum, &
+       AcoefH, AcoefQ, BcoefH, BcoefQ, &
+       AcoefU, AcoefV, BcoefU, BcoefV, &
+       ps, u1, v1, gustiness, rugoro, pctsrf, &
+       snow, qsurf, qsol, agesno, &
+       tsoil, z0m, z0h, SFRWL, alb_dir, alb_dif, evap, fluxsens, fluxlat, &
+       tsurf_new, dflux_s, dflux_l, &
+       slope, cloudf, &
+       snowhgt, qsnow, to_ice, sissnow, &
+       alb3, runoff, &
+       flux_u1, flux_v1)
+
+    USE dimphy
+    USE surface_data,     ONLY : type_ocean, calice, calsno, ok_snow
+    USE fonte_neige_mod,  ONLY : fonte_neige, run_off_lic
+    USE cpl_mod,          ONLY : cpl_send_landice_fields
+    USE calcul_fluxs_mod
+    USE phys_output_var_mod
+#ifdef CPP_SISVAT
+    USE surf_sisvat_mod,  ONLY : surf_sisvat
+#endif
+    USE indice_sol_mod
+
+!    INCLUDE "indicesol.h"
+    INCLUDE "dimsoil.h"
+    INCLUDE "YOMCST.h"
+    INCLUDE "clesphys.h"
+
+! Input variables 
+!****************************************************************************************
+    INTEGER, INTENT(IN)                           :: itime, knon
+    INTEGER, DIMENSION(klon), INTENT(in)          :: knindex
+    REAL, INTENT(in)                              :: dtime
+    REAL, DIMENSION(klon), INTENT(IN)             :: swnet ! net shortwave radiance
+    REAL, DIMENSION(klon), INTENT(IN)             :: lwnet ! net longwave radiance
+    REAL, DIMENSION(klon), INTENT(IN)             :: tsurf
+    REAL, DIMENSION(klon), INTENT(IN)             :: p1lay
+    REAL, DIMENSION(klon), INTENT(IN)             :: cdragh, cdragm
+    REAL, DIMENSION(klon), INTENT(IN)             :: precip_rain, precip_snow
+    REAL, DIMENSION(klon), INTENT(IN)             :: temp_air, spechum
+    REAL, DIMENSION(klon), INTENT(IN)             :: AcoefH, AcoefQ
+    REAL, DIMENSION(klon), INTENT(IN)             :: BcoefH, BcoefQ
+    REAL, DIMENSION(klon), INTENT(IN)             :: AcoefU, AcoefV, BcoefU, BcoefV
+    REAL, DIMENSION(klon), INTENT(IN)             :: ps
+    REAL, DIMENSION(klon), INTENT(IN)             :: u1, v1, gustiness
+    REAL, DIMENSION(klon), INTENT(IN)             :: rugoro
+    REAL, DIMENSION(klon,nbsrf), INTENT(IN)       :: pctsrf
+
+    LOGICAL,  INTENT(IN)                          :: debut   !true if first step
+    LOGICAL,  INTENT(IN)                          :: lafin   !true if last step
+    REAL, DIMENSION(klon), INTENT(IN)             :: rlon, rlat
+    REAL, DIMENSION(klon), INTENT(IN)             :: rmu0
+    REAL, DIMENSION(klon), INTENT(IN)             :: lwdownm !ylwdown
+    REAL, DIMENSION(klon), INTENT(IN)             :: albedo  !mean albedo
+    REAL, DIMENSION(klon), INTENT(IN)             :: pphi1    
+    REAL, DIMENSION(klon), INTENT(IN)             :: slope   !mean slope in grid box  
+    REAL, DIMENSION(klon), INTENT(IN)             :: cloudf  !total cloud fraction
+
+! In/Output variables
+!****************************************************************************************
+    REAL, DIMENSION(klon), INTENT(INOUT)          :: snow, qsol
+    REAL, DIMENSION(klon), INTENT(INOUT)          :: agesno
+    REAL, DIMENSION(klon, nsoilmx), INTENT(INOUT) :: tsoil
+
+! Output variables
+!****************************************************************************************
+    REAL, DIMENSION(klon), INTENT(OUT)            :: qsurf
+    REAL, DIMENSION(klon), INTENT(OUT)            :: z0m, z0h
+!albedo SB >>>
+!    REAL, DIMENSION(klon), INTENT(OUT)            :: alb1  ! new albedo in visible SW interval
+!    REAL, DIMENSION(klon), INTENT(OUT)            :: alb2  ! new albedo in near IR interval
+    REAL, DIMENSION(6), INTENT(IN)              ::SFRWL
+    REAL, DIMENSION(klon,nsw), INTENT(OUT)        ::alb_dir,alb_dif
+!albedo SB <<<
+    REAL, DIMENSION(klon), INTENT(OUT)            :: evap, fluxsens, fluxlat
+    REAL, DIMENSION(klon), INTENT(OUT)            :: tsurf_new
+    REAL, DIMENSION(klon), INTENT(OUT)            :: dflux_s, dflux_l      
+    REAL, DIMENSION(klon), INTENT(OUT)            :: flux_u1, flux_v1
+
+    REAL, DIMENSION(klon), INTENT(OUT)           :: alb3
+    REAL, DIMENSION(klon), INTENT(OUT)           :: qsnow   !column water in snow [kg/m2]
+    REAL, DIMENSION(klon), INTENT(OUT)           :: snowhgt !Snow height (m)
+    REAL, DIMENSION(klon), INTENT(OUT)           :: to_ice
+    REAL, DIMENSION(klon), INTENT(OUT)           :: sissnow
+    REAL, DIMENSION(klon), INTENT(OUT)           :: runoff  !Land ice runoff
+ 
+
+! Local variables
+!****************************************************************************************
+    REAL, DIMENSION(klon)    :: soilcap, soilflux
+    REAL, DIMENSION(klon)    :: cal, beta, dif_grnd
+    REAL, DIMENSION(klon)    :: zfra, alb_neig
+    REAL, DIMENSION(klon)    :: radsol
+    REAL, DIMENSION(klon)    :: u0, v0, u1_lay, v1_lay
+    INTEGER                  :: i,j
+
+    REAL, DIMENSION(klon)    :: emis_new                  !Emissivity
+    REAL, DIMENSION(klon)    :: swdown,lwdown
+    REAL, DIMENSION(klon)    :: precip_snow_adv, snow_adv !Snow Drift precip./advection
+    REAL, DIMENSION(klon)    :: bl_height, wind_velo      !height boundary layer, wind spd
+    REAL, DIMENSION(klon)    :: dens_air,  snow_cont_air  !air density; snow content air
+    REAL, DIMENSION(klon)    :: alb_soil                  !albedo of underlying ice
+    REAL, DIMENSION(klon)    :: pexner                    !Exner potential
+    REAL                     :: pref
+    REAL, DIMENSION(klon,nsoilmx) :: tsoil0 !modfi
+
+    CHARACTER (len = 20)                      :: modname = 'surf_landice'
+    CHARACTER (len = 80)                      :: abort_message
+
+!albedo SB >>>
+    real,dimension(klon) :: alb1,alb2
+!albedo SB <<<
+
+! End definition
+!****************************************************************************************
+!
+! Initialize output variables
+    alb3(:) = 999999.
+    alb2(:) = 999999.
+    alb1(:) = 999999.
+    
+    runoff(:) = 0.
+!****************************************************************************************
+! Calculate total absorbed radiance at surface
+!
+!****************************************************************************************
+    radsol(:) = 0.0
+    radsol(1:knon) = swnet(1:knon) + lwnet(1:knon)
+
+!****************************************************************************************
+!   ok_snow = TRUE  : prepare and call SISVAT snow model
+!   ok_snow = FALSE : soil_model, calcul_flux, fonte_neige, ... 
+!
+!****************************************************************************************
+    IF (ok_snow) THEN
+#ifdef CPP_SISVAT
+       ! Prepare for calling SISVAT
+       
+       ! Calculate incoming flux for SW and LW interval: swdown, lwdown
+       swdown(:)        = 0.0
+       lwdown(:)        = 0.0
+       DO i = 1, knon
+          swdown(i)        = swnet(i)/(1-albedo(i))
+          lwdown(i)        = lwdownm(i)
+       END DO
+       
+       ! Set constants and compute some input for SISVAT
+       snow_adv(:)      = 0.                          ! no snow blown in for now
+       snow_cont_air(:) = 0.       
+       alb_soil(:)      = albedo(:)
+       pref             = 100000.                     ! = 1000 hPa
+       DO i = 1, knon
+          wind_velo(i)     = u1(i)**2 + v1(i)**2
+          wind_velo(i)     = wind_velo(i)**0.5
+          pexner(i)        = (p1lay(i)/pref)**(RD/RCPD)
+          dens_air(i)      = p1lay(i)/RD/temp_air(i)  ! dry air density
+          bl_height(i)     = pphi1(i)/RG              
+       END DO
+
+!****************************************************************************************
+! CALL to SISVAT interface
+!
+!****************************************************************************************
+       ! config: compute everything with SV but temperatures afterwards with soil/calculfluxs
+       DO i = 1, knon
+          tsoil0(i,:)=tsoil(i,:)
+       END DO
+           ! Martin
+           PRINT*, 'on appelle surf_sisvat'
+           ! Martin
+       CALL surf_sisvat(knon, rlon, rlat, knindex, itime, dtime, debut, lafin, &
+            rmu0, swdown, lwdown, pexner, ps, p1lay, &
+            precip_rain, precip_snow, precip_snow_adv, snow_adv, &
+            bl_height, wind_velo, temp_air, dens_air, spechum, tsurf, &
+            rugoro, snow_cont_air, alb_soil, slope, cloudf, &
+            radsol, qsol, tsoil0, snow, snowhgt, qsnow, to_ice,sissnow, agesno, &
+            AcoefH, AcoefQ, BcoefH, BcoefQ, cdragh, &
+            run_off_lic, evap, fluxsens, fluxlat, dflux_s, dflux_l, &        
+            tsurf_new, alb1, alb2, alb3, &
+            emis_new, z0m, qsurf)
+       z0h(1:knon)=z0m(1:knon) ! en attendant mieux
+       
+       ! Suppose zero surface speed
+       u0(:)            = 0.0
+       v0(:)            = 0.0
+       ! The calculation of heat/water fluxes, otherwise done by "CALL calcul_fluxs" is 
+       ! integrated in SISVAT, using the same method. It can be found in "sisvat.f", in the
+       ! subroutine "SISVAT_TS2". 
+       ! u0, v0=0., dif_grnd=0. and beta=1 are assumed there! 
+       
+       CALL calcul_flux_wind(knon, dtime, &
+            u0, v0, u1, v1, gustiness, cdragm, &
+            AcoefU, AcoefV, BcoefU, BcoefV, &
+            p1lay, temp_air, &
+            flux_u1, flux_v1)
+#else
+       abort_message='Pb de coherence: ok_snow = .true. mais CPP_SISVAT = .false.'
+       CALL abort_physic(modname,abort_message,1)
+#endif
+    ELSE ! ok_snow=FALSE
+
+!****************************************************************************************
+! Soil calculations
+! 
+!****************************************************************************************
+    IF (soil_model) THEN 
+       CALL soil(dtime, is_lic, knon, snow, tsurf, tsoil, soilcap, soilflux)
+       cal(1:knon) = RCPD / soilcap(1:knon)
+       radsol(1:knon)  = radsol(1:knon) + soilflux(1:knon)
+    ELSE 
+       cal = RCPD * calice
+       WHERE (snow > 0.0) cal = RCPD * calsno
+    ENDIF
+
+
+!****************************************************************************************
+! Calulate fluxes
+!
+!****************************************************************************************
+    beta(:) = 1.0
+    dif_grnd(:) = 0.0
+
+! Suppose zero surface speed
+    u0(:)=0.0
+    v0(:)=0.0
+    u1_lay(:) = u1(:) - u0(:)
+    v1_lay(:) = v1(:) - v0(:)
+
+    CALL calcul_fluxs(knon, is_lic, dtime, &
+         tsurf, p1lay, cal, beta, cdragh, cdragh, ps, &
+         precip_rain, precip_snow, snow, qsurf,  &
+         radsol, dif_grnd, temp_air, spechum, u1_lay, v1_lay, gustiness, &
+         1.,AcoefH, AcoefQ, BcoefH, BcoefQ, &
+         tsurf_new, evap, fluxlat, fluxsens, dflux_s, dflux_l)
+
+    CALL calcul_flux_wind(knon, dtime, &
+         u0, v0, u1, v1, gustiness, cdragm, &
+         AcoefU, AcoefV, BcoefU, BcoefV, &
+         p1lay, temp_air, &
+         flux_u1, flux_v1)
+
+!****************************************************************************************
+! Calculate snow height, age, run-off,..
+!    
+!****************************************************************************************
+    CALL fonte_neige( knon, is_lic, knindex, dtime, &
+         tsurf, precip_rain, precip_snow, &
+         snow, qsol, tsurf_new, evap)
+
+
+!****************************************************************************************
+! Calculate albedo
+!
+!****************************************************************************************
+    CALL albsno(klon,knon,dtime,agesno(:),alb_neig(:), precip_snow(:))  
+    WHERE (snow(1 : knon) .LT. 0.0001) agesno(1 : knon) = 0.
+    zfra(1:knon) = MAX(0.0,MIN(1.0,snow(1:knon)/(snow(1:knon)+10.0)))
+    alb1(1:knon) = alb_neig(1:knon)*zfra(1:knon) + &
+         0.6 * (1.0-zfra(1:knon))
+!
+!IM: plusieurs choix/tests sur l'albedo des "glaciers continentaux"
+!       alb1(1 : knon)  = 0.6 !IM cf FH/GK 
+!       alb1(1 : knon)  = 0.82
+!       alb1(1 : knon)  = 0.77 !211003 Ksta0.77
+!       alb1(1 : knon)  = 0.8 !KstaTER0.8 & LMD_ARMIP5
+!IM: KstaTER0.77 & LMD_ARMIP6    
+
+! Attention: alb1 and alb2 are the same!
+! Modif for simulations with no land ice. Because we have a landice point
+! on the South Pole (otherwise ORCHIDEE crashes), we alter some of the
+! properties to simulate a bare soil point even though it is land ice.
+! (ie comment line below) -- JBL 08.02.2017
+!    alb1(1:knon)  = 0.77
+    alb1(1:knon)  = 0.15
+!    alb2(1:knon)  = alb1(1:knon)
+    alb2(1:knon)  = 0.33
+
+
+!****************************************************************************************
+! Rugosity
+!
+!****************************************************************************************
+    z0m=1.e-3
+    z0h = z0m
+    z0m = SQRT(z0m**2+rugoro**2)
+
+    END IF ! ok_snow
+
+
+!****************************************************************************************
+! Send run-off on land-ice to coupler if coupled ocean.
+! run_off_lic has been calculated in fonte_neige or surf_sisvat
+!
+!****************************************************************************************
+    IF (type_ocean=='couple') THEN
+       CALL cpl_send_landice_fields(itime, knon, knindex, run_off_lic)
+    ENDIF
+
+ ! transfer runoff rate [kg/m2/s](!) to physiq for output
+    runoff(1:knon)=run_off_lic(1:knon)/dtime
+
+  
+!****************************************************************************************
+       snow_o=0.
+       zfra_o = 0.
+       DO j = 1, knon
+           i = knindex(j)
+           snow_o(i) = snow(j) 
+           zfra_o(i) = zfra(j)
+       ENDDO
+
+!****************************************************************************************
+       snow_o=0.
+       zfra_o = 0.
+       DO j = 1, knon
+           i = knindex(j)
+           snow_o(i) = snow(j)
+           zfra_o(i) = zfra(j)
+       ENDDO
+
+
+!albedo SB >>>
+     select case(NSW)
+     case(2)
+       alb_dir(1:knon,1)=alb1(1:knon)
+       alb_dir(1:knon,2)=alb2(1:knon)
+     case(4)
+       alb_dir(1:knon,1)=alb1(1:knon)
+       alb_dir(1:knon,2)=alb2(1:knon)
+       alb_dir(1:knon,3)=alb2(1:knon)
+       alb_dir(1:knon,4)=alb2(1:knon)
+     case(6)
+       alb_dir(1:knon,1)=alb1(1:knon)
+       alb_dir(1:knon,2)=alb1(1:knon)
+       alb_dir(1:knon,3)=alb1(1:knon)
+       alb_dir(1:knon,4)=alb2(1:knon)
+       alb_dir(1:knon,5)=alb2(1:knon)
+       alb_dir(1:knon,6)=alb2(1:knon)
+     end select
+alb_dif=alb_dir
+!albedo SB <<<
+
+
+
+
+  END SUBROUTINE surf_landice
+!
+!****************************************************************************************
+!
+END MODULE surf_landice_mod
+
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/closea.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/closea.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/closea.F90	(revision 5879)
@@ -0,0 +1,531 @@
+MODULE closea
+   !!======================================================================
+   !!                       ***  MODULE  closea  ***
+   !! Closed Seas  : specific treatments associated with closed seas
+   !!======================================================================
+   !! History :   8.2  !  00-05  (O. Marti)  Original code
+   !!             8.5  !  02-06  (E. Durand, G. Madec)  F90
+   !!             9.0  !  06-07  (G. Madec)  add clo_rnf, clo_ups, clo_bat
+   !!        NEMO 3.4  !  03-12  (P.G. Fogli) sbc_clo bug fix & mpp reproducibility
+   !!
+   !! 2016 : new closed seas for use in IPSLCM6 coupled model (O. Marti)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_clo    : modification of the ocean domain for closed seas cases
+   !!   sbc_clo    : Special handling of closed seas
+   !!   clo_rnf    : set close sea outflows as river mouths (see sbcrnf)
+   !!   clo_ups    : set mixed centered/upstream scheme in closed sea (see traadv_cen2)
+   !!   clo_bat    : set to zero a field over closed sea (see domzrg)
+   !!----------------------------------------------------------------------
+   USE oce             ! dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   !USE iom             ! I/O manager library
+   USE sbc_oce         ! ocean surface boundary conditions
+   USE lib_fortran,    ONLY: glob_sum, DDPDD
+   USE lbclnk          ! lateral boundary condition - MPP exchanges
+   USE lib_mpp         ! MPP library
+   USE timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dom_clo      ! routine called by domain module
+   PUBLIC sbc_clo      ! routine called by step module
+   PUBLIC clo_rnf      ! routine called by sbcrnf module
+   PUBLIC clo_ups      ! routine called in traadv_cen2(_jki) module
+   PUBLIC clo_bat      ! routine called in domzgr module
+
+   INTEGER, PUBLIC, PARAMETER          ::   jpncs   = 7      !: number of closed sea
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncstt            !: Type of closed sea
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi1, ncsj1     !: south-west closed sea limits (i,j)
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi2, ncsj2     !: north-east closed sea limits (i,j)
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsnr            !: number of point where run-off pours
+   INTEGER, PUBLIC, DIMENSION(jpncs,4) ::   ncsir, ncsjr     !: Location of runoff
+
+   REAL(wp), DIMENSION (:,:), ALLOCATABLE :: clo_mask        !: Defines area where excess run-off is distributed
+
+   REAL(wp), DIMENSION (jpncs+1)       ::   surf             !: Closed sea surface
+
+   INTEGER :: dia_closea_alloc
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: closea.F90 4162 2013-11-07 10:19:49Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dom_clo
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_clo  ***
+      !!        
+      !! ** Purpose :   Closed sea domain initialization
+      !!
+      !! ** Method  :   if a closed sea is located only in a model grid point
+      !!                just the thermodynamic processes are applied.
+      !!
+      !! ** Action  :   ncsi1(), ncsj1() : south-west closed sea limits (i,j)
+      !!                ncsi2(), ncsj2() : north-east Closed sea limits (i,j)
+      !!                ncsir(), ncsjr() : Location of runoff
+      !!                ncsnr            : number of point where run-off pours
+      !!                ncstt            : Type of closed sea
+      !!                                   =0 spread over the world ocean
+      !!                                   =2 put at location runoff
+      !!----------------------------------------------------------------------
+      INTEGER ::   jc               ! dummy loop indices
+      REAL(wp)::   ztmp
+      INTEGER ::   isrow
+      !!----------------------------------------------------------------------
+      
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)'dom_clo : closed seas '
+      IF(lwp) WRITE(numout,*)'~~~~~~~'
+
+      ! Initial values
+      ncsnr(:) = 1  ;  ncsi1(:) = 1  ;  ncsi2(:) = 1  ;  ncsir(:,:) = 1
+      ncstt(:) = 0  ;  ncsj1(:) = 1  ;  ncsj2(:) = 1  ;  ncsjr(:,:) = 1
+
+      ! set the closed seas (in data domain indices)
+      ! -------------------
+
+      IF( cp_cfg == "orca" ) THEN
+         !
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 1 )                                  ! ORCA_R1 configuration
+            !
+            !! This dirty section will be suppressed by simplification process: all this will come back in input files.
+            !! Currently these hard-wired indices relate to NEMO v3.6 and later. In this version, the grid has been extended southwards
+            !! for use with the under ice-shelf options (isf). The grid resolution is 362x332.
+            !! The pre v3.6 (362x292) domain can still be used optionally if the isf code is not activated. An adjustment (isrow)
+            !! is made to the hard-wired indices if the reduced domain is used.
+            
+            !! =======================
+            IF         ( jpjglo == 332 ) THEN  !  eORCA1 R1 - Using full isfÂ­extended domain.
+               isrow =  0
+            ELSEIF     ( jpjglo == 292 ) THEN  !  ORCA1 R1 Â­ Using pre-v3.6 files or adjusted start row from isf-extended grid
+               isrow = 40                      !    - Adjust jÂ­indices to account for less southerly starting latitude
+            ENDIF
+            
+            ncsnr(1)   = 1    ; ncstt(1)   = 0              ! Caspian Sea
+            ncsi1(1)   = 333  ; ncsj1(1)   = 243 - isrow      ! spread over the globe
+            ncsi2(1)   = 342  ; ncsj2(1)   = 274 - isrow
+            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
+            !
+            ncsnr(2)   = 4    ; ncstt(2)   = 2              ! Lake Superior
+            ncsi1(2)   = 198  ; ncsj1(2)   = 258 - isrow      ! put at St Laurent mouth
+            ncsi2(2)   = 204  ; ncsj2(2)   = 262 - isrow
+            ncsir(2,1) = 225  ; ncsjr(2,1) = 220 - isrow
+            ncsir(2,2) = 225  ; ncsjr(2,2) = 221 - isrow
+            ncsir(2,3) = 226  ; ncsjr(2,3) = 220 - isrow
+            ncsir(2,4) = 226  ; ncsjr(2,4) = 221 - isrow
+            !
+            ncsnr(3)   = 4    ; ncstt(3)   = 2              ! Lake Michigan
+            ncsi1(3)   = 201  ; ncsj1(3)   = 250 - isrow      ! put at St Laurent mouth
+            ncsi2(3)   = 203  ; ncsj2(3)   = 256 - isrow
+            ncsir(3,1) = 225  ; ncsjr(3,1) = 220 - isrow
+            ncsir(3,2) = 225  ; ncsjr(3,2) = 221 - isrow
+            ncsir(3,3) = 226  ; ncsjr(3,3) = 220 - isrow
+            ncsir(3,4) = 226  ; ncsjr(3,4) = 221 - isrow
+            !
+            ncsnr(4)   = 4    ; ncstt(4)   = 2             ! Lake Huron
+            ncsi1(4)   = 204  ; ncsj1(4)   = 252 - isrow      ! put at St Laurent mouth
+            ncsi2(4)   = 209  ; ncsj2(4)   = 256 - isrow
+            ncsir(4,1) = 225  ; ncsjr(4,1) = 220 - isrow
+            ncsir(4,2) = 225  ; ncsjr(4,2) = 221 - isrow
+            ncsir(4,3) = 226  ; ncsjr(4,3) = 220 - isrow
+            ncsir(4,4) = 226  ; ncsjr(4,4) = 221 - isrow
+            !
+            ncsnr(5)   = 4    ; ncstt(5)   = 2              ! Lake Erie
+            ncsi1(5)   = 206  ; ncsj1(5)   = 249 - isrow      ! put at St Laurent mouth
+            ncsi2(5)   = 209  ; ncsj2(5)   = 251 - isrow
+            ncsir(5,1) = 225  ; ncsjr(5,1) = 220 - isrow
+            ncsir(5,2) = 225  ; ncsjr(5,2) = 221 - isrow
+            ncsir(5,3) = 226  ; ncsjr(5,3) = 220 - isrow
+            ncsir(5,4) = 226  ; ncsjr(5,4) = 221 - isrow
+            !
+            ncsnr(6)   = 4    ; ncstt(6)   = 2              ! Lake Ontario
+            ncsi1(6)   = 210  ; ncsj1(6)   = 252 - isrow      ! put at St Laurent mouth
+            ncsi2(6)   = 212  ; ncsj2(6)   = 252 - isrow
+            ncsir(6,1) = 225  ; ncsjr(6,1) = 220 - isrow
+            ncsir(6,2) = 225  ; ncsjr(6,2) = 221 - isrow
+            ncsir(6,3) = 226  ; ncsjr(6,3) = 220 - isrow
+            ncsir(6,4) = 226  ; ncsjr(6,4) = 221 - isrow
+            !
+            ncsnr(7)   = 1    ; ncstt(7)   = 0             ! Victoria Lake
+            ncsi1(7)   = 321  ; ncsj1(7)   = 180 - isrow     ! spread over the globe
+            ncsi2(7)   = 322  ; ncsj2(7)   = 189 - isrow
+            ncsir(7,1) = 1    ; ncsjr(7,1) = 1
+            
+            !                                        
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            !                                            ! Caspian Sea
+            ncsnr(1)   =   1  ;  ncstt(1)   =   0           ! spread over the globe
+            ncsi1(1)   =  11  ;  ncsj1(1)   = 103
+            ncsi2(1)   =  17  ;  ncsj2(1)   = 112
+            ncsir(1,1) =   1  ;  ncsjr(1,1) =   1 
+            !                                            ! Great North American Lakes
+            ncsnr(2)   =   1  ;  ncstt(2)   =   2           ! put at St Laurent mouth
+            ncsi1(2)   =  97  ;  ncsj1(2)   = 107
+            ncsi2(2)   = 103  ;  ncsj2(2)   = 111
+            ncsir(2,1) = 110  ;  ncsjr(2,1) = 111           
+            !                                            ! Black Sea (crossed by the cyclic boundary condition)
+            ncsnr(3:4) =   4  ;  ncstt(3:4) =   2           ! put in Med Sea (north of Aegean Sea)
+            ncsir(3:4,1) = 171;  ncsjr(3:4,1) = 106         !
+            ncsir(3:4,2) = 170;  ncsjr(3:4,2) = 106 
+            ncsir(3:4,3) = 171;  ncsjr(3:4,3) = 105 
+            ncsir(3:4,4) = 170;  ncsjr(3:4,4) = 105 
+            ncsi1(3)   = 174  ;  ncsj1(3)   = 107           ! 1 : west part of the Black Sea      
+            ncsi2(3)   = 181  ;  ncsj2(3)   = 112           !            (ie west of the cyclic b.c.)
+            ncsi1(4)   =   2  ;  ncsj1(4)   = 107           ! 2 : east part of the Black Sea 
+            ncsi2(4)   =   6  ;  ncsj2(4)   = 112           !           (ie east of the cyclic b.c.)
+             
+          
+
+            !                                        ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            !                                            ! Caspian Sea
+            ncsnr(1)   =  1  ;  ncstt(1)   =  0  
+            ncsi1(1)   =  4  ;  ncsj1(1)   = 53 
+            ncsi2(1)   =  4  ;  ncsj2(1)   = 56
+            ncsir(1,1) =  1  ;  ncsjr(1,1) =  1
+            !                                            ! Great North American Lakes
+            ncsnr(2)   =  1  ;  ncstt(2)   =  2 
+            ncsi1(2)   = 49  ;  ncsj1(2)   = 55
+            ncsi2(2)   = 51  ;  ncsj2(2)   = 56
+            ncsir(2,1) = 57  ;  ncsjr(2,1) = 55
+            !                                            ! Black Sea
+            ncsnr(3)   =  4  ;  ncstt(3)   =  2  
+            ncsi1(3)   = 88  ;  ncsj1(3)   = 55 
+            ncsi2(3)   = 91  ;  ncsj2(3)   = 56
+            ncsir(3,1) = 86  ;  ncsjr(3,1) = 53
+            ncsir(3,2) = 87  ;  ncsjr(3,2) = 53 
+            ncsir(3,3) = 86  ;  ncsjr(3,3) = 52 
+            ncsir(3,4) = 87  ;  ncsjr(3,4) = 52
+            !                                            ! Baltic Sea
+            ncsnr(4)   =  1  ;  ncstt(4)   =  2
+            ncsi1(4)   = 75  ;  ncsj1(4)   = 59
+            ncsi2(4)   = 76  ;  ncsj2(4)   = 61
+            ncsir(4,1) = 84  ;  ncsjr(4,1) = 59 
+            !                                        ! =======================
+         CASE ( 025 )                                ! ORCA_R025 configuration
+            !                                        ! =======================
+            ncsnr(1)   = 1    ; ncstt(1)   = 0               ! Caspian + Aral sea
+            ncsi1(1)   = 1330 ; ncsj1(1)   = 645
+            ncsi2(1)   = 1400 ; ncsj2(1)   = 795
+            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
+            !                                        
+            ncsnr(2)   = 1    ; ncstt(2)   = 0               ! Azov Sea 
+            ncsi1(2)   = 1284 ; ncsj1(2)   = 722
+            ncsi2(2)   = 1304 ; ncsj2(2)   = 747
+            ncsir(2,1) = 1    ; ncsjr(2,1) = 1
+            !
+         END SELECT
+         !
+      ENDIF
+
+      ! convert the position in local domain indices
+      ! --------------------------------------------
+      DO jc = 1, jpncs
+         ncsi1(jc)   = mi0( ncsi1(jc) )
+         ncsj1(jc)   = mj0( ncsj1(jc) )
+
+         ncsi2(jc)   = mi1( ncsi2(jc) )   
+         ncsj2(jc)   = mj1( ncsj2(jc) )  
+      END DO
+
+      !
+   END SUBROUTINE dom_clo
+
+
+   SUBROUTINE sbc_clo( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_clo  ***
+      !!                    
+      !! ** Purpose :   Special handling of closed seas
+      !!
+      !! ** Method  :   Water flux is forced to zero over closed sea
+      !!      Excess is shared between remaining ocean, or
+      !!      put as run-off in open ocean.
+      !!
+      !! ** Action  :   emp updated surface freshwater fluxes and associated heat content at kt
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean model time step
+      !
+      INTEGER             ::   ji, jj, jc, jn   ! dummy loop indices
+      REAL(wp), PARAMETER ::   rsmall = 1.e-20_wp    ! Closed sea correction epsilon
+      REAL(wp)            ::   zze2, ztmp, zcorr     ! 
+      REAL(wp)            ::   zcoef, zcoef1         ! 
+      COMPLEX(wp)         ::   ctmp 
+      REAL(wp), DIMENSION(jpncs) ::   zfwf   ! 1D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('sbc_clo')
+      !                                                   !------------------!
+      IF( kt == nit000 ) THEN                             !  Initialisation  !
+         !                                                !------------------!
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'sbc_clo : closed seas '
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+         !
+         ! Mask
+         ! --------------------------------------------
+         ALLOCATE ( clo_mask (jpi, jpj), STAT=dia_closea_alloc)
+         IF(dia_closea_alloc /= 0)   CALL ctl_warn('dia_closea_alloc: failed to allocate arrays.')
+         
+         clo_mask (:,:) = tmask (:,:,1)
+         
+         ! Latitude limits
+         WHERE ( gphit (:,:) .GT.  30.0_wp ) clo_mask (:,:) = 0.0_wp
+         WHERE ( gphit (:,:) .LT. -30.0_wp ) clo_mask (:,:) = 0.0_wp
+         !
+         ! Remove closed seas from mask
+         DO jc = 1, jpncs
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  clo_mask (ji, jj) = 0.0_wp
+               END DO
+            END DO
+         END DO
+         
+         IF( lk_mpp ) CALL lbc_lnk ( clo_mask, 'T', 1._wp)
+      
+         !
+         surf(:) = 0.e0_wp
+         !
+         surf(jpncs+1) = glob_sum( e1e2t(:,:) * clo_mask (:,:) )   ! surface of the ocean where excess run-off goes
+         !
+         !                                        ! surface of closed seas 
+         IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+            DO jc = 1, jpncs
+               ctmp = CMPLX( 0.e0, 0.e0, wp )
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     ztmp = e1e2t(ji,jj) * tmask_i(ji,jj)
+                     CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+                  END DO 
+               END DO 
+               IF( lk_mpp )   CALL mpp_sum( ctmp )
+               surf(jc) = REAL(ctmp,wp)
+            END DO
+         ELSE                                          ! Standard calculation           
+            DO jc = 1, jpncs
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     surf(jc) = surf(jc) + e1e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+                  END DO 
+               END DO 
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum ( surf, jpncs )       ! mpp: sum over all the global domain
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
+         DO jc = 1, jpncs
+            IF(lwp)WRITE(numout,FMT='(1I3,4I4,5X,F16.2)') jc, ncsi1(jc), ncsi2(jc), ncsj1(jc), ncsj2(jc), surf(jc)
+         END DO
+
+         IF(lwp) WRITE(numout,*)'     Surface for redistribution in closea ', surf(jpncs+1)
+         
+         !
+      ENDIF
+      !
+      !                                                   !--------------------!
+      !                                                   !  update emp        !
+      zfwf = 0.e0_wp                                      !--------------------!
+      IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+         DO jc = 1, jpncs
+            ctmp = CMPLX( 0.e0, 0.e0, wp )
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  ztmp = e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj)
+                  CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+               END DO  
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum( ctmp )
+            zfwf(jc) = REAL(ctmp,wp)
+         END DO
+      ELSE                                          ! Standard calculation           
+         DO jc = 1, jpncs
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zfwf(jc) = zfwf(jc) + e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj) 
+               END DO  
+            END DO 
+         END DO
+         IF( lk_mpp )   CALL mpp_sum ( zfwf(:) , jpncs )       ! mpp: sum over all the global domain
+      ENDIF
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
+         zze2    = ( zfwf(3) + zfwf(4) ) * 0.5_wp
+         zfwf(3) = zze2
+         zfwf(4) = zze2
+      ENDIF
+
+      zcorr = 0._wp
+
+      DO jc = 1, jpncs
+         !
+         ! The following if avoids the redistribution of the round off
+         IF ( ABS(zfwf(jc) / surf(jpncs+1) ) > rsmall) THEN
+            !
+            IF( ncstt(jc) == 0 ) THEN           ! water/evap excess is shared by all open ocean
+               zcoef    = zfwf(jc) / surf(jpncs+1)
+               zcoef1   = rcp * zcoef
+               emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:) 
+               qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
+               !
+            ELSEIF( ncstt(jc) == 1 ) THEN       ! Excess water in open sea, at outflow location, excess evap shared
+               IF ( zfwf(jc) <= 0.e0_wp ) THEN 
+                   DO jn = 1, ncsnr(jc)
+                     ji = mi0(ncsir(jc,jn))
+                     jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                     IF (      ji > 1 .AND. ji < jpi   &
+                         .AND. jj > 1 .AND. jj < jpj ) THEN 
+                         zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) * e1e2t(ji,jj) )
+                         zcoef1     = rcp * zcoef
+                         emp(ji,jj) = emp(ji,jj) + zcoef 
+                         qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                     ENDIF 
+                   END DO 
+               ELSE 
+                   zcoef    = zfwf(jc) / surf(jpncs+1)
+                   zcoef1   = rcp * zcoef
+                   emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:)
+                   qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
+               ENDIF
+            ELSEIF( ncstt(jc) == 2 ) THEN       ! Excess e-p-r (either sign) goes to open ocean, at outflow location
+               DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  IF(      ji > 1 .AND. ji < jpi    &
+                     .AND. jj > 1 .AND. jj < jpj ) THEN 
+                     zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) *  e1e2t(ji,jj) )
+                     zcoef1     = rcp * zcoef
+                     emp(ji,jj) = emp(ji,jj) + zcoef
+                     qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                  ENDIF 
+               END DO 
+            ENDIF 
+            !
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zcoef      = zfwf(jc) / surf(jc)
+                  zcoef1     = rcp * zcoef
+                  emp(ji,jj) = emp(ji,jj) - zcoef
+                  qns(ji,jj) = qns(ji,jj) + zcoef1 * sst_m(ji,jj)
+               END DO  
+            END DO 
+            !
+         END IF
+      END DO 
+
+      emp (:,:) = emp (:,:) * tmask(:,:,1)
+      qns (:,:) = qns (:,:) * tmask(:,:,1)
+      !
+      CALL lbc_lnk( emp , 'T', 1._wp )
+      CALL lbc_lnk( qns , 'T', 1._wp )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('sbc_clo')
+      !
+   END SUBROUTINE sbc_clo
+
+
+   SUBROUTINE clo_rnf( p_rnfmsk )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_rnf  ***
+      !!                    
+      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
+      !!                to be the same as river mouth grid-points
+      !!
+      !! ** Method  :   set to 1 the runoff mask (mskrnf, see sbcrnf module)
+      !!                at the closed sea outflow grid-point.
+      !!
+      !! ** Action  :   update (p_)mskrnf (set 1 at closed sea outflow)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_rnfmsk   ! river runoff mask (rnfmsk array)
+      !
+      INTEGER  ::   jc, jn, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         IF( ncstt(jc) >= 1 ) THEN            ! runoff mask set to 1 at closed sea outflows
+             DO jn = 1, 4
+                DO jj =    mj0( ncsjr(jc,jn) ), mj1( ncsjr(jc,jn) )
+                   DO ji = mi0( ncsir(jc,jn) ), mi1( ncsir(jc,jn) )
+                      p_rnfmsk(ji,jj) = MAX( p_rnfmsk(ji,jj), 1.0_wp )
+                   END DO
+                END DO
+            END DO 
+         ENDIF 
+      END DO 
+      !
+   END SUBROUTINE clo_rnf
+
+   
+   SUBROUTINE clo_ups( p_upsmsk )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_rnf  ***
+      !!                    
+      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
+      !!                to be the same as river mouth grid-points
+      !!
+      !! ** Method  :   set to 0.5 the upstream mask (upsmsk, see traadv_cen2 
+      !!                module) over the closed seas.
+      !!
+      !! ** Action  :   update (p_)upsmsk (set 0.5 over closed seas)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_upsmsk   ! upstream mask (upsmsk array)
+      !
+      INTEGER  ::   jc, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               p_upsmsk(ji,jj) = 0.5_wp         ! mixed upstream/centered scheme over closed seas
+            END DO 
+         END DO 
+       END DO 
+       !
+   END SUBROUTINE clo_ups
+   
+      
+   SUBROUTINE clo_bat( pbat, kbat )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE clo_bat  ***
+      !!                    
+      !! ** Purpose :   suppress closed sea from the domain
+      !!
+      !! ** Method  :   set to 0 the meter and level bathymetry (given in 
+      !!                arguments) over the closed seas.
+      !!
+      !! ** Action  :   set pbat=0 and kbat=0 over closed seas
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pbat   ! bathymetry in meters (bathy array)
+      INTEGER , DIMENSION(jpi,jpj), INTENT(inout) ::   kbat   ! bathymetry in levels (mbathy array)
+      !
+      INTEGER  ::   jc, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               pbat(ji,jj) = 0._wp   
+               kbat(ji,jj) = 0   
+            END DO 
+         END DO 
+       END DO 
+       !
+   END SUBROUTINE clo_bat
+
+   !!======================================================================
+END MODULE closea
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diaar5.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diaar5.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diaar5.F90	(revision 5879)
@@ -0,0 +1,285 @@
+MODULE diaar5
+   !!======================================================================
+   !!                       ***  MODULE  diaar5  ***
+   !! AR5 diagnostics
+   !!======================================================================
+   !! History :  3.2  !  2009-11  (S. Masson)  Original code
+   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
+   !!----------------------------------------------------------------------
+#if defined key_diaar5   || defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_diaar5'  :                           activate ar5 diagnotics
+   !!----------------------------------------------------------------------
+   !!   dia_ar5       : AR5 diagnostics
+   !!   dia_ar5_init  : initialisation of AR5 diagnostics
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers 
+   USE dom_oce        ! ocean space and time domain
+   USE eosbn2         ! equation of state                (eos_bn2 routine)
+   USE lib_mpp        ! distribued memory computing library
+   USE iom            ! I/O manager library
+   USE timing         ! preformance summary
+   USE wrk_nemo       ! working arrays
+   USE fldread        ! type FLD_N
+   USE phycst         ! physical constant
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dia_ar5        ! routine called in step.F90 module
+   PUBLIC   dia_ar5_init   ! routine called in opa.F90 module
+   PUBLIC   dia_ar5_alloc  ! routine called in nemogcm.F90 module
+
+   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .TRUE.   ! coupled flag
+
+   REAL(wp)                         ::   vol0         ! ocean volume (interior domain)
+   REAL(wp)                         ::   area_tot     ! total ocean surface (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   area         ! cell surface (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   thick0       ! ocean thickness (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sn0          ! initial salinity
+      
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: diaar5.F90 6664 2016-06-03 13:42:46Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   FUNCTION dia_ar5_alloc()
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dia_ar5_alloc  ***
+      !!----------------------------------------------------------------------
+      INTEGER :: dia_ar5_alloc
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( area(jpi,jpj), thick0(jpi,jpj) , sn0(jpi,jpj,jpk) , STAT=dia_ar5_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( dia_ar5_alloc )
+      IF( dia_ar5_alloc /= 0 )   CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
+      !
+   END FUNCTION dia_ar5_alloc
+
+
+   SUBROUTINE dia_ar5( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dia_ar5  ***
+      !!
+      !! ** Purpose :   compute and output some AR5 diagnostics
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk                      ! dummy loop arguments
+      REAL(wp) ::   zvolssh, zvol, zssh_steric, zztmp, zarho, ztemp, zsal, zmass
+      !
+      REAL(wp), POINTER, DIMENSION(:,:)     :: zarea_ssh , zbotpres       ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zrhd , z3d, zrhop               ! 3D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztsn                       ! 4D workspace
+      !!--------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('dia_ar5')
+ 
+      CALL wrk_alloc( jpi , jpj              , zarea_ssh , zbotpres )
+      CALL wrk_alloc( jpi , jpj , jpk        , zrhd      , z3d, zrhop    )
+      CALL wrk_alloc( jpi , jpj , jpk , jpts , ztsn                 )
+
+      zarea_ssh(:,:) = area(:,:) * sshn(:,:)
+
+      !                                         ! total volume of liquid seawater
+      zvolssh = SUM( zarea_ssh(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zvolssh )
+      zvol = vol0 + zvolssh
+
+      z3d(:,:,jpk) = 0._wp        ! ocean volume
+      DO jk = 1, jpkm1
+         z3d (:,:,jk) = area(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
+      END DO
+
+      CALL iom_put( "bathy"     , bathy(:,:) )
+      CALL iom_put( "areacello" , area (:,:) )
+      CALL iom_put( "volcello"  , z3d(:,:,:)         )     ! WARNING not consistent with CMIP DR where volcello is at ca. 2000 
+      CALL iom_put( "masscello" , rau0 * fse3t(:,:,:) * tmask(:,:,:) )  ! ocean mass 
+
+
+      CALL iom_put( 'voltot', zvol               )
+      CALL iom_put( 'sshtot', zvolssh / area_tot )
+
+      !                     
+      ztsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)                    ! thermosteric ssh
+      ztsn(:,:,:,jp_sal) = sn0(:,:,:)
+      CALL eos( ztsn, zrhd, fsdept_n(:,:,:) )                       ! now in situ density using initial salinity
+      !
+      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
+      DO jk = 1, jpkm1
+         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
+               END DO
+            END DO
+         ELSE
+            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
+         END IF
+      END IF
+      !                                         
+      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zarho )
+      zssh_steric = - zarho / area_tot
+      CALL iom_put( 'sshthster', zssh_steric )
+      
+      !                                         ! steric sea surface height
+      CALL eos( tsn, zrhd, zrhop, fsdept_n(:,:,:) )                 ! now in situ and potential density
+      zrhop(:,:,jpk) = 0._wp
+      CALL iom_put( 'rhop', zrhop )
+      !
+      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
+      DO jk = 1, jpkm1
+         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
+               END DO
+            END DO
+         ELSE
+            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
+         END IF
+      END IF
+      !    
+      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zarho )
+      zssh_steric = - zarho / area_tot
+      CALL iom_put( 'sshsteric', zssh_steric )
+      
+      !                                         ! ocean bottom pressure
+      zztmp = rau0 * grav * 1.e-4_wp               ! recover pressure from pressure anomaly and cover to dbar = 1.e4 Pa
+      zbotpres(:,:) = zztmp * ( zbotpres(:,:) + sshn(:,:) + thick0(:,:) )
+      CALL iom_put( 'botpres', zbotpres )
+
+      !                                         ! Mean density anomalie, temperature and salinity
+      ztemp = 0._wp
+      zsal  = 0._wp
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zztmp = area(ji,jj) * fse3t(ji,jj,jk)
+               ztemp = ztemp + zztmp * tsn(ji,jj,jk,jp_tem)
+               zsal  = zsal  + zztmp * tsn(ji,jj,jk,jp_sal)
+            END DO
+         END DO
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  ztemp = ztemp + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_tem) 
+                  zsal  = zsal  + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_sal) 
+               END DO
+            END DO
+         ELSE
+            ztemp = ztemp + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_tem) )
+            zsal  = zsal  + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_sal) )
+         END IF
+      ENDIF
+      IF( lk_mpp ) THEN  
+         CALL mpp_sum( ztemp )
+         CALL mpp_sum( zsal  )
+      END IF
+      !
+      zmass = rau0 * ( zarho + zvol )                 ! total mass of liquid seawater
+      ztemp = ztemp / zvol                            ! potential temperature in liquid seawater
+      zsal  = zsal  / zvol                            ! Salinity of liquid seawater
+      !
+      CALL iom_put( 'masstot', zmass )
+      CALL iom_put( 'temptot', ztemp )
+      CALL iom_put( 'saltot' , zsal  )
+      ! 
+      CALL wrk_dealloc( jpi , jpj              , zarea_ssh , zbotpres    )
+      CALL wrk_dealloc( jpi , jpj , jpk        , zrhd      , z3d , zrhop )
+      CALL wrk_dealloc( jpi , jpj , jpk , jpts , ztsn                    )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5')
+      !
+   END SUBROUTINE dia_ar5
+
+
+   SUBROUTINE dia_ar5_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_ar5_init  ***
+      !!                   
+      !! ** Purpose :   initialization for AR5 diagnostic computation
+      !!----------------------------------------------------------------------
+      INTEGER  ::   inum
+      INTEGER  ::   ik
+      INTEGER  ::   ji, jj, jk  ! dummy loop indices
+      REAL(wp) ::   zztmp  
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zsaldta   ! Jan/Dec levitus salinity
+      !
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dia_ar5_init')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, 2, zsaldta )
+      !                                      ! allocate dia_ar5 arrays
+      IF( dia_ar5_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_ar5_init : unable to allocate arrays' )
+
+      area(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+
+      area_tot = SUM( area(:,:) )   ;   IF( lk_mpp )   CALL mpp_sum( area_tot )
+
+      vol0        = 0._wp
+      thick0(:,:) = 0._wp
+      DO jk = 1, jpkm1
+         vol0        = vol0        + SUM( area (:,:) * tmask(:,:,jk) * e3t_0(:,:,jk) )
+         thick0(:,:) = thick0(:,:) +    tmask_i(:,:) * tmask(:,:,jk) * e3t_0(:,:,jk)
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( vol0 )
+
+      CALL iom_open ( 'sali_ref_clim_monthly', inum )
+      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,1), 1  )
+      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,2), 12 )
+      CALL iom_close( inum )
+
+      sn0(:,:,:) = 0.5_wp * ( zsaldta(:,:,:,1) + zsaldta(:,:,:,2) )        
+      sn0(:,:,:) = sn0(:,:,:) * tmask(:,:,:)
+      IF( ln_zps ) THEN               ! z-coord. partial steps
+         DO jj = 1, jpj               ! interpolation of salinity at the last ocean level (i.e. the partial step)
+            DO ji = 1, jpi
+               ik = mbkt(ji,jj)
+               IF( ik > 1 ) THEN
+                  zztmp = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
+                  sn0(ji,jj,ik) = ( 1._wp - zztmp ) * sn0(ji,jj,ik) + zztmp * sn0(ji,jj,ik-1)
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, 2, zsaldta )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5_init')
+      !
+   END SUBROUTINE dia_ar5_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                         NO diaar5
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .FALSE.   ! coupled flag
+CONTAINS
+   SUBROUTINE dia_ar5_init    ! Dummy routine
+   END SUBROUTINE dia_ar5_init
+   SUBROUTINE dia_ar5( kt )   ! Empty routine
+      INTEGER ::   kt
+      WRITE(*,*) 'dia_ar5: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_ar5
+#endif
+
+   !!======================================================================
+END MODULE diaar5
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diafwb.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diafwb.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/diafwb.F90	(revision 5879)
@@ -0,0 +1,479 @@
+MODULE diafwb
+   !!======================================================================
+   !!                       ***  MODULE  diafwb  ***
+   !! Ocean diagnostics: freshwater budget
+   !!======================================================================
+   !! History :  8.2  !  01-02  (E. Durand)  Original code
+   !!            8.5  !  02-06  (G. Madec)  F90: Free form and module
+   !!            9.0  !  05-11  (V. Garnier) Surface pressure gradient organization
+   !!---------------------------------------------------------------------- 
+   !!----------------------------------------------------------------------
+   !!   Only for ORCA2 ORCA1 and ORCA025
+   !!----------------------------------------------------------------------
+   !!----------------------------------------------------------------------
+   !!   dia_fwb     : freshwater budget for global ocean configurations
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE sbc_oce         ! ???
+   USE zdf_oce         ! ocean vertical physics
+   USE in_out_manager  ! I/O manager
+   USE lib_mpp         ! distributed memory computing library
+   USE timing          ! preformance summary
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dia_fwb    ! routine called by step.F90
+
+   REAL(wp)               ::   a_fwf ,          &
+      &                        a_sshb, a_sshn, a_salb, a_saln
+   REAL(wp), DIMENSION(4) ::   a_flxi, a_flxo, a_temi, a_temo, a_sali, a_salo
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: diafwb.F90 5506 2015-06-29 15:19:38Z clevy $
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE dia_fwb( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_fwb  ***
+      !!     
+      !! ** Purpose :
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index
+      !!
+      INTEGER  :: inum             ! temporary logical unit
+      INTEGER  :: ji, jj, jk, jt   ! dummy loop indices
+      INTEGER  :: ii0, ii1, ij0, ij1
+      INTEGER  :: isrow         ! index for ORCA1 starting row
+      REAL(wp) :: zarea, zvol, zwei
+      REAL(wp) :: ztemi(4), ztemo(4), zsali(4), zsalo(4), zflxi(4), zflxo(4)
+      REAL(wp) :: zt, zs, zu  
+      REAL(wp) :: zsm0, zfwfnew
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. jp_cfg == 1 .OR. jp_cfg == 2 .OR. jp_cfg == 4 ) THEN
+      !!----------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('dia_fwb')
+
+      ! Mean global salinity
+      ! CORRECTED FOR PALEORCA2 -- JBL 08.02.2017
+      ! zsm0 = 34.72654
+      zsm0 = 34.7
+
+      ! To compute fwf mean value mean fwf
+
+      IF( kt == nit000 ) THEN
+
+         a_fwf    = 0.e0
+         a_sshb   = 0.e0 ! valeur de ssh au debut de la simulation
+         a_salb   = 0.e0 ! valeur de sal au debut de la simulation
+         ! sshb used because diafwb called after tranxt (i.e. after the swap)
+         a_sshb = SUM( e1t(:,:) * e2t(:,:) * sshb(:,:) * tmask_i(:,:) )
+         IF( lk_mpp )   CALL mpp_sum( a_sshb )      ! sum over the global domain
+
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwei  = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+                  a_salb = a_salb + ( tsb(ji,jj,jk,jp_sal) - zsm0 ) * zwei
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( a_salb )      ! sum over the global domain
+      ENDIF
+      
+      a_fwf    = SUM( e1t(:,:) * e2t(:,:) * ( emp(:,:)-rnf(:,:) ) * tmask_i(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( a_fwf    )       ! sum over the global domain
+
+      IF( kt == nitend ) THEN
+         a_sshn = 0.e0
+         a_saln = 0.e0
+         zarea = 0.e0
+         zvol  = 0.e0
+         zfwfnew = 0.e0
+         ! Mean sea level at nitend
+         a_sshn = SUM( e1t(:,:) * e2t(:,:) * sshn(:,:) * tmask_i(:,:) )
+         IF( lk_mpp )   CALL mpp_sum( a_sshn )      ! sum over the global domain
+         zarea  = SUM( e1t(:,:) * e2t(:,:) *             tmask_i(:,:) )
+         IF( lk_mpp )   CALL mpp_sum( zarea  )      ! sum over the global domain
+         
+         DO jk = 1, jpkm1   
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  zwei  = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+                  a_saln = a_saln + ( tsn(ji,jj,jk,jp_sal) - zsm0 ) * zwei
+                  zvol  = zvol  + zwei
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( a_saln )      ! sum over the global domain
+         IF( lk_mpp )   CALL mpp_sum( zvol )      ! sum over the global domain
+         
+         ! Conversion in m3
+         a_fwf    = a_fwf * rdttra(1) * 1.e-3 
+         
+         ! fwf correction to bring back the mean ssh to zero
+         zfwfnew = a_sshn / ( ( nitend - nit000 + 1 ) * rdt ) * 1.e3 / zarea
+
+      ENDIF
+
+
+      ! Calcul des termes de transport 
+      ! ------------------------------
+      
+      ! 1 --> Gibraltar 
+      ! 2 --> Cadiz 
+      ! 3 --> Red Sea
+      ! 4 --> Baltic Sea
+
+      IF( kt == nit000 ) THEN
+         a_flxi(:) = 0.e0
+         a_flxo(:) = 0.e0
+         a_temi(:) = 0.e0
+         a_temo(:) = 0.e0
+         a_sali(:) = 0.e0
+         a_salo(:) = 0.e0
+      ENDIF
+
+      zflxi(:) = 0.e0
+      zflxo(:) = 0.e0
+      ztemi(:) = 0.e0
+      ztemo(:) = 0.e0
+      zsali(:) = 0.e0
+      zsalo(:) = 0.e0
+
+      ! Mean flow at Gibraltar
+
+      IF( cp_cfg == "orca" ) THEN  
+               
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            ii0 = 70   ;   ii1 = 70
+            ij0 = 52   ;   ij1 = 52
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            ii0 = 140   ;   ii1 = 140
+            ij0 = 102   ;   ij1 = 102
+            !                                        ! =======================
+         CASE ( 1 )                                  !  ORCA_R1 configurations
+            !                                        ! =======================
+            ! This dirty section will be suppressed by simplification process:
+            ! all this will come back in input files
+            ! Currently these hard-wired indices relate to configuration with
+            ! extend grid (jpjglo=332)
+            isrow = 332 - jpjglo
+            !
+            ii0 = 283           ;   ii1 = 283
+            ij0 = 241 - isrow   ;   ij1 = 241 - isrow
+            !                                        ! =======================
+         CASE DEFAULT                                !    ORCA R05 or R025
+            !                                        ! =======================
+            CALL ctl_stop( ' dia_fwb Not yet implemented in ORCA_R05 or R025' )
+            ! 
+         END SELECT
+         ! 
+         DO ji = mi0(ii0), MIN(mi1(ii1),jpim1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, jpk 
+                  zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
+                  zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+
+                  IF( un(ji,jj,jk) > 0.e0 ) THEN 
+                     zflxi(1) = zflxi(1) +    zu
+                     ztemi(1) = ztemi(1) + zt*zu
+                     zsali(1) = zsali(1) + zs*zu
+                  ELSE
+                     zflxo(1) = zflxo(1) +    zu
+                     ztemo(1) = ztemo(1) + zt*zu
+                     zsalo(1) = zsalo(1) + zs*zu
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+      
+      ! Mean flow at Cadiz
+      IF( cp_cfg == "orca" ) THEN
+               
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            ii0 = 69   ;   ii1 = 69
+            ij0 = 52   ;   ij1 = 52
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            ii0 = 137   ;   ii1 = 137
+            ij0 = 101   ;   ij1 = 102
+            !                                        ! =======================
+         CASE ( 1 )                                  !  ORCA_R1 configurations
+            !                                        ! =======================
+            ! This dirty section will be suppressed by simplification process:
+            ! all this will come back in input files
+            ! Currently these hard-wired indices relate to configuration with
+            ! extend grid (jpjglo=332)
+            isrow = 332 - jpjglo
+            ii0 = 282           ;   ii1 = 282
+            ij0 = 240 - isrow   ;   ij1 = 240 - isrow
+            !                                        ! =======================
+         CASE DEFAULT                                !    ORCA R05 or R025
+            !                                        ! =======================
+            CALL ctl_stop( ' dia_fwb Not yet implemented in ORCA_R05 or R025' )
+            ! 
+         END SELECT
+         ! 
+         DO ji = mi0(ii0), MIN(mi1(ii1),jpim1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, jpk 
+                  zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
+                  zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  
+                  IF( un(ji,jj,jk) > 0.e0 ) THEN 
+                     zflxi(2) = zflxi(2) +    zu
+                     ztemi(2) = ztemi(2) + zt*zu
+                     zsali(2) = zsali(2) + zs*zu
+                  ELSE
+                     zflxo(2) = zflxo(2) +    zu
+                     ztemo(2) = ztemo(2) + zt*zu
+                     zsalo(2) = zsalo(2) + zs*zu
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! Mean flow at Red Sea entrance
+      IF( cp_cfg == "orca" ) THEN
+               
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            ii0 = 83   ;   ii1 = 83
+            ij0 = 45   ;   ij1 = 45
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            ii0 = 160   ;   ii1 = 160
+            ij0 = 88    ;   ij1 = 88 
+            !                                        ! =======================
+         CASE ( 1 )                                  !  ORCA_R1 configurations
+            !                                        ! =======================
+            ! This dirty section will be suppressed by simplification process:
+            ! all this will come back in input files
+            ! Currently these hard-wired indices relate to configuration with
+            ! extend grid (jpjglo=332)
+            isrow = 332 - jpjglo
+            ii0 = 331           ;   ii1 = 331
+            ij0 = 215 - isrow   ;   ij1 = 215 - isrow
+            !                                        ! =======================
+         CASE DEFAULT                                !    ORCA R05 or R025
+            !                                        ! =======================
+            CALL ctl_stop( ' dia_fwb Not yet implemented in ORCA_R05 or R025' )
+            ! 
+         END SELECT
+         ! 
+         DO ji = mi0(ii0), MIN(mi1(ii1),jpim1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, jpk 
+                  zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
+                  zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  
+                  IF( un(ji,jj,jk) > 0.e0 ) THEN 
+                     zflxi(3) = zflxi(3) +    zu
+                     ztemi(3) = ztemi(3) + zt*zu
+                     zsali(3) = zsali(3) + zs*zu
+                  ELSE
+                     zflxo(3) = zflxo(3) +    zu
+                     ztemo(3) = ztemo(3) + zt*zu
+                     zsalo(3) = zsalo(3) + zs*zu
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! Mean flow at Baltic Sea entrance
+      IF( cp_cfg == "orca" ) THEN
+               
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            ii0 = 1     ;   ii1 = 1  
+            ij0 = 1     ;   ij1 = 1  
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            ii0 = 146   ;   ii1 = 146 
+            ij0 = 116   ;   ij1 = 116
+            !                                        ! =======================
+         CASE ( 1 )                                  !  ORCA_R1 configurations
+            !                                        ! =======================
+            ! This dirty section will be suppressed by simplification process:
+            ! all this will come back in input files
+            ! Currently these hard-wired indices relate to configuration with
+            ! extend grid (jpjglo=332)
+            isrow = 332 - jpjglo
+            ii0 = 297           ;   ii1 = 297
+            ij0 = 269 - isrow   ;   ij1 = 269 - isrow
+            !                                        ! =======================
+         CASE DEFAULT                                !    ORCA R05 or R025
+            !                                        ! =======================
+            CALL ctl_stop( ' dia_fwb Not yet implemented in ORCA_R05 or R025' )
+            ! 
+         END SELECT
+         ! 
+         DO ji = mi0(ii0), MIN(mi1(ii1),jpim1)
+            DO jj = mj0(ij0), mj1(ij1)
+               DO jk = 1, jpk
+                  zt = 0.5 * ( tsn(ji,jj,jk,jp_tem) + tsn(ji+1,jj,jk,jp_tem) )
+                  zs = 0.5 * ( tsn(ji,jj,jk,jp_sal) + tsn(ji+1,jj,jk,jp_sal) )
+                  zu = un(ji,jj,jk) * fse3t(ji,jj,jk) * e2u(ji,jj) * tmask_i(ji,jj)
+                  
+                  IF( un(ji,jj,jk) > 0.e0 ) THEN 
+                     zflxi(4) = zflxi(4) +    zu
+                     ztemi(4) = ztemi(4) + zt*zu
+                     zsali(4) = zsali(4) + zs*zu
+                  ELSE
+                     zflxo(4) = zflxo(4) +    zu
+                     ztemo(4) = ztemo(4) + zt*zu
+                     zsalo(4) = zsalo(4) + zs*zu
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      ! Sum at each time-step
+      DO jt = 1, 4 
+         !
+         IF( zflxi(jt) /= 0.e0 ) THEN
+            a_flxi(jt) = a_flxi(jt) + zflxi(jt)
+            a_temi(jt) = a_temi(jt) + ztemi(jt)/zflxi(jt)
+            a_sali(jt) = a_sali(jt) + zsali(jt)/zflxi(jt)
+         ENDIF
+         !
+         IF( zflxo(jt) /= 0.e0 ) THEN
+            a_flxo(jt) = a_flxo(jt) + zflxo(jt)
+            a_temo(jt) = a_temo(jt) + ztemo(jt)/zflxo(jt)
+            a_salo(jt) = a_salo(jt) + zsalo(jt)/zflxo(jt)
+         ENDIF
+         !
+      END DO
+
+      IF( kt == nitend ) THEN
+         DO jt = 1, 4 
+            a_flxi(jt) = a_flxi(jt) / ( FLOAT( nitend - nit000 + 1 ) * 1.e6 )
+            a_temi(jt) = a_temi(jt) /   FLOAT( nitend - nit000 + 1 )
+            a_sali(jt) = a_sali(jt) /   FLOAT( nitend - nit000 + 1 )
+            a_flxo(jt) = a_flxo(jt) / ( FLOAT( nitend - nit000 + 1 ) * 1.e6 )
+            a_temo(jt) = a_temo(jt) /   FLOAT( nitend - nit000 + 1 )
+            a_salo(jt) = a_salo(jt) /   FLOAT( nitend - nit000 + 1 )
+         END DO
+         IF( lk_mpp ) THEN
+            CALL mpp_sum( a_flxi, 4 )      ! sum over the global domain
+            CALL mpp_sum( a_temi, 4 )      ! sum over the global domain
+            CALL mpp_sum( a_sali, 4 )      ! sum over the global domain
+
+            CALL mpp_sum( a_flxo, 4 )      ! sum over the global domain
+            CALL mpp_sum( a_temo, 4 )      ! sum over the global domain
+            CALL mpp_sum( a_salo, 4 )      ! sum over the global domain
+         ENDIF
+      ENDIF
+
+
+      ! Ecriture des diagnostiques 
+      ! --------------------------
+
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      !IF ( kt == nitend .AND. cp_cfg == "orca" .AND. lwp ) THEN
+      IF ( kt == nitend .AND. ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. lwp ) THEN
+
+         CALL ctl_opn( inum, 'STRAIT.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
+         WRITE(inum,*)
+         WRITE(inum,*)    'Net freshwater budget '
+         WRITE(inum,9010) '  fwf    = ',a_fwf,   ' m3 =', a_fwf   /(FLOAT(nitend-nit000+1)*rdttra(1)) * 1.e-6,' Sv'
+         WRITE(inum,*)
+         WRITE(inum,9010) '  zarea =',zarea
+         WRITE(inum,9010) '  zvol  =',zvol
+         WRITE(inum,*)
+         WRITE(inum,*)    'Mean sea level : '
+         WRITE(inum,9010) '  at nit000 = ',a_sshb        ,' m3 '
+         WRITE(inum,9010) '  at nitend = ',a_sshn        ,' m3 '
+         WRITE(inum,9010) '  diff      = ',(a_sshn-a_sshb),' m3 =', (a_sshn-a_sshb)/(FLOAT(nitend-nit000+1)*rdt) * 1.e-6,' Sv'
+         WRITE(inum,9020) '  mean sea level elevation    =', a_sshn/zarea,' m'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Anomaly of salinity content : '
+         WRITE(inum,9010) '  at nit000 = ',a_salb        ,' psu.m3 '
+         WRITE(inum,9010) '  at nitend = ',a_saln        ,' psu.m3 '
+         WRITE(inum,9010) '  diff      = ',(a_saln-a_salb),' psu.m3'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Mean salinity : '
+         WRITE(inum,9020) '  at nit000 =',a_salb/zvol+zsm0   ,' psu '
+         WRITE(inum,9020) '  at nitend =',a_saln/zvol+zsm0   ,' psu '
+         WRITE(inum,9020) '  diff      =',(a_saln-a_salb)/zvol,' psu'
+         WRITE(inum,9020) '  S-SLevitus=',a_saln/zvol,' psu'
+         WRITE(inum,*)
+         WRITE(inum,*)    'Gibraltar : '
+         WRITE(inum,9030) '  Flux entrant (Sv) :', a_flxi(1)
+         WRITE(inum,9030) '  Flux sortant (Sv) :', a_flxo(1)
+         WRITE(inum,9030) '  T entrant (deg)   :', a_temi(1)
+         WRITE(inum,9030) '  T sortant (deg)   :', a_temo(1)
+         WRITE(inum,9030) '  S entrant (psu)   :', a_sali(1)
+         WRITE(inum,9030) '  S sortant (psu)   :', a_salo(1)
+         WRITE(inum,*)
+         WRITE(inum,*)    'Cadiz : '
+         WRITE(inum,9030) '  Flux entrant (Sv) :', a_flxi(2)
+         WRITE(inum,9030) '  Flux sortant (Sv) :', a_flxo(2)
+         WRITE(inum,9030) '  T entrant (deg)   :', a_temi(2)
+         WRITE(inum,9030) '  T sortant (deg)   :', a_temo(2)
+         WRITE(inum,9030) '  S entrant (psu)   :', a_sali(2)
+         WRITE(inum,9030) '  S sortant (psu)   :', a_salo(2)
+         WRITE(inum,*)
+         WRITE(inum,*)    'Bab el Mandeb : '
+         WRITE(inum,9030) '  Flux entrant (Sv) :', a_flxi(3)
+         WRITE(inum,9030) '  Flux sortant (Sv) :', a_flxo(3)
+         WRITE(inum,9030) '  T entrant (deg)   :', a_temi(3)
+         WRITE(inum,9030) '  T sortant (deg)   :', a_temo(3)
+         WRITE(inum,9030) '  S entrant (psu)   :', a_sali(3)
+         WRITE(inum,9030) '  S sortant (psu)   :', a_salo(3)
+         WRITE(inum,*)
+         WRITE(inum,*)    'Baltic : '
+         WRITE(inum,9030) '  Flux entrant (Sv) :', a_flxi(4)
+         WRITE(inum,9030) '  Flux sortant (Sv) :', a_flxo(4)
+         WRITE(inum,9030) '  T entrant (deg)   :', a_temi(4)
+         WRITE(inum,9030) '  T sortant (deg)   :', a_temo(4)
+         WRITE(inum,9030) '  S entrant (psu)   :', a_sali(4)
+         WRITE(inum,9030) '  S sortant (psu)   :', a_salo(4)
+         CLOSE(inum)
+      ENDIF
+
+      IF( nn_timing == 1 )   CALL timing_start('dia_fwb')
+
+ 9005 FORMAT(1X,A,ES24.16)
+ 9010 FORMAT(1X,A,ES12.5,A,F10.5,A)
+ 9020 FORMAT(1X,A,F10.5,A)
+ 9030 FORMAT(1X,A,F9.4,A)
+  
+      ENDIF 
+
+   END SUBROUTINE dia_fwb
+
+   !!======================================================================
+END MODULE diafwb
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c2d.h90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c2d.h90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c2d.h90	(revision 5879)
@@ -0,0 +1,526 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldfdyn_c2d.h90  ***
+   !!----------------------------------------------------------------------
+   !!   ldf_dyn_c2d  : set the lateral viscosity coefficients
+   !!   ldf_dyn_c2d_orca : specific case for orca r2 and r4
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: ldfdyn_c2d.h90 5400 2015-06-10 15:29:08Z cbricaud $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_dyn_c2d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldf_dyn_c2d  ***
+      !!                  
+      !! ** Purpose :   initializations of the horizontal ocean physics
+      !!
+      !! ** Method :
+      !!      2D eddy viscosity coefficients ( longitude, latitude )
+      !!
+      !!       harmonic operator   : ahm1 is defined at t-point
+      !!                             ahm2 is defined at f-point
+      !!           + isopycnal     : ahm3 is defined at u-point
+      !!           or geopotential   ahm4 is defined at v-point
+      !!           iso-model level : ahm3, ahm4 not used
+      !!
+      !!       biharmonic operator : ahm3 is defined at u-point
+      !!                             ahm4 is defined at v-point
+      !!                           : ahm1, ahm2 not used
+      !!
+      !!----------------------------------------------------------------------
+      LOGICAL, INTENT (in) :: ld_print   ! If true, output arrays on numout
+      !
+      INTEGER  ::   ji, jj
+      REAL(wp) ::   za00, zd_max, zetmax, zeumax, zefmax, zevmax
+      !!----------------------------------------------------------------------
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ldf_dyn_c2d : 2d lateral eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+      ! harmonic operator (ahm1, ahm2) : ( T- and F- points) (used for laplacian operators
+      ! ===============================                       whatever its orientation is)
+      IF( ln_dynldf_lap ) THEN
+         ! define ahm1 and ahm2 at the right grid point position
+         ! (USER: modify ahm1 and ahm2 following your desiderata)
+
+         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              laplacian operator: ahm proportional to e1'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0 / zd_max
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
+               zefmax = MAX( e1f(ji,jj), e2f(ji,jj) )
+               ahm1(ji,jj) = za00 * zetmax
+               ahm2(ji,jj) = za00 * zefmax
+            END DO
+         END DO
+
+         IF( ln_dynldf_iso ) THEN
+            IF(lwp) WRITE(numout,*) '              Caution, as implemented now, the isopycnal part of momentum'
+            IF(lwp) WRITE(numout,*) '                 mixing use aht0 as eddy viscosity coefficient. Thus, it is'
+            IF(lwp) WRITE(numout,*) '                 uniform and you must be sure that your ahm is greater than'
+            IF(lwp) WRITE(numout,*) '                 aht0 everywhere in the model domain.'
+         ENDIF
+
+         ! Special case for ORCA R1, R2 and R4 configurations (overwrite the value of ahm1 ahm2)
+         ! Add PALEORCA2 configuration -- JBL 08.02.2017
+         ! ==============================================
+         IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. ( jp_cfg == 2 .OR. jp_cfg == 4 ) )   CALL ldf_dyn_c2d_orca( ld_print )
+         IF( cp_cfg == "orca" .AND.   jp_cfg == 1)                       CALL ldf_dyn_c2d_orca_R1( ld_print )
+
+         ! Control print
+         IF( lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: 2D ahm1 array'
+            CALL prihre(ahm1,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: 2D ahm2 array'
+            CALL prihre(ahm2,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         ENDIF
+      ENDIF
+
+      ! biharmonic operator (ahm3, ahm4) : at U- and V-points (used for bilaplacian operator
+      ! =================================                      whatever its orientation is)
+      IF( ln_dynldf_bilap ) THEN
+         ! (USER: modify ahm3 and ahm4 following your desiderata)
+         ! Here: ahm is proportional to the cube of the maximum of the gridspacing
+         !       in the to horizontal direction
+
+         zd_max = MAX( MAXVAL( e1u(:,:) ), MAXVAL( e2u(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              bi-laplacian operator: ahm proportional to e1**3 '
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0_blp / ( zd_max * zd_max * zd_max )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zeumax = MAX( e1u(ji,jj), e2u(ji,jj) )
+               zevmax = MAX( e1v(ji,jj), e2v(ji,jj) )
+               ahm3(ji,jj) = za00 * zeumax * zeumax * zeumax
+               ahm4(ji,jj) = za00 * zevmax * zevmax * zevmax
+            END DO
+         END DO
+
+         ! Control print
+         IF( lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahm3 array'
+            CALL prihre(ahm3,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahm4 array'
+            CALL prihre(ahm4,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         ENDIF
+      ENDIF
+      !
+   END SUBROUTINE ldf_dyn_c2d
+
+
+   SUBROUTINE ldf_dyn_c2d_orca( ld_print )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldf_dyn_c2d  ***
+      !!
+      !!                   **** W A R N I N G ****
+      !!
+      !!                ORCA R2 and R4 configurations
+      !!                  
+      !!                   **** W A R N I N G ****
+      !!                  
+      !! ** Purpose :   initializations of the lateral viscosity for orca R2
+      !!
+      !! ** Method  :   blah blah blah...
+      !!
+      !!----------------------------------------------------------------------
+      USE ldftra_oce, ONLY:   aht0
+      USE iom
+      !
+      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
+      !
+      INTEGER  ::   ji, jj, jn   ! dummy loop indices
+      INTEGER  ::   inum, iim, ijm            ! local integers
+      INTEGER  ::   ifreq, il1, il2, ij, ii
+      INTEGER  ::   ijpt0,ijpt1, ierror
+      REAL(wp) ::   zahmeq, zcoft, zcoff, zmsk
+      CHARACTER (len=15) ::   clexp
+      INTEGER,     POINTER, DIMENSION(:,:)  :: icof
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: ztemp2d  ! temporary array to read ahmcoef file
+      !!----------------------------------------------------------------------
+      !                                
+      CALL wrk_alloc( jpi   , jpj   , icof  )
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'inildf: 2d eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~  --'
+      IF(lwp) WRITE(numout,*) '        orca ocean configuration'
+
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. cp_cfz == "antarctic" ) THEN
+!
+! 1.2 Modify ahm
+! --------------
+         IF(lwp)WRITE(numout,*) ' inildf: Antarctic ocean'
+         IF(lwp)WRITE(numout,*) '         no tropics, no reduction of ahm'
+         IF(lwp)WRITE(numout,*) '         north boundary increase'
+
+         ahm1(:,:) = ahm0
+         ahm2(:,:) = ahm0
+
+         ijpt0=max(1,min(49 -njmpp+1,jpj))
+         ijpt1=max(0,min(49-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*2.
+            ahm1(:,jj)=ahm0*2.
+         END DO
+         ijpt0=max(1,min(48 -njmpp+1,jpj))
+         ijpt1=max(0,min(48-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.9
+            ahm1(:,jj)=ahm0*1.75
+         END DO
+         ijpt0=max(1,min(47 -njmpp+1,jpj))
+         ijpt1=max(0,min(47-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.5
+            ahm1(:,jj)=ahm0*1.25
+         END DO
+         ijpt0=max(1,min(46 -njmpp+1,jpj))
+         ijpt1=max(0,min(46-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.1
+         END DO
+
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      ELSE IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. cp_cfz == "arctic" ) THEN
+! 1.2 Modify ahm 
+! --------------
+         IF(lwp)WRITE(numout,*) ' inildf: Arctic ocean'
+         IF(lwp)WRITE(numout,*) '         no tropics, no reduction of ahm'
+         IF(lwp)WRITE(numout,*) '         south and west boundary increase'
+
+
+         ahm1(:,:) = ahm0
+         ahm2(:,:) = ahm0
+
+         ijpt0=max(1,min(98-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(98-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*2.
+            ahm1(:,jj)=ahm0*2.
+         END DO
+         ijpt0=max(1,min(99-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(99-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.9
+            ahm1(:,jj)=ahm0*1.75
+         END DO
+         ijpt0=max(1,min(100-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(100-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.5
+            ahm1(:,jj)=ahm0*1.25
+         END DO
+         ijpt0=max(1,min(101-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(101-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.1
+         END DO
+      ELSE
+         ! Read 2d integer array to specify western boundary increase in the
+         ! ===================== equatorial strip (20N-20S) defined at t-points
+         !
+         ALLOCATE( ztemp2d(jpi,jpj) )
+         ztemp2d(:,:) = 0.
+         CALL iom_open ( 'ahmcoef.nc', inum )
+         CALL iom_get  ( inum, jpdom_data, 'icof', ztemp2d)
+         icof(:,:)  = NINT(ztemp2d(:,:))
+         CALL iom_close( inum )
+         DEALLOCATE(ztemp2d)
+
+         ! Set ahm1 and ahm2  ( T- and F- points) (used for laplacian operator)
+         ! =================
+         ! define ahm1 and ahm2 at the right grid point position
+         ! (USER: modify ahm1 and ahm2 following your desiderata)
+
+
+         ! Decrease ahm to zahmeq m2/s in the tropics
+         ! (from 90 to 20 degre: ahm = constant
+         ! from 20 to  2.5 degre: ahm = decrease in (1-cos)/2
+         ! from  2.5 to  0 degre: ahm = constant
+         ! symmetric in the south hemisphere)
+
+         zahmeq = aht0
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( ABS( gphif(ji,jj) ) >= 20. ) THEN
+                  ahm2(ji,jj) =  ahm0
+               ELSEIF( ABS( gphif(ji,jj) ) <= 2.5 ) THEN
+                  ahm2(ji,jj) =  zahmeq
+               ELSE
+                  ahm2(ji,jj) = zahmeq + (ahm0-zahmeq)/2.   &
+                     * ( 1. - COS( rad * ( ABS(gphif(ji,jj))-2.5 ) * 180. / 17.5 ) )
+               ENDIF
+               IF( ABS( gphit(ji,jj) ) >= 20. ) THEN
+                  ahm1(ji,jj) =  ahm0
+               ELSEIF( ABS( gphit(ji,jj) ) <= 2.5 ) THEN
+                  ahm1(ji,jj) =  zahmeq
+               ELSE
+                  ahm1(ji,jj) = zahmeq + (ahm0-zahmeq)/2.   &
+                     * ( 1. - COS( rad * ( ABS(gphit(ji,jj))-2.5 ) * 180. / 17.5 ) )
+               ENDIF
+            END DO
+         END DO
+
+         ! increase along western boundaries of equatorial strip
+         ! t-point
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               zcoft = FLOAT( icof(ji,jj) ) / 100.
+               ahm1(ji,jj) = zcoft * ahm0 + (1.-zcoft) * ahm1(ji,jj) 
+            END DO
+         END DO
+         ! f-point
+         icof(:,:) = icof(:,:) * tmask(:,:,1)
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1   ! NO vector opt.
+               zmsk = tmask(ji,jj+1,1) + tmask(ji+1,jj+1,1) + tmask(ji,jj,1) + tmask(ji,jj+1,1)
+               IF( zmsk == 0. ) THEN
+                  zcoff = 1.
+               ELSE
+                  zcoff = FLOAT( icof(ji,jj+1) + icof(ji+1,jj+1) + icof(ji,jj) + icof(ji,jj+1) )   &
+                     / (zmsk * 100.)
+               ENDIF
+               ahm2(ji,jj) = zcoff * ahm0 + (1.-zcoff) * ahm2(ji,jj)
+            END DO
+         END DO
+      ENDIF
+      
+      ! Lateral boundary conditions on ( ahm1, ahm2 )
+      !                                ==============
+      CALL lbc_lnk( ahm1, 'T', 1. )   ! T-point, unchanged sign
+      CALL lbc_lnk( ahm2, 'F', 1. )   ! F-point, unchanged sign
+
+      ! Control print
+      IF( lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: 2D ahm1 array'
+         CALL prihre(ahm1,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: 2D ahm2 array'
+         CALL prihre(ahm2,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi   , jpj   , icof  )
+      !
+   END SUBROUTINE ldf_dyn_c2d_orca
+
+
+   SUBROUTINE ldf_dyn_c2d_orca_R1( ld_print )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE ldf_dyn_c2d  ***
+      !!
+      !!                   **** W A R N I N G ****
+      !!
+      !!                ORCA R1 configuration
+      !!                  
+      !!                   **** W A R N I N G ****
+      !!                  
+      !! ** Purpose :   initializations of the lateral viscosity for orca R1
+      !!
+      !! ** Method  :   blah blah blah...
+      !!
+      !!----------------------------------------------------------------------
+      USE ldftra_oce, ONLY:   aht0
+      USE iom
+      !
+      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
+      !
+      INTEGER ::   ji, jj, jn      ! dummy loop indices
+      INTEGER ::   inum            ! temporary logical unit
+      INTEGER ::   iim, ijm
+      INTEGER ::   ifreq, il1, il2, ij, ii
+      INTEGER ::   ijpt0,ijpt1, ierror
+      REAL(wp) ::   zahmeq, zcoft, zcoff, zmsk, zam20s
+      CHARACTER (len=15) ::   clexp
+      INTEGER,     POINTER, DIMENSION(:,:)  :: icof
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE :: ztemp2d  ! temporary array to read ahmcoef file
+      !!----------------------------------------------------------------------
+      !                                
+      CALL wrk_alloc( jpi   , jpj   , icof  )
+      !                                
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'inildf: 2d eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~  --'
+      IF(lwp) WRITE(numout,*) '        orca_r1 configuration'
+
+      IF( cp_cfg == "orca" .AND. cp_cfz == "antarctic" ) THEN
+!
+! 1.2 Modify ahm
+! --------------
+         IF(lwp)WRITE(numout,*) ' inildf: Antarctic ocean'
+         IF(lwp)WRITE(numout,*) '         no tropics, no reduction of ahm'
+         IF(lwp)WRITE(numout,*) '         north boundary increase'
+
+         ahm1(:,:) = ahm0
+         ahm2(:,:) = ahm0
+
+         ijpt0=max(1,min(49 -njmpp+1,jpj))
+         ijpt1=max(0,min(49-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*2.
+            ahm1(:,jj)=ahm0*2.
+         END DO
+         ijpt0=max(1,min(48 -njmpp+1,jpj))
+         ijpt1=max(0,min(48-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.9
+            ahm1(:,jj)=ahm0*1.75
+         END DO
+         ijpt0=max(1,min(47 -njmpp+1,jpj))
+         ijpt1=max(0,min(47-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.5
+            ahm1(:,jj)=ahm0*1.25
+         END DO
+         ijpt0=max(1,min(46 -njmpp+1,jpj))
+         ijpt1=max(0,min(46-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.1
+         END DO
+
+      ELSE IF( cp_cfg == "orca" .AND. cp_cfz == "arctic" ) THEN
+! 1.2 Modify ahm 
+! --------------
+         IF(lwp)WRITE(numout,*) ' inildf: Arctic ocean'
+         IF(lwp)WRITE(numout,*) '         no tropics, no reduction of ahm'
+         IF(lwp)WRITE(numout,*) '         south and west boundary increase'
+
+
+         ahm1(:,:) = ahm0
+         ahm2(:,:) = ahm0
+
+         ijpt0=max(1,min(98-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(98-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*2.
+            ahm1(:,jj)=ahm0*2.
+         END DO
+         ijpt0=max(1,min(99-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(99-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.9
+            ahm1(:,jj)=ahm0*1.75
+         END DO
+         ijpt0=max(1,min(100-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(100-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.5
+            ahm1(:,jj)=ahm0*1.25
+         END DO
+         ijpt0=max(1,min(101-jpjzoom+1-njmpp+1,jpj))
+         ijpt1=max(0,min(101-jpjzoom+1-njmpp+1,jpj-1))
+         DO jj=ijpt0,ijpt1
+            ahm2(:,jj)=ahm0*1.1
+         END DO
+      ELSE
+         
+         ! Read 2d integer array to specify western boundary increase in the
+         ! ===================== equatorial strip (20N-20S) defined at t-points
+         ALLOCATE( ztemp2d(jpi,jpj) )
+         ztemp2d(:,:) = 0.
+         CALL iom_open ( 'ahmcoef.nc', inum )
+         CALL iom_get  ( inum, jpdom_data, 'icof', ztemp2d)
+         icof(:,:)  = NINT(ztemp2d(:,:))
+         CALL iom_close( inum )
+         DEALLOCATE(ztemp2d)
+
+         ! Set ahm1 and ahm2  ( T- and F- points) (used for laplacian operator)
+         ! =================
+         ! define ahm1 and ahm2 at the right grid point position
+         ! (USER: modify ahm1 and ahm2 following your desiderata)
+
+
+         ! Decrease ahm to zahmeq m2/s in the tropics
+         ! (from 90   to 20   degrees: ahm = scaled by local metrics
+         !  from 20   to  2.5 degrees: ahm = decrease in (1-cos)/2
+         !  from  2.5 to  0   degrees: ahm = constant
+         ! symmetric in the south hemisphere)
+
+         zahmeq = aht0
+         zam20s = ahm0*COS( rad * 20. )
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( ABS( gphif(ji,jj) ) >= 20. ) THEN
+                  !              leave as set in ldf_dyn_c2d
+               ELSEIF( ABS( gphif(ji,jj) ) <= 2.5 ) THEN
+                  ahm2(ji,jj) =  zahmeq
+               ELSE
+                  ahm2(ji,jj) =  zahmeq + (zam20s-zahmeq)/2.   &
+                     * ( 1. - COS( rad * ( ABS(gphif(ji,jj))-2.5 ) * 180. / 17.5 ) )
+               ENDIF
+               IF( ABS( gphit(ji,jj) ) >= 20. ) THEN
+                  !             leave as set in ldf_dyn_c2d
+               ELSEIF( ABS( gphit(ji,jj) ) <= 2.5 ) THEN
+                  ahm1(ji,jj) =  zahmeq
+               ELSE
+                  ahm1(ji,jj) =  zahmeq + (zam20s-zahmeq)/2.   &
+                     * ( 1. - COS( rad * ( ABS(gphit(ji,jj))-2.5 ) * 180. / 17.5 ) )
+               ENDIF
+            END DO
+         END DO
+
+         ! increase along western boundaries of equatorial strip
+         ! t-point
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( ABS( gphit(ji,jj) ) < 20. ) THEN
+                  zcoft = FLOAT( icof(ji,jj) ) / 100.
+                  ahm1(ji,jj) = zcoft * ahm0 + (1.-zcoft) * ahm1(ji,jj) 
+               ENDIF
+            END DO
+         END DO
+         ! f-point
+         icof(:,:) = icof(:,:) * tmask(:,:,1)
+         DO jj = 1, jpjm1
+            DO ji = 1, jpim1
+               IF( ABS( gphif(ji,jj) ) < 20. ) THEN
+                  zmsk = tmask(ji,jj+1,1) + tmask(ji+1,jj+1,1) + tmask(ji,jj,1) + tmask(ji,jj+1,1)
+                  IF( zmsk == 0. ) THEN
+                     zcoff = 1.
+                  ELSE
+                     zcoff = FLOAT( icof(ji,jj+1) + icof(ji+1,jj+1) + icof(ji,jj) + icof(ji,jj+1) )   &
+                        / (zmsk * 100.)
+                  ENDIF
+                  ahm2(ji,jj) = zcoff * ahm0 + (1.-zcoff) * ahm2(ji,jj)
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+      
+      ! Lateral boundary conditions on ( ahm1, ahm2 )
+      !                                ==============
+      CALL lbc_lnk( ahm1, 'T', 1. )   ! T-point, unchanged sign
+      CALL lbc_lnk( ahm2, 'F', 1. )   ! F-point, unchanged sign
+
+      ! Control print
+      IF( lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: 2D ahm1 array'
+         CALL prihre(ahm1,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: 2D ahm2 array'
+         CALL prihre(ahm2,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi   , jpj   , icof  )
+      !
+   END SUBROUTINE ldf_dyn_c2d_orca_R1
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c3d.h90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c3d.h90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfdyn_c3d.h90	(revision 5879)
@@ -0,0 +1,434 @@
+   !!----------------------------------------------------------------------
+   !!                        ***  ldfdyn_c3d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: ldfdyn_c3d.h90 5400 2015-06-10 15:29:08Z cbricaud $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   'key_dynldf_c3d'             3D lateral eddy viscosity coefficients
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_dyn_c3d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_dyn_c3d  ***
+      !!                   
+      !! ** Purpose :   initializations of the horizontal ocean physics
+      !!
+      !! ** Method  :   3D eddy viscosity coef. ( longitude, latitude, depth )
+      !!       laplacian operator   : ahm1, ahm2 defined at T- and F-points
+      !!                              ahm2, ahm4 never used
+      !!       bilaplacian operator : ahm1, ahm2 never used
+      !!                           :  ahm3, ahm4 defined at U- and V-points
+      !!       ??? explanation of the default is missing
+      !!----------------------------------------------------------------------
+      USE ldftra_oce, ONLY :   aht0
+      USE iom
+      !!
+      LOGICAL, INTENT (in) ::   ld_print   ! If true, output arrays on numout
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zr = 0.2     ! maximum of the reduction factor at the bottom ocean ( 0 < zr < 1 )
+      REAL(wp) ::   zh = 500.    ! depth of at which start the reduction ( > dept(1) )
+      REAL(wp) ::   zd_max       ! maximum grid spacing over the global domain
+      REAL(wp) ::   za00, zc, zd, zetmax, zefmax, zeumax, zevmax   ! local scalars
+      REAL(wp), POINTER, DIMENSION(:) :: zcoef   
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpk, zcoef )
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ldf_dyn_c3d : 3D lateral eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+
+      
+      ! Set ahm1 and ahm2  ( T- and F- points) (used for laplacian operators
+      ! =================                       whatever its orientation is)
+      IF( ln_dynldf_lap ) THEN
+         ! define ahm1 and ahm2 at the right grid point position
+         ! (USER: modify ahm1 and ahm2 following your desiderata)
+
+         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              laplacian operator: ahm proportional to e1'
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0 / zd_max
+
+         IF( ln_dynldf_iso ) THEN
+            IF(lwp) WRITE(numout,*) '              Caution, as implemented now, the isopycnal part of momentum'
+            IF(lwp) WRITE(numout,*) '                 mixing use aht0 as eddy viscosity coefficient. Thus, it is'
+            IF(lwp) WRITE(numout,*) '                 uniform and you must be sure that your ahm is greater than'
+            IF(lwp) WRITE(numout,*) '                 aht0 everywhere in the model domain.'
+         ENDIF
+
+         CALL ldf_zpf( .TRUE. , 1000., 500., 0.25, fsdept(:,:,:), ahm1 )   ! vertical profile
+         CALL ldf_zpf( .TRUE. , 1000., 500., 0.25, fsdept(:,:,:), ahm2 )   ! vertical profile
+         DO jk = 1,jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
+                  zefmax = MAX( e1f(ji,jj), e2f(ji,jj) )
+                  ahm1(ji,jj,jk) = za00 * zetmax * ahm1(ji,jj,jk)
+                  ahm2(ji,jj,jk) = za00 * zefmax * ahm2(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+
+         ! Special case for ORCA R1, R2 and R4 configurations (overwrite the value of ahm1 ahm2)
+         ! Add PALEORCA2 configuration -- JBL 08.02.2017
+         ! ==============================================
+         IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. ( jp_cfg == 1 .OR. jp_cfg == 2 .OR. jp_cfg == 4 ) ) THEN 
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '              ORCA R1, R2 or R4: overwrite the previous definition of ahm'
+            IF(lwp) WRITE(numout,*) '              ================='
+            CALL ldf_dyn_c3d_orca( ld_print )
+         ENDIF
+
+      ENDIF
+      
+      ! Control print
+      IF(lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         3D ahm1 array (k=1)'
+         CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) '         3D ahm2 array (k=1)'
+         CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
+      ENDIF
+
+
+      ! ahm3 and ahm4 at U- and V-points (used for bilaplacian operator
+      ! ================================  whatever its orientation is)
+      ! (USER: modify ahm3 and ahm4 following your desiderata)
+      ! Here: ahm is proportional to the cube of the maximum of the gridspacing
+      !       in the to horizontal direction
+
+      IF( ln_dynldf_bilap ) THEN
+
+         zd_max = MAX( MAXVAL( e1u(:,:) ), MAXVAL( e2u(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+
+         IF(lwp) WRITE(numout,*) '              bi-laplacian operator: ahm proportional to e1**3 '
+         IF(lwp) WRITE(numout,*) '              maximum grid-spacing = ', zd_max, ' maximum value for ahm = ', ahm0
+
+         za00 = ahm0_blp / ( zd_max * zd_max * zd_max )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zeumax = MAX( e1u(ji,jj), e2u(ji,jj) )
+               zevmax = MAX( e1v(ji,jj), e2v(ji,jj) )
+               ahm3(ji,jj,1) = za00 * zeumax * zeumax * zeumax
+               ahm4(ji,jj,1) = za00 * zevmax * zevmax * zevmax
+            END DO
+         END DO
+
+         zh = MAX( zh, fsdept(1,1,1) )   ! at least the first reach ahm0
+         IF( ln_zco ) THEN               ! z-coordinate, same profile everywhere
+            IF(lwp) WRITE(numout,'(36x," ahm ", 7x)')
+            DO jk = 1, jpk
+               IF( fsdept(1,1,jk) <= zh ) THEN
+                  zcoef(jk) = 1.e0
+               ELSE
+                  zcoef(jk) = 1.e0 + ( zr - 1.e0 )   &
+                     &               * (  1. - EXP( ( fsdept(1,1,jk   ) - zh ) / zh )  )   &
+                     &               / (  1. - EXP( ( fsdept(1,1,jpkm1) - zh ) / zh )  )
+               ENDIF
+               ahm3(:,:,jk) = ahm3(:,:,1) * zcoef(jk)
+               ahm4(:,:,jk) = ahm4(:,:,1) * zcoef(jk)
+               IF(lwp) WRITE(numout,'(34x,E7.2,8x,i3)') zcoef(jk) * ahm0, jk
+            END DO
+         ELSE                            ! partial steps or s-ccordinate
+            zc = MAXVAL( fsdept(:,:,jpkm1) )
+            IF( lk_mpp )   CALL mpp_max( zc )   ! max over the global domain
+
+            zc = 1. / (  1. - EXP( ( zc - zh ) / zh )  )
+            DO jk = 2, jpkm1
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( fsdept(ji,jj,jk) <= zh ) THEN
+                        ahm3(ji,jj,jk) = ahm3(ji,jj,1)
+                        ahm4(ji,jj,jk) = ahm4(ji,jj,1)
+                     ELSE
+                        zd = 1.e0 + ( zr - 1.e0 ) * (  1. - EXP( ( fsdept(ji,jj,jk) - zh ) / zh )  ) * zc
+                        ahm3(ji,jj,jk) = ahm3(ji,jj,1) * zd
+                        ahm4(ji,jj,jk) = ahm4(ji,jj,1) * zd
+                     ENDIF
+                  END DO
+               END DO
+            END DO
+            ahm3(:,:,jpk) = ahm3(:,:,jpkm1)
+            ahm4(:,:,jpk) = ahm4(:,:,jpkm1)
+            IF(lwp) WRITE(numout,'(36x," ahm ", 7x)')
+            DO jk = 1, jpk
+               IF(lwp) WRITE(numout,'(30x,E10.2,8x,i3)') ahm3(1,1,jk), jk
+            END DO
+         ENDIF
+
+         ! Control print
+         IF( lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahm3 array at level 1'
+            CALL prihre(ahm3(:,:,1  ),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahm4 array at level 1'
+            CALL prihre(ahm4(:,:,jpk),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         ENDIF
+      ENDIF
+      !
+      CALL wrk_dealloc( jpk, zcoef )
+      !
+   END SUBROUTINE ldf_dyn_c3d
+
+
+   SUBROUTINE ldf_dyn_c3d_orca( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_dyn_c3d  ***
+      !!                   
+      !! ** Purpose :   ORCA R1, R2 and R4 only
+      !!
+      !! ** Method  :   blah blah blah ....
+      !!----------------------------------------------------------------------
+      USE ldftra_oce, ONLY:   aht0
+      USE iom
+      !!
+      LOGICAL, INTENT(in) ::   ld_print   ! If true, output arrays on numout
+      !!
+      INTEGER ::   ji, jj, jk, jn      ! dummy loop indices
+      INTEGER ::   ii0, ii1, ij0, ij1  ! local integers
+      INTEGER ::   inum, iim, ijm      ! 
+      INTEGER ::   ifreq, il1, il2, ij, ii
+      REAL(wp) ::   zahmeq, zcoff, zcoft, zmsk   ! local scalars
+      REAL(wp) ::   zemax , zemin, zeref, zahmm
+      CHARACTER (len=15) ::   clexp
+      INTEGER , POINTER, DIMENSION(:,:)  :: icof
+      REAL(wp), POINTER, DIMENSION(:  )  :: zcoef   
+      REAL(wp), POINTER, DIMENSION(:,:)  :: zahm0
+      !
+      REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   ztemp2d  ! temporary array to read ahmcoef file
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc( jpi   , jpj   , icof  )
+      CALL wrk_alloc( jpk   ,         zcoef )
+      CALL wrk_alloc( jpi   , jpj   , zahm0 )
+      !
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*) 'ldfdyn_c3d_orca : 3D eddy viscosity coefficient'
+      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
+      IF(lwp) WRITE(numout,*) '        orca R1, R2 or R4 configuration: reduced in the surface Eq. strip '
+
+      ! Read 2d integer array to specify western boundary increase in the
+      ! ===================== equatorial strip (20N-20S) defined at t-points
+      ALLOCATE( ztemp2d(jpi,jpj) )
+      ztemp2d(:,:) = 0.
+      CALL iom_open ( 'ahmcoef.nc', inum )
+      CALL iom_get  ( inum, jpdom_data, 'icof', ztemp2d)
+      icof(:,:)  = NINT(ztemp2d(:,:))
+      CALL iom_close( inum )
+      DEALLOCATE(ztemp2d)
+
+      ! Set ahm1 and ahm2
+      ! =================
+      
+      ! define ahm1 and ahm2 at the right grid point position
+      ! (USER: modify ahm1 and ahm2 following your desiderata)
+      ! biharmonic : ahm1 (ahm2) defined at u- (v-) point
+      ! harmonic   : ahm1 (ahm2) defined at t- (f-) point
+      
+      ! first level : as for 2D coefficients
+      
+      ! Decrease ahm to zahmeq m2/s in the tropics
+      ! (from 90 to 20 degre: ahm = constant
+      ! from 20 to  2.5 degre: ahm = decrease in (1-cos)/2
+      ! from  2.5 to  0 degre: ahm = constant
+      ! symmetric in the south hemisphere)
+      
+      IF( jp_cfg == 4 )   THEN
+         zahmeq = 5.0 * aht0
+         zahmm  = min( 160000.0, ahm0)
+         zemax = MAXVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
+         zemin = MINVAL ( e1t(:,:) * e2t(:,:), tmask(:,:,1) .GE. 0.5 )
+         zeref = MAXVAL ( e1t(:,:) * e2t(:,:),   &
+             &   tmask(:,:,1) .GE. 0.5 .AND. ABS(gphit(:,:)) .GT. 50. )
+ 
+         DO jj = 1, jpj
+           DO ji = 1, jpi
+              zmsk = e1t(ji,jj) * e2t(ji,jj)
+              IF( abs(gphit(ji,jj)) .LE. 15 ) THEN 
+                 zahm0(ji,jj) = ahm0
+              ELSE 
+                 IF( zmsk .GE. zeref ) THEN 
+                    zahm0(ji,jj) = ahm0
+                 ELSE 
+                    zahm0(ji,jj) = zahmm + (ahm0-zahmm)*(1.0 -   &
+                        &          cos((rpi*0.5*(zmsk-zemin)/(zeref-zemin))))
+                 ENDIF 
+              ENDIF 
+           END DO 
+         END DO 
+      ENDIF
+
+      IF( jp_cfg == 2 )   THEN
+         zahmeq     = aht0
+         zahmm      = ahm0
+         zahm0(:,:) = ahm0
+      ENDIF
+
+      IF( jp_cfg == 1 )   THEN
+         zahmeq     = aht0  ! reduced to aht0 on equator; set to ahm0 if no tropical reduction is required
+         zahmm      = ahm0
+         zahm0(:,:) = ahm0
+      ENDIF
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( ABS(gphif(ji,jj)) >= 20.) THEN
+               ahm2(ji,jj,1) =  zahm0(ji,jj)
+            ELSEIF( ABS(gphif(ji,jj)) <= 2.5) THEN
+               ahm2(ji,jj,1) =  zahmeq
+            ELSE
+               ahm2(ji,jj,1) = zahmeq + (zahm0(ji,jj)-zahmeq)/2.   &
+                  &            *(1.-COS( rad*(ABS(gphif(ji,jj))-2.5)*180./17.5 ) )
+            ENDIF
+            IF( ABS(gphit(ji,jj)) >= 20.) THEN
+               ahm1(ji,jj,1) =  zahm0(ji,jj)
+            ELSEIF( ABS(gphit(ji,jj)) <= 2.5) THEN
+               ahm1(ji,jj,1) =  zahmeq
+            ELSE
+               ahm1(ji,jj,1) = zahmeq + (zahm0(ji,jj)-zahmeq)/2.   &
+                  &            *(1.-COS( rad*(ABS(gphit(ji,jj))-2.5)*180./17.5 ) )
+            ENDIF
+         END DO
+      END DO
+      
+      ! increase along western boundaries of equatorial strip
+      ! t-point
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1
+            zcoft = float( icof(ji,jj) ) / 100.
+            ahm1(ji,jj,1) = zcoft * zahm0(ji,jj) + (1.-zcoft) * ahm1(ji,jj,1)
+         END DO
+      END DO
+      ! f-point
+      icof(:,:) = icof(:,:) * tmask(:,:,1)
+      DO jj = 1, jpjm1
+         DO ji = 1, jpim1   ! NO vector opt.
+            zmsk = tmask(ji,jj+1,1) + tmask(ji+1,jj+1,1) + tmask(ji,jj,1) + tmask(ji,jj+1,1)
+            IF( zmsk == 0. ) THEN
+               zcoff = 1.
+            ELSE
+               zcoff = FLOAT( icof(ji,jj+1) + icof(ji+1,jj+1) + icof(ji,jj) + icof(ji,jj+1) )   &
+                     / (zmsk * 100.)
+            ENDIF
+            ahm2(ji,jj,1) = zcoff * zahm0(ji,jj) + (1.-zcoff) * ahm2(ji,jj,1)
+         END DO
+      END DO
+
+      ! other level: re-increase the coef in the deep ocean
+      !==================================================================
+      ! Prior to v3.3, zcoeff was hardwired according to k-index jk.
+      !
+      ! From v3.3 onwards this has been generalised to a function of 
+      ! depth so that it can be used with any number of levels.
+      !
+      ! The function has been chosen to match the original values (shown
+      ! in the following comments) when using the standard 31 ORCA levels.  
+      !     DO jk = 1, 21
+      !        zcoef(jk) = 1._wp
+      !     END DO
+      !     zcoef(22) = 2._wp
+      !     zcoef(23) = 3._wp
+      !     zcoef(24) = 5._wp
+      !     zcoef(25) = 7._wp
+      !     zcoef(26) = 9._wp
+      !     DO jk = 27, jpk
+      !        zcoef(jk) = 10._wp
+      !     END DO
+      !==================================================================
+
+       IF(lwp) THEN
+          WRITE(numout,*)
+          WRITE(numout,*) '         1D zcoef array '
+          WRITE(numout,*) '         ~~~~~~~~~~~~~~ '
+          WRITE(numout,*)
+          WRITE(numout,*) '    jk        zcoef '
+       ENDIF
+
+      DO jk=1, jpk
+         zcoef(jk) = 1.0_wp + NINT(9.0_wp*(gdept_1d(jk)-800.0_wp)/(3000.0_wp-800.0_wp))
+         zcoef(jk) = MIN(10.0_wp, MAX(1.0_wp, zcoef(jk)))
+         IF(lwp) WRITE(numout,'(4x,i3,6x,f7.3)') jk,zcoef(jk)
+      END DO
+
+      DO jk = 2, jpk
+         ahm1(:,:,jk) = MIN( zahm0(:,:), zcoef(jk) * ahm1(:,:,1) )
+         ahm2(:,:,jk) = MIN( zahm0(:,:), zcoef(jk) * ahm2(:,:,1) )
+      END DO
+
+      IF( jp_cfg == 4 )   THEN         ! Limit AHM in Gibraltar strait
+         ij0 = 50   ;   ij1 = 53
+         ii0 = 69   ;   ii1 = 71
+         DO jk = 1, jpk
+            ahm1(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) = MIN( zahmm, ahm1(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) ) 
+            ahm2(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) = MIN( zahmm, ahm2(mi0(ii0):mi1(ii1),mj0(ij0):mj1(ij1),jk) )
+         END DO
+      ENDIF
+      CALL lbc_lnk( ahm1, 'T', 1. )   ! Lateral boundary conditions (unchanged sign)
+      CALL lbc_lnk( ahm2, 'F', 1. )
+
+
+      IF(lwp) THEN                    ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '         3D ahm1 array (k=1)'
+         CALL prihre( ahm1(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) '         3D ahm2 array (k=1)'
+         CALL prihre( ahm2(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
+         WRITE(numout,*)
+         WRITE(numout,*) '         3D ahm2 array (k=jpk)'
+         CALL prihre( ahm2(:,:,jpk), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1.e-3, numout )
+      ENDIF
+
+
+      ! Set ahm3 and ahm4
+      ! =================
+
+      ! define ahm3 and ahm4 at the right grid point position
+      ! initialization to a constant value
+      !     (USER: modify ahm3 and ahm4 following your desiderata)
+      !     harmonic isopycnal or geopotential:
+      !                          ahm3 (ahm4) defined at u- (v-) point
+      DO jk = 1, jpk
+         DO jj = 2, jpj
+            DO ji = 2, jpi
+               ahm3(ji,jj,jk) = 0.5 * ( ahm2(ji,jj,jk) + ahm2(ji  ,jj-1,jk) )
+               ahm4(ji,jj,jk) = 0.5 * ( ahm2(ji,jj,jk) + ahm2(ji-1,jj  ,jk) )
+            END DO
+         END DO
+      END DO
+      ahm3 ( :, 1, :) = ahm3 ( :, 2, :)
+      ahm4 ( :, 1, :) = ahm4 ( :, 2, :)
+      
+      CALL lbc_lnk( ahm3, 'U', 1. )    ! Lateral boundary conditions (unchanged sign)
+      CALL lbc_lnk( ahm4, 'V', 1. )
+
+      ! Control print
+
+      IF( lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm3 array level 1'
+         CALL prihre(ahm3(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) '         ahm4 array level 1'
+         CALL prihre(ahm4(:,:,1),jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi   , jpj   , icof  )
+      CALL wrk_dealloc( jpk   ,         zcoef )
+      CALL wrk_dealloc( jpi   , jpj   , zahm0 )
+      !
+   END SUBROUTINE ldf_dyn_c3d_orca
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfeiv.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfeiv.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldfeiv.F90	(revision 5879)
@@ -0,0 +1,235 @@
+MODULE ldfeiv
+   !!======================================================================
+   !!                     ***  MODULE  ldfeiv  ***
+   !! Ocean physics:  variable eddy induced velocity coefficients
+   !!======================================================================
+   !! History :  OPA  ! 1999-03  (G. Madec, A. Jouzeau)  Original code
+   !!   NEMO     1.0  ! 2002-06  (G. Madec)  Free form, F90
+   !!----------------------------------------------------------------------
+#if   defined key_traldf_eiv   &&   defined key_traldf_c2d
+   !!----------------------------------------------------------------------
+   !!   'key_traldf_eiv'      and                     eddy induced velocity
+   !!   'key_traldf_c2d'                    2D tracer lateral  mixing coef.
+   !!----------------------------------------------------------------------
+   !!   ldf_eiv      : compute the eddy induced velocity coefficients
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE sbc_oce         ! surface boundary condition: ocean
+   USE sbcrnf          ! river runoffs
+   USE ldftra_oce      ! ocean tracer   lateral physics
+   USE phycst          ! physical constants
+   USE ldfslp          ! iso-neutral slopes
+   USE in_out_manager  ! I/O manager
+   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE prtctl          ! Print control
+   USE iom             ! I/O library
+   USE wrk_nemo        ! work arrays
+   USE timing          ! Timing
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   ldf_eiv    ! routine called by step.F90
+   
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: ldfeiv.F90 6631 2016-05-27 07:12:30Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE ldf_eiv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldf_eiv  ***
+      !!
+      !! ** Purpose :   Compute the eddy induced velocity coefficient from the
+      !!              growth rate of baroclinic instability.
+      !!
+      !! ** Method :
+      !!
+      !! ** Action : - uslp , vslp  : i- and j-slopes of neutral surfaces at u- & v-points
+      !!             - wslpi, wslpj : i- and j-slopes of neutral surfaces at w-points. 
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step inedx
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   zfw, ze3w, zn2, zf20, zaht, zaht_min      ! temporary scalars
+      REAL(wp), DIMENSION(:,:), POINTER ::   zn, zah, zhw, zross   ! 2D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('ldf_eiv')
+      !
+      CALL wrk_alloc( jpi,jpj, zn, zah, zhw, zross )
+
+      IF( kt == nit000 ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'ldf_eiv : eddy induced velocity coefficients'
+         IF(lwp) WRITE(numout,*) '~~~~~~~'
+      ENDIF
+      
+      ! 0. Local initialization
+      ! -----------------------
+      zn   (:,:) = 0._wp
+      zhw  (:,:) = 5._wp
+      zah  (:,:) = 0._wp
+      zross(:,:) = 0._wp
+
+
+      ! 1. Compute lateral diffusive coefficient 
+      ! ----------------------------------------
+      IF( ln_traldf_grif ) THEN
+         DO jk = 1, jpk
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ! Take the max of N^2 and zero then take the vertical sum 
+                  ! of the square root of the resulting N^2 ( required to compute 
+                  ! internal Rossby radius Ro = .5 * sum_jpk(N) / f 
+                  zn2 = MAX( rn2b(ji,jj,jk), 0._wp )
+                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * fse3w(ji,jj,jk)
+                  ! Compute elements required for the inverse time scale of baroclinic
+                  ! eddies using the isopycnal slopes calculated in ldfslp.F : 
+                  ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
+                  ze3w = fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  zah(ji,jj) = zah(ji,jj) + zn2 * wslp2(ji,jj,jk) * ze3w
+                  zhw(ji,jj) = zhw(ji,jj) + ze3w
+               END DO
+            END DO
+         END DO
+      ELSE
+         DO jk = 1, jpk
+            DO jj = 2, jpjm1
+               DO ji = 2, jpim1
+                  ! Take the max of N^2 and zero then take the vertical sum 
+                  ! of the square root of the resulting N^2 ( required to compute 
+                  ! internal Rossby radius Ro = .5 * sum_jpk(N) / f 
+                  zn2 = MAX( rn2b(ji,jj,jk), 0._wp )
+                  zn(ji,jj) = zn(ji,jj) + SQRT( zn2 ) * fse3w(ji,jj,jk)
+                  ! Compute elements required for the inverse time scale of baroclinic
+                  ! eddies using the isopycnal slopes calculated in ldfslp.F : 
+                  ! T^-1 = sqrt(m_jpk(N^2*(r1^2+r2^2)*e3w))
+                  ze3w = fse3w(ji,jj,jk) * tmask(ji,jj,jk)
+                  zah(ji,jj) = zah(ji,jj) + zn2 * ( wslpi(ji,jj,jk) * wslpi(ji,jj,jk)   &
+                     &                            + wslpj(ji,jj,jk) * wslpj(ji,jj,jk) ) * ze3w
+                  zhw(ji,jj) = zhw(ji,jj) + ze3w
+               END DO
+            END DO
+         END DO
+      END IF
+
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            zfw = MAX( ABS( 2. * omega * SIN( rad * gphit(ji,jj) ) ) , 1.e-10 )
+            ! Rossby radius at w-point taken < 40km and  > 2km
+            zross(ji,jj) = MAX( MIN( .4 * zn(ji,jj) / zfw, 40.e3 ), 2.e3 )
+            ! Compute aeiw by multiplying Ro^2 and T^-1
+            aeiw(ji,jj) = zross(ji,jj) * zross(ji,jj) * SQRT( zah(ji,jj) / zhw(ji,jj) ) * ssmask(ji,jj)
+         END DO
+      END DO
+
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. jp_cfg == 2 ) THEN   ! ORCA R2
+         DO jj = 2, jpjm1
+!CDIR NOVERRCHK 
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               ! Take the minimum between aeiw and 1000 m2/s over shelves (depth shallower than 650 m)
+               IF( mbkt(ji,jj) <= 20 )   aeiw(ji,jj) = MIN( aeiw(ji,jj), 1000. )
+            END DO
+         END DO
+      ENDIF
+
+      ! Decrease the coefficient in the tropics (20N-20S) 
+      zf20 = 2._wp * omega * sin( rad * 20._wp )
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiw(ji,jj) = MIN( 1., ABS( ff(ji,jj) / zf20 ) ) * aeiw(ji,jj)
+         END DO
+      END DO
+
+      ! ORCA R05: Take the minimum between aeiw  and aeiv0
+      IF( cp_cfg == "orca" .AND. jp_cfg == 05 ) THEN
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               aeiw(ji,jj) = MIN( aeiw(ji,jj), aeiv0 )
+            END DO
+         END DO
+      ENDIF
+
+      ! ORCA R1: Take the minimum between aeiw  and aeiv0
+      IF( cp_cfg == "orca" .AND. jp_cfg == 1 ) THEN
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               aeiw(ji,jj) = MIN( aeiw(ji,jj), aeiv0 )
+            END DO
+         END DO
+      ENDIF
+
+      CALL lbc_lnk( aeiw, 'W', 1. )      ! lateral boundary condition on aeiw 
+
+
+      ! Average the diffusive coefficient at u- v- points 
+      DO jj = 2, jpjm1
+         DO ji = fs_2, fs_jpim1   ! vector opt.
+            aeiu(ji,jj) = 0.5_wp * ( aeiw(ji,jj) + aeiw(ji+1,jj  ) )
+            aeiv(ji,jj) = 0.5_wp * ( aeiw(ji,jj) + aeiw(ji  ,jj+1) )
+         END DO 
+      END DO 
+      CALL lbc_lnk( aeiu, 'U', 1. )   ;   CALL lbc_lnk( aeiv, 'V', 1. )      ! lateral boundary condition
+
+
+      IF(ln_ctl) THEN
+         CALL prt_ctl(tab2d_1=aeiu, clinfo1=' eiv  - u: ', ovlap=1)
+         CALL prt_ctl(tab2d_1=aeiv, clinfo1=' eiv  - v: ', ovlap=1)
+      ENDIF
+
+      ! ORCA R05: add a space variation on aht (=aeiv except at the equator and river mouth)
+      IF( cp_cfg == "orca" .AND. jp_cfg == 05 ) THEN
+         zf20     = 2._wp * omega * SIN( rad * 20._wp )
+         zaht_min = 100._wp                           ! minimum value for aht
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zaht      = ( 1._wp -  MIN( 1._wp , ABS( ff(ji,jj) / zf20 ) ) ) * ( aht0 - zaht_min )  &
+                  &      + aht0 * rnfmsk(ji,jj)                          ! enhanced near river mouths
+               ahtu(ji,jj) = MAX( MAX( zaht_min, aeiu(ji,jj) ) + zaht, aht0 )
+               ahtv(ji,jj) = MAX( MAX( zaht_min, aeiv(ji,jj) ) + zaht, aht0 )
+               ahtw(ji,jj) = MAX( MAX( zaht_min, aeiw(ji,jj) ) + zaht, aht0 )
+            END DO
+         END DO
+         IF(ln_ctl) THEN
+            CALL prt_ctl(tab2d_1=ahtu, clinfo1=' aht  - u: ', ovlap=1)
+            CALL prt_ctl(tab2d_1=ahtv, clinfo1=' aht  - v: ', ovlap=1)
+            CALL prt_ctl(tab2d_1=ahtw, clinfo1=' aht  - w: ', ovlap=1)
+         ENDIF
+      ENDIF
+
+      IF( aeiv0 == 0._wp ) THEN
+         aeiu(:,:) = 0._wp
+         aeiv(:,:) = 0._wp
+         aeiw(:,:) = 0._wp
+      ENDIF
+
+      CALL iom_put( "aht2d"    , ahtw )   ! lateral eddy diffusivity
+      CALL iom_put( "aht2d_eiv", aeiw )   ! EIV lateral eddy diffusivity
+      !  
+      CALL wrk_dealloc( jpi,jpj, zn, zah, zhw, zross )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('ldf_eiv')
+      !
+   END SUBROUTINE ldf_eiv
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option                                         Dummy module
+   !!----------------------------------------------------------------------
+CONTAINS
+   SUBROUTINE ldf_eiv( kt )       ! Empty routine
+      INTEGER :: kt
+      WRITE(*,*) 'ldf_eiv: You should not have seen this print! error?', kt
+   END SUBROUTINE ldf_eiv
+#endif
+
+   !!======================================================================
+END MODULE ldfeiv
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldftra_c2d.h90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldftra_c2d.h90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/ldftra_c2d.h90	(revision 5879)
@@ -0,0 +1,163 @@
+   !!----------------------------------------------------------------------
+   !!                      ***  ldftra_c2d.h90  ***
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: ldftra_c2d.h90 4147 2013-11-04 11:51:55Z cetlod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ldf_tra_c2d( ld_print )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ldftra_c2d  ***
+      !!              
+      !! ** Purpose :   initializations of horizontally non uniform eddy 
+      !!      diffusivity coefficients
+      !!
+      !! ** Method :
+      !!       biharmonic operator    : ahtt = defined at T-level
+      !!                                ahtu,ahtv,ahtw never used
+      !!       harmonic operator (ahtt never used)
+      !!           iso-model level   : ahtu, ahtv defined at u-, v-points
+      !!         isopycnal         : ahtu, ahtv, ahtw defined at u-, v-, w-pts
+      !!         or geopotential   
+      !!       eddy induced velocity
+      !!           always harmonic   : aeiu, aeiv, aeiw defined at u-, v-, w-pts
+      !!----------------------------------------------------------------------
+      LOGICAL, INTENT (in) ::   ld_print   ! If true, print arrays in numout
+      !
+      INTEGER ::   ji, jj   ! dummy loop indices
+      REAL(wp) ::   za00, zd_max, zeumax, zevmax, zetmax
+      !!----------------------------------------------------------------------
+
+      IF( lk_traldf_eiv ) THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra_c2d : 2D eddy diffusivity and eddy'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --  induced velocity coefficients'
+      ELSE
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' ldf_tra2d : 2D eddy diffusivity coefficient'
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~   --'
+      ENDIF
+
+      zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+      IF( lk_mpp ) CALL mpp_max( zd_max )   ! max over the global domain
+
+      ! harmonic operator : (U-, V-, W-points)
+      ! ==================
+      IF( ln_traldf_lap ) THEN
+         !
+         za00 = aht0 / zd_max
+         !
+         DO jj = 1, jpj 
+            DO ji = 1, jpi 
+               zeumax = MAX( e1u(ji,jj), e2u(ji,jj) ) 
+               zevmax = MAX( e1v(ji,jj), e2v(ji,jj) ) 
+               zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
+               ahtu(ji,jj) = za00 * zeumax ! set ahtu = ahtv at u- and v-points, 
+               ahtv(ji,jj) = za00 * zevmax ! and ahtw at w-point (idem T-point) 
+               ahtw(ji,jj) = za00 * zetmax ! 
+            END DO
+         END DO
+
+         CALL lbc_lnk( ahtu, 'U', 1. )   ! Lateral boundary conditions
+         CALL lbc_lnk( ahtv, 'V', 1. )   ! (no change of sign)
+         CALL lbc_lnk( ahtw, 'W', 1. )
+
+         ! Special case for ORCA R2 and R4 configurations (overwrite the value of ahtu ahtv ahtw)
+         ! Add PALEORCA2 configuration -- JBL 08.02.2017
+         ! ==============================================
+         IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. ( jp_cfg == 2 .OR. jp_cfg == 4 ) )   THEN
+            ahtu(:,:) = aht0              ! set ahtu = ahtv at u- and v-points,
+            ahtv(:,:) = aht0              ! and ahtw at w-point
+            ahtw(:,:) = aht0              ! (here : no space variation)
+            IF(lwp) WRITE(numout,*) '               ORCA R2 or R4 case'
+            IF(lwp) WRITE(numout,*) '               Constant values used for eddy diffusivity coefficients'
+            IF(lwp) WRITE(numout,*) '               Variation lat/lon only for eddy induced velocity coefficients'
+         ENDIF
+
+         ! Control print
+         IF( lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahtu array'
+            CALL prihre( ahtu, jpi, jpj, 1, jpi, 1,   &
+               &                         1, jpj, 1, 1.e-3, numout )
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahtv array'
+            CALL prihre( ahtv, jpi, jpj, 1, jpi, 1,   &
+               &                         1, jpj, 1, 1.e-3, numout )
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: ahtw array'
+            CALL prihre( ahtw, jpi, jpj, 1, jpi, 1,   &
+               &                         1, jpj, 1, 1.e-3, numout )
+         ENDIF
+      ENDIF
+      
+      ! biharmonic operator : (T-point)
+      ! ====================
+      IF( ln_traldf_bilap ) THEN
+         ! (USER: modify ahtt following your desiderata)
+         ! Here: ahm is proportional to the cube of the maximum of the gridspacing
+         !       in the to horizontal direction
+
+         zd_max = MAX( MAXVAL( e1t(:,:) ), MAXVAL( e2t(:,:) ) )
+         IF( lk_mpp )   CALL mpp_max( zd_max )   ! max over the global domain
+
+         za00 = aht0 / ( zd_max * zd_max * zd_max )
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zetmax = MAX( e1t(ji,jj), e2t(ji,jj) )
+               ahtt(ji,jj) = za00 * zetmax * zetmax * zetmax      ! set ahtt at T-point
+            END DO
+         END DO
+
+         CALL lbc_lnk( ahtt, 'T', 1. )   ! Lateral boundary conditions on ( ahtt )
+
+         ! Control print
+         IF( lwp .AND. ld_print ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'inildf: 2D ahtt array'
+            CALL prihre( ahtt, jpi, jpj, 1, jpi, 1,   &
+               &                         1, jpj, 1, 1.e-3, numout )
+         ENDIF
+      ENDIF
+
+# if defined key_traldf_eiv
+      ! set aeiu = aeiv at u- and v-points, and aeiw at w-point (idem T-point)
+      ! (here no space variation)
+      aeiu(:,:) = aeiv0
+      aeiv(:,:) = aeiv0
+      aeiw(:,:) = aeiv0
+      
+      IF( cp_cfg == "orca" .AND. jp_cfg == 4 ) THEN
+         !                                 ! Cancel eiv in Gibraltar strait
+         aeiu( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
+         aeiv( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
+         aeiw( mi0(68):mi1(71) , mj0(50):mj1(53) ) = 0.e0
+         !                                 ! Cancel eiv in Mediterrannean sea
+         aeiu( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
+         aeiv( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
+         aeiw( mi0(70):mi1(90) , mj0(49):mj1(56) ) = 0.e0
+      ENDIF
+
+      ! Lateral boundary conditions on ( aeiu, aeiv, aeiw )
+      CALL lbc_lnk( aeiu, 'U', 1. )
+      CALL lbc_lnk( aeiv, 'V', 1. )
+      CALL lbc_lnk( aeiw, 'W', 1. )
+
+      ! Control print
+      IF( lwp .AND. ld_print ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiu array'
+         CALL prihre(aeiu,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiv array'
+         CALL prihre(aeiv,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+         WRITE(numout,*)
+         WRITE(numout,*) 'inildf: aeiw array'
+         CALL prihre(aeiw,jpi,jpj,1,jpi,1,1,jpj,1,1.e-3,numout)
+      ENDIF
+# endif
+      !
+   END SUBROUTINE ldf_tra_c2d
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/lib_mpp.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/lib_mpp.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/lib_mpp.F90	(revision 5879)
@@ -0,0 +1,4041 @@
+MODULE lib_mpp
+   !!======================================================================
+   !!                       ***  MODULE  lib_mpp  ***
+   !! Ocean numerics:  massively parallel processing library
+   !!=====================================================================
+   !! History :  OPA  !  1994  (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!            7.0  !  1997  (A.M. Treguier)  SHMEM additions
+   !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!                 !  1998  (J.M. Molines) Open boundary conditions
+   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
+   !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
+   !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
+   !!                 !  2004  (J.M. Molines) minloc, maxloc
+   !!             -   !  2005  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!             -   !  2005  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
+   !!             -   !  2005  (R. Benshila, G. Madec)  add extra halo case
+   !!             -   !  2008  (R. Benshila) add mpp_ini_ice
+   !!            3.2  !  2009  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
+   !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl
+   !!            4.0  !  2011  (G. Madec)  move ctl_ routines from in_out_manager
+   !!            3.5  !  2012  (S.Mocavero, I. Epicoco) Add 'mpp_lnk_bdy_3d', 'mpp_lnk_obc_3d', 
+   !!                          'mpp_lnk_bdy_2d' and 'mpp_lnk_obc_2d' routines and update
+   !!                          the mppobc routine to optimize the BDY and OBC communications
+   !!            3.5  !  2013  ( C. Ethe, G. Madec ) message passing arrays as local variables 
+   !!            3.5  !  2013  (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
+   !!            3.6  !  2015  (O. TintÃ³ and M. Castrillo - BSC) Added 'mpp_lnk_2d_multiple', 'mpp_lbc_north_2d_multiple', 'mpp_max_multiple' 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
+   !!   ctl_warn   : initialization, namelist read, and parameters control
+   !!   ctl_opn    : Open file and check if required file is available.
+   !!   ctl_nam    : Prints informations when an error occurs while reading a namelist
+   !!   get_unit   : give the index of an unused logical unit
+   !!----------------------------------------------------------------------
+#if   defined key_mpp_mpi
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'             MPI massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!   lib_mpp_alloc : allocate mpp arrays
+   !!   mynode        : indentify the processor unit
+   !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
+   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
+   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
+   !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
+   !!   mpprecv       :
+   !!   mppsend       :   SUBROUTINE mpp_ini_znl
+   !!   mppscatter    :
+   !!   mppgather     :
+   !!   mpp_min       : generic interface for mppmin_int , mppmin_a_int , mppmin_real, mppmin_a_real
+   !!   mpp_max       : generic interface for mppmax_int , mppmax_a_int , mppmax_real, mppmax_a_real
+   !!   mpp_sum       : generic interface for mppsum_int , mppsum_a_int , mppsum_real, mppsum_a_real
+   !!   mpp_minloc    :
+   !!   mpp_maxloc    :
+   !!   mppsync       :
+   !!   mppstop       :
+   !!   mpp_ini_north : initialisation of north fold
+   !!   mpp_lbc_north : north fold processors gathering
+   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
+   !!   mpp_lbc_north_icb : variant of mpp_lbc_north for extra outer halo with icebergs
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE lbcnfd         ! north fold treatment
+   USE in_out_manager ! I/O manager
+   USE wrk_nemo       ! work arrays
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
+   PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
+   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
+   PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
+   PUBLIC   mpp_max_multiple
+   PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
+   PUBLIC   mpp_lnk_2d_9 , mpp_lnk_2d_multiple 
+   PUBLIC   mppscatter, mppgather
+   PUBLIC   mpp_ini_ice, mpp_ini_znl
+   PUBLIC   mppsize
+   PUBLIC   mppsend, mpprecv                          ! needed by TAM and ICB routines
+   PUBLIC   mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
+   PUBLIC   mpp_lbc_north_icb, mpp_lnk_2d_icb
+   PUBLIC   mpprank
+
+   TYPE arrayptr
+      REAL , DIMENSION (:,:),  POINTER :: pt2d
+   END TYPE arrayptr
+   PUBLIC   arrayptr
+   
+   !! * Interfaces
+   !! define generic interface for these routine as they are called sometimes
+   !! with scalar arguments instead of array arguments, which causes problems
+   !! for the compilation on AIX system as well as NEC and SGI. Ok on COMPACQ
+   INTERFACE mpp_min
+      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
+   END INTERFACE
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
+                       mppsum_realdd, mppsum_a_realdd
+   END INTERFACE
+   INTERFACE mpp_lbc_north
+      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d
+   END INTERFACE
+   INTERFACE mpp_minloc
+      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
+   END INTERFACE
+   INTERFACE mpp_maxloc
+      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
+   END INTERFACE
+
+   INTERFACE mpp_max_multiple
+      MODULE PROCEDURE mppmax_real_multiple
+   END INTERFACE
+
+   !! ========================= !!
+   !!  MPI  variable definition !!
+   !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
+   INCLUDE 'mpif.h'
+!$AGRIF_END_DO_NOT_TREAT
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
+
+   INTEGER, PARAMETER         ::   nprocmax = 2**10   ! maximun dimension (required to be a power of 2)
+
+   INTEGER ::   mppsize        ! number of process
+   INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
+!$AGRIF_DO_NOT_TREAT
+   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
+!$AGRIF_END_DO_NOT_TREAT
+
+   INTEGER :: MPI_SUMDD
+
+   ! variables used in case of sea-ice
+   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
+   INTEGER ::   ngrp_iworld     !  group ID for the world processors (for rheology)
+   INTEGER ::   ngrp_ice        !  group ID for the ice processors (for rheology)
+   INTEGER ::   ndim_rank_ice   !  number of 'ice' processors
+   INTEGER ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_ice     ! dimension ndim_rank_ice
+
+   ! variables used for zonal integration
+   INTEGER, PUBLIC ::   ncomm_znl       !: communicator made by the processors on the same zonal average
+   LOGICAL, PUBLIC ::   l_znl_root      ! True on the 'left'most processor on the same row
+   INTEGER ::   ngrp_znl        ! group ID for the znl processors
+   INTEGER ::   ndim_rank_znl   ! number of processors on the same zonal average
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_znl  ! dimension ndim_rank_znl, number of the procs into the same znl domain
+
+   ! North fold condition in mpp_mpi with jpni > 1 (PUBLIC for TAM)
+   INTEGER, PUBLIC ::   ngrp_world        ! group ID for the world processors
+   INTEGER, PUBLIC ::   ngrp_opa          ! group ID for the opa processors
+   INTEGER, PUBLIC ::   ngrp_north        ! group ID for the northern processors (to be fold)
+   INTEGER, PUBLIC ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
+   INTEGER, PUBLIC ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
+   INTEGER, PUBLIC ::   njmppmax          ! value of njmpp for the processors of the northern line
+   INTEGER, PUBLIC ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE, PUBLIC ::   nrank_north   ! dimension ndim_rank_north
+
+   ! Type of send : standard, buffered, immediate
+   CHARACTER(len=1), PUBLIC ::   cn_mpi_send   ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
+   LOGICAL, PUBLIC          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
+   INTEGER, PUBLIC          ::   nn_buffer     ! size of the buffer in case of mpi_bsend
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE :: tampon  ! buffer in case of bsend
+
+   LOGICAL, PUBLIC                                  ::   ln_nnogather       ! namelist control of northfold comms
+   LOGICAL, PUBLIC                                  ::   l_north_nogather = .FALSE.  ! internal control of northfold comms
+   INTEGER, PUBLIC                                  ::   ityp
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: lib_mpp.F90 8537 2017-09-19 05:46:09Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+
+   FUNCTION mynode( ldtxt, ldname, kumnam_ref , kumnam_cfg , kumond , kstop, localComm )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mynode  ***
+      !!
+      !! ** Purpose :   Find processor unit
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
+      CHARACTER(len=*)             , INTENT(in   ) ::   ldname
+      INTEGER                      , INTENT(in   ) ::   kumnam_ref     ! logical unit for reference namelist
+      INTEGER                      , INTENT(in   ) ::   kumnam_cfg     ! logical unit for configuration namelist
+      INTEGER                      , INTENT(inout) ::   kumond         ! logical unit for namelist output
+      INTEGER                      , INTENT(inout) ::   kstop          ! stop indicator
+      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
+      !
+      INTEGER ::   mynode, ierr, code, ji, ii, ios
+      LOGICAL ::   mpi_was_called
+      !
+      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, jpnij, ln_nnogather
+      !!----------------------------------------------------------------------
+      !
+      ii = 1
+      WRITE(ldtxt(ii),*)                                                                          ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                            ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '~~~~~~ '                                                                ;   ii = ii + 1
+      !
+
+      REWIND( kumnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
+      READ  ( kumnam_ref, nammpp, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
+
+      REWIND( kumnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
+      READ  ( kumnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
+
+      !                              ! control print
+      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                                     ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      mpi send type                      cn_mpi_send = ', cn_mpi_send   ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer     ;   ii = ii + 1
+
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+         jpni  = Agrif_Parent(jpni )
+         jpnj  = Agrif_Parent(jpnj )
+         jpnij = Agrif_Parent(jpnij)
+      ENDIF
+#endif
+
+      IF(jpnij < 1)THEN
+         ! If jpnij is not specified in namelist then we calculate it - this
+         ! means there will be no land cutting out.
+         jpnij = jpni * jpnj
+      END IF
+
+      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically'; ii = ii + 1
+      ELSE
+         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni; ii = ii + 1
+         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj; ii = ii + 1
+         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij; ii = ii +1
+      END IF
+
+      WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
+
+      CALL mpi_initialized ( mpi_was_called, code )
+      IF( code /= MPI_SUCCESS ) THEN
+         DO ji = 1, SIZE(ldtxt)
+            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+         END DO
+         WRITE(*, cform_err)
+         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
+         CALL mpi_abort( mpi_comm_world, code, ierr )
+      ENDIF
+
+      IF( mpi_was_called ) THEN
+         !
+         SELECT CASE ( cn_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            l_isend = .TRUE.
+         CASE DEFAULT
+            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            kstop = kstop + 1
+         END SELECT
+      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '                  ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                        ;   ii = ii + 1
+         kstop = kstop + 1
+      ELSE
+         SELECT CASE ( cn_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+            CALL mpi_init( ierr )
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            l_isend = .TRUE.
+            CALL mpi_init( ierr )
+         CASE DEFAULT
+            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            kstop = kstop + 1
+         END SELECT
+         !
+      ENDIF
+
+      IF( PRESENT(localComm) ) THEN
+         IF( Agrif_Root() ) THEN
+            mpi_comm_opa = localComm
+         ENDIF
+      ELSE
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
+         IF( code /= MPI_SUCCESS ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF
+
+#if defined key_agrif
+      IF (Agrif_Root()) THEN
+         CALL Agrif_MPI_Init(mpi_comm_opa)
+      ELSE
+         CALL Agrif_MPI_set_grid_comm(mpi_comm_opa)
+      ENDIF
+#endif
+
+      CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
+      CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
+      mynode = mpprank
+
+      IF( mynode == 0 ) THEN
+         CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
+         WRITE(kumond, nammpp)      
+      ENDIF
+      !
+      CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
+      !
+   END FUNCTION mynode
+
+   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+      
+      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
+         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING ptab is defined only between nld and nle
+         DO jk = 1, jpk
+            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+               ptab(nldi  :nlei  , jj          ,jk) = ptab(nldi:nlei,     nlej,jk)
+               ptab(1     :nldi-1, jj          ,jk) = ptab(nldi     ,     nlej,jk)
+               ptab(nlei+1:nlci  , jj          ,jk) = ptab(     nlei,     nlej,jk)
+            END DO
+            DO ji = nlci+1, jpi                 ! added column(s) (full)
+               ptab(ji           ,nldj  :nlej  ,jk) = ptab(     nlei,nldj:nlej,jk)
+               ptab(ji           ,1     :nldj-1,jk) = ptab(     nlei,nldj     ,jk)
+               ptab(ji           ,nlej+1:jpj   ,jk) = ptab(     nlei,     nlej,jk)
+            END DO
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment
+         !
+         !                                   ! East-West boundaries
+         !                                        !* Cyclic east-west
+         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            ptab( 1 ,:,:) = ptab(jpim1,:,:)
+            ptab(jpi,:,:) = ptab(  2  ,:,:)
+         ELSE                                     !* closed
+            IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+                                         ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+         ENDIF
+         !                                   ! North-South boundaries (always closed)
+         IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+                                      ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = zt3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
+      !
+   END SUBROUTINE mpp_lnk_3d
+
+   SUBROUTINE mpp_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields , cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_multiple  ***
+      !!
+      !! ** Purpose :   Message passing management for multiple 2d arrays
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+
+      INTEGER :: num_fields
+      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
+      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
+      !                                                               ! = T , U , V , F , W and I points
+      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
+      !                                                               ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL    , INTENT(in   ) ::   cd_mpp       ! fill the overlap area only
+      REAL(wp)        , OPTIONAL    , INTENT(in   ) ::   pval         ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2*num_fields), zt2sn(jpi,jprecj,2*num_fields),  &
+         &      zt2ew(jpj,jpreci,2*num_fields), zt2we(jpj,jpreci,2*num_fields)   )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      !First Array
+      DO ii = 1 , num_fields
+         IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+            !
+            ! WARNING pt2d is defined only between nld and nle
+            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+               pt2d_array(ii)%pt2d(nldi  :nlei  , jj) = pt2d_array(ii)%pt2d(nldi:nlei, nlej)
+               pt2d_array(ii)%pt2d(1     :nldi-1, jj) = pt2d_array(ii)%pt2d(nldi     , nlej)
+               pt2d_array(ii)%pt2d(nlei+1:nlci  , jj) = pt2d_array(ii)%pt2d(     nlei, nlej) 
+            END DO
+            DO ji = nlci+1, jpi                 ! added column(s) (full)
+               pt2d_array(ii)%pt2d(ji, nldj  :nlej  ) = pt2d_array(ii)%pt2d(nlei, nldj:nlej)
+               pt2d_array(ii)%pt2d(ji, 1     :nldj-1) = pt2d_array(ii)%pt2d(nlei, nldj     )
+               pt2d_array(ii)%pt2d(ji, nlej+1:jpj   ) = pt2d_array(ii)%pt2d(nlei,      nlej)
+            END DO
+            !
+         ELSE                              ! standard close or cyclic treatment
+            !
+            !                                   ! East-West boundaries
+            IF( nbondi == 2 .AND.   &                ! Cyclic east-west
+               &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+               pt2d_array(ii)%pt2d(  1  , : ) = pt2d_array(ii)%pt2d( jpim1, : )                                    ! west
+               pt2d_array(ii)%pt2d( jpi , : ) = pt2d_array(ii)%pt2d(   2  , : )                                    ! east
+            ELSE                                     ! closed
+               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(            1 : jpreci,:) = zland    ! south except F-point
+                                                   pt2d_array(ii)%pt2d(nlci-jpreci+1 : jpi   ,:) = zland    ! north
+            ENDIF
+            !                                   ! North-South boundaries (always closed)
+               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(:,             1:jprecj ) = zland    ! south except F-point
+                                                   pt2d_array(ii)%pt2d(:, nlcj-jprecj+1:jpj    ) = zland    ! north
+            !
+         ENDIF
+      END DO
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      DO ii = 1 , num_fields
+         SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               zt2ew( : , jl , ii ) = pt2d_array(ii)%pt2d( jpreci+jl , : )
+               zt2we( : , jl , ii ) = pt2d_array(ii)%pt2d( iihom +jl , : )
+            END DO
+         END SELECT
+      END DO
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+
+      DO ii = 1 , num_fields
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( jl , : ) = zt2we(:,jl,num_fields+ii)
+               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( jl , : )= zt2we(:,jl,num_fields+ii)
+            END DO
+         END SELECT
+      END DO
+      
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      !First Array
+      DO ii = 1 , num_fields
+         IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+            ijhom = nlcj-nrecj
+            DO jl = 1, jprecj
+               zt2sn(:,jl , ii) = pt2d_array(ii)%pt2d( : , ijhom +jl )
+               zt2ns(:,jl , ii) = pt2d_array(ii)%pt2d( : , jprecj+jl )
+            END DO
+         ENDIF
+      END DO
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+
+      DO ii = 1 , num_fields
+         !First Array
+         SELECT CASE ( nbondj )
+         CASE ( -1 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , ijhom+jl ) = zt2ns( : , jl , num_fields+ii )
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii)
+               pt2d_array(ii)%pt2d( : , ijhom + jl ) = zt2ns( : , jl , num_fields + ii )
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii )
+            END DO
+         END SELECT
+      END DO
+      
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+         !First Array
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   
+             DO ii = 1 , num_fields  
+                       CALL lbc_nfd      ( pt2d_array(ii)%pt2d( : , : ), type_array(ii) , psgn_array(ii) )   ! only 1 northern proc, no mpp
+             END DO
+         CASE DEFAULT   ;   CALL mpp_lbc_north_2d_multiple( pt2d_array, type_array, psgn_array, num_fields )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+        !
+      
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
+      !
+   END SUBROUTINE mpp_lnk_2d_multiple
+
+   
+   SUBROUTINE load_array(pt2d,cd_type,psgn,pt2d_array, type_array, psgn_array,num_fields)
+      !!---------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), TARGET   ,   INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
+      REAL(wp)                    , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
+      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array
+      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
+      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
+      INTEGER                      , INTENT (inout):: num_fields 
+      !!---------------------------------------------------------------------
+      num_fields=num_fields+1
+      pt2d_array(num_fields)%pt2d=>pt2d
+      type_array(num_fields)=cd_type
+      psgn_array(num_fields)=psgn
+   END SUBROUTINE load_array
+   
+   
+   SUBROUTINE mpp_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
+      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
+      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
+      !!---------------------------------------------------------------------
+      ! Second 2D array on which the boundary condition is applied
+      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA    
+      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
+      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI 
+      ! define the nature of ptab array grid-points
+      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
+      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
+      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
+      ! =-1 the sign change across the north fold boundary
+      REAL(wp)                                      , INTENT(in   ) ::   psgnA    
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI   
+      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array 
+      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
+      INTEGER :: num_fields
+      !!---------------------------------------------------------------------
+
+      num_fields = 0
+
+      !! Load the first array
+      CALL load_array(pt2dA,cd_typeA,psgnA,pt2d_array, type_array, psgn_array,num_fields)
+
+      !! Look if more arrays are added
+      IF(PRESENT (psgnB) )CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnC) )CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnD) )CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnE) )CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnF) )CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnG) )CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnH) )CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnI) )CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
+      
+      CALL mpp_lnk_2d_multiple(pt2d_array,type_array,psgn_array,num_fields,cd_mpp,pval)
+   END SUBROUTINE mpp_lnk_2d_9
+
+
+   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
+         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING pt2d is defined only between nld and nle
+         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+            pt2d(nldi  :nlei  , jj          ) = pt2d(nldi:nlei,     nlej)
+            pt2d(1     :nldi-1, jj          ) = pt2d(nldi     ,     nlej)
+            pt2d(nlei+1:nlci  , jj          ) = pt2d(     nlei,     nlej)
+         END DO
+         DO ji = nlci+1, jpi                 ! added column(s) (full)
+            pt2d(ji           ,nldj  :nlej  ) = pt2d(     nlei,nldj:nlej)
+            pt2d(ji           ,1     :nldj-1) = pt2d(     nlei,nldj     )
+            pt2d(ji           ,nlej+1:jpj   ) = pt2d(     nlei,     nlej)
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment
+         !
+         !                                   ! East-West boundaries
+         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
+            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
+            pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
+         ELSE                                     ! closed
+            IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
+                                         pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
+         ENDIF
+         !                                   ! North-South boundaries (always closed)
+            IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
+                                         pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            zt2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = zt2we(:,jl,2)
+            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = zt2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            zt2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = zt2sn(:,jl,2)
+            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = zt2sn(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
+      !
+   END SUBROUTINE mpp_lnk_2d
+
+
+   SUBROUTINE mpp_lnk_3d_gather( ptab1, cd_type1, ptab2, cd_type2, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d_gather  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for two 3D arrays
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1     ! first and second 3D array on which
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2     ! the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ns, zt4sn   ! 2 x 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ew, zt4we   ! 2 x 3d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+      ALLOCATE( zt4ns(jpi,jprecj,jpk,2,2), zt4sn(jpi,jprecj,jpk,2,2) ,    &
+         &      zt4ew(jpj,jpreci,jpk,2,2), zt4we(jpj,jpreci,jpk,2,2) )
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         ptab1( 1 ,:,:) = ptab1(jpim1,:,:)
+         ptab1(jpi,:,:) = ptab1(  2  ,:,:)
+         ptab2( 1 ,:,:) = ptab2(jpim1,:,:)
+         ptab2(jpi,:,:) = ptab2(  2  ,:,:)
+      ELSE                                        !* closed
+         IF( .NOT. cd_type1 == 'F' )   ptab1(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
+         IF( .NOT. cd_type2 == 'F' )   ptab2(     1       :jpreci,:,:) = 0.e0
+                                       ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
+                                       ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+      ENDIF
+
+
+      !                                      ! North-South boundaries
+      IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
+      IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
+                                    ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
+                                    ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+            zt4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+            zt4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+            zt4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk *2
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
+            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
+            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
+            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj - nrecj
+         DO jl = 1, jprecj
+            zt4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
+            zt4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
+            zt4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
+            zt4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk * 2
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
+            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab1(:,jl      ,:) = zt4sn(:,jl,:,1,2)
+            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
+            ptab2(:,jl      ,:) = zt4sn(:,jl,:,2,2)
+            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab1(:,jl,:) = zt4sn(:,jl,:,1,2)
+            ptab2(:,jl,:) = zt4sn(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )
+            CALL lbc_nfd      ( ptab1, cd_type1, psgn )   ! only for northern procs.
+            CALL lbc_nfd      ( ptab2, cd_type2, psgn )
+         CASE DEFAULT
+            CALL mpp_lbc_north( ptab1, cd_type1, psgn )   ! for all northern procs.
+            CALL mpp_lbc_north (ptab2, cd_type2, psgn)
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt4ns, zt4sn, zt4ew, zt4we )
+      !
+   END SUBROUTINE mpp_lnk_3d_gather
+
+
+   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_e  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    jpri   : number of rows for extra outer halo
+      !!                    jprj   : number of columns for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER                                             , INTENT(in   ) ::   jpri
+      INTEGER                                             , INTENT(in   ) ::   jprj
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      !                                                                                 ! = T , U , V , F , W and I points
+      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
+      !!                                                                                ! north boundary, =  1. otherwise
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
+      iprecj = jprecj + jprj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      !                                      !* North-South boundaries (always colsed)
+      IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0.e0    ! south except at F-point
+                                   pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0.e0    ! north
+
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         !
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
+                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
+      ENDIF
+      !
+
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
+         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
+         END SELECT
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci-jpri
+         DO jl = 1, ipreci
+            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*jprj)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj-jprj
+         DO jl = 1, iprecj
+            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
+            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*jpri )
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+         END DO
+      END SELECT
+
+   END SUBROUTINE mpp_lnk_2d_e
+
+
+   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsend  ***
+      !!
+      !! ** Purpose :   Send messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
+      INTEGER , INTENT(in   ) ::   kbytes     ! size of the array pmess
+      INTEGER , INTENT(in   ) ::   kdest      ! receive process number
+      INTEGER , INTENT(in   ) ::   ktyp       ! tag of the message
+      INTEGER , INTENT(in   ) ::   md_req     ! argument for isend
+      !!
+      INTEGER ::   iflag
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE ( cn_mpi_send )
+      CASE ( 'S' )                ! Standard mpi send (blocking)
+         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
+      CASE ( 'B' )                ! Buffer mpi send (blocking)
+         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
+      CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+         ! be carefull, one more argument here : the mpi request identifier..
+         CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa, md_req, iflag )
+      END SELECT
+      !
+   END SUBROUTINE mppsend
+
+
+   SUBROUTINE mpprecv( ktyp, pmess, kbytes, ksource )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpprecv  ***
+      !!
+      !! ** Purpose :   Receive messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
+      INTEGER , INTENT(in   ) ::   kbytes     ! suze of the array pmess
+      INTEGER , INTENT(in   ) ::   ktyp       ! Tag of the recevied message
+      INTEGER, OPTIONAL, INTENT(in) :: ksource    ! source process number
+      !!
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      INTEGER :: use_source
+      !!----------------------------------------------------------------------
+      !
+
+      ! If a specific process number has been passed to the receive call,
+      ! use that one. Default is to use mpi_any_source
+      use_source=mpi_any_source
+      if(present(ksource)) then
+         use_source=ksource
+      end if
+
+      CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_opa, istatus, iflag )
+      !
+   END SUBROUTINE mpprecv
+
+
+   SUBROUTINE mppgather( ptab, kp, pio )
+      !!----------------------------------------------------------------------
+      !!                   ***  routine mppgather  ***
+      !!
+      !! ** Purpose :   Transfert between a local subdomain array and a work
+      !!     array which is distributed following the vertical level.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj),       INTENT(in   ) ::   ptab   ! subdomain input array
+      INTEGER ,                           INTENT(in   ) ::   kp     ! record length
+      REAL(wp), DIMENSION(jpi,jpj,jpnij), INTENT(  out) ::   pio    ! subdomain input array
+      !!
+      INTEGER :: itaille, ierror   ! temporary integer
+      !!---------------------------------------------------------------------
+      !
+      itaille = jpi * jpj
+      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille     ,   &
+         &                            mpi_double_precision, kp , mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppgather
+
+
+   SUBROUTINE mppscatter( pio, kp, ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppscatter  ***
+      !!
+      !! ** Purpose :   Transfert between awork array which is distributed
+      !!      following the vertical level and the local subdomain array.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::  pio        ! output array
+      INTEGER                             ::   kp        ! Tag (not used with MPI
+      REAL(wp), DIMENSION(jpi,jpj)        ::  ptab       ! subdomain array input
+      !!
+      INTEGER :: itaille, ierror   ! temporary integer
+      !!---------------------------------------------------------------------
+      !
+      itaille=jpi*jpj
+      !
+      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
+         &                            mpi_double_precision, kp  , mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppscatter
+
+
+   SUBROUTINE mppmax_a_int( ktab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_a_int  ***
+      !!
+      !! ** Purpose :   Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim   ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   !
+      !!
+      INTEGER :: ierror, localcomm   ! temporary integer
+      INTEGER, DIMENSION(kdim) ::   iwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, localcomm, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppmax_a_int
+
+
+   SUBROUTINE mppmax_int( ktab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_int  ***
+      !!
+      !! ** Purpose :   Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout)           ::   ktab      ! ???
+      INTEGER, INTENT(in   ), OPTIONAL ::   kcom      ! ???
+      !!
+      INTEGER ::   ierror, iwork, localcomm   ! temporary integer
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror)
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppmax_int
+
+
+   SUBROUTINE mppmin_a_int( ktab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_a_int  ***
+      !!
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
+      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
+      !!
+      INTEGER ::   ierror, localcomm   ! temporary integer
+      INTEGER, DIMENSION(kdim) ::   iwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, localcomm, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppmin_a_int
+
+
+   SUBROUTINE mppmin_int( ktab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_int  ***
+      !!
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout) ::   ktab      ! ???
+      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
+      !!
+      INTEGER ::  ierror, iwork, localcomm
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+     CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppmin_int
+
+
+   SUBROUTINE mppsum_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_int  ***
+      !!
+      !! ** Purpose :   Global integer sum, 1D array case
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   )                   ::   kdim      ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
+      !!
+      INTEGER :: ierror
+      INTEGER, DIMENSION (kdim) ::  iwork
+      !!----------------------------------------------------------------------
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppsum_a_int
+
+
+   SUBROUTINE mppsum_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppsum_int  ***
+      !!
+      !! ** Purpose :   Global integer sum
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout) ::   ktab
+      !!
+      INTEGER :: ierror, iwork
+      !!----------------------------------------------------------------------
+      !
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppsum_int
+
+
+   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppmax_a_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim
+      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
+      !!
+      INTEGER :: ierror, localcomm
+      REAL(wp), DIMENSION(kdim) ::  zwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppmax_a_real
+
+
+   SUBROUTINE mppmax_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab   ! ???
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmax_real_multiple( ptab, NUM , kcom  )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:) ,  INTENT(inout)           ::   ptab   ! ???
+      INTEGER , INTENT(in   )           ::   NUM
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) , POINTER , DIMENSION(:) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc(NUM , zwork)
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, NUM, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab = zwork
+      CALL wrk_dealloc(NUM , zwork)
+      !
+   END SUBROUTINE mppmax_real_multiple
+
+
+   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppmin_a_real  ***
+      !!
+      !! ** Purpose :   Minimum of REAL, array case
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim
+      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
+      !!
+      INTEGER :: ierror, localcomm
+      REAL(wp), DIMENSION(kdim) ::   zwork
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppmin_a_real
+
+
+   SUBROUTINE mppmin_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_real  ***
+      !!
+      !! ** Purpose :   minimum of REAL, scalar case
+      !!
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab        !
+      INTEGER , INTENT(in   ), OPTIONAL :: kcom
+      !!
+      INTEGER  ::   ierror
+      REAL(wp) ::   zwork
+      INTEGER :: localcomm
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppmin_real
+
+
+   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_real  ***
+      !!
+      !! ** Purpose :   global sum, REAL ARRAY argument case
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
+      REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
+      INTEGER , INTENT( in ), OPTIONAL           :: kcom
+      !!
+      INTEGER                   ::   ierror    ! temporary integer
+      INTEGER                   ::   localcomm
+      REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppsum_a_real
+
+
+   SUBROUTINE mppsum_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_real  ***
+      !!
+      !! ** Purpose :   global sum, SCALAR argument case
+      !!
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab   ! input scalar
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) ::   zwork
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppsum_real
+
+   SUBROUTINE mppsum_realdd( ytab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_realdd ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                SCALAR argument case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER  ::    ierror
+      INTEGER  ::   localcomm
+      COMPLEX(wp) :: zwork
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      ! reduce local sums into global sum
+      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab = zwork
+
+   END SUBROUTINE mppsum_realdd
+
+
+   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_realdd  ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                COMPLEX ARRAY case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER                      :: ierror    ! temporary integer
+      INTEGER                      ::   localcomm
+      COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab(:) = zwork(:)
+
+   END SUBROUTINE mppsum_a_realdd
+
+   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_minloc  ***
+      !!
+      !! ** Purpose :   Compute the global minimum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab    ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask   ! Local mask
+      REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
+      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
+      !!
+      INTEGER , DIMENSION(2)   ::   ilocs
+      INTEGER :: ierror
+      REAL(wp) ::   zmin   ! local minimum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1.e0 )
+      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      !
+      zain(1,:)=zmin
+      zain(2,:)=ki+10000.*kj
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
+      !
+      pmin = zaout(1,1)
+      kj = INT(zaout(2,1)/10000.)
+      ki = INT(zaout(2,1) - 10000.*kj )
+      !
+   END SUBROUTINE mpp_minloc2d
+
+
+   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj ,kk)
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_minloc  ***
+      !!
+      !! ** Purpose :   Compute the global minimum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                         , INTENT(  out) ::   pmin         ! Global minimum of ptab
+      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
+      !!
+      INTEGER  ::   ierror
+      REAL(wp) ::   zmin     ! local minimum
+      INTEGER , DIMENSION(3)   ::   ilocs
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
+      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      kk = ilocs(3)
+      !
+      zain(1,:)=zmin
+      zain(2,:)=ki+10000.*kj+100000000.*kk
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
+      !
+      pmin = zaout(1,1)
+      kk   = INT( zaout(2,1) / 100000000. )
+      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
+      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
+      !
+   END SUBROUTINE mpp_minloc3d
+
+
+   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_maxloc  ***
+      !!
+      !! ** Purpose :   Compute the global maximum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab     ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask    ! Local mask
+      REAL(wp)                     , INTENT(  out) ::   pmax     ! Global maximum of ptab
+      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of maximum in global frame
+      !!
+      INTEGER  :: ierror
+      INTEGER, DIMENSION (2)   ::   ilocs
+      REAL(wp) :: zmax   ! local maximum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1.e0 )
+      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      !
+      zain(1,:) = zmax
+      zain(2,:) = ki + 10000. * kj
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
+      !
+      pmax = zaout(1,1)
+      kj   = INT( zaout(2,1) / 10000.     )
+      ki   = INT( zaout(2,1) - 10000.* kj )
+      !
+   END SUBROUTINE mpp_maxloc2d
+
+
+   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_maxloc  ***
+      !!
+      !! ** Purpose :  Compute the global maximum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method : Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                         , INTENT(  out) ::   pmax         ! Global maximum of ptab
+      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
+      !!
+      REAL(wp) :: zmax   ! local maximum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      INTEGER , DIMENSION(3)   ::   ilocs
+      INTEGER :: ierror
+      !!-----------------------------------------------------------------------
+      !
+      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
+      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      kk = ilocs(3)
+      !
+      zain(1,:)=zmax
+      zain(2,:)=ki+10000.*kj+100000000.*kk
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
+      !
+      pmax = zaout(1,1)
+      kk   = INT( zaout(2,1) / 100000000. )
+      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
+      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
+      !
+   END SUBROUTINE mpp_maxloc3d
+
+
+   SUBROUTINE mppsync()
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsync  ***
+      !!
+      !! ** Purpose :   Massively parallel processors, synchroneous
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER :: ierror
+      !!-----------------------------------------------------------------------
+      !
+      CALL mpi_barrier( mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppsync
+
+
+   SUBROUTINE mppstop
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppstop  ***
+      !!
+      !! ** purpose :   Stop massively parallel processors method
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ::   info
+      !!----------------------------------------------------------------------
+      !
+      CALL mppsync
+      CALL mpi_finalize( info )
+      !
+   END SUBROUTINE mppstop
+
+
+   SUBROUTINE mpp_comm_free( kcom )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kcom
+      !!
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
+      !
+      CALL MPI_COMM_FREE(kcom, ierr)
+      !
+   END SUBROUTINE mpp_comm_free
+
+
+   SUBROUTINE mpp_ini_ice( pindic, kumout )
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_ice  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for ice areas
+      !!      condition together with global variables needed in the ddmpp folding
+      !!
+      !! ** Method  : - Look for ice processors in ice routines
+      !!              - Put their number in nrank_ice
+      !!              - Create groups for the world processors and the ice processors
+      !!              - Create a communicator for ice processors
+      !!
+      !! ** output
+      !!      njmppmax = njmpp for northern procs
+      !!      ndim_rank_ice = number of processors with ice
+      !!      nrank_ice (ndim_rank_ice) = ice processors
+      !!      ngrp_iworld = group ID for the world processors
+      !!      ngrp_ice = group ID for the ice processors
+      !!      ncomm_ice = communicator for the ice procs.
+      !!      n_ice_root = number (in the world) of proc 0 in the ice comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   pindic
+      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical unit
+      !!
+      INTEGER :: jjproc
+      INTEGER :: ii, ierr
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kice
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      ! Since this is just an init routine and these arrays are of length jpnij
+      ! then don't use wrk_nemo module - just allocate and deallocate.
+      ALLOCATE( kice(jpnij), zwork(jpnij), STAT=ierr )
+      IF( ierr /= 0 ) THEN
+         WRITE(kumout, cform_err)
+         WRITE(kumout,*) 'mpp_ini_ice : failed to allocate 2, 1D arrays (jpnij in length)'
+         CALL mppstop
+      ENDIF
+
+      ! Look for how many procs with sea-ice
+      !
+      kice = 0
+      DO jjproc = 1, jpnij
+         IF( jjproc == narea .AND. pindic .GT. 0 )   kice(jjproc) = 1
+      END DO
+      !
+      zwork = 0
+      CALL MPI_ALLREDUCE( kice, zwork, jpnij, mpi_integer, mpi_sum, mpi_comm_opa, ierr )
+      ndim_rank_ice = SUM( zwork )
+
+      ! Allocate the right size to nrank_north
+      IF( ALLOCATED ( nrank_ice ) )   DEALLOCATE( nrank_ice )
+      ALLOCATE( nrank_ice(ndim_rank_ice) )
+      !
+      ii = 0
+      nrank_ice = 0
+      DO jjproc = 1, jpnij
+         IF( zwork(jjproc) == 1) THEN
+            ii = ii + 1
+            nrank_ice(ii) = jjproc -1
+         ENDIF
+      END DO
+
+      ! Create the world group
+      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_iworld, ierr )
+
+      ! Create the ice group from the world group
+      CALL MPI_GROUP_INCL( ngrp_iworld, ndim_rank_ice, nrank_ice, ngrp_ice, ierr )
+
+      ! Create the ice communicator , ie the pool of procs with sea-ice
+      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_ice, ncomm_ice, ierr )
+
+      ! Find proc number in the world of proc 0 in the north
+      ! The following line seems to be useless, we just comment & keep it as reminder
+      ! CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_ice,1,0,ngrp_iworld,n_ice_root,ierr)
+      !
+      CALL MPI_GROUP_FREE(ngrp_ice, ierr)
+      CALL MPI_GROUP_FREE(ngrp_iworld, ierr)
+
+      DEALLOCATE(kice, zwork)
+      !
+   END SUBROUTINE mpp_ini_ice
+
+
+   SUBROUTINE mpp_ini_znl( kumout )
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_znl  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for computing zonal sum
+      !!
+      !! ** Method  : - Look for processors in the same row
+      !!              - Put their number in nrank_znl
+      !!              - Create group for the znl processors
+      !!              - Create a communicator for znl processors
+      !!              - Determine if processor should write znl files
+      !!
+      !! ** output
+      !!      ndim_rank_znl = number of processors on the same row
+      !!      ngrp_znl = group ID for the znl processors
+      !!      ncomm_znl = communicator for the ice procs.
+      !!      n_znl_root = number (in the world) of proc 0 in the ice comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical units
+      !
+      INTEGER :: jproc      ! dummy loop integer
+      INTEGER :: ierr, ii   ! local integer
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kwork
+      !!----------------------------------------------------------------------
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_world     : ', ngrp_world
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_world : ', mpi_comm_world
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_opa   : ', mpi_comm_opa
+      !
+      ALLOCATE( kwork(jpnij), STAT=ierr )
+      IF( ierr /= 0 ) THEN
+         WRITE(kumout, cform_err)
+         WRITE(kumout,*) 'mpp_ini_znl : failed to allocate 1D array of length jpnij'
+         CALL mppstop
+      ENDIF
+
+      IF( jpnj == 1 ) THEN
+         ngrp_znl  = ngrp_world
+         ncomm_znl = mpi_comm_opa
+      ELSE
+         !
+         CALL MPI_ALLGATHER ( njmpp, 1, mpi_integer, kwork, 1, mpi_integer, mpi_comm_opa, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - kwork pour njmpp : ', kwork
+         !-$$        CALL flush(numout)
+         !
+         ! Count number of processors on the same row
+         ndim_rank_znl = 0
+         DO jproc=1,jpnij
+            IF ( kwork(jproc) == njmpp ) THEN
+               ndim_rank_znl = ndim_rank_znl + 1
+            ENDIF
+         END DO
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ndim_rank_znl : ', ndim_rank_znl
+         !-$$        CALL flush(numout)
+         ! Allocate the right size to nrank_znl
+         IF (ALLOCATED (nrank_znl)) DEALLOCATE(nrank_znl)
+         ALLOCATE(nrank_znl(ndim_rank_znl))
+         ii = 0
+         nrank_znl (:) = 0
+         DO jproc=1,jpnij
+            IF ( kwork(jproc) == njmpp) THEN
+               ii = ii + 1
+               nrank_znl(ii) = jproc -1
+            ENDIF
+         END DO
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - nrank_znl : ', nrank_znl
+         !-$$        CALL flush(numout)
+
+         ! Create the opa group
+         CALL MPI_COMM_GROUP(mpi_comm_opa,ngrp_opa,ierr)
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_opa : ', ngrp_opa
+         !-$$        CALL flush(numout)
+
+         ! Create the znl group from the opa group
+         CALL MPI_GROUP_INCL  ( ngrp_opa, ndim_rank_znl, nrank_znl, ngrp_znl, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_znl ', ngrp_znl
+         !-$$        CALL flush(numout)
+
+         ! Create the znl communicator from the opa communicator, ie the pool of procs in the same row
+         CALL MPI_COMM_CREATE ( mpi_comm_opa, ngrp_znl, ncomm_znl, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ncomm_znl ', ncomm_znl
+         !-$$        CALL flush(numout)
+         !
+      END IF
+
+      ! Determines if processor if the first (starting from i=1) on the row
+      IF ( jpni == 1 ) THEN
+         l_znl_root = .TRUE.
+      ELSE
+         l_znl_root = .FALSE.
+         kwork (1) = nimpp
+         CALL mpp_min ( kwork(1), kcom = ncomm_znl)
+         IF ( nimpp == kwork(1)) l_znl_root = .TRUE.
+      END IF
+
+      DEALLOCATE(kwork)
+
+   END SUBROUTINE mpp_ini_znl
+
+
+   SUBROUTINE mpp_ini_north
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_north  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for north folding
+      !!      condition together with global variables needed in the mpp folding
+      !!
+      !! ** Method  : - Look for northern processors
+      !!              - Put their number in nrank_north
+      !!              - Create groups for the world processors and the north processors
+      !!              - Create a communicator for northern processors
+      !!
+      !! ** output
+      !!      njmppmax = njmpp for northern procs
+      !!      ndim_rank_north = number of processors in the northern line
+      !!      nrank_north (ndim_rank_north) = number  of the northern procs.
+      !!      ngrp_world = group ID for the world processors
+      !!      ngrp_north = group ID for the northern processors
+      !!      ncomm_north = communicator for the northern procs.
+      !!      north_root = number (in the world) of proc 0 in the northern comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ::   ierr
+      INTEGER ::   jjproc
+      INTEGER ::   ii, ji
+      !!----------------------------------------------------------------------
+      !
+      njmppmax = MAXVAL( njmppt )
+      !
+      ! Look for how many procs on the northern boundary
+      ndim_rank_north = 0
+      DO jjproc = 1, jpnij
+         IF( njmppt(jjproc) == njmppmax )   ndim_rank_north = ndim_rank_north + 1
+      END DO
+      !
+      ! Allocate the right size to nrank_north
+      IF (ALLOCATED (nrank_north)) DEALLOCATE(nrank_north)
+      ALLOCATE( nrank_north(ndim_rank_north) )
+
+      ! Fill the nrank_north array with proc. number of northern procs.
+      ! Note : the rank start at 0 in MPI
+      ii = 0
+      DO ji = 1, jpnij
+         IF ( njmppt(ji) == njmppmax   ) THEN
+            ii=ii+1
+            nrank_north(ii)=ji-1
+         END IF
+      END DO
+      !
+      ! create the world group
+      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
+      !
+      ! Create the North group from the world group
+      CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_north, nrank_north, ngrp_north, ierr )
+      !
+      ! Create the North communicator , ie the pool of procs in the north group
+      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_north, ncomm_north, ierr )
+      !
+   END SUBROUTINE mpp_ini_north
+
+
+   SUBROUTINE mpp_lbc_north_3d( pt3d, cd_type, psgn )
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_3d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the b.c. is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      !                                                              !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr, jk
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)          ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                                ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
+
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk), zfoldwk(jpi,4,jpk), znorthgloio(jpi,4,jpk,jpni) )
+      ALLOCATE( ztabl(jpi,4,jpk), ztabr(jpi*jpmaxngh, 4, jpk) ) 
+
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      znorthloc(:,:,:) = 0
+      DO jk = 1, jpk
+         DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
+            ij = jj - nlcj + ijpj
+            znorthloc(:,ij,jk) = pt3d(:,jj,jk)
+         END DO
+      END DO
+      !
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * jpk * ijpj
+
+      IF ( l_north_nogather ) THEN
+         !
+        ztabr(:,:,:) = 0
+        ztabl(:,:,:) = 0
+
+        DO jk = 1, jpk
+           DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+              ij = jj - nlcj + ijpj
+              DO ji = nfsloop, nfeloop
+                 ztabl(ji,ij,jk) = pt3d(ji,jj,jk)
+              END DO
+           END DO
+        END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
+              DO jk = 1, jpk
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)
+                    END DO
+                 END DO
+              END DO
+           ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jk = 1, jpk
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = pt3d(ji,nlcj-ijpj+jj,jk)
+                    END DO
+                 END DO
+              END DO
+           ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF    
+            END DO
+         ENDIF
+         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
+         DO jk = 1, jpk
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
+               ij = jj - nlcj + ijpj
+               DO ji= 1, nlci
+                  pt3d(ji,jj,jk) = ztabl(ji,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+
+      ELSE
+         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
+            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:,:) = 0.e0
+         DO jr = 1, ndim_rank_north         ! recover the global north array
+            iproc = nrank_north(jr) + 1
+            ildi  = nldit (iproc)
+            ilei  = nleit (iproc)
+            iilb  = nimppt(iproc)
+            DO jk = 1, jpk
+               DO jj = 1, ijpj
+                  DO ji = ildi, ilei
+                    ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                  END DO
+               END DO
+            END DO
+         END DO
+         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jk = 1, jpk
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
+               ij = jj - nlcj + ijpj
+               DO ji= 1, nlci
+                  pt3d(ji,jj,jk) = ztab(ji+nimpp-1,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+      ! The ztab array has been either:
+      !  a. Fully populated by the mpi_allgather operation or
+      !  b. Had the active points for this domain and northern neighbours populated
+      !     by peer to peer exchanges
+      ! Either way the array may be folded by lbc_nfd and the result for the span of
+      ! this domain will be identical.
+      !
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr ) 
+      !
+   END SUBROUTINE mpp_lbc_north_3d
+
+
+   SUBROUTINE mpp_lbc_north_2d( pt2d, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the b.c. is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
+      !                                                          !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztabl, ztabr
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4), znorthloc(jpi,4), zfoldwk(jpi,4), znorthgloio(jpi,4,jpni) )
+      ALLOCATE( ztabl(jpi,4), ztabr(jpi*jpmaxngh, 4) ) 
+      !
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
+         ij = jj - nlcj + ijpj
+         znorthloc(:,ij) = pt2d(:,jj)
+      END DO
+
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * ijpj
+      IF ( l_north_nogather ) THEN
+         !
+         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
+         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
+         !
+         ztabr(:,:) = 0
+         ztabl(:,:) = 0
+
+         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+            ij = jj - nlcj + ijpj
+              DO ji = nfsloop, nfeloop
+               ztabl(ji,ij) = pt2d(ji,jj)
+            END DO
+         END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+               CALL mppsend(5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr))
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
+              DO jj = 1, ijpj
+                 DO ji = ildi, ilei
+                    ztabr(iilb+ji,jj) = zfoldwk(ji,jj)
+                 END DO
+              END DO
+            ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jj = 1, ijpj
+                 DO ji = ildi, ilei
+                    ztabr(iilb+ji,jj) = pt2d(ji,nlcj-ijpj+jj)
+                 END DO
+              END DO
+            ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF
+            END DO
+         ENDIF
+         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+            ij = jj - nlcj + ijpj
+            DO ji = 1, nlci
+               pt2d(ji,jj) = ztabl(ji,ij)
+            END DO
+         END DO
+         !
+      ELSE
+         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,        &
+            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:) = 0.e0
+         DO jr = 1, ndim_rank_north            ! recover the global north array
+            iproc = nrank_north(jr) + 1
+            ildi = nldit (iproc)
+            ilei = nleit (iproc)
+            iilb = nimppt(iproc)
+            DO jj = 1, ijpj
+               DO ji = ildi, ilei
+                  ztab(ji+iilb-1,jj) = znorthgloio(ji,jj,jr)
+               END DO
+            END DO
+         END DO
+         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+            ij = jj - nlcj + ijpj
+            DO ji = 1, nlci
+               pt2d(ji,jj) = ztab(ji+nimpp-1,ij)
+            END DO
+         END DO
+         !
+      ENDIF
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr ) 
+      !
+   END SUBROUTINE mpp_lbc_north_2d
+
+   SUBROUTINE mpp_lbc_north_2d_multiple( pt2d_array, cd_type, psgn, num_fields)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1
+      !!              (for multiple 2d arrays )
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ,  INTENT (in   ) ::   num_fields  ! number of variables contained in pt2d
+      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
+      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
+      !                                                          !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr, jk
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4,num_fields), znorthloc(jpi,4,num_fields), zfoldwk(jpi,4,num_fields),   & 
+            &   znorthgloio(jpi,4,num_fields,jpni) )   ! expanded to 3 dimensions
+      ALLOCATE( ztabl(jpi,4,num_fields), ztabr(jpi*jpmaxngh, 4,num_fields) )
+      !
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      
+      DO jk = 1, num_fields
+         DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d (for every variable)
+            ij = jj - nlcj + ijpj
+            znorthloc(:,ij,jk) = pt2d_array(jk)%pt2d(:,jj)
+         END DO
+      END DO
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * ijpj
+                                                                  
+      IF ( l_north_nogather ) THEN
+         !
+         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
+         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
+         !
+         ztabr(:,:,:) = 0
+         ztabl(:,:,:) = 0
+
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+               ij = jj - nlcj + ijpj
+               DO ji = nfsloop, nfeloop
+                  ztabl(ji,ij,jk) = pt2d_array(jk)%pt2d(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+               CALL mppsend(5, znorthloc, itaille*num_fields, nfipproc(isendto(jr),jpnj), ml_req_nf(jr)) ! Buffer expanded "num_fields" times
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille*num_fields, iproc) ! Buffer expanded "num_fields" times
+              DO jk = 1 , num_fields
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)       ! Modified to 3D
+                    END DO
+                 END DO
+              END DO
+            ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jk = 1, num_fields
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                          ztabr(iilb+ji,jj,jk) = pt2d_array(jk)%pt2d(ji,nlcj-ijpj+jj)       ! Modified to 3D
+                    END DO
+                 END DO
+              END DO
+            ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF
+            END DO
+         ENDIF
+         !
+         DO ji = 1, num_fields     ! Loop to manage 3D variables
+            CALL mpp_lbc_nfd( ztabl(:,:,ji), ztabr(:,:,ji), cd_type(ji), psgn(ji) )  ! North fold boundary condition
+         END DO
+         !
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+               ij = jj - nlcj + ijpj
+               DO ji = 1, nlci
+                  pt2d_array(jk)%pt2d(ji,jj) = ztabl(ji,ij,jk)       ! Modified to 3D
+               END DO
+            END DO
+         END DO
+         
+         !
+      ELSE
+         !
+         CALL MPI_ALLGATHER( znorthloc  , itaille*num_fields, MPI_DOUBLE_PRECISION,        &
+            &                znorthgloio, itaille*num_fields, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:,:) = 0.e0
+         DO jk = 1, num_fields
+            DO jr = 1, ndim_rank_north            ! recover the global north array
+               iproc = nrank_north(jr) + 1
+               ildi = nldit (iproc)
+               ilei = nleit (iproc)
+               iilb = nimppt(iproc)
+               DO jj = 1, ijpj
+                  DO ji = ildi, ilei
+                     ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                  END DO
+               END DO
+            END DO
+         END DO
+         
+         DO ji = 1, num_fields
+            CALL lbc_nfd( ztab(:,:,ji), cd_type(ji), psgn(ji) )   ! North fold boundary condition
+         END DO
+         !
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+               ij = jj - nlcj + ijpj
+               DO ji = 1, nlci
+                  pt2d_array(jk)%pt2d(ji,jj) = ztab(ji+nimpp-1,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+         !
+      ENDIF
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr )
+      !
+   END SUBROUTINE mpp_lbc_north_2d_multiple
+
+   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              processor and apply lbc north-fold on this sub array.
+      !!              Then we scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                                                         !   = T ,  U , V , F or W -points
+      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
+      !!                                                                                        ! north fold, =  1. otherwise
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ij, iproc
+      !
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
+
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab_e(jpiglo,4+2*jpr2dj), znorthloc_e(jpi,4+2*jpr2dj), znorthgloio_e(jpi,4+2*jpr2dj,jpni) )
+
+      !
+      ijpj=4
+      ztab_e(:,:) = 0.e0
+
+      ij=0
+      ! put in znorthloc_e the last 4 jlines of pt2d
+      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
+         ij = ij + 1
+         DO ji = 1, jpi
+            znorthloc_e(ji,ij)=pt2d(ji,jj)
+         END DO
+      END DO
+      !
+      itaille = jpi * ( ijpj + 2 * jpr2dj )
+      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
+         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1, ijpj+2*jpr2dj
+            DO ji = ildi, ilei
+               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
+
+      ij = jpr2dj
+      !! Scatter back to pt2d
+      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
+      ij  = ij +1
+         DO ji= 1, nlci
+            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+         END DO
+      END DO
+      !
+      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
+      !
+   END SUBROUTINE mpp_lbc_north_e
+
+      SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_bdy_3d  ***
+      !!
+      !! ** Purpose :   Message passing management
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi_bdy : mark for "east-west local boundary"
+      !!                    nbondj_bdy : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland                      ! local scalar
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+      !!----------------------------------------------------------------------
+      
+      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
+         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
+
+      zland = 0.e0
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      
+      !                                   ! East-West boundaries
+      !                                        !* Cyclic east-west
+
+      IF( nbondi == 2) THEN
+        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+          ptab( 1 ,:,:) = ptab(jpim1,:,:)
+          ptab(jpi,:,:) = ptab(  2  ,:,:)
+        ELSE
+          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+          ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+        ENDIF
+      ELSEIF(nbondi == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+      ELSEIF(nbondi == 1) THEN
+        ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+      ENDIF                                     !* closed
+
+      IF (nbondj == 2 .OR. nbondj == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
+        ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+      ENDIF
+      
+      !
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+      CASE ( 0 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+      CASE ( 1 )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+      CASE ( 0 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+      CASE ( 1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = zt3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
+      !
+   END SUBROUTINE mpp_lnk_bdy_3d
+
+
+   SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_bdy_2d  ***
+      !!
+      !! ** Purpose :   Message passing management
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi_bdy : mark for "east-west local boundary"
+      !!                    nbondj_bdy : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      INTEGER                     , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
+      INTEGER  ::   ji, jj, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
+         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
+
+      zland = 0._wp
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      
+      !                                   ! East-West boundaries
+      !                                        !* Cyclic east-west
+
+      IF( nbondi == 2) THEN
+        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+          ptab( 1 ,:) = ptab(jpim1,:)
+          ptab(jpi,:) = ptab(  2  ,:)
+        ELSE
+          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
+          ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+        ENDIF
+      ELSEIF(nbondi == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
+      ELSEIF(nbondi == 1) THEN
+        ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+      ENDIF                                     !* closed
+
+      IF (nbondj == 2 .OR. nbondj == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj) = zland       ! south except F-point
+      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
+        ptab(:,nlcj-jprecj+1:jpj) = zland       ! north
+      ENDIF
+      
+      !
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt2ew(:,jl,1) = ptab(jpreci+jl,:)
+            zt2we(:,jl,1) = ptab(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+      CASE ( 0 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+      CASE ( 1 )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:) = zt2we(:,jl,2)
+            ptab(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:) = zt2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt2sn(:,jl,1) = ptab(:,ijhom +jl)
+            zt2ns(:,jl,1) = ptab(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+      CASE ( 0 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+      CASE ( 1 )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ) = zt2sn(:,jl,2)
+            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl) = zt2sn(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we  )
+      !
+   END SUBROUTINE mpp_lnk_bdy_2d
+
+   SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_init.opa  ***
+      !!
+      !! ** Purpose :: export and attach a MPI buffer for bsend
+      !!
+      !! ** Method  :: define buffer size in namelist, if 0 no buffer attachment
+      !!            but classical mpi_init
+      !!
+      !! History :: 01/11 :: IDRIS initial version for IBM only
+      !!            08/04 :: R. Benshila, generalisation
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
+      INTEGER                      , INTENT(inout) ::   ksft
+      INTEGER                      , INTENT(  out) ::   code
+      INTEGER                                      ::   ierr, ji
+      LOGICAL                                      ::   mpi_was_called
+      !!---------------------------------------------------------------------
+      !
+      CALL mpi_initialized( mpi_was_called, code )      ! MPI initialization
+      IF ( code /= MPI_SUCCESS ) THEN
+         DO ji = 1, SIZE(ldtxt)
+            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+         END DO
+         WRITE(*, cform_err)
+         WRITE(*, *) ' lib_mpp: Error in routine mpi_initialized'
+         CALL mpi_abort( mpi_comm_world, code, ierr )
+      ENDIF
+      !
+      IF( .NOT. mpi_was_called ) THEN
+         CALL mpi_init( code )
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code )
+         IF ( code /= MPI_SUCCESS ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF
+      !
+      IF( nn_buffer > 0 ) THEN
+         WRITE(ldtxt(ksft),*) 'mpi_bsend, buffer allocation of  : ', nn_buffer   ;   ksft = ksft + 1
+         ! Buffer allocation and attachment
+         ALLOCATE( tampon(nn_buffer), stat = ierr )
+         IF( ierr /= 0 ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in ALLOCATE', ierr
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         END IF
+         CALL mpi_buffer_attach( tampon, nn_buffer, code )
+      ENDIF
+      !
+   END SUBROUTINE mpi_init_opa
+
+   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
+      !!---------------------------------------------------------------------
+      !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
+      !!
+      !!   Modification of original codes written by David H. Bailey
+      !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)                         :: ilen, itype
+      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
+      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
+      !
+      REAL(wp) :: zerr, zt1, zt2    ! local work variables
+      INTEGER :: ji, ztmp           ! local scalar
+
+      ztmp = itype   ! avoid compilation warning
+
+      DO ji=1,ilen
+      ! Compute ydda + yddb using Knuth's trick.
+         zt1  = real(ydda(ji)) + real(yddb(ji))
+         zerr = zt1 - real(ydda(ji))
+         zt2  = ((real(yddb(ji)) - zerr) + (real(ydda(ji)) - (zt1 - zerr))) &
+                + aimag(ydda(ji)) + aimag(yddb(ji))
+
+         ! The result is zt1 + zt2, after normalization.
+         yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
+      END DO
+
+   END SUBROUTINE DDPDD_MPI
+
+   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_icb  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              processor and apply lbc north-fold on this sub array.
+      !!              Then we scatter the north fold array back to the processors.
+      !!              This version accounts for an extra halo with icebergs.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                     !   = T ,  U , V , F or W -points
+      REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
+      !!                                                    ! north fold, =  1. otherwise
+      INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ij, iproc, ipr2dj
+      !
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
+
+      !!----------------------------------------------------------------------
+      !
+      ijpj=4
+      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
+         ipr2dj = pr2dj
+      ELSE
+         ipr2dj = 0
+      ENDIF
+      ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
+
+      !
+      ztab_e(:,:) = 0.e0
+
+      ij=0
+      ! put in znorthloc_e the last 4 jlines of pt2d
+      DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
+         ij = ij + 1
+         DO ji = 1, jpi
+            znorthloc_e(ji,ij)=pt2d(ji,jj)
+         END DO
+      END DO
+      !
+      itaille = jpi * ( ijpj + 2 * ipr2dj )
+      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
+         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1, ijpj+2*ipr2dj
+            DO ji = ildi, ilei
+               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = ipr2dj )
+
+      ij = ipr2dj
+      !! Scatter back to pt2d
+      DO jj = nlcj - ijpj + 1 , nlcj +ipr2dj
+      ij  = ij +1
+         DO ji= 1, nlci
+            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+         END DO
+      END DO
+      !
+      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
+      !
+   END SUBROUTINE mpp_lbc_north_icb
+
+   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_icb  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array (with extra halo and icebergs)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    jpri   : number of rows for extra outer halo
+      !!                    jprj   : number of columns for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER                                             , INTENT(in   ) ::   jpri
+      INTEGER                                             , INTENT(in   ) ::   jprj
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      !                                                                                 ! = T , U , V , F , W and I points
+      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
+      !!                                                                                ! north boundary, =  1. otherwise
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
+      iprecj = jprecj + jprj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         !
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
+                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
+      ENDIF
+      !
+
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
+         CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+jprj)  , cd_type, psgn , pr2dj=jprj  )
+         END SELECT
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci-jpri
+         DO jl = 1, ipreci
+            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*jprj)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj-jprj
+         DO jl = 1, iprecj
+            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
+            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*jpri )
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+         END DO
+      END SELECT
+
+   END SUBROUTINE mpp_lnk_2d_icb
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case:            Dummy module        share memory computing
+   !!----------------------------------------------------------------------
+   USE in_out_manager
+
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i, mppsum_realdd, mppsum_a_realdd
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
+   END INTERFACE
+   INTERFACE mpp_min
+      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
+   END INTERFACE
+   INTERFACE mpp_minloc
+      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
+   END INTERFACE
+   INTERFACE mpp_maxloc
+      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
+   END INTERFACE
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
+   LOGICAL, PUBLIC            ::   ln_nnogather          !: namelist control of northfold comms (needed here in case "key_mpp_mpi" is not used)
+   INTEGER :: ncomm_ice
+   INTEGER, PUBLIC            ::   mpi_comm_opa          ! opa local communicator
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION lib_mpp_alloc(kumout)          ! Dummy function
+      INTEGER, INTENT(in) ::   kumout
+      lib_mpp_alloc = 0
+   END FUNCTION lib_mpp_alloc
+
+   FUNCTION mynode( ldtxt, ldname, kumnam_ref, knumnam_cfg,  kumond , kstop, localComm ) RESULT (function_value)
+      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
+      CHARACTER(len=*),DIMENSION(:) ::   ldtxt
+      CHARACTER(len=*) ::   ldname
+      INTEGER ::   kumnam_ref, knumnam_cfg , kumond , kstop
+      IF( PRESENT( localComm ) ) mpi_comm_opa = localComm
+      function_value = 0
+      IF( .FALSE. )   ldtxt(:) = 'never done'
+      CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
+   END FUNCTION mynode
+
+   SUBROUTINE mppsync                       ! Dummy routine
+   END SUBROUTINE mppsync
+
+   SUBROUTINE mpp_sum_as( parr, kdim, kcom )      ! Dummy routine
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mpp_sum_as
+
+   SUBROUTINE mpp_sum_a2s( parr, kdim, kcom )      ! Dummy routine
+      REAL   , DIMENSION(:,:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1), kcom
+   END SUBROUTINE mpp_sum_a2s
+
+   SUBROUTINE mpp_sum_ai( karr, kdim, kcom )      ! Dummy routine
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mpp_sum_ai
+
+   SUBROUTINE mpp_sum_s( psca, kcom )            ! Dummy routine
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mpp_sum_s
+
+   SUBROUTINE mpp_sum_i( kint, kcom )            ! Dummy routine
+      integer               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mpp_sum_i
+
+   SUBROUTINE mppsum_realdd( ytab, kcom )
+      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+      WRITE(*,*) 'mppsum_realdd: You should not have seen this print! error?', ytab
+   END SUBROUTINE mppsum_realdd
+
+   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
+      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+      WRITE(*,*) 'mppsum_a_realdd: You should not have seen this print! error?', kdim, ytab(1), kcom
+   END SUBROUTINE mppsum_a_realdd
+
+   SUBROUTINE mppmax_a_real( parr, kdim, kcom )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mppmax_a_real
+
+   SUBROUTINE mppmax_real( psca, kcom )
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmin_a_real( parr, kdim, kcom )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mppmin_a_real
+
+   SUBROUTINE mppmin_real( psca, kcom )
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mppmin_real
+
+   SUBROUTINE mppmax_a_int( karr, kdim ,kcom)
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mppmax_a_int
+
+   SUBROUTINE mppmax_int( kint, kcom)
+      INTEGER               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_int: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mppmax_int
+
+   SUBROUTINE mppmin_a_int( karr, kdim, kcom )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mppmin_a_int
+
+   SUBROUTINE mppmin_int( kint, kcom )
+      INTEGER               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mppmin_int
+
+   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki, kj )
+      REAL                   :: pmin
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mpp_minloc2d: You should not have seen this print! error?', pmin, ki, kj, ptab(1,1), pmask(1,1)
+   END SUBROUTINE mpp_minloc2d
+
+   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj, kk )
+      REAL                     :: pmin
+      REAL , DIMENSION (:,:,:) :: ptab, pmask
+      INTEGER :: ki, kj, kk
+      WRITE(*,*) 'mpp_minloc3d: You should not have seen this print! error?', pmin, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_minloc3d
+
+   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
+      REAL                   :: pmax
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mpp_maxloc2d: You should not have seen this print! error?', pmax, ki, kj, ptab(1,1), pmask(1,1)
+   END SUBROUTINE mpp_maxloc2d
+
+   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
+      REAL                     :: pmax
+      REAL , DIMENSION (:,:,:) :: ptab, pmask
+      INTEGER :: ki, kj, kk
+      WRITE(*,*) 'mpp_maxloc3d: You should not have seen this print! error?', pmax, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_maxloc3d
+
+   SUBROUTINE mppstop
+      STOP      ! non MPP case, just stop the run
+   END SUBROUTINE mppstop
+
+   SUBROUTINE mpp_ini_ice( kcom, knum )
+      INTEGER :: kcom, knum
+      WRITE(*,*) 'mpp_ini_ice: You should not have seen this print! error?', kcom, knum
+   END SUBROUTINE mpp_ini_ice
+
+   SUBROUTINE mpp_ini_znl( knum )
+      INTEGER :: knum
+      WRITE(*,*) 'mpp_ini_znl: You should not have seen this print! error?', knum
+   END SUBROUTINE mpp_ini_znl
+
+   SUBROUTINE mpp_comm_free( kcom )
+      INTEGER :: kcom
+      WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
+   END SUBROUTINE mpp_comm_free
+#endif
+
+   !!----------------------------------------------------------------------
+   !!   All cases:         ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5 ,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_opa  ***
+      !!
+      !! ** Purpose :   print in ocean.outpput file a error message and
+      !!                increment the error number (nstop) by one.
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      !!----------------------------------------------------------------------
+      !
+      nstop = nstop + 1
+      IF(lwp) THEN
+         WRITE(numout,cform_err)
+         IF( PRESENT(cd1 ) )   WRITE(numout,*) cd1
+         IF( PRESENT(cd2 ) )   WRITE(numout,*) cd2
+         IF( PRESENT(cd3 ) )   WRITE(numout,*) cd3
+         IF( PRESENT(cd4 ) )   WRITE(numout,*) cd4
+         IF( PRESENT(cd5 ) )   WRITE(numout,*) cd5
+         IF( PRESENT(cd6 ) )   WRITE(numout,*) cd6
+         IF( PRESENT(cd7 ) )   WRITE(numout,*) cd7
+         IF( PRESENT(cd8 ) )   WRITE(numout,*) cd8
+         IF( PRESENT(cd9 ) )   WRITE(numout,*) cd9
+         IF( PRESENT(cd10) )   WRITE(numout,*) cd10
+      ENDIF
+                               CALL FLUSH(numout    )
+      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
+      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
+      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
+      !
+      IF( cd1 == 'STOP' ) THEN
+         IF(lwp) WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
+         CALL mppstop()
+      ENDIF
+      !
+   END SUBROUTINE ctl_stop
+
+
+   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_warn  ***
+      !!
+      !! ** Purpose :   print in ocean.outpput file a error message and
+      !!                increment the warning number (nwarn) by one.
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      !!----------------------------------------------------------------------
+      !
+      nwarn = nwarn + 1
+      IF(lwp) THEN
+         WRITE(numout,cform_war)
+         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
+         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
+         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
+         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
+         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
+         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
+         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
+         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
+         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
+         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
+      ENDIF
+      CALL FLUSH(numout)
+      !
+   END SUBROUTINE ctl_warn
+
+
+   SUBROUTINE ctl_opn( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctl_opn  ***
+      !!
+      !! ** Purpose :   Open file and check if required file is available.
+      !!
+      !! ** Method  :   Fortan open
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
+      INTEGER          , INTENT(in   ) ::   klengh    ! record length
+      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
+      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
+      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
+      !!
+      CHARACTER(len=80) ::   clfile
+      INTEGER           ::   iost
+      !!----------------------------------------------------------------------
+
+      ! adapt filename
+      ! ----------------
+      clfile = TRIM(cdfile)
+      IF( PRESENT( karea ) ) THEN
+         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
+      ENDIF
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
+      knum=Agrif_Get_Unit()
+#else
+      knum=get_unit()
+#endif
+
+      iost=0
+      IF( cdacce(1:6) == 'DIRECT' )  THEN
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
+      ELSE
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
+      ENDIF
+      IF( iost == 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*) '     file   : ', clfile,' open ok'
+            WRITE(kout,*) '     unit   = ', knum
+            WRITE(kout,*) '     status = ', cdstat
+            WRITE(kout,*) '     form   = ', cdform
+            WRITE(kout,*) '     access = ', cdacce
+            WRITE(kout,*)
+         ENDIF
+      ENDIF
+100   CONTINUE
+      IF( iost /= 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*)
+            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
+            WRITE(kout,*) ' =======   ===  '
+            WRITE(kout,*) '           unit   = ', knum
+            WRITE(kout,*) '           status = ', cdstat
+            WRITE(kout,*) '           form   = ', cdform
+            WRITE(kout,*) '           access = ', cdacce
+            WRITE(kout,*) '           iostat = ', iost
+            WRITE(kout,*) '           we stop. verify the file '
+            WRITE(kout,*)
+         ENDIF
+         STOP 'ctl_opn bad opening'
+      ENDIF
+
+   END SUBROUTINE ctl_opn
+
+   SUBROUTINE ctl_nam ( kios, cdnam, ldwp )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctl_nam  ***
+      !!
+      !! ** Purpose :   Informations when error while reading a namelist
+      !!
+      !! ** Method  :   Fortan open
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(inout) ::   kios      ! IO status after reading the namelist
+      CHARACTER(len=*) , INTENT(in   ) ::   cdnam     ! group name of namelist for which error occurs
+      CHARACTER(len=5)                 ::   clios     ! string to convert iostat in character for print
+      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
+      !!----------------------------------------------------------------------
+
+      ! 
+      ! ----------------
+      WRITE (clios, '(I5.0)') kios
+      IF( kios < 0 ) THEN         
+         CALL ctl_warn( 'W A R N I N G:  end of record or file while reading namelist ' &
+ &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
+      ENDIF
+
+      IF( kios > 0 ) THEN
+         CALL ctl_stop( 'E R R O R :   misspelled variable in namelist ' &
+ &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
+      ENDIF
+      kios = 0
+      RETURN
+      
+   END SUBROUTINE ctl_nam
+
+   INTEGER FUNCTION get_unit()
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  get_unit  ***
+      !!
+      !! ** Purpose :   return the index of an unused logical unit
+      !!----------------------------------------------------------------------
+      LOGICAL :: llopn
+      !!----------------------------------------------------------------------
+      !
+      get_unit = 15   ! choose a unit that is big enough then it is not already used in NEMO
+      llopn = .TRUE.
+      DO WHILE( (get_unit < 998) .AND. llopn )
+         get_unit = get_unit + 1
+         INQUIRE( unit = get_unit, opened = llopn )
+      END DO
+      IF( (get_unit == 999) .AND. llopn ) THEN
+         CALL ctl_stop( 'get_unit: All logical units until 999 are used...' )
+         get_unit = -1
+      ENDIF
+      !
+   END FUNCTION get_unit
+
+   !!----------------------------------------------------------------------
+END MODULE lib_mpp
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/nemogcm.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/nemogcm.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/nemogcm.F90	(revision 5879)
@@ -0,0 +1,860 @@
+MODULE nemogcm
+   !!======================================================================
+   !!                       ***  MODULE nemogcm   ***
+   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
+   !!======================================================================
+   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
+   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
+   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
+   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
+   !!             -   ! 1992-06  (L.Terray)  coupling implementation
+   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
+   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
+   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
+   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
+   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
+   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
+   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
+   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
+   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
+   !!             -   ! 2004-08  (C. Talandier) New trends organization
+   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
+   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
+   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
+   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
+   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
+   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
+   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
+   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
+   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
+   !!                 ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
+   !!   nemo_init      : initialization of the NEMO system
+   !!   nemo_ctl       : initialisation of the contol print
+   !!   nemo_closefile : close remaining open files
+   !!   nemo_alloc     : dynamical allocation
+   !!   nemo_partition : calculate MPP domain decomposition
+   !!   factorise      : calculate the factors of the no. of MPI processes
+   !!----------------------------------------------------------------------
+   USE step_oce        ! module used in the ocean time stepping module
+   USE cla             ! cross land advection               (tra_cla routine)
+   USE domcfg          ! domain configuration               (dom_cfg routine)
+   USE mppini          ! shared/distributed memory setting (mpp_init routine)
+   USE domain          ! domain initialization             (dom_init routine)
+#if defined key_nemocice_decomp
+   USE ice_domain_size, only: nx_global, ny_global
+#endif
+   USE tideini         ! tidal components initialization   (tide_ini routine)
+   USE bdyini          ! open boundary cond. setting       (bdy_init routine)
+   USE bdydta          ! open boundary cond. setting   (bdy_dta_init routine)
+   USE bdytides        ! open boundary cond. setting   (bdytide_init routine)
+   USE istate          ! initial state setting          (istate_init routine)
+   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
+   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
+   USE zdfini          ! vertical physics setting          (zdf_init routine)
+   USE phycst          ! physical constant                  (par_cst routine)
+   USE trdini          ! dyn/tra trends initialization     (trd_init routine)
+   USE asminc          ! assimilation increments     
+   USE asmbkg          ! writing out state trajectory
+   USE diaptr          ! poleward transports           (dia_ptr_init routine)
+   USE diadct          ! sections transports           (dia_dct_init routine)
+   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
+   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
+   USE step            ! NEMO time-stepping                 (stp     routine)
+   USE icbini          ! handle bergs, initialisation
+   USE icbstp          ! handle bergs, calving, themodynamics and transport
+   USE cpl_oasis3      ! OASIS3 coupling
+   USE c1d             ! 1D configuration
+   USE step_c1d        ! Time stepping loop for the 1D configuration
+   USE dyndmp          ! Momentum damping
+#if defined key_top
+   USE trcini          ! passive tracer initialisation
+#endif
+   USE lib_mpp         ! distributed memory computing
+#if defined key_iomput
+   USE xios
+#endif
+   USE sbctide, ONLY: lk_tide
+   USE crsini          ! initialise grid coarsening utility
+   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges 
+   USE sbc_oce, ONLY: lk_oasis
+   USE stopar
+   USE stopts
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   nemo_gcm    ! called by model.F90
+   PUBLIC   nemo_init   ! needed by AGRIF
+   PUBLIC   nemo_alloc  ! needed by TAM
+
+   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id: nemogcm.F90 6204 2016-01-04 13:47:06Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE nemo_gcm
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_gcm  ***
+      !!
+      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
+      !!              curvilinear mesh on the sphere.
+      !!
+      !! ** Method  : - model general initialization
+      !!              - launch the time-stepping (stp routine)
+      !!              - finalize the run by closing files and communications
+      !!
+      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
+      !!              Madec, 2008, internal report, IPSL.
+      !!----------------------------------------------------------------------
+      INTEGER ::   istp       ! time step index
+      !!----------------------------------------------------------------------
+      !
+#if defined key_agrif
+      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
+#endif
+
+      !                            !-----------------------!
+      CALL nemo_init               !==  Initialisations  ==!
+      !                            !-----------------------!
+#if defined key_agrif
+      CALL Agrif_Declare_Var_dom   ! AGRIF: set the meshes for DOM
+      CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA 
+# if defined key_top
+      CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
+# endif
+# if defined key_lim2
+      CALL Agrif_Declare_Var_lim2  !  "      "   "   "      "  LIM
+# endif
+#endif
+      ! check that all process are still there... If some process have an error,
+      ! they will never enter in step and other processes will wait until the end of the cpu time!
+      IF( lk_mpp )   CALL mpp_max( nstop )
+
+      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
+
+      !                            !-----------------------!
+      !                            !==   time stepping   ==!
+      !                            !-----------------------!
+      istp = nit000
+#if defined key_c1d
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+            CALL stp_c1d( istp )
+            istp = istp + 1
+         END DO
+#else
+          IF( lk_asminc ) THEN
+             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
+             IF( ln_asmdin ) THEN                        ! Direct initialization
+                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
+                IF( ln_dyninc ) CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
+                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
+             ENDIF
+          ENDIF
+
+#if defined key_agrif
+          CALL Agrif_Regrid()
+#endif
+
+         DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_agrif
+            CALL stp                         ! AGRIF: time stepping
+#else
+            CALL stp( istp )                 ! standard time stepping
+#endif
+            istp = istp + 1
+            IF( lk_mpp )   CALL mpp_max( nstop )
+         END DO
+#endif
+
+      IF( lk_diaobs   )   CALL dia_obs_wri
+      !
+      IF( ln_icebergs )   CALL icb_end( nitend )
+
+      !                            !------------------------!
+      !                            !==  finalize the run  ==!
+      !                            !------------------------!
+      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
+      !
+      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
+         WRITE(numout,cform_err)
+         WRITE(numout,*) nstop, ' error have been found'
+      ENDIF
+      !
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+         CALL Agrif_ParentGrid_To_ChildGrid()
+         IF( lk_diaobs ) CALL dia_obs_wri
+         IF( nn_timing == 1 )   CALL timing_finalize
+         CALL Agrif_ChildGrid_To_ParentGrid()
+      ENDIF
+#endif
+      IF( nn_timing == 1 )   CALL timing_finalize
+      !
+      CALL nemo_closefile
+      !
+#if defined key_iomput
+      CALL xios_finalize                ! end mpp communications with xios
+      IF( lk_oasis ) CALL cpl_finalize    ! end coupling and mpp communications with OASIS
+#else
+      IF( lk_oasis ) THEN 
+         CALL cpl_finalize              ! end coupling and mpp communications with OASIS
+      ELSE
+         IF( lk_mpp )   CALL mppstop    ! end mpp communications
+      ENDIF
+#endif
+      !
+   END SUBROUTINE nemo_gcm
+
+
+   SUBROUTINE nemo_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_init  ***
+      !!
+      !! ** Purpose :   initialization of the NEMO GCM
+      !!----------------------------------------------------------------------
+      INTEGER ::   ji            ! dummy loop indices
+      INTEGER ::   ilocal_comm   ! local integer
+      INTEGER ::   ios
+      CHARACTER(len=80), DIMENSION(16) ::   cltxt
+      !
+      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
+         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
+         &             nn_bench, nn_timing
+      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
+         &             jpizoom, jpjzoom, jperio, ln_use_jattr
+      !!----------------------------------------------------------------------
+      !
+      cltxt = ''
+      cxios_context = 'nemo'
+      !
+      !                             ! Open reference namelist and configuration namelist files
+      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
+      !
+      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
+      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
+
+      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
+      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
+
+      !
+      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
+      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
+
+      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
+      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
+
+! Force values for AGRIF zoom (cf. agrif_user.F90)
+#if defined key_agrif
+   IF( .NOT. Agrif_Root() ) THEN
+      jpiglo  = nbcellsx + 2 + 2*nbghostcells
+      jpjglo  = nbcellsy + 2 + 2*nbghostcells
+      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
+      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
+      jpidta  = jpiglo
+      jpjdta  = jpjglo
+      jpizoom = 1
+      jpjzoom = 1
+      nperio  = 0
+      jperio  = 0
+      ln_use_jattr = .false.
+   ENDIF
+#endif
+      !
+      !                             !--------------------------------------------!
+      !                             !  set communicator & select the local node  !
+      !                             !  NB: mynode also opens output.namelist.dyn !
+      !                             !      on unit number numond on first proc   !
+      !                             !--------------------------------------------!
+#if defined key_iomput
+      IF( Agrif_Root() ) THEN
+         IF( lk_oasis ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
+            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
+         ELSE
+            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
+         ENDIF
+      ENDIF
+      ! Nodes selection (control print return in cltxt)
+      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+#else
+      IF( lk_oasis ) THEN
+         IF( Agrif_Root() ) THEN
+            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
+         ENDIF
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
+      ELSE
+         ilocal_comm = 0
+         ! Nodes selection (control print return in cltxt)
+         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
+      ENDIF
+#endif
+      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
+
+      lwm = (narea == 1)                                    ! control of output namelists
+      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
+
+      IF(lwm) THEN
+         ! write merged namelists from earlier to output namelist now that the
+         ! file has been opened in call to mynode. nammpp has already been
+         ! written in mynode (if lk_mpp_mpi)
+         WRITE( numond, namctl )
+         WRITE( numond, namcfg )
+      ENDIF
+
+      ! If dimensions of processor grid weren't specified in the namelist file
+      ! then we calculate them here now that we have our communicator size
+      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+#if   defined key_mpp_mpi
+         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
+#else
+         jpni  = 1
+         jpnj  = 1
+         jpnij = jpni*jpnj
+#endif
+      END IF
+
+      ! Calculate domain dimensions given calculated jpni and jpnj
+      ! This used to be done in par_oce.F90 when they were parameters rather
+      ! than variables
+      IF( Agrif_Root() ) THEN
+#if defined key_nemocice_decomp
+         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
+         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. 
+#else
+         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
+         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
+#endif
+      ENDIF         
+         jpk = jpkdta                                             ! third dim
+#if defined key_agrif
+         ! simple trick to use same vertical grid as parent
+         ! but different number of levels: 
+         ! Save maximum number of levels in jpkdta, then define all vertical grids
+         ! with this number.
+         ! Suppress once vertical online interpolation is ok
+         IF(.NOT.Agrif_Root()) jpkdta = Agrif_Parent(jpkdta)
+#endif
+         jpim1 = jpi-1                                            ! inner domain indices
+         jpjm1 = jpj-1                                            !   "           "
+         jpkm1 = jpk-1                                            !   "           "
+         jpij  = jpi*jpj                                          !  jpi x j
+
+      IF(lwp) THEN                            ! open listing units
+         !
+         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+         !
+         WRITE(numout,*)
+         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
+         WRITE(numout,*) '                       NEMO team'
+         WRITE(numout,*) '            Ocean General Circulation Model'
+         WRITE(numout,*) '                  version 3.6  (2015) '
+         WRITE(numout,*)
+         WRITE(numout,*)
+         DO ji = 1, SIZE(cltxt)
+            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
+         END DO
+         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
+         !
+      ENDIF
+
+      ! Now we know the dimensions of the grid and numout has been set we can
+      ! allocate arrays
+      CALL nemo_alloc()
+
+      !                             !-------------------------------!
+      !                             !  NEMO general initialization  !
+      !                             !-------------------------------!
+
+      CALL nemo_ctl                          ! Control prints & Benchmark
+
+      !                                      ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
+      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_init
+      !
+      !                                      ! General initialization
+                            CALL     phy_cst    ! Physical constants
+                            CALL     eos_init   ! Equation of state
+      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
+                            CALL     dom_cfg    ! Domain configuration
+                            CALL     dom_init   ! Domain
+
+      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
+
+      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
+
+                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
+
+      IF( lk_tide       )   CALL    tide_init( nit000 )    ! Initialisation of the tidal harmonics
+
+                            CALL     sbc_init   ! Forcings : surface module (clem: moved here for bdy purpose)
+
+      IF( lk_bdy        )   CALL     bdy_init   ! Open boundaries initialisation
+      IF( lk_bdy        )   CALL bdy_dta_init   ! Open boundaries initialisation of external data arrays
+      IF( lk_bdy .AND. lk_tide )   &
+         &                  CALL bdytide_init   ! Open boundaries initialisation of tidal harmonic forcing
+
+                            CALL dyn_nept_init  ! simplified form of Neptune effect
+      !     
+      IF( ln_crs        )   CALL     crs_init   ! Domain initialization of coarsened grid
+      !
+                                ! Ocean physics
+      !                                         ! Vertical physics
+                            CALL     zdf_init      ! namelist read
+                            CALL zdf_bfr_init      ! bottom friction
+      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
+      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
+      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
+      IF( lk_zdfkpp     )   CALL zdf_kpp_init      ! KPP closure scheme
+      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
+      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
+         &                  CALL zdf_ddm_init      ! double diffusive mixing
+      !                                         ! Lateral physics
+                            CALL ldf_tra_init      ! Lateral ocean tracer physics
+                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
+      IF( lk_ldfslp     )   CALL ldf_slp_init      ! slope of lateral mixing
+
+      !                                     ! Active tracers
+                            CALL tra_qsr_init   ! penetrative solar radiation qsr
+                            CALL tra_bbc_init   ! bottom heat flux
+      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
+                            CALL tra_dmp_init   ! internal damping trends- tracers
+                            CALL tra_adv_init   ! horizontal & vertical advection
+                            CALL tra_ldf_init   ! lateral mixing
+                            CALL tra_zdf_init   ! vertical mixing and after tracer fields
+
+      !                                     ! Dynamics
+      IF( lk_c1d        )   CALL dyn_dmp_init   ! internal damping trends- momentum
+                            CALL dyn_adv_init   ! advection (vector or flux form)
+                            CALL dyn_vor_init   ! vorticity term including Coriolis
+                            CALL dyn_ldf_init   ! lateral mixing
+                            CALL dyn_hpg_init   ! horizontal gradient of Hydrostatic pressure
+                            CALL dyn_zdf_init   ! vertical diffusion
+                            CALL dyn_spg_init   ! surface pressure gradient
+
+      !                                     ! Misc. options
+      ! ADD PALEORCA2 configuration -- JBL 07.02.2017
+      IF( nn_cla == 1 .AND. cp_cfg == 'orca' .AND. jp_cfg == 2 )   CALL cla_init       ! Cross Land Advection
+      IF( nn_cla == 1 .AND. cp_cfg == 'paleorca' .AND. jp_cfg == 2 )   CALL cla_init       ! Cross Land Advection if needed
+                            CALL icb_init( rdt, nit000)   ! initialise icebergs instance
+                            CALL sto_par_init   ! Stochastic parametrization
+      IF( ln_sto_eos     )  CALL sto_pts_init   ! RRandom T/S fluctuations
+     
+#if defined key_top
+      !                                     ! Passive tracers
+                            CALL     trc_init
+#endif
+      !                                     ! Diagnostics
+      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
+      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
+                            CALL dia_ptr_init   ! Poleward TRansports initialization
+      IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
+                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
+                            CALL     trd_init   ! Mixed-layer/Vorticity/Integral constraints trends
+      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
+                            CALL dia_obs_init            ! Initialize observational data
+                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
+      ENDIF
+
+      !                                     ! Assimilation increments
+      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
+      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
+      !
+   END SUBROUTINE nemo_init
+
+
+   SUBROUTINE nemo_ctl
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_ctl  ***
+      !!
+      !! ** Purpose :   control print setting
+      !!
+      !! ** Method  : - print namctl information and check some consistencies
+      !!----------------------------------------------------------------------
+      !
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '   Namelist namctl'
+         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
+         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
+         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
+         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
+         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
+         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
+         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
+         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
+         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
+         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
+      ENDIF
+      !
+      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
+      nictls    = nn_ictls
+      nictle    = nn_ictle
+      njctls    = nn_jctls
+      njctle    = nn_jctle
+      isplt     = nn_isplt
+      jsplt     = nn_jsplt
+      nbench    = nn_bench
+
+      IF(lwp) THEN                  ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
+         WRITE(numout,*) '~~~~~~~ '
+         WRITE(numout,*) '   Namelist namcfg'
+         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
+         WRITE(numout,*) '      configuration zoom name         cp_cfz      = ', TRIM(cp_cfz)
+         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
+         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
+         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
+         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
+         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
+         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
+         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
+         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
+         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
+         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
+      ENDIF
+      !                             ! Parameter control
+      !
+      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
+         IF( lk_mpp .AND. jpnij > 1 ) THEN
+            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
+         ELSE
+            IF( isplt == 1 .AND. jsplt == 1  ) THEN
+               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
+                  &           ' - the print control will be done over the whole domain' )
+            ENDIF
+            ijsplt = isplt * jsplt            ! total number of processors ijsplt
+         ENDIF
+         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
+         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
+         !
+         !                              ! indices used for the SUM control
+         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
+            lsp_area = .FALSE.
+         ELSE                                             ! print control done over a specific  area
+            lsp_area = .TRUE.
+            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
+               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
+               nictls = 1
+            ENDIF
+            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
+               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
+               nictle = jpiglo
+            ENDIF
+            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
+               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
+               njctls = 1
+            ENDIF
+            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
+               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
+               njctle = jpjglo
+            ENDIF
+         ENDIF
+      ENDIF
+      !
+      IF( nbench == 1 ) THEN              ! Benchmark
+         SELECT CASE ( cp_cfg )
+         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
+         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
+            &                                 ' cp_cfg = "gyre" in namelist &namcfg or set nbench = 0' )
+         END SELECT
+      ENDIF
+      !
+      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
+         &                                               'f2003 standard. '                              ,  &
+         &                                               'Compile with key_nosignedzero enabled' )
+      !
+   END SUBROUTINE nemo_ctl
+
+
+   SUBROUTINE nemo_closefile
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_closefile  ***
+      !!
+      !! ** Purpose :   Close the files
+      !!----------------------------------------------------------------------
+      !
+      IF( lk_mpp )   CALL mppsync
+      !
+      CALL iom_close                                 ! close all input/output files managed by iom_*
+      !
+      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
+      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
+      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
+      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
+      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
+      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
+      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
+      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
+      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
+      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
+      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
+      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
+      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
+
+      !
+      numout = 6                                     ! redefine numout in case it is used after this point...
+      !
+   END SUBROUTINE nemo_closefile
+
+
+   SUBROUTINE nemo_alloc
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE nemo_alloc  ***
+      !!
+      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
+      !!
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      USE diawri    , ONLY: dia_wri_alloc
+      USE dom_oce   , ONLY: dom_oce_alloc
+      USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc
+      USE ldftra_oce, ONLY: ldftra_oce_alloc
+      USE trc_oce   , ONLY: trc_oce_alloc
+#if defined key_diadct 
+      USE diadct    , ONLY: diadct_alloc 
+#endif 
+#if defined key_bdy
+      USE bdy_oce   , ONLY: bdy_oce_alloc
+#endif
+      !
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
+      !
+      ierr =        oce_alloc       ()          ! ocean
+      ierr = ierr + dia_wri_alloc   ()
+      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
+      ierr = ierr + ldfdyn_oce_alloc()          ! ocean lateral  physics : dynamics
+      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
+      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
+      !
+      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
+      !
+#if defined key_diadct 
+      ierr = ierr + diadct_alloc    ()          ! 
+#endif 
+#if defined key_bdy
+      ierr = ierr + bdy_oce_alloc   ()          ! bdy masks (incl. initialization)
+#endif
+      !
+      IF( lk_mpp    )   CALL mpp_sum( ierr )
+      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
+      !
+   END SUBROUTINE nemo_alloc
+
+
+   SUBROUTINE nemo_partition( num_pes )
+      !!----------------------------------------------------------------------
+      !!                 ***  ROUTINE nemo_partition  ***
+      !!
+      !! ** Purpose :
+      !!
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
+      !
+      INTEGER, PARAMETER :: nfactmax = 20
+      INTEGER :: nfact ! The no. of factors returned
+      INTEGER :: ierr  ! Error flag
+      INTEGER :: ji
+      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
+      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
+      !!----------------------------------------------------------------------
+      !
+      ierr = 0
+      !
+      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
+      !
+      IF( nfact <= 1 ) THEN
+         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
+         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
+         jpnj = 1
+         jpni = num_pes
+      ELSE
+         ! Search through factors for the pair that are closest in value
+         mindiff = 1000000
+         imin    = 1
+         DO ji = 1, nfact-1, 2
+            idiff = ABS( ifact(ji) - ifact(ji+1) )
+            IF( idiff < mindiff ) THEN
+               mindiff = idiff
+               imin = ji
+            ENDIF
+         END DO
+         jpnj = ifact(imin)
+         jpni = ifact(imin + 1)
+      ENDIF
+      !
+      jpnij = jpni*jpnj
+      !
+   END SUBROUTINE nemo_partition
+
+
+   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE factorise  ***
+      !!
+      !! ** Purpose :   return the prime factors of n.
+      !!                knfax factors are returned in array kfax which is of
+      !!                maximum dimension kmaxfax.
+      !! ** Method  :
+      !!----------------------------------------------------------------------
+      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
+      INTEGER                    , INTENT(  out) ::   kerr, knfax
+      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
+      !
+      INTEGER :: ifac, jl, inu
+      INTEGER, PARAMETER :: ntest = 14
+      INTEGER, DIMENSION(ntest) :: ilfax
+      !
+      ! ilfax contains the set of allowed factors.
+      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
+      !!----------------------------------------------------------------------
+      ! ilfax contains the set of allowed factors.
+      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
+
+      ! Clear the error flag and initialise output vars
+      kerr = 0
+      kfax = 1
+      knfax = 0
+
+      ! Find the factors of n.
+      IF( kn == 1 )   GOTO 20
+
+      ! nu holds the unfactorised part of the number.
+      ! knfax holds the number of factors found.
+      ! l points to the allowed factor list.
+      ! ifac holds the current factor.
+
+      inu   = kn
+      knfax = 0
+
+      DO jl = ntest, 1, -1
+         !
+         ifac = ilfax(jl)
+         IF( ifac > inu )   CYCLE
+
+         ! Test whether the factor will divide.
+
+         IF( MOD(inu,ifac) == 0 ) THEN
+            !
+            knfax = knfax + 1            ! Add the factor to the list
+            IF( knfax > kmaxfax ) THEN
+               kerr = 6
+               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
+               return
+            ENDIF
+            kfax(knfax) = ifac
+            ! Store the other factor that goes with this one
+            knfax = knfax + 1
+            kfax(knfax) = inu / ifac
+            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
+         ENDIF
+         !
+      END DO
+
+   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
+      !
+   END SUBROUTINE factorise
+
+#if defined key_mpp_mpi
+
+   SUBROUTINE nemo_northcomms
+      !!======================================================================
+      !!                     ***  ROUTINE  nemo_northcomms  ***
+      !! nemo_northcomms    :  Setup for north fold exchanges with explicit 
+      !!                       point-to-point messaging
+      !!=====================================================================
+      !!----------------------------------------------------------------------
+      !!
+      !! ** Purpose :   Initialization of the northern neighbours lists.
+      !!----------------------------------------------------------------------
+      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
+      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC) 
+      !!----------------------------------------------------------------------
+
+      INTEGER  ::   sxM, dxM, sxT, dxT, jn
+      INTEGER  ::   njmppmax
+
+      njmppmax = MAXVAL( njmppt )
+    
+      !initializes the north-fold communication variables
+      isendto(:) = 0
+      nsndto = 0
+
+      !if I am a process in the north
+      IF ( njmpp == njmppmax ) THEN
+          !sxM is the first point (in the global domain) needed to compute the
+          !north-fold for the current process
+          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
+          !dxM is the last point (in the global domain) needed to compute the
+          !north-fold for the current process
+          dxM = jpiglo - nimppt(narea) + 2
+
+          !loop over the other north-fold processes to find the processes
+          !managing the points belonging to the sxT-dxT range
+  
+          DO jn = 1, jpni
+                !sxT is the first point (in the global domain) of the jn
+                !process
+                sxT = nfiimpp(jn, jpnj)
+                !dxT is the last point (in the global domain) of the jn
+                !process
+                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
+                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
+                   nsndto = nsndto + 1
+                     isendto(nsndto) = jn
+                END IF
+          END DO
+          nfsloop = 1
+          nfeloop = nlci
+          DO jn = 2,jpni-1
+           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
+              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
+                 nfsloop = nldi
+              ENDIF
+              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
+                 nfeloop = nlei
+              ENDIF
+           ENDIF
+        END DO
+
+      ENDIF
+      l_north_nogather = .TRUE.
+   END SUBROUTINE nemo_northcomms
+#else
+   SUBROUTINE nemo_northcomms      ! Dummy routine
+      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
+   END SUBROUTINE nemo_northcomms
+#endif
+
+   !!======================================================================
+END MODULE nemogcm
+
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/p4zsms.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/p4zsms.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/p4zsms.F90	(revision 5879)
@@ -0,0 +1,617 @@
+MODULE p4zsms
+   !!======================================================================
+   !!                         ***  MODULE p4zsms  ***
+   !! TOP :   PISCES Source Minus Sink manager
+   !!======================================================================
+   !! History :   1.0  !  2004-03 (O. Aumont) Original code
+   !!             2.0  !  2007-12  (C. Ethe, G. Madec)  F90
+   !!----------------------------------------------------------------------
+#if defined key_pisces
+   !!----------------------------------------------------------------------
+   !!   'key_pisces'                                       PISCES bio-model
+   !!----------------------------------------------------------------------
+   !!   p4zsms         :  Time loop of passive tracers sms
+   !!----------------------------------------------------------------------
+   USE oce_trc         !  shared variables between ocean and passive tracers
+   USE trc             !  passive tracers common variables 
+   USE trcdta
+   USE sms_pisces      !  PISCES Source Minus Sink variables
+   USE p4zbio          !  Biological model
+   USE p4zche          !  Chemical model
+   USE p4zlys          !  Calcite saturation
+   USE p4zflx          !  Gas exchange
+   USE p4zsbc          !  External source of nutrients
+   USE p4zsed          !  Sedimentation
+   USE p4zint          !  time interpolation
+   USE p4zrem          !  remineralisation
+   USE iom             !  I/O manager
+   USE trd_oce         !  Ocean trends variables
+   USE trdtrc          !  TOP trends variables
+   USE sedmodel        !  Sediment model
+   USE prtctl_trc      !  print control for debugging
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   p4z_sms_init   ! called in p4zsms.F90
+   PUBLIC   p4z_sms        ! called in p4zsms.F90
+
+   REAL(wp) :: alkbudget, no3budget, silbudget, ferbudget, po4budget
+   REAL(wp) :: xfact1, xfact2, xfact3
+   INTEGER ::  numco2, numnut, numnit  !: logical unit for co2 budget
+
+   !!* Array used to indicate negative tracer values
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   xnegtr     !: ???
+
+
+   !! * Substitutions
+#  include "top_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
+   !! $Id: p4zsms.F90 3320 2012-03-05 16:37:52Z cetlod $ 
+   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+
+CONTAINS
+
+   SUBROUTINE p4z_sms( kt )
+      !!---------------------------------------------------------------------
+      !!                     ***  ROUTINE p4z_sms  ***
+      !!
+      !! ** Purpose :   Managment of the call to Biological sources and sinks 
+      !!              routines of PISCES bio-model
+      !!
+      !! ** Method  : - at each new day ...
+      !!              - several calls of bio and sed ???
+      !!              - ...
+      !!---------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      !!
+      INTEGER ::   ji, jj, jk, jnt, jn, jl
+      REAL(wp) ::  ztra
+#if defined key_kriest
+      REAL(wp) ::  zcoef1, zcoef2
+#endif
+      CHARACTER (len=25) :: charout
+      !!---------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('p4z_sms')
+      !
+      IF( kt == nittrc000 ) THEN
+        !
+        ALLOCATE( xnegtr(jpi,jpj,jpk) )
+        !
+        CALL p4z_che                              ! initialize the chemical constants
+        !
+        IF( .NOT. ln_rsttr ) THEN  ;   CALL p4z_ph_ini   !  set PH at kt=nit000 
+        ELSE                       ;   CALL p4z_rst( nittrc000, 'READ' )  !* read or initialize all required fields 
+        ENDIF
+        !
+      ENDIF
+      !
+      IF( ln_pisdmp .AND. MOD( kt - nn_dttrc, nn_pisdmp ) == 0 )   CALL p4z_dmp( kt )      ! Relaxation of some tracers
+      !
+      !                                                                    !   set time step size (Euler/Leapfrog)
+      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN   ;    rfact = rdttrc(1)     !  at nittrc000
+      ELSEIF( kt <= nittrc000 + nn_dttrc )                          THEN   ;    rfact = 2. * rdttrc(1)   ! at nittrc000 or nittrc000+nn_dttrc (Leapfrog)
+      ENDIF
+      !
+      IF( ( ln_top_euler .AND. kt == nittrc000 )  .OR. ( .NOT.ln_top_euler .AND. kt <= nittrc000 + nn_dttrc ) ) THEN
+         rfactr  = 1. / rfact
+         rfact2  = rfact / FLOAT( nrdttrc )
+         rfact2r = 1. / rfact2
+         xstep = rfact2 / rday         ! Time step duration for biology
+         IF(lwp) WRITE(numout,*) 
+         IF(lwp) WRITE(numout,*) '    Passive Tracer  time step    rfact  = ', rfact, ' rdt = ', rdttra(1)
+         IF(lwp) write(numout,*) '    PISCES  Biology time step    rfact2 = ', rfact2
+         IF(lwp) WRITE(numout,*)
+      ENDIF
+
+      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN
+         DO jn = jp_pcs0, jp_pcs1              !   SMS on tracer without Asselin time-filter
+            trb(:,:,:,jn) = trn(:,:,:,jn)
+         END DO
+      ENDIF
+      !
+      IF( ndayflxtr /= nday_year ) THEN      ! New days
+         !
+         ndayflxtr = nday_year
+
+         IF(lwp) write(numout,*)
+         IF(lwp) write(numout,*) ' New chemical constants and various rates for biogeochemistry at new day : ', nday_year
+         IF(lwp) write(numout,*) '~~~~~~'
+
+         CALL p4z_che              ! computation of chemical constants
+         CALL p4z_int( kt )        ! computation of various rates for biogeochemistry
+         !
+      ENDIF
+
+      IF( ll_sbc ) CALL p4z_sbc( kt )   ! external sources of nutrients 
+
+      DO jnt = 1, nrdttrc          ! Potential time splitting if requested
+         !
+         CALL p4z_bio( kt, jnt )   ! Biology
+         CALL p4z_lys( kt, jnt )   ! Compute CaCO3 saturation
+         CALL p4z_sed( kt, jnt )   ! Surface and Bottom boundary conditions
+         CALL p4z_flx( kt, jnt )   ! Compute surface fluxes
+         !
+         xnegtr(:,:,:) = 1.e0
+         DO jn = jp_pcs0, jp_pcs1
+            DO jk = 1, jpk
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     IF( ( trb(ji,jj,jk,jn) + tra(ji,jj,jk,jn) ) < 0.e0 ) THEN
+                        ztra             = ABS( trb(ji,jj,jk,jn) ) / ( ABS( tra(ji,jj,jk,jn) ) + rtrn )
+                        xnegtr(ji,jj,jk) = MIN( xnegtr(ji,jj,jk),  ztra )
+                     ENDIF
+                 END DO
+               END DO
+            END DO
+         END DO
+         !                                ! where at least 1 tracer concentration becomes negative
+         !                                ! 
+         DO jn = jp_pcs0, jp_pcs1
+           trb(:,:,:,jn) = trb(:,:,:,jn) + xnegtr(:,:,:) * tra(:,:,:,jn)
+         END DO
+        !
+         DO jn = jp_pcs0, jp_pcs1
+            tra(:,:,:,jn) = 0._wp
+         END DO
+         !
+         IF( ln_top_euler ) THEN
+            DO jn = jp_pcs0, jp_pcs1
+               trn(:,:,:,jn) = trb(:,:,:,jn)
+            END DO
+         ENDIF
+      END DO
+
+#if defined key_kriest
+      ! 
+      zcoef1 = 1.e0 / xkr_massp 
+      zcoef2 = 1.e0 / xkr_massp / 1.1
+      DO jk = 1,jpkm1
+         trb(:,:,jk,jpnum) = MAX(  trb(:,:,jk,jpnum), trb(:,:,jk,jppoc) * zcoef1 / xnumm(jk)  )
+         trb(:,:,jk,jpnum) = MIN(  trb(:,:,jk,jpnum), trb(:,:,jk,jppoc) * zcoef2              )
+      END DO
+      !
+#endif
+      !
+      !
+      IF( l_trdtrc ) THEN
+         DO jn = jp_pcs0, jp_pcs1
+           CALL trd_trc( tra(:,:,:,jn), jn, jptra_sms, kt )   ! save trends
+         END DO
+      END IF
+      !
+      IF( lk_sed ) THEN 
+         !
+         CALL sed_model( kt )     !  Main program of Sediment model
+         !
+         DO jn = jp_pcs0, jp_pcs1
+           CALL lbc_lnk( trb(:,:,:,jn), 'T', 1. )
+         END DO
+         !
+      ENDIF
+      !
+      IF( lrst_trc )  CALL p4z_rst( kt, 'WRITE' )  !* Write PISCES informations in restart file 
+      !
+
+      IF( lk_iomput .OR. ln_check_mass )  CALL p4z_chk_mass( kt ) ! Mass conservation checking
+
+      IF ( lwm .AND. kt == nittrc000 ) CALL FLUSH    ( numonp )     ! flush output namelist PISCES
+      IF( nn_timing == 1 )  CALL timing_stop('p4z_sms')
+      !
+      !
+   END SUBROUTINE p4z_sms
+
+   SUBROUTINE p4z_sms_init
+      !!----------------------------------------------------------------------
+      !!                     ***  p4z_sms_init  ***  
+      !!
+      !! ** Purpose :   read PISCES namelist
+      !!
+      !! ** input   :   file 'namelist.trc.s' containing the following
+      !!             namelist: natext, natbio, natsms
+      !!                       natkriest ("key_kriest")
+      !!----------------------------------------------------------------------
+      NAMELIST/nampisbio/ nrdttrc, wsbio, xkmort, ferat3, wsbio2, niter1max, niter2max
+#if defined key_kriest
+      NAMELIST/nampiskrp/ xkr_eta, xkr_zeta, xkr_ncontent, xkr_mass_min, xkr_mass_max
+#endif
+      NAMELIST/nampisdmp/ ln_pisdmp, nn_pisdmp
+      NAMELIST/nampismass/ ln_check_mass
+      INTEGER :: ios                 ! Local integer output status for namelist read
+      !!----------------------------------------------------------------------
+
+      REWIND( numnatp_ref )              ! Namelist nampisbio in reference namelist : Pisces variables
+      READ  ( numnatp_ref, nampisbio, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisbio in reference namelist', lwp )
+
+      REWIND( numnatp_cfg )              ! Namelist nampisbio in configuration namelist : Pisces variables
+      READ  ( numnatp_cfg, nampisbio, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisbio in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, nampisbio )
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) ' Namelist : nampisbio'
+         WRITE(numout,*) '    frequence pour la biologie                nrdttrc   =', nrdttrc
+         WRITE(numout,*) '    POC sinking speed                         wsbio     =', wsbio
+         WRITE(numout,*) '    half saturation constant for mortality    xkmort    =', xkmort
+         WRITE(numout,*) '    Fe/C in zooplankton                       ferat3    =', ferat3
+         WRITE(numout,*) '    Big particles sinking speed               wsbio2    =', wsbio2
+         WRITE(numout,*) '    Maximum number of iterations for POC      niter1max =', niter1max
+         WRITE(numout,*) '    Maximum number of iterations for GOC      niter2max =', niter2max
+      ENDIF
+
+#if defined key_kriest
+
+      !                               ! nampiskrp : kriest parameters
+      !                               ! -----------------------------
+      REWIND( numnatp_ref )              ! Namelist nampiskrp in reference namelist : Pisces Kriest
+      READ  ( numnatp_ref, nampiskrp, IOSTAT = ios, ERR = 903)
+903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampiskrp in reference namelist', lwp )
+
+      REWIND( numnatp_cfg )              ! Namelist nampiskrp in configuration namelist : Pisces Kriest
+      READ  ( numnatp_cfg, nampiskrp, IOSTAT = ios, ERR = 904 )
+904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampiskrp in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, nampiskrp )
+
+      IF(lwp) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : nampiskrp'
+         WRITE(numout,*) '    Sinking  exponent                        xkr_eta      = ', xkr_eta
+         WRITE(numout,*) '    N content exponent                       xkr_zeta     = ', xkr_zeta
+         WRITE(numout,*) '    N content factor                         xkr_ncontent = ', xkr_ncontent
+         WRITE(numout,*) '    Minimum mass for Aggregates              xkr_mass_min = ', xkr_mass_min
+         WRITE(numout,*) '    Maximum mass for Aggregates              xkr_mass_max = ', xkr_mass_max
+         WRITE(numout,*)
+     ENDIF
+
+
+     ! Computation of some variables
+     xkr_massp = xkr_ncontent * 7.625 * xkr_mass_min**xkr_zeta
+
+#endif
+
+      REWIND( numnatp_ref )              ! Namelist nampisdmp in reference namelist : Pisces damping
+      READ  ( numnatp_ref, nampisdmp, IOSTAT = ios, ERR = 905)
+905   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisdmp in reference namelist', lwp )
+
+      REWIND( numnatp_cfg )              ! Namelist nampisdmp in configuration namelist : Pisces damping
+      READ  ( numnatp_cfg, nampisdmp, IOSTAT = ios, ERR = 906 )
+906   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampisdmp in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, nampisdmp )
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*)
+         WRITE(numout,*) ' Namelist : nampisdmp'
+         WRITE(numout,*) '    Relaxation of tracer to glodap mean value             ln_pisdmp      =', ln_pisdmp
+         WRITE(numout,*) '    Frequency of Relaxation                               nn_pisdmp      =', nn_pisdmp
+         WRITE(numout,*) ' '
+      ENDIF
+
+      REWIND( numnatp_ref )              ! Namelist nampismass in reference namelist : Pisces mass conservation check
+      READ  ( numnatp_ref, nampismass, IOSTAT = ios, ERR = 907)
+907   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismass in reference namelist', lwp )
+
+      REWIND( numnatp_cfg )              ! Namelist nampismass in configuration namelist : Pisces mass conservation check 
+      READ  ( numnatp_cfg, nampismass, IOSTAT = ios, ERR = 908 )
+908   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nampismass in configuration namelist', lwp )
+      IF(lwm) WRITE ( numonp, nampismass )
+
+      IF(lwp) THEN                         ! control print
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' Namelist parameter for mass conservation checking'
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*) '    Flag to check mass conservation of NO3/Si/TALK ln_check_mass = ', ln_check_mass
+      ENDIF
+
+   END SUBROUTINE p4z_sms_init
+
+   SUBROUTINE p4z_ph_ini
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE p4z_ini_ph  ***
+      !!
+      !!  ** Purpose : Initialization of chemical variables of the carbon cycle
+      !!---------------------------------------------------------------------
+      INTEGER  ::  ji, jj, jk
+      REAL(wp) ::  zcaralk, zbicarb, zco3
+      REAL(wp) ::  ztmas, ztmas1
+      !!---------------------------------------------------------------------
+
+      ! Set PH from  total alkalinity, borat (???), akb3 (???) and ak23 (???)
+      ! --------------------------------------------------------
+      DO jk = 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               ztmas   = tmask(ji,jj,jk)
+               ztmas1  = 1. - tmask(ji,jj,jk)
+               zcaralk = trb(ji,jj,jk,jptal) - borat(ji,jj,jk) / (  1. + 1.E-8 / ( rtrn + akb3(ji,jj,jk) )  )
+               zco3    = ( zcaralk - trb(ji,jj,jk,jpdic) ) * ztmas + 0.5e-3 * ztmas1
+               zbicarb = ( 2. * trb(ji,jj,jk,jpdic) - zcaralk )
+               hi(ji,jj,jk) = ( ak23(ji,jj,jk) * zbicarb / zco3 ) * ztmas + 1.e-9 * ztmas1
+            END DO
+         END DO
+     END DO
+     !
+   END SUBROUTINE p4z_ph_ini
+
+   SUBROUTINE p4z_rst( kt, cdrw )
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE p4z_rst  ***
+      !!
+      !!  ** Purpose : Read or write variables in restart file:
+      !!
+      !!  WRITE(READ) mode:
+      !!       kt        : number of time step since the begining of the experiment at the
+      !!                   end of the current(previous) run
+      !!---------------------------------------------------------------------
+      INTEGER         , INTENT(in) ::   kt         ! ocean time-step
+      CHARACTER(len=*), INTENT(in) ::   cdrw       ! "READ"/"WRITE" flag
+      !
+      INTEGER  ::  ji, jj, jk
+      REAL(wp) ::  zcaralk, zbicarb, zco3
+      REAL(wp) ::  ztmas, ztmas1
+      !!---------------------------------------------------------------------
+
+      IF( TRIM(cdrw) == 'READ' ) THEN
+         !
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) ' p4z_rst : Read specific variables from pisces model '
+         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~'
+         ! 
+         IF( iom_varid( numrtr, 'PH', ldstop = .FALSE. ) > 0 ) THEN
+            CALL iom_get( numrtr, jpdom_autoglo, 'PH' , hi(:,:,:)  )
+         ELSE
+!            hi(:,:,:) = 1.e-9 
+            CALL p4z_ph_ini
+         ENDIF
+         CALL iom_get( numrtr, jpdom_autoglo, 'Silicalim', xksi(:,:) )
+         IF( iom_varid( numrtr, 'Silicamax', ldstop = .FALSE. ) > 0 ) THEN
+            CALL iom_get( numrtr, jpdom_autoglo, 'Silicamax' , xksimax(:,:)  )
+         ELSE
+            xksimax(:,:) = xksi(:,:)
+         ENDIF
+         !
+         IF( iom_varid( numrtr, 'tcflxcum', ldstop = .FALSE. ) > 0 ) THEN  ! cumulative total flux of carbon
+            CALL iom_get( numrtr, 'tcflxcum' , t_oce_co2_flx_cum  )
+         ELSE
+            t_oce_co2_flx_cum = 0._wp
+         ENDIF
+         !
+      ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN
+         IF( kt == nitrst ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) 'p4z_rst : write pisces restart file  kt =', kt
+            IF(lwp) WRITE(numout,*) '~~~~~~~'
+         ENDIF
+         CALL iom_rstput( kt, nitrst, numrtw, 'PH', hi(:,:,:) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'Silicalim', xksi(:,:) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'Silicamax', xksimax(:,:) )
+         CALL iom_rstput( kt, nitrst, numrtw, 'tcflxcum', t_oce_co2_flx_cum )
+      ENDIF
+      !
+   END SUBROUTINE p4z_rst
+
+   SUBROUTINE p4z_dmp( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  p4z_dmp  ***
+      !!
+      !! ** purpose  : Relaxation of some tracers
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in )  ::     kt ! time step
+      !
+      REAL(wp) ::  alkmean = 2426.     ! mean value of alkalinity ( Glodap ; for Goyet 2391. )
+      REAL(wp) ::  po4mean = 2.165     ! mean value of phosphates
+      REAL(wp) ::  no3mean = 30.90     ! mean value of nitrate
+      REAL(wp) ::  silmean = 91.51     ! mean value of silicate
+      !
+      REAL(wp) :: zarea, zalksumn, zpo4sumn, zno3sumn, zsilsumn
+      REAL(wp) :: zalksumb, zpo4sumb, zno3sumb, zsilsumb
+      !!---------------------------------------------------------------------
+
+
+      IF(lwp)  WRITE(numout,*)
+      IF(lwp)  WRITE(numout,*) ' p4z_dmp : Restoring of nutrients at time-step kt = ', kt
+      IF(lwp)  WRITE(numout,*)
+
+      !IF( cp_cfg == "orca" .AND. .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) !
+      IF( ( cp_cfg == "orca" .OR. cp_cfg == "paleorca" ) .AND. .NOT. lk_c1d ) THEN      ! ORCA configuration (not 1D) !
+         !                                                    ! --------------------------- !
+         ! set total alkalinity, phosphate, nitrate & silicate
+         zarea          = 1._wp / glob_sum( cvol(:,:,:) ) * 1e6              
+
+         zalksumn = glob_sum( trn(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
+         zpo4sumn = glob_sum( trn(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
+         zno3sumn = glob_sum( trn(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
+         zsilsumn = glob_sum( trn(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+ 
+         IF(lwp) WRITE(numout,*) '       TALKN mean : ', zalksumn
+         trn(:,:,:,jptal) = trn(:,:,:,jptal) * alkmean / zalksumn
+
+         IF(lwp) WRITE(numout,*) '       PO4N  mean : ', zpo4sumn
+         trn(:,:,:,jppo4) = trn(:,:,:,jppo4) * po4mean / zpo4sumn
+
+         IF(lwp) WRITE(numout,*) '       NO3N  mean : ', zno3sumn
+         trn(:,:,:,jpno3) = trn(:,:,:,jpno3) * no3mean / zno3sumn
+
+         IF(lwp) WRITE(numout,*) '       SiO3N mean : ', zsilsumn
+         trn(:,:,:,jpsil) = MIN( 400.e-6,trn(:,:,:,jpsil) * silmean / zsilsumn )
+         !
+         !
+         IF( .NOT. ln_top_euler ) THEN
+            zalksumb = glob_sum( trb(:,:,:,jptal) * cvol(:,:,:)  ) * zarea
+            zpo4sumb = glob_sum( trb(:,:,:,jppo4) * cvol(:,:,:)  ) * zarea * po4r
+            zno3sumb = glob_sum( trb(:,:,:,jpno3) * cvol(:,:,:)  ) * zarea * rno3
+            zsilsumb = glob_sum( trb(:,:,:,jpsil) * cvol(:,:,:)  ) * zarea
+ 
+            IF(lwp) WRITE(numout,*) ' '
+            IF(lwp) WRITE(numout,*) '       TALKB mean : ', zalksumb
+            trb(:,:,:,jptal) = trb(:,:,:,jptal) * alkmean / zalksumb
+
+            IF(lwp) WRITE(numout,*) '       PO4B  mean : ', zpo4sumb
+            trb(:,:,:,jppo4) = trb(:,:,:,jppo4) * po4mean / zpo4sumb
+
+            IF(lwp) WRITE(numout,*) '       NO3B  mean : ', zno3sumb
+            trb(:,:,:,jpno3) = trb(:,:,:,jpno3) * no3mean / zno3sumb
+
+            IF(lwp) WRITE(numout,*) '       SiO3B mean : ', zsilsumb
+            trb(:,:,:,jpsil) = MIN( 400.e-6,trb(:,:,:,jpsil) * silmean / zsilsumb )
+        ENDIF
+        !
+      ENDIF
+        !
+   END SUBROUTINE p4z_dmp
+
+
+   SUBROUTINE p4z_chk_mass( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE p4z_chk_mass  ***
+      !!
+      !! ** Purpose :  Mass conservation check 
+      !!
+      !!---------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in ) ::   kt      ! ocean time-step index      
+      REAL(wp)             ::  zrdenittot, zsdenittot, znitrpottot
+      CHARACTER(LEN=100)   ::   cltxt
+      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zvol
+      INTEGER :: jk
+      !!----------------------------------------------------------------------
+
+      !
+      !!---------------------------------------------------------------------
+
+      IF( kt == nittrc000 ) THEN 
+         IF( ln_check_mass .AND. lwp) THEN      !   Open budget file of NO3, ALK, Si, Fer
+            CALL ctl_opn( numco2, 'carbon.budget'  , 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+            CALL ctl_opn( numnut, 'nutrient.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+            CALL ctl_opn( numnit, 'nitrogen.budget', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
+            xfact1 = rfact2r * 12. / 1.e15 * ryyss    ! conversion molC/kt --> PgC/yr
+            xfact2 = 1.e+3 * rno3 * 14. / 1.e12 * ryyss   ! conversion molC/l/s ----> TgN/m3/yr
+            xfact3 = 1.e+3 * rfact2r * rno3   ! conversion molC/l/kt ----> molN/m3/s
+            cltxt='time-step   Alkalinity        Nitrate        Phosphorus         Silicate           Iron'
+            IF( lwp ) WRITE(numnut,*)  TRIM(cltxt)
+            IF( lwp ) WRITE(numnut,*) 
+         ENDIF
+      ENDIF
+
+      !
+      IF( iom_use( "pno3tot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
+         !   Compute the budget of NO3, ALK, Si, Fer
+         no3budget = glob_sum( (   trn(:,:,:,jpno3) + trn(:,:,:,jpnh4)  &
+            &                    + trn(:,:,:,jpphy) + trn(:,:,:,jpdia)  &
+            &                    + trn(:,:,:,jpzoo) + trn(:,:,:,jpmes)  &
+            &                    + trn(:,:,:,jppoc)                     &
+#if ! defined key_kriest
+            &                    + trn(:,:,:,jpgoc)                     &
+#endif
+            &                    + trn(:,:,:,jpdoc)                     ) * cvol(:,:,:)  )
+         !
+         no3budget = no3budget / areatot
+         CALL iom_put( "pno3tot", no3budget )
+      ENDIF
+      !
+      IF( iom_use( "ppo4tot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
+         po4budget = glob_sum( (   trn(:,:,:,jppo4)                     &
+            &                    + trn(:,:,:,jpphy) + trn(:,:,:,jpdia)  &
+            &                    + trn(:,:,:,jpzoo) + trn(:,:,:,jpmes)  &
+            &                    + trn(:,:,:,jppoc)                     &
+#if ! defined key_kriest
+            &                    + trn(:,:,:,jpgoc)                     &
+#endif
+            &                    + trn(:,:,:,jpdoc)                     ) * cvol(:,:,:)  )
+         po4budget = po4budget / areatot
+         CALL iom_put( "ppo4tot", po4budget )
+      ENDIF
+      !
+      IF( iom_use( "psiltot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
+         silbudget = glob_sum( (   trn(:,:,:,jpsil) + trn(:,:,:,jpgsi)  &
+            &                    + trn(:,:,:,jpdsi)                     ) * cvol(:,:,:)  )
+         !
+         silbudget = silbudget / areatot
+         CALL iom_put( "psiltot", silbudget )
+      ENDIF
+      !
+      IF( iom_use( "palktot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
+         alkbudget = glob_sum( (   trn(:,:,:,jpno3) * rno3              &
+            &                    + trn(:,:,:,jptal)                     &
+            &                    + trn(:,:,:,jpcal) * 2.                ) * cvol(:,:,:)  )
+         !
+         alkbudget = alkbudget / areatot
+         CALL iom_put( "palktot", alkbudget )
+      ENDIF
+      !
+      IF( iom_use( "pfertot" ) .OR. ( ln_check_mass .AND. kt == nitend )  ) THEN
+         ferbudget = glob_sum( (   trn(:,:,:,jpfer) + trn(:,:,:,jpnfe)  &
+            &                    + trn(:,:,:,jpdfe)                     &
+#if ! defined key_kriest
+            &                    + trn(:,:,:,jpbfe)                     &
+#endif
+            &                    + trn(:,:,:,jpsfe)                     &
+            &                    + trn(:,:,:,jpzoo) * ferat3            &
+            &                    + trn(:,:,:,jpmes) * ferat3            ) * cvol(:,:,:)  )
+         !
+         ferbudget = ferbudget / areatot
+         CALL iom_put( "pfertot", ferbudget )
+      ENDIF
+      !
+
+      ! Global budget of N SMS : denitrification in the water column and in the sediment
+      !                          nitrogen fixation by the diazotrophs
+      ! --------------------------------------------------------------------------------
+      IF( iom_use( "tnfix" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
+         znitrpottot  = glob_sum ( nitrpot(:,:,:) * nitrfix * cvol(:,:,:) )
+         CALL iom_put( "tnfix"  , znitrpottot * 1.e+3 * rno3 )  ! Global  nitrogen fixation molC/l  to molN/m3 
+      ENDIF
+      !
+      IF( iom_use( "tdenit" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
+         zrdenittot   = glob_sum ( denitr(:,:,:) * rdenit * xnegtr(:,:,:) * cvol(:,:,:) )
+         CALL iom_put( "tdenit"  , zrdenittot * 1.e+3 * rno3 )  ! Total denitrification molC/l to molN/m3 
+      ENDIF
+      !
+      IF( iom_use( "Sdenit" ) .OR.  ( ln_check_mass .AND. kt == nitend )  ) THEN
+         zsdenittot   = glob_sum ( sdenit(:,:) * e1e2t(:,:) )
+         CALL iom_put( "Sdenit", sdenit(:,:) * xfact3 * tmask(:,:,1) )  ! Nitrate reduction in the sediments
+      ENDIF
+
+      IF( ln_check_mass .AND. kt == nitend ) THEN   ! Compute the budget of NO3, ALK, Si, Fer
+         t_atm_co2_flx  = t_atm_co2_flx / glob_sum( e1e2t(:,:) )
+         t_oce_co2_flx  = t_oce_co2_flx         * xfact1 * (-1 )
+         tpp            = tpp           * 1000. * xfact1
+         t_oce_co2_exp  = t_oce_co2_exp * 1000. * xfact1
+         IF( lwp ) WRITE(numco2,9000) ndastp, t_atm_co2_flx, t_oce_co2_flx, tpp, t_oce_co2_exp
+         IF( lwp ) WRITE(numnut,9100) ndastp, alkbudget        * 1.e+06, &
+             &                                no3budget * rno3 * 1.e+06, &
+             &                                po4budget * po4r * 1.e+06, &
+             &                                silbudget        * 1.e+06, &
+             &                                ferbudget        * 1.e+09
+         !
+         IF( lwp ) WRITE(numnit,9200) ndastp, znitrpottot * xfact2  , &
+         &                             zrdenittot  * xfact2  , &
+         &                             zsdenittot  * xfact2
+
+      ENDIF
+      !
+ 9000  FORMAT(i8,f10.5,e18.10,f10.5,f10.5)
+ 9100  FORMAT(i8,5e18.10)
+ 9200  FORMAT(i8,3f10.5)
+
+       !
+   END SUBROUTINE p4z_chk_mass
+
+#else
+   !!======================================================================
+   !!  Dummy module :                                   No PISCES bio-model
+   !!======================================================================
+CONTAINS
+   SUBROUTINE p4z_sms( kt )                   ! Empty routine
+      INTEGER, INTENT( in ) ::   kt
+      WRITE(*,*) 'p4z_sms: You should not have seen this print! error?', kt
+   END SUBROUTINE p4z_sms
+#endif 
+
+   !!======================================================================
+END MODULE p4zsms 
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv.F90	(revision 5879)
@@ -0,0 +1,248 @@
+MODULE traadv
+   !!==============================================================================
+   !!                       ***  MODULE  traadv  ***
+   !! Ocean active tracers:  advection trend 
+   !!==============================================================================
+   !! History :  2.0  !  2005-11  (G. Madec)  Original code
+   !!            3.3  !  2010-09  (C. Ethe, G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!            4.0  !  2011-06  (G. Madec)  Addition of Mixed Layer Eddy parameterisation
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv      : compute ocean tracer advection trend
+   !!   tra_adv_ctl  : control the different options of advection scheme
+   !!----------------------------------------------------------------------
+   USE oce             ! ocean dynamics and active tracers
+   USE dom_oce         ! ocean space and time domain
+   USE domvvl          ! variable vertical scale factors
+   USE traadv_cen2     ! 2nd order centered scheme (tra_adv_cen2   routine)
+   USE traadv_tvd      ! TVD      scheme           (tra_adv_tvd    routine)
+   USE traadv_muscl    ! MUSCL    scheme           (tra_adv_muscl  routine)
+   USE traadv_muscl2   ! MUSCL2   scheme           (tra_adv_muscl2 routine)
+   USE traadv_ubs      ! UBS      scheme           (tra_adv_ubs    routine)
+   USE traadv_qck      ! QUICKEST scheme           (tra_adv_qck    routine)
+   USE traadv_eiv      ! eddy induced velocity     (tra_adv_eiv    routine)
+   USE traadv_mle      ! ML eddy induced velocity  (tra_adv_mle    routine)
+   USE cla             ! cross land advection      (cla_traadv     routine)
+   USE ldftra_oce      ! lateral diffusion coefficient on tracers
+   !
+   USE in_out_manager  ! I/O manager
+   USE iom             ! I/O module
+   USE prtctl          ! Print control
+   USE lib_mpp         ! MPP library
+   USE wrk_nemo        ! Memory Allocation
+   USE timing          ! Timing
+   USE sbc_oce
+   USE diaptr          ! Poleward heat transport 
+
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv        ! routine called by step module
+   PUBLIC   tra_adv_init   ! routine called by opa module
+
+   !                              !!* Namelist namtra_adv *
+   LOGICAL ::   ln_traadv_cen2     ! 2nd order centered scheme flag
+   LOGICAL ::   ln_traadv_tvd      ! TVD scheme flag
+   LOGICAL ::   ln_traadv_tvd_zts  ! TVD scheme flag with vertical sub time-stepping
+   LOGICAL ::   ln_traadv_muscl    ! MUSCL scheme flag
+   LOGICAL ::   ln_traadv_muscl2   ! MUSCL2 scheme flag
+   LOGICAL ::   ln_traadv_ubs      ! UBS scheme flag
+   LOGICAL ::   ln_traadv_qck      ! QUICKEST scheme flag
+   LOGICAL ::   ln_traadv_msc_ups  ! use upstream scheme within muscl
+
+
+   INTEGER ::   nadv   ! choice of the type of advection scheme
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: traadv.F90 5147 2015-03-13 10:01:32Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tra_adv( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv  ***
+      !!
+      !! ** Purpose :   compute the ocean tracer advection trend.
+      !!
+      !! ** Method  : - Update (ua,va) with the advection term following nadv
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER ::   jk   ! dummy loop index
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zun, zvn, zwn
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_adv')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zun, zvn, zwn )
+      !                                          ! set time step
+      IF( neuler == 0 .AND. kt == nit000 ) THEN     ! at nit000
+         r2dtra(:) =  rdttra(:)                          ! = rdtra (restarting with Euler time stepping)
+      ELSEIF( kt <= nit000 + 1) THEN                ! at nit000 or nit000+1
+         r2dtra(:) = 2._wp * rdttra(:)                   ! = 2 rdttra (leapfrog)
+      ENDIF
+      !
+      ! Add PALEORCA2 configuration -- JBL 08.02.2017
+      IF( nn_cla == 1 .AND. cp_cfg == 'orca' .AND. jp_cfg == 2 )   CALL cla_traadv( kt )       !==  Cross Land Advection  ==! (hor. advection)
+      IF( nn_cla == 1 .AND. cp_cfg == 'paleorca' .AND. jp_cfg == 2 )   CALL cla_traadv( kt )       !==  Cross Land Advection if needed ==! (hor. advection)
+      !
+      !                                               !==  effective transport  ==!
+      DO jk = 1, jpkm1
+         zun(:,:,jk) = e2u(:,:) * fse3u(:,:,jk) * un(:,:,jk)                  ! eulerian transport only
+         zvn(:,:,jk) = e1v(:,:) * fse3v(:,:,jk) * vn(:,:,jk)
+         zwn(:,:,jk) = e1t(:,:) * e2t(:,:)      * wn(:,:,jk)
+      END DO
+      !
+      IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN
+         zun(:,:,:) = zun(:,:,:) + un_td(:,:,:)
+         zvn(:,:,:) = zvn(:,:,:) + vn_td(:,:,:)
+      ENDIF
+      !
+      zun(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
+      zvn(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
+      zwn(:,:,jpk) = 0._wp                                                     ! no transport trough the bottom
+      !
+      IF( lk_traldf_eiv .AND. .NOT. ln_traldf_grif )   &
+         &              CALL tra_adv_eiv( kt, nit000, zun, zvn, zwn, 'TRA' )    ! add the eiv transport (if necessary)
+      !
+      IF( ln_mle    )   CALL tra_adv_mle( kt, nit000, zun, zvn, zwn, 'TRA' )    ! add the mle transport (if necessary)
+      !
+      CALL iom_put( "uocetr_eff", zun )                                         ! output effective transport      
+      CALL iom_put( "vocetr_eff", zvn )
+      CALL iom_put( "wocetr_eff", zwn )
+      !
+      IF( ln_diaptr )   CALL dia_ptr( zvn )                                     ! diagnose the effective MSF 
+      !
+   
+      SELECT CASE ( nadv )                            !==  compute advection trend and add it to general trend  ==!
+      CASE ( 1 )   ;    CALL tra_adv_cen2   ( kt, nit000, 'TRA',         zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  2nd order centered
+      CASE ( 2 )   ;    CALL tra_adv_tvd    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  TVD 
+      CASE ( 3 )   ;    CALL tra_adv_muscl  ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb,      tsa, jpts, ln_traadv_msc_ups )   !  MUSCL 
+      CASE ( 4 )   ;    CALL tra_adv_muscl2 ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  MUSCL2 
+      CASE ( 5 )   ;    CALL tra_adv_ubs    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  UBS 
+      CASE ( 6 )   ;    CALL tra_adv_qck    ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  QUICKEST 
+      CASE ( 7 )   ;    CALL tra_adv_tvd_zts( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )   !  TVD ZTS
+      !
+      CASE (-1 )                                      !==  esopa: test all possibility with control print  ==!
+         CALL tra_adv_cen2  ( kt, nit000, 'TRA',         zun, zvn, zwn, tsb, tsn, tsa, jpts )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv0 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_adv_tvd   ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv1 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_adv_muscl ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb,      tsa, jpts, ln_traadv_msc_ups )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv3 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_adv_muscl2( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv4 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_adv_ubs   ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv5 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+         CALL tra_adv_qck   ( kt, nit000, 'TRA', r2dtra, zun, zvn, zwn, tsb, tsn, tsa, jpts )          
+         CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv6 - Ta: ', mask1=tmask,               &
+            &          tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      END SELECT
+      !
+      !                                              ! print mean trends (used for debugging)
+      IF(ln_ctl)   CALL prt_ctl( tab3d_1=tsa(:,:,:,jp_tem), clinfo1=' adv  - Ta: ', mask1=tmask,               &
+         &                       tab3d_2=tsa(:,:,:,jp_sal), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop( 'tra_adv' )
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zun, zvn, zwn )
+      !                                          
+   END SUBROUTINE tra_adv
+
+
+   SUBROUTINE tra_adv_init
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_init  ***
+      !!                
+      !! ** Purpose :   Control the consistency between namelist options for 
+      !!              tracer advection schemes and set nadv
+      !!----------------------------------------------------------------------
+      INTEGER ::   ioptio
+      INTEGER ::   ios                 ! Local integer output status for namelist read
+      !!
+      NAMELIST/namtra_adv/ ln_traadv_cen2 , ln_traadv_tvd,     &
+         &                 ln_traadv_muscl, ln_traadv_muscl2,  &
+         &                 ln_traadv_ubs  , ln_traadv_qck,     &
+         &                 ln_traadv_msc_ups, ln_traadv_tvd_zts
+      !!----------------------------------------------------------------------
+
+      REWIND( numnam_ref )              ! Namelist namtra_adv in reference namelist : Tracer advection scheme
+      READ  ( numnam_ref, namtra_adv, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_adv in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namtra_adv in configuration namelist : Tracer advection scheme
+      READ  ( numnam_cfg, namtra_adv, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namtra_adv in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namtra_adv )
+
+      IF(lwp) THEN                    ! Namelist print
+         WRITE(numout,*)
+         WRITE(numout,*) 'tra_adv_init : choice/control of the tracer advection scheme'
+         WRITE(numout,*) '~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namtra_adv : chose a advection scheme for tracers'
+         WRITE(numout,*) '      2nd order advection scheme     ln_traadv_cen2    = ', ln_traadv_cen2
+         WRITE(numout,*) '      TVD advection scheme           ln_traadv_tvd     = ', ln_traadv_tvd
+         WRITE(numout,*) '      MUSCL  advection scheme        ln_traadv_muscl   = ', ln_traadv_muscl
+         WRITE(numout,*) '      MUSCL2 advection scheme        ln_traadv_muscl2  = ', ln_traadv_muscl2
+         WRITE(numout,*) '      UBS    advection scheme        ln_traadv_ubs     = ', ln_traadv_ubs
+         WRITE(numout,*) '      QUICKEST advection scheme      ln_traadv_qck     = ', ln_traadv_qck
+         WRITE(numout,*) '      upstream scheme within muscl   ln_traadv_msc_ups = ', ln_traadv_msc_ups
+         WRITE(numout,*) '      TVD advection scheme with zts  ln_traadv_tvd_zts = ', ln_traadv_tvd_zts
+      ENDIF
+
+      ioptio = 0                      ! Parameter control
+      IF( ln_traadv_cen2   )   ioptio = ioptio + 1
+      IF( ln_traadv_tvd    )   ioptio = ioptio + 1
+      IF( ln_traadv_muscl  )   ioptio = ioptio + 1
+      IF( ln_traadv_muscl2 )   ioptio = ioptio + 1
+      IF( ln_traadv_ubs    )   ioptio = ioptio + 1
+      IF( ln_traadv_qck    )   ioptio = ioptio + 1
+      IF( ln_traadv_tvd_zts)   ioptio = ioptio + 1
+      IF( lk_esopa         )   ioptio =          1
+
+      IF( ( ln_traadv_muscl .OR. ln_traadv_muscl2 .OR. ln_traadv_ubs .OR. ln_traadv_qck .OR. ln_traadv_tvd_zts )   &
+         .AND. ln_isfcav )   CALL ctl_stop( 'Only traadv_cen2 and traadv_tvd is compatible with ice shelf cavity')
+
+      IF( ioptio /= 1 )   CALL ctl_stop( 'Choose ONE advection scheme in namelist namtra_adv' )
+
+      !                              ! Set nadv
+      IF( ln_traadv_cen2   )   nadv =  1
+      IF( ln_traadv_tvd    )   nadv =  2
+      IF( ln_traadv_muscl  )   nadv =  3
+      IF( ln_traadv_muscl2 )   nadv =  4
+      IF( ln_traadv_ubs    )   nadv =  5
+      IF( ln_traadv_qck    )   nadv =  6
+      IF( ln_traadv_tvd_zts)   nadv =  7
+      IF( lk_esopa         )   nadv = -1
+
+      IF(lwp) THEN                   ! Print the choice
+         WRITE(numout,*)
+         IF( nadv ==  1 )   WRITE(numout,*) '         2nd order scheme is used'
+         IF( nadv ==  2 )   WRITE(numout,*) '         TVD       scheme is used'
+         IF( nadv ==  3 )   WRITE(numout,*) '         MUSCL     scheme is used'
+         IF( nadv ==  4 )   WRITE(numout,*) '         MUSCL2    scheme is used'
+         IF( nadv ==  5 )   WRITE(numout,*) '         UBS       scheme is used'
+         IF( nadv ==  6 )   WRITE(numout,*) '         QUICKEST  scheme is used'
+         IF( nadv ==  7 )   WRITE(numout,*) '         TVD ZTS   scheme is used'
+         IF( nadv == -1 )   WRITE(numout,*) '         esopa test: use all advection scheme'
+      ENDIF
+      !
+      CALL tra_adv_mle_init          ! initialisation of the Mixed Layer Eddy parametrisation (MLE)
+      !
+   END SUBROUTINE tra_adv_init
+
+  !!======================================================================
+END MODULE traadv
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv_tvd.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv_tvd.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/traadv_tvd.F90	(revision 5879)
@@ -0,0 +1,682 @@
+MODULE traadv_tvd
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_tvd  ***
+   !! Ocean  tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  OPA  !  1995-12  (L. Mortier)  Original code
+   !!                 !  2000-01  (H. Loukos)  adapted to ORCA 
+   !!                 !  2000-10  (MA Foujols E.Kestenare)  include file not routine
+   !!                 !  2000-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
+   !!                 !  2001-07  (E. Durand G. Madec)  adaptation to ORCA config
+   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
+   !!    NEMO    1.0  !  2004-01  (A. de Miranda, G. Madec, J.M. Molines ): advective bbl
+   !!            2.0  !  2008-04  (S. Cravatte) add the i-, j- & k- trends computation
+   !!             -   !  2009-11  (V. Garnier) Surface pressure gradient organization
+   !!            3.3  !  2010-05  (C. Ethe, G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_tvd   : update the tracer trend with the 3D advection trends using a TVD scheme
+   !!   nonosc        : compute monotonic tracer fluxes by a non-oscillatory algorithm 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! tracers trends
+   USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
+   USE diaptr         ! poleward transport diagnostics
+   !
+   USE lib_mpp        ! MPP library
+   USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
+   USE in_out_manager ! I/O manager
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_tvd        ! routine called by traadv.F90
+   PUBLIC   tra_adv_tvd_zts    ! routine called by traadv.F90
+
+   LOGICAL ::   l_trd   ! flag to compute trends
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: traadv_tvd.F90 6692 2016-06-13 14:39:24Z flavoni $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tra_adv_tvd ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
+      &                                       ptb, ptn, pta, kjpt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_tvd  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - update (pta) with the now advective tracer trends
+      !!             - save the trends 
+      !!----------------------------------------------------------------------
+      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
+      !
+      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
+      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
+      !
+      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices
+      INTEGER  ::   ik  
+      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz )
+      !
+      IF( kt == kit000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_tvd : TVD advection scheme on ', cdtype
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         !
+         l_trd = .FALSE.
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
+      ENDIF
+      !
+      IF( l_trd )  THEN
+         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+         ztrdx(:,:,:) = 0.e0   ;    ztrdy(:,:,:) = 0.e0   ;   ztrdz(:,:,:) = 0.e0
+      ENDIF
+      !
+      zwi(:,:,:) = 0.e0 ; 
+      !
+      !                                                          ! ===========
+      DO jn = 1, kjpt                                            ! tracer loop
+         !                                                       ! ===========
+         ! 1. Bottom and k=1 value : flux set to zero
+         ! ----------------------------------
+         zwx(:,:,jpk) = 0.e0    ;    zwz(:,:,jpk) = 0.e0
+         zwy(:,:,jpk) = 0.e0    ;    zwi(:,:,jpk) = 0.e0
+          
+         zwz(:,:,1  ) = 0._wp
+         ! 2. upstream advection with initial mass fluxes & intermediate update
+         ! --------------------------------------------------------------------
+         ! upstream tracer flux in the i and j direction
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! upstream scheme
+                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
+                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
+                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
+                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
+                  zwx(ji,jj,jk) = 0.5 * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5 * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
+               END DO
+            END DO
+         END DO
+
+         ! upstream tracer flux in the k direction
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
+                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
+                  zwz(ji,jj,jk) = 0.5 * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) ) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! Surface value
+         IF( lk_vvl ) THEN   
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = 0.e0          ! volume variable
+            END IF
+         ELSE                
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface 
+                  END DO
+               END DO   
+            ELSE
+               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)   ! linear free surface
+            END IF
+         ENDIF
+
+         ! total advective trend
+         DO jk = 1, jpkm1
+            z2dtt = p2dt(jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! total intermediate advective trends
+                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
+                  ! update and guess with monotonic sheme
+                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
+         CALL lbc_lnk( zwi, 'T', 1. )  
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ! store intermediate advective trends
+            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
+         ENDIF
+
+         ! 3. antidiffusive flux : high order minus low order
+         ! --------------------------------------------------
+         ! antidiffusive flux on i and j
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx(ji,jj,jk) = 0.5 * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) ) - zwx(ji,jj,jk)
+                  zwy(ji,jj,jk) = 0.5 * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) ) - zwy(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      
+         ! antidiffusive flux on k
+         ! Interior value
+         DO jk = 2, jpkm1                    
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zwz(ji,jj,jk) = 0.5 * pwn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj,jk-1,jn) ) - zwz(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! surface value
+         IF ( ln_isfcav ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zwz(ji,jj,mikt(ji,jj)) = 0.e0
+               END DO
+            END DO
+         ELSE
+            zwz(:,:,1) = 0.e0
+         END IF
+         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
+         CALL lbc_lnk( zwz, 'W',  1. )
+
+         ! 4. monotonicity algorithm
+         ! -------------------------
+         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
+
+
+         ! 5. final trend with corrected fluxes
+         ! ------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.  
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ! total advective trends
+                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                  ! add them to the general tracer trends
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
+            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
+            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
+            
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
+         ENDIF
+         !
+      END DO
+      !
+                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz )
+      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd')
+      !
+   END SUBROUTINE tra_adv_tvd
+
+   SUBROUTINE tra_adv_tvd_zts ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
+      &                                       ptb, ptn, pta, kjpt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_tvd_zts  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD ZTS scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction). This version use sub-
+      !!       timestepping for the vertical advection which increases stability
+      !!       when vertical metrics are small.
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - update (pta) with the now advective tracer trends
+      !!             - save the trends 
+      !!----------------------------------------------------------------------
+      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
+      !
+      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
+      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
+      !
+      REAL(wp), DIMENSION( jpk )                           ::   zts             ! length of sub-timestep for vertical advection
+      REAL(wp), DIMENSION( jpk )                           ::   zr_p2dt         ! reciprocal of tracer timestep
+      INTEGER  ::   ji, jj, jk, jl, jn       ! dummy loop indices  
+      INTEGER  ::   jnzts = 5       ! number of sub-timesteps for vertical advection
+      INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
+      INTEGER  ::   jtaken          ! toggle for collecting appropriate fluxes from sub timesteps
+      REAL(wp) ::   z_rzts          ! Fractional length of Euler forward sub-timestep for vertical advection
+      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zwx_sav , zwy_sav
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz, zhdiv, zwz_sav, zwzts
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrs
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd_zts')
+      !
+      CALL wrk_alloc( jpi, jpj, zwx_sav, zwy_sav )
+      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz , zhdiv, zwz_sav, zwzts )
+      CALL wrk_alloc( jpi, jpj, jpk, kjpt+1, ztrs )
+      !
+      IF( kt == kit000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_tvd_zts : TVD ZTS advection scheme on ', cdtype
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      !
+      l_trd = .FALSE.
+      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
+      !
+      IF( l_trd )  THEN
+         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+         ztrdx(:,:,:) = 0._wp  ;    ztrdy(:,:,:) = 0._wp  ;   ztrdz(:,:,:) = 0._wp
+      ENDIF
+      !
+      zwi(:,:,:) = 0._wp
+      z_rzts = 1._wp / REAL( jnzts, wp )
+      zr_p2dt(:) = 1._wp / p2dt(:)
+      !
+      !                                                          ! ===========
+      DO jn = 1, kjpt                                            ! tracer loop
+         !                                                       ! ===========
+         ! 1. Bottom value : flux set to zero
+         ! ----------------------------------
+         zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
+         zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
+
+         ! 2. upstream advection with initial mass fluxes & intermediate update
+         ! --------------------------------------------------------------------
+         ! upstream tracer flux in the i and j direction
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! upstream scheme
+                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
+                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
+                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
+                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
+                  zwx(ji,jj,jk) = 0.5_wp * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5_wp * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
+               END DO
+            END DO
+         END DO
+
+         ! upstream tracer flux in the k direction
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
+                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
+                  zwz(ji,jj,jk) = 0.5_wp * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) )
+               END DO
+            END DO
+         END DO
+         ! Surface value
+         IF( lk_vvl ) THEN
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable +    isf
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = 0.e0                              ! volume variable + no isf
+            END IF
+         ELSE
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface +    isf
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)                                               ! linear free surface + no isf
+            END IF
+         ENDIF
+
+         ! total advective trend
+         DO jk = 1, jpkm1
+            z2dtt = p2dt(jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! total intermediate advective trends
+                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
+                  ! update and guess with monotonic sheme
+                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
+         CALL lbc_lnk( zwi, 'T', 1. )  
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ! store intermediate advective trends
+            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
+         ENDIF
+
+         ! 3. antidiffusive flux : high order minus low order
+         ! --------------------------------------------------
+         ! antidiffusive flux on i and j
+         !
+         DO jk = 1, jpkm1
+            !
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx_sav(ji,jj) = zwx(ji,jj,jk)
+                  zwy_sav(ji,jj) = zwy(ji,jj,jk)
+
+                  zwx(ji,jj,jk) = 0.5_wp * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5_wp * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) )
+               END DO
+            END DO
+
+            DO jj = 2, jpjm1         ! partial horizontal divergence
+               DO ji = fs_2, fs_jpim1
+                  zhdiv(ji,jj,jk) = (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
+                     &               + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
+               END DO
+            END DO
+
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx(ji,jj,jk) = zwx(ji,jj,jk)  - zwx_sav(ji,jj)
+                  zwy(ji,jj,jk) = zwy(ji,jj,jk)  - zwy_sav(ji,jj)
+               END DO
+            END DO
+         END DO
+      
+         ! antidiffusive flux on k
+         zwz(:,:,1) = 0._wp        ! Surface value
+         zwz_sav(:,:,:) = zwz(:,:,:)
+         !
+         ztrs(:,:,:,1) = ptb(:,:,:,jn)
+         zwzts(:,:,:) = 0._wp
+
+         DO jl = 1, jnzts                   ! Start of sub timestepping loop
+
+            IF( jl == 1 ) THEN              ! Euler forward to kick things off
+              jtb = 1   ;   jtn = 1   ;   jta = 2
+              zts(:) = p2dt(:) * z_rzts
+              jtaken = MOD( jnzts + 1 , 2)  ! Toggle to collect every second flux
+                                            ! starting at jl =1 if jnzts is odd; 
+                                            ! starting at jl =2 otherwise
+            ELSEIF( jl == 2 ) THEN          ! First leapfrog step
+              jtb = 1   ;   jtn = 2   ;   jta = 3
+              zts(:) = 2._wp * p2dt(:) * z_rzts
+            ELSE                            ! Shuffle pointers for subsequent leapfrog steps
+              jtb = MOD(jtb,3) + 1
+              jtn = MOD(jtn,3) + 1
+              jta = MOD(jta,3) + 1
+            ENDIF
+            DO jk = 2, jpkm1          ! Interior value
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zwz(ji,jj,jk) = 0.5_wp * pwn(ji,jj,jk) * ( ztrs(ji,jj,jk,jtn) + ztrs(ji,jj,jk-1,jtn) )
+                     IF( jtaken == 0 ) zwzts(ji,jj,jk) = zwzts(ji,jj,jk) + zwz(ji,jj,jk)*zts(jk)           ! Accumulate time-weighted vertcal flux
+                  END DO
+               END DO
+            END DO
+
+            jtaken = MOD( jtaken + 1 , 2 )
+
+            DO jk = 2, jpkm1          ! Interior value
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zbtr = 1._wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     ! total advective trends
+                     ztra = - zbtr * (  zhdiv(ji,jj,jk) + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                     ztrs(ji,jj,jk,jta) = ztrs(ji,jj,jk,jtb) + zts(jk) * ztra
+                  END DO
+               END DO
+            END DO
+
+         END DO
+
+         DO jk = 2, jpkm1          ! Anti-diffusive vertical flux using average flux from the sub-timestepping
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zwz(ji,jj,jk) = zwzts(ji,jj,jk) * zr_p2dt(jk) - zwz_sav(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
+         CALL lbc_lnk( zwz, 'W',  1. )
+
+         ! 4. monotonicity algorithm
+         ! -------------------------
+         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
+
+
+         ! 5. final trend with corrected fluxes
+         ! ------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.  
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ! total advective trends
+                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                  ! add them to the general tracer trends
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
+               END DO
+            END DO
+         END DO
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
+            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
+            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
+            
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
+         ENDIF
+         !
+      END DO
+      !
+                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz, zhdiv, zwz_sav, zwzts )
+                   CALL wrk_dealloc( jpi, jpj, jpk, kjpt+1, ztrs )
+                   CALL wrk_dealloc( jpi, jpj, zwx_sav, zwy_sav )
+      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd_zts')
+      !
+   END SUBROUTINE tra_adv_tvd_zts
+
+
+   SUBROUTINE nonosc( pbef, paa, pbb, pcc, paft, p2dt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc  ***
+      !!     
+      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
+      !!       scheme and the before field by a nonoscillatory algorithm 
+      !!
+      !! **  Method  :   ... ???
+      !!       warning : pbef and paft must be masked, but the boundaries
+      !!       conditions on the fluxes are not necessary zalezak (1979)
+      !!       drange (1995) multi-dimensional forward-in-time and upstream-
+      !!       in-space based differencing for fluid
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpk)         , INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pbef, paft      ! before & after field
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(inout) ::   paa, pbb, pcc   ! monotonic fluxes in the 3 directions
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   ikm1         ! local integer
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
+      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo, zbup, zbdo
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('nonosc')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
+      !
+      zbig  = 1.e+40_wp
+      zrtrn = 1.e-15_wp
+      zbetup(:,:,:) = 0._wp   ;   zbetdo(:,:,:) = 0._wp
+
+      ! Search local extrema
+      ! --------------------
+      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
+      zbup = MAX( pbef * tmask - zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask - zbig * ( 1._wp - tmask )  )
+      zbdo = MIN( pbef * tmask + zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask + zbig * ( 1._wp - tmask )  )
+
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         z2dtt = p2dt(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               ! search maximum in neighbourhood
+               zup = MAX(  zbup(ji  ,jj  ,jk  ),   &
+                  &        zbup(ji-1,jj  ,jk  ), zbup(ji+1,jj  ,jk  ),   &
+                  &        zbup(ji  ,jj-1,jk  ), zbup(ji  ,jj+1,jk  ),   &
+                  &        zbup(ji  ,jj  ,ikm1), zbup(ji  ,jj  ,jk+1)  )
+
+               ! search minimum in neighbourhood
+               zdo = MIN(  zbdo(ji  ,jj  ,jk  ),   &
+                  &        zbdo(ji-1,jj  ,jk  ), zbdo(ji+1,jj  ,jk  ),   &
+                  &        zbdo(ji  ,jj-1,jk  ), zbdo(ji  ,jj+1,jk  ),   &
+                  &        zbdo(ji  ,jj  ,ikm1), zbdo(ji  ,jj  ,jk+1)  )
+
+               ! positive part of the flux
+               zpos = MAX( 0., paa(ji-1,jj  ,jk  ) ) - MIN( 0., paa(ji  ,jj  ,jk  ) )   &
+                  & + MAX( 0., pbb(ji  ,jj-1,jk  ) ) - MIN( 0., pbb(ji  ,jj  ,jk  ) )   &
+                  & + MAX( 0., pcc(ji  ,jj  ,jk+1) ) - MIN( 0., pcc(ji  ,jj  ,jk  ) )
+
+               ! negative part of the flux
+               zneg = MAX( 0., paa(ji  ,jj  ,jk  ) ) - MIN( 0., paa(ji-1,jj  ,jk  ) )   &
+                  & + MAX( 0., pbb(ji  ,jj  ,jk  ) ) - MIN( 0., pbb(ji  ,jj-1,jk  ) )   &
+                  & + MAX( 0., pcc(ji  ,jj  ,jk  ) ) - MIN( 0., pcc(ji  ,jj  ,jk+1) )
+
+               ! up & down beta terms
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
+               zbetup(ji,jj,jk) = ( zup            - paft(ji,jj,jk) ) / ( zpos + zrtrn ) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zdo            ) / ( zneg + zrtrn ) * zbt
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( zbetup, 'T', 1. )   ;   CALL lbc_lnk( zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
+
+      ! 3. monotonic flux in the i & j direction (paa & pbb)
+      ! ----------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zau = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
+               zbu = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
+               zcu =       ( 0.5  + SIGN( 0.5 , paa(ji,jj,jk) ) )
+               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zcu * zau + ( 1._wp - zcu) * zbu )
+
+               zav = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
+               zbv = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
+               zcv =       ( 0.5  + SIGN( 0.5 , pbb(ji,jj,jk) ) )
+               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zcv * zav + ( 1._wp - zcv) * zbv )
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+               za = MIN( 1., zbetdo(ji,jj,jk+1), zbetup(ji,jj,jk) )
+               zb = MIN( 1., zbetup(ji,jj,jk+1), zbetdo(ji,jj,jk) )
+               zc =       ( 0.5  + SIGN( 0.5 , pcc(ji,jj,jk+1) ) )
+               pcc(ji,jj,jk+1) = pcc(ji,jj,jk+1) * ( zc * za + ( 1._wp - zc) * zb )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( paa, 'U', -1. )   ;   CALL lbc_lnk( pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('nonosc')
+      !
+   END SUBROUTINE nonosc
+
+   !!======================================================================
+END MODULE traadv_tvd
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/zdftmx.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/zdftmx.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/PALEO/zdftmx.F90	(revision 5879)
@@ -0,0 +1,1070 @@
+MODULE zdftmx
+   !!========================================================================
+   !!                       ***  MODULE  zdftmx  ***
+   !! Ocean physics: vertical tidal mixing coefficient
+   !!========================================================================
+   !! History :  1.0  !  2004-04  (L. Bessieres, G. Madec)  Original code
+   !!             -   !  2006-08  (A. Koch-Larrouy) Indonesian strait
+   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
+   !!----------------------------------------------------------------------
+#if defined key_zdftmx   ||   defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_zdftmx'                                  Tidal vertical mixing
+   !!----------------------------------------------------------------------
+   !!   zdf_tmx       : global     momentum & tracer Kz with tidal induced Kz
+   !!   tmx_itf       : Indonesian momentum & tracer Kz with tidal induced Kz 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE eosbn2         ! ocean equation of state
+   USE phycst         ! physical constants
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O Manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_tmx         ! called in step module 
+   PUBLIC   zdf_tmx_init    ! called in opa module 
+   PUBLIC   zdf_tmx_alloc   ! called in nemogcm module
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .TRUE.    !: tidal mixing flag
+
+   !                       !!* Namelist  namzdf_tmx : tidal mixing *
+   REAL(wp) ::  rn_htmx     ! vertical decay scale for turbulence (meters)
+   REAL(wp) ::  rn_n2min    ! threshold of the Brunt-Vaisala frequency (s-1)
+   REAL(wp) ::  rn_tfe      ! tidal dissipation efficiency (St Laurent et al. 2002)
+   REAL(wp) ::  rn_me       ! mixing efficiency (Osborn 1980)
+   LOGICAL  ::  ln_tmx_itf  ! Indonesian Through Flow (ITF): Koch-Larrouy et al. (2007) parameterization
+   REAL(wp) ::  rn_tfe_itf  ! ITF tidal dissipation efficiency (St Laurent et al. 2002)
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   en_tmx     ! energy available for tidal mixing (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   mask_itf   ! mask to use over Indonesian area
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   az_tmx     ! coefficient used to evaluate the tidal induced Kz
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
+   !! $Id: zdftmx.F90 6314 2016-02-15 12:04:56Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION zdf_tmx_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION zdf_tmx_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE(en_tmx(jpi,jpj), mask_itf(jpi,jpj), az_tmx(jpi,jpj,jpk), STAT=zdf_tmx_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( zdf_tmx_alloc )
+      IF( zdf_tmx_alloc /= 0 )   CALL ctl_warn('zdf_tmx_alloc: failed to allocate arrays')
+   END FUNCTION zdf_tmx_alloc
+
+
+   SUBROUTINE zdf_tmx( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_tmx  ***
+      !!                   
+      !! ** Purpose :   add to the vertical mixing coefficients the effect of
+      !!              tidal mixing (Simmons et al 2004).
+      !!
+      !! ** Method  : - tidal-induced vertical mixing is given by:
+      !!                  Kz_tides = az_tmx / max( rn_n2min, N^2 )
+      !!              where az_tmx is a coefficient that specified the 3D space 
+      !!              distribution of the faction of tidal energy taht is used
+      !!              for mixing. Its expression is set in zdf_tmx_init routine,
+      !!              following Simmons et al. 2004.
+      !!                NB: a specific bounding procedure is performed on av_tide
+      !!              so that the input tidal energy is actually almost used. The
+      !!              basic maximum value is 60 cm2/s, but values of 300 cm2/s 
+      !!              can be reached in area where bottom stratification is too 
+      !!              weak.
+      !!
+      !!              - update av_tide in the Indonesian Through Flow area
+      !!              following Koch-Larrouy et al. (2007) parameterisation
+      !!              (see tmx_itf routine).
+      !!
+      !!              - update the model vertical eddy viscosity and diffusivity: 
+      !!                     avt  = avt  +    av_tides
+      !!                     avm  = avm  +    av_tides
+      !!                     avmu = avmu + mi(av_tides)
+      !!                     avmv = avmv + mj(av_tides)
+      !!
+      !! ** Action  :   avt, avm, avmu, avmv   increased by tidal mixing
+      !!
+      !! References : Simmons et al. 2004, Ocean Modelling, 6, 3-4, 245-263.
+      !!              Koch-Larrouy et al. 2007, GRL.
+      !!----------------------------------------------------------------------
+      USE oce, zav_tide  =>   ua    ! use ua as workspace
+      !!
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step 
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   ztpc         ! scalar workspace
+      REAL(wp), POINTER, DIMENSION(:,:) ::   zkz
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx')
+      !
+      CALL wrk_alloc( jpi,jpj, zkz )
+
+      !                          ! ----------------------- !
+      !                          !  Standard tidal mixing  !  (compute zav_tide)
+      !                          ! ----------------------- !
+      !                             !* First estimation (with n2 bound by rn_n2min) bounded by 60 cm2/s
+      zav_tide(:,:,:) = MIN(  60.e-4, az_tmx(:,:,:) / MAX( rn_n2min, rn2(:,:,:) )  )
+
+      zkz(:,:) = 0.e0               !* Associated potential energy consummed over the whole water column
+      DO jk = 2, jpkm1
+         zkz(:,:) = zkz(:,:) + fse3w(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zav_tide(:,:,jk) * wmask(:,:,jk)
+      END DO
+
+      DO jj = 1, jpj                !* Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
+         DO ji = 1, jpi
+            IF( zkz(ji,jj) /= 0.e0 )   zkz(ji,jj) = en_tmx(ji,jj) / zkz(ji,jj)
+         END DO
+      END DO
+
+      DO jk = 2, jpkm1     !* Mutiply by zkz to recover en_tmx, BUT bound by 30/6 ==> zav_tide bound by 300 cm2/s
+         DO jj = 1, jpj                !* Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
+            DO ji = 1, jpi
+               zav_tide(ji,jj,jk) = zav_tide(ji,jj,jk) * MIN( zkz(ji,jj), 30./6. ) * wmask(ji,jj,jk)  !kz max = 300 cm2/s
+            END DO
+         END DO
+      END DO
+
+      IF( kt == nit000 ) THEN       !* check at first time-step: diagnose the energy consumed by zav_tide
+         ztpc = 0.e0
+         DO jk= 1, jpk
+            DO jj= 1, jpj
+               DO ji= 1, jpi
+                  ztpc = ztpc + fse3w(ji,jj,jk) * e1t(ji,jj) * e2t(ji,jj)   &
+                     &         * MAX( 0.e0, rn2(ji,jj,jk) ) * zav_tide(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         ztpc= rau0 / ( rn_tfe * rn_me ) * ztpc
+         IF(lwp) WRITE(numout,*) 
+         IF(lwp) WRITE(numout,*) '          N Total power consumption by av_tide    : ztpc = ', ztpc * 1.e-12 ,'TW'
+      ENDIF
+       
+      !                          ! ----------------------- !
+      !                          !    ITF  tidal mixing    !  (update zav_tide)
+      !                          ! ----------------------- !
+      IF( ln_tmx_itf )   CALL tmx_itf( kt, zav_tide )
+
+      !                          ! ----------------------- !
+      !                          !   Update  mixing coefs  !                          
+      !                          ! ----------------------- !
+      DO jk = 2, jpkm1              !* update momentum & tracer diffusivity with tidal mixing
+         DO jj = 1, jpj                !* Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
+            DO ji = 1, jpi
+               avt(ji,jj,jk) = avt(ji,jj,jk) + zav_tide(ji,jj,jk) * wmask(ji,jj,jk)
+               avm(ji,jj,jk) = avm(ji,jj,jk) + zav_tide(ji,jj,jk) * wmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      
+      DO jk = 2, jpkm1              !* update momentum & tracer diffusivity with tidal mixing
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1  ! vector opt.
+               avmu(ji,jj,jk) = avmu(ji,jj,jk) + 0.5 * ( zav_tide(ji,jj,jk) + zav_tide(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
+               avmv(ji,jj,jk) = avmv(ji,jj,jk) + 0.5 * ( zav_tide(ji,jj,jk) + zav_tide(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! lateral boundary condition
+
+      !                             !* output tidal mixing coefficient
+      CALL iom_put( "av_tide", zav_tide )
+      !                             !* output useful diagnostic (see zdf_tmx_new)
+      !                             !* Kz is cst - only need BV frequency
+      !                             !* JBL 28.04.20
+      CALL iom_put( "bn2", rn2 )
+
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=zav_tide , clinfo1=' tmx - av_tide: ', tab3d_2=avt, clinfo2=' avt: ', ovlap=1, kdim=jpk)
+      !
+      CALL wrk_dealloc( jpi,jpj, zkz )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx')
+      !
+   END SUBROUTINE zdf_tmx
+
+
+   SUBROUTINE tmx_itf( kt, pav )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tmx_itf  ***
+      !!                   
+      !! ** Purpose :   modify the vertical eddy diffusivity coefficients 
+      !!              (pav) in the Indonesian Through Flow area (ITF).
+      !!
+      !! ** Method  : - Following Koch-Larrouy et al. (2007), in the ITF defined
+      !!                by msk_itf (read in a file, see tmx_init), the tidal
+      !!                mixing coefficient is computed with :
+      !!                  * q=1 (i.e. all the tidal energy remains trapped in
+      !!                         the area and thus is used for mixing)
+      !!                  * the vertical distribution of the tifal energy is a
+      !!                    proportional to N above the thermocline (d(N^2)/dz > 0)
+      !!                    and to N^2 below the thermocline (d(N^2)/dz < 0)
+      !!
+      !! ** Action  :   av_tide   updated in the ITF area (msk_itf)
+      !!
+      !! References :  Koch-Larrouy et al. 2007, GRL 
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                         ::   kt   ! ocean time-step
+      REAL(wp), INTENT(inout), DIMENSION(jpi,jpj,jpk) ::   pav  ! Tidal mixing coef.
+      !! 
+      INTEGER  ::   ji, jj, jk    ! dummy loop indices
+      REAL(wp) ::   zcoef, ztpc   ! temporary scalar
+      REAL(wp), DIMENSION(:,:)  , POINTER ::   zkz                        ! 2D workspace
+      REAL(wp), DIMENSION(:,:)  , POINTER ::   zsum1 , zsum2 , zsum       !  -      -
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   zempba_3d_1, zempba_3d_2   ! 3D workspace
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   zempba_3d  , zdn2dz        !  -      -
+      REAL(wp), DIMENSION(:,:,:), POINTER ::   zavt_itf                   !  -      -
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tmx_itf')
+      !
+      CALL wrk_alloc( jpi,jpj, zkz, zsum1 , zsum2 , zsum )
+      CALL wrk_alloc( jpi,jpj,jpk, zempba_3d_1, zempba_3d_2, zempba_3d, zdn2dz, zavt_itf )
+
+      !                             ! compute the form function using N2 at each time step
+      zempba_3d_1(:,:,jpk) = 0.e0
+      zempba_3d_2(:,:,jpk) = 0.e0
+      DO jk = 1, jpkm1             
+         zdn2dz     (:,:,jk) = rn2(:,:,jk) - rn2(:,:,jk+1)           ! Vertical profile of dN2/dz
+!CDIR NOVERRCHK
+         zempba_3d_1(:,:,jk) = SQRT(  MAX( 0.e0, rn2(:,:,jk) )  )    !    -        -    of N
+         zempba_3d_2(:,:,jk) =        MAX( 0.e0, rn2(:,:,jk) )       !    -        -    of N^2
+      END DO
+      !
+      zsum (:,:) = 0.e0
+      zsum1(:,:) = 0.e0
+      zsum2(:,:) = 0.e0
+      DO jk= 2, jpk
+         zsum1(:,:) = zsum1(:,:) + zempba_3d_1(:,:,jk) * fse3w(:,:,jk) * tmask(:,:,jk) * tmask(:,:,jk-1)
+         zsum2(:,:) = zsum2(:,:) + zempba_3d_2(:,:,jk) * fse3w(:,:,jk) * tmask(:,:,jk) * tmask(:,:,jk-1)               
+      END DO
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( zsum1(ji,jj) /= 0.e0 )   zsum1(ji,jj) = 1.e0 / zsum1(ji,jj)
+            IF( zsum2(ji,jj) /= 0.e0 )   zsum2(ji,jj) = 1.e0 / zsum2(ji,jj)                
+         END DO
+      END DO
+
+      DO jk= 1, jpk
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zcoef = 0.5 - SIGN( 0.5, zdn2dz(ji,jj,jk) )       ! =0 if dN2/dz > 0, =1 otherwise 
+               ztpc  = zempba_3d_1(ji,jj,jk) * zsum1(ji,jj) *        zcoef     &
+                  &  + zempba_3d_2(ji,jj,jk) * zsum2(ji,jj) * ( 1. - zcoef )
+               !
+               zempba_3d(ji,jj,jk) =               ztpc 
+               zsum     (ji,jj)    = zsum(ji,jj) + ztpc * fse3w(ji,jj,jk)
+            END DO
+         END DO
+       END DO
+       DO jj = 1, jpj
+          DO ji = 1, jpi
+             IF( zsum(ji,jj) > 0.e0 )   zsum(ji,jj) = 1.e0 / zsum(ji,jj)                
+          END DO
+       END DO
+
+      !                             ! first estimation bounded by 10 cm2/s (with n2 bounded by rn_n2min) 
+      zcoef = rn_tfe_itf / ( rn_tfe * rau0 )
+      DO jk = 1, jpk
+         zavt_itf(:,:,jk) = MIN(  10.e-4, zcoef * en_tmx(:,:) * zsum(:,:) * zempba_3d(:,:,jk)   &
+            &                                      / MAX( rn_n2min, rn2(:,:,jk) ) * tmask(:,:,jk)  )
+      END DO           
+
+      zkz(:,:) = 0.e0               ! Associated potential energy consummed over the whole water column
+      DO jk = 2, jpkm1
+         zkz(:,:) = zkz(:,:) + fse3w(:,:,jk) * MAX( 0.e0, rn2(:,:,jk) ) * rau0 * zavt_itf(:,:,jk) * tmask(:,:,jk) * tmask(:,:,jk-1)
+      END DO
+
+      DO jj = 1, jpj                ! Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz to recover en_tmx
+         DO ji = 1, jpi
+            IF( zkz(ji,jj) /= 0.e0 )   zkz(ji,jj) = en_tmx(ji,jj) * rn_tfe_itf / rn_tfe / zkz(ji,jj)
+         END DO
+      END DO
+
+      DO jk = 2, jpkm1              ! Mutiply by zkz to recover en_tmx, BUT bound by 30/6 ==> zavt_itf bound by 300 cm2/s
+         zavt_itf(:,:,jk) = zavt_itf(:,:,jk) * MIN( zkz(:,:), 120./10. ) * tmask(:,:,jk) * tmask(:,:,jk-1)   ! kz max = 120 cm2/s
+      END DO
+
+      IF( kt == nit000 ) THEN       ! diagnose the nergy consumed by zavt_itf
+         ztpc = 0.e0
+         DO jk= 1, jpk
+            DO jj= 1, jpj
+               DO ji= 1, jpi
+                  ztpc = ztpc + e1t(ji,jj) * e2t(ji,jj) * fse3w(ji,jj,jk) * MAX( 0.e0, rn2(ji,jj,jk) )   &
+                     &                     * zavt_itf(ji,jj,jk) * tmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         ztpc= rau0 * ztpc / ( rn_me * rn_tfe_itf )
+         IF(lwp) WRITE(numout,*) '          N Total power consumption by zavt_itf: ztpc = ', ztpc * 1.e-12 ,'TW'
+      ENDIF
+
+      !                             ! Update pav with the ITF mixing coefficient
+      DO jk = 2, jpkm1
+         pav(:,:,jk) = pav     (:,:,jk) * ( 1.e0 - mask_itf(:,:) )   &
+            &        + zavt_itf(:,:,jk) *          mask_itf(:,:) 
+      END DO
+      !
+      CALL wrk_dealloc( jpi,jpj, zkz, zsum1 , zsum2 , zsum )
+      CALL wrk_dealloc( jpi,jpj,jpk, zempba_3d_1, zempba_3d_2, zempba_3d, zdn2dz, zavt_itf )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tmx_itf')
+      !
+   END SUBROUTINE tmx_itf
+
+
+   SUBROUTINE zdf_tmx_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_tmx_init  ***
+      !!                     
+      !! ** Purpose :   Initialization of the vertical tidal mixing, Reading
+      !!              of M2 and K1 tidal energy in nc files
+      !!
+      !! ** Method  : - Read the namtmx namelist and check the parameters
+      !!
+      !!              - Read the input data in NetCDF files :
+      !!              M2 and K1 tidal energy. The total tidal energy, en_tmx, 
+      !!              is the sum of M2, K1 and S2 energy where S2 is assumed 
+      !!              to be: S2=(1/2)^2 * M2
+      !!              mask_itf, a mask array that determine where substituing 
+      !!              the standard Simmons et al. (2005) formulation with the
+      !!              one of Koch_Larrouy et al. (2007).
+      !!
+      !!              - Compute az_tmx, a 3D coefficient that allows to compute
+      !!             the standard tidal-induced vertical mixing as follows:
+      !!                  Kz_tides = az_tmx / max( rn_n2min, N^2 )
+      !!             with az_tmx a bottom intensified coefficient is given by:
+      !!                 az_tmx(z) = en_tmx / ( rau0 * rn_htmx ) * EXP( -(H-z)/rn_htmx )
+      !!                                                  / ( 1. - EXP( - H   /rn_htmx ) ) 
+      !!             where rn_htmx the characteristic length scale of the bottom 
+      !!             intensification, en_tmx the tidal energy, and H the ocean depth
+      !!
+      !! ** input   :   - Namlist namtmx
+      !!                - NetCDF file : M2_ORCA2.nc, K1_ORCA2.nc, and mask_itf.nc
+      !!
+      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
+      !!              - defined az_tmx used to compute tidal-induced mixing
+      !!
+      !! References : Simmons et al. 2004, Ocean Modelling, 6, 3-4, 245-263.
+      !!              Koch-Larrouy et al. 2007, GRL.
+      !!----------------------------------------------------------------------
+      USE oce     ,         zav_tide =>  ua         ! ua used as workspace
+      !!
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   inum         ! local integer
+      INTEGER  ::   ios
+      REAL(wp) ::   ztpc, ze_z   ! local scalars
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zem2, zek1   ! read M2 and K1 tidal energy
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zkz          ! total M2, K1 and S2 tidal energy
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zfact        ! used for vertical structure function
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zhdep        ! Ocean depth 
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  zpc      ! power consumption
+      !!
+      NAMELIST/namzdf_tmx/ rn_htmx, rn_n2min, rn_tfe, rn_me, ln_tmx_itf, rn_tfe_itf
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx_init')
+      !
+      CALL wrk_alloc( jpi,jpj, zem2, zek1, zkz, zfact, zhdep )
+      CALL wrk_alloc( jpi,jpj,jpk, zpc )
+      
+      REWIND( numnam_ref )              ! Namelist namzdf_tmx in reference namelist : Tidal Mixing
+      READ  ( numnam_ref, namzdf_tmx, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in reference namelist', lwp )
+
+      REWIND( numnam_cfg )              ! Namelist namzdf_tmx in configuration namelist : Tidal Mixing
+      READ  ( numnam_cfg, namzdf_tmx, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzdf_tmx )
+
+      IF(lwp) THEN                   ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_tmx_init : tidal mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf_tmx : set tidal mixing parameters'
+         WRITE(numout,*) '      Vertical decay scale for turbulence   = ', rn_htmx 
+         WRITE(numout,*) '      Brunt-Vaisala frequency threshold     = ', rn_n2min
+         WRITE(numout,*) '      Tidal dissipation efficiency          = ', rn_tfe
+         WRITE(numout,*) '      Mixing efficiency                     = ', rn_me
+         WRITE(numout,*) '      ITF specific parameterisation         = ', ln_tmx_itf
+         WRITE(numout,*) '      ITF tidal dissipation efficiency      = ', rn_tfe_itf
+      ENDIF
+
+      !                              ! allocate tmx arrays
+      IF( zdf_tmx_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tmx_init : unable to allocate tmx arrays' )
+
+      IF( ln_tmx_itf ) THEN          ! read the Indonesian Through Flow mask
+         CALL iom_open('mask_itf',inum)
+         CALL iom_get (inum, jpdom_data, 'tmaskitf',mask_itf,1) ! 
+         CALL iom_close(inum)
+      ENDIF
+
+      ! read M2 tidal energy flux : W/m2  ( zem2 < 0 )
+      CALL iom_open('M2rowdrg',inum)
+      CALL iom_get (inum, jpdom_data, 'field',zem2,1) ! 
+      CALL iom_close(inum)
+
+      ! read K1 tidal energy flux : W/m2  ( zek1 < 0 )
+      CALL iom_open('K1rowdrg',inum)
+      CALL iom_get (inum, jpdom_data, 'field',zek1,1) ! 
+      CALL iom_close(inum)
+ 
+      ! Total tidal energy ( M2, S2 and K1  with S2=(1/2)^2 * M2 )
+      ! only the energy available for mixing is taken into account,
+      ! (mixing efficiency tidal dissipation efficiency)
+      en_tmx(:,:) = - rn_tfe * rn_me * ( zem2(:,:) * 1.25 + zek1(:,:) ) * ssmask(:,:)
+
+!============
+!TG: Bug for VVL? Should this section be moved out of _init and be updated at every timestep?
+      ! Vertical structure (az_tmx)
+      DO jj = 1, jpj                ! part independent of the level
+         DO ji = 1, jpi
+            zhdep(ji,jj) = gdepw_0(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
+            zfact(ji,jj) = rau0 * rn_htmx * ( 1. - EXP( -zhdep(ji,jj) / rn_htmx ) )
+            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = en_tmx(ji,jj) / zfact(ji,jj)
+         END DO
+      END DO
+      DO jk= 1, jpk                 ! complete with the level-dependent part
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               az_tmx(ji,jj,jk) = zfact(ji,jj) * EXP( -( zhdep(ji,jj)-gdepw_0(ji,jj,jk) ) / rn_htmx ) * tmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+!===========
+
+      IF( nprint == 1 .AND. lwp ) THEN
+         ! Control print
+         ! Total power consumption due to vertical mixing
+         ! zpc = rau0 * 1/rn_me * rn2 * zav_tide
+         zav_tide(:,:,:) = 0.e0
+         DO jk = 2, jpkm1
+            zav_tide(:,:,jk) = az_tmx(:,:,jk) / MAX( rn_n2min, rn2(:,:,jk) )
+         END DO
+
+         ztpc = 0.e0
+         zpc(:,:,:) = MAX(rn_n2min,rn2(:,:,:)) * zav_tide(:,:,:)
+         DO jk= 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztpc = ztpc + fse3w(ji,jj,jk) * e1t(ji,jj) * e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         ztpc= rau0 * 1/(rn_tfe * rn_me) * ztpc
+
+         WRITE(numout,*) 
+         WRITE(numout,*) '          Total power consumption of the tidally driven part of Kz : ztpc = ', ztpc * 1.e-12 ,'TW'
+
+
+         ! control print 2
+         zav_tide(:,:,:) = MIN( zav_tide(:,:,:), 60.e-4 )   
+         zkz(:,:) = 0.e0
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zkz(ji,jj) = zkz(ji,jj) + fse3w(ji,jj,jk) * MAX(0.e0, rn2(ji,jj,jk)) * rau0 * zav_tide(ji,jj,jk) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! Here zkz should be equal to en_tmx ==> multiply by en_tmx/zkz
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zkz(ji,jj) /= 0.e0 )   THEN
+                   zkz(ji,jj) = en_tmx(ji,jj) / zkz(ji,jj)
+               ENDIF
+            END DO
+         END DO
+         ztpc = 1.e50
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zkz(ji,jj) /= 0.e0 )   THEN
+                   ztpc = Min( zkz(ji,jj), ztpc)
+               ENDIF
+            END DO
+         END DO
+         WRITE(numout,*) '          Min de zkz ', ztpc, ' Max = ', maxval(zkz(:,:) )
+
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zav_tide(ji,jj,jk) = zav_tide(ji,jj,jk) * MIN( zkz(ji,jj), 30./6. ) * wmask(ji,jj,jk)  !kz max = 300 cm2/s
+               END DO
+            END DO
+         END DO
+         ztpc = 0.e0
+         zpc(:,:,:) = Max(0.e0,rn2(:,:,:)) * zav_tide(:,:,:)
+         DO jk= 1, jpk
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztpc = ztpc + fse3w(ji,jj,jk) * e1t(ji,jj) * e2t(ji,jj) * zpc(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         ztpc= rau0 * 1/(rn_tfe * rn_me) * ztpc
+         WRITE(numout,*) '          2 Total power consumption of the tidally driven part of Kz : ztpc = ', ztpc * 1.e-12 ,'TW'
+
+         DO jk = 1, jpk
+            ze_z =                  SUM( e1t(:,:) * e2t(:,:) * zav_tide(:,:,jk)     * tmask_i(:,:) )   &
+               &     / MAX( 1.e-20, SUM( e1t(:,:) * e2t(:,:) * wmask (:,:,jk) * tmask_i(:,:) ) )
+            ztpc = 1.E50
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( zav_tide(ji,jj,jk) /= 0.e0 )   ztpc =Min( ztpc, zav_tide(ji,jj,jk) )
+               END DO
+            END DO
+            WRITE(numout,*) '            N2 min - jk= ', jk,'   ', ze_z * 1.e4,' cm2/s min= ',ztpc*1.e4,   &
+               &       'max= ', MAXVAL(zav_tide(:,:,jk) )*1.e4, ' cm2/s'
+         END DO
+
+         WRITE(numout,*) '          e_tide : ', SUM( e1t*e2t*en_tmx ) / ( rn_tfe * rn_me ) * 1.e-12, 'TW'
+         WRITE(numout,*) 
+         WRITE(numout,*) '          Initial profile of tidal vertical mixing'
+         DO jk = 1, jpk
+            DO jj = 1,jpj
+               DO ji = 1,jpi
+                  zkz(ji,jj) = az_tmx(ji,jj,jk) /MAX( rn_n2min, rn2(ji,jj,jk) )
+               END DO
+            END DO
+            ze_z =                  SUM( e1t(:,:) * e2t(:,:) * zkz(:,:)     * tmask_i(:,:) )   &
+               &     / MAX( 1.e-20, SUM( e1t(:,:) * e2t(:,:) * wmask (:,:,jk) * tmask_i(:,:) ) )
+            WRITE(numout,*) '                jk= ', jk,'   ', ze_z * 1.e4,' cm2/s'
+         END DO
+         DO jk = 1, jpk
+            zkz(:,:) = az_tmx(:,:,jk) /rn_n2min
+            ze_z =                  SUM( e1t(:,:) * e2t(:,:) * zkz(:,:)     * tmask_i(:,:) )   &
+               &     / MAX( 1.e-20, SUM( e1t(:,:) * e2t(:,:) * wmask (:,:,jk) * tmask_i(:,:) ) )
+            WRITE(numout,*) 
+            WRITE(numout,*) '          N2 min - jk= ', jk,'   ', ze_z * 1.e4,' cm2/s min= ',MINVAL(zkz)*1.e4,   &
+               &       'max= ', MAXVAL(zkz)*1.e4, ' cm2/s'
+         END DO
+         !
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi,jpj, zem2, zek1, zkz, zfact, zhdep )
+      CALL wrk_dealloc( jpi,jpj,jpk, zpc )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx_init')
+      !
+   END SUBROUTINE zdf_tmx_init
+
+#elif defined key_zdftmx_new
+   !!----------------------------------------------------------------------
+   !!   'key_zdftmx_new'               Internal wave-driven vertical mixing
+   !!----------------------------------------------------------------------
+   !!   zdf_tmx       : global     momentum & tracer Kz with wave induced Kz
+   !!   zdf_tmx_init  : global     momentum & tracer Kz with wave induced Kz
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and tracers variables
+   USE dom_oce        ! ocean space and time domain variables
+   USE zdf_oce        ! ocean vertical physics variables
+   USE zdfddm         ! ocean vertical physics: double diffusive mixing
+   USE lbclnk         ! ocean lateral boundary conditions (or mpp link)
+   USE eosbn2         ! ocean equation of state
+   USE phycst         ! physical constants
+   USE prtctl         ! Print control
+   USE in_out_manager ! I/O manager
+   USE iom            ! I/O Manager
+   USE lib_mpp        ! MPP library
+   USE wrk_nemo       ! work arrays
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   zdf_tmx         ! called in step module 
+   PUBLIC   zdf_tmx_init    ! called in nemogcm module 
+   PUBLIC   zdf_tmx_alloc   ! called in nemogcm module
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .TRUE.    !: wave-driven mixing flag
+
+   !                       !!* Namelist  namzdf_tmx : internal wave-driven mixing *
+   INTEGER  ::  nn_zpyc     ! pycnocline-intensified mixing energy proportional to N (=1) or N^2 (=2)
+   LOGICAL  ::  ln_mevar    ! variable (=T) or constant (=F) mixing efficiency
+   LOGICAL  ::  ln_tsdiff   ! account for differential T/S wave-driven mixing (=T) or not (=F)
+
+   REAL(wp) ::  r1_6 = 1._wp / 6._wp
+
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ebot_tmx     ! power available from high-mode wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   epyc_tmx     ! power available from low-mode, pycnocline-intensified wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   ecri_tmx     ! power available from low-mode, critical slope wave breaking (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hbot_tmx     ! WKB decay scale for high-mode energy dissipation (m)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   hcri_tmx     ! decay scale for low-mode critical slope dissipation (m)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   emix_tmx     ! local energy density available for mixing (W/kg)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   bflx_tmx     ! buoyancy flux Kz * N^2 (W/kg)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:)   ::   pcmap_tmx    ! vertically integrated buoyancy flux (W/m2)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zav_ratio    ! S/T diffusivity ratio (only for ln_tsdiff=T)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   zav_wave     ! Internal wave-induced diffusivity
+
+   !! * Substitutions
+#  include "zdfddm_substitute.h90"
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
+   !! $Id: zdftmx.F90 6314 2016-02-15 12:04:56Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION zdf_tmx_alloc()
+      !!----------------------------------------------------------------------
+      !!                ***  FUNCTION zdf_tmx_alloc  ***
+      !!----------------------------------------------------------------------
+      ALLOCATE(     ebot_tmx(jpi,jpj),  epyc_tmx(jpi,jpj),  ecri_tmx(jpi,jpj)    ,   &
+      &             hbot_tmx(jpi,jpj),  hcri_tmx(jpi,jpj),  emix_tmx(jpi,jpj,jpk),   &
+      &         bflx_tmx(jpi,jpj,jpk), pcmap_tmx(jpi,jpj), zav_ratio(jpi,jpj,jpk),   & 
+      &         zav_wave(jpi,jpj,jpk), STAT=zdf_tmx_alloc     )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( zdf_tmx_alloc )
+      IF( zdf_tmx_alloc /= 0 )   CALL ctl_warn('zdf_tmx_alloc: failed to allocate arrays')
+   END FUNCTION zdf_tmx_alloc
+
+
+   SUBROUTINE zdf_tmx( kt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_tmx  ***
+      !!                   
+      !! ** Purpose :   add to the vertical mixing coefficients the effect of
+      !!              breaking internal waves.
+      !!
+      !! ** Method  : - internal wave-driven vertical mixing is given by:
+      !!                  Kz_wave = min(  100 cm2/s, f(  Reb = emix_tmx /( Nu * N^2 )  )
+      !!              where emix_tmx is the 3D space distribution of the wave-breaking 
+      !!              energy and Nu the molecular kinematic viscosity.
+      !!              The function f(Reb) is linear (constant mixing efficiency)
+      !!              if the namelist parameter ln_mevar = F and nonlinear if ln_mevar = T.
+      !!
+      !!              - Compute emix_tmx, the 3D power density that allows to compute
+      !!              Reb and therefrom the wave-induced vertical diffusivity.
+      !!              This is divided into three components:
+      !!                 1. Bottom-intensified low-mode dissipation at critical slopes
+      !!                     emix_tmx(z) = ( ecri_tmx / rau0 ) * EXP( -(H-z)/hcri_tmx )
+      !!                                   / ( 1. - EXP( - H/hcri_tmx ) ) * hcri_tmx
+      !!              where hcri_tmx is the characteristic length scale of the bottom 
+      !!              intensification, ecri_tmx a map of available power, and H the ocean depth.
+      !!                 2. Pycnocline-intensified low-mode dissipation
+      !!                     emix_tmx(z) = ( epyc_tmx / rau0 ) * ( sqrt(rn2(z))^nn_zpyc )
+      !!                                   / SUM( sqrt(rn2(z))^nn_zpyc * e3w(z) )
+      !!              where epyc_tmx is a map of available power, and nn_zpyc
+      !!              is the chosen stratification-dependence of the internal wave
+      !!              energy dissipation.
+      !!                 3. WKB-height dependent high mode dissipation
+      !!                     emix_tmx(z) = ( ebot_tmx / rau0 ) * rn2(z) * EXP(-z_wkb(z)/hbot_tmx)
+      !!                                   / SUM( rn2(z) * EXP(-z_wkb(z)/hbot_tmx) * e3w(z) )
+      !!              where hbot_tmx is the characteristic length scale of the WKB bottom 
+      !!              intensification, ebot_tmx is a map of available power, and z_wkb is the
+      !!              WKB-stretched height above bottom defined as
+      !!                    z_wkb(z) = H * SUM( sqrt(rn2(z'>=z)) * e3w(z'>=z) )
+      !!                                 / SUM( sqrt(rn2(z'))    * e3w(z')    )
+      !!
+      !!              - update the model vertical eddy viscosity and diffusivity: 
+      !!                     avt  = avt  +    av_wave
+      !!                     avm  = avm  +    av_wave
+      !!                     avmu = avmu + mi(av_wave)
+      !!                     avmv = avmv + mj(av_wave)
+      !!
+      !!              - if namelist parameter ln_tsdiff = T, account for differential mixing:
+      !!                     avs  = avt  +    av_wave * diffusivity_ratio(Reb)
+      !!
+      !! ** Action  : - Define emix_tmx used to compute internal wave-induced mixing
+      !!              - avt, avs, avm, avmu, avmv increased by internal wave-driven mixing    
+      !!
+      !! References :  de Lavergne et al. 2015, JPO; 2016, in prep.
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean time-step 
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      REAL(wp) ::   ztpc         ! scalar workspace
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zfact     ! Used for vertical structure
+      REAL(wp), DIMENSION(:,:)  , POINTER ::  zhdep     ! Ocean depth
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  zwkb      ! WKB-stretched height above bottom
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  zweight   ! Weight for high mode vertical distribution
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  znu_t     ! Molecular kinematic viscosity (T grid)
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  znu_w     ! Molecular kinematic viscosity (W grid)
+      REAL(wp), DIMENSION(:,:,:), POINTER ::  zReb      ! Turbulence intensity parameter
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('zdf_tmx')
+      !
+      CALL wrk_alloc( jpi,jpj,       zfact, zhdep )
+      CALL wrk_alloc( jpi,jpj,jpk,   zwkb, zweight, znu_t, znu_w, zReb )
+
+      !                          ! ----------------------------- !
+      !                          !  Internal wave-driven mixing  !  (compute zav_wave)
+      !                          ! ----------------------------- !
+      !                             
+      !                        !* Critical slope mixing: distribute energy over the time-varying ocean depth,
+      !                                                 using an exponential decay from the seafloor.
+      DO jj = 1, jpj                ! part independent of the level
+         DO ji = 1, jpi
+            zhdep(ji,jj) = fsdepw(ji,jj,mbkt(ji,jj)+1)       ! depth of the ocean
+            zfact(ji,jj) = rau0 * (  1._wp - EXP( -zhdep(ji,jj) / hcri_tmx(ji,jj) )  )
+            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ecri_tmx(ji,jj) / zfact(ji,jj)
+         END DO
+      END DO
+
+      DO jk = 2, jpkm1              ! complete with the level-dependent part
+         emix_tmx(:,:,jk) = zfact(:,:) * (  EXP( ( fsde3w(:,:,jk  ) - zhdep(:,:) ) / hcri_tmx(:,:) )                      &
+            &                             - EXP( ( fsde3w(:,:,jk-1) - zhdep(:,:) ) / hcri_tmx(:,:) )  ) * wmask(:,:,jk)   &
+            &                          / ( fsde3w(:,:,jk) - fsde3w(:,:,jk-1) )
+      END DO
+
+      !                        !* Pycnocline-intensified mixing: distribute energy over the time-varying 
+      !                        !* ocean depth as proportional to sqrt(rn2)^nn_zpyc
+
+      SELECT CASE ( nn_zpyc )
+
+      CASE ( 1 )               ! Dissipation scales as N (recommended)
+
+         zfact(:,:) = 0._wp
+         DO jk = 2, jpkm1              ! part independent of the level
+            zfact(:,:) = zfact(:,:) + fse3w(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         END DO
+
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
+            END DO
+         END DO
+
+         DO jk = 2, jpkm1              ! complete with the level-dependent part
+            emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zfact(:,:) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         END DO
+
+      CASE ( 2 )               ! Dissipation scales as N^2
+
+         zfact(:,:) = 0._wp
+         DO jk = 2, jpkm1              ! part independent of the level
+            zfact(:,:) = zfact(:,:) + fse3w(:,:,jk) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
+         END DO
+
+         DO jj= 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = epyc_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
+            END DO
+         END DO
+
+         DO jk = 2, jpkm1              ! complete with the level-dependent part
+            emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zfact(:,:) * MAX( 0._wp, rn2(:,:,jk) ) * wmask(:,:,jk)
+         END DO
+
+      END SELECT
+
+      !                        !* WKB-height dependent mixing: distribute energy over the time-varying 
+      !                        !* ocean depth as proportional to rn2 * exp(-z_wkb/rn_hbot)
+      
+      zwkb(:,:,:) = 0._wp
+      zfact(:,:) = 0._wp
+      DO jk = 2, jpkm1
+         zfact(:,:) = zfact(:,:) + fse3w(:,:,jk) * SQRT(  MAX( 0._wp, rn2(:,:,jk) )  ) * wmask(:,:,jk)
+         zwkb(:,:,jk) = zfact(:,:)
+      END DO
+
+      DO jk = 2, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( zfact(ji,jj) /= 0 )   zwkb(ji,jj,jk) = zhdep(ji,jj) * ( zfact(ji,jj) - zwkb(ji,jj,jk) )   &
+                                            &           * tmask(ji,jj,jk) / zfact(ji,jj)
+            END DO
+         END DO
+      END DO
+      zwkb(:,:,1) = zhdep(:,:) * tmask(:,:,1)
+
+      zweight(:,:,:) = 0._wp
+      DO jk = 2, jpkm1
+         zweight(:,:,jk) = MAX( 0._wp, rn2(:,:,jk) ) * hbot_tmx(:,:) * wmask(:,:,jk)                    &
+            &   * (  EXP( -zwkb(:,:,jk) / hbot_tmx(:,:) ) - EXP( -zwkb(:,:,jk-1) / hbot_tmx(:,:) )  )
+      END DO
+
+      zfact(:,:) = 0._wp
+      DO jk = 2, jpkm1              ! part independent of the level
+         zfact(:,:) = zfact(:,:) + zweight(:,:,jk)
+      END DO
+
+      DO jj = 1, jpj
+         DO ji = 1, jpi
+            IF( zfact(ji,jj) /= 0 )   zfact(ji,jj) = ebot_tmx(ji,jj) / ( rau0 * zfact(ji,jj) )
+         END DO
+      END DO
+
+      DO jk = 2, jpkm1              ! complete with the level-dependent part
+         emix_tmx(:,:,jk) = emix_tmx(:,:,jk) + zweight(:,:,jk) * zfact(:,:) * wmask(:,:,jk)   &
+            &                                / ( fsde3w(:,:,jk) - fsde3w(:,:,jk-1) )
+      END DO
+
+
+      ! Calculate molecular kinematic viscosity
+      znu_t(:,:,:) = 1.e-4_wp * (  17.91_wp - 0.53810_wp * tsn(:,:,:,jp_tem) + 0.00694_wp * tsn(:,:,:,jp_tem) * tsn(:,:,:,jp_tem)  &
+         &                                  + 0.02305_wp * tsn(:,:,:,jp_sal)  ) * tmask(:,:,:) * r1_rau0
+      DO jk = 2, jpkm1
+         znu_w(:,:,jk) = 0.5_wp * ( znu_t(:,:,jk-1) + znu_t(:,:,jk) ) * wmask(:,:,jk)
+      END DO
+
+      ! Calculate turbulence intensity parameter Reb
+      DO jk = 2, jpkm1
+         zReb(:,:,jk) = emix_tmx(:,:,jk) / MAX( 1.e-20_wp, znu_w(:,:,jk) * rn2(:,:,jk) )
+      END DO
+
+      ! Define internal wave-induced diffusivity
+      DO jk = 2, jpkm1
+         zav_wave(:,:,jk) = znu_w(:,:,jk) * zReb(:,:,jk) * r1_6   ! This corresponds to a constant mixing efficiency of 1/6
+      END DO
+
+      IF( ln_mevar ) THEN              ! Variable mixing efficiency case : modify zav_wave in the
+         DO jk = 2, jpkm1              ! energetic (Reb > 480) and buoyancy-controlled (Reb <10.224 ) regimes
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  IF( zReb(ji,jj,jk) > 480.00_wp ) THEN
+                     zav_wave(ji,jj,jk) = 3.6515_wp * znu_w(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
+                  ELSEIF( zReb(ji,jj,jk) < 10.224_wp ) THEN
+                     zav_wave(ji,jj,jk) = 0.052125_wp * znu_w(ji,jj,jk) * zReb(ji,jj,jk) * SQRT( zReb(ji,jj,jk) )
+                  ENDIF
+               END DO
+            END DO
+         END DO
+      ENDIF
+
+      DO jk = 2, jpkm1                 ! Bound diffusivity by molecular value and 100 cm2/s
+         zav_wave(:,:,jk) = MIN(  MAX( 1.4e-7_wp, zav_wave(:,:,jk) ), 1.e-2_wp  ) * wmask(:,:,jk)
+      END DO
+
+      IF( kt == nit000 ) THEN        !* Control print at first time-step: diagnose the energy consumed by zav_wave
+         ztpc = 0._wp
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  ztpc = ztpc + fse3w(ji,jj,jk) * e1e2t(ji,jj)   &
+                     &         * MAX( 0._wp, rn2(ji,jj,jk) ) * zav_wave(ji,jj,jk) * wmask(ji,jj,jk) * tmask_i(ji,jj)
+               END DO
+            END DO
+         END DO
+         IF( lk_mpp )   CALL mpp_sum( ztpc )
+         ztpc = rau0 * ztpc ! Global integral of rauo * Kz * N^2 = power contributing to mixing 
+ 
+         IF(lwp) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) 'zdf_tmx : Internal wave-driven mixing (tmx)'
+            WRITE(numout,*) '~~~~~~~ '
+            WRITE(numout,*)
+            WRITE(numout,*) '      Total power consumption by av_wave: ztpc =  ', ztpc * 1.e-12_wp, 'TW'
+         ENDIF
+      ENDIF
+
+      !                          ! ----------------------- !
+      !                          !   Update  mixing coefs  !                          
+      !                          ! ----------------------- !
+      !      
+      IF( ln_tsdiff ) THEN          !* Option for differential mixing of salinity and temperature
+         DO jk = 2, jpkm1              ! Calculate S/T diffusivity ratio as a function of Reb
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zav_ratio(ji,jj,jk) = ( 0.505_wp + 0.495_wp *                                                                  &
+                      &   TANH(    0.92_wp * (   LOG10(  MAX( 1.e-20_wp, zReb(ji,jj,jk) * 5._wp * r1_6 )  ) - 0.60_wp   )    )   &
+                      &                 ) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL iom_put( "av_ratio", zav_ratio )
+         DO jk = 2, jpkm1           !* update momentum & tracer diffusivity with wave-driven mixing
+            fsavs(:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk) * zav_ratio(:,:,jk)
+            avt  (:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
+            avm  (:,:,jk) = avm(:,:,jk) + zav_wave(:,:,jk)
+         END DO
+         !
+      ELSE                          !* update momentum & tracer diffusivity with wave-driven mixing
+         DO jk = 2, jpkm1
+            fsavs(:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
+            avt  (:,:,jk) = avt(:,:,jk) + zav_wave(:,:,jk)
+            avm  (:,:,jk) = avm(:,:,jk) + zav_wave(:,:,jk)
+         END DO
+      ENDIF
+
+      DO jk = 2, jpkm1              !* update momentum diffusivity at wu and wv points
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1  ! vector opt.
+               avmu(ji,jj,jk) = avmu(ji,jj,jk) + 0.5_wp * ( zav_wave(ji,jj,jk) + zav_wave(ji+1,jj  ,jk) ) * wumask(ji,jj,jk)
+               avmv(ji,jj,jk) = avmv(ji,jj,jk) + 0.5_wp * ( zav_wave(ji,jj,jk) + zav_wave(ji  ,jj+1,jk) ) * wvmask(ji,jj,jk)
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( avmu, 'U', 1. )   ;   CALL lbc_lnk( avmv, 'V', 1. )      ! lateral boundary condition
+
+      !                             !* output internal wave-driven mixing coefficient
+      CALL iom_put( "av_wave", zav_wave )
+                                    !* output useful diagnostics: N^2, Kz * N^2 (bflx_tmx), 
+                                    !  vertical integral of rau0 * Kz * N^2 (pcmap_tmx), energy density (emix_tmx)
+      IF( iom_use("bflx_tmx") .OR. iom_use("pcmap_tmx") ) THEN
+         bflx_tmx(:,:,:) = MAX( 0._wp, rn2(:,:,:) ) * zav_wave(:,:,:)
+         pcmap_tmx(:,:) = 0._wp
+         DO jk = 2, jpkm1
+            pcmap_tmx(:,:) = pcmap_tmx(:,:) + fse3w(:,:,jk) * bflx_tmx(:,:,jk) * wmask(:,:,jk)
+         END DO
+         pcmap_tmx(:,:) = rau0 * pcmap_tmx(:,:)
+         CALL iom_put( "bflx_tmx", bflx_tmx )
+         CALL iom_put( "pcmap_tmx", pcmap_tmx )
+      ENDIF
+      CALL iom_put( "bn2", rn2 )
+      CALL iom_put( "emix_tmx", emix_tmx )
+      
+      CALL wrk_dealloc( jpi,jpj,       zfact, zhdep )
+      CALL wrk_dealloc( jpi,jpj,jpk,   zwkb, zweight, znu_t, znu_w, zReb )
+
+      IF(ln_ctl)   CALL prt_ctl(tab3d_1=zav_wave , clinfo1=' tmx - av_wave: ', tab3d_2=avt, clinfo2=' avt: ', ovlap=1, kdim=jpk)
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('zdf_tmx')
+      !
+   END SUBROUTINE zdf_tmx
+
+
+   SUBROUTINE zdf_tmx_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE zdf_tmx_init  ***
+      !!                     
+      !! ** Purpose :   Initialization of the wave-driven vertical mixing, reading
+      !!              of input power maps and decay length scales in netcdf files.
+      !!
+      !! ** Method  : - Read the namzdf_tmx namelist and check the parameters
+      !!
+      !!              - Read the input data in NetCDF files :
+      !!              power available from high-mode wave breaking (mixing_power_bot.nc)
+      !!              power available from pycnocline-intensified wave-breaking (mixing_power_pyc.nc)
+      !!              power available from critical slope wave-breaking (mixing_power_cri.nc)
+      !!              WKB decay scale for high-mode wave-breaking (decay_scale_bot.nc)
+      !!              decay scale for critical slope wave-breaking (decay_scale_cri.nc)
+      !!
+      !! ** input   : - Namlist namzdf_tmx
+      !!              - NetCDF files : mixing_power_bot.nc, mixing_power_pyc.nc, mixing_power_cri.nc,
+      !!              decay_scale_bot.nc decay_scale_cri.nc
+      !!
+      !! ** Action  : - Increase by 1 the nstop flag is setting problem encounter
+      !!              - Define ebot_tmx, epyc_tmx, ecri_tmx, hbot_tmx, hcri_tmx
+      !!
+      !! References : de Lavergne et al. 2015, JPO; 2016, in prep.
+      !!			  
+      !!----------------------------------------------------------------------
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   inum         ! local integer
+      INTEGER  ::   ios
+      REAL(wp) ::   zbot, zpyc, zcri   ! local scalars
+      !!
+      NAMELIST/namzdf_tmx_new/ nn_zpyc, ln_mevar, ln_tsdiff
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('zdf_tmx_init')
+      !
+      REWIND( numnam_ref )              ! Namelist namzdf_tmx in reference namelist : Wave-driven mixing
+      READ  ( numnam_ref, namzdf_tmx_new, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in reference namelist', lwp )
+      !
+      REWIND( numnam_cfg )              ! Namelist namzdf_tmx in configuration namelist : Wave-driven mixing
+      READ  ( numnam_cfg, namzdf_tmx_new, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzdf_tmx in configuration namelist', lwp )
+      IF(lwm) WRITE ( numond, namzdf_tmx_new )
+      !
+      IF(lwp) THEN                  ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) 'zdf_tmx_init : internal wave-driven mixing'
+         WRITE(numout,*) '~~~~~~~~~~~~'
+         WRITE(numout,*) '   Namelist namzdf_tmx_new : set wave-driven mixing parameters'
+         WRITE(numout,*) '      Pycnocline-intensified diss. scales as N (=1) or N^2 (=2) = ', nn_zpyc
+         WRITE(numout,*) '      Variable (T) or constant (F) mixing efficiency            = ', ln_mevar
+         WRITE(numout,*) '      Differential internal wave-driven mixing (T) or not (F)   = ', ln_tsdiff
+      ENDIF
+      
+      ! The new wave-driven mixing parameterization elevates avt and avm in the interior, and
+      ! ensures that avt remains larger than its molecular value (=1.4e-7). Therefore, avtb should 
+      ! be set here to a very small value, and avmb to its (uniform) molecular value (=1.4e-6).
+      avmb(:) = 1.4e-6_wp        ! viscous molecular value
+      avtb(:) = 1.e-10_wp        ! very small diffusive minimum (background avt is specified in zdf_tmx)    
+      avtb_2d(:,:) = 1.e0_wp     ! uniform 
+      IF(lwp) THEN                  ! Control print
+         WRITE(numout,*)
+         WRITE(numout,*) '   Force the background value applied to avm & avt in TKE to be everywhere ',   &
+            &               'the viscous molecular value & a very small diffusive value, resp.'
+      ENDIF
+      
+      IF( .NOT.lk_zdfddm )   CALL ctl_stop( 'STOP', 'zdf_tmx_init_new : key_zdftmx_new requires key_zdfddm' )
+      
+      !                             ! allocate tmx arrays
+      IF( zdf_tmx_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_tmx_init : unable to allocate tmx arrays' )
+      !
+      !                             ! read necessary fields
+      CALL iom_open('mixing_power_bot',inum)       ! energy flux for high-mode wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', ebot_tmx, 1 ) 
+      CALL iom_close(inum)
+      !
+      CALL iom_open('mixing_power_pyc',inum)       ! energy flux for pynocline-intensified wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', epyc_tmx, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('mixing_power_cri',inum)       ! energy flux for critical slope wave breaking [W/m2]
+      CALL iom_get  (inum, jpdom_data, 'field', ecri_tmx, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('decay_scale_bot',inum)        ! spatially variable decay scale for high-mode wave breaking [m]
+      CALL iom_get  (inum, jpdom_data, 'field', hbot_tmx, 1 )
+      CALL iom_close(inum)
+      !
+      CALL iom_open('decay_scale_cri',inum)        ! spatially variable decay scale for critical slope wave breaking [m]
+      CALL iom_get  (inum, jpdom_data, 'field', hcri_tmx, 1 )
+      CALL iom_close(inum)
+
+      ebot_tmx(:,:) = ebot_tmx(:,:) * ssmask(:,:)
+      epyc_tmx(:,:) = epyc_tmx(:,:) * ssmask(:,:)
+      ecri_tmx(:,:) = ecri_tmx(:,:) * ssmask(:,:)
+
+      ! Set once for all to zero the first and last vertical levels of appropriate variables
+      emix_tmx (:,:, 1 ) = 0._wp
+      emix_tmx (:,:,jpk) = 0._wp
+      zav_ratio(:,:, 1 ) = 0._wp
+      zav_ratio(:,:,jpk) = 0._wp
+      zav_wave (:,:, 1 ) = 0._wp
+      zav_wave (:,:,jpk) = 0._wp
+
+      zbot = glob_sum( e1e2t(:,:) * ebot_tmx(:,:) )
+      zpyc = glob_sum( e1e2t(:,:) * epyc_tmx(:,:) )
+      zcri = glob_sum( e1e2t(:,:) * ecri_tmx(:,:) )
+      IF(lwp) THEN
+         WRITE(numout,*) '      High-mode wave-breaking energy:             ', zbot * 1.e-12_wp, 'TW'
+         WRITE(numout,*) '      Pycnocline-intensifed wave-breaking energy: ', zpyc * 1.e-12_wp, 'TW'
+         WRITE(numout,*) '      Critical slope wave-breaking energy:        ', zcri * 1.e-12_wp, 'TW'
+      ENDIF
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('zdf_tmx_init')
+      !
+   END SUBROUTINE zdf_tmx_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option          Dummy module                NO Tidal MiXing
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER ::   lk_zdftmx = .FALSE.   !: tidal mixing flag
+CONTAINS
+   SUBROUTINE zdf_tmx_init           ! Dummy routine
+      WRITE(*,*) 'zdf_tmx: You should not have seen this print! error?'
+   END SUBROUTINE zdf_tmx_init
+   SUBROUTINE zdf_tmx( kt )          ! Dummy routine
+      WRITE(*,*) 'zdf_tmx: You should not have seen this print! error?', kt
+   END SUBROUTINE zdf_tmx
+#endif
+
+   !!======================================================================
+END MODULE zdftmx
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/closea.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/closea.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/closea.F90	(revision 5879)
@@ -0,0 +1,531 @@
+MODULE closea
+   !!======================================================================
+   !!                       ***  MODULE  closea  ***
+   !! Closed Seas  : specific treatments associated with closed seas
+   !!======================================================================
+   !! History :   8.2  !  00-05  (O. Marti)  Original code
+   !!             8.5  !  02-06  (E. Durand, G. Madec)  F90
+   !!             9.0  !  06-07  (G. Madec)  add clo_rnf, clo_ups, clo_bat
+   !!        NEMO 3.4  !  03-12  (P.G. Fogli) sbc_clo bug fix & mpp reproducibility
+   !!
+   !! 2016 : new closed seas for use in IPSLCM6 coupled model (O. Marti)
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   dom_clo    : modification of the ocean domain for closed seas cases
+   !!   sbc_clo    : Special handling of closed seas
+   !!   clo_rnf    : set close sea outflows as river mouths (see sbcrnf)
+   !!   clo_ups    : set mixed centered/upstream scheme in closed sea (see traadv_cen2)
+   !!   clo_bat    : set to zero a field over closed sea (see domzrg)
+   !!----------------------------------------------------------------------
+   USE oce             ! dynamics and tracers
+   USE dom_oce         ! ocean space and time domain
+   USE phycst          ! physical constants
+   USE in_out_manager  ! I/O manager
+   !USE iom             ! I/O manager library
+   USE sbc_oce         ! ocean surface boundary conditions
+   USE lib_fortran,    ONLY: glob_sum, DDPDD
+   USE lbclnk          ! lateral boundary condition - MPP exchanges
+   USE lib_mpp         ! MPP library
+   USE timing
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC dom_clo      ! routine called by domain module
+   PUBLIC sbc_clo      ! routine called by step module
+   PUBLIC clo_rnf      ! routine called by sbcrnf module
+   PUBLIC clo_ups      ! routine called in traadv_cen2(_jki) module
+   PUBLIC clo_bat      ! routine called in domzgr module
+
+   INTEGER, PUBLIC, PARAMETER          ::   jpncs   = 7      !: number of closed sea
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncstt            !: Type of closed sea
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi1, ncsj1     !: south-west closed sea limits (i,j)
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi2, ncsj2     !: north-east closed sea limits (i,j)
+   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsnr            !: number of point where run-off pours
+   INTEGER, PUBLIC, DIMENSION(jpncs,4) ::   ncsir, ncsjr     !: Location of runoff
+
+   REAL(wp), DIMENSION (:,:), ALLOCATABLE :: clo_mask        !: Defines area where excess run-off is distributed
+
+   REAL(wp), DIMENSION (jpncs+1)       ::   surf             !: Closed sea surface
+
+   INTEGER :: dia_closea_alloc
+
+   !! * Substitutions
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: closea.F90 4162 2013-11-07 10:19:49Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE dom_clo
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE dom_clo  ***
+      !!        
+      !! ** Purpose :   Closed sea domain initialization
+      !!
+      !! ** Method  :   if a closed sea is located only in a model grid point
+      !!                just the thermodynamic processes are applied.
+      !!
+      !! ** Action  :   ncsi1(), ncsj1() : south-west closed sea limits (i,j)
+      !!                ncsi2(), ncsj2() : north-east Closed sea limits (i,j)
+      !!                ncsir(), ncsjr() : Location of runoff
+      !!                ncsnr            : number of point where run-off pours
+      !!                ncstt            : Type of closed sea
+      !!                                   =0 spread over the world ocean
+      !!                                   =2 put at location runoff
+      !!----------------------------------------------------------------------
+      INTEGER ::   jc               ! dummy loop indices
+      REAL(wp)::   ztmp
+      INTEGER ::   isrow
+      !!----------------------------------------------------------------------
+      
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)'dom_clo : closed seas '
+      IF(lwp) WRITE(numout,*)'~~~~~~~'
+
+      ! Initial values
+      ncsnr(:) = 1  ;  ncsi1(:) = 1  ;  ncsi2(:) = 1  ;  ncsir(:,:) = 1
+      ncstt(:) = 0  ;  ncsj1(:) = 1  ;  ncsj2(:) = 1  ;  ncsjr(:,:) = 1
+
+      ! set the closed seas (in data domain indices)
+      ! -------------------
+
+      IF( cp_cfg == "orca" ) THEN
+         !
+         SELECT CASE ( jp_cfg )
+         !                                           ! =======================
+         CASE ( 1 )                                  ! ORCA_R1 configuration
+            !
+            !! This dirty section will be suppressed by simplification process: all this will come back in input files.
+            !! Currently these hard-wired indices relate to NEMO v3.6 and later. In this version, the grid has been extended southwards
+            !! for use with the under ice-shelf options (isf). The grid resolution is 362x332.
+            !! The pre v3.6 (362x292) domain can still be used optionally if the isf code is not activated. An adjustment (isrow)
+            !! is made to the hard-wired indices if the reduced domain is used.
+            
+            !! =======================
+            IF         ( jpjglo == 332 ) THEN  !  eORCA1 R1 - Using full isfÂ­extended domain.
+               isrow =  0
+            ELSEIF     ( jpjglo == 292 ) THEN  !  ORCA1 R1 Â­ Using pre-v3.6 files or adjusted start row from isf-extended grid
+               isrow = 40                      !    - Adjust jÂ­indices to account for less southerly starting latitude
+            ENDIF
+            
+            ncsnr(1)   = 1    ; ncstt(1)   = 0              ! Caspian Sea
+            ncsi1(1)   = 333  ; ncsj1(1)   = 243 - isrow      ! spread over the globe
+            ncsi2(1)   = 342  ; ncsj2(1)   = 274 - isrow
+            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
+            !
+            ncsnr(2)   = 4    ; ncstt(2)   = 2              ! Lake Superior
+            ncsi1(2)   = 198  ; ncsj1(2)   = 258 - isrow      ! put at St Laurent mouth
+            ncsi2(2)   = 204  ; ncsj2(2)   = 262 - isrow
+            ncsir(2,1) = 225  ; ncsjr(2,1) = 220 - isrow
+            ncsir(2,2) = 225  ; ncsjr(2,2) = 221 - isrow
+            ncsir(2,3) = 226  ; ncsjr(2,3) = 220 - isrow
+            ncsir(2,4) = 226  ; ncsjr(2,4) = 221 - isrow
+            !
+            ncsnr(3)   = 4    ; ncstt(3)   = 2              ! Lake Michigan
+            ncsi1(3)   = 201  ; ncsj1(3)   = 250 - isrow      ! put at St Laurent mouth
+            ncsi2(3)   = 203  ; ncsj2(3)   = 256 - isrow
+            ncsir(3,1) = 225  ; ncsjr(3,1) = 220 - isrow
+            ncsir(3,2) = 225  ; ncsjr(3,2) = 221 - isrow
+            ncsir(3,3) = 226  ; ncsjr(3,3) = 220 - isrow
+            ncsir(3,4) = 226  ; ncsjr(3,4) = 221 - isrow
+            !
+            ncsnr(4)   = 4    ; ncstt(4)   = 2             ! Lake Huron
+            ncsi1(4)   = 204  ; ncsj1(4)   = 252 - isrow      ! put at St Laurent mouth
+            ncsi2(4)   = 209  ; ncsj2(4)   = 256 - isrow
+            ncsir(4,1) = 225  ; ncsjr(4,1) = 220 - isrow
+            ncsir(4,2) = 225  ; ncsjr(4,2) = 221 - isrow
+            ncsir(4,3) = 226  ; ncsjr(4,3) = 220 - isrow
+            ncsir(4,4) = 226  ; ncsjr(4,4) = 221 - isrow
+            !
+            ncsnr(5)   = 4    ; ncstt(5)   = 2              ! Lake Erie
+            ncsi1(5)   = 206  ; ncsj1(5)   = 249 - isrow      ! put at St Laurent mouth
+            ncsi2(5)   = 209  ; ncsj2(5)   = 251 - isrow
+            ncsir(5,1) = 225  ; ncsjr(5,1) = 220 - isrow
+            ncsir(5,2) = 225  ; ncsjr(5,2) = 221 - isrow
+            ncsir(5,3) = 226  ; ncsjr(5,3) = 220 - isrow
+            ncsir(5,4) = 226  ; ncsjr(5,4) = 221 - isrow
+            !
+            ncsnr(6)   = 4    ; ncstt(6)   = 2              ! Lake Ontario
+            ncsi1(6)   = 210  ; ncsj1(6)   = 252 - isrow      ! put at St Laurent mouth
+            ncsi2(6)   = 212  ; ncsj2(6)   = 252 - isrow
+            ncsir(6,1) = 225  ; ncsjr(6,1) = 220 - isrow
+            ncsir(6,2) = 225  ; ncsjr(6,2) = 221 - isrow
+            ncsir(6,3) = 226  ; ncsjr(6,3) = 220 - isrow
+            ncsir(6,4) = 226  ; ncsjr(6,4) = 221 - isrow
+            !
+            ncsnr(7)   = 1    ; ncstt(7)   = 0             ! Victoria Lake
+            ncsi1(7)   = 321  ; ncsj1(7)   = 180 - isrow     ! spread over the globe
+            ncsi2(7)   = 322  ; ncsj2(7)   = 189 - isrow
+            ncsir(7,1) = 1    ; ncsjr(7,1) = 1
+            
+            !                                        
+            !                                        ! =======================
+         CASE ( 2 )                                  !  ORCA_R2 configuration
+            !                                        ! =======================
+            !                                            ! Caspian Sea
+            ncsnr(1)   =   1  ;  ncstt(1)   =   0           ! spread over the globe
+            ncsi1(1)   =  11  ;  ncsj1(1)   = 103
+            ncsi2(1)   =  17  ;  ncsj2(1)   = 112
+            ncsir(1,1) =   1  ;  ncsjr(1,1) =   1 
+            !                                            ! Great North American Lakes
+            ncsnr(2)   =   1  ;  ncstt(2)   =   2           ! put at St Laurent mouth
+            ncsi1(2)   =  97  ;  ncsj1(2)   = 107
+            ncsi2(2)   = 103  ;  ncsj2(2)   = 111
+            ncsir(2,1) = 110  ;  ncsjr(2,1) = 111           
+            !                                            ! Black Sea (crossed by the cyclic boundary condition)
+            ncsnr(3:4) =   4  ;  ncstt(3:4) =   2           ! put in Med Sea (north of Aegean Sea)
+            ncsir(3:4,1) = 171;  ncsjr(3:4,1) = 106         !
+            ncsir(3:4,2) = 170;  ncsjr(3:4,2) = 106 
+            ncsir(3:4,3) = 171;  ncsjr(3:4,3) = 105 
+            ncsir(3:4,4) = 170;  ncsjr(3:4,4) = 105 
+            ncsi1(3)   = 174  ;  ncsj1(3)   = 107           ! 1 : west part of the Black Sea      
+            ncsi2(3)   = 181  ;  ncsj2(3)   = 112           !            (ie west of the cyclic b.c.)
+            ncsi1(4)   =   2  ;  ncsj1(4)   = 107           ! 2 : east part of the Black Sea 
+            ncsi2(4)   =   6  ;  ncsj2(4)   = 112           !           (ie east of the cyclic b.c.)
+             
+          
+
+            !                                        ! =======================
+         CASE ( 4 )                                  !  ORCA_R4 configuration
+            !                                        ! =======================
+            !                                            ! Caspian Sea
+            ncsnr(1)   =  1  ;  ncstt(1)   =  0  
+            ncsi1(1)   =  4  ;  ncsj1(1)   = 53 
+            ncsi2(1)   =  4  ;  ncsj2(1)   = 56
+            ncsir(1,1) =  1  ;  ncsjr(1,1) =  1
+            !                                            ! Great North American Lakes
+            ncsnr(2)   =  1  ;  ncstt(2)   =  2 
+            ncsi1(2)   = 49  ;  ncsj1(2)   = 55
+            ncsi2(2)   = 51  ;  ncsj2(2)   = 56
+            ncsir(2,1) = 57  ;  ncsjr(2,1) = 55
+            !                                            ! Black Sea
+            ncsnr(3)   =  4  ;  ncstt(3)   =  2  
+            ncsi1(3)   = 88  ;  ncsj1(3)   = 55 
+            ncsi2(3)   = 91  ;  ncsj2(3)   = 56
+            ncsir(3,1) = 86  ;  ncsjr(3,1) = 53
+            ncsir(3,2) = 87  ;  ncsjr(3,2) = 53 
+            ncsir(3,3) = 86  ;  ncsjr(3,3) = 52 
+            ncsir(3,4) = 87  ;  ncsjr(3,4) = 52
+            !                                            ! Baltic Sea
+            ncsnr(4)   =  1  ;  ncstt(4)   =  2
+            ncsi1(4)   = 75  ;  ncsj1(4)   = 59
+            ncsi2(4)   = 76  ;  ncsj2(4)   = 61
+            ncsir(4,1) = 84  ;  ncsjr(4,1) = 59 
+            !                                        ! =======================
+         CASE ( 025 )                                ! ORCA_R025 configuration
+            !                                        ! =======================
+            ncsnr(1)   = 1    ; ncstt(1)   = 0               ! Caspian + Aral sea
+            ncsi1(1)   = 1330 ; ncsj1(1)   = 645
+            ncsi2(1)   = 1400 ; ncsj2(1)   = 795
+            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
+            !                                        
+            ncsnr(2)   = 1    ; ncstt(2)   = 0               ! Azov Sea 
+            ncsi1(2)   = 1284 ; ncsj1(2)   = 722
+            ncsi2(2)   = 1304 ; ncsj2(2)   = 747
+            ncsir(2,1) = 1    ; ncsjr(2,1) = 1
+            !
+         END SELECT
+         !
+      ENDIF
+
+      ! convert the position in local domain indices
+      ! --------------------------------------------
+      DO jc = 1, jpncs
+         ncsi1(jc)   = mi0( ncsi1(jc) )
+         ncsj1(jc)   = mj0( ncsj1(jc) )
+
+         ncsi2(jc)   = mi1( ncsi2(jc) )   
+         ncsj2(jc)   = mj1( ncsj2(jc) )  
+      END DO
+
+      !
+   END SUBROUTINE dom_clo
+
+
+   SUBROUTINE sbc_clo( kt )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_clo  ***
+      !!                    
+      !! ** Purpose :   Special handling of closed seas
+      !!
+      !! ** Method  :   Water flux is forced to zero over closed sea
+      !!      Excess is shared between remaining ocean, or
+      !!      put as run-off in open ocean.
+      !!
+      !! ** Action  :   emp updated surface freshwater fluxes and associated heat content at kt
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kt   ! ocean model time step
+      !
+      INTEGER             ::   ji, jj, jc, jn   ! dummy loop indices
+      REAL(wp), PARAMETER ::   rsmall = 1.e-20_wp    ! Closed sea correction epsilon
+      REAL(wp)            ::   zze2, ztmp, zcorr     ! 
+      REAL(wp)            ::   zcoef, zcoef1         ! 
+      COMPLEX(wp)         ::   ctmp 
+      REAL(wp), DIMENSION(jpncs) ::   zfwf   ! 1D workspace
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('sbc_clo')
+      !                                                   !------------------!
+      IF( kt == nit000 ) THEN                             !  Initialisation  !
+         !                                                !------------------!
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*)'sbc_clo : closed seas '
+         IF(lwp) WRITE(numout,*)'~~~~~~~'
+         !
+         ! Mask
+         ! --------------------------------------------
+         ALLOCATE ( clo_mask (jpi, jpj), STAT=dia_closea_alloc)
+         IF(dia_closea_alloc /= 0)   CALL ctl_warn('dia_closea_alloc: failed to allocate arrays.')
+         
+         clo_mask (:,:) = tmask (:,:,1)
+         
+         ! Latitude limits
+         WHERE ( gphit (:,:) .GT.  30.0_wp ) clo_mask (:,:) = 0.0_wp
+         WHERE ( gphit (:,:) .LT. -30.0_wp ) clo_mask (:,:) = 0.0_wp
+         !
+         ! Remove closed seas from mask
+         DO jc = 1, jpncs
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  clo_mask (ji, jj) = 0.0_wp
+               END DO
+            END DO
+         END DO
+         
+         IF( lk_mpp ) CALL lbc_lnk ( clo_mask, 'T', 1._wp)
+      
+         !
+         surf(:) = 0.e0_wp
+         !
+         surf(jpncs+1) = glob_sum( e1e2t(:,:) * clo_mask (:,:) )   ! surface of the ocean where excess run-off goes
+         !
+         !                                        ! surface of closed seas 
+         IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+            DO jc = 1, jpncs
+               ctmp = CMPLX( 0.e0, 0.e0, wp )
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     ztmp = e1e2t(ji,jj) * tmask_i(ji,jj)
+                     CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+                  END DO 
+               END DO 
+               IF( lk_mpp )   CALL mpp_sum( ctmp )
+               surf(jc) = REAL(ctmp,wp)
+            END DO
+         ELSE                                          ! Standard calculation           
+            DO jc = 1, jpncs
+               DO jj = ncsj1(jc), ncsj2(jc)
+                  DO ji = ncsi1(jc), ncsi2(jc)
+                     surf(jc) = surf(jc) + e1e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
+                  END DO 
+               END DO 
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum ( surf, jpncs )       ! mpp: sum over all the global domain
+         ENDIF
+
+         IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
+         DO jc = 1, jpncs
+            IF(lwp)WRITE(numout,FMT='(1I3,4I4,5X,F16.2)') jc, ncsi1(jc), ncsi2(jc), ncsj1(jc), ncsj2(jc), surf(jc)
+         END DO
+
+         IF(lwp) WRITE(numout,*)'     Surface for redistribution in closea ', surf(jpncs+1)
+         
+         !
+      ENDIF
+      !
+      !                                                   !--------------------!
+      !                                                   !  update emp        !
+      zfwf = 0.e0_wp                                      !--------------------!
+      IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
+         DO jc = 1, jpncs
+            ctmp = CMPLX( 0.e0, 0.e0, wp )
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  ztmp = e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj)
+                  CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
+               END DO  
+            END DO 
+            IF( lk_mpp )   CALL mpp_sum( ctmp )
+            zfwf(jc) = REAL(ctmp,wp)
+         END DO
+      ELSE                                          ! Standard calculation           
+         DO jc = 1, jpncs
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zfwf(jc) = zfwf(jc) + e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj) 
+               END DO  
+            END DO 
+         END DO
+         IF( lk_mpp )   CALL mpp_sum ( zfwf(:) , jpncs )       ! mpp: sum over all the global domain
+      ENDIF
+
+      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
+         zze2    = ( zfwf(3) + zfwf(4) ) * 0.5_wp
+         zfwf(3) = zze2
+         zfwf(4) = zze2
+      ENDIF
+
+      zcorr = 0._wp
+
+      DO jc = 1, jpncs
+         !
+         ! The following if avoids the redistribution of the round off
+         IF ( ABS(zfwf(jc) / surf(jpncs+1) ) > rsmall) THEN
+            !
+            IF( ncstt(jc) == 0 ) THEN           ! water/evap excess is shared by all open ocean
+               zcoef    = zfwf(jc) / surf(jpncs+1)
+               zcoef1   = rcp * zcoef
+               emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:) 
+               qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
+               !
+            ELSEIF( ncstt(jc) == 1 ) THEN       ! Excess water in open sea, at outflow location, excess evap shared
+               IF ( zfwf(jc) <= 0.e0_wp ) THEN 
+                   DO jn = 1, ncsnr(jc)
+                     ji = mi0(ncsir(jc,jn))
+                     jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                     IF (      ji > 1 .AND. ji < jpi   &
+                         .AND. jj > 1 .AND. jj < jpj ) THEN 
+                         zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) * e1e2t(ji,jj) )
+                         zcoef1     = rcp * zcoef
+                         emp(ji,jj) = emp(ji,jj) + zcoef 
+                         qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                     ENDIF 
+                   END DO 
+               ELSE 
+                   zcoef    = zfwf(jc) / surf(jpncs+1)
+                   zcoef1   = rcp * zcoef
+                   emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:)
+                   qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
+               ENDIF
+            ELSEIF( ncstt(jc) == 2 ) THEN       ! Excess e-p-r (either sign) goes to open ocean, at outflow location
+               DO jn = 1, ncsnr(jc)
+                  ji = mi0(ncsir(jc,jn))
+                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
+                  IF(      ji > 1 .AND. ji < jpi    &
+                     .AND. jj > 1 .AND. jj < jpj ) THEN 
+                     zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) *  e1e2t(ji,jj) )
+                     zcoef1     = rcp * zcoef
+                     emp(ji,jj) = emp(ji,jj) + zcoef
+                     qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
+                  ENDIF 
+               END DO 
+            ENDIF 
+            !
+            DO jj = ncsj1(jc), ncsj2(jc)
+               DO ji = ncsi1(jc), ncsi2(jc)
+                  zcoef      = zfwf(jc) / surf(jc)
+                  zcoef1     = rcp * zcoef
+                  emp(ji,jj) = emp(ji,jj) - zcoef
+                  qns(ji,jj) = qns(ji,jj) + zcoef1 * sst_m(ji,jj)
+               END DO  
+            END DO 
+            !
+         END IF
+      END DO 
+
+      emp (:,:) = emp (:,:) * tmask(:,:,1)
+      qns (:,:) = qns (:,:) * tmask(:,:,1)
+      !
+      CALL lbc_lnk( emp , 'T', 1._wp )
+      CALL lbc_lnk( qns , 'T', 1._wp )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('sbc_clo')
+      !
+   END SUBROUTINE sbc_clo
+
+
+   SUBROUTINE clo_rnf( p_rnfmsk )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_rnf  ***
+      !!                    
+      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
+      !!                to be the same as river mouth grid-points
+      !!
+      !! ** Method  :   set to 1 the runoff mask (mskrnf, see sbcrnf module)
+      !!                at the closed sea outflow grid-point.
+      !!
+      !! ** Action  :   update (p_)mskrnf (set 1 at closed sea outflow)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_rnfmsk   ! river runoff mask (rnfmsk array)
+      !
+      INTEGER  ::   jc, jn, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         IF( ncstt(jc) >= 1 ) THEN            ! runoff mask set to 1 at closed sea outflows
+             DO jn = 1, 4
+                DO jj =    mj0( ncsjr(jc,jn) ), mj1( ncsjr(jc,jn) )
+                   DO ji = mi0( ncsir(jc,jn) ), mi1( ncsir(jc,jn) )
+                      p_rnfmsk(ji,jj) = MAX( p_rnfmsk(ji,jj), 1.0_wp )
+                   END DO
+                END DO
+            END DO 
+         ENDIF 
+      END DO 
+      !
+   END SUBROUTINE clo_rnf
+
+   
+   SUBROUTINE clo_ups( p_upsmsk )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE sbc_rnf  ***
+      !!                    
+      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
+      !!                to be the same as river mouth grid-points
+      !!
+      !! ** Method  :   set to 0.5 the upstream mask (upsmsk, see traadv_cen2 
+      !!                module) over the closed seas.
+      !!
+      !! ** Action  :   update (p_)upsmsk (set 0.5 over closed seas)
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_upsmsk   ! upstream mask (upsmsk array)
+      !
+      INTEGER  ::   jc, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               p_upsmsk(ji,jj) = 0.5_wp         ! mixed upstream/centered scheme over closed seas
+            END DO 
+         END DO 
+       END DO 
+       !
+   END SUBROUTINE clo_ups
+   
+      
+   SUBROUTINE clo_bat( pbat, kbat )
+      !!---------------------------------------------------------------------
+      !!                  ***  ROUTINE clo_bat  ***
+      !!                    
+      !! ** Purpose :   suppress closed sea from the domain
+      !!
+      !! ** Method  :   set to 0 the meter and level bathymetry (given in 
+      !!                arguments) over the closed seas.
+      !!
+      !! ** Action  :   set pbat=0 and kbat=0 over closed seas
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pbat   ! bathymetry in meters (bathy array)
+      INTEGER , DIMENSION(jpi,jpj), INTENT(inout) ::   kbat   ! bathymetry in levels (mbathy array)
+      !
+      INTEGER  ::   jc, ji, jj      ! dummy loop indices
+      !!----------------------------------------------------------------------
+      !
+      DO jc = 1, jpncs
+         DO jj = ncsj1(jc), ncsj2(jc)
+            DO ji = ncsi1(jc), ncsi2(jc)
+               pbat(ji,jj) = 0._wp   
+               kbat(ji,jj) = 0   
+            END DO 
+         END DO 
+       END DO 
+       !
+   END SUBROUTINE clo_bat
+
+   !!======================================================================
+END MODULE closea
+
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/diaar5.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/diaar5.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/diaar5.F90	(revision 5879)
@@ -0,0 +1,285 @@
+MODULE diaar5
+   !!======================================================================
+   !!                       ***  MODULE  diaar5  ***
+   !! AR5 diagnostics
+   !!======================================================================
+   !! History :  3.2  !  2009-11  (S. Masson)  Original code
+   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
+   !!----------------------------------------------------------------------
+#if defined key_diaar5   || defined key_esopa
+   !!----------------------------------------------------------------------
+   !!   'key_diaar5'  :                           activate ar5 diagnotics
+   !!----------------------------------------------------------------------
+   !!   dia_ar5       : AR5 diagnostics
+   !!   dia_ar5_init  : initialisation of AR5 diagnostics
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers 
+   USE dom_oce        ! ocean space and time domain
+   USE eosbn2         ! equation of state                (eos_bn2 routine)
+   USE lib_mpp        ! distribued memory computing library
+   USE iom            ! I/O manager library
+   USE timing         ! preformance summary
+   USE wrk_nemo       ! working arrays
+   USE fldread        ! type FLD_N
+   USE phycst         ! physical constant
+   USE in_out_manager  ! I/O manager
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   dia_ar5        ! routine called in step.F90 module
+   PUBLIC   dia_ar5_init   ! routine called in opa.F90 module
+   PUBLIC   dia_ar5_alloc  ! routine called in nemogcm.F90 module
+
+   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .TRUE.   ! coupled flag
+
+   REAL(wp)                         ::   vol0         ! ocean volume (interior domain)
+   REAL(wp)                         ::   area_tot     ! total ocean surface (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   area         ! cell surface (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   thick0       ! ocean thickness (interior domain)
+   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sn0          ! initial salinity
+      
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: diaar5.F90 6664 2016-06-03 13:42:46Z cetlod $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   FUNCTION dia_ar5_alloc()
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dia_ar5_alloc  ***
+      !!----------------------------------------------------------------------
+      INTEGER :: dia_ar5_alloc
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( area(jpi,jpj), thick0(jpi,jpj) , sn0(jpi,jpj,jpk) , STAT=dia_ar5_alloc )
+      !
+      IF( lk_mpp             )   CALL mpp_sum ( dia_ar5_alloc )
+      IF( dia_ar5_alloc /= 0 )   CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
+      !
+   END FUNCTION dia_ar5_alloc
+
+
+   SUBROUTINE dia_ar5( kt )
+      !!----------------------------------------------------------------------
+      !!                    ***  ROUTINE dia_ar5  ***
+      !!
+      !! ** Purpose :   compute and output some AR5 diagnostics
+      !!----------------------------------------------------------------------
+      !
+      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
+      !
+      INTEGER  ::   ji, jj, jk                      ! dummy loop arguments
+      REAL(wp) ::   zvolssh, zvol, zssh_steric, zztmp, zarho, ztemp, zsal, zmass
+      !
+      REAL(wp), POINTER, DIMENSION(:,:)     :: zarea_ssh , zbotpres       ! 2D workspace 
+      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zrhd , z3d, zrhop               ! 3D workspace
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztsn                       ! 4D workspace
+      !!--------------------------------------------------------------------
+      IF( nn_timing == 1 )   CALL timing_start('dia_ar5')
+ 
+      CALL wrk_alloc( jpi , jpj              , zarea_ssh , zbotpres )
+      CALL wrk_alloc( jpi , jpj , jpk        , zrhd      , z3d, zrhop    )
+      CALL wrk_alloc( jpi , jpj , jpk , jpts , ztsn                 )
+
+      zarea_ssh(:,:) = area(:,:) * sshn(:,:)
+
+      !                                         ! total volume of liquid seawater
+      zvolssh = SUM( zarea_ssh(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zvolssh )
+      zvol = vol0 + zvolssh
+
+      z3d(:,:,jpk) = 0._wp        ! ocean volume
+      DO jk = 1, jpkm1
+         z3d (:,:,jk) = area(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
+      END DO
+
+      CALL iom_put( "bathy"     , bathy(:,:) )
+      CALL iom_put( "areacello" , area (:,:) )
+      CALL iom_put( "volcello"  , z3d(:,:,:)         )     ! WARNING not consistent with CMIP DR where volcello is at ca. 2000 
+      CALL iom_put( "masscello" , rau0 * fse3t(:,:,:) * tmask(:,:,:) )  ! ocean mass 
+
+
+      CALL iom_put( 'voltot', zvol               )
+      CALL iom_put( 'sshtot', zvolssh / area_tot )
+
+      !                     
+      ztsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)                    ! thermosteric ssh
+      ztsn(:,:,:,jp_sal) = sn0(:,:,:)
+      CALL eos( ztsn, zrhd, fsdept_n(:,:,:) )                       ! now in situ density using initial salinity
+      !
+      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
+      DO jk = 1, jpkm1
+         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
+               END DO
+            END DO
+         ELSE
+            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
+         END IF
+      END IF
+      !                                         
+      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zarho )
+      zssh_steric = - zarho / area_tot
+      CALL iom_put( 'sshthster', zssh_steric )
+      
+      !                                         ! steric sea surface height
+      CALL eos( tsn, zrhd, zrhop, fsdept_n(:,:,:) )                 ! now in situ and potential density
+      zrhop(:,:,jpk) = 0._wp
+      CALL iom_put( 'rhop', zrhop )
+      !
+      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
+      DO jk = 1, jpkm1
+         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
+               END DO
+            END DO
+         ELSE
+            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
+         END IF
+      END IF
+      !    
+      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
+      IF( lk_mpp )   CALL mpp_sum( zarho )
+      zssh_steric = - zarho / area_tot
+      CALL iom_put( 'sshsteric', zssh_steric )
+      
+      !                                         ! ocean bottom pressure
+      zztmp = rau0 * grav * 1.e-4_wp               ! recover pressure from pressure anomaly and cover to dbar = 1.e4 Pa
+      zbotpres(:,:) = zztmp * ( zbotpres(:,:) + sshn(:,:) + thick0(:,:) )
+      CALL iom_put( 'botpres', zbotpres )
+
+      !                                         ! Mean density anomalie, temperature and salinity
+      ztemp = 0._wp
+      zsal  = 0._wp
+      DO jk = 1, jpkm1
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               zztmp = area(ji,jj) * fse3t(ji,jj,jk)
+               ztemp = ztemp + zztmp * tsn(ji,jj,jk,jp_tem)
+               zsal  = zsal  + zztmp * tsn(ji,jj,jk,jp_sal)
+            END DO
+         END DO
+      END DO
+      IF( .NOT.lk_vvl ) THEN
+         IF ( ln_isfcav ) THEN
+            DO ji=1,jpi
+               DO jj=1,jpj
+                  ztemp = ztemp + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_tem) 
+                  zsal  = zsal  + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_sal) 
+               END DO
+            END DO
+         ELSE
+            ztemp = ztemp + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_tem) )
+            zsal  = zsal  + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_sal) )
+         END IF
+      ENDIF
+      IF( lk_mpp ) THEN  
+         CALL mpp_sum( ztemp )
+         CALL mpp_sum( zsal  )
+      END IF
+      !
+      zmass = rau0 * ( zarho + zvol )                 ! total mass of liquid seawater
+      ztemp = ztemp / zvol                            ! potential temperature in liquid seawater
+      zsal  = zsal  / zvol                            ! Salinity of liquid seawater
+      !
+      CALL iom_put( 'masstot', zmass )
+      CALL iom_put( 'temptot', ztemp )
+      CALL iom_put( 'saltot' , zsal  )
+      ! 
+      CALL wrk_dealloc( jpi , jpj              , zarea_ssh , zbotpres    )
+      CALL wrk_dealloc( jpi , jpj , jpk        , zrhd      , z3d , zrhop )
+      CALL wrk_dealloc( jpi , jpj , jpk , jpts , ztsn                    )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5')
+      !
+   END SUBROUTINE dia_ar5
+
+
+   SUBROUTINE dia_ar5_init
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE dia_ar5_init  ***
+      !!                   
+      !! ** Purpose :   initialization for AR5 diagnostic computation
+      !!----------------------------------------------------------------------
+      INTEGER  ::   inum
+      INTEGER  ::   ik
+      INTEGER  ::   ji, jj, jk  ! dummy loop indices
+      REAL(wp) ::   zztmp  
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zsaldta   ! Jan/Dec levitus salinity
+      !
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('dia_ar5_init')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, 2, zsaldta )
+      !                                      ! allocate dia_ar5 arrays
+      IF( dia_ar5_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_ar5_init : unable to allocate arrays' )
+
+      area(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
+
+      area_tot = SUM( area(:,:) )   ;   IF( lk_mpp )   CALL mpp_sum( area_tot )
+
+      vol0        = 0._wp
+      thick0(:,:) = 0._wp
+      DO jk = 1, jpkm1
+         vol0        = vol0        + SUM( area (:,:) * tmask(:,:,jk) * e3t_0(:,:,jk) )
+         thick0(:,:) = thick0(:,:) +    tmask_i(:,:) * tmask(:,:,jk) * e3t_0(:,:,jk)
+      END DO
+      IF( lk_mpp )   CALL mpp_sum( vol0 )
+
+      CALL iom_open ( 'sali_ref_clim_monthly', inum )
+      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,1), 1  )
+      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,2), 12 )
+      CALL iom_close( inum )
+
+      sn0(:,:,:) = 0.5_wp * ( zsaldta(:,:,:,1) + zsaldta(:,:,:,2) )        
+      sn0(:,:,:) = sn0(:,:,:) * tmask(:,:,:)
+      IF( ln_zps ) THEN               ! z-coord. partial steps
+         DO jj = 1, jpj               ! interpolation of salinity at the last ocean level (i.e. the partial step)
+            DO ji = 1, jpi
+               ik = mbkt(ji,jj)
+               IF( ik > 1 ) THEN
+                  zztmp = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
+                  sn0(ji,jj,ik) = ( 1._wp - zztmp ) * sn0(ji,jj,ik) + zztmp * sn0(ji,jj,ik-1)
+               ENDIF
+            END DO
+         END DO
+      ENDIF
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, 2, zsaldta )
+      !
+      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5_init')
+      !
+   END SUBROUTINE dia_ar5_init
+
+#else
+   !!----------------------------------------------------------------------
+   !!   Default option :                                         NO diaar5
+   !!----------------------------------------------------------------------
+   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .FALSE.   ! coupled flag
+CONTAINS
+   SUBROUTINE dia_ar5_init    ! Dummy routine
+   END SUBROUTINE dia_ar5_init
+   SUBROUTINE dia_ar5( kt )   ! Empty routine
+      INTEGER ::   kt
+      WRITE(*,*) 'dia_ar5: You should not have seen this print! error?', kt
+   END SUBROUTINE dia_ar5
+#endif
+
+   !!======================================================================
+END MODULE diaar5
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/lib_mpp.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/lib_mpp.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/lib_mpp.F90	(revision 5879)
@@ -0,0 +1,4041 @@
+MODULE lib_mpp
+   !!======================================================================
+   !!                       ***  MODULE  lib_mpp  ***
+   !! Ocean numerics:  massively parallel processing library
+   !!=====================================================================
+   !! History :  OPA  !  1994  (M. Guyon, J. Escobar, M. Imbard)  Original code
+   !!            7.0  !  1997  (A.M. Treguier)  SHMEM additions
+   !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
+   !!                 !  1998  (J.M. Molines) Open boundary conditions
+   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
+   !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
+   !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
+   !!                 !  2004  (J.M. Molines) minloc, maxloc
+   !!             -   !  2005  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
+   !!             -   !  2005  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
+   !!             -   !  2005  (R. Benshila, G. Madec)  add extra halo case
+   !!             -   !  2008  (R. Benshila) add mpp_ini_ice
+   !!            3.2  !  2009  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
+   !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl
+   !!            4.0  !  2011  (G. Madec)  move ctl_ routines from in_out_manager
+   !!            3.5  !  2012  (S.Mocavero, I. Epicoco) Add 'mpp_lnk_bdy_3d', 'mpp_lnk_obc_3d', 
+   !!                          'mpp_lnk_bdy_2d' and 'mpp_lnk_obc_2d' routines and update
+   !!                          the mppobc routine to optimize the BDY and OBC communications
+   !!            3.5  !  2013  ( C. Ethe, G. Madec ) message passing arrays as local variables 
+   !!            3.5  !  2013  (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
+   !!            3.6  !  2015  (O. TintÃ³ and M. Castrillo - BSC) Added 'mpp_lnk_2d_multiple', 'mpp_lbc_north_2d_multiple', 'mpp_max_multiple' 
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
+   !!   ctl_warn   : initialization, namelist read, and parameters control
+   !!   ctl_opn    : Open file and check if required file is available.
+   !!   ctl_nam    : Prints informations when an error occurs while reading a namelist
+   !!   get_unit   : give the index of an unused logical unit
+   !!----------------------------------------------------------------------
+#if   defined key_mpp_mpi
+   !!----------------------------------------------------------------------
+   !!   'key_mpp_mpi'             MPI massively parallel processing library
+   !!----------------------------------------------------------------------
+   !!   lib_mpp_alloc : allocate mpp arrays
+   !!   mynode        : indentify the processor unit
+   !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
+   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
+   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
+   !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
+   !!   mpprecv       :
+   !!   mppsend       :   SUBROUTINE mpp_ini_znl
+   !!   mppscatter    :
+   !!   mppgather     :
+   !!   mpp_min       : generic interface for mppmin_int , mppmin_a_int , mppmin_real, mppmin_a_real
+   !!   mpp_max       : generic interface for mppmax_int , mppmax_a_int , mppmax_real, mppmax_a_real
+   !!   mpp_sum       : generic interface for mppsum_int , mppsum_a_int , mppsum_real, mppsum_a_real
+   !!   mpp_minloc    :
+   !!   mpp_maxloc    :
+   !!   mppsync       :
+   !!   mppstop       :
+   !!   mpp_ini_north : initialisation of north fold
+   !!   mpp_lbc_north : north fold processors gathering
+   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
+   !!   mpp_lbc_north_icb : variant of mpp_lbc_north for extra outer halo with icebergs
+   !!----------------------------------------------------------------------
+   USE dom_oce        ! ocean space and time domain
+   USE lbcnfd         ! north fold treatment
+   USE in_out_manager ! I/O manager
+   USE wrk_nemo       ! work arrays
+
+   IMPLICIT NONE
+   PRIVATE
+   
+   PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
+   PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
+   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
+   PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
+   PUBLIC   mpp_max_multiple
+   PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
+   PUBLIC   mpp_lnk_2d_9 , mpp_lnk_2d_multiple 
+   PUBLIC   mppscatter, mppgather
+   PUBLIC   mpp_ini_ice, mpp_ini_znl
+   PUBLIC   mppsize
+   PUBLIC   mppsend, mpprecv                          ! needed by TAM and ICB routines
+   PUBLIC   mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
+   PUBLIC   mpp_lbc_north_icb, mpp_lnk_2d_icb
+   PUBLIC   mpprank
+
+   TYPE arrayptr
+      REAL , DIMENSION (:,:),  POINTER :: pt2d
+   END TYPE arrayptr
+   PUBLIC   arrayptr
+   
+   !! * Interfaces
+   !! define generic interface for these routine as they are called sometimes
+   !! with scalar arguments instead of array arguments, which causes problems
+   !! for the compilation on AIX system as well as NEC and SGI. Ok on COMPACQ
+   INTERFACE mpp_min
+      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
+   END INTERFACE
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
+                       mppsum_realdd, mppsum_a_realdd
+   END INTERFACE
+   INTERFACE mpp_lbc_north
+      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d
+   END INTERFACE
+   INTERFACE mpp_minloc
+      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
+   END INTERFACE
+   INTERFACE mpp_maxloc
+      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
+   END INTERFACE
+
+   INTERFACE mpp_max_multiple
+      MODULE PROCEDURE mppmax_real_multiple
+   END INTERFACE
+
+   !! ========================= !!
+   !!  MPI  variable definition !!
+   !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
+   INCLUDE 'mpif.h'
+!$AGRIF_END_DO_NOT_TREAT
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
+
+   INTEGER, PARAMETER         ::   nprocmax = 2**10   ! maximun dimension (required to be a power of 2)
+
+   INTEGER ::   mppsize        ! number of process
+   INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
+!$AGRIF_DO_NOT_TREAT
+   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
+!$AGRIF_END_DO_NOT_TREAT
+
+   INTEGER :: MPI_SUMDD
+
+   ! variables used in case of sea-ice
+   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
+   INTEGER ::   ngrp_iworld     !  group ID for the world processors (for rheology)
+   INTEGER ::   ngrp_ice        !  group ID for the ice processors (for rheology)
+   INTEGER ::   ndim_rank_ice   !  number of 'ice' processors
+   INTEGER ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_ice     ! dimension ndim_rank_ice
+
+   ! variables used for zonal integration
+   INTEGER, PUBLIC ::   ncomm_znl       !: communicator made by the processors on the same zonal average
+   LOGICAL, PUBLIC ::   l_znl_root      ! True on the 'left'most processor on the same row
+   INTEGER ::   ngrp_znl        ! group ID for the znl processors
+   INTEGER ::   ndim_rank_znl   ! number of processors on the same zonal average
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_znl  ! dimension ndim_rank_znl, number of the procs into the same znl domain
+
+   ! North fold condition in mpp_mpi with jpni > 1 (PUBLIC for TAM)
+   INTEGER, PUBLIC ::   ngrp_world        ! group ID for the world processors
+   INTEGER, PUBLIC ::   ngrp_opa          ! group ID for the opa processors
+   INTEGER, PUBLIC ::   ngrp_north        ! group ID for the northern processors (to be fold)
+   INTEGER, PUBLIC ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
+   INTEGER, PUBLIC ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
+   INTEGER, PUBLIC ::   njmppmax          ! value of njmpp for the processors of the northern line
+   INTEGER, PUBLIC ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
+   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE, PUBLIC ::   nrank_north   ! dimension ndim_rank_north
+
+   ! Type of send : standard, buffered, immediate
+   CHARACTER(len=1), PUBLIC ::   cn_mpi_send   ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
+   LOGICAL, PUBLIC          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
+   INTEGER, PUBLIC          ::   nn_buffer     ! size of the buffer in case of mpi_bsend
+
+   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE :: tampon  ! buffer in case of bsend
+
+   LOGICAL, PUBLIC                                  ::   ln_nnogather       ! namelist control of northfold comms
+   LOGICAL, PUBLIC                                  ::   l_north_nogather = .FALSE.  ! internal control of northfold comms
+   INTEGER, PUBLIC                                  ::   ityp
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: lib_mpp.F90 8537 2017-09-19 05:46:09Z gm $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+
+   FUNCTION mynode( ldtxt, ldname, kumnam_ref , kumnam_cfg , kumond , kstop, localComm )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mynode  ***
+      !!
+      !! ** Purpose :   Find processor unit
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
+      CHARACTER(len=*)             , INTENT(in   ) ::   ldname
+      INTEGER                      , INTENT(in   ) ::   kumnam_ref     ! logical unit for reference namelist
+      INTEGER                      , INTENT(in   ) ::   kumnam_cfg     ! logical unit for configuration namelist
+      INTEGER                      , INTENT(inout) ::   kumond         ! logical unit for namelist output
+      INTEGER                      , INTENT(inout) ::   kstop          ! stop indicator
+      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
+      !
+      INTEGER ::   mynode, ierr, code, ji, ii, ios
+      LOGICAL ::   mpi_was_called
+      !
+      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, jpnij, ln_nnogather
+      !!----------------------------------------------------------------------
+      !
+      ii = 1
+      WRITE(ldtxt(ii),*)                                                                          ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                            ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '~~~~~~ '                                                                ;   ii = ii + 1
+      !
+
+      REWIND( kumnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
+      READ  ( kumnam_ref, nammpp, IOSTAT = ios, ERR = 901)
+901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
+
+      REWIND( kumnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
+      READ  ( kumnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
+902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
+
+      !                              ! control print
+      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                                     ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      mpi send type                      cn_mpi_send = ', cn_mpi_send   ;   ii = ii + 1
+      WRITE(ldtxt(ii),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer     ;   ii = ii + 1
+
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() ) THEN
+         jpni  = Agrif_Parent(jpni )
+         jpnj  = Agrif_Parent(jpnj )
+         jpnij = Agrif_Parent(jpnij)
+      ENDIF
+#endif
+
+      IF(jpnij < 1)THEN
+         ! If jpnij is not specified in namelist then we calculate it - this
+         ! means there will be no land cutting out.
+         jpnij = jpni * jpnj
+      END IF
+
+      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
+         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically'; ii = ii + 1
+      ELSE
+         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni; ii = ii + 1
+         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj; ii = ii + 1
+         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij; ii = ii +1
+      END IF
+
+      WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
+
+      CALL mpi_initialized ( mpi_was_called, code )
+      IF( code /= MPI_SUCCESS ) THEN
+         DO ji = 1, SIZE(ldtxt)
+            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+         END DO
+         WRITE(*, cform_err)
+         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
+         CALL mpi_abort( mpi_comm_world, code, ierr )
+      ENDIF
+
+      IF( mpi_was_called ) THEN
+         !
+         SELECT CASE ( cn_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            l_isend = .TRUE.
+         CASE DEFAULT
+            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            kstop = kstop + 1
+         END SELECT
+      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
+         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '                  ;   ii = ii + 1
+         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                        ;   ii = ii + 1
+         kstop = kstop + 1
+      ELSE
+         SELECT CASE ( cn_mpi_send )
+         CASE ( 'S' )                ! Standard mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
+            CALL mpi_init( ierr )
+         CASE ( 'B' )                ! Buffer mpi send (blocking)
+            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
+            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
+         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
+            l_isend = .TRUE.
+            CALL mpi_init( ierr )
+         CASE DEFAULT
+            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
+            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
+            kstop = kstop + 1
+         END SELECT
+         !
+      ENDIF
+
+      IF( PRESENT(localComm) ) THEN
+         IF( Agrif_Root() ) THEN
+            mpi_comm_opa = localComm
+         ENDIF
+      ELSE
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
+         IF( code /= MPI_SUCCESS ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF
+
+#if defined key_agrif
+      IF (Agrif_Root()) THEN
+         CALL Agrif_MPI_Init(mpi_comm_opa)
+      ELSE
+         CALL Agrif_MPI_set_grid_comm(mpi_comm_opa)
+      ENDIF
+#endif
+
+      CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
+      CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
+      mynode = mpprank
+
+      IF( mynode == 0 ) THEN
+         CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
+         WRITE(kumond, nammpp)      
+      ENDIF
+      !
+      CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
+      !
+   END FUNCTION mynode
+
+   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+      
+      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
+         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING ptab is defined only between nld and nle
+         DO jk = 1, jpk
+            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+               ptab(nldi  :nlei  , jj          ,jk) = ptab(nldi:nlei,     nlej,jk)
+               ptab(1     :nldi-1, jj          ,jk) = ptab(nldi     ,     nlej,jk)
+               ptab(nlei+1:nlci  , jj          ,jk) = ptab(     nlei,     nlej,jk)
+            END DO
+            DO ji = nlci+1, jpi                 ! added column(s) (full)
+               ptab(ji           ,nldj  :nlej  ,jk) = ptab(     nlei,nldj:nlej,jk)
+               ptab(ji           ,1     :nldj-1,jk) = ptab(     nlei,nldj     ,jk)
+               ptab(ji           ,nlej+1:jpj   ,jk) = ptab(     nlei,     nlej,jk)
+            END DO
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment
+         !
+         !                                   ! East-West boundaries
+         !                                        !* Cyclic east-west
+         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            ptab( 1 ,:,:) = ptab(jpim1,:,:)
+            ptab(jpi,:,:) = ptab(  2  ,:,:)
+         ELSE                                     !* closed
+            IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+                                         ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+         ENDIF
+         !                                   ! North-South boundaries (always closed)
+         IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+                                      ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = zt3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
+      !
+   END SUBROUTINE mpp_lnk_3d
+
+   SUBROUTINE mpp_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields , cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_multiple  ***
+      !!
+      !! ** Purpose :   Message passing management for multiple 2d arrays
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+
+      INTEGER :: num_fields
+      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
+      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
+      !                                                               ! = T , U , V , F , W and I points
+      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
+      !                                                               ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL    , INTENT(in   ) ::   cd_mpp       ! fill the overlap area only
+      REAL(wp)        , OPTIONAL    , INTENT(in   ) ::   pval         ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2*num_fields), zt2sn(jpi,jprecj,2*num_fields),  &
+         &      zt2ew(jpj,jpreci,2*num_fields), zt2we(jpj,jpreci,2*num_fields)   )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      !First Array
+      DO ii = 1 , num_fields
+         IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+            !
+            ! WARNING pt2d is defined only between nld and nle
+            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+               pt2d_array(ii)%pt2d(nldi  :nlei  , jj) = pt2d_array(ii)%pt2d(nldi:nlei, nlej)
+               pt2d_array(ii)%pt2d(1     :nldi-1, jj) = pt2d_array(ii)%pt2d(nldi     , nlej)
+               pt2d_array(ii)%pt2d(nlei+1:nlci  , jj) = pt2d_array(ii)%pt2d(     nlei, nlej) 
+            END DO
+            DO ji = nlci+1, jpi                 ! added column(s) (full)
+               pt2d_array(ii)%pt2d(ji, nldj  :nlej  ) = pt2d_array(ii)%pt2d(nlei, nldj:nlej)
+               pt2d_array(ii)%pt2d(ji, 1     :nldj-1) = pt2d_array(ii)%pt2d(nlei, nldj     )
+               pt2d_array(ii)%pt2d(ji, nlej+1:jpj   ) = pt2d_array(ii)%pt2d(nlei,      nlej)
+            END DO
+            !
+         ELSE                              ! standard close or cyclic treatment
+            !
+            !                                   ! East-West boundaries
+            IF( nbondi == 2 .AND.   &                ! Cyclic east-west
+               &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+               pt2d_array(ii)%pt2d(  1  , : ) = pt2d_array(ii)%pt2d( jpim1, : )                                    ! west
+               pt2d_array(ii)%pt2d( jpi , : ) = pt2d_array(ii)%pt2d(   2  , : )                                    ! east
+            ELSE                                     ! closed
+               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(            1 : jpreci,:) = zland    ! south except F-point
+                                                   pt2d_array(ii)%pt2d(nlci-jpreci+1 : jpi   ,:) = zland    ! north
+            ENDIF
+            !                                   ! North-South boundaries (always closed)
+               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(:,             1:jprecj ) = zland    ! south except F-point
+                                                   pt2d_array(ii)%pt2d(:, nlcj-jprecj+1:jpj    ) = zland    ! north
+            !
+         ENDIF
+      END DO
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      DO ii = 1 , num_fields
+         SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+            iihom = nlci-nreci
+            DO jl = 1, jpreci
+               zt2ew( : , jl , ii ) = pt2d_array(ii)%pt2d( jpreci+jl , : )
+               zt2we( : , jl , ii ) = pt2d_array(ii)%pt2d( iihom +jl , : )
+            END DO
+         END SELECT
+      END DO
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+
+      DO ii = 1 , num_fields
+         SELECT CASE ( nbondi )
+         CASE ( -1 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( jl , : ) = zt2we(:,jl,num_fields+ii)
+               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jpreci
+               pt2d_array(ii)%pt2d( jl , : )= zt2we(:,jl,num_fields+ii)
+            END DO
+         END SELECT
+      END DO
+      
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      !First Array
+      DO ii = 1 , num_fields
+         IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+            ijhom = nlcj-nrecj
+            DO jl = 1, jprecj
+               zt2sn(:,jl , ii) = pt2d_array(ii)%pt2d( : , ijhom +jl )
+               zt2ns(:,jl , ii) = pt2d_array(ii)%pt2d( : , jprecj+jl )
+            END DO
+         ENDIF
+      END DO
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+
+      DO ii = 1 , num_fields
+         !First Array
+         SELECT CASE ( nbondj )
+         CASE ( -1 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , ijhom+jl ) = zt2ns( : , jl , num_fields+ii )
+            END DO
+         CASE ( 0 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii)
+               pt2d_array(ii)%pt2d( : , ijhom + jl ) = zt2ns( : , jl , num_fields + ii )
+            END DO
+         CASE ( 1 )
+            DO jl = 1, jprecj
+               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii )
+            END DO
+         END SELECT
+      END DO
+      
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+         !First Array
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   
+             DO ii = 1 , num_fields  
+                       CALL lbc_nfd      ( pt2d_array(ii)%pt2d( : , : ), type_array(ii) , psgn_array(ii) )   ! only 1 northern proc, no mpp
+             END DO
+         CASE DEFAULT   ;   CALL mpp_lbc_north_2d_multiple( pt2d_array, type_array, psgn_array, num_fields )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+        !
+      
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
+      !
+   END SUBROUTINE mpp_lnk_2d_multiple
+
+   
+   SUBROUTINE load_array(pt2d,cd_type,psgn,pt2d_array, type_array, psgn_array,num_fields)
+      !!---------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), TARGET   ,   INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
+      REAL(wp)                    , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
+      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array
+      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
+      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
+      INTEGER                      , INTENT (inout):: num_fields 
+      !!---------------------------------------------------------------------
+      num_fields=num_fields+1
+      pt2d_array(num_fields)%pt2d=>pt2d
+      type_array(num_fields)=cd_type
+      psgn_array(num_fields)=psgn
+   END SUBROUTINE load_array
+   
+   
+   SUBROUTINE mpp_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
+      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
+      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
+      !!---------------------------------------------------------------------
+      ! Second 2D array on which the boundary condition is applied
+      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA    
+      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
+      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI 
+      ! define the nature of ptab array grid-points
+      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
+      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
+      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
+      ! =-1 the sign change across the north fold boundary
+      REAL(wp)                                      , INTENT(in   ) ::   psgnA    
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI   
+      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array 
+      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
+      INTEGER :: num_fields
+      !!---------------------------------------------------------------------
+
+      num_fields = 0
+
+      !! Load the first array
+      CALL load_array(pt2dA,cd_typeA,psgnA,pt2d_array, type_array, psgn_array,num_fields)
+
+      !! Look if more arrays are added
+      IF(PRESENT (psgnB) )CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnC) )CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnD) )CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnE) )CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnF) )CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnG) )CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnH) )CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
+      IF(PRESENT (psgnI) )CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
+      
+      CALL mpp_lnk_2d_multiple(pt2d_array,type_array,psgn_array,num_fields,cd_mpp,pval)
+   END SUBROUTINE mpp_lnk_2d_9
+
+
+   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W and I points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
+      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
+      !!
+      INTEGER  ::   ji, jj, jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
+         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
+
+      !
+      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
+      ELSE                         ;   zland = 0.e0      ! zero by default
+      ENDIF
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !
+      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
+         !
+         ! WARNING pt2d is defined only between nld and nle
+         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
+            pt2d(nldi  :nlei  , jj          ) = pt2d(nldi:nlei,     nlej)
+            pt2d(1     :nldi-1, jj          ) = pt2d(nldi     ,     nlej)
+            pt2d(nlei+1:nlci  , jj          ) = pt2d(     nlei,     nlej)
+         END DO
+         DO ji = nlci+1, jpi                 ! added column(s) (full)
+            pt2d(ji           ,nldj  :nlej  ) = pt2d(     nlei,nldj:nlej)
+            pt2d(ji           ,1     :nldj-1) = pt2d(     nlei,nldj     )
+            pt2d(ji           ,nlej+1:jpj   ) = pt2d(     nlei,     nlej)
+         END DO
+         !
+      ELSE                              ! standard close or cyclic treatment
+         !
+         !                                   ! East-West boundaries
+         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
+            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+            pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
+            pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
+         ELSE                                     ! closed
+            IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
+                                         pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
+         ENDIF
+         !                                   ! North-South boundaries (always closed)
+            IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
+                                         pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt2ew(:,jl,1) = pt2d(jpreci+jl,:)
+            zt2we(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = zt2we(:,jl,2)
+            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            pt2d(jl      ,:) = zt2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt2sn(:,jl,1) = pt2d(:,ijhom +jl)
+            zt2ns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = zt2sn(:,jl,2)
+            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            pt2d(:,jl      ) = zt2sn(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
+      !
+   END SUBROUTINE mpp_lnk_2d
+
+
+   SUBROUTINE mpp_lnk_3d_gather( ptab1, cd_type1, ptab2, cd_type2, psgn )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_3d_gather  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for two 3D arrays
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1     ! first and second 3D array on which
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2     ! the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ns, zt4sn   ! 2 x 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ew, zt4we   ! 2 x 3d for east-west & west-east
+
+      !!----------------------------------------------------------------------
+      ALLOCATE( zt4ns(jpi,jprecj,jpk,2,2), zt4sn(jpi,jprecj,jpk,2,2) ,    &
+         &      zt4ew(jpj,jpreci,jpk,2,2), zt4we(jpj,jpreci,jpk,2,2) )
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         ptab1( 1 ,:,:) = ptab1(jpim1,:,:)
+         ptab1(jpi,:,:) = ptab1(  2  ,:,:)
+         ptab2( 1 ,:,:) = ptab2(jpim1,:,:)
+         ptab2(jpi,:,:) = ptab2(  2  ,:,:)
+      ELSE                                        !* closed
+         IF( .NOT. cd_type1 == 'F' )   ptab1(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
+         IF( .NOT. cd_type2 == 'F' )   ptab2(     1       :jpreci,:,:) = 0.e0
+                                       ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
+                                       ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
+      ENDIF
+
+
+      !                                      ! North-South boundaries
+      IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
+      IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
+                                    ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
+                                    ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
+
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
+            zt4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
+            zt4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
+            zt4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk *2
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
+            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
+            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
+            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
+            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj - nrecj
+         DO jl = 1, jprecj
+            zt4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
+            zt4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
+            zt4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
+            zt4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk * 2
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
+            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab1(:,jl      ,:) = zt4sn(:,jl,:,1,2)
+            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
+            ptab2(:,jl      ,:) = zt4sn(:,jl,:,2,2)
+            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab1(:,jl,:) = zt4sn(:,jl,:,1,2)
+            ptab2(:,jl,:) = zt4sn(:,jl,:,2,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )
+            CALL lbc_nfd      ( ptab1, cd_type1, psgn )   ! only for northern procs.
+            CALL lbc_nfd      ( ptab2, cd_type2, psgn )
+         CASE DEFAULT
+            CALL mpp_lbc_north( ptab1, cd_type1, psgn )   ! for all northern procs.
+            CALL mpp_lbc_north (ptab2, cd_type2, psgn)
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt4ns, zt4sn, zt4ew, zt4we )
+      !
+   END SUBROUTINE mpp_lnk_3d_gather
+
+
+   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_e  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    jpri   : number of rows for extra outer halo
+      !!                    jprj   : number of columns for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER                                             , INTENT(in   ) ::   jpri
+      INTEGER                                             , INTENT(in   ) ::   jprj
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      !                                                                                 ! = T , U , V , F , W and I points
+      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
+      !!                                                                                ! north boundary, =  1. otherwise
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
+      iprecj = jprecj + jprj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      !                                      !* North-South boundaries (always colsed)
+      IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0.e0    ! south except at F-point
+                                   pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0.e0    ! north
+
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         !
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
+                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
+      ENDIF
+      !
+
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
+         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
+         END SELECT
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci-jpri
+         DO jl = 1, ipreci
+            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*jprj)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj-jprj
+         DO jl = 1, iprecj
+            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
+            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*jpri )
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+         END DO
+      END SELECT
+
+   END SUBROUTINE mpp_lnk_2d_e
+
+
+   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsend  ***
+      !!
+      !! ** Purpose :   Send messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
+      INTEGER , INTENT(in   ) ::   kbytes     ! size of the array pmess
+      INTEGER , INTENT(in   ) ::   kdest      ! receive process number
+      INTEGER , INTENT(in   ) ::   ktyp       ! tag of the message
+      INTEGER , INTENT(in   ) ::   md_req     ! argument for isend
+      !!
+      INTEGER ::   iflag
+      !!----------------------------------------------------------------------
+      !
+      SELECT CASE ( cn_mpi_send )
+      CASE ( 'S' )                ! Standard mpi send (blocking)
+         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
+      CASE ( 'B' )                ! Buffer mpi send (blocking)
+         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
+      CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
+         ! be carefull, one more argument here : the mpi request identifier..
+         CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa, md_req, iflag )
+      END SELECT
+      !
+   END SUBROUTINE mppsend
+
+
+   SUBROUTINE mpprecv( ktyp, pmess, kbytes, ksource )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpprecv  ***
+      !!
+      !! ** Purpose :   Receive messag passing array
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
+      INTEGER , INTENT(in   ) ::   kbytes     ! suze of the array pmess
+      INTEGER , INTENT(in   ) ::   ktyp       ! Tag of the recevied message
+      INTEGER, OPTIONAL, INTENT(in) :: ksource    ! source process number
+      !!
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      INTEGER :: use_source
+      !!----------------------------------------------------------------------
+      !
+
+      ! If a specific process number has been passed to the receive call,
+      ! use that one. Default is to use mpi_any_source
+      use_source=mpi_any_source
+      if(present(ksource)) then
+         use_source=ksource
+      end if
+
+      CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_opa, istatus, iflag )
+      !
+   END SUBROUTINE mpprecv
+
+
+   SUBROUTINE mppgather( ptab, kp, pio )
+      !!----------------------------------------------------------------------
+      !!                   ***  routine mppgather  ***
+      !!
+      !! ** Purpose :   Transfert between a local subdomain array and a work
+      !!     array which is distributed following the vertical level.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj),       INTENT(in   ) ::   ptab   ! subdomain input array
+      INTEGER ,                           INTENT(in   ) ::   kp     ! record length
+      REAL(wp), DIMENSION(jpi,jpj,jpnij), INTENT(  out) ::   pio    ! subdomain input array
+      !!
+      INTEGER :: itaille, ierror   ! temporary integer
+      !!---------------------------------------------------------------------
+      !
+      itaille = jpi * jpj
+      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille     ,   &
+         &                            mpi_double_precision, kp , mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppgather
+
+
+   SUBROUTINE mppscatter( pio, kp, ptab )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppscatter  ***
+      !!
+      !! ** Purpose :   Transfert between awork array which is distributed
+      !!      following the vertical level and the local subdomain array.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::  pio        ! output array
+      INTEGER                             ::   kp        ! Tag (not used with MPI
+      REAL(wp), DIMENSION(jpi,jpj)        ::  ptab       ! subdomain array input
+      !!
+      INTEGER :: itaille, ierror   ! temporary integer
+      !!---------------------------------------------------------------------
+      !
+      itaille=jpi*jpj
+      !
+      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
+         &                            mpi_double_precision, kp  , mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppscatter
+
+
+   SUBROUTINE mppmax_a_int( ktab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_a_int  ***
+      !!
+      !! ** Purpose :   Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim   ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   !
+      !!
+      INTEGER :: ierror, localcomm   ! temporary integer
+      INTEGER, DIMENSION(kdim) ::   iwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, localcomm, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppmax_a_int
+
+
+   SUBROUTINE mppmax_int( ktab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_int  ***
+      !!
+      !! ** Purpose :   Find maximum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout)           ::   ktab      ! ???
+      INTEGER, INTENT(in   ), OPTIONAL ::   kcom      ! ???
+      !!
+      INTEGER ::   ierror, iwork, localcomm   ! temporary integer
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror)
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppmax_int
+
+
+   SUBROUTINE mppmin_a_int( ktab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_a_int  ***
+      !!
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
+      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
+      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
+      !!
+      INTEGER ::   ierror, localcomm   ! temporary integer
+      INTEGER, DIMENSION(kdim) ::   iwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, localcomm, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppmin_a_int
+
+
+   SUBROUTINE mppmin_int( ktab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_int  ***
+      !!
+      !! ** Purpose :   Find minimum value in an integer layout array
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout) ::   ktab      ! ???
+      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
+      !!
+      INTEGER ::  ierror, iwork, localcomm
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+     CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppmin_int
+
+
+   SUBROUTINE mppsum_a_int( ktab, kdim )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_int  ***
+      !!
+      !! ** Purpose :   Global integer sum, 1D array case
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in   )                   ::   kdim      ! ???
+      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
+      !!
+      INTEGER :: ierror
+      INTEGER, DIMENSION (kdim) ::  iwork
+      !!----------------------------------------------------------------------
+      !
+      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      !
+      ktab(:) = iwork(:)
+      !
+   END SUBROUTINE mppsum_a_int
+
+
+   SUBROUTINE mppsum_int( ktab )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppsum_int  ***
+      !!
+      !! ** Purpose :   Global integer sum
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(inout) ::   ktab
+      !!
+      INTEGER :: ierror, iwork
+      !!----------------------------------------------------------------------
+      !
+      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
+      !
+      ktab = iwork
+      !
+   END SUBROUTINE mppsum_int
+
+
+   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppmax_a_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim
+      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
+      !!
+      INTEGER :: ierror, localcomm
+      REAL(wp), DIMENSION(kdim) ::  zwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppmax_a_real
+
+
+   SUBROUTINE mppmax_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab   ! ???
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmax_real_multiple( ptab, NUM , kcom  )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmax_real  ***
+      !!
+      !! ** Purpose :   Maximum
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:) ,  INTENT(inout)           ::   ptab   ! ???
+      INTEGER , INTENT(in   )           ::   NUM
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) , POINTER , DIMENSION(:) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      CALL wrk_alloc(NUM , zwork)
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, NUM, mpi_double_precision, mpi_max, localcomm, ierror )
+      ptab = zwork
+      CALL wrk_dealloc(NUM , zwork)
+      !
+   END SUBROUTINE mppmax_real_multiple
+
+
+   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                 ***  routine mppmin_a_real  ***
+      !!
+      !! ** Purpose :   Minimum of REAL, array case
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT(in   )                  ::   kdim
+      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
+      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
+      !!
+      INTEGER :: ierror, localcomm
+      REAL(wp), DIMENSION(kdim) ::   zwork
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppmin_a_real
+
+
+   SUBROUTINE mppmin_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppmin_real  ***
+      !!
+      !! ** Purpose :   minimum of REAL, scalar case
+      !!
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab        !
+      INTEGER , INTENT(in   ), OPTIONAL :: kcom
+      !!
+      INTEGER  ::   ierror
+      REAL(wp) ::   zwork
+      INTEGER :: localcomm
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppmin_real
+
+
+   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_real  ***
+      !!
+      !! ** Purpose :   global sum, REAL ARRAY argument case
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
+      REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
+      INTEGER , INTENT( in ), OPTIONAL           :: kcom
+      !!
+      INTEGER                   ::   ierror    ! temporary integer
+      INTEGER                   ::   localcomm
+      REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) )   localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, localcomm, ierror )
+      ptab(:) = zwork(:)
+      !
+   END SUBROUTINE mppsum_a_real
+
+
+   SUBROUTINE mppsum_real( ptab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_real  ***
+      !!
+      !! ** Purpose :   global sum, SCALAR argument case
+      !!
+      !!-----------------------------------------------------------------------
+      REAL(wp), INTENT(inout)           ::   ptab   ! input scalar
+      INTEGER , INTENT(in   ), OPTIONAL ::   kcom
+      !!
+      INTEGER  ::   ierror, localcomm
+      REAL(wp) ::   zwork
+      !!-----------------------------------------------------------------------
+      !
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+      !
+      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, localcomm, ierror )
+      ptab = zwork
+      !
+   END SUBROUTINE mppsum_real
+
+   SUBROUTINE mppsum_realdd( ytab, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_realdd ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                SCALAR argument case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER  ::    ierror
+      INTEGER  ::   localcomm
+      COMPLEX(wp) :: zwork
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      ! reduce local sums into global sum
+      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab = zwork
+
+   END SUBROUTINE mppsum_realdd
+
+
+   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsum_a_realdd  ***
+      !!
+      !! ** Purpose :   global sum in Massively Parallel Processing
+      !!                COMPLEX ARRAY case for double-double precision
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+
+      !! * Local variables   (MPI version)
+      INTEGER                      :: ierror    ! temporary integer
+      INTEGER                      ::   localcomm
+      COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
+
+      localcomm = mpi_comm_opa
+      IF( PRESENT(kcom) ) localcomm = kcom
+
+      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
+                       MPI_SUMDD,localcomm,ierror)
+      ytab(:) = zwork(:)
+
+   END SUBROUTINE mppsum_a_realdd
+
+   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_minloc  ***
+      !!
+      !! ** Purpose :   Compute the global minimum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab    ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask   ! Local mask
+      REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
+      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
+      !!
+      INTEGER , DIMENSION(2)   ::   ilocs
+      INTEGER :: ierror
+      REAL(wp) ::   zmin   ! local minimum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1.e0 )
+      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      !
+      zain(1,:)=zmin
+      zain(2,:)=ki+10000.*kj
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
+      !
+      pmin = zaout(1,1)
+      kj = INT(zaout(2,1)/10000.)
+      ki = INT(zaout(2,1) - 10000.*kj )
+      !
+   END SUBROUTINE mpp_minloc2d
+
+
+   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj ,kk)
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_minloc  ***
+      !!
+      !! ** Purpose :   Compute the global minimum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                         , INTENT(  out) ::   pmin         ! Global minimum of ptab
+      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
+      !!
+      INTEGER  ::   ierror
+      REAL(wp) ::   zmin     ! local minimum
+      INTEGER , DIMENSION(3)   ::   ilocs
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
+      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      kk = ilocs(3)
+      !
+      zain(1,:)=zmin
+      zain(2,:)=ki+10000.*kj+100000000.*kk
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
+      !
+      pmin = zaout(1,1)
+      kk   = INT( zaout(2,1) / 100000000. )
+      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
+      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
+      !
+   END SUBROUTINE mpp_minloc3d
+
+
+   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_maxloc  ***
+      !!
+      !! ** Purpose :   Compute the global maximum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab     ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask    ! Local mask
+      REAL(wp)                     , INTENT(  out) ::   pmax     ! Global maximum of ptab
+      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of maximum in global frame
+      !!
+      INTEGER  :: ierror
+      INTEGER, DIMENSION (2)   ::   ilocs
+      REAL(wp) :: zmax   ! local maximum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      !!-----------------------------------------------------------------------
+      !
+      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1.e0 )
+      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      !
+      zain(1,:) = zmax
+      zain(2,:) = ki + 10000. * kj
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
+      !
+      pmax = zaout(1,1)
+      kj   = INT( zaout(2,1) / 10000.     )
+      ki   = INT( zaout(2,1) - 10000.* kj )
+      !
+   END SUBROUTINE mpp_maxloc2d
+
+
+   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
+      !!------------------------------------------------------------------------
+      !!             ***  routine mpp_maxloc  ***
+      !!
+      !! ** Purpose :  Compute the global maximum of an array ptab
+      !!              and also give its global position
+      !!
+      !! ** Method : Use MPI_ALLREDUCE with MPI_MINLOC
+      !!
+      !!--------------------------------------------------------------------------
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
+      REAL(wp)                         , INTENT(  out) ::   pmax         ! Global maximum of ptab
+      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
+      !!
+      REAL(wp) :: zmax   ! local maximum
+      REAL(wp), DIMENSION(2,1) ::   zain, zaout
+      INTEGER , DIMENSION(3)   ::   ilocs
+      INTEGER :: ierror
+      !!-----------------------------------------------------------------------
+      !
+      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
+      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
+      !
+      ki = ilocs(1) + nimpp - 1
+      kj = ilocs(2) + njmpp - 1
+      kk = ilocs(3)
+      !
+      zain(1,:)=zmax
+      zain(2,:)=ki+10000.*kj+100000000.*kk
+      !
+      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
+      !
+      pmax = zaout(1,1)
+      kk   = INT( zaout(2,1) / 100000000. )
+      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
+      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
+      !
+   END SUBROUTINE mpp_maxloc3d
+
+
+   SUBROUTINE mppsync()
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppsync  ***
+      !!
+      !! ** Purpose :   Massively parallel processors, synchroneous
+      !!
+      !!-----------------------------------------------------------------------
+      INTEGER :: ierror
+      !!-----------------------------------------------------------------------
+      !
+      CALL mpi_barrier( mpi_comm_opa, ierror )
+      !
+   END SUBROUTINE mppsync
+
+
+   SUBROUTINE mppstop
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mppstop  ***
+      !!
+      !! ** purpose :   Stop massively parallel processors method
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ::   info
+      !!----------------------------------------------------------------------
+      !
+      CALL mppsync
+      CALL mpi_finalize( info )
+      !
+   END SUBROUTINE mppstop
+
+
+   SUBROUTINE mpp_comm_free( kcom )
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kcom
+      !!
+      INTEGER :: ierr
+      !!----------------------------------------------------------------------
+      !
+      CALL MPI_COMM_FREE(kcom, ierr)
+      !
+   END SUBROUTINE mpp_comm_free
+
+
+   SUBROUTINE mpp_ini_ice( pindic, kumout )
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_ice  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for ice areas
+      !!      condition together with global variables needed in the ddmpp folding
+      !!
+      !! ** Method  : - Look for ice processors in ice routines
+      !!              - Put their number in nrank_ice
+      !!              - Create groups for the world processors and the ice processors
+      !!              - Create a communicator for ice processors
+      !!
+      !! ** output
+      !!      njmppmax = njmpp for northern procs
+      !!      ndim_rank_ice = number of processors with ice
+      !!      nrank_ice (ndim_rank_ice) = ice processors
+      !!      ngrp_iworld = group ID for the world processors
+      !!      ngrp_ice = group ID for the ice processors
+      !!      ncomm_ice = communicator for the ice procs.
+      !!      n_ice_root = number (in the world) of proc 0 in the ice comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   pindic
+      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical unit
+      !!
+      INTEGER :: jjproc
+      INTEGER :: ii, ierr
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kice
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   zwork
+      !!----------------------------------------------------------------------
+      !
+      ! Since this is just an init routine and these arrays are of length jpnij
+      ! then don't use wrk_nemo module - just allocate and deallocate.
+      ALLOCATE( kice(jpnij), zwork(jpnij), STAT=ierr )
+      IF( ierr /= 0 ) THEN
+         WRITE(kumout, cform_err)
+         WRITE(kumout,*) 'mpp_ini_ice : failed to allocate 2, 1D arrays (jpnij in length)'
+         CALL mppstop
+      ENDIF
+
+      ! Look for how many procs with sea-ice
+      !
+      kice = 0
+      DO jjproc = 1, jpnij
+         IF( jjproc == narea .AND. pindic .GT. 0 )   kice(jjproc) = 1
+      END DO
+      !
+      zwork = 0
+      CALL MPI_ALLREDUCE( kice, zwork, jpnij, mpi_integer, mpi_sum, mpi_comm_opa, ierr )
+      ndim_rank_ice = SUM( zwork )
+
+      ! Allocate the right size to nrank_north
+      IF( ALLOCATED ( nrank_ice ) )   DEALLOCATE( nrank_ice )
+      ALLOCATE( nrank_ice(ndim_rank_ice) )
+      !
+      ii = 0
+      nrank_ice = 0
+      DO jjproc = 1, jpnij
+         IF( zwork(jjproc) == 1) THEN
+            ii = ii + 1
+            nrank_ice(ii) = jjproc -1
+         ENDIF
+      END DO
+
+      ! Create the world group
+      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_iworld, ierr )
+
+      ! Create the ice group from the world group
+      CALL MPI_GROUP_INCL( ngrp_iworld, ndim_rank_ice, nrank_ice, ngrp_ice, ierr )
+
+      ! Create the ice communicator , ie the pool of procs with sea-ice
+      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_ice, ncomm_ice, ierr )
+
+      ! Find proc number in the world of proc 0 in the north
+      ! The following line seems to be useless, we just comment & keep it as reminder
+      ! CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_ice,1,0,ngrp_iworld,n_ice_root,ierr)
+      !
+      CALL MPI_GROUP_FREE(ngrp_ice, ierr)
+      CALL MPI_GROUP_FREE(ngrp_iworld, ierr)
+
+      DEALLOCATE(kice, zwork)
+      !
+   END SUBROUTINE mpp_ini_ice
+
+
+   SUBROUTINE mpp_ini_znl( kumout )
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_znl  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for computing zonal sum
+      !!
+      !! ** Method  : - Look for processors in the same row
+      !!              - Put their number in nrank_znl
+      !!              - Create group for the znl processors
+      !!              - Create a communicator for znl processors
+      !!              - Determine if processor should write znl files
+      !!
+      !! ** output
+      !!      ndim_rank_znl = number of processors on the same row
+      !!      ngrp_znl = group ID for the znl processors
+      !!      ncomm_znl = communicator for the ice procs.
+      !!      n_znl_root = number (in the world) of proc 0 in the ice comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical units
+      !
+      INTEGER :: jproc      ! dummy loop integer
+      INTEGER :: ierr, ii   ! local integer
+      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kwork
+      !!----------------------------------------------------------------------
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_world     : ', ngrp_world
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_world : ', mpi_comm_world
+      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_opa   : ', mpi_comm_opa
+      !
+      ALLOCATE( kwork(jpnij), STAT=ierr )
+      IF( ierr /= 0 ) THEN
+         WRITE(kumout, cform_err)
+         WRITE(kumout,*) 'mpp_ini_znl : failed to allocate 1D array of length jpnij'
+         CALL mppstop
+      ENDIF
+
+      IF( jpnj == 1 ) THEN
+         ngrp_znl  = ngrp_world
+         ncomm_znl = mpi_comm_opa
+      ELSE
+         !
+         CALL MPI_ALLGATHER ( njmpp, 1, mpi_integer, kwork, 1, mpi_integer, mpi_comm_opa, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - kwork pour njmpp : ', kwork
+         !-$$        CALL flush(numout)
+         !
+         ! Count number of processors on the same row
+         ndim_rank_znl = 0
+         DO jproc=1,jpnij
+            IF ( kwork(jproc) == njmpp ) THEN
+               ndim_rank_znl = ndim_rank_znl + 1
+            ENDIF
+         END DO
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ndim_rank_znl : ', ndim_rank_znl
+         !-$$        CALL flush(numout)
+         ! Allocate the right size to nrank_znl
+         IF (ALLOCATED (nrank_znl)) DEALLOCATE(nrank_znl)
+         ALLOCATE(nrank_znl(ndim_rank_znl))
+         ii = 0
+         nrank_znl (:) = 0
+         DO jproc=1,jpnij
+            IF ( kwork(jproc) == njmpp) THEN
+               ii = ii + 1
+               nrank_znl(ii) = jproc -1
+            ENDIF
+         END DO
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - nrank_znl : ', nrank_znl
+         !-$$        CALL flush(numout)
+
+         ! Create the opa group
+         CALL MPI_COMM_GROUP(mpi_comm_opa,ngrp_opa,ierr)
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_opa : ', ngrp_opa
+         !-$$        CALL flush(numout)
+
+         ! Create the znl group from the opa group
+         CALL MPI_GROUP_INCL  ( ngrp_opa, ndim_rank_znl, nrank_znl, ngrp_znl, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_znl ', ngrp_znl
+         !-$$        CALL flush(numout)
+
+         ! Create the znl communicator from the opa communicator, ie the pool of procs in the same row
+         CALL MPI_COMM_CREATE ( mpi_comm_opa, ngrp_znl, ncomm_znl, ierr )
+         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ncomm_znl ', ncomm_znl
+         !-$$        CALL flush(numout)
+         !
+      END IF
+
+      ! Determines if processor if the first (starting from i=1) on the row
+      IF ( jpni == 1 ) THEN
+         l_znl_root = .TRUE.
+      ELSE
+         l_znl_root = .FALSE.
+         kwork (1) = nimpp
+         CALL mpp_min ( kwork(1), kcom = ncomm_znl)
+         IF ( nimpp == kwork(1)) l_znl_root = .TRUE.
+      END IF
+
+      DEALLOCATE(kwork)
+
+   END SUBROUTINE mpp_ini_znl
+
+
+   SUBROUTINE mpp_ini_north
+      !!----------------------------------------------------------------------
+      !!               ***  routine mpp_ini_north  ***
+      !!
+      !! ** Purpose :   Initialize special communicator for north folding
+      !!      condition together with global variables needed in the mpp folding
+      !!
+      !! ** Method  : - Look for northern processors
+      !!              - Put their number in nrank_north
+      !!              - Create groups for the world processors and the north processors
+      !!              - Create a communicator for northern processors
+      !!
+      !! ** output
+      !!      njmppmax = njmpp for northern procs
+      !!      ndim_rank_north = number of processors in the northern line
+      !!      nrank_north (ndim_rank_north) = number  of the northern procs.
+      !!      ngrp_world = group ID for the world processors
+      !!      ngrp_north = group ID for the northern processors
+      !!      ncomm_north = communicator for the northern procs.
+      !!      north_root = number (in the world) of proc 0 in the northern comm.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ::   ierr
+      INTEGER ::   jjproc
+      INTEGER ::   ii, ji
+      !!----------------------------------------------------------------------
+      !
+      njmppmax = MAXVAL( njmppt )
+      !
+      ! Look for how many procs on the northern boundary
+      ndim_rank_north = 0
+      DO jjproc = 1, jpnij
+         IF( njmppt(jjproc) == njmppmax )   ndim_rank_north = ndim_rank_north + 1
+      END DO
+      !
+      ! Allocate the right size to nrank_north
+      IF (ALLOCATED (nrank_north)) DEALLOCATE(nrank_north)
+      ALLOCATE( nrank_north(ndim_rank_north) )
+
+      ! Fill the nrank_north array with proc. number of northern procs.
+      ! Note : the rank start at 0 in MPI
+      ii = 0
+      DO ji = 1, jpnij
+         IF ( njmppt(ji) == njmppmax   ) THEN
+            ii=ii+1
+            nrank_north(ii)=ji-1
+         END IF
+      END DO
+      !
+      ! create the world group
+      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
+      !
+      ! Create the North group from the world group
+      CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_north, nrank_north, ngrp_north, ierr )
+      !
+      ! Create the North communicator , ie the pool of procs in the north group
+      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_north, ncomm_north, ierr )
+      !
+   END SUBROUTINE mpp_ini_north
+
+
+   SUBROUTINE mpp_lbc_north_3d( pt3d, cd_type, psgn )
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_3d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the b.c. is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
+      !                                                              !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr, jk
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)          ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                                ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
+
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk), zfoldwk(jpi,4,jpk), znorthgloio(jpi,4,jpk,jpni) )
+      ALLOCATE( ztabl(jpi,4,jpk), ztabr(jpi*jpmaxngh, 4, jpk) ) 
+
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      znorthloc(:,:,:) = 0
+      DO jk = 1, jpk
+         DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
+            ij = jj - nlcj + ijpj
+            znorthloc(:,ij,jk) = pt3d(:,jj,jk)
+         END DO
+      END DO
+      !
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * jpk * ijpj
+
+      IF ( l_north_nogather ) THEN
+         !
+        ztabr(:,:,:) = 0
+        ztabl(:,:,:) = 0
+
+        DO jk = 1, jpk
+           DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+              ij = jj - nlcj + ijpj
+              DO ji = nfsloop, nfeloop
+                 ztabl(ji,ij,jk) = pt3d(ji,jj,jk)
+              END DO
+           END DO
+        END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
+              DO jk = 1, jpk
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)
+                    END DO
+                 END DO
+              END DO
+           ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jk = 1, jpk
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = pt3d(ji,nlcj-ijpj+jj,jk)
+                    END DO
+                 END DO
+              END DO
+           ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF    
+            END DO
+         ENDIF
+         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
+         DO jk = 1, jpk
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
+               ij = jj - nlcj + ijpj
+               DO ji= 1, nlci
+                  pt3d(ji,jj,jk) = ztabl(ji,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+
+      ELSE
+         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
+            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:,:) = 0.e0
+         DO jr = 1, ndim_rank_north         ! recover the global north array
+            iproc = nrank_north(jr) + 1
+            ildi  = nldit (iproc)
+            ilei  = nleit (iproc)
+            iilb  = nimppt(iproc)
+            DO jk = 1, jpk
+               DO jj = 1, ijpj
+                  DO ji = ildi, ilei
+                    ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                  END DO
+               END DO
+            END DO
+         END DO
+         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jk = 1, jpk
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
+               ij = jj - nlcj + ijpj
+               DO ji= 1, nlci
+                  pt3d(ji,jj,jk) = ztab(ji+nimpp-1,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+      ENDIF
+      !
+      ! The ztab array has been either:
+      !  a. Fully populated by the mpi_allgather operation or
+      !  b. Had the active points for this domain and northern neighbours populated
+      !     by peer to peer exchanges
+      ! Either way the array may be folded by lbc_nfd and the result for the span of
+      ! this domain will be identical.
+      !
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr ) 
+      !
+   END SUBROUTINE mpp_lbc_north_3d
+
+
+   SUBROUTINE mpp_lbc_north_2d( pt2d, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the b.c. is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
+      !                                                          !   = T ,  U , V , F or W  gridpoints
+      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztabl, ztabr
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4), znorthloc(jpi,4), zfoldwk(jpi,4), znorthgloio(jpi,4,jpni) )
+      ALLOCATE( ztabl(jpi,4), ztabr(jpi*jpmaxngh, 4) ) 
+      !
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
+         ij = jj - nlcj + ijpj
+         znorthloc(:,ij) = pt2d(:,jj)
+      END DO
+
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * ijpj
+      IF ( l_north_nogather ) THEN
+         !
+         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
+         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
+         !
+         ztabr(:,:) = 0
+         ztabl(:,:) = 0
+
+         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+            ij = jj - nlcj + ijpj
+              DO ji = nfsloop, nfeloop
+               ztabl(ji,ij) = pt2d(ji,jj)
+            END DO
+         END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+               CALL mppsend(5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr))
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille, iproc)
+              DO jj = 1, ijpj
+                 DO ji = ildi, ilei
+                    ztabr(iilb+ji,jj) = zfoldwk(ji,jj)
+                 END DO
+              END DO
+            ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jj = 1, ijpj
+                 DO ji = ildi, ilei
+                    ztabr(iilb+ji,jj) = pt2d(ji,nlcj-ijpj+jj)
+                 END DO
+              END DO
+            ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF
+            END DO
+         ENDIF
+         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+            ij = jj - nlcj + ijpj
+            DO ji = 1, nlci
+               pt2d(ji,jj) = ztabl(ji,ij)
+            END DO
+         END DO
+         !
+      ELSE
+         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,        &
+            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:) = 0.e0
+         DO jr = 1, ndim_rank_north            ! recover the global north array
+            iproc = nrank_north(jr) + 1
+            ildi = nldit (iproc)
+            ilei = nleit (iproc)
+            iilb = nimppt(iproc)
+            DO jj = 1, ijpj
+               DO ji = ildi, ilei
+                  ztab(ji+iilb-1,jj) = znorthgloio(ji,jj,jr)
+               END DO
+            END DO
+         END DO
+         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
+         !
+         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+            ij = jj - nlcj + ijpj
+            DO ji = 1, nlci
+               pt2d(ji,jj) = ztab(ji+nimpp-1,ij)
+            END DO
+         END DO
+         !
+      ENDIF
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr ) 
+      !
+   END SUBROUTINE mpp_lbc_north_2d
+
+   SUBROUTINE mpp_lbc_north_2d_multiple( pt2d_array, cd_type, psgn, num_fields)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1
+      !!              (for multiple 2d arrays )
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4 northern lines of the global domain on 1 processor
+      !!              and apply lbc north-fold on this sub array. Then we
+      !!              scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER ,  INTENT (in   ) ::   num_fields  ! number of variables contained in pt2d
+      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
+      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
+      !                                                          !   = T ,  U , V , F or W  gridpoints
+      REAL(wp), DIMENSION(:), INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
+      !!                                                             ! =  1. , the sign is kept
+      INTEGER ::   ji, jj, jr, jk
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ijpjm1, ij, iproc
+      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
+      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
+      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
+      !                                                              ! Workspace for message transfers avoiding mpi_allgather
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
+      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
+      INTEGER :: istatus(mpi_status_size)
+      INTEGER :: iflag
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab(jpiglo,4,num_fields), znorthloc(jpi,4,num_fields), zfoldwk(jpi,4,num_fields),   & 
+            &   znorthgloio(jpi,4,num_fields,jpni) )   ! expanded to 3 dimensions
+      ALLOCATE( ztabl(jpi,4,num_fields), ztabr(jpi*jpmaxngh, 4,num_fields) )
+      !
+      ijpj   = 4
+      ijpjm1 = 3
+      !
+      
+      DO jk = 1, num_fields
+         DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d (for every variable)
+            ij = jj - nlcj + ijpj
+            znorthloc(:,ij,jk) = pt2d_array(jk)%pt2d(:,jj)
+         END DO
+      END DO
+      !                                     ! Build in procs of ncomm_north the znorthgloio
+      itaille = jpi * ijpj
+                                                                  
+      IF ( l_north_nogather ) THEN
+         !
+         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
+         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
+         !
+         ztabr(:,:,:) = 0
+         ztabl(:,:,:) = 0
+
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
+               ij = jj - nlcj + ijpj
+               DO ji = nfsloop, nfeloop
+                  ztabl(ji,ij,jk) = pt2d_array(jk)%pt2d(ji,jj)
+               END DO
+            END DO
+         END DO
+
+         DO jr = 1,nsndto
+            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+               CALL mppsend(5, znorthloc, itaille*num_fields, nfipproc(isendto(jr),jpnj), ml_req_nf(jr)) ! Buffer expanded "num_fields" times
+            ENDIF
+         END DO
+         DO jr = 1,nsndto
+            iproc = nfipproc(isendto(jr),jpnj)
+            IF(iproc .ne. -1) THEN
+               ilei = nleit (iproc+1)
+               ildi = nldit (iproc+1)
+               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
+            ENDIF
+            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
+              CALL mpprecv(5, zfoldwk, itaille*num_fields, iproc) ! Buffer expanded "num_fields" times
+              DO jk = 1 , num_fields
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)       ! Modified to 3D
+                    END DO
+                 END DO
+              END DO
+            ELSE IF (iproc .eq. (narea-1)) THEN
+              DO jk = 1, num_fields
+                 DO jj = 1, ijpj
+                    DO ji = ildi, ilei
+                          ztabr(iilb+ji,jj,jk) = pt2d_array(jk)%pt2d(ji,nlcj-ijpj+jj)       ! Modified to 3D
+                    END DO
+                 END DO
+              END DO
+            ENDIF
+         END DO
+         IF (l_isend) THEN
+            DO jr = 1,nsndto
+               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
+                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
+               ENDIF
+            END DO
+         ENDIF
+         !
+         DO ji = 1, num_fields     ! Loop to manage 3D variables
+            CALL mpp_lbc_nfd( ztabl(:,:,ji), ztabr(:,:,ji), cd_type(ji), psgn(ji) )  ! North fold boundary condition
+         END DO
+         !
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+               ij = jj - nlcj + ijpj
+               DO ji = 1, nlci
+                  pt2d_array(jk)%pt2d(ji,jj) = ztabl(ji,ij,jk)       ! Modified to 3D
+               END DO
+            END DO
+         END DO
+         
+         !
+      ELSE
+         !
+         CALL MPI_ALLGATHER( znorthloc  , itaille*num_fields, MPI_DOUBLE_PRECISION,        &
+            &                znorthgloio, itaille*num_fields, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+         !
+         ztab(:,:,:) = 0.e0
+         DO jk = 1, num_fields
+            DO jr = 1, ndim_rank_north            ! recover the global north array
+               iproc = nrank_north(jr) + 1
+               ildi = nldit (iproc)
+               ilei = nleit (iproc)
+               iilb = nimppt(iproc)
+               DO jj = 1, ijpj
+                  DO ji = ildi, ilei
+                     ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
+                  END DO
+               END DO
+            END DO
+         END DO
+         
+         DO ji = 1, num_fields
+            CALL lbc_nfd( ztab(:,:,ji), cd_type(ji), psgn(ji) )   ! North fold boundary condition
+         END DO
+         !
+         DO jk = 1, num_fields
+            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
+               ij = jj - nlcj + ijpj
+               DO ji = 1, nlci
+                  pt2d_array(jk)%pt2d(ji,jj) = ztab(ji+nimpp-1,ij,jk)
+               END DO
+            END DO
+         END DO
+         !
+         !
+      ENDIF
+      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
+      DEALLOCATE( ztabl, ztabr )
+      !
+   END SUBROUTINE mpp_lbc_north_2d_multiple
+
+   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_2d  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              processor and apply lbc north-fold on this sub array.
+      !!              Then we scatter the north fold array back to the processors.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                                                         !   = T ,  U , V , F or W -points
+      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
+      !!                                                                                        ! north fold, =  1. otherwise
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ij, iproc
+      !
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
+
+      !!----------------------------------------------------------------------
+      !
+      ALLOCATE( ztab_e(jpiglo,4+2*jpr2dj), znorthloc_e(jpi,4+2*jpr2dj), znorthgloio_e(jpi,4+2*jpr2dj,jpni) )
+
+      !
+      ijpj=4
+      ztab_e(:,:) = 0.e0
+
+      ij=0
+      ! put in znorthloc_e the last 4 jlines of pt2d
+      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
+         ij = ij + 1
+         DO ji = 1, jpi
+            znorthloc_e(ji,ij)=pt2d(ji,jj)
+         END DO
+      END DO
+      !
+      itaille = jpi * ( ijpj + 2 * jpr2dj )
+      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
+         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1, ijpj+2*jpr2dj
+            DO ji = ildi, ilei
+               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
+
+      ij = jpr2dj
+      !! Scatter back to pt2d
+      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
+      ij  = ij +1
+         DO ji= 1, nlci
+            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+         END DO
+      END DO
+      !
+      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
+      !
+   END SUBROUTINE mpp_lbc_north_e
+
+      SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_bdy_3d  ***
+      !!
+      !! ** Purpose :   Message passing management
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi_bdy : mark for "east-west local boundary"
+      !!                    nbondj_bdy : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                             ! = T , U , V , F , W points
+      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                             ! =  1. , the sign is kept
+      INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
+      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland                      ! local scalar
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
+      !!----------------------------------------------------------------------
+      
+      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
+         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
+
+      zland = 0.e0
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      
+      !                                   ! East-West boundaries
+      !                                        !* Cyclic east-west
+
+      IF( nbondi == 2) THEN
+        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+          ptab( 1 ,:,:) = ptab(jpim1,:,:)
+          ptab(jpi,:,:) = ptab(  2  ,:,:)
+        ELSE
+          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+          ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+        ENDIF
+      ELSEIF(nbondi == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
+      ELSEIF(nbondi == 1) THEN
+        ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
+      ENDIF                                     !* closed
+
+      IF (nbondj == 2 .OR. nbondj == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
+      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
+        ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
+      ENDIF
+      
+      !
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
+            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj * jpk
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+      CASE ( 0 )
+         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+      CASE ( 1 )
+         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
+            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi * jpk
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+      CASE ( 0 )
+         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+      CASE ( 1 )
+         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
+            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl,:) = zt3sn(:,jl,:,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
+      !
+   END SUBROUTINE mpp_lnk_bdy_3d
+
+
+   SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_bdy_2d  ***
+      !!
+      !! ** Purpose :   Message passing management
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    nbondi_bdy : mark for "east-west local boundary"
+      !!                    nbondj_bdy : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors 
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !! ** Action  :   ptab with update value at its periphery
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
+      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
+      !                                                         ! = T , U , V , F , W points
+      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
+      !                                                         ! =  1. , the sign is kept
+      INTEGER                     , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
+      !
+      INTEGER  ::   ji, jj, jl             ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! local integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      REAL(wp) ::   zland
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
+      !!----------------------------------------------------------------------
+
+      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
+         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
+
+      zland = 0._wp
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      
+      !                                   ! East-West boundaries
+      !                                        !* Cyclic east-west
+
+      IF( nbondi == 2) THEN
+        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
+          ptab( 1 ,:) = ptab(jpim1,:)
+          ptab(jpi,:) = ptab(  2  ,:)
+        ELSE
+          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
+          ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+        ENDIF
+      ELSEIF(nbondi == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
+      ELSEIF(nbondi == 1) THEN
+        ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
+      ENDIF                                     !* closed
+
+      IF (nbondj == 2 .OR. nbondj == -1) THEN
+        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj) = zland       ! south except F-point
+      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
+        ptab(:,nlcj-jprecj+1:jpj) = zland       ! north
+      ENDIF
+      
+      !
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity 
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci
+         DO jl = 1, jpreci
+            zt2ew(:,jl,1) = ptab(jpreci+jl,:)
+            zt2we(:,jl,1) = ptab(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = jpreci * jpj
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+      CASE ( 0 )
+         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+      CASE ( 1 )
+         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
+      END SELECT
+      !
+      SELECT CASE ( nbondi_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci-jpreci
+      !
+      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jpreci
+            ptab(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:) = zt2we(:,jl,2)
+            ptab(iihom+jl,:) = zt2ew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jpreci
+            ptab(jl      ,:) = zt2we(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj
+         DO jl = 1, jprecj
+            zt2sn(:,jl,1) = ptab(:,ijhom +jl)
+            zt2ns(:,jl,1) = ptab(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = jprecj * jpi
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
+      CASE ( 0 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
+      CASE ( 1 )
+         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+      CASE ( 0 )
+         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+      CASE ( 1 )
+         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
+      END SELECT
+      !
+      SELECT CASE ( nbondj_bdy(ib_bdy) )
+      CASE ( -1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      CASE ( 0 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
+      CASE ( 1 )
+         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj-jprecj
+      !
+      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
+      CASE ( -1 )
+         DO jl = 1, jprecj
+            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, jprecj
+            ptab(:,jl      ) = zt2sn(:,jl,2)
+            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, jprecj
+            ptab(:,jl) = zt2sn(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 4. north fold treatment
+      ! -----------------------
+      !
+      IF( npolj /= 0) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
+         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
+         END SELECT
+         !
+      ENDIF
+      !
+      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we  )
+      !
+   END SUBROUTINE mpp_lnk_bdy_2d
+
+   SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_init.opa  ***
+      !!
+      !! ** Purpose :: export and attach a MPI buffer for bsend
+      !!
+      !! ** Method  :: define buffer size in namelist, if 0 no buffer attachment
+      !!            but classical mpi_init
+      !!
+      !! History :: 01/11 :: IDRIS initial version for IBM only
+      !!            08/04 :: R. Benshila, generalisation
+      !!---------------------------------------------------------------------
+      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
+      INTEGER                      , INTENT(inout) ::   ksft
+      INTEGER                      , INTENT(  out) ::   code
+      INTEGER                                      ::   ierr, ji
+      LOGICAL                                      ::   mpi_was_called
+      !!---------------------------------------------------------------------
+      !
+      CALL mpi_initialized( mpi_was_called, code )      ! MPI initialization
+      IF ( code /= MPI_SUCCESS ) THEN
+         DO ji = 1, SIZE(ldtxt)
+            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+         END DO
+         WRITE(*, cform_err)
+         WRITE(*, *) ' lib_mpp: Error in routine mpi_initialized'
+         CALL mpi_abort( mpi_comm_world, code, ierr )
+      ENDIF
+      !
+      IF( .NOT. mpi_was_called ) THEN
+         CALL mpi_init( code )
+         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code )
+         IF ( code /= MPI_SUCCESS ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         ENDIF
+      ENDIF
+      !
+      IF( nn_buffer > 0 ) THEN
+         WRITE(ldtxt(ksft),*) 'mpi_bsend, buffer allocation of  : ', nn_buffer   ;   ksft = ksft + 1
+         ! Buffer allocation and attachment
+         ALLOCATE( tampon(nn_buffer), stat = ierr )
+         IF( ierr /= 0 ) THEN
+            DO ji = 1, SIZE(ldtxt)
+               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
+            END DO
+            WRITE(*, cform_err)
+            WRITE(*, *) ' lib_mpp: Error in ALLOCATE', ierr
+            CALL mpi_abort( mpi_comm_world, code, ierr )
+         END IF
+         CALL mpi_buffer_attach( tampon, nn_buffer, code )
+      ENDIF
+      !
+   END SUBROUTINE mpi_init_opa
+
+   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
+      !!---------------------------------------------------------------------
+      !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
+      !!
+      !!   Modification of original codes written by David H. Bailey
+      !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
+      !!---------------------------------------------------------------------
+      INTEGER, INTENT(in)                         :: ilen, itype
+      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
+      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
+      !
+      REAL(wp) :: zerr, zt1, zt2    ! local work variables
+      INTEGER :: ji, ztmp           ! local scalar
+
+      ztmp = itype   ! avoid compilation warning
+
+      DO ji=1,ilen
+      ! Compute ydda + yddb using Knuth's trick.
+         zt1  = real(ydda(ji)) + real(yddb(ji))
+         zerr = zt1 - real(ydda(ji))
+         zt2  = ((real(yddb(ji)) - zerr) + (real(ydda(ji)) - (zt1 - zerr))) &
+                + aimag(ydda(ji)) + aimag(yddb(ji))
+
+         ! The result is zt1 + zt2, after normalization.
+         yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
+      END DO
+
+   END SUBROUTINE DDPDD_MPI
+
+   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
+      !!---------------------------------------------------------------------
+      !!                   ***  routine mpp_lbc_north_icb  ***
+      !!
+      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
+      !!              in mpp configuration in case of jpn1 > 1 and for 2d
+      !!              array with outer extra halo
+      !!
+      !! ** Method  :   North fold condition and mpp with more than one proc
+      !!              in i-direction require a specific treatment. We gather
+      !!              the 4+2*jpr2dj northern lines of the global domain on 1
+      !!              processor and apply lbc north-fold on this sub array.
+      !!              Then we scatter the north fold array back to the processors.
+      !!              This version accounts for an extra halo with icebergs.
+      !!
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
+      !                                                     !   = T ,  U , V , F or W -points
+      REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
+      !!                                                    ! north fold, =  1. otherwise
+      INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
+      INTEGER ::   ji, jj, jr
+      INTEGER ::   ierr, itaille, ildi, ilei, iilb
+      INTEGER ::   ijpj, ij, iproc, ipr2dj
+      !
+      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
+      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
+
+      !!----------------------------------------------------------------------
+      !
+      ijpj=4
+      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
+         ipr2dj = pr2dj
+      ELSE
+         ipr2dj = 0
+      ENDIF
+      ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
+
+      !
+      ztab_e(:,:) = 0.e0
+
+      ij=0
+      ! put in znorthloc_e the last 4 jlines of pt2d
+      DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
+         ij = ij + 1
+         DO ji = 1, jpi
+            znorthloc_e(ji,ij)=pt2d(ji,jj)
+         END DO
+      END DO
+      !
+      itaille = jpi * ( ijpj + 2 * ipr2dj )
+      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
+         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
+      !
+      DO jr = 1, ndim_rank_north            ! recover the global north array
+         iproc = nrank_north(jr) + 1
+         ildi = nldit (iproc)
+         ilei = nleit (iproc)
+         iilb = nimppt(iproc)
+         DO jj = 1, ijpj+2*ipr2dj
+            DO ji = ildi, ilei
+               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
+            END DO
+         END DO
+      END DO
+
+
+      ! 2. North-Fold boundary conditions
+      ! ----------------------------------
+      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = ipr2dj )
+
+      ij = ipr2dj
+      !! Scatter back to pt2d
+      DO jj = nlcj - ijpj + 1 , nlcj +ipr2dj
+      ij  = ij +1
+         DO ji= 1, nlci
+            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
+         END DO
+      END DO
+      !
+      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
+      !
+   END SUBROUTINE mpp_lbc_north_icb
+
+   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
+      !!----------------------------------------------------------------------
+      !!                  ***  routine mpp_lnk_2d_icb  ***
+      !!
+      !! ** Purpose :   Message passing manadgement for 2d array (with extra halo and icebergs)
+      !!
+      !! ** Method  :   Use mppsend and mpprecv function for passing mask
+      !!      between processors following neighboring subdomains.
+      !!            domain parameters
+      !!                    nlci   : first dimension of the local subdomain
+      !!                    nlcj   : second dimension of the local subdomain
+      !!                    jpri   : number of rows for extra outer halo
+      !!                    jprj   : number of columns for extra outer halo
+      !!                    nbondi : mark for "east-west local boundary"
+      !!                    nbondj : mark for "north-south local boundary"
+      !!                    noea   : number for local neighboring processors
+      !!                    nowe   : number for local neighboring processors
+      !!                    noso   : number for local neighboring processors
+      !!                    nono   : number for local neighboring processors
+      !!
+      !!----------------------------------------------------------------------
+      INTEGER                                             , INTENT(in   ) ::   jpri
+      INTEGER                                             , INTENT(in   ) ::   jprj
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
+      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
+      !                                                                                 ! = T , U , V , F , W and I points
+      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
+      !!                                                                                ! north boundary, =  1. otherwise
+      INTEGER  ::   jl   ! dummy loop indices
+      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
+      INTEGER  ::   ipreci, iprecj             ! temporary integers
+      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
+      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
+      !!
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
+      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
+      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
+      !!----------------------------------------------------------------------
+
+      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
+      iprecj = jprecj + jprj
+
+
+      ! 1. standard boundary treatment
+      ! ------------------------------
+      ! Order matters Here !!!!
+      !
+      !                                      ! East-West boundaries
+      !                                           !* Cyclic east-west
+      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
+         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
+         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
+         !
+      ELSE                                        !* closed
+         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
+                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
+      ENDIF
+      !
+
+      ! north fold treatment
+      ! -----------------------
+      IF( npolj /= 0 ) THEN
+         !
+         SELECT CASE ( jpni )
+         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
+         CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+jprj)  , cd_type, psgn , pr2dj=jprj  )
+         END SELECT
+         !
+      ENDIF
+
+      ! 2. East and west directions exchange
+      ! ------------------------------------
+      ! we play with the neigbours AND the row number because of the periodicity
+      !
+      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
+      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
+         iihom = nlci-nreci-jpri
+         DO jl = 1, ipreci
+            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
+            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
+         END DO
+      END SELECT
+      !
+      !                           ! Migrations
+      imigr = ipreci * ( jpj + 2*jprj)
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
+         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
+         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      iihom = nlci - jpreci
+      !
+      SELECT CASE ( nbondi )
+      CASE ( -1 )
+         DO jl = 1, ipreci
+            pt2d(iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+            pt2d( iihom+jl,:) = r2dew(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, ipreci
+            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
+         END DO
+      END SELECT
+
+
+      ! 3. North and south directions
+      ! -----------------------------
+      ! always closed : we play only with the neigbours
+      !
+      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
+         ijhom = nlcj-nrecj-jprj
+         DO jl = 1, iprecj
+            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
+            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
+         END DO
+      ENDIF
+      !
+      !                           ! Migrations
+      imigr = iprecj * ( jpi + 2*jpri )
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      CASE ( 0 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
+         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
+      CASE ( 1 )
+         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
+         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
+         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
+      END SELECT
+      !
+      !                           ! Write Dirichlet lateral conditions
+      ijhom = nlcj - jprecj
+      !
+      SELECT CASE ( nbondj )
+      CASE ( -1 )
+         DO jl = 1, iprecj
+            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
+         END DO
+      CASE ( 0 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
+         END DO
+      CASE ( 1 )
+         DO jl = 1, iprecj
+            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
+         END DO
+      END SELECT
+
+   END SUBROUTINE mpp_lnk_2d_icb
+#else
+   !!----------------------------------------------------------------------
+   !!   Default case:            Dummy module        share memory computing
+   !!----------------------------------------------------------------------
+   USE in_out_manager
+
+   INTERFACE mpp_sum
+      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i, mppsum_realdd, mppsum_a_realdd
+   END INTERFACE
+   INTERFACE mpp_max
+      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
+   END INTERFACE
+   INTERFACE mpp_min
+      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
+   END INTERFACE
+   INTERFACE mpp_minloc
+      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
+   END INTERFACE
+   INTERFACE mpp_maxloc
+      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
+   END INTERFACE
+
+   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
+   LOGICAL, PUBLIC            ::   ln_nnogather          !: namelist control of northfold comms (needed here in case "key_mpp_mpi" is not used)
+   INTEGER :: ncomm_ice
+   INTEGER, PUBLIC            ::   mpi_comm_opa          ! opa local communicator
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   INTEGER FUNCTION lib_mpp_alloc(kumout)          ! Dummy function
+      INTEGER, INTENT(in) ::   kumout
+      lib_mpp_alloc = 0
+   END FUNCTION lib_mpp_alloc
+
+   FUNCTION mynode( ldtxt, ldname, kumnam_ref, knumnam_cfg,  kumond , kstop, localComm ) RESULT (function_value)
+      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
+      CHARACTER(len=*),DIMENSION(:) ::   ldtxt
+      CHARACTER(len=*) ::   ldname
+      INTEGER ::   kumnam_ref, knumnam_cfg , kumond , kstop
+      IF( PRESENT( localComm ) ) mpi_comm_opa = localComm
+      function_value = 0
+      IF( .FALSE. )   ldtxt(:) = 'never done'
+      CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
+   END FUNCTION mynode
+
+   SUBROUTINE mppsync                       ! Dummy routine
+   END SUBROUTINE mppsync
+
+   SUBROUTINE mpp_sum_as( parr, kdim, kcom )      ! Dummy routine
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mpp_sum_as
+
+   SUBROUTINE mpp_sum_a2s( parr, kdim, kcom )      ! Dummy routine
+      REAL   , DIMENSION(:,:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1), kcom
+   END SUBROUTINE mpp_sum_a2s
+
+   SUBROUTINE mpp_sum_ai( karr, kdim, kcom )      ! Dummy routine
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mpp_sum_ai
+
+   SUBROUTINE mpp_sum_s( psca, kcom )            ! Dummy routine
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mpp_sum_s
+
+   SUBROUTINE mpp_sum_i( kint, kcom )            ! Dummy routine
+      integer               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mpp_sum_i
+
+   SUBROUTINE mppsum_realdd( ytab, kcom )
+      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+      WRITE(*,*) 'mppsum_realdd: You should not have seen this print! error?', ytab
+   END SUBROUTINE mppsum_realdd
+
+   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
+      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
+      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
+      INTEGER , INTENT( in  ), OPTIONAL :: kcom
+      WRITE(*,*) 'mppsum_a_realdd: You should not have seen this print! error?', kdim, ytab(1), kcom
+   END SUBROUTINE mppsum_a_realdd
+
+   SUBROUTINE mppmax_a_real( parr, kdim, kcom )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mppmax_a_real
+
+   SUBROUTINE mppmax_real( psca, kcom )
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mppmax_real
+
+   SUBROUTINE mppmin_a_real( parr, kdim, kcom )
+      REAL   , DIMENSION(:) :: parr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
+   END SUBROUTINE mppmin_a_real
+
+   SUBROUTINE mppmin_real( psca, kcom )
+      REAL                  :: psca
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca, kcom
+   END SUBROUTINE mppmin_real
+
+   SUBROUTINE mppmax_a_int( karr, kdim ,kcom)
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mppmax_a_int
+
+   SUBROUTINE mppmax_int( kint, kcom)
+      INTEGER               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmax_int: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mppmax_int
+
+   SUBROUTINE mppmin_a_int( karr, kdim, kcom )
+      INTEGER, DIMENSION(:) :: karr
+      INTEGER               :: kdim
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
+   END SUBROUTINE mppmin_a_int
+
+   SUBROUTINE mppmin_int( kint, kcom )
+      INTEGER               :: kint
+      INTEGER, OPTIONAL     :: kcom
+      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint, kcom
+   END SUBROUTINE mppmin_int
+
+   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki, kj )
+      REAL                   :: pmin
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mpp_minloc2d: You should not have seen this print! error?', pmin, ki, kj, ptab(1,1), pmask(1,1)
+   END SUBROUTINE mpp_minloc2d
+
+   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj, kk )
+      REAL                     :: pmin
+      REAL , DIMENSION (:,:,:) :: ptab, pmask
+      INTEGER :: ki, kj, kk
+      WRITE(*,*) 'mpp_minloc3d: You should not have seen this print! error?', pmin, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_minloc3d
+
+   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
+      REAL                   :: pmax
+      REAL , DIMENSION (:,:) :: ptab, pmask
+      INTEGER :: ki, kj
+      WRITE(*,*) 'mpp_maxloc2d: You should not have seen this print! error?', pmax, ki, kj, ptab(1,1), pmask(1,1)
+   END SUBROUTINE mpp_maxloc2d
+
+   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
+      REAL                     :: pmax
+      REAL , DIMENSION (:,:,:) :: ptab, pmask
+      INTEGER :: ki, kj, kk
+      WRITE(*,*) 'mpp_maxloc3d: You should not have seen this print! error?', pmax, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
+   END SUBROUTINE mpp_maxloc3d
+
+   SUBROUTINE mppstop
+      STOP      ! non MPP case, just stop the run
+   END SUBROUTINE mppstop
+
+   SUBROUTINE mpp_ini_ice( kcom, knum )
+      INTEGER :: kcom, knum
+      WRITE(*,*) 'mpp_ini_ice: You should not have seen this print! error?', kcom, knum
+   END SUBROUTINE mpp_ini_ice
+
+   SUBROUTINE mpp_ini_znl( knum )
+      INTEGER :: knum
+      WRITE(*,*) 'mpp_ini_znl: You should not have seen this print! error?', knum
+   END SUBROUTINE mpp_ini_znl
+
+   SUBROUTINE mpp_comm_free( kcom )
+      INTEGER :: kcom
+      WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
+   END SUBROUTINE mpp_comm_free
+#endif
+
+   !!----------------------------------------------------------------------
+   !!   All cases:         ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines
+   !!----------------------------------------------------------------------
+
+   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5 ,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_opa  ***
+      !!
+      !! ** Purpose :   print in ocean.outpput file a error message and
+      !!                increment the error number (nstop) by one.
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      !!----------------------------------------------------------------------
+      !
+      nstop = nstop + 1
+      IF(lwp) THEN
+         WRITE(numout,cform_err)
+         IF( PRESENT(cd1 ) )   WRITE(numout,*) cd1
+         IF( PRESENT(cd2 ) )   WRITE(numout,*) cd2
+         IF( PRESENT(cd3 ) )   WRITE(numout,*) cd3
+         IF( PRESENT(cd4 ) )   WRITE(numout,*) cd4
+         IF( PRESENT(cd5 ) )   WRITE(numout,*) cd5
+         IF( PRESENT(cd6 ) )   WRITE(numout,*) cd6
+         IF( PRESENT(cd7 ) )   WRITE(numout,*) cd7
+         IF( PRESENT(cd8 ) )   WRITE(numout,*) cd8
+         IF( PRESENT(cd9 ) )   WRITE(numout,*) cd9
+         IF( PRESENT(cd10) )   WRITE(numout,*) cd10
+      ENDIF
+                               CALL FLUSH(numout    )
+      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
+      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
+      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
+      !
+      IF( cd1 == 'STOP' ) THEN
+         IF(lwp) WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
+         CALL mppstop()
+      ENDIF
+      !
+   END SUBROUTINE ctl_stop
+
+
+   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
+      &                 cd6, cd7, cd8, cd9, cd10 )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE  stop_warn  ***
+      !!
+      !! ** Purpose :   print in ocean.outpput file a error message and
+      !!                increment the warning number (nwarn) by one.
+      !!----------------------------------------------------------------------
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
+      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
+      !!----------------------------------------------------------------------
+      !
+      nwarn = nwarn + 1
+      IF(lwp) THEN
+         WRITE(numout,cform_war)
+         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
+         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
+         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
+         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
+         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
+         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
+         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
+         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
+         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
+         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
+      ENDIF
+      CALL FLUSH(numout)
+      !
+   END SUBROUTINE ctl_warn
+
+
+   SUBROUTINE ctl_opn( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctl_opn  ***
+      !!
+      !! ** Purpose :   Open file and check if required file is available.
+      !!
+      !! ** Method  :   Fortan open
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
+      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
+      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
+      INTEGER          , INTENT(in   ) ::   klengh    ! record length
+      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
+      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
+      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
+      !!
+      CHARACTER(len=80) ::   clfile
+      INTEGER           ::   iost
+      !!----------------------------------------------------------------------
+
+      ! adapt filename
+      ! ----------------
+      clfile = TRIM(cdfile)
+      IF( PRESENT( karea ) ) THEN
+         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
+      ENDIF
+#if defined key_agrif
+      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
+      knum=Agrif_Get_Unit()
+#else
+      knum=get_unit()
+#endif
+
+      iost=0
+      IF( cdacce(1:6) == 'DIRECT' )  THEN
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
+      ELSE
+         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
+      ENDIF
+      IF( iost == 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*) '     file   : ', clfile,' open ok'
+            WRITE(kout,*) '     unit   = ', knum
+            WRITE(kout,*) '     status = ', cdstat
+            WRITE(kout,*) '     form   = ', cdform
+            WRITE(kout,*) '     access = ', cdacce
+            WRITE(kout,*)
+         ENDIF
+      ENDIF
+100   CONTINUE
+      IF( iost /= 0 ) THEN
+         IF(ldwp) THEN
+            WRITE(kout,*)
+            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
+            WRITE(kout,*) ' =======   ===  '
+            WRITE(kout,*) '           unit   = ', knum
+            WRITE(kout,*) '           status = ', cdstat
+            WRITE(kout,*) '           form   = ', cdform
+            WRITE(kout,*) '           access = ', cdacce
+            WRITE(kout,*) '           iostat = ', iost
+            WRITE(kout,*) '           we stop. verify the file '
+            WRITE(kout,*)
+         ENDIF
+         STOP 'ctl_opn bad opening'
+      ENDIF
+
+   END SUBROUTINE ctl_opn
+
+   SUBROUTINE ctl_nam ( kios, cdnam, ldwp )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE ctl_nam  ***
+      !!
+      !! ** Purpose :   Informations when error while reading a namelist
+      !!
+      !! ** Method  :   Fortan open
+      !!----------------------------------------------------------------------
+      INTEGER          , INTENT(inout) ::   kios      ! IO status after reading the namelist
+      CHARACTER(len=*) , INTENT(in   ) ::   cdnam     ! group name of namelist for which error occurs
+      CHARACTER(len=5)                 ::   clios     ! string to convert iostat in character for print
+      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
+      !!----------------------------------------------------------------------
+
+      ! 
+      ! ----------------
+      WRITE (clios, '(I5.0)') kios
+      IF( kios < 0 ) THEN         
+         CALL ctl_warn( 'W A R N I N G:  end of record or file while reading namelist ' &
+ &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
+      ENDIF
+
+      IF( kios > 0 ) THEN
+         CALL ctl_stop( 'E R R O R :   misspelled variable in namelist ' &
+ &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
+      ENDIF
+      kios = 0
+      RETURN
+      
+   END SUBROUTINE ctl_nam
+
+   INTEGER FUNCTION get_unit()
+      !!----------------------------------------------------------------------
+      !!                  ***  FUNCTION  get_unit  ***
+      !!
+      !! ** Purpose :   return the index of an unused logical unit
+      !!----------------------------------------------------------------------
+      LOGICAL :: llopn
+      !!----------------------------------------------------------------------
+      !
+      get_unit = 15   ! choose a unit that is big enough then it is not already used in NEMO
+      llopn = .TRUE.
+      DO WHILE( (get_unit < 998) .AND. llopn )
+         get_unit = get_unit + 1
+         INQUIRE( unit = get_unit, opened = llopn )
+      END DO
+      IF( (get_unit == 999) .AND. llopn ) THEN
+         CALL ctl_stop( 'get_unit: All logical units until 999 are used...' )
+         get_unit = -1
+      ENDIF
+      !
+   END FUNCTION get_unit
+
+   !!----------------------------------------------------------------------
+END MODULE lib_mpp
Index: /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/traadv_tvd.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/traadv_tvd.F90	(revision 5879)
+++ /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/STANDARD/traadv_tvd.F90	(revision 5879)
@@ -0,0 +1,682 @@
+MODULE traadv_tvd
+   !!==============================================================================
+   !!                       ***  MODULE  traadv_tvd  ***
+   !! Ocean  tracers:  horizontal & vertical advective trend
+   !!==============================================================================
+   !! History :  OPA  !  1995-12  (L. Mortier)  Original code
+   !!                 !  2000-01  (H. Loukos)  adapted to ORCA 
+   !!                 !  2000-10  (MA Foujols E.Kestenare)  include file not routine
+   !!                 !  2000-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
+   !!                 !  2001-07  (E. Durand G. Madec)  adaptation to ORCA config
+   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
+   !!    NEMO    1.0  !  2004-01  (A. de Miranda, G. Madec, J.M. Molines ): advective bbl
+   !!            2.0  !  2008-04  (S. Cravatte) add the i-, j- & k- trends computation
+   !!             -   !  2009-11  (V. Garnier) Surface pressure gradient organization
+   !!            3.3  !  2010-05  (C. Ethe, G. Madec)  merge TRC-TRA + switch from velocity to transport
+   !!----------------------------------------------------------------------
+
+   !!----------------------------------------------------------------------
+   !!   tra_adv_tvd   : update the tracer trend with the 3D advection trends using a TVD scheme
+   !!   nonosc        : compute monotonic tracer fluxes by a non-oscillatory algorithm 
+   !!----------------------------------------------------------------------
+   USE oce            ! ocean dynamics and active tracers
+   USE dom_oce        ! ocean space and time domain
+   USE trc_oce        ! share passive tracers/Ocean variables
+   USE trd_oce        ! trends: ocean variables
+   USE trdtra         ! tracers trends
+   USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
+   USE diaptr         ! poleward transport diagnostics
+   !
+   USE lib_mpp        ! MPP library
+   USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
+   USE in_out_manager ! I/O manager
+   USE wrk_nemo       ! Memory Allocation
+   USE timing         ! Timing
+   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
+
+   IMPLICIT NONE
+   PRIVATE
+
+   PUBLIC   tra_adv_tvd        ! routine called by traadv.F90
+   PUBLIC   tra_adv_tvd_zts    ! routine called by traadv.F90
+
+   LOGICAL ::   l_trd   ! flag to compute trends
+
+   !! * Substitutions
+#  include "domzgr_substitute.h90"
+#  include "vectopt_loop_substitute.h90"
+   !!----------------------------------------------------------------------
+   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
+   !! $Id: traadv_tvd.F90 6692 2016-06-13 14:39:24Z flavoni $
+   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
+   !!----------------------------------------------------------------------
+CONTAINS
+
+   SUBROUTINE tra_adv_tvd ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
+      &                                       ptb, ptn, pta, kjpt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_tvd  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction)
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - update (pta) with the now advective tracer trends
+      !!             - save the trends 
+      !!----------------------------------------------------------------------
+      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
+      !
+      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
+      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
+      !
+      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices
+      INTEGER  ::   ik  
+      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz )
+      !
+      IF( kt == kit000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_tvd : TVD advection scheme on ', cdtype
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+         !
+         l_trd = .FALSE.
+         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
+      ENDIF
+      !
+      IF( l_trd )  THEN
+         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+         ztrdx(:,:,:) = 0.e0   ;    ztrdy(:,:,:) = 0.e0   ;   ztrdz(:,:,:) = 0.e0
+      ENDIF
+      !
+      zwi(:,:,:) = 0.e0 ; 
+      !
+      !                                                          ! ===========
+      DO jn = 1, kjpt                                            ! tracer loop
+         !                                                       ! ===========
+         ! 1. Bottom and k=1 value : flux set to zero
+         ! ----------------------------------
+         zwx(:,:,jpk) = 0.e0    ;    zwz(:,:,jpk) = 0.e0
+         zwy(:,:,jpk) = 0.e0    ;    zwi(:,:,jpk) = 0.e0
+          
+         zwz(:,:,1  ) = 0._wp
+         ! 2. upstream advection with initial mass fluxes & intermediate update
+         ! --------------------------------------------------------------------
+         ! upstream tracer flux in the i and j direction
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! upstream scheme
+                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
+                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
+                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
+                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
+                  zwx(ji,jj,jk) = 0.5 * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5 * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
+               END DO
+            END DO
+         END DO
+
+         ! upstream tracer flux in the k direction
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
+                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
+                  zwz(ji,jj,jk) = 0.5 * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) ) * wmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! Surface value
+         IF( lk_vvl ) THEN   
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = 0.e0          ! volume variable
+            END IF
+         ELSE                
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface 
+                  END DO
+               END DO   
+            ELSE
+               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)   ! linear free surface
+            END IF
+         ENDIF
+
+         ! total advective trend
+         DO jk = 1, jpkm1
+            z2dtt = p2dt(jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! total intermediate advective trends
+                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
+                  ! update and guess with monotonic sheme
+                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
+         CALL lbc_lnk( zwi, 'T', 1. )  
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ! store intermediate advective trends
+            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
+         ENDIF
+
+         ! 3. antidiffusive flux : high order minus low order
+         ! --------------------------------------------------
+         ! antidiffusive flux on i and j
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx(ji,jj,jk) = 0.5 * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) ) - zwx(ji,jj,jk)
+                  zwy(ji,jj,jk) = 0.5 * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) ) - zwy(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+      
+         ! antidiffusive flux on k
+         ! Interior value
+         DO jk = 2, jpkm1                    
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zwz(ji,jj,jk) = 0.5 * pwn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj,jk-1,jn) ) - zwz(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         ! surface value
+         IF ( ln_isfcav ) THEN
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zwz(ji,jj,mikt(ji,jj)) = 0.e0
+               END DO
+            END DO
+         ELSE
+            zwz(:,:,1) = 0.e0
+         END IF
+         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
+         CALL lbc_lnk( zwz, 'W',  1. )
+
+         ! 4. monotonicity algorithm
+         ! -------------------------
+         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
+
+
+         ! 5. final trend with corrected fluxes
+         ! ------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.  
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ! total advective trends
+                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                  ! add them to the general tracer trends
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
+            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
+            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
+            
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
+         ENDIF
+         !
+      END DO
+      !
+                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz )
+      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd')
+      !
+   END SUBROUTINE tra_adv_tvd
+
+   SUBROUTINE tra_adv_tvd_zts ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
+      &                                       ptb, ptn, pta, kjpt )
+      !!----------------------------------------------------------------------
+      !!                  ***  ROUTINE tra_adv_tvd_zts  ***
+      !! 
+      !! **  Purpose :   Compute the now trend due to total advection of 
+      !!       tracers and add it to the general trend of tracer equations
+      !!
+      !! **  Method  :   TVD ZTS scheme, i.e. 2nd order centered scheme with
+      !!       corrected flux (monotonic correction). This version use sub-
+      !!       timestepping for the vertical advection which increases stability
+      !!       when vertical metrics are small.
+      !!       note: - this advection scheme needs a leap-frog time scheme
+      !!
+      !! ** Action : - update (pta) with the now advective tracer trends
+      !!             - save the trends 
+      !!----------------------------------------------------------------------
+      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
+      !
+      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
+      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
+      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
+      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
+      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
+      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
+      !
+      REAL(wp), DIMENSION( jpk )                           ::   zts             ! length of sub-timestep for vertical advection
+      REAL(wp), DIMENSION( jpk )                           ::   zr_p2dt         ! reciprocal of tracer timestep
+      INTEGER  ::   ji, jj, jk, jl, jn       ! dummy loop indices  
+      INTEGER  ::   jnzts = 5       ! number of sub-timesteps for vertical advection
+      INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
+      INTEGER  ::   jtaken          ! toggle for collecting appropriate fluxes from sub timesteps
+      REAL(wp) ::   z_rzts          ! Fractional length of Euler forward sub-timestep for vertical advection
+      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
+      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
+      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:  ) :: zwx_sav , zwy_sav
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz, zhdiv, zwz_sav, zwzts
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
+      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrs
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd_zts')
+      !
+      CALL wrk_alloc( jpi, jpj, zwx_sav, zwy_sav )
+      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz , zhdiv, zwz_sav, zwzts )
+      CALL wrk_alloc( jpi, jpj, jpk, kjpt+1, ztrs )
+      !
+      IF( kt == kit000 )  THEN
+         IF(lwp) WRITE(numout,*)
+         IF(lwp) WRITE(numout,*) 'tra_adv_tvd_zts : TVD ZTS advection scheme on ', cdtype
+         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
+      ENDIF
+      !
+      l_trd = .FALSE.
+      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
+      !
+      IF( l_trd )  THEN
+         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+         ztrdx(:,:,:) = 0._wp  ;    ztrdy(:,:,:) = 0._wp  ;   ztrdz(:,:,:) = 0._wp
+      ENDIF
+      !
+      zwi(:,:,:) = 0._wp
+      z_rzts = 1._wp / REAL( jnzts, wp )
+      zr_p2dt(:) = 1._wp / p2dt(:)
+      !
+      !                                                          ! ===========
+      DO jn = 1, kjpt                                            ! tracer loop
+         !                                                       ! ===========
+         ! 1. Bottom value : flux set to zero
+         ! ----------------------------------
+         zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
+         zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
+
+         ! 2. upstream advection with initial mass fluxes & intermediate update
+         ! --------------------------------------------------------------------
+         ! upstream tracer flux in the i and j direction
+         DO jk = 1, jpkm1
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  ! upstream scheme
+                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
+                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
+                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
+                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
+                  zwx(ji,jj,jk) = 0.5_wp * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5_wp * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
+               END DO
+            END DO
+         END DO
+
+         ! upstream tracer flux in the k direction
+         ! Interior value
+         DO jk = 2, jpkm1
+            DO jj = 1, jpj
+               DO ji = 1, jpi
+                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
+                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
+                  zwz(ji,jj,jk) = 0.5_wp * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) )
+               END DO
+            END DO
+         END DO
+         ! Surface value
+         IF( lk_vvl ) THEN
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable +    isf
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = 0.e0                              ! volume variable + no isf
+            END IF
+         ELSE
+            IF ( ln_isfcav ) THEN
+               DO jj = 1, jpj
+                  DO ji = 1, jpi
+                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface +    isf
+                  END DO
+               END DO
+            ELSE
+               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)                                               ! linear free surface + no isf
+            END IF
+         ENDIF
+
+         ! total advective trend
+         DO jk = 1, jpkm1
+            z2dtt = p2dt(jk)
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.
+                  ! total intermediate advective trends
+                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
+                  ! update and guess with monotonic sheme
+                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
+                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
+         CALL lbc_lnk( zwi, 'T', 1. )  
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ! store intermediate advective trends
+            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
+         ENDIF
+
+         ! 3. antidiffusive flux : high order minus low order
+         ! --------------------------------------------------
+         ! antidiffusive flux on i and j
+         !
+         DO jk = 1, jpkm1
+            !
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx_sav(ji,jj) = zwx(ji,jj,jk)
+                  zwy_sav(ji,jj) = zwy(ji,jj,jk)
+
+                  zwx(ji,jj,jk) = 0.5_wp * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) )
+                  zwy(ji,jj,jk) = 0.5_wp * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) )
+               END DO
+            END DO
+
+            DO jj = 2, jpjm1         ! partial horizontal divergence
+               DO ji = fs_2, fs_jpim1
+                  zhdiv(ji,jj,jk) = (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
+                     &               + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
+               END DO
+            END DO
+
+            DO jj = 1, jpjm1
+               DO ji = 1, fs_jpim1   ! vector opt.
+                  zwx(ji,jj,jk) = zwx(ji,jj,jk)  - zwx_sav(ji,jj)
+                  zwy(ji,jj,jk) = zwy(ji,jj,jk)  - zwy_sav(ji,jj)
+               END DO
+            END DO
+         END DO
+      
+         ! antidiffusive flux on k
+         zwz(:,:,1) = 0._wp        ! Surface value
+         zwz_sav(:,:,:) = zwz(:,:,:)
+         !
+         ztrs(:,:,:,1) = ptb(:,:,:,jn)
+         zwzts(:,:,:) = 0._wp
+
+         DO jl = 1, jnzts                   ! Start of sub timestepping loop
+
+            IF( jl == 1 ) THEN              ! Euler forward to kick things off
+              jtb = 1   ;   jtn = 1   ;   jta = 2
+              zts(:) = p2dt(:) * z_rzts
+              jtaken = MOD( jnzts + 1 , 2)  ! Toggle to collect every second flux
+                                            ! starting at jl =1 if jnzts is odd; 
+                                            ! starting at jl =2 otherwise
+            ELSEIF( jl == 2 ) THEN          ! First leapfrog step
+              jtb = 1   ;   jtn = 2   ;   jta = 3
+              zts(:) = 2._wp * p2dt(:) * z_rzts
+            ELSE                            ! Shuffle pointers for subsequent leapfrog steps
+              jtb = MOD(jtb,3) + 1
+              jtn = MOD(jtn,3) + 1
+              jta = MOD(jta,3) + 1
+            ENDIF
+            DO jk = 2, jpkm1          ! Interior value
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zwz(ji,jj,jk) = 0.5_wp * pwn(ji,jj,jk) * ( ztrs(ji,jj,jk,jtn) + ztrs(ji,jj,jk-1,jtn) )
+                     IF( jtaken == 0 ) zwzts(ji,jj,jk) = zwzts(ji,jj,jk) + zwz(ji,jj,jk)*zts(jk)           ! Accumulate time-weighted vertcal flux
+                  END DO
+               END DO
+            END DO
+
+            jtaken = MOD( jtaken + 1 , 2 )
+
+            DO jk = 2, jpkm1          ! Interior value
+               DO jj = 2, jpjm1
+                  DO ji = fs_2, fs_jpim1
+                     zbtr = 1._wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                     ! total advective trends
+                     ztra = - zbtr * (  zhdiv(ji,jj,jk) + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                     ztrs(ji,jj,jk,jta) = ztrs(ji,jj,jk,jtb) + zts(jk) * ztra
+                  END DO
+               END DO
+            END DO
+
+         END DO
+
+         DO jk = 2, jpkm1          ! Anti-diffusive vertical flux using average flux from the sub-timestepping
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1
+                  zwz(ji,jj,jk) = zwzts(ji,jj,jk) * zr_p2dt(jk) - zwz_sav(ji,jj,jk)
+               END DO
+            END DO
+         END DO
+         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
+         CALL lbc_lnk( zwz, 'W',  1. )
+
+         ! 4. monotonicity algorithm
+         ! -------------------------
+         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
+
+
+         ! 5. final trend with corrected fluxes
+         ! ------------------------------------
+         DO jk = 1, jpkm1
+            DO jj = 2, jpjm1
+               DO ji = fs_2, fs_jpim1   ! vector opt.  
+                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
+                  ! total advective trends
+                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
+                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
+                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
+                  ! add them to the general tracer trends
+                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
+               END DO
+            END DO
+         END DO
+
+         !                                 ! trend diagnostics (contribution of upstream fluxes)
+         IF( l_trd )  THEN 
+            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
+            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
+            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
+            
+            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
+            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
+            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
+         END IF
+         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
+         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
+           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
+           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
+         ENDIF
+         !
+      END DO
+      !
+                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz, zhdiv, zwz_sav, zwzts )
+                   CALL wrk_dealloc( jpi, jpj, jpk, kjpt+1, ztrs )
+                   CALL wrk_dealloc( jpi, jpj, zwx_sav, zwy_sav )
+      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd_zts')
+      !
+   END SUBROUTINE tra_adv_tvd_zts
+
+
+   SUBROUTINE nonosc( pbef, paa, pbb, pcc, paft, p2dt )
+      !!---------------------------------------------------------------------
+      !!                    ***  ROUTINE nonosc  ***
+      !!     
+      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
+      !!       scheme and the before field by a nonoscillatory algorithm 
+      !!
+      !! **  Method  :   ... ???
+      !!       warning : pbef and paft must be masked, but the boundaries
+      !!       conditions on the fluxes are not necessary zalezak (1979)
+      !!       drange (1995) multi-dimensional forward-in-time and upstream-
+      !!       in-space based differencing for fluid
+      !!----------------------------------------------------------------------
+      REAL(wp), DIMENSION(jpk)         , INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pbef, paft      ! before & after field
+      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(inout) ::   paa, pbb, pcc   ! monotonic fluxes in the 3 directions
+      !
+      INTEGER  ::   ji, jj, jk   ! dummy loop indices
+      INTEGER  ::   ikm1         ! local integer
+      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
+      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
+      REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo, zbup, zbdo
+      !!----------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )  CALL timing_start('nonosc')
+      !
+      CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
+      !
+      zbig  = 1.e+40_wp
+      zrtrn = 1.e-15_wp
+      zbetup(:,:,:) = 0._wp   ;   zbetdo(:,:,:) = 0._wp
+
+      ! Search local extrema
+      ! --------------------
+      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
+      zbup = MAX( pbef * tmask - zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask - zbig * ( 1._wp - tmask )  )
+      zbdo = MIN( pbef * tmask + zbig * ( 1._wp - tmask ),   &
+         &        paft * tmask + zbig * ( 1._wp - tmask )  )
+
+      DO jk = 1, jpkm1
+         ikm1 = MAX(jk-1,1)
+         z2dtt = p2dt(jk)
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+
+               ! search maximum in neighbourhood
+               zup = MAX(  zbup(ji  ,jj  ,jk  ),   &
+                  &        zbup(ji-1,jj  ,jk  ), zbup(ji+1,jj  ,jk  ),   &
+                  &        zbup(ji  ,jj-1,jk  ), zbup(ji  ,jj+1,jk  ),   &
+                  &        zbup(ji  ,jj  ,ikm1), zbup(ji  ,jj  ,jk+1)  )
+
+               ! search minimum in neighbourhood
+               zdo = MIN(  zbdo(ji  ,jj  ,jk  ),   &
+                  &        zbdo(ji-1,jj  ,jk  ), zbdo(ji+1,jj  ,jk  ),   &
+                  &        zbdo(ji  ,jj-1,jk  ), zbdo(ji  ,jj+1,jk  ),   &
+                  &        zbdo(ji  ,jj  ,ikm1), zbdo(ji  ,jj  ,jk+1)  )
+
+               ! positive part of the flux
+               zpos = MAX( 0., paa(ji-1,jj  ,jk  ) ) - MIN( 0., paa(ji  ,jj  ,jk  ) )   &
+                  & + MAX( 0., pbb(ji  ,jj-1,jk  ) ) - MIN( 0., pbb(ji  ,jj  ,jk  ) )   &
+                  & + MAX( 0., pcc(ji  ,jj  ,jk+1) ) - MIN( 0., pcc(ji  ,jj  ,jk  ) )
+
+               ! negative part of the flux
+               zneg = MAX( 0., paa(ji  ,jj  ,jk  ) ) - MIN( 0., paa(ji-1,jj  ,jk  ) )   &
+                  & + MAX( 0., pbb(ji  ,jj  ,jk  ) ) - MIN( 0., pbb(ji  ,jj-1,jk  ) )   &
+                  & + MAX( 0., pcc(ji  ,jj  ,jk  ) ) - MIN( 0., pcc(ji  ,jj  ,jk+1) )
+
+               ! up & down beta terms
+               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
+               zbetup(ji,jj,jk) = ( zup            - paft(ji,jj,jk) ) / ( zpos + zrtrn ) * zbt
+               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zdo            ) / ( zneg + zrtrn ) * zbt
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( zbetup, 'T', 1. )   ;   CALL lbc_lnk( zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
+
+      ! 3. monotonic flux in the i & j direction (paa & pbb)
+      ! ----------------------------------------
+      DO jk = 1, jpkm1
+         DO jj = 2, jpjm1
+            DO ji = fs_2, fs_jpim1   ! vector opt.
+               zau = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
+               zbu = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
+               zcu =       ( 0.5  + SIGN( 0.5 , paa(ji,jj,jk) ) )
+               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zcu * zau + ( 1._wp - zcu) * zbu )
+
+               zav = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
+               zbv = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
+               zcv =       ( 0.5  + SIGN( 0.5 , pbb(ji,jj,jk) ) )
+               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zcv * zav + ( 1._wp - zcv) * zbv )
+
+      ! monotonic flux in the k direction, i.e. pcc
+      ! -------------------------------------------
+               za = MIN( 1., zbetdo(ji,jj,jk+1), zbetup(ji,jj,jk) )
+               zb = MIN( 1., zbetup(ji,jj,jk+1), zbetdo(ji,jj,jk) )
+               zc =       ( 0.5  + SIGN( 0.5 , pcc(ji,jj,jk+1) ) )
+               pcc(ji,jj,jk+1) = pcc(ji,jj,jk+1) * ( zc * za + ( 1._wp - zc) * zb )
+            END DO
+         END DO
+      END DO
+      CALL lbc_lnk( paa, 'U', -1. )   ;   CALL lbc_lnk( pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
+      !
+      CALL wrk_dealloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
+      !
+      IF( nn_timing == 1 )  CALL timing_stop('nonosc')
+      !
+   END SUBROUTINE nonosc
+
+   !!======================================================================
+END MODULE traadv_tvd
Index: NFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/closea.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/closea.F90	(revision 5878)
+++ 	(revision )
@@ -1,531 +1,0 @@
-MODULE closea
-   !!======================================================================
-   !!                       ***  MODULE  closea  ***
-   !! Closed Seas  : specific treatments associated with closed seas
-   !!======================================================================
-   !! History :   8.2  !  00-05  (O. Marti)  Original code
-   !!             8.5  !  02-06  (E. Durand, G. Madec)  F90
-   !!             9.0  !  06-07  (G. Madec)  add clo_rnf, clo_ups, clo_bat
-   !!        NEMO 3.4  !  03-12  (P.G. Fogli) sbc_clo bug fix & mpp reproducibility
-   !!
-   !! 2016 : new closed seas for use in IPSLCM6 coupled model (O. Marti)
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   dom_clo    : modification of the ocean domain for closed seas cases
-   !!   sbc_clo    : Special handling of closed seas
-   !!   clo_rnf    : set close sea outflows as river mouths (see sbcrnf)
-   !!   clo_ups    : set mixed centered/upstream scheme in closed sea (see traadv_cen2)
-   !!   clo_bat    : set to zero a field over closed sea (see domzrg)
-   !!----------------------------------------------------------------------
-   USE oce             ! dynamics and tracers
-   USE dom_oce         ! ocean space and time domain
-   USE phycst          ! physical constants
-   USE in_out_manager  ! I/O manager
-   !USE iom             ! I/O manager library
-   USE sbc_oce         ! ocean surface boundary conditions
-   USE lib_fortran,    ONLY: glob_sum, DDPDD
-   USE lbclnk          ! lateral boundary condition - MPP exchanges
-   USE lib_mpp         ! MPP library
-   USE timing
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC dom_clo      ! routine called by domain module
-   PUBLIC sbc_clo      ! routine called by step module
-   PUBLIC clo_rnf      ! routine called by sbcrnf module
-   PUBLIC clo_ups      ! routine called in traadv_cen2(_jki) module
-   PUBLIC clo_bat      ! routine called in domzgr module
-
-   INTEGER, PUBLIC, PARAMETER          ::   jpncs   = 7      !: number of closed sea
-   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncstt            !: Type of closed sea
-   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi1, ncsj1     !: south-west closed sea limits (i,j)
-   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsi2, ncsj2     !: north-east closed sea limits (i,j)
-   INTEGER, PUBLIC, DIMENSION(jpncs)   ::   ncsnr            !: number of point where run-off pours
-   INTEGER, PUBLIC, DIMENSION(jpncs,4) ::   ncsir, ncsjr     !: Location of runoff
-
-   REAL(wp), DIMENSION (:,:), ALLOCATABLE :: clo_mask        !: Defines area where excess run-off is distributed
-
-   REAL(wp), DIMENSION (jpncs+1)       ::   surf             !: Closed sea surface
-
-   INTEGER :: dia_closea_alloc
-
-   !! * Substitutions
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: closea.F90 4162 2013-11-07 10:19:49Z cetlod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE dom_clo
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE dom_clo  ***
-      !!        
-      !! ** Purpose :   Closed sea domain initialization
-      !!
-      !! ** Method  :   if a closed sea is located only in a model grid point
-      !!                just the thermodynamic processes are applied.
-      !!
-      !! ** Action  :   ncsi1(), ncsj1() : south-west closed sea limits (i,j)
-      !!                ncsi2(), ncsj2() : north-east Closed sea limits (i,j)
-      !!                ncsir(), ncsjr() : Location of runoff
-      !!                ncsnr            : number of point where run-off pours
-      !!                ncstt            : Type of closed sea
-      !!                                   =0 spread over the world ocean
-      !!                                   =2 put at location runoff
-      !!----------------------------------------------------------------------
-      INTEGER ::   jc               ! dummy loop indices
-      REAL(wp)::   ztmp
-      INTEGER ::   isrow
-      !!----------------------------------------------------------------------
-      
-      IF(lwp) WRITE(numout,*)
-      IF(lwp) WRITE(numout,*)'dom_clo : closed seas '
-      IF(lwp) WRITE(numout,*)'~~~~~~~'
-
-      ! Initial values
-      ncsnr(:) = 1  ;  ncsi1(:) = 1  ;  ncsi2(:) = 1  ;  ncsir(:,:) = 1
-      ncstt(:) = 0  ;  ncsj1(:) = 1  ;  ncsj2(:) = 1  ;  ncsjr(:,:) = 1
-
-      ! set the closed seas (in data domain indices)
-      ! -------------------
-
-      IF( cp_cfg == "orca" ) THEN
-         !
-         SELECT CASE ( jp_cfg )
-         !                                           ! =======================
-         CASE ( 1 )                                  ! ORCA_R1 configuration
-            !
-            !! This dirty section will be suppressed by simplification process: all this will come back in input files.
-            !! Currently these hard-wired indices relate to NEMO v3.6 and later. In this version, the grid has been extended southwards
-            !! for use with the under ice-shelf options (isf). The grid resolution is 362x332.
-            !! The pre v3.6 (362x292) domain can still be used optionally if the isf code is not activated. An adjustment (isrow)
-            !! is made to the hard-wired indices if the reduced domain is used.
-            
-            !! =======================
-            IF         ( jpjglo == 332 ) THEN  !  eORCA1 R1 - Using full isfÂ­extended domain.
-               isrow =  0
-            ELSEIF     ( jpjglo == 292 ) THEN  !  ORCA1 R1 Â­ Using pre-v3.6 files or adjusted start row from isf-extended grid
-               isrow = 40                      !    - Adjust jÂ­indices to account for less southerly starting latitude
-            ENDIF
-            
-            ncsnr(1)   = 1    ; ncstt(1)   = 0              ! Caspian Sea
-            ncsi1(1)   = 333  ; ncsj1(1)   = 243 - isrow      ! spread over the globe
-            ncsi2(1)   = 342  ; ncsj2(1)   = 274 - isrow
-            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
-            !
-            ncsnr(2)   = 4    ; ncstt(2)   = 2              ! Lake Superior
-            ncsi1(2)   = 198  ; ncsj1(2)   = 258 - isrow      ! put at St Laurent mouth
-            ncsi2(2)   = 204  ; ncsj2(2)   = 262 - isrow
-            ncsir(2,1) = 225  ; ncsjr(2,1) = 220 - isrow
-            ncsir(2,2) = 225  ; ncsjr(2,2) = 221 - isrow
-            ncsir(2,3) = 226  ; ncsjr(2,3) = 220 - isrow
-            ncsir(2,4) = 226  ; ncsjr(2,4) = 221 - isrow
-            !
-            ncsnr(3)   = 4    ; ncstt(3)   = 2              ! Lake Michigan
-            ncsi1(3)   = 201  ; ncsj1(3)   = 250 - isrow      ! put at St Laurent mouth
-            ncsi2(3)   = 203  ; ncsj2(3)   = 256 - isrow
-            ncsir(3,1) = 225  ; ncsjr(3,1) = 220 - isrow
-            ncsir(3,2) = 225  ; ncsjr(3,2) = 221 - isrow
-            ncsir(3,3) = 226  ; ncsjr(3,3) = 220 - isrow
-            ncsir(3,4) = 226  ; ncsjr(3,4) = 221 - isrow
-            !
-            ncsnr(4)   = 4    ; ncstt(4)   = 2             ! Lake Huron
-            ncsi1(4)   = 204  ; ncsj1(4)   = 252 - isrow      ! put at St Laurent mouth
-            ncsi2(4)   = 209  ; ncsj2(4)   = 256 - isrow
-            ncsir(4,1) = 225  ; ncsjr(4,1) = 220 - isrow
-            ncsir(4,2) = 225  ; ncsjr(4,2) = 221 - isrow
-            ncsir(4,3) = 226  ; ncsjr(4,3) = 220 - isrow
-            ncsir(4,4) = 226  ; ncsjr(4,4) = 221 - isrow
-            !
-            ncsnr(5)   = 4    ; ncstt(5)   = 2              ! Lake Erie
-            ncsi1(5)   = 206  ; ncsj1(5)   = 249 - isrow      ! put at St Laurent mouth
-            ncsi2(5)   = 209  ; ncsj2(5)   = 251 - isrow
-            ncsir(5,1) = 225  ; ncsjr(5,1) = 220 - isrow
-            ncsir(5,2) = 225  ; ncsjr(5,2) = 221 - isrow
-            ncsir(5,3) = 226  ; ncsjr(5,3) = 220 - isrow
-            ncsir(5,4) = 226  ; ncsjr(5,4) = 221 - isrow
-            !
-            ncsnr(6)   = 4    ; ncstt(6)   = 2              ! Lake Ontario
-            ncsi1(6)   = 210  ; ncsj1(6)   = 252 - isrow      ! put at St Laurent mouth
-            ncsi2(6)   = 212  ; ncsj2(6)   = 252 - isrow
-            ncsir(6,1) = 225  ; ncsjr(6,1) = 220 - isrow
-            ncsir(6,2) = 225  ; ncsjr(6,2) = 221 - isrow
-            ncsir(6,3) = 226  ; ncsjr(6,3) = 220 - isrow
-            ncsir(6,4) = 226  ; ncsjr(6,4) = 221 - isrow
-            !
-            ncsnr(7)   = 1    ; ncstt(7)   = 0             ! Victoria Lake
-            ncsi1(7)   = 321  ; ncsj1(7)   = 180 - isrow     ! spread over the globe
-            ncsi2(7)   = 322  ; ncsj2(7)   = 189 - isrow
-            ncsir(7,1) = 1    ; ncsjr(7,1) = 1
-            
-            !                                        
-            !                                        ! =======================
-         CASE ( 2 )                                  !  ORCA_R2 configuration
-            !                                        ! =======================
-            !                                            ! Caspian Sea
-            ncsnr(1)   =   1  ;  ncstt(1)   =   0           ! spread over the globe
-            ncsi1(1)   =  11  ;  ncsj1(1)   = 103
-            ncsi2(1)   =  17  ;  ncsj2(1)   = 112
-            ncsir(1,1) =   1  ;  ncsjr(1,1) =   1 
-            !                                            ! Great North American Lakes
-            ncsnr(2)   =   1  ;  ncstt(2)   =   2           ! put at St Laurent mouth
-            ncsi1(2)   =  97  ;  ncsj1(2)   = 107
-            ncsi2(2)   = 103  ;  ncsj2(2)   = 111
-            ncsir(2,1) = 110  ;  ncsjr(2,1) = 111           
-            !                                            ! Black Sea (crossed by the cyclic boundary condition)
-            ncsnr(3:4) =   4  ;  ncstt(3:4) =   2           ! put in Med Sea (north of Aegean Sea)
-            ncsir(3:4,1) = 171;  ncsjr(3:4,1) = 106         !
-            ncsir(3:4,2) = 170;  ncsjr(3:4,2) = 106 
-            ncsir(3:4,3) = 171;  ncsjr(3:4,3) = 105 
-            ncsir(3:4,4) = 170;  ncsjr(3:4,4) = 105 
-            ncsi1(3)   = 174  ;  ncsj1(3)   = 107           ! 1 : west part of the Black Sea      
-            ncsi2(3)   = 181  ;  ncsj2(3)   = 112           !            (ie west of the cyclic b.c.)
-            ncsi1(4)   =   2  ;  ncsj1(4)   = 107           ! 2 : east part of the Black Sea 
-            ncsi2(4)   =   6  ;  ncsj2(4)   = 112           !           (ie east of the cyclic b.c.)
-             
-          
-
-            !                                        ! =======================
-         CASE ( 4 )                                  !  ORCA_R4 configuration
-            !                                        ! =======================
-            !                                            ! Caspian Sea
-            ncsnr(1)   =  1  ;  ncstt(1)   =  0  
-            ncsi1(1)   =  4  ;  ncsj1(1)   = 53 
-            ncsi2(1)   =  4  ;  ncsj2(1)   = 56
-            ncsir(1,1) =  1  ;  ncsjr(1,1) =  1
-            !                                            ! Great North American Lakes
-            ncsnr(2)   =  1  ;  ncstt(2)   =  2 
-            ncsi1(2)   = 49  ;  ncsj1(2)   = 55
-            ncsi2(2)   = 51  ;  ncsj2(2)   = 56
-            ncsir(2,1) = 57  ;  ncsjr(2,1) = 55
-            !                                            ! Black Sea
-            ncsnr(3)   =  4  ;  ncstt(3)   =  2  
-            ncsi1(3)   = 88  ;  ncsj1(3)   = 55 
-            ncsi2(3)   = 91  ;  ncsj2(3)   = 56
-            ncsir(3,1) = 86  ;  ncsjr(3,1) = 53
-            ncsir(3,2) = 87  ;  ncsjr(3,2) = 53 
-            ncsir(3,3) = 86  ;  ncsjr(3,3) = 52 
-            ncsir(3,4) = 87  ;  ncsjr(3,4) = 52
-            !                                            ! Baltic Sea
-            ncsnr(4)   =  1  ;  ncstt(4)   =  2
-            ncsi1(4)   = 75  ;  ncsj1(4)   = 59
-            ncsi2(4)   = 76  ;  ncsj2(4)   = 61
-            ncsir(4,1) = 84  ;  ncsjr(4,1) = 59 
-            !                                        ! =======================
-         CASE ( 025 )                                ! ORCA_R025 configuration
-            !                                        ! =======================
-            ncsnr(1)   = 1    ; ncstt(1)   = 0               ! Caspian + Aral sea
-            ncsi1(1)   = 1330 ; ncsj1(1)   = 645
-            ncsi2(1)   = 1400 ; ncsj2(1)   = 795
-            ncsir(1,1) = 1    ; ncsjr(1,1) = 1
-            !                                        
-            ncsnr(2)   = 1    ; ncstt(2)   = 0               ! Azov Sea 
-            ncsi1(2)   = 1284 ; ncsj1(2)   = 722
-            ncsi2(2)   = 1304 ; ncsj2(2)   = 747
-            ncsir(2,1) = 1    ; ncsjr(2,1) = 1
-            !
-         END SELECT
-         !
-      ENDIF
-
-      ! convert the position in local domain indices
-      ! --------------------------------------------
-      DO jc = 1, jpncs
-         ncsi1(jc)   = mi0( ncsi1(jc) )
-         ncsj1(jc)   = mj0( ncsj1(jc) )
-
-         ncsi2(jc)   = mi1( ncsi2(jc) )   
-         ncsj2(jc)   = mj1( ncsj2(jc) )  
-      END DO
-
-      !
-   END SUBROUTINE dom_clo
-
-
-   SUBROUTINE sbc_clo( kt )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_clo  ***
-      !!                    
-      !! ** Purpose :   Special handling of closed seas
-      !!
-      !! ** Method  :   Water flux is forced to zero over closed sea
-      !!      Excess is shared between remaining ocean, or
-      !!      put as run-off in open ocean.
-      !!
-      !! ** Action  :   emp updated surface freshwater fluxes and associated heat content at kt
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kt   ! ocean model time step
-      !
-      INTEGER             ::   ji, jj, jc, jn   ! dummy loop indices
-      REAL(wp), PARAMETER ::   rsmall = 1.e-20_wp    ! Closed sea correction epsilon
-      REAL(wp)            ::   zze2, ztmp, zcorr     ! 
-      REAL(wp)            ::   zcoef, zcoef1         ! 
-      COMPLEX(wp)         ::   ctmp 
-      REAL(wp), DIMENSION(jpncs) ::   zfwf   ! 1D workspace
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('sbc_clo')
-      !                                                   !------------------!
-      IF( kt == nit000 ) THEN                             !  Initialisation  !
-         !                                                !------------------!
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*)'sbc_clo : closed seas '
-         IF(lwp) WRITE(numout,*)'~~~~~~~'
-         !
-         ! Mask
-         ! --------------------------------------------
-         ALLOCATE ( clo_mask (jpi, jpj), STAT=dia_closea_alloc)
-         IF(dia_closea_alloc /= 0)   CALL ctl_warn('dia_closea_alloc: failed to allocate arrays.')
-         
-         clo_mask (:,:) = tmask (:,:,1)
-         
-         ! Latitude limits
-         WHERE ( gphit (:,:) .GT.  30.0_wp ) clo_mask (:,:) = 0.0_wp
-         WHERE ( gphit (:,:) .LT. -30.0_wp ) clo_mask (:,:) = 0.0_wp
-         !
-         ! Remove closed seas from mask
-         DO jc = 1, jpncs
-            DO jj = ncsj1(jc), ncsj2(jc)
-               DO ji = ncsi1(jc), ncsi2(jc)
-                  clo_mask (ji, jj) = 0.0_wp
-               END DO
-            END DO
-         END DO
-         
-         IF( lk_mpp ) CALL lbc_lnk ( clo_mask, 'T', 1._wp)
-      
-         !
-         surf(:) = 0.e0_wp
-         !
-         surf(jpncs+1) = glob_sum( e1e2t(:,:) * clo_mask (:,:) )   ! surface of the ocean where excess run-off goes
-         !
-         !                                        ! surface of closed seas 
-         IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
-            DO jc = 1, jpncs
-               ctmp = CMPLX( 0.e0, 0.e0, wp )
-               DO jj = ncsj1(jc), ncsj2(jc)
-                  DO ji = ncsi1(jc), ncsi2(jc)
-                     ztmp = e1e2t(ji,jj) * tmask_i(ji,jj)
-                     CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
-                  END DO 
-               END DO 
-               IF( lk_mpp )   CALL mpp_sum( ctmp )
-               surf(jc) = REAL(ctmp,wp)
-            END DO
-         ELSE                                          ! Standard calculation           
-            DO jc = 1, jpncs
-               DO jj = ncsj1(jc), ncsj2(jc)
-                  DO ji = ncsi1(jc), ncsi2(jc)
-                     surf(jc) = surf(jc) + e1e2t(ji,jj) * tmask_i(ji,jj)      ! surface of closed seas
-                  END DO 
-               END DO 
-            END DO 
-            IF( lk_mpp )   CALL mpp_sum ( surf, jpncs )       ! mpp: sum over all the global domain
-         ENDIF
-
-         IF(lwp) WRITE(numout,*)'     Closed sea surfaces'
-         DO jc = 1, jpncs
-            IF(lwp)WRITE(numout,FMT='(1I3,4I4,5X,F16.2)') jc, ncsi1(jc), ncsi2(jc), ncsj1(jc), ncsj2(jc), surf(jc)
-         END DO
-
-         IF(lwp) WRITE(numout,*)'     Surface for redistribution in closea ', surf(jpncs+1)
-         
-         !
-      ENDIF
-      !
-      !                                                   !--------------------!
-      !                                                   !  update emp        !
-      zfwf = 0.e0_wp                                      !--------------------!
-      IF( lk_mpp_rep ) THEN                         ! MPP reproductible calculation
-         DO jc = 1, jpncs
-            ctmp = CMPLX( 0.e0, 0.e0, wp )
-            DO jj = ncsj1(jc), ncsj2(jc)
-               DO ji = ncsi1(jc), ncsi2(jc)
-                  ztmp = e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj)
-                  CALL DDPDD( CMPLX( ztmp, 0.e0, wp ), ctmp )
-               END DO  
-            END DO 
-            IF( lk_mpp )   CALL mpp_sum( ctmp )
-            zfwf(jc) = REAL(ctmp,wp)
-         END DO
-      ELSE                                          ! Standard calculation           
-         DO jc = 1, jpncs
-            DO jj = ncsj1(jc), ncsj2(jc)
-               DO ji = ncsi1(jc), ncsi2(jc)
-                  zfwf(jc) = zfwf(jc) + e1e2t(ji,jj) * ( emp(ji,jj)-rnf(ji,jj) ) * tmask_i(ji,jj) 
-               END DO  
-            END DO 
-         END DO
-         IF( lk_mpp )   CALL mpp_sum ( zfwf(:) , jpncs )       ! mpp: sum over all the global domain
-      ENDIF
-
-      IF( cp_cfg == "orca" .AND. jp_cfg == 2 ) THEN      ! Black Sea case for ORCA_R2 configuration
-         zze2    = ( zfwf(3) + zfwf(4) ) * 0.5_wp
-         zfwf(3) = zze2
-         zfwf(4) = zze2
-      ENDIF
-
-      zcorr = 0._wp
-
-      DO jc = 1, jpncs
-         !
-         ! The following if avoids the redistribution of the round off
-         IF ( ABS(zfwf(jc) / surf(jpncs+1) ) > rsmall) THEN
-            !
-            IF( ncstt(jc) == 0 ) THEN           ! water/evap excess is shared by all open ocean
-               zcoef    = zfwf(jc) / surf(jpncs+1)
-               zcoef1   = rcp * zcoef
-               emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:) 
-               qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
-               !
-            ELSEIF( ncstt(jc) == 1 ) THEN       ! Excess water in open sea, at outflow location, excess evap shared
-               IF ( zfwf(jc) <= 0.e0_wp ) THEN 
-                   DO jn = 1, ncsnr(jc)
-                     ji = mi0(ncsir(jc,jn))
-                     jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
-                     IF (      ji > 1 .AND. ji < jpi   &
-                         .AND. jj > 1 .AND. jj < jpj ) THEN 
-                         zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) * e1e2t(ji,jj) )
-                         zcoef1     = rcp * zcoef
-                         emp(ji,jj) = emp(ji,jj) + zcoef 
-                         qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
-                     ENDIF 
-                   END DO 
-               ELSE 
-                   zcoef    = zfwf(jc) / surf(jpncs+1)
-                   zcoef1   = rcp * zcoef
-                   emp(:,:) = emp(:,:) + zcoef  * clo_mask (:,:)
-                   qns(:,:) = qns(:,:) - zcoef1 * sst_m(:,:) * clo_mask (:,:)
-               ENDIF
-            ELSEIF( ncstt(jc) == 2 ) THEN       ! Excess e-p-r (either sign) goes to open ocean, at outflow location
-               DO jn = 1, ncsnr(jc)
-                  ji = mi0(ncsir(jc,jn))
-                  jj = mj0(ncsjr(jc,jn)) ! Location of outflow in open ocean
-                  IF(      ji > 1 .AND. ji < jpi    &
-                     .AND. jj > 1 .AND. jj < jpj ) THEN 
-                     zcoef      = zfwf(jc) / ( REAL(ncsnr(jc)) *  e1e2t(ji,jj) )
-                     zcoef1     = rcp * zcoef
-                     emp(ji,jj) = emp(ji,jj) + zcoef
-                     qns(ji,jj) = qns(ji,jj) - zcoef1 * sst_m(ji,jj)
-                  ENDIF 
-               END DO 
-            ENDIF 
-            !
-            DO jj = ncsj1(jc), ncsj2(jc)
-               DO ji = ncsi1(jc), ncsi2(jc)
-                  zcoef      = zfwf(jc) / surf(jc)
-                  zcoef1     = rcp * zcoef
-                  emp(ji,jj) = emp(ji,jj) - zcoef
-                  qns(ji,jj) = qns(ji,jj) + zcoef1 * sst_m(ji,jj)
-               END DO  
-            END DO 
-            !
-         END IF
-      END DO 
-
-      emp (:,:) = emp (:,:) * tmask(:,:,1)
-      qns (:,:) = qns (:,:) * tmask(:,:,1)
-      !
-      CALL lbc_lnk( emp , 'T', 1._wp )
-      CALL lbc_lnk( qns , 'T', 1._wp )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('sbc_clo')
-      !
-   END SUBROUTINE sbc_clo
-
-
-   SUBROUTINE clo_rnf( p_rnfmsk )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_rnf  ***
-      !!                    
-      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
-      !!                to be the same as river mouth grid-points
-      !!
-      !! ** Method  :   set to 1 the runoff mask (mskrnf, see sbcrnf module)
-      !!                at the closed sea outflow grid-point.
-      !!
-      !! ** Action  :   update (p_)mskrnf (set 1 at closed sea outflow)
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_rnfmsk   ! river runoff mask (rnfmsk array)
-      !
-      INTEGER  ::   jc, jn, ji, jj      ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jc = 1, jpncs
-         IF( ncstt(jc) >= 1 ) THEN            ! runoff mask set to 1 at closed sea outflows
-             DO jn = 1, 4
-                DO jj =    mj0( ncsjr(jc,jn) ), mj1( ncsjr(jc,jn) )
-                   DO ji = mi0( ncsir(jc,jn) ), mi1( ncsir(jc,jn) )
-                      p_rnfmsk(ji,jj) = MAX( p_rnfmsk(ji,jj), 1.0_wp )
-                   END DO
-                END DO
-            END DO 
-         ENDIF 
-      END DO 
-      !
-   END SUBROUTINE clo_rnf
-
-   
-   SUBROUTINE clo_ups( p_upsmsk )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE sbc_rnf  ***
-      !!                    
-      !! ** Purpose :   allow the treatment of closed sea outflow grid-points
-      !!                to be the same as river mouth grid-points
-      !!
-      !! ** Method  :   set to 0.5 the upstream mask (upsmsk, see traadv_cen2 
-      !!                module) over the closed seas.
-      !!
-      !! ** Action  :   update (p_)upsmsk (set 0.5 over closed seas)
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   p_upsmsk   ! upstream mask (upsmsk array)
-      !
-      INTEGER  ::   jc, ji, jj      ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jc = 1, jpncs
-         DO jj = ncsj1(jc), ncsj2(jc)
-            DO ji = ncsi1(jc), ncsi2(jc)
-               p_upsmsk(ji,jj) = 0.5_wp         ! mixed upstream/centered scheme over closed seas
-            END DO 
-         END DO 
-       END DO 
-       !
-   END SUBROUTINE clo_ups
-   
-      
-   SUBROUTINE clo_bat( pbat, kbat )
-      !!---------------------------------------------------------------------
-      !!                  ***  ROUTINE clo_bat  ***
-      !!                    
-      !! ** Purpose :   suppress closed sea from the domain
-      !!
-      !! ** Method  :   set to 0 the meter and level bathymetry (given in 
-      !!                arguments) over the closed seas.
-      !!
-      !! ** Action  :   set pbat=0 and kbat=0 over closed seas
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pbat   ! bathymetry in meters (bathy array)
-      INTEGER , DIMENSION(jpi,jpj), INTENT(inout) ::   kbat   ! bathymetry in levels (mbathy array)
-      !
-      INTEGER  ::   jc, ji, jj      ! dummy loop indices
-      !!----------------------------------------------------------------------
-      !
-      DO jc = 1, jpncs
-         DO jj = ncsj1(jc), ncsj2(jc)
-            DO ji = ncsi1(jc), ncsi2(jc)
-               pbat(ji,jj) = 0._wp   
-               kbat(ji,jj) = 0   
-            END DO 
-         END DO 
-       END DO 
-       !
-   END SUBROUTINE clo_bat
-
-   !!======================================================================
-END MODULE closea
-
Index: NFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/diaar5.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/diaar5.F90	(revision 5878)
+++ 	(revision )
@@ -1,285 +1,0 @@
-MODULE diaar5
-   !!======================================================================
-   !!                       ***  MODULE  diaar5  ***
-   !! AR5 diagnostics
-   !!======================================================================
-   !! History :  3.2  !  2009-11  (S. Masson)  Original code
-   !!            3.3  !  2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase + merge TRC-TRA
-   !!----------------------------------------------------------------------
-#if defined key_diaar5   || defined key_esopa
-   !!----------------------------------------------------------------------
-   !!   'key_diaar5'  :                           activate ar5 diagnotics
-   !!----------------------------------------------------------------------
-   !!   dia_ar5       : AR5 diagnostics
-   !!   dia_ar5_init  : initialisation of AR5 diagnostics
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and active tracers 
-   USE dom_oce        ! ocean space and time domain
-   USE eosbn2         ! equation of state                (eos_bn2 routine)
-   USE lib_mpp        ! distribued memory computing library
-   USE iom            ! I/O manager library
-   USE timing         ! preformance summary
-   USE wrk_nemo       ! working arrays
-   USE fldread        ! type FLD_N
-   USE phycst         ! physical constant
-   USE in_out_manager  ! I/O manager
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   dia_ar5        ! routine called in step.F90 module
-   PUBLIC   dia_ar5_init   ! routine called in opa.F90 module
-   PUBLIC   dia_ar5_alloc  ! routine called in nemogcm.F90 module
-
-   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .TRUE.   ! coupled flag
-
-   REAL(wp)                         ::   vol0         ! ocean volume (interior domain)
-   REAL(wp)                         ::   area_tot     ! total ocean surface (interior domain)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   area         ! cell surface (interior domain)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:  ) ::   thick0       ! ocean thickness (interior domain)
-   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   sn0          ! initial salinity
-      
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: diaar5.F90 6664 2016-06-03 13:42:46Z cetlod $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   FUNCTION dia_ar5_alloc()
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE dia_ar5_alloc  ***
-      !!----------------------------------------------------------------------
-      INTEGER :: dia_ar5_alloc
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( area(jpi,jpj), thick0(jpi,jpj) , sn0(jpi,jpj,jpk) , STAT=dia_ar5_alloc )
-      !
-      IF( lk_mpp             )   CALL mpp_sum ( dia_ar5_alloc )
-      IF( dia_ar5_alloc /= 0 )   CALL ctl_warn('dia_ar5_alloc: failed to allocate arrays')
-      !
-   END FUNCTION dia_ar5_alloc
-
-
-   SUBROUTINE dia_ar5( kt )
-      !!----------------------------------------------------------------------
-      !!                    ***  ROUTINE dia_ar5  ***
-      !!
-      !! ** Purpose :   compute and output some AR5 diagnostics
-      !!----------------------------------------------------------------------
-      !
-      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
-      !
-      INTEGER  ::   ji, jj, jk                      ! dummy loop arguments
-      REAL(wp) ::   zvolssh, zvol, zssh_steric, zztmp, zarho, ztemp, zsal, zmass
-      !
-      REAL(wp), POINTER, DIMENSION(:,:)     :: zarea_ssh , zbotpres       ! 2D workspace 
-      REAL(wp), POINTER, DIMENSION(:,:,:)   :: zrhd , z3d, zrhop               ! 3D workspace
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztsn                       ! 4D workspace
-      !!--------------------------------------------------------------------
-      IF( nn_timing == 1 )   CALL timing_start('dia_ar5')
- 
-      CALL wrk_alloc( jpi , jpj              , zarea_ssh , zbotpres )
-      CALL wrk_alloc( jpi , jpj , jpk        , zrhd      , z3d, zrhop    )
-      CALL wrk_alloc( jpi , jpj , jpk , jpts , ztsn                 )
-
-      zarea_ssh(:,:) = area(:,:) * sshn(:,:)
-
-      !                                         ! total volume of liquid seawater
-      zvolssh = SUM( zarea_ssh(:,:) ) 
-      IF( lk_mpp )   CALL mpp_sum( zvolssh )
-      zvol = vol0 + zvolssh
-
-      z3d(:,:,jpk) = 0._wp        ! ocean volume
-      DO jk = 1, jpkm1
-         z3d (:,:,jk) = area(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
-      END DO
-
-      CALL iom_put( "bathy"     , bathy(:,:) )
-      CALL iom_put( "areacello" , area (:,:) )
-      CALL iom_put( "volcello"  , z3d(:,:,:)         )     ! WARNING not consistent with CMIP DR where volcello is at ca. 2000 
-      CALL iom_put( "masscello" , rau0 * fse3t(:,:,:) * tmask(:,:,:) )  ! ocean mass 
-
-
-      CALL iom_put( 'voltot', zvol               )
-      CALL iom_put( 'sshtot', zvolssh / area_tot )
-
-      !                     
-      ztsn(:,:,:,jp_tem) = tsn(:,:,:,jp_tem)                    ! thermosteric ssh
-      ztsn(:,:,:,jp_sal) = sn0(:,:,:)
-      CALL eos( ztsn, zrhd, fsdept_n(:,:,:) )                       ! now in situ density using initial salinity
-      !
-      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
-      DO jk = 1, jpkm1
-         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
-      END DO
-      IF( .NOT.lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
-            DO ji=1,jpi
-               DO jj=1,jpj
-                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
-               END DO
-            END DO
-         ELSE
-            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
-         END IF
-      END IF
-      !                                         
-      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
-      IF( lk_mpp )   CALL mpp_sum( zarho )
-      zssh_steric = - zarho / area_tot
-      CALL iom_put( 'sshthster', zssh_steric )
-      
-      !                                         ! steric sea surface height
-      CALL eos( tsn, zrhd, zrhop, fsdept_n(:,:,:) )                 ! now in situ and potential density
-      zrhop(:,:,jpk) = 0._wp
-      CALL iom_put( 'rhop', zrhop )
-      !
-      zbotpres(:,:) = 0._wp                        ! no atmospheric surface pressure, levitating sea-ice
-      DO jk = 1, jpkm1
-         zbotpres(:,:) = zbotpres(:,:) + fse3t(:,:,jk) * zrhd(:,:,jk)
-      END DO
-      IF( .NOT.lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
-            DO ji=1,jpi
-               DO jj=1,jpj
-                  zbotpres(ji,jj) = zbotpres(ji,jj) + sshn(ji,jj) * zrhd(ji,jj,mikt(ji,jj)) + riceload(ji,jj)
-               END DO
-            END DO
-         ELSE
-            zbotpres(:,:) = zbotpres(:,:) + sshn(:,:) * zrhd(:,:,1)
-         END IF
-      END IF
-      !    
-      zarho = SUM( area(:,:) * zbotpres(:,:) ) 
-      IF( lk_mpp )   CALL mpp_sum( zarho )
-      zssh_steric = - zarho / area_tot
-      CALL iom_put( 'sshsteric', zssh_steric )
-      
-      !                                         ! ocean bottom pressure
-      zztmp = rau0 * grav * 1.e-4_wp               ! recover pressure from pressure anomaly and cover to dbar = 1.e4 Pa
-      zbotpres(:,:) = zztmp * ( zbotpres(:,:) + sshn(:,:) + thick0(:,:) )
-      CALL iom_put( 'botpres', zbotpres )
-
-      !                                         ! Mean density anomalie, temperature and salinity
-      ztemp = 0._wp
-      zsal  = 0._wp
-      DO jk = 1, jpkm1
-         DO jj = 1, jpj
-            DO ji = 1, jpi
-               zztmp = area(ji,jj) * fse3t(ji,jj,jk)
-               ztemp = ztemp + zztmp * tsn(ji,jj,jk,jp_tem)
-               zsal  = zsal  + zztmp * tsn(ji,jj,jk,jp_sal)
-            END DO
-         END DO
-      END DO
-      IF( .NOT.lk_vvl ) THEN
-         IF ( ln_isfcav ) THEN
-            DO ji=1,jpi
-               DO jj=1,jpj
-                  ztemp = ztemp + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_tem) 
-                  zsal  = zsal  + zarea_ssh(ji,jj) * tsn(ji,jj,mikt(ji,jj),jp_sal) 
-               END DO
-            END DO
-         ELSE
-            ztemp = ztemp + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_tem) )
-            zsal  = zsal  + SUM( zarea_ssh(:,:) * tsn(:,:,1,jp_sal) )
-         END IF
-      ENDIF
-      IF( lk_mpp ) THEN  
-         CALL mpp_sum( ztemp )
-         CALL mpp_sum( zsal  )
-      END IF
-      !
-      zmass = rau0 * ( zarho + zvol )                 ! total mass of liquid seawater
-      ztemp = ztemp / zvol                            ! potential temperature in liquid seawater
-      zsal  = zsal  / zvol                            ! Salinity of liquid seawater
-      !
-      CALL iom_put( 'masstot', zmass )
-      CALL iom_put( 'temptot', ztemp )
-      CALL iom_put( 'saltot' , zsal  )
-      ! 
-      CALL wrk_dealloc( jpi , jpj              , zarea_ssh , zbotpres    )
-      CALL wrk_dealloc( jpi , jpj , jpk        , zrhd      , z3d , zrhop )
-      CALL wrk_dealloc( jpi , jpj , jpk , jpts , ztsn                    )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5')
-      !
-   END SUBROUTINE dia_ar5
-
-
-   SUBROUTINE dia_ar5_init
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE dia_ar5_init  ***
-      !!                   
-      !! ** Purpose :   initialization for AR5 diagnostic computation
-      !!----------------------------------------------------------------------
-      INTEGER  ::   inum
-      INTEGER  ::   ik
-      INTEGER  ::   ji, jj, jk  ! dummy loop indices
-      REAL(wp) ::   zztmp  
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::   zsaldta   ! Jan/Dec levitus salinity
-      !
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )   CALL timing_start('dia_ar5_init')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, 2, zsaldta )
-      !                                      ! allocate dia_ar5 arrays
-      IF( dia_ar5_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'dia_ar5_init : unable to allocate arrays' )
-
-      area(:,:) = e1t(:,:) * e2t(:,:) * tmask_i(:,:)
-
-      area_tot = SUM( area(:,:) )   ;   IF( lk_mpp )   CALL mpp_sum( area_tot )
-
-      vol0        = 0._wp
-      thick0(:,:) = 0._wp
-      DO jk = 1, jpkm1
-         vol0        = vol0        + SUM( area (:,:) * tmask(:,:,jk) * e3t_0(:,:,jk) )
-         thick0(:,:) = thick0(:,:) +    tmask_i(:,:) * tmask(:,:,jk) * e3t_0(:,:,jk)
-      END DO
-      IF( lk_mpp )   CALL mpp_sum( vol0 )
-
-      CALL iom_open ( 'sali_ref_clim_monthly', inum )
-      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,1), 1  )
-      CALL iom_get  ( inum, jpdom_data, 'vosaline' , zsaldta(:,:,:,2), 12 )
-      CALL iom_close( inum )
-
-      sn0(:,:,:) = 0.5_wp * ( zsaldta(:,:,:,1) + zsaldta(:,:,:,2) )        
-      sn0(:,:,:) = sn0(:,:,:) * tmask(:,:,:)
-      IF( ln_zps ) THEN               ! z-coord. partial steps
-         DO jj = 1, jpj               ! interpolation of salinity at the last ocean level (i.e. the partial step)
-            DO ji = 1, jpi
-               ik = mbkt(ji,jj)
-               IF( ik > 1 ) THEN
-                  zztmp = ( gdept_1d(ik) - gdept_0(ji,jj,ik) ) / ( gdept_1d(ik) - gdept_1d(ik-1) )
-                  sn0(ji,jj,ik) = ( 1._wp - zztmp ) * sn0(ji,jj,ik) + zztmp * sn0(ji,jj,ik-1)
-               ENDIF
-            END DO
-         END DO
-      ENDIF
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, 2, zsaldta )
-      !
-      IF( nn_timing == 1 )   CALL timing_stop('dia_ar5_init')
-      !
-   END SUBROUTINE dia_ar5_init
-
-#else
-   !!----------------------------------------------------------------------
-   !!   Default option :                                         NO diaar5
-   !!----------------------------------------------------------------------
-   LOGICAL, PUBLIC, PARAMETER :: lk_diaar5 = .FALSE.   ! coupled flag
-CONTAINS
-   SUBROUTINE dia_ar5_init    ! Dummy routine
-   END SUBROUTINE dia_ar5_init
-   SUBROUTINE dia_ar5( kt )   ! Empty routine
-      INTEGER ::   kt
-      WRITE(*,*) 'dia_ar5: You should not have seen this print! error?', kt
-   END SUBROUTINE dia_ar5
-#endif
-
-   !!======================================================================
-END MODULE diaar5
Index: NFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/lib_mpp.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/lib_mpp.F90	(revision 5878)
+++ 	(revision )
@@ -1,4041 +1,0 @@
-MODULE lib_mpp
-   !!======================================================================
-   !!                       ***  MODULE  lib_mpp  ***
-   !! Ocean numerics:  massively parallel processing library
-   !!=====================================================================
-   !! History :  OPA  !  1994  (M. Guyon, J. Escobar, M. Imbard)  Original code
-   !!            7.0  !  1997  (A.M. Treguier)  SHMEM additions
-   !!            8.0  !  1998  (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI
-   !!                 !  1998  (J.M. Molines) Open boundary conditions
-   !!   NEMO     1.0  !  2003  (J.-M. Molines, G. Madec)  F90, free form
-   !!                 !  2003  (J.M. Molines) add mpp_ini_north(_3d,_2d)
-   !!             -   !  2004  (R. Bourdalle Badie)  isend option in mpi
-   !!                 !  2004  (J.M. Molines) minloc, maxloc
-   !!             -   !  2005  (G. Madec, S. Masson)  npolj=5,6 F-point & ice cases
-   !!             -   !  2005  (R. Redler) Replacement of MPI_COMM_WORLD except for MPI_Abort
-   !!             -   !  2005  (R. Benshila, G. Madec)  add extra halo case
-   !!             -   !  2008  (R. Benshila) add mpp_ini_ice
-   !!            3.2  !  2009  (R. Benshila) SHMEM suppression, north fold in lbc_nfd
-   !!            3.2  !  2009  (O. Marti)    add mpp_ini_znl
-   !!            4.0  !  2011  (G. Madec)  move ctl_ routines from in_out_manager
-   !!            3.5  !  2012  (S.Mocavero, I. Epicoco) Add 'mpp_lnk_bdy_3d', 'mpp_lnk_obc_3d', 
-   !!                          'mpp_lnk_bdy_2d' and 'mpp_lnk_obc_2d' routines and update
-   !!                          the mppobc routine to optimize the BDY and OBC communications
-   !!            3.5  !  2013  ( C. Ethe, G. Madec ) message passing arrays as local variables 
-   !!            3.5  !  2013  (S.Mocavero, I.Epicoco - CMCC) north fold optimizations
-   !!            3.6  !  2015  (O. TintÃ³ and M. Castrillo - BSC) Added 'mpp_lnk_2d_multiple', 'mpp_lbc_north_2d_multiple', 'mpp_max_multiple' 
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   ctl_stop   : update momentum and tracer Kz from a tke scheme
-   !!   ctl_warn   : initialization, namelist read, and parameters control
-   !!   ctl_opn    : Open file and check if required file is available.
-   !!   ctl_nam    : Prints informations when an error occurs while reading a namelist
-   !!   get_unit   : give the index of an unused logical unit
-   !!----------------------------------------------------------------------
-#if   defined key_mpp_mpi
-   !!----------------------------------------------------------------------
-   !!   'key_mpp_mpi'             MPI massively parallel processing library
-   !!----------------------------------------------------------------------
-   !!   lib_mpp_alloc : allocate mpp arrays
-   !!   mynode        : indentify the processor unit
-   !!   mpp_lnk       : interface (defined in lbclnk) for message passing of 2d or 3d arrays (mpp_lnk_2d, mpp_lnk_3d)
-   !!   mpp_lnk_3d_gather :  Message passing manadgement for two 3D arrays
-   !!   mpp_lnk_e     : interface (defined in lbclnk) for message passing of 2d array with extra halo (mpp_lnk_2d_e)
-   !!   mpp_lnk_icb   : interface for message passing of 2d arrays with extra halo for icebergs (mpp_lnk_2d_icb)
-   !!   mpprecv       :
-   !!   mppsend       :   SUBROUTINE mpp_ini_znl
-   !!   mppscatter    :
-   !!   mppgather     :
-   !!   mpp_min       : generic interface for mppmin_int , mppmin_a_int , mppmin_real, mppmin_a_real
-   !!   mpp_max       : generic interface for mppmax_int , mppmax_a_int , mppmax_real, mppmax_a_real
-   !!   mpp_sum       : generic interface for mppsum_int , mppsum_a_int , mppsum_real, mppsum_a_real
-   !!   mpp_minloc    :
-   !!   mpp_maxloc    :
-   !!   mppsync       :
-   !!   mppstop       :
-   !!   mpp_ini_north : initialisation of north fold
-   !!   mpp_lbc_north : north fold processors gathering
-   !!   mpp_lbc_north_e : variant of mpp_lbc_north for extra outer halo
-   !!   mpp_lbc_north_icb : variant of mpp_lbc_north for extra outer halo with icebergs
-   !!----------------------------------------------------------------------
-   USE dom_oce        ! ocean space and time domain
-   USE lbcnfd         ! north fold treatment
-   USE in_out_manager ! I/O manager
-   USE wrk_nemo       ! work arrays
-
-   IMPLICIT NONE
-   PRIVATE
-   
-   PUBLIC   ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam
-   PUBLIC   mynode, mppstop, mppsync, mpp_comm_free
-   PUBLIC   mpp_ini_north, mpp_lbc_north, mpp_lbc_north_e
-   PUBLIC   mpp_min, mpp_max, mpp_sum, mpp_minloc, mpp_maxloc
-   PUBLIC   mpp_max_multiple
-   PUBLIC   mpp_lnk_3d, mpp_lnk_3d_gather, mpp_lnk_2d, mpp_lnk_2d_e
-   PUBLIC   mpp_lnk_2d_9 , mpp_lnk_2d_multiple 
-   PUBLIC   mppscatter, mppgather
-   PUBLIC   mpp_ini_ice, mpp_ini_znl
-   PUBLIC   mppsize
-   PUBLIC   mppsend, mpprecv                          ! needed by TAM and ICB routines
-   PUBLIC   mpp_lnk_bdy_2d, mpp_lnk_bdy_3d
-   PUBLIC   mpp_lbc_north_icb, mpp_lnk_2d_icb
-   PUBLIC   mpprank
-
-   TYPE arrayptr
-      REAL , DIMENSION (:,:),  POINTER :: pt2d
-   END TYPE arrayptr
-   PUBLIC   arrayptr
-   
-   !! * Interfaces
-   !! define generic interface for these routine as they are called sometimes
-   !! with scalar arguments instead of array arguments, which causes problems
-   !! for the compilation on AIX system as well as NEC and SGI. Ok on COMPACQ
-   INTERFACE mpp_min
-      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
-   END INTERFACE
-   INTERFACE mpp_max
-      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
-   END INTERFACE
-   INTERFACE mpp_sum
-      MODULE PROCEDURE mppsum_a_int, mppsum_int, mppsum_a_real, mppsum_real, &
-                       mppsum_realdd, mppsum_a_realdd
-   END INTERFACE
-   INTERFACE mpp_lbc_north
-      MODULE PROCEDURE mpp_lbc_north_3d, mpp_lbc_north_2d
-   END INTERFACE
-   INTERFACE mpp_minloc
-      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
-   END INTERFACE
-   INTERFACE mpp_maxloc
-      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
-   END INTERFACE
-
-   INTERFACE mpp_max_multiple
-      MODULE PROCEDURE mppmax_real_multiple
-   END INTERFACE
-
-   !! ========================= !!
-   !!  MPI  variable definition !!
-   !! ========================= !!
-!$AGRIF_DO_NOT_TREAT
-   INCLUDE 'mpif.h'
-!$AGRIF_END_DO_NOT_TREAT
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .TRUE.    !: mpp flag
-
-   INTEGER, PARAMETER         ::   nprocmax = 2**10   ! maximun dimension (required to be a power of 2)
-
-   INTEGER ::   mppsize        ! number of process
-   INTEGER ::   mpprank        ! process number  [ 0 - size-1 ]
-!$AGRIF_DO_NOT_TREAT
-   INTEGER, PUBLIC ::   mpi_comm_opa   ! opa local communicator
-!$AGRIF_END_DO_NOT_TREAT
-
-   INTEGER :: MPI_SUMDD
-
-   ! variables used in case of sea-ice
-   INTEGER, PUBLIC ::   ncomm_ice       !: communicator made by the processors with sea-ice (public so that it can be freed in limthd)
-   INTEGER ::   ngrp_iworld     !  group ID for the world processors (for rheology)
-   INTEGER ::   ngrp_ice        !  group ID for the ice processors (for rheology)
-   INTEGER ::   ndim_rank_ice   !  number of 'ice' processors
-   INTEGER ::   n_ice_root      !  number (in the comm_ice) of proc 0 in the ice comm
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_ice     ! dimension ndim_rank_ice
-
-   ! variables used for zonal integration
-   INTEGER, PUBLIC ::   ncomm_znl       !: communicator made by the processors on the same zonal average
-   LOGICAL, PUBLIC ::   l_znl_root      ! True on the 'left'most processor on the same row
-   INTEGER ::   ngrp_znl        ! group ID for the znl processors
-   INTEGER ::   ndim_rank_znl   ! number of processors on the same zonal average
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE ::   nrank_znl  ! dimension ndim_rank_znl, number of the procs into the same znl domain
-
-   ! North fold condition in mpp_mpi with jpni > 1 (PUBLIC for TAM)
-   INTEGER, PUBLIC ::   ngrp_world        ! group ID for the world processors
-   INTEGER, PUBLIC ::   ngrp_opa          ! group ID for the opa processors
-   INTEGER, PUBLIC ::   ngrp_north        ! group ID for the northern processors (to be fold)
-   INTEGER, PUBLIC ::   ncomm_north       ! communicator made by the processors belonging to ngrp_north
-   INTEGER, PUBLIC ::   ndim_rank_north   ! number of 'sea' processor in the northern line (can be /= jpni !)
-   INTEGER, PUBLIC ::   njmppmax          ! value of njmpp for the processors of the northern line
-   INTEGER, PUBLIC ::   north_root        ! number (in the comm_opa) of proc 0 in the northern comm
-   INTEGER, DIMENSION(:), ALLOCATABLE, SAVE, PUBLIC ::   nrank_north   ! dimension ndim_rank_north
-
-   ! Type of send : standard, buffered, immediate
-   CHARACTER(len=1), PUBLIC ::   cn_mpi_send   ! type od mpi send/recieve (S=standard, B=bsend, I=isend)
-   LOGICAL, PUBLIC          ::   l_isend = .FALSE.   ! isend use indicator (T if cn_mpi_send='I')
-   INTEGER, PUBLIC          ::   nn_buffer     ! size of the buffer in case of mpi_bsend
-
-   REAL(wp), DIMENSION(:), ALLOCATABLE, SAVE :: tampon  ! buffer in case of bsend
-
-   LOGICAL, PUBLIC                                  ::   ln_nnogather       ! namelist control of northfold comms
-   LOGICAL, PUBLIC                                  ::   l_north_nogather = .FALSE.  ! internal control of northfold comms
-   INTEGER, PUBLIC                                  ::   ityp
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: lib_mpp.F90 8537 2017-09-19 05:46:09Z gm $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-
-   FUNCTION mynode( ldtxt, ldname, kumnam_ref , kumnam_cfg , kumond , kstop, localComm )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mynode  ***
-      !!
-      !! ** Purpose :   Find processor unit
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
-      CHARACTER(len=*)             , INTENT(in   ) ::   ldname
-      INTEGER                      , INTENT(in   ) ::   kumnam_ref     ! logical unit for reference namelist
-      INTEGER                      , INTENT(in   ) ::   kumnam_cfg     ! logical unit for configuration namelist
-      INTEGER                      , INTENT(inout) ::   kumond         ! logical unit for namelist output
-      INTEGER                      , INTENT(inout) ::   kstop          ! stop indicator
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
-      !
-      INTEGER ::   mynode, ierr, code, ji, ii, ios
-      LOGICAL ::   mpi_was_called
-      !
-      NAMELIST/nammpp/ cn_mpi_send, nn_buffer, jpni, jpnj, jpnij, ln_nnogather
-      !!----------------------------------------------------------------------
-      !
-      ii = 1
-      WRITE(ldtxt(ii),*)                                                                          ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) 'mynode : mpi initialisation'                                            ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '~~~~~~ '                                                                ;   ii = ii + 1
-      !
-
-      REWIND( kumnam_ref )              ! Namelist nammpp in reference namelist: mpi variables
-      READ  ( kumnam_ref, nammpp, IOSTAT = ios, ERR = 901)
-901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in reference namelist', lwp )
-
-      REWIND( kumnam_cfg )              ! Namelist nammpp in configuration namelist: mpi variables
-      READ  ( kumnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
-902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in configuration namelist', lwp )
-
-      !                              ! control print
-      WRITE(ldtxt(ii),*) '   Namelist nammpp'                                                     ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      mpi send type                      cn_mpi_send = ', cn_mpi_send   ;   ii = ii + 1
-      WRITE(ldtxt(ii),*) '      size in bytes of exported buffer   nn_buffer   = ', nn_buffer     ;   ii = ii + 1
-
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() ) THEN
-         jpni  = Agrif_Parent(jpni )
-         jpnj  = Agrif_Parent(jpnj )
-         jpnij = Agrif_Parent(jpnij)
-      ENDIF
-#endif
-
-      IF(jpnij < 1)THEN
-         ! If jpnij is not specified in namelist then we calculate it - this
-         ! means there will be no land cutting out.
-         jpnij = jpni * jpnj
-      END IF
-
-      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
-         WRITE(ldtxt(ii),*) '      jpni, jpnj and jpnij will be calculated automatically'; ii = ii + 1
-      ELSE
-         WRITE(ldtxt(ii),*) '      processor grid extent in i         jpni = ',jpni; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      processor grid extent in j         jpnj = ',jpnj; ii = ii + 1
-         WRITE(ldtxt(ii),*) '      number of local domains           jpnij = ',jpnij; ii = ii +1
-      END IF
-
-      WRITE(ldtxt(ii),*) '      avoid use of mpi_allgather at the north fold  ln_nnogather = ', ln_nnogather  ; ii = ii + 1
-
-      CALL mpi_initialized ( mpi_was_called, code )
-      IF( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt)
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO
-         WRITE(*, cform_err)
-         WRITE(*, *) 'lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-
-      IF( mpi_was_called ) THEN
-         !
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
-            l_isend = .TRUE.
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-      ELSE IF ( PRESENT(localComm) .and. .not. mpi_was_called ) THEN
-         WRITE(ldtxt(ii),*) ' lib_mpp: You cannot provide a local communicator '                  ;   ii = ii + 1
-         WRITE(ldtxt(ii),*) '          without calling MPI_Init before ! '                        ;   ii = ii + 1
-         kstop = kstop + 1
-      ELSE
-         SELECT CASE ( cn_mpi_send )
-         CASE ( 'S' )                ! Standard mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Standard blocking mpi send (send)'                     ;   ii = ii + 1
-            CALL mpi_init( ierr )
-         CASE ( 'B' )                ! Buffer mpi send (blocking)
-            WRITE(ldtxt(ii),*) '           Buffer blocking mpi send (bsend)'                      ;   ii = ii + 1
-            IF( Agrif_Root() )   CALL mpi_init_opa( ldtxt, ii, ierr )
-         CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-            WRITE(ldtxt(ii),*) '           Immediate non-blocking send (isend)'                   ;   ii = ii + 1
-            l_isend = .TRUE.
-            CALL mpi_init( ierr )
-         CASE DEFAULT
-            WRITE(ldtxt(ii),cform_err)                                                            ;   ii = ii + 1
-            WRITE(ldtxt(ii),*) '           bad value for cn_mpi_send = ', cn_mpi_send             ;   ii = ii + 1
-            kstop = kstop + 1
-         END SELECT
-         !
-      ENDIF
-
-      IF( PRESENT(localComm) ) THEN
-         IF( Agrif_Root() ) THEN
-            mpi_comm_opa = localComm
-         ENDIF
-      ELSE
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code)
-         IF( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF
-
-#if defined key_agrif
-      IF (Agrif_Root()) THEN
-         CALL Agrif_MPI_Init(mpi_comm_opa)
-      ELSE
-         CALL Agrif_MPI_set_grid_comm(mpi_comm_opa)
-      ENDIF
-#endif
-
-      CALL mpi_comm_rank( mpi_comm_opa, mpprank, ierr )
-      CALL mpi_comm_size( mpi_comm_opa, mppsize, ierr )
-      mynode = mpprank
-
-      IF( mynode == 0 ) THEN
-         CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
-         WRITE(kumond, nammpp)      
-      ENDIF
-      !
-      CALL MPI_OP_CREATE(DDPDD_MPI, .TRUE., MPI_SUMDD, ierr)
-      !
-   END FUNCTION mynode
-
-   SUBROUTINE mpp_lnk_3d( ptab, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL      , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL      , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-      
-      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
-         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING ptab is defined only between nld and nle
-         DO jk = 1, jpk
-            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-               ptab(nldi  :nlei  , jj          ,jk) = ptab(nldi:nlei,     nlej,jk)
-               ptab(1     :nldi-1, jj          ,jk) = ptab(nldi     ,     nlej,jk)
-               ptab(nlei+1:nlci  , jj          ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-            DO ji = nlci+1, jpi                 ! added column(s) (full)
-               ptab(ji           ,nldj  :nlej  ,jk) = ptab(     nlei,nldj:nlej,jk)
-               ptab(ji           ,1     :nldj-1,jk) = ptab(     nlei,nldj     ,jk)
-               ptab(ji           ,nlej+1:jpj   ,jk) = ptab(     nlei,     nlej,jk)
-            END DO
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment
-         !
-         !                                   ! East-West boundaries
-         !                                        !* Cyclic east-west
-         IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            ptab( 1 ,:,:) = ptab(jpim1,:,:)
-            ptab(jpi,:,:) = ptab(  2  ,:,:)
-         ELSE                                     !* closed
-            IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-                                         ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-         ENDIF
-         !                                   ! North-South boundaries (always closed)
-         IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
-                                      ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
-            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
-            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl,:) = zt3sn(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we )
-      !
-   END SUBROUTINE mpp_lnk_3d
-
-   SUBROUTINE mpp_lnk_2d_multiple( pt2d_array , type_array , psgn_array , num_fields , cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_multiple  ***
-      !!
-      !! ** Purpose :   Message passing management for multiple 2d arrays
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-
-      INTEGER :: num_fields
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   type_array   ! define the nature of ptab array grid-points
-      !                                                               ! = T , U , V , F , W and I points
-      REAL(wp)        , DIMENSION(:), INTENT(in   ) ::   psgn_array   ! =-1 the sign change across the north fold boundary
-      !                                                               ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL    , INTENT(in   ) ::   cd_mpp       ! fill the overlap area only
-      REAL(wp)        , OPTIONAL    , INTENT(in   ) ::   pval         ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   ii    !!MULTI SEND DUMMY LOOP INDICES
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( zt2ns(jpi,jprecj,2*num_fields), zt2sn(jpi,jprecj,2*num_fields),  &
-         &      zt2ew(jpj,jpreci,2*num_fields), zt2we(jpj,jpreci,2*num_fields)   )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      !First Array
-      DO ii = 1 , num_fields
-         IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-            !
-            ! WARNING pt2d is defined only between nld and nle
-            DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-               pt2d_array(ii)%pt2d(nldi  :nlei  , jj) = pt2d_array(ii)%pt2d(nldi:nlei, nlej)
-               pt2d_array(ii)%pt2d(1     :nldi-1, jj) = pt2d_array(ii)%pt2d(nldi     , nlej)
-               pt2d_array(ii)%pt2d(nlei+1:nlci  , jj) = pt2d_array(ii)%pt2d(     nlei, nlej) 
-            END DO
-            DO ji = nlci+1, jpi                 ! added column(s) (full)
-               pt2d_array(ii)%pt2d(ji, nldj  :nlej  ) = pt2d_array(ii)%pt2d(nlei, nldj:nlej)
-               pt2d_array(ii)%pt2d(ji, 1     :nldj-1) = pt2d_array(ii)%pt2d(nlei, nldj     )
-               pt2d_array(ii)%pt2d(ji, nlej+1:jpj   ) = pt2d_array(ii)%pt2d(nlei,      nlej)
-            END DO
-            !
-         ELSE                              ! standard close or cyclic treatment
-            !
-            !                                   ! East-West boundaries
-            IF( nbondi == 2 .AND.   &                ! Cyclic east-west
-               &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-               pt2d_array(ii)%pt2d(  1  , : ) = pt2d_array(ii)%pt2d( jpim1, : )                                    ! west
-               pt2d_array(ii)%pt2d( jpi , : ) = pt2d_array(ii)%pt2d(   2  , : )                                    ! east
-            ELSE                                     ! closed
-               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(            1 : jpreci,:) = zland    ! south except F-point
-                                                   pt2d_array(ii)%pt2d(nlci-jpreci+1 : jpi   ,:) = zland    ! north
-            ENDIF
-            !                                   ! North-South boundaries (always closed)
-               IF( .NOT. type_array(ii) == 'F' )   pt2d_array(ii)%pt2d(:,             1:jprecj ) = zland    ! south except F-point
-                                                   pt2d_array(ii)%pt2d(:, nlcj-jprecj+1:jpj    ) = zland    ! north
-            !
-         ENDIF
-      END DO
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      DO ii = 1 , num_fields
-         SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-         CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-            iihom = nlci-nreci
-            DO jl = 1, jpreci
-               zt2ew( : , jl , ii ) = pt2d_array(ii)%pt2d( jpreci+jl , : )
-               zt2we( : , jl , ii ) = pt2d_array(ii)%pt2d( iihom +jl , : )
-            END DO
-         END SELECT
-      END DO
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), num_fields*imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt2ew(1,1,num_fields+1), num_fields*imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), num_fields*imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt2we(1,1,num_fields+1), num_fields*imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-
-      DO ii = 1 , num_fields
-         SELECT CASE ( nbondi )
-         CASE ( -1 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
-            END DO
-         CASE ( 0 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( jl , : ) = zt2we(:,jl,num_fields+ii)
-               pt2d_array(ii)%pt2d( iihom+jl , : ) = zt2ew(:,jl,num_fields+ii)
-            END DO
-         CASE ( 1 )
-            DO jl = 1, jpreci
-               pt2d_array(ii)%pt2d( jl , : )= zt2we(:,jl,num_fields+ii)
-            END DO
-         END SELECT
-      END DO
-      
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      !First Array
-      DO ii = 1 , num_fields
-         IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-            ijhom = nlcj-nrecj
-            DO jl = 1, jprecj
-               zt2sn(:,jl , ii) = pt2d_array(ii)%pt2d( : , ijhom +jl )
-               zt2ns(:,jl , ii) = pt2d_array(ii)%pt2d( : , jprecj+jl )
-            END DO
-         ENDIF
-      END DO
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), num_fields*imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt2ns(1,1,num_fields+1), num_fields*imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), num_fields*imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt2sn(1,1,num_fields+1), num_fields*imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-
-      DO ii = 1 , num_fields
-         !First Array
-         SELECT CASE ( nbondj )
-         CASE ( -1 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , ijhom+jl ) = zt2ns( : , jl , num_fields+ii )
-            END DO
-         CASE ( 0 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii)
-               pt2d_array(ii)%pt2d( : , ijhom + jl ) = zt2ns( : , jl , num_fields + ii )
-            END DO
-         CASE ( 1 )
-            DO jl = 1, jprecj
-               pt2d_array(ii)%pt2d( : , jl ) = zt2sn( : , jl , num_fields + ii )
-            END DO
-         END SELECT
-      END DO
-      
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-         !First Array
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   
-             DO ii = 1 , num_fields  
-                       CALL lbc_nfd      ( pt2d_array(ii)%pt2d( : , : ), type_array(ii) , psgn_array(ii) )   ! only 1 northern proc, no mpp
-             END DO
-         CASE DEFAULT   ;   CALL mpp_lbc_north_2d_multiple( pt2d_array, type_array, psgn_array, num_fields )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-        !
-      
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
-      !
-   END SUBROUTINE mpp_lnk_2d_multiple
-
-   
-   SUBROUTINE load_array(pt2d,cd_type,psgn,pt2d_array, type_array, psgn_array,num_fields)
-      !!---------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), TARGET   ,   INTENT(inout) ::   pt2d    ! Second 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type ! define the nature of ptab array grid-points
-      REAL(wp)                    , INTENT(in   ) ::   psgn    ! =-1 the sign change across the north fold boundary
-      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array
-      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
-      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
-      INTEGER                      , INTENT (inout):: num_fields 
-      !!---------------------------------------------------------------------
-      num_fields=num_fields+1
-      pt2d_array(num_fields)%pt2d=>pt2d
-      type_array(num_fields)=cd_type
-      psgn_array(num_fields)=psgn
-   END SUBROUTINE load_array
-   
-   
-   SUBROUTINE mpp_lnk_2d_9( pt2dA, cd_typeA, psgnA, pt2dB, cd_typeB, psgnB, pt2dC, cd_typeC, psgnC   &
-      &                   , pt2dD, cd_typeD, psgnD, pt2dE, cd_typeE, psgnE, pt2dF, cd_typeF, psgnF   &
-      &                   , pt2dG, cd_typeG, psgnG, pt2dH, cd_typeH, psgnH, pt2dI, cd_typeI, psgnI, cd_mpp, pval)
-      !!---------------------------------------------------------------------
-      ! Second 2D array on which the boundary condition is applied
-      REAL(wp), DIMENSION(jpi,jpj), TARGET          , INTENT(inout) ::   pt2dA    
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dB , pt2dC , pt2dD , pt2dE
-      REAL(wp), DIMENSION(jpi,jpj), TARGET, OPTIONAL, INTENT(inout) ::   pt2dF , pt2dG , pt2dH , pt2dI 
-      ! define the nature of ptab array grid-points
-      CHARACTER(len=1)                              , INTENT(in   ) ::   cd_typeA
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeB , cd_typeC , cd_typeD , cd_typeE
-      CHARACTER(len=1)                    , OPTIONAL, INTENT(in   ) ::   cd_typeF , cd_typeG , cd_typeH , cd_typeI
-      ! =-1 the sign change across the north fold boundary
-      REAL(wp)                                      , INTENT(in   ) ::   psgnA    
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnB , psgnC , psgnD , psgnE
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   psgnF , psgnG , psgnH , psgnI   
-      CHARACTER(len=3)                    , OPTIONAL, INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)                            , OPTIONAL, INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      TYPE(arrayptr)   , DIMENSION(9) ::   pt2d_array 
-      CHARACTER(len=1) , DIMENSION(9) ::   type_array    ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)         , DIMENSION(9) ::   psgn_array    ! =-1 the sign change across the north fold boundary
-      INTEGER :: num_fields
-      !!---------------------------------------------------------------------
-
-      num_fields = 0
-
-      !! Load the first array
-      CALL load_array(pt2dA,cd_typeA,psgnA,pt2d_array, type_array, psgn_array,num_fields)
-
-      !! Look if more arrays are added
-      IF(PRESENT (psgnB) )CALL load_array(pt2dB,cd_typeB,psgnB,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnC) )CALL load_array(pt2dC,cd_typeC,psgnC,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnD) )CALL load_array(pt2dD,cd_typeD,psgnD,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnE) )CALL load_array(pt2dE,cd_typeE,psgnE,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnF) )CALL load_array(pt2dF,cd_typeF,psgnF,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnG) )CALL load_array(pt2dG,cd_typeG,psgnG,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnH) )CALL load_array(pt2dH,cd_typeH,psgnH,pt2d_array, type_array, psgn_array,num_fields)
-      IF(PRESENT (psgnI) )CALL load_array(pt2dI,cd_typeI,psgnI,pt2d_array, type_array, psgn_array,num_fields)
-      
-      CALL mpp_lnk_2d_multiple(pt2d_array,type_array,psgn_array,num_fields,cd_mpp,pval)
-   END SUBROUTINE mpp_lnk_2d_9
-
-
-   SUBROUTINE mpp_lnk_2d( pt2d, cd_type, psgn, cd_mpp, pval )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d     ! 2D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W and I points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      CHARACTER(len=3), OPTIONAL  , INTENT(in   ) ::   cd_mpp   ! fill the overlap area only
-      REAL(wp)        , OPTIONAL  , INTENT(in   ) ::   pval     ! background value (used at closed boundaries)
-      !!
-      INTEGER  ::   ji, jj, jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
-         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-
-      !
-      IF( PRESENT( pval ) ) THEN   ;   zland = pval      ! set land value
-      ELSE                         ;   zland = 0.e0      ! zero by default
-      ENDIF
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !
-      IF( PRESENT( cd_mpp ) ) THEN      ! only fill added line/raw with existing values
-         !
-         ! WARNING pt2d is defined only between nld and nle
-         DO jj = nlcj+1, jpj                 ! added line(s)   (inner only)
-            pt2d(nldi  :nlei  , jj          ) = pt2d(nldi:nlei,     nlej)
-            pt2d(1     :nldi-1, jj          ) = pt2d(nldi     ,     nlej)
-            pt2d(nlei+1:nlci  , jj          ) = pt2d(     nlei,     nlej)
-         END DO
-         DO ji = nlci+1, jpi                 ! added column(s) (full)
-            pt2d(ji           ,nldj  :nlej  ) = pt2d(     nlei,nldj:nlej)
-            pt2d(ji           ,1     :nldj-1) = pt2d(     nlei,nldj     )
-            pt2d(ji           ,nlej+1:jpj   ) = pt2d(     nlei,     nlej)
-         END DO
-         !
-      ELSE                              ! standard close or cyclic treatment
-         !
-         !                                   ! East-West boundaries
-         IF( nbondi == 2 .AND.   &                ! Cyclic east-west
-            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-            pt2d( 1 ,:) = pt2d(jpim1,:)                                    ! west
-            pt2d(jpi,:) = pt2d(  2  ,:)                                    ! east
-         ELSE                                     ! closed
-            IF( .NOT. cd_type == 'F' )   pt2d(     1       :jpreci,:) = zland    ! south except F-point
-                                         pt2d(nlci-jpreci+1:jpi   ,:) = zland    ! north
-         ENDIF
-         !                                   ! North-South boundaries (always closed)
-            IF( .NOT. cd_type == 'F' )   pt2d(:,     1       :jprecj) = zland    !south except F-point
-                                         pt2d(:,nlcj-jprecj+1:jpj   ) = zland    ! north
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt2ew(:,jl,1) = pt2d(jpreci+jl,:)
-            zt2we(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = zt2we(:,jl,2)
-            pt2d(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            pt2d(jl      ,:) = zt2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt2sn(:,jl,1) = pt2d(:,ijhom +jl)
-            zt2ns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = zt2sn(:,jl,2)
-            pt2d(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            pt2d(:,jl      ) = zt2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0 .AND. .NOT. PRESENT(cd_mpp) ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( pt2d, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( pt2d, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we )
-      !
-   END SUBROUTINE mpp_lnk_2d
-
-
-   SUBROUTINE mpp_lnk_3d_gather( ptab1, cd_type1, ptab2, cd_type2, psgn )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_3d_gather  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for two 3D arrays
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab1 and ptab2  with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab1     ! first and second 3D array on which
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab2     ! the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type1  ! nature of ptab1 and ptab2 arrays
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type2  ! i.e. grid-points = T , U , V , F or W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! =-1 the sign change across the north fold boundary
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ns, zt4sn   ! 2 x 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:,:), ALLOCATABLE ::   zt4ew, zt4we   ! 2 x 3d for east-west & west-east
-
-      !!----------------------------------------------------------------------
-      ALLOCATE( zt4ns(jpi,jprecj,jpk,2,2), zt4sn(jpi,jprecj,jpk,2,2) ,    &
-         &      zt4ew(jpj,jpreci,jpk,2,2), zt4we(jpj,jpreci,jpk,2,2) )
-
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         ptab1( 1 ,:,:) = ptab1(jpim1,:,:)
-         ptab1(jpi,:,:) = ptab1(  2  ,:,:)
-         ptab2( 1 ,:,:) = ptab2(jpim1,:,:)
-         ptab2(jpi,:,:) = ptab2(  2  ,:,:)
-      ELSE                                        !* closed
-         IF( .NOT. cd_type1 == 'F' )   ptab1(     1       :jpreci,:,:) = 0.e0    ! south except at F-point
-         IF( .NOT. cd_type2 == 'F' )   ptab2(     1       :jpreci,:,:) = 0.e0
-                                       ptab1(nlci-jpreci+1:jpi   ,:,:) = 0.e0    ! north
-                                       ptab2(nlci-jpreci+1:jpi   ,:,:) = 0.e0
-      ENDIF
-
-
-      !                                      ! North-South boundaries
-      IF( .NOT. cd_type1 == 'F' )   ptab1(:,     1       :jprecj,:) = 0.e0    ! south except at F-point
-      IF( .NOT. cd_type2 == 'F' )   ptab2(:,     1       :jprecj,:) = 0.e0
-                                    ptab1(:,nlcj-jprecj+1:jpj   ,:) = 0.e0    ! north
-                                    ptab2(:,nlcj-jprecj+1:jpj   ,:) = 0.e0
-
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt4ew(:,jl,:,1,1) = ptab1(jpreci+jl,:,:)
-            zt4we(:,jl,:,1,1) = ptab1(iihom +jl,:,:)
-            zt4ew(:,jl,:,2,1) = ptab2(jpreci+jl,:,:)
-            zt4we(:,jl,:,2,1) = ptab2(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk *2
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt4we(1,1,1,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, zt4ew(1,1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, zt4ew(1,1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, zt4we(1,1,1,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
-            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
-            ptab1(iihom+jl,:,:) = zt4ew(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
-            ptab2(iihom+jl,:,:) = zt4ew(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab1(jl      ,:,:) = zt4we(:,jl,:,1,2)
-            ptab2(jl      ,:,:) = zt4we(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj - nrecj
-         DO jl = 1, jprecj
-            zt4sn(:,jl,:,1,1) = ptab1(:,ijhom +jl,:)
-            zt4ns(:,jl,:,1,1) = ptab1(:,jprecj+jl,:)
-            zt4sn(:,jl,:,2,1) = ptab2(:,ijhom +jl,:)
-            zt4ns(:,jl,:,2,1) = ptab2(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk * 2
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt4sn(1,1,1,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, zt4ns(1,1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, zt4ns(1,1,1,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, zt4sn(1,1,1,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
-            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab1(:,jl      ,:) = zt4sn(:,jl,:,1,2)
-            ptab1(:,ijhom+jl,:) = zt4ns(:,jl,:,1,2)
-            ptab2(:,jl      ,:) = zt4sn(:,jl,:,2,2)
-            ptab2(:,ijhom+jl,:) = zt4ns(:,jl,:,2,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab1(:,jl,:) = zt4sn(:,jl,:,1,2)
-            ptab2(:,jl,:) = zt4sn(:,jl,:,2,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )
-            CALL lbc_nfd      ( ptab1, cd_type1, psgn )   ! only for northern procs.
-            CALL lbc_nfd      ( ptab2, cd_type2, psgn )
-         CASE DEFAULT
-            CALL mpp_lbc_north( ptab1, cd_type1, psgn )   ! for all northern procs.
-            CALL mpp_lbc_north (ptab2, cd_type2, psgn)
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt4ns, zt4sn, zt4ew, zt4we )
-      !
-   END SUBROUTINE mpp_lnk_3d_gather
-
-
-   SUBROUTINE mpp_lnk_2d_e( pt2d, cd_type, psgn, jpri, jprj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_e  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with halo)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                ! north boundary, =  1. otherwise
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
-
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! Order matters Here !!!!
-      !
-      !                                      !* North-South boundaries (always colsed)
-      IF( .NOT. cd_type == 'F' )   pt2d(:,  1-jprj   :  jprecj  ) = 0.e0    ! south except at F-point
-                                   pt2d(:,nlcj-jprecj+1:jpj+jprj) = 0.e0    ! north
-
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
-         !
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
-      ENDIF
-      !
-
-      ! north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_e( pt2d                    , cd_type, psgn               )
-         END SELECT
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
-         DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
-            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
-         DO jl = 1, iprecj
-            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-         END DO
-      END SELECT
-
-   END SUBROUTINE mpp_lnk_2d_e
-
-
-   SUBROUTINE mppsend( ktyp, pmess, kbytes, kdest, md_req )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsend  ***
-      !!
-      !! ** Purpose :   Send messag passing array
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
-      INTEGER , INTENT(in   ) ::   kbytes     ! size of the array pmess
-      INTEGER , INTENT(in   ) ::   kdest      ! receive process number
-      INTEGER , INTENT(in   ) ::   ktyp       ! tag of the message
-      INTEGER , INTENT(in   ) ::   md_req     ! argument for isend
-      !!
-      INTEGER ::   iflag
-      !!----------------------------------------------------------------------
-      !
-      SELECT CASE ( cn_mpi_send )
-      CASE ( 'S' )                ! Standard mpi send (blocking)
-         CALL mpi_send ( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
-      CASE ( 'B' )                ! Buffer mpi send (blocking)
-         CALL mpi_bsend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa        , iflag )
-      CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
-         ! be carefull, one more argument here : the mpi request identifier..
-         CALL mpi_isend( pmess, kbytes, mpi_double_precision, kdest , ktyp, mpi_comm_opa, md_req, iflag )
-      END SELECT
-      !
-   END SUBROUTINE mppsend
-
-
-   SUBROUTINE mpprecv( ktyp, pmess, kbytes, ksource )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpprecv  ***
-      !!
-      !! ** Purpose :   Receive messag passing array
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout) ::   pmess(*)   ! array of real
-      INTEGER , INTENT(in   ) ::   kbytes     ! suze of the array pmess
-      INTEGER , INTENT(in   ) ::   ktyp       ! Tag of the recevied message
-      INTEGER, OPTIONAL, INTENT(in) :: ksource    ! source process number
-      !!
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      INTEGER :: use_source
-      !!----------------------------------------------------------------------
-      !
-
-      ! If a specific process number has been passed to the receive call,
-      ! use that one. Default is to use mpi_any_source
-      use_source=mpi_any_source
-      if(present(ksource)) then
-         use_source=ksource
-      end if
-
-      CALL mpi_recv( pmess, kbytes, mpi_double_precision, use_source, ktyp, mpi_comm_opa, istatus, iflag )
-      !
-   END SUBROUTINE mpprecv
-
-
-   SUBROUTINE mppgather( ptab, kp, pio )
-      !!----------------------------------------------------------------------
-      !!                   ***  routine mppgather  ***
-      !!
-      !! ** Purpose :   Transfert between a local subdomain array and a work
-      !!     array which is distributed following the vertical level.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj),       INTENT(in   ) ::   ptab   ! subdomain input array
-      INTEGER ,                           INTENT(in   ) ::   kp     ! record length
-      REAL(wp), DIMENSION(jpi,jpj,jpnij), INTENT(  out) ::   pio    ! subdomain input array
-      !!
-      INTEGER :: itaille, ierror   ! temporary integer
-      !!---------------------------------------------------------------------
-      !
-      itaille = jpi * jpj
-      CALL mpi_gather( ptab, itaille, mpi_double_precision, pio, itaille     ,   &
-         &                            mpi_double_precision, kp , mpi_comm_opa, ierror )
-      !
-   END SUBROUTINE mppgather
-
-
-   SUBROUTINE mppscatter( pio, kp, ptab )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppscatter  ***
-      !!
-      !! ** Purpose :   Transfert between awork array which is distributed
-      !!      following the vertical level and the local subdomain array.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpnij)  ::  pio        ! output array
-      INTEGER                             ::   kp        ! Tag (not used with MPI
-      REAL(wp), DIMENSION(jpi,jpj)        ::  ptab       ! subdomain array input
-      !!
-      INTEGER :: itaille, ierror   ! temporary integer
-      !!---------------------------------------------------------------------
-      !
-      itaille=jpi*jpj
-      !
-      CALL mpi_scatter( pio, itaille, mpi_double_precision, ptab, itaille     ,   &
-         &                            mpi_double_precision, kp  , mpi_comm_opa, ierror )
-      !
-   END SUBROUTINE mppscatter
-
-
-   SUBROUTINE mppmax_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_a_int  ***
-      !!
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim   ! size of array
-      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab   ! input array
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom   !
-      !!
-      INTEGER :: ierror, localcomm   ! temporary integer
-      INTEGER, DIMENSION(kdim) ::   iwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_max, localcomm, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppmax_a_int
-
-
-   SUBROUTINE mppmax_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_int  ***
-      !!
-      !! ** Purpose :   Find maximum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout)           ::   ktab      ! ???
-      INTEGER, INTENT(in   ), OPTIONAL ::   kcom      ! ???
-      !!
-      INTEGER ::   ierror, iwork, localcomm   ! temporary integer
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_max, localcomm, ierror)
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppmax_int
-
-
-   SUBROUTINE mppmin_a_int( ktab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_a_int  ***
-      !!
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT( in  )                  ::   kdim        ! size of array
-      INTEGER , INTENT(inout), DIMENSION(kdim) ::   ktab        ! input array
-      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
-      !!
-      INTEGER ::   ierror, localcomm   ! temporary integer
-      INTEGER, DIMENSION(kdim) ::   iwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_min, localcomm, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppmin_a_int
-
-
-   SUBROUTINE mppmin_int( ktab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_int  ***
-      !!
-      !! ** Purpose :   Find minimum value in an integer layout array
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout) ::   ktab      ! ???
-      INTEGER , INTENT( in  ), OPTIONAL        ::   kcom        ! input array
-      !!
-      INTEGER ::  ierror, iwork, localcomm
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-     CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_min, localcomm, ierror )
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppmin_int
-
-
-   SUBROUTINE mppsum_a_int( ktab, kdim )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_int  ***
-      !!
-      !! ** Purpose :   Global integer sum, 1D array case
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in   )                   ::   kdim      ! ???
-      INTEGER, INTENT(inout), DIMENSION (kdim) ::   ktab      ! ???
-      !!
-      INTEGER :: ierror
-      INTEGER, DIMENSION (kdim) ::  iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, kdim, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab(:) = iwork(:)
-      !
-   END SUBROUTINE mppsum_a_int
-
-
-   SUBROUTINE mppsum_int( ktab )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppsum_int  ***
-      !!
-      !! ** Purpose :   Global integer sum
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(inout) ::   ktab
-      !!
-      INTEGER :: ierror, iwork
-      !!----------------------------------------------------------------------
-      !
-      CALL mpi_allreduce( ktab, iwork, 1, mpi_integer, mpi_sum, mpi_comm_opa, ierror )
-      !
-      ktab = iwork
-      !
-   END SUBROUTINE mppsum_int
-
-
-   SUBROUTINE mppmax_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmax_a_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim
-      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
-      INTEGER :: ierror, localcomm
-      REAL(wp), DIMENSION(kdim) ::  zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppmax_a_real
-
-
-   SUBROUTINE mppmax_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! ???
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmax_real
-
-   SUBROUTINE mppmax_real_multiple( ptab, NUM , kcom  )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmax_real  ***
-      !!
-      !! ** Purpose :   Maximum
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:) ,  INTENT(inout)           ::   ptab   ! ???
-      INTEGER , INTENT(in   )           ::   NUM
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom   ! ???
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) , POINTER , DIMENSION(:) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      CALL wrk_alloc(NUM , zwork)
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, NUM, mpi_double_precision, mpi_max, localcomm, ierror )
-      ptab = zwork
-      CALL wrk_dealloc(NUM , zwork)
-      !
-   END SUBROUTINE mppmax_real_multiple
-
-
-   SUBROUTINE mppmin_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                 ***  routine mppmin_a_real  ***
-      !!
-      !! ** Purpose :   Minimum of REAL, array case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT(in   )                  ::   kdim
-      REAL(wp), INTENT(inout), DIMENSION(kdim) ::   ptab
-      INTEGER , INTENT(in   ), OPTIONAL        ::   kcom
-      !!
-      INTEGER :: ierror, localcomm
-      REAL(wp), DIMENSION(kdim) ::   zwork
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_min, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppmin_a_real
-
-
-   SUBROUTINE mppmin_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppmin_real  ***
-      !!
-      !! ** Purpose :   minimum of REAL, scalar case
-      !!
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab        !
-      INTEGER , INTENT(in   ), OPTIONAL :: kcom
-      !!
-      INTEGER  ::   ierror
-      REAL(wp) ::   zwork
-      INTEGER :: localcomm
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_min, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppmin_real
-
-
-   SUBROUTINE mppsum_a_real( ptab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_real  ***
-      !!
-      !! ** Purpose :   global sum, REAL ARRAY argument case
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                     ::   kdim      ! size of ptab
-      REAL(wp), DIMENSION(kdim), INTENT( inout ) ::   ptab      ! input array
-      INTEGER , INTENT( in ), OPTIONAL           :: kcom
-      !!
-      INTEGER                   ::   ierror    ! temporary integer
-      INTEGER                   ::   localcomm
-      REAL(wp), DIMENSION(kdim) ::   zwork     ! temporary workspace
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) )   localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, kdim, mpi_double_precision, mpi_sum, localcomm, ierror )
-      ptab(:) = zwork(:)
-      !
-   END SUBROUTINE mppsum_a_real
-
-
-   SUBROUTINE mppsum_real( ptab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_real  ***
-      !!
-      !! ** Purpose :   global sum, SCALAR argument case
-      !!
-      !!-----------------------------------------------------------------------
-      REAL(wp), INTENT(inout)           ::   ptab   ! input scalar
-      INTEGER , INTENT(in   ), OPTIONAL ::   kcom
-      !!
-      INTEGER  ::   ierror, localcomm
-      REAL(wp) ::   zwork
-      !!-----------------------------------------------------------------------
-      !
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-      !
-      CALL mpi_allreduce( ptab, zwork, 1, mpi_double_precision, mpi_sum, localcomm, ierror )
-      ptab = zwork
-      !
-   END SUBROUTINE mppsum_real
-
-   SUBROUTINE mppsum_realdd( ytab, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_realdd ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                SCALAR argument case for double-double precision
-      !!
-      !!-----------------------------------------------------------------------
-      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER  ::    ierror
-      INTEGER  ::   localcomm
-      COMPLEX(wp) :: zwork
-
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
-      ! reduce local sums into global sum
-      CALL MPI_ALLREDUCE (ytab, zwork, 1, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
-      ytab = zwork
-
-   END SUBROUTINE mppsum_realdd
-
-
-   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsum_a_realdd  ***
-      !!
-      !! ** Purpose :   global sum in Massively Parallel Processing
-      !!                COMPLEX ARRAY case for double-double precision
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
-      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-
-      !! * Local variables   (MPI version)
-      INTEGER                      :: ierror    ! temporary integer
-      INTEGER                      ::   localcomm
-      COMPLEX(wp), DIMENSION(kdim) :: zwork     ! temporary workspace
-
-      localcomm = mpi_comm_opa
-      IF( PRESENT(kcom) ) localcomm = kcom
-
-      CALL MPI_ALLREDUCE (ytab, zwork, kdim, MPI_DOUBLE_COMPLEX, &
-                       MPI_SUMDD,localcomm,ierror)
-      ytab(:) = zwork(:)
-
-   END SUBROUTINE mppsum_a_realdd
-
-   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki,kj )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_minloc  ***
-      !!
-      !! ** Purpose :   Compute the global minimum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab    ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask   ! Local mask
-      REAL(wp)                     , INTENT(  out) ::   pmin    ! Global minimum of ptab
-      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of minimum in global frame
-      !!
-      INTEGER , DIMENSION(2)   ::   ilocs
-      INTEGER :: ierror
-      REAL(wp) ::   zmin   ! local minimum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmin  = MINVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      !
-      zain(1,:)=zmin
-      zain(2,:)=ki+10000.*kj
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
-      !
-      pmin = zaout(1,1)
-      kj = INT(zaout(2,1)/10000.)
-      ki = INT(zaout(2,1) - 10000.*kj )
-      !
-   END SUBROUTINE mpp_minloc2d
-
-
-   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj ,kk)
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_minloc  ***
-      !!
-      !! ** Purpose :   Compute the global minimum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmin         ! Global minimum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of minimum in global frame
-      !!
-      INTEGER  ::   ierror
-      REAL(wp) ::   zmin     ! local minimum
-      INTEGER , DIMENSION(3)   ::   ilocs
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmin  = MINVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MINLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      kk = ilocs(3)
-      !
-      zain(1,:)=zmin
-      zain(2,:)=ki+10000.*kj+100000000.*kk
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MINLOC,MPI_COMM_OPA,ierror)
-      !
-      pmin = zaout(1,1)
-      kk   = INT( zaout(2,1) / 100000000. )
-      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
-      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
-      !
-   END SUBROUTINE mpp_minloc3d
-
-
-   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_maxloc  ***
-      !!
-      !! ** Purpose :   Compute the global maximum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method  :   Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   ptab     ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj), INTENT(in   ) ::   pmask    ! Local mask
-      REAL(wp)                     , INTENT(  out) ::   pmax     ! Global maximum of ptab
-      INTEGER                      , INTENT(  out) ::   ki, kj   ! index of maximum in global frame
-      !!
-      INTEGER  :: ierror
-      INTEGER, DIMENSION (2)   ::   ilocs
-      REAL(wp) :: zmax   ! local maximum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      !!-----------------------------------------------------------------------
-      !
-      zmax  = MAXVAL( ptab(:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      !
-      zain(1,:) = zmax
-      zain(2,:) = ki + 10000. * kj
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
-      !
-      pmax = zaout(1,1)
-      kj   = INT( zaout(2,1) / 10000.     )
-      ki   = INT( zaout(2,1) - 10000.* kj )
-      !
-   END SUBROUTINE mpp_maxloc2d
-
-
-   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
-      !!------------------------------------------------------------------------
-      !!             ***  routine mpp_maxloc  ***
-      !!
-      !! ** Purpose :  Compute the global maximum of an array ptab
-      !!              and also give its global position
-      !!
-      !! ** Method : Use MPI_ALLREDUCE with MPI_MINLOC
-      !!
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   ptab         ! Local 2D array
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pmask        ! Local mask
-      REAL(wp)                         , INTENT(  out) ::   pmax         ! Global maximum of ptab
-      INTEGER                          , INTENT(  out) ::   ki, kj, kk   ! index of maximum in global frame
-      !!
-      REAL(wp) :: zmax   ! local maximum
-      REAL(wp), DIMENSION(2,1) ::   zain, zaout
-      INTEGER , DIMENSION(3)   ::   ilocs
-      INTEGER :: ierror
-      !!-----------------------------------------------------------------------
-      !
-      zmax  = MAXVAL( ptab(:,:,:) , mask= pmask == 1.e0 )
-      ilocs = MAXLOC( ptab(:,:,:) , mask= pmask == 1.e0 )
-      !
-      ki = ilocs(1) + nimpp - 1
-      kj = ilocs(2) + njmpp - 1
-      kk = ilocs(3)
-      !
-      zain(1,:)=zmax
-      zain(2,:)=ki+10000.*kj+100000000.*kk
-      !
-      CALL MPI_ALLREDUCE( zain,zaout, 1, MPI_2DOUBLE_PRECISION,MPI_MAXLOC,MPI_COMM_OPA,ierror)
-      !
-      pmax = zaout(1,1)
-      kk   = INT( zaout(2,1) / 100000000. )
-      kj   = INT( zaout(2,1) - kk * 100000000. ) / 10000
-      ki   = INT( zaout(2,1) - kk * 100000000. -kj * 10000. )
-      !
-   END SUBROUTINE mpp_maxloc3d
-
-
-   SUBROUTINE mppsync()
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppsync  ***
-      !!
-      !! ** Purpose :   Massively parallel processors, synchroneous
-      !!
-      !!-----------------------------------------------------------------------
-      INTEGER :: ierror
-      !!-----------------------------------------------------------------------
-      !
-      CALL mpi_barrier( mpi_comm_opa, ierror )
-      !
-   END SUBROUTINE mppsync
-
-
-   SUBROUTINE mppstop
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mppstop  ***
-      !!
-      !! ** purpose :   Stop massively parallel processors method
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ::   info
-      !!----------------------------------------------------------------------
-      !
-      CALL mppsync
-      CALL mpi_finalize( info )
-      !
-   END SUBROUTINE mppstop
-
-
-   SUBROUTINE mpp_comm_free( kcom )
-      !!----------------------------------------------------------------------
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kcom
-      !!
-      INTEGER :: ierr
-      !!----------------------------------------------------------------------
-      !
-      CALL MPI_COMM_FREE(kcom, ierr)
-      !
-   END SUBROUTINE mpp_comm_free
-
-
-   SUBROUTINE mpp_ini_ice( pindic, kumout )
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_ice  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for ice areas
-      !!      condition together with global variables needed in the ddmpp folding
-      !!
-      !! ** Method  : - Look for ice processors in ice routines
-      !!              - Put their number in nrank_ice
-      !!              - Create groups for the world processors and the ice processors
-      !!              - Create a communicator for ice processors
-      !!
-      !! ** output
-      !!      njmppmax = njmpp for northern procs
-      !!      ndim_rank_ice = number of processors with ice
-      !!      nrank_ice (ndim_rank_ice) = ice processors
-      !!      ngrp_iworld = group ID for the world processors
-      !!      ngrp_ice = group ID for the ice processors
-      !!      ncomm_ice = communicator for the ice procs.
-      !!      n_ice_root = number (in the world) of proc 0 in the ice comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   pindic
-      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical unit
-      !!
-      INTEGER :: jjproc
-      INTEGER :: ii, ierr
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kice
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   zwork
-      !!----------------------------------------------------------------------
-      !
-      ! Since this is just an init routine and these arrays are of length jpnij
-      ! then don't use wrk_nemo module - just allocate and deallocate.
-      ALLOCATE( kice(jpnij), zwork(jpnij), STAT=ierr )
-      IF( ierr /= 0 ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mpp_ini_ice : failed to allocate 2, 1D arrays (jpnij in length)'
-         CALL mppstop
-      ENDIF
-
-      ! Look for how many procs with sea-ice
-      !
-      kice = 0
-      DO jjproc = 1, jpnij
-         IF( jjproc == narea .AND. pindic .GT. 0 )   kice(jjproc) = 1
-      END DO
-      !
-      zwork = 0
-      CALL MPI_ALLREDUCE( kice, zwork, jpnij, mpi_integer, mpi_sum, mpi_comm_opa, ierr )
-      ndim_rank_ice = SUM( zwork )
-
-      ! Allocate the right size to nrank_north
-      IF( ALLOCATED ( nrank_ice ) )   DEALLOCATE( nrank_ice )
-      ALLOCATE( nrank_ice(ndim_rank_ice) )
-      !
-      ii = 0
-      nrank_ice = 0
-      DO jjproc = 1, jpnij
-         IF( zwork(jjproc) == 1) THEN
-            ii = ii + 1
-            nrank_ice(ii) = jjproc -1
-         ENDIF
-      END DO
-
-      ! Create the world group
-      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_iworld, ierr )
-
-      ! Create the ice group from the world group
-      CALL MPI_GROUP_INCL( ngrp_iworld, ndim_rank_ice, nrank_ice, ngrp_ice, ierr )
-
-      ! Create the ice communicator , ie the pool of procs with sea-ice
-      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_ice, ncomm_ice, ierr )
-
-      ! Find proc number in the world of proc 0 in the north
-      ! The following line seems to be useless, we just comment & keep it as reminder
-      ! CALL MPI_GROUP_TRANSLATE_RANKS(ngrp_ice,1,0,ngrp_iworld,n_ice_root,ierr)
-      !
-      CALL MPI_GROUP_FREE(ngrp_ice, ierr)
-      CALL MPI_GROUP_FREE(ngrp_iworld, ierr)
-
-      DEALLOCATE(kice, zwork)
-      !
-   END SUBROUTINE mpp_ini_ice
-
-
-   SUBROUTINE mpp_ini_znl( kumout )
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_znl  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for computing zonal sum
-      !!
-      !! ** Method  : - Look for processors in the same row
-      !!              - Put their number in nrank_znl
-      !!              - Create group for the znl processors
-      !!              - Create a communicator for znl processors
-      !!              - Determine if processor should write znl files
-      !!
-      !! ** output
-      !!      ndim_rank_znl = number of processors on the same row
-      !!      ngrp_znl = group ID for the znl processors
-      !!      ncomm_znl = communicator for the ice procs.
-      !!      n_znl_root = number (in the world) of proc 0 in the ice comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER, INTENT(in) ::   kumout   ! ocean.output logical units
-      !
-      INTEGER :: jproc      ! dummy loop integer
-      INTEGER :: ierr, ii   ! local integer
-      INTEGER, ALLOCATABLE, DIMENSION(:) ::   kwork
-      !!----------------------------------------------------------------------
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_world     : ', ngrp_world
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_world : ', mpi_comm_world
-      !-$$     WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - mpi_comm_opa   : ', mpi_comm_opa
-      !
-      ALLOCATE( kwork(jpnij), STAT=ierr )
-      IF( ierr /= 0 ) THEN
-         WRITE(kumout, cform_err)
-         WRITE(kumout,*) 'mpp_ini_znl : failed to allocate 1D array of length jpnij'
-         CALL mppstop
-      ENDIF
-
-      IF( jpnj == 1 ) THEN
-         ngrp_znl  = ngrp_world
-         ncomm_znl = mpi_comm_opa
-      ELSE
-         !
-         CALL MPI_ALLGATHER ( njmpp, 1, mpi_integer, kwork, 1, mpi_integer, mpi_comm_opa, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - kwork pour njmpp : ', kwork
-         !-$$        CALL flush(numout)
-         !
-         ! Count number of processors on the same row
-         ndim_rank_znl = 0
-         DO jproc=1,jpnij
-            IF ( kwork(jproc) == njmpp ) THEN
-               ndim_rank_znl = ndim_rank_znl + 1
-            ENDIF
-         END DO
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ndim_rank_znl : ', ndim_rank_znl
-         !-$$        CALL flush(numout)
-         ! Allocate the right size to nrank_znl
-         IF (ALLOCATED (nrank_znl)) DEALLOCATE(nrank_znl)
-         ALLOCATE(nrank_znl(ndim_rank_znl))
-         ii = 0
-         nrank_znl (:) = 0
-         DO jproc=1,jpnij
-            IF ( kwork(jproc) == njmpp) THEN
-               ii = ii + 1
-               nrank_znl(ii) = jproc -1
-            ENDIF
-         END DO
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - nrank_znl : ', nrank_znl
-         !-$$        CALL flush(numout)
-
-         ! Create the opa group
-         CALL MPI_COMM_GROUP(mpi_comm_opa,ngrp_opa,ierr)
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_opa : ', ngrp_opa
-         !-$$        CALL flush(numout)
-
-         ! Create the znl group from the opa group
-         CALL MPI_GROUP_INCL  ( ngrp_opa, ndim_rank_znl, nrank_znl, ngrp_znl, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ngrp_znl ', ngrp_znl
-         !-$$        CALL flush(numout)
-
-         ! Create the znl communicator from the opa communicator, ie the pool of procs in the same row
-         CALL MPI_COMM_CREATE ( mpi_comm_opa, ngrp_znl, ncomm_znl, ierr )
-         !-$$        WRITE (numout,*) 'mpp_ini_znl ', nproc, ' - ncomm_znl ', ncomm_znl
-         !-$$        CALL flush(numout)
-         !
-      END IF
-
-      ! Determines if processor if the first (starting from i=1) on the row
-      IF ( jpni == 1 ) THEN
-         l_znl_root = .TRUE.
-      ELSE
-         l_znl_root = .FALSE.
-         kwork (1) = nimpp
-         CALL mpp_min ( kwork(1), kcom = ncomm_znl)
-         IF ( nimpp == kwork(1)) l_znl_root = .TRUE.
-      END IF
-
-      DEALLOCATE(kwork)
-
-   END SUBROUTINE mpp_ini_znl
-
-
-   SUBROUTINE mpp_ini_north
-      !!----------------------------------------------------------------------
-      !!               ***  routine mpp_ini_north  ***
-      !!
-      !! ** Purpose :   Initialize special communicator for north folding
-      !!      condition together with global variables needed in the mpp folding
-      !!
-      !! ** Method  : - Look for northern processors
-      !!              - Put their number in nrank_north
-      !!              - Create groups for the world processors and the north processors
-      !!              - Create a communicator for northern processors
-      !!
-      !! ** output
-      !!      njmppmax = njmpp for northern procs
-      !!      ndim_rank_north = number of processors in the northern line
-      !!      nrank_north (ndim_rank_north) = number  of the northern procs.
-      !!      ngrp_world = group ID for the world processors
-      !!      ngrp_north = group ID for the northern processors
-      !!      ncomm_north = communicator for the northern procs.
-      !!      north_root = number (in the world) of proc 0 in the northern comm.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ::   ierr
-      INTEGER ::   jjproc
-      INTEGER ::   ii, ji
-      !!----------------------------------------------------------------------
-      !
-      njmppmax = MAXVAL( njmppt )
-      !
-      ! Look for how many procs on the northern boundary
-      ndim_rank_north = 0
-      DO jjproc = 1, jpnij
-         IF( njmppt(jjproc) == njmppmax )   ndim_rank_north = ndim_rank_north + 1
-      END DO
-      !
-      ! Allocate the right size to nrank_north
-      IF (ALLOCATED (nrank_north)) DEALLOCATE(nrank_north)
-      ALLOCATE( nrank_north(ndim_rank_north) )
-
-      ! Fill the nrank_north array with proc. number of northern procs.
-      ! Note : the rank start at 0 in MPI
-      ii = 0
-      DO ji = 1, jpnij
-         IF ( njmppt(ji) == njmppmax   ) THEN
-            ii=ii+1
-            nrank_north(ii)=ji-1
-         END IF
-      END DO
-      !
-      ! create the world group
-      CALL MPI_COMM_GROUP( mpi_comm_opa, ngrp_world, ierr )
-      !
-      ! Create the North group from the world group
-      CALL MPI_GROUP_INCL( ngrp_world, ndim_rank_north, nrank_north, ngrp_north, ierr )
-      !
-      ! Create the North communicator , ie the pool of procs in the north group
-      CALL MPI_COMM_CREATE( mpi_comm_opa, ngrp_north, ncomm_north, ierr )
-      !
-   END SUBROUTINE mpp_ini_north
-
-
-   SUBROUTINE mpp_lbc_north_3d( pt3d, cd_type, psgn )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_3d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   pt3d      ! 3D array on which the b.c. is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type   ! nature of pt3d grid-points
-      !                                                              !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                        , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr, jk
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)          ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                                ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)    ::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
-
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4,jpk) , znorthloc(jpi,4,jpk), zfoldwk(jpi,4,jpk), znorthgloio(jpi,4,jpk,jpni) )
-      ALLOCATE( ztabl(jpi,4,jpk), ztabr(jpi*jpmaxngh, 4, jpk) ) 
-
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      znorthloc(:,:,:) = 0
-      DO jk = 1, jpk
-         DO jj = nlcj - ijpj +1, nlcj          ! put in xnorthloc the last 4 jlines of pt3d
-            ij = jj - nlcj + ijpj
-            znorthloc(:,ij,jk) = pt3d(:,jj,jk)
-         END DO
-      END DO
-      !
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * jpk * ijpj
-
-      IF ( l_north_nogather ) THEN
-         !
-        ztabr(:,:,:) = 0
-        ztabl(:,:,:) = 0
-
-        DO jk = 1, jpk
-           DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-              ij = jj - nlcj + ijpj
-              DO ji = nfsloop, nfeloop
-                 ztabl(ji,ij,jk) = pt3d(ji,jj,jk)
-              END DO
-           END DO
-        END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-              CALL mppsend( 5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr) )
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille, iproc)
-              DO jk = 1, jpk
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)
-                    END DO
-                 END DO
-              END DO
-           ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jk = 1, jpk
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = pt3d(ji,nlcj-ijpj+jj,jk)
-                    END DO
-                 END DO
-              END DO
-           ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF    
-            END DO
-         ENDIF
-         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
-         DO jk = 1, jpk
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
-               ij = jj - nlcj + ijpj
-               DO ji= 1, nlci
-                  pt3d(ji,jj,jk) = ztabl(ji,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-
-      ELSE
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,                &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:,:) = 0.e0
-         DO jr = 1, ndim_rank_north         ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi  = nldit (iproc)
-            ilei  = nleit (iproc)
-            iilb  = nimppt(iproc)
-            DO jk = 1, jpk
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                    ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
-                  END DO
-               END DO
-            END DO
-         END DO
-         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jk = 1, jpk
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt3d
-               ij = jj - nlcj + ijpj
-               DO ji= 1, nlci
-                  pt3d(ji,jj,jk) = ztab(ji+nimpp-1,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-      ENDIF
-      !
-      ! The ztab array has been either:
-      !  a. Fully populated by the mpi_allgather operation or
-      !  b. Had the active points for this domain and northern neighbours populated
-      !     by peer to peer exchanges
-      ! Either way the array may be folded by lbc_nfd and the result for the span of
-      ! this domain will be identical.
-      !
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr ) 
-      !
-   END SUBROUTINE mpp_lbc_north_3d
-
-
-   SUBROUTINE mpp_lbc_north_2d( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 (for 2d array )
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   pt2d      ! 2D array on which the b.c. is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
-      !                                                          !   = T ,  U , V , F or W  gridpoints
-      REAL(wp)                    , INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk      
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE   :: ztabl, ztabr
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4), znorthloc(jpi,4), zfoldwk(jpi,4), znorthgloio(jpi,4,jpni) )
-      ALLOCATE( ztabl(jpi,4), ztabr(jpi*jpmaxngh, 4) ) 
-      !
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d
-         ij = jj - nlcj + ijpj
-         znorthloc(:,ij) = pt2d(:,jj)
-      END DO
-
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * ijpj
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         ztabr(:,:) = 0
-         ztabl(:,:) = 0
-
-         DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-            ij = jj - nlcj + ijpj
-              DO ji = nfsloop, nfeloop
-               ztabl(ji,ij) = pt2d(ji,jj)
-            END DO
-         END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-               CALL mppsend(5, znorthloc, itaille, nfipproc(isendto(jr),jpnj), ml_req_nf(jr))
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille, iproc)
-              DO jj = 1, ijpj
-                 DO ji = ildi, ilei
-                    ztabr(iilb+ji,jj) = zfoldwk(ji,jj)
-                 END DO
-              END DO
-            ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jj = 1, ijpj
-                 DO ji = ildi, ilei
-                    ztabr(iilb+ji,jj) = pt2d(ji,nlcj-ijpj+jj)
-                 END DO
-              END DO
-            ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF
-            END DO
-         ENDIF
-         CALL mpp_lbc_nfd( ztabl, ztabr, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               pt2d(ji,jj) = ztabl(ji,ij)
-            END DO
-         END DO
-         !
-      ELSE
-         CALL MPI_ALLGATHER( znorthloc  , itaille, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio, itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:) = 0.e0
-         DO jr = 1, ndim_rank_north            ! recover the global north array
-            iproc = nrank_north(jr) + 1
-            ildi = nldit (iproc)
-            ilei = nleit (iproc)
-            iilb = nimppt(iproc)
-            DO jj = 1, ijpj
-               DO ji = ildi, ilei
-                  ztab(ji+iilb-1,jj) = znorthgloio(ji,jj,jr)
-               END DO
-            END DO
-         END DO
-         CALL lbc_nfd( ztab, cd_type, psgn )   ! North fold boundary condition
-         !
-         DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-            ij = jj - nlcj + ijpj
-            DO ji = 1, nlci
-               pt2d(ji,jj) = ztab(ji+nimpp-1,ij)
-            END DO
-         END DO
-         !
-      ENDIF
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr ) 
-      !
-   END SUBROUTINE mpp_lbc_north_2d
-
-   SUBROUTINE mpp_lbc_north_2d_multiple( pt2d_array, cd_type, psgn, num_fields)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1
-      !!              (for multiple 2d arrays )
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4 northern lines of the global domain on 1 processor
-      !!              and apply lbc north-fold on this sub array. Then we
-      !!              scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER ,  INTENT (in   ) ::   num_fields  ! number of variables contained in pt2d
-      TYPE( arrayptr ), DIMENSION(:) :: pt2d_array
-      CHARACTER(len=1), DIMENSION(:), INTENT(in   ) ::   cd_type   ! nature of pt2d grid-points
-      !                                                          !   = T ,  U , V , F or W  gridpoints
-      REAL(wp), DIMENSION(:), INTENT(in   ) ::   psgn      ! = -1. the sign change across the north fold 
-      !!                                                             ! =  1. , the sign is kept
-      INTEGER ::   ji, jj, jr, jk
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ijpjm1, ij, iproc
-      INTEGER, DIMENSION (jpmaxngh)      ::   ml_req_nf          !for mpi_isend when avoiding mpi_allgather
-      INTEGER                            ::   ml_err             ! for mpi_isend when avoiding mpi_allgather
-      INTEGER, DIMENSION(MPI_STATUS_SIZE)::   ml_stat            ! for mpi_isend when avoiding mpi_allgather
-      !                                                              ! Workspace for message transfers avoiding mpi_allgather
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztab
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: znorthloc, zfoldwk
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   :: znorthgloio
-      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE   :: ztabl, ztabr
-      INTEGER :: istatus(mpi_status_size)
-      INTEGER :: iflag
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab(jpiglo,4,num_fields), znorthloc(jpi,4,num_fields), zfoldwk(jpi,4,num_fields),   & 
-            &   znorthgloio(jpi,4,num_fields,jpni) )   ! expanded to 3 dimensions
-      ALLOCATE( ztabl(jpi,4,num_fields), ztabr(jpi*jpmaxngh, 4,num_fields) )
-      !
-      ijpj   = 4
-      ijpjm1 = 3
-      !
-      
-      DO jk = 1, num_fields
-         DO jj = nlcj-ijpj+1, nlcj             ! put in znorthloc the last 4 jlines of pt2d (for every variable)
-            ij = jj - nlcj + ijpj
-            znorthloc(:,ij,jk) = pt2d_array(jk)%pt2d(:,jj)
-         END DO
-      END DO
-      !                                     ! Build in procs of ncomm_north the znorthgloio
-      itaille = jpi * ijpj
-                                                                  
-      IF ( l_north_nogather ) THEN
-         !
-         ! Avoid the use of mpi_allgather by exchanging only with the processes already identified 
-         ! (in nemo_northcomms) as being  involved in this process' northern boundary exchange
-         !
-         ztabr(:,:,:) = 0
-         ztabl(:,:,:) = 0
-
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj          ! First put local values into the global array
-               ij = jj - nlcj + ijpj
-               DO ji = nfsloop, nfeloop
-                  ztabl(ji,ij,jk) = pt2d_array(jk)%pt2d(ji,jj)
-               END DO
-            END DO
-         END DO
-
-         DO jr = 1,nsndto
-            IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-               CALL mppsend(5, znorthloc, itaille*num_fields, nfipproc(isendto(jr),jpnj), ml_req_nf(jr)) ! Buffer expanded "num_fields" times
-            ENDIF
-         END DO
-         DO jr = 1,nsndto
-            iproc = nfipproc(isendto(jr),jpnj)
-            IF(iproc .ne. -1) THEN
-               ilei = nleit (iproc+1)
-               ildi = nldit (iproc+1)
-               iilb = nfiimpp(isendto(jr),jpnj) - nfiimpp(isendto(1),jpnj)
-            ENDIF
-            IF((iproc .ne. (narea-1)) .and. (iproc .ne. -1)) THEN
-              CALL mpprecv(5, zfoldwk, itaille*num_fields, iproc) ! Buffer expanded "num_fields" times
-              DO jk = 1 , num_fields
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                       ztabr(iilb+ji,jj,jk) = zfoldwk(ji,jj,jk)       ! Modified to 3D
-                    END DO
-                 END DO
-              END DO
-            ELSE IF (iproc .eq. (narea-1)) THEN
-              DO jk = 1, num_fields
-                 DO jj = 1, ijpj
-                    DO ji = ildi, ilei
-                          ztabr(iilb+ji,jj,jk) = pt2d_array(jk)%pt2d(ji,nlcj-ijpj+jj)       ! Modified to 3D
-                    END DO
-                 END DO
-              END DO
-            ENDIF
-         END DO
-         IF (l_isend) THEN
-            DO jr = 1,nsndto
-               IF ((nfipproc(isendto(jr),jpnj) .ne. (narea-1)) .and. (nfipproc(isendto(jr),jpnj) .ne. -1)) THEN
-                  CALL mpi_wait(ml_req_nf(jr), ml_stat, ml_err)
-               ENDIF
-            END DO
-         ENDIF
-         !
-         DO ji = 1, num_fields     ! Loop to manage 3D variables
-            CALL mpp_lbc_nfd( ztabl(:,:,ji), ztabr(:,:,ji), cd_type(ji), psgn(ji) )  ! North fold boundary condition
-         END DO
-         !
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-               ij = jj - nlcj + ijpj
-               DO ji = 1, nlci
-                  pt2d_array(jk)%pt2d(ji,jj) = ztabl(ji,ij,jk)       ! Modified to 3D
-               END DO
-            END DO
-         END DO
-         
-         !
-      ELSE
-         !
-         CALL MPI_ALLGATHER( znorthloc  , itaille*num_fields, MPI_DOUBLE_PRECISION,        &
-            &                znorthgloio, itaille*num_fields, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-         !
-         ztab(:,:,:) = 0.e0
-         DO jk = 1, num_fields
-            DO jr = 1, ndim_rank_north            ! recover the global north array
-               iproc = nrank_north(jr) + 1
-               ildi = nldit (iproc)
-               ilei = nleit (iproc)
-               iilb = nimppt(iproc)
-               DO jj = 1, ijpj
-                  DO ji = ildi, ilei
-                     ztab(ji+iilb-1,jj,jk) = znorthgloio(ji,jj,jk,jr)
-                  END DO
-               END DO
-            END DO
-         END DO
-         
-         DO ji = 1, num_fields
-            CALL lbc_nfd( ztab(:,:,ji), cd_type(ji), psgn(ji) )   ! North fold boundary condition
-         END DO
-         !
-         DO jk = 1, num_fields
-            DO jj = nlcj-ijpj+1, nlcj             ! Scatter back to pt2d
-               ij = jj - nlcj + ijpj
-               DO ji = 1, nlci
-                  pt2d_array(jk)%pt2d(ji,jj) = ztab(ji+nimpp-1,ij,jk)
-               END DO
-            END DO
-         END DO
-         !
-         !
-      ENDIF
-      DEALLOCATE( ztab, znorthloc, zfoldwk, znorthgloio )
-      DEALLOCATE( ztabl, ztabr )
-      !
-   END SUBROUTINE mpp_lbc_north_2d_multiple
-
-   SUBROUTINE mpp_lbc_north_e( pt2d, cd_type, psgn)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_2d  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
-      !!              processor and apply lbc north-fold on this sub array.
-      !!              Then we scatter the north fold array back to the processors.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(1-jpr2di:jpi+jpr2di,1-jpr2dj:jpj+jpr2dj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                            , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      !                                                                                         !   = T ,  U , V , F or W -points
-      REAL(wp)                                                    , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
-      !!                                                                                        ! north fold, =  1. otherwise
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc
-      !
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-
-      !!----------------------------------------------------------------------
-      !
-      ALLOCATE( ztab_e(jpiglo,4+2*jpr2dj), znorthloc_e(jpi,4+2*jpr2dj), znorthgloio_e(jpi,4+2*jpr2dj,jpni) )
-
-      !
-      ijpj=4
-      ztab_e(:,:) = 0.e0
-
-      ij=0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - jpr2dj, nlcj +jpr2dj
-         ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
-      END DO
-      !
-      itaille = jpi * ( ijpj + 2 * jpr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi = nldit (iproc)
-         ilei = nleit (iproc)
-         iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*jpr2dj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = jpr2dj )
-
-      ij = jpr2dj
-      !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +jpr2dj
-      ij  = ij +1
-         DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
-      !
-   END SUBROUTINE mpp_lbc_north_e
-
-      SUBROUTINE mpp_lnk_bdy_3d( ptab, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_bdy_3d  ***
-      !!
-      !! ** Purpose :   Message passing management
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi_bdy : mark for "east-west local boundary"
-      !!                    nbondj_bdy : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)                , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                             ! = T , U , V , F , W points
-      REAL(wp)                        , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                             ! =  1. , the sign is kept
-      INTEGER                         , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
-      !
-      INTEGER  ::   ji, jj, jk, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland                      ! local scalar
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ns, zt3sn   ! 3d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::   zt3ew, zt3we   ! 3d for east-west & west-east
-      !!----------------------------------------------------------------------
-      
-      ALLOCATE( zt3ns(jpi,jprecj,jpk,2), zt3sn(jpi,jprecj,jpk,2),   &
-         &      zt3ew(jpj,jpreci,jpk,2), zt3we(jpj,jpreci,jpk,2)  )
-
-      zland = 0.e0
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      
-      !                                   ! East-West boundaries
-      !                                        !* Cyclic east-west
-
-      IF( nbondi == 2) THEN
-        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
-          ptab( 1 ,:,:) = ptab(jpim1,:,:)
-          ptab(jpi,:,:) = ptab(  2  ,:,:)
-        ELSE
-          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-          ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-        ENDIF
-      ELSEIF(nbondi == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:,:) = zland    ! south except F-point
-      ELSEIF(nbondi == 1) THEN
-        ptab(nlci-jpreci+1:jpi   ,:,:) = zland    ! north
-      ENDIF                                     !* closed
-
-      IF (nbondj == 2 .OR. nbondj == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj,:) = zland       ! south except F-point
-      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-        ptab(:,nlcj-jprecj+1:jpj   ,:) = zland       ! north
-      ENDIF
-      
-      !
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt3ew(:,jl,:,1) = ptab(jpreci+jl,:,:)
-            zt3we(:,jl,:,1) = ptab(iihom +jl,:,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj * jpk
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt3we(1,1,1,1), imigr, noea, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 1, zt3ew(1,1,1,1), imigr, nowe, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-      CASE ( 0 )
-         CALL mpprecv( 1, zt3ew(1,1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-      CASE ( 1 )
-         CALL mpprecv( 2, zt3we(1,1,1,2), imigr, nowe )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-            ptab(iihom+jl,:,:) = zt3ew(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:,:) = zt3we(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt3sn(:,jl,:,1) = ptab(:,ijhom +jl,:)
-            zt3ns(:,jl,:,1) = ptab(:,jprecj+jl,:)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi * jpk
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt3sn(1,1,1,1), imigr, nono, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 3, zt3ns(1,1,1,1), imigr, noso, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-      CASE ( 0 )
-         CALL mpprecv( 3, zt3ns(1,1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-      CASE ( 1 )
-         CALL mpprecv( 4, zt3sn(1,1,1,2), imigr, noso )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ,:) = zt3sn(:,jl,:,2)
-            ptab(:,ijhom+jl,:) = zt3ns(:,jl,:,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl,:) = zt3sn(:,jl,:,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt3ns, zt3sn, zt3ew, zt3we  )
-      !
-   END SUBROUTINE mpp_lnk_bdy_3d
-
-
-   SUBROUTINE mpp_lnk_bdy_2d( ptab, cd_type, psgn, ib_bdy )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_bdy_2d  ***
-      !!
-      !! ** Purpose :   Message passing management
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing BDY boundaries 
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    nbondi_bdy : mark for "east-west local boundary"
-      !!                    nbondj_bdy : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors 
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !! ** Action  :   ptab with update value at its periphery
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) ::   ptab     ! 3D array on which the boundary condition is applied
-      CHARACTER(len=1)            , INTENT(in   ) ::   cd_type  ! define the nature of ptab array grid-points
-      !                                                         ! = T , U , V , F , W points
-      REAL(wp)                    , INTENT(in   ) ::   psgn     ! =-1 the sign change across the north fold boundary
-      !                                                         ! =  1. , the sign is kept
-      INTEGER                     , INTENT(in   ) ::   ib_bdy   ! BDY boundary set
-      !
-      INTEGER  ::   ji, jj, jl             ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! local integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      REAL(wp) ::   zland
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ns, zt2sn   ! 2d for north-south & south-north
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  zt2ew, zt2we   ! 2d for east-west & west-east
-      !!----------------------------------------------------------------------
-
-      ALLOCATE( zt2ns(jpi,jprecj,2), zt2sn(jpi,jprecj,2),  &
-         &      zt2ew(jpj,jpreci,2), zt2we(jpj,jpreci,2)   )
-
-      zland = 0._wp
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      
-      !                                   ! East-West boundaries
-      !                                        !* Cyclic east-west
-
-      IF( nbondi == 2) THEN
-        IF (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
-          ptab( 1 ,:) = ptab(jpim1,:)
-          ptab(jpi,:) = ptab(  2  ,:)
-        ELSE
-          IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
-          ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-        ENDIF
-      ELSEIF(nbondi == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(     1       :jpreci,:) = zland    ! south except F-point
-      ELSEIF(nbondi == 1) THEN
-        ptab(nlci-jpreci+1:jpi   ,:) = zland    ! north
-      ENDIF                                     !* closed
-
-      IF (nbondj == 2 .OR. nbondj == -1) THEN
-        IF( .NOT. cd_type == 'F' )   ptab(:,     1       :jprecj) = zland       ! south except F-point
-      ELSEIF (nbondj == 2 .OR. nbondj == 1) THEN
-        ptab(:,nlcj-jprecj+1:jpj) = zland       ! north
-      ENDIF
-      
-      !
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity 
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci
-         DO jl = 1, jpreci
-            zt2ew(:,jl,1) = ptab(jpreci+jl,:)
-            zt2we(:,jl,1) = ptab(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = jpreci * jpj
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, zt2we(1,1,1), imigr, noea, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 1, zt2ew(1,1,1), imigr, nowe, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-      CASE ( 0 )
-         CALL mpprecv( 1, zt2ew(1,1,2), imigr, noea )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-      CASE ( 1 )
-         CALL mpprecv( 2, zt2we(1,1,2), imigr, nowe )
-      END SELECT
-      !
-      SELECT CASE ( nbondi_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci-jpreci
-      !
-      SELECT CASE ( nbondi_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jpreci
-            ptab(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:) = zt2we(:,jl,2)
-            ptab(iihom+jl,:) = zt2ew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jpreci
-            ptab(jl      ,:) = zt2we(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj_bdy(ib_bdy) /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj
-         DO jl = 1, jprecj
-            zt2sn(:,jl,1) = ptab(:,ijhom +jl)
-            zt2ns(:,jl,1) = ptab(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = jprecj * jpi
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req1 )
-      CASE ( 0 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, zt2sn(1,1,1), imigr, nono, ml_req2 )
-      CASE ( 1 )
-         CALL mppsend( 3, zt2ns(1,1,1), imigr, noso, ml_req1 )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-      CASE ( 0 )
-         CALL mpprecv( 3, zt2ns(1,1,2), imigr, nono )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-      CASE ( 1 )
-         CALL mpprecv( 4, zt2sn(1,1,2), imigr, noso )
-      END SELECT
-      !
-      SELECT CASE ( nbondj_bdy(ib_bdy) )
-      CASE ( -1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      CASE ( 0 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2, ml_stat, ml_err)
-      CASE ( 1 )
-         IF(l_isend) CALL mpi_wait(ml_req1, ml_stat, ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj-jprecj
-      !
-      SELECT CASE ( nbondj_bdy_b(ib_bdy) )
-      CASE ( -1 )
-         DO jl = 1, jprecj
-            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, jprecj
-            ptab(:,jl      ) = zt2sn(:,jl,2)
-            ptab(:,ijhom+jl) = zt2ns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, jprecj
-            ptab(:,jl) = zt2sn(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 4. north fold treatment
-      ! -----------------------
-      !
-      IF( npolj /= 0) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd      ( ptab, cd_type, psgn )   ! only 1 northern proc, no mpp
-         CASE DEFAULT   ;   CALL mpp_lbc_north( ptab, cd_type, psgn )   ! for all northern procs.
-         END SELECT
-         !
-      ENDIF
-      !
-      DEALLOCATE( zt2ns, zt2sn, zt2ew, zt2we  )
-      !
-   END SUBROUTINE mpp_lnk_bdy_2d
-
-   SUBROUTINE mpi_init_opa( ldtxt, ksft, code )
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_init.opa  ***
-      !!
-      !! ** Purpose :: export and attach a MPI buffer for bsend
-      !!
-      !! ** Method  :: define buffer size in namelist, if 0 no buffer attachment
-      !!            but classical mpi_init
-      !!
-      !! History :: 01/11 :: IDRIS initial version for IBM only
-      !!            08/04 :: R. Benshila, generalisation
-      !!---------------------------------------------------------------------
-      CHARACTER(len=*),DIMENSION(:), INTENT(  out) ::   ldtxt
-      INTEGER                      , INTENT(inout) ::   ksft
-      INTEGER                      , INTENT(  out) ::   code
-      INTEGER                                      ::   ierr, ji
-      LOGICAL                                      ::   mpi_was_called
-      !!---------------------------------------------------------------------
-      !
-      CALL mpi_initialized( mpi_was_called, code )      ! MPI initialization
-      IF ( code /= MPI_SUCCESS ) THEN
-         DO ji = 1, SIZE(ldtxt)
-            IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-         END DO
-         WRITE(*, cform_err)
-         WRITE(*, *) ' lib_mpp: Error in routine mpi_initialized'
-         CALL mpi_abort( mpi_comm_world, code, ierr )
-      ENDIF
-      !
-      IF( .NOT. mpi_was_called ) THEN
-         CALL mpi_init( code )
-         CALL mpi_comm_dup( mpi_comm_world, mpi_comm_opa, code )
-         IF ( code /= MPI_SUCCESS ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in routine mpi_comm_dup'
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         ENDIF
-      ENDIF
-      !
-      IF( nn_buffer > 0 ) THEN
-         WRITE(ldtxt(ksft),*) 'mpi_bsend, buffer allocation of  : ', nn_buffer   ;   ksft = ksft + 1
-         ! Buffer allocation and attachment
-         ALLOCATE( tampon(nn_buffer), stat = ierr )
-         IF( ierr /= 0 ) THEN
-            DO ji = 1, SIZE(ldtxt)
-               IF( TRIM(ldtxt(ji)) /= '' )   WRITE(*,*) ldtxt(ji)      ! control print of mynode
-            END DO
-            WRITE(*, cform_err)
-            WRITE(*, *) ' lib_mpp: Error in ALLOCATE', ierr
-            CALL mpi_abort( mpi_comm_world, code, ierr )
-         END IF
-         CALL mpi_buffer_attach( tampon, nn_buffer, code )
-      ENDIF
-      !
-   END SUBROUTINE mpi_init_opa
-
-   SUBROUTINE DDPDD_MPI (ydda, yddb, ilen, itype)
-      !!---------------------------------------------------------------------
-      !!   Routine DDPDD_MPI: used by reduction operator MPI_SUMDD
-      !!
-      !!   Modification of original codes written by David H. Bailey
-      !!   This subroutine computes yddb(i) = ydda(i)+yddb(i)
-      !!---------------------------------------------------------------------
-      INTEGER, INTENT(in)                         :: ilen, itype
-      COMPLEX(wp), DIMENSION(ilen), INTENT(in)     :: ydda
-      COMPLEX(wp), DIMENSION(ilen), INTENT(inout)  :: yddb
-      !
-      REAL(wp) :: zerr, zt1, zt2    ! local work variables
-      INTEGER :: ji, ztmp           ! local scalar
-
-      ztmp = itype   ! avoid compilation warning
-
-      DO ji=1,ilen
-      ! Compute ydda + yddb using Knuth's trick.
-         zt1  = real(ydda(ji)) + real(yddb(ji))
-         zerr = zt1 - real(ydda(ji))
-         zt2  = ((real(yddb(ji)) - zerr) + (real(ydda(ji)) - (zt1 - zerr))) &
-                + aimag(ydda(ji)) + aimag(yddb(ji))
-
-         ! The result is zt1 + zt2, after normalization.
-         yddb(ji) = cmplx ( zt1 + zt2, zt2 - ((zt1 + zt2) - zt1),wp )
-      END DO
-
-   END SUBROUTINE DDPDD_MPI
-
-   SUBROUTINE mpp_lbc_north_icb( pt2d, cd_type, psgn, pr2dj)
-      !!---------------------------------------------------------------------
-      !!                   ***  routine mpp_lbc_north_icb  ***
-      !!
-      !! ** Purpose :   Ensure proper north fold horizontal bondary condition
-      !!              in mpp configuration in case of jpn1 > 1 and for 2d
-      !!              array with outer extra halo
-      !!
-      !! ** Method  :   North fold condition and mpp with more than one proc
-      !!              in i-direction require a specific treatment. We gather
-      !!              the 4+2*jpr2dj northern lines of the global domain on 1
-      !!              processor and apply lbc north-fold on this sub array.
-      !!              Then we scatter the north fold array back to the processors.
-      !!              This version accounts for an extra halo with icebergs.
-      !!
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(:,:), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)        , INTENT(in   ) ::   cd_type  ! nature of pt3d grid-points
-      !                                                     !   = T ,  U , V , F or W -points
-      REAL(wp)                , INTENT(in   ) ::   psgn     ! = -1. the sign change across the
-      !!                                                    ! north fold, =  1. otherwise
-      INTEGER, OPTIONAL       , INTENT(in   ) ::   pr2dj
-      INTEGER ::   ji, jj, jr
-      INTEGER ::   ierr, itaille, ildi, ilei, iilb
-      INTEGER ::   ijpj, ij, iproc, ipr2dj
-      !
-      REAL(wp), DIMENSION(:,:)  , ALLOCATABLE  ::  ztab_e, znorthloc_e
-      REAL(wp), DIMENSION(:,:,:), ALLOCATABLE  ::  znorthgloio_e
-
-      !!----------------------------------------------------------------------
-      !
-      ijpj=4
-      IF( PRESENT(pr2dj) ) THEN           ! use of additional halos
-         ipr2dj = pr2dj
-      ELSE
-         ipr2dj = 0
-      ENDIF
-      ALLOCATE( ztab_e(jpiglo,4+2*ipr2dj), znorthloc_e(jpi,4+2*ipr2dj), znorthgloio_e(jpi,4+2*ipr2dj,jpni) )
-
-      !
-      ztab_e(:,:) = 0.e0
-
-      ij=0
-      ! put in znorthloc_e the last 4 jlines of pt2d
-      DO jj = nlcj - ijpj + 1 - ipr2dj, nlcj +ipr2dj
-         ij = ij + 1
-         DO ji = 1, jpi
-            znorthloc_e(ji,ij)=pt2d(ji,jj)
-         END DO
-      END DO
-      !
-      itaille = jpi * ( ijpj + 2 * ipr2dj )
-      CALL MPI_ALLGATHER( znorthloc_e(1,1)  , itaille, MPI_DOUBLE_PRECISION,    &
-         &                znorthgloio_e(1,1,1), itaille, MPI_DOUBLE_PRECISION, ncomm_north, ierr )
-      !
-      DO jr = 1, ndim_rank_north            ! recover the global north array
-         iproc = nrank_north(jr) + 1
-         ildi = nldit (iproc)
-         ilei = nleit (iproc)
-         iilb = nimppt(iproc)
-         DO jj = 1, ijpj+2*ipr2dj
-            DO ji = ildi, ilei
-               ztab_e(ji+iilb-1,jj) = znorthgloio_e(ji,jj,jr)
-            END DO
-         END DO
-      END DO
-
-
-      ! 2. North-Fold boundary conditions
-      ! ----------------------------------
-      CALL lbc_nfd( ztab_e(:,:), cd_type, psgn, pr2dj = ipr2dj )
-
-      ij = ipr2dj
-      !! Scatter back to pt2d
-      DO jj = nlcj - ijpj + 1 , nlcj +ipr2dj
-      ij  = ij +1
-         DO ji= 1, nlci
-            pt2d(ji,jj) = ztab_e(ji+nimpp-1,ij)
-         END DO
-      END DO
-      !
-      DEALLOCATE( ztab_e, znorthloc_e, znorthgloio_e )
-      !
-   END SUBROUTINE mpp_lbc_north_icb
-
-   SUBROUTINE mpp_lnk_2d_icb( pt2d, cd_type, psgn, jpri, jprj )
-      !!----------------------------------------------------------------------
-      !!                  ***  routine mpp_lnk_2d_icb  ***
-      !!
-      !! ** Purpose :   Message passing manadgement for 2d array (with extra halo and icebergs)
-      !!
-      !! ** Method  :   Use mppsend and mpprecv function for passing mask
-      !!      between processors following neighboring subdomains.
-      !!            domain parameters
-      !!                    nlci   : first dimension of the local subdomain
-      !!                    nlcj   : second dimension of the local subdomain
-      !!                    jpri   : number of rows for extra outer halo
-      !!                    jprj   : number of columns for extra outer halo
-      !!                    nbondi : mark for "east-west local boundary"
-      !!                    nbondj : mark for "north-south local boundary"
-      !!                    noea   : number for local neighboring processors
-      !!                    nowe   : number for local neighboring processors
-      !!                    noso   : number for local neighboring processors
-      !!                    nono   : number for local neighboring processors
-      !!
-      !!----------------------------------------------------------------------
-      INTEGER                                             , INTENT(in   ) ::   jpri
-      INTEGER                                             , INTENT(in   ) ::   jprj
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,1-jprj:jpj+jprj), INTENT(inout) ::   pt2d     ! 2D array with extra halo
-      CHARACTER(len=1)                                    , INTENT(in   ) ::   cd_type  ! nature of ptab array grid-points
-      !                                                                                 ! = T , U , V , F , W and I points
-      REAL(wp)                                            , INTENT(in   ) ::   psgn     ! =-1 the sign change across the
-      !!                                                                                ! north boundary, =  1. otherwise
-      INTEGER  ::   jl   ! dummy loop indices
-      INTEGER  ::   imigr, iihom, ijhom        ! temporary integers
-      INTEGER  ::   ipreci, iprecj             ! temporary integers
-      INTEGER  ::   ml_req1, ml_req2, ml_err   ! for key_mpi_isend
-      INTEGER, DIMENSION(MPI_STATUS_SIZE) ::   ml_stat   ! for key_mpi_isend
-      !!
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dns
-      REAL(wp), DIMENSION(1-jpri:jpi+jpri,jprecj+jprj,2) :: r2dsn
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dwe
-      REAL(wp), DIMENSION(1-jprj:jpj+jprj,jpreci+jpri,2) :: r2dew
-      !!----------------------------------------------------------------------
-
-      ipreci = jpreci + jpri      ! take into account outer extra 2D overlap area
-      iprecj = jprecj + jprj
-
-
-      ! 1. standard boundary treatment
-      ! ------------------------------
-      ! Order matters Here !!!!
-      !
-      !                                      ! East-West boundaries
-      !                                           !* Cyclic east-west
-      IF( nbondi == 2 .AND. (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN
-         pt2d(1-jpri:     1    ,:) = pt2d(jpim1-jpri:  jpim1 ,:)       ! east
-         pt2d(   jpi  :jpi+jpri,:) = pt2d(     2      :2+jpri,:)       ! west
-         !
-      ELSE                                        !* closed
-         IF( .NOT. cd_type == 'F' )   pt2d(  1-jpri   :jpreci    ,:) = 0.e0    ! south except at F-point
-                                      pt2d(nlci-jpreci+1:jpi+jpri,:) = 0.e0    ! north
-      ENDIF
-      !
-
-      ! north fold treatment
-      ! -----------------------
-      IF( npolj /= 0 ) THEN
-         !
-         SELECT CASE ( jpni )
-         CASE ( 1 )     ;   CALL lbc_nfd        ( pt2d(1:jpi,1:jpj+jprj), cd_type, psgn, pr2dj=jprj )
-         CASE DEFAULT   ;   CALL mpp_lbc_north_icb( pt2d(1:jpi,1:jpj+jprj)  , cd_type, psgn , pr2dj=jprj  )
-         END SELECT
-         !
-      ENDIF
-
-      ! 2. East and west directions exchange
-      ! ------------------------------------
-      ! we play with the neigbours AND the row number because of the periodicity
-      !
-      SELECT CASE ( nbondi )      ! Read Dirichlet lateral conditions
-      CASE ( -1, 0, 1 )                ! all exept 2 (i.e. close case)
-         iihom = nlci-nreci-jpri
-         DO jl = 1, ipreci
-            r2dew(:,jl,1) = pt2d(jpreci+jl,:)
-            r2dwe(:,jl,1) = pt2d(iihom +jl,:)
-         END DO
-      END SELECT
-      !
-      !                           ! Migrations
-      imigr = ipreci * ( jpj + 2*jprj)
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req1 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mppsend( 2, r2dwe(1-jprj,1,1), imigr, noea, ml_req2 )
-         CALL mpprecv( 1, r2dew(1-jprj,1,2), imigr, noea )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 1, r2dew(1-jprj,1,1), imigr, nowe, ml_req1 )
-         CALL mpprecv( 2, r2dwe(1-jprj,1,2), imigr, nowe )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      iihom = nlci - jpreci
-      !
-      SELECT CASE ( nbondi )
-      CASE ( -1 )
-         DO jl = 1, ipreci
-            pt2d(iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-            pt2d( iihom+jl,:) = r2dew(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, ipreci
-            pt2d(jl-jpri,:) = r2dwe(:,jl,2)
-         END DO
-      END SELECT
-
-
-      ! 3. North and south directions
-      ! -----------------------------
-      ! always closed : we play only with the neigbours
-      !
-      IF( nbondj /= 2 ) THEN      ! Read Dirichlet lateral conditions
-         ijhom = nlcj-nrecj-jprj
-         DO jl = 1, iprecj
-            r2dsn(:,jl,1) = pt2d(:,ijhom +jl)
-            r2dns(:,jl,1) = pt2d(:,jprecj+jl)
-         END DO
-      ENDIF
-      !
-      !                           ! Migrations
-      imigr = iprecj * ( jpi + 2*jpri )
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req1 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      CASE ( 0 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mppsend( 4, r2dsn(1-jpri,1,1), imigr, nono, ml_req2 )
-         CALL mpprecv( 3, r2dns(1-jpri,1,2), imigr, nono )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-         IF(l_isend) CALL mpi_wait(ml_req2,ml_stat,ml_err)
-      CASE ( 1 )
-         CALL mppsend( 3, r2dns(1-jpri,1,1), imigr, noso, ml_req1 )
-         CALL mpprecv( 4, r2dsn(1-jpri,1,2), imigr, noso )
-         IF(l_isend) CALL mpi_wait(ml_req1,ml_stat,ml_err)
-      END SELECT
-      !
-      !                           ! Write Dirichlet lateral conditions
-      ijhom = nlcj - jprecj
-      !
-      SELECT CASE ( nbondj )
-      CASE ( -1 )
-         DO jl = 1, iprecj
-            pt2d(:,ijhom+jl) = r2dns(:,jl,2)
-         END DO
-      CASE ( 0 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-            pt2d(:,ijhom+jl ) = r2dns(:,jl,2)
-         END DO
-      CASE ( 1 )
-         DO jl = 1, iprecj
-            pt2d(:,jl-jprj) = r2dsn(:,jl,2)
-         END DO
-      END SELECT
-
-   END SUBROUTINE mpp_lnk_2d_icb
-#else
-   !!----------------------------------------------------------------------
-   !!   Default case:            Dummy module        share memory computing
-   !!----------------------------------------------------------------------
-   USE in_out_manager
-
-   INTERFACE mpp_sum
-      MODULE PROCEDURE mpp_sum_a2s, mpp_sum_as, mpp_sum_ai, mpp_sum_s, mpp_sum_i, mppsum_realdd, mppsum_a_realdd
-   END INTERFACE
-   INTERFACE mpp_max
-      MODULE PROCEDURE mppmax_a_int, mppmax_int, mppmax_a_real, mppmax_real
-   END INTERFACE
-   INTERFACE mpp_min
-      MODULE PROCEDURE mppmin_a_int, mppmin_int, mppmin_a_real, mppmin_real
-   END INTERFACE
-   INTERFACE mpp_minloc
-      MODULE PROCEDURE mpp_minloc2d ,mpp_minloc3d
-   END INTERFACE
-   INTERFACE mpp_maxloc
-      MODULE PROCEDURE mpp_maxloc2d ,mpp_maxloc3d
-   END INTERFACE
-
-   LOGICAL, PUBLIC, PARAMETER ::   lk_mpp = .FALSE.      !: mpp flag
-   LOGICAL, PUBLIC            ::   ln_nnogather          !: namelist control of northfold comms (needed here in case "key_mpp_mpi" is not used)
-   INTEGER :: ncomm_ice
-   INTEGER, PUBLIC            ::   mpi_comm_opa          ! opa local communicator
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   INTEGER FUNCTION lib_mpp_alloc(kumout)          ! Dummy function
-      INTEGER, INTENT(in) ::   kumout
-      lib_mpp_alloc = 0
-   END FUNCTION lib_mpp_alloc
-
-   FUNCTION mynode( ldtxt, ldname, kumnam_ref, knumnam_cfg,  kumond , kstop, localComm ) RESULT (function_value)
-      INTEGER, OPTIONAL            , INTENT(in   ) ::   localComm
-      CHARACTER(len=*),DIMENSION(:) ::   ldtxt
-      CHARACTER(len=*) ::   ldname
-      INTEGER ::   kumnam_ref, knumnam_cfg , kumond , kstop
-      IF( PRESENT( localComm ) ) mpi_comm_opa = localComm
-      function_value = 0
-      IF( .FALSE. )   ldtxt(:) = 'never done'
-      CALL ctl_opn( kumond, TRIM(ldname), 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. , 1 )
-   END FUNCTION mynode
-
-   SUBROUTINE mppsync                       ! Dummy routine
-   END SUBROUTINE mppsync
-
-   SUBROUTINE mpp_sum_as( parr, kdim, kcom )      ! Dummy routine
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mpp_sum_as: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mpp_sum_as
-
-   SUBROUTINE mpp_sum_a2s( parr, kdim, kcom )      ! Dummy routine
-      REAL   , DIMENSION(:,:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mpp_sum_a2s: You should not have seen this print! error?', kdim, parr(1,1), kcom
-   END SUBROUTINE mpp_sum_a2s
-
-   SUBROUTINE mpp_sum_ai( karr, kdim, kcom )      ! Dummy routine
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mpp_sum_ai: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mpp_sum_ai
-
-   SUBROUTINE mpp_sum_s( psca, kcom )            ! Dummy routine
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mpp_sum_s: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mpp_sum_s
-
-   SUBROUTINE mpp_sum_i( kint, kcom )            ! Dummy routine
-      integer               :: kint
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mpp_sum_i: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mpp_sum_i
-
-   SUBROUTINE mppsum_realdd( ytab, kcom )
-      COMPLEX(wp), INTENT(inout)         :: ytab    ! input scalar
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-      WRITE(*,*) 'mppsum_realdd: You should not have seen this print! error?', ytab
-   END SUBROUTINE mppsum_realdd
-
-   SUBROUTINE mppsum_a_realdd( ytab, kdim, kcom )
-      INTEGER , INTENT( in )                        ::   kdim      ! size of ytab
-      COMPLEX(wp), DIMENSION(kdim), INTENT( inout ) ::   ytab      ! input array
-      INTEGER , INTENT( in  ), OPTIONAL :: kcom
-      WRITE(*,*) 'mppsum_a_realdd: You should not have seen this print! error?', kdim, ytab(1), kcom
-   END SUBROUTINE mppsum_a_realdd
-
-   SUBROUTINE mppmax_a_real( parr, kdim, kcom )
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmax_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mppmax_a_real
-
-   SUBROUTINE mppmax_real( psca, kcom )
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmax_real: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mppmax_real
-
-   SUBROUTINE mppmin_a_real( parr, kdim, kcom )
-      REAL   , DIMENSION(:) :: parr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmin_a_real: You should not have seen this print! error?', kdim, parr(1), kcom
-   END SUBROUTINE mppmin_a_real
-
-   SUBROUTINE mppmin_real( psca, kcom )
-      REAL                  :: psca
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmin_real: You should not have seen this print! error?', psca, kcom
-   END SUBROUTINE mppmin_real
-
-   SUBROUTINE mppmax_a_int( karr, kdim ,kcom)
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmax_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mppmax_a_int
-
-   SUBROUTINE mppmax_int( kint, kcom)
-      INTEGER               :: kint
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmax_int: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mppmax_int
-
-   SUBROUTINE mppmin_a_int( karr, kdim, kcom )
-      INTEGER, DIMENSION(:) :: karr
-      INTEGER               :: kdim
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmin_a_int: You should not have seen this print! error?', kdim, karr(1), kcom
-   END SUBROUTINE mppmin_a_int
-
-   SUBROUTINE mppmin_int( kint, kcom )
-      INTEGER               :: kint
-      INTEGER, OPTIONAL     :: kcom
-      WRITE(*,*) 'mppmin_int: You should not have seen this print! error?', kint, kcom
-   END SUBROUTINE mppmin_int
-
-   SUBROUTINE mpp_minloc2d( ptab, pmask, pmin, ki, kj )
-      REAL                   :: pmin
-      REAL , DIMENSION (:,:) :: ptab, pmask
-      INTEGER :: ki, kj
-      WRITE(*,*) 'mpp_minloc2d: You should not have seen this print! error?', pmin, ki, kj, ptab(1,1), pmask(1,1)
-   END SUBROUTINE mpp_minloc2d
-
-   SUBROUTINE mpp_minloc3d( ptab, pmask, pmin, ki, kj, kk )
-      REAL                     :: pmin
-      REAL , DIMENSION (:,:,:) :: ptab, pmask
-      INTEGER :: ki, kj, kk
-      WRITE(*,*) 'mpp_minloc3d: You should not have seen this print! error?', pmin, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
-   END SUBROUTINE mpp_minloc3d
-
-   SUBROUTINE mpp_maxloc2d( ptab, pmask, pmax, ki, kj )
-      REAL                   :: pmax
-      REAL , DIMENSION (:,:) :: ptab, pmask
-      INTEGER :: ki, kj
-      WRITE(*,*) 'mpp_maxloc2d: You should not have seen this print! error?', pmax, ki, kj, ptab(1,1), pmask(1,1)
-   END SUBROUTINE mpp_maxloc2d
-
-   SUBROUTINE mpp_maxloc3d( ptab, pmask, pmax, ki, kj, kk )
-      REAL                     :: pmax
-      REAL , DIMENSION (:,:,:) :: ptab, pmask
-      INTEGER :: ki, kj, kk
-      WRITE(*,*) 'mpp_maxloc3d: You should not have seen this print! error?', pmax, ki, kj, kk, ptab(1,1,1), pmask(1,1,1)
-   END SUBROUTINE mpp_maxloc3d
-
-   SUBROUTINE mppstop
-      STOP      ! non MPP case, just stop the run
-   END SUBROUTINE mppstop
-
-   SUBROUTINE mpp_ini_ice( kcom, knum )
-      INTEGER :: kcom, knum
-      WRITE(*,*) 'mpp_ini_ice: You should not have seen this print! error?', kcom, knum
-   END SUBROUTINE mpp_ini_ice
-
-   SUBROUTINE mpp_ini_znl( knum )
-      INTEGER :: knum
-      WRITE(*,*) 'mpp_ini_znl: You should not have seen this print! error?', knum
-   END SUBROUTINE mpp_ini_znl
-
-   SUBROUTINE mpp_comm_free( kcom )
-      INTEGER :: kcom
-      WRITE(*,*) 'mpp_comm_free: You should not have seen this print! error?', kcom
-   END SUBROUTINE mpp_comm_free
-#endif
-
-   !!----------------------------------------------------------------------
-   !!   All cases:         ctl_stop, ctl_warn, get_unit, ctl_opn, ctl_nam   routines
-   !!----------------------------------------------------------------------
-
-   SUBROUTINE ctl_stop( cd1, cd2, cd3, cd4, cd5 ,   &
-      &                 cd6, cd7, cd8, cd9, cd10 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE  stop_opa  ***
-      !!
-      !! ** Purpose :   print in ocean.outpput file a error message and
-      !!                increment the error number (nstop) by one.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
-      !!----------------------------------------------------------------------
-      !
-      nstop = nstop + 1
-      IF(lwp) THEN
-         WRITE(numout,cform_err)
-         IF( PRESENT(cd1 ) )   WRITE(numout,*) cd1
-         IF( PRESENT(cd2 ) )   WRITE(numout,*) cd2
-         IF( PRESENT(cd3 ) )   WRITE(numout,*) cd3
-         IF( PRESENT(cd4 ) )   WRITE(numout,*) cd4
-         IF( PRESENT(cd5 ) )   WRITE(numout,*) cd5
-         IF( PRESENT(cd6 ) )   WRITE(numout,*) cd6
-         IF( PRESENT(cd7 ) )   WRITE(numout,*) cd7
-         IF( PRESENT(cd8 ) )   WRITE(numout,*) cd8
-         IF( PRESENT(cd9 ) )   WRITE(numout,*) cd9
-         IF( PRESENT(cd10) )   WRITE(numout,*) cd10
-      ENDIF
-                               CALL FLUSH(numout    )
-      IF( numstp     /= -1 )   CALL FLUSH(numstp    )
-      IF( numsol     /= -1 )   CALL FLUSH(numsol    )
-      IF( numevo_ice /= -1 )   CALL FLUSH(numevo_ice)
-      !
-      IF( cd1 == 'STOP' ) THEN
-         IF(lwp) WRITE(numout,*)  'huge E-R-R-O-R : immediate stop'
-         CALL mppstop()
-      ENDIF
-      !
-   END SUBROUTINE ctl_stop
-
-
-   SUBROUTINE ctl_warn( cd1, cd2, cd3, cd4, cd5,   &
-      &                 cd6, cd7, cd8, cd9, cd10 )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE  stop_warn  ***
-      !!
-      !! ** Purpose :   print in ocean.outpput file a error message and
-      !!                increment the warning number (nwarn) by one.
-      !!----------------------------------------------------------------------
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd1, cd2, cd3, cd4, cd5
-      CHARACTER(len=*), INTENT(in), OPTIONAL ::  cd6, cd7, cd8, cd9, cd10
-      !!----------------------------------------------------------------------
-      !
-      nwarn = nwarn + 1
-      IF(lwp) THEN
-         WRITE(numout,cform_war)
-         IF( PRESENT(cd1 ) ) WRITE(numout,*) cd1
-         IF( PRESENT(cd2 ) ) WRITE(numout,*) cd2
-         IF( PRESENT(cd3 ) ) WRITE(numout,*) cd3
-         IF( PRESENT(cd4 ) ) WRITE(numout,*) cd4
-         IF( PRESENT(cd5 ) ) WRITE(numout,*) cd5
-         IF( PRESENT(cd6 ) ) WRITE(numout,*) cd6
-         IF( PRESENT(cd7 ) ) WRITE(numout,*) cd7
-         IF( PRESENT(cd8 ) ) WRITE(numout,*) cd8
-         IF( PRESENT(cd9 ) ) WRITE(numout,*) cd9
-         IF( PRESENT(cd10) ) WRITE(numout,*) cd10
-      ENDIF
-      CALL FLUSH(numout)
-      !
-   END SUBROUTINE ctl_warn
-
-
-   SUBROUTINE ctl_opn( knum, cdfile, cdstat, cdform, cdacce, klengh, kout, ldwp, karea )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ctl_opn  ***
-      !!
-      !! ** Purpose :   Open file and check if required file is available.
-      !!
-      !! ** Method  :   Fortan open
-      !!----------------------------------------------------------------------
-      INTEGER          , INTENT(  out) ::   knum      ! logical unit to open
-      CHARACTER(len=*) , INTENT(in   ) ::   cdfile    ! file name to open
-      CHARACTER(len=*) , INTENT(in   ) ::   cdstat    ! disposition specifier
-      CHARACTER(len=*) , INTENT(in   ) ::   cdform    ! formatting specifier
-      CHARACTER(len=*) , INTENT(in   ) ::   cdacce    ! access specifier
-      INTEGER          , INTENT(in   ) ::   klengh    ! record length
-      INTEGER          , INTENT(in   ) ::   kout      ! number of logical units for write
-      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
-      INTEGER, OPTIONAL, INTENT(in   ) ::   karea     ! proc number
-      !!
-      CHARACTER(len=80) ::   clfile
-      INTEGER           ::   iost
-      !!----------------------------------------------------------------------
-
-      ! adapt filename
-      ! ----------------
-      clfile = TRIM(cdfile)
-      IF( PRESENT( karea ) ) THEN
-         IF( karea > 1 )   WRITE(clfile, "(a,'_',i4.4)") TRIM(clfile), karea-1
-      ENDIF
-#if defined key_agrif
-      IF( .NOT. Agrif_Root() )   clfile = TRIM(Agrif_CFixed())//'_'//TRIM(clfile)
-      knum=Agrif_Get_Unit()
-#else
-      knum=get_unit()
-#endif
-
-      iost=0
-      IF( cdacce(1:6) == 'DIRECT' )  THEN
-         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat, RECL=klengh, ERR=100, IOSTAT=iost )
-      ELSE
-         OPEN( UNIT=knum, FILE=clfile, FORM=cdform, ACCESS=cdacce, STATUS=cdstat             , ERR=100, IOSTAT=iost )
-      ENDIF
-      IF( iost == 0 ) THEN
-         IF(ldwp) THEN
-            WRITE(kout,*) '     file   : ', clfile,' open ok'
-            WRITE(kout,*) '     unit   = ', knum
-            WRITE(kout,*) '     status = ', cdstat
-            WRITE(kout,*) '     form   = ', cdform
-            WRITE(kout,*) '     access = ', cdacce
-            WRITE(kout,*)
-         ENDIF
-      ENDIF
-100   CONTINUE
-      IF( iost /= 0 ) THEN
-         IF(ldwp) THEN
-            WRITE(kout,*)
-            WRITE(kout,*) ' ===>>>> : bad opening file: ', clfile
-            WRITE(kout,*) ' =======   ===  '
-            WRITE(kout,*) '           unit   = ', knum
-            WRITE(kout,*) '           status = ', cdstat
-            WRITE(kout,*) '           form   = ', cdform
-            WRITE(kout,*) '           access = ', cdacce
-            WRITE(kout,*) '           iostat = ', iost
-            WRITE(kout,*) '           we stop. verify the file '
-            WRITE(kout,*)
-         ENDIF
-         STOP 'ctl_opn bad opening'
-      ENDIF
-
-   END SUBROUTINE ctl_opn
-
-   SUBROUTINE ctl_nam ( kios, cdnam, ldwp )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE ctl_nam  ***
-      !!
-      !! ** Purpose :   Informations when error while reading a namelist
-      !!
-      !! ** Method  :   Fortan open
-      !!----------------------------------------------------------------------
-      INTEGER          , INTENT(inout) ::   kios      ! IO status after reading the namelist
-      CHARACTER(len=*) , INTENT(in   ) ::   cdnam     ! group name of namelist for which error occurs
-      CHARACTER(len=5)                 ::   clios     ! string to convert iostat in character for print
-      LOGICAL          , INTENT(in   ) ::   ldwp      ! boolean term for print
-      !!----------------------------------------------------------------------
-
-      ! 
-      ! ----------------
-      WRITE (clios, '(I5.0)') kios
-      IF( kios < 0 ) THEN         
-         CALL ctl_warn( 'W A R N I N G:  end of record or file while reading namelist ' &
- &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
-      ENDIF
-
-      IF( kios > 0 ) THEN
-         CALL ctl_stop( 'E R R O R :   misspelled variable in namelist ' &
- &           // TRIM(cdnam) // ' iostat = ' // TRIM(clios) )
-      ENDIF
-      kios = 0
-      RETURN
-      
-   END SUBROUTINE ctl_nam
-
-   INTEGER FUNCTION get_unit()
-      !!----------------------------------------------------------------------
-      !!                  ***  FUNCTION  get_unit  ***
-      !!
-      !! ** Purpose :   return the index of an unused logical unit
-      !!----------------------------------------------------------------------
-      LOGICAL :: llopn
-      !!----------------------------------------------------------------------
-      !
-      get_unit = 15   ! choose a unit that is big enough then it is not already used in NEMO
-      llopn = .TRUE.
-      DO WHILE( (get_unit < 998) .AND. llopn )
-         get_unit = get_unit + 1
-         INQUIRE( unit = get_unit, opened = llopn )
-      END DO
-      IF( (get_unit == 999) .AND. llopn ) THEN
-         CALL ctl_stop( 'get_unit: All logical units until 999 are used...' )
-         get_unit = -1
-      ENDIF
-      !
-   END FUNCTION get_unit
-
-   !!----------------------------------------------------------------------
-END MODULE lib_mpp
Index: NFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/traadv_tvd.F90
===================================================================
--- /CONFIG/UNIFORM/v6/IPSLCM5A2/SOURCES/NEMO/traadv_tvd.F90	(revision 5878)
+++ 	(revision )
@@ -1,682 +1,0 @@
-MODULE traadv_tvd
-   !!==============================================================================
-   !!                       ***  MODULE  traadv_tvd  ***
-   !! Ocean  tracers:  horizontal & vertical advective trend
-   !!==============================================================================
-   !! History :  OPA  !  1995-12  (L. Mortier)  Original code
-   !!                 !  2000-01  (H. Loukos)  adapted to ORCA 
-   !!                 !  2000-10  (MA Foujols E.Kestenare)  include file not routine
-   !!                 !  2000-12  (E. Kestenare M. Levy)  fix bug in trtrd indexes
-   !!                 !  2001-07  (E. Durand G. Madec)  adaptation to ORCA config
-   !!            8.5  !  2002-06  (G. Madec)  F90: Free form and module
-   !!    NEMO    1.0  !  2004-01  (A. de Miranda, G. Madec, J.M. Molines ): advective bbl
-   !!            2.0  !  2008-04  (S. Cravatte) add the i-, j- & k- trends computation
-   !!             -   !  2009-11  (V. Garnier) Surface pressure gradient organization
-   !!            3.3  !  2010-05  (C. Ethe, G. Madec)  merge TRC-TRA + switch from velocity to transport
-   !!----------------------------------------------------------------------
-
-   !!----------------------------------------------------------------------
-   !!   tra_adv_tvd   : update the tracer trend with the 3D advection trends using a TVD scheme
-   !!   nonosc        : compute monotonic tracer fluxes by a non-oscillatory algorithm 
-   !!----------------------------------------------------------------------
-   USE oce            ! ocean dynamics and active tracers
-   USE dom_oce        ! ocean space and time domain
-   USE trc_oce        ! share passive tracers/Ocean variables
-   USE trd_oce        ! trends: ocean variables
-   USE trdtra         ! tracers trends
-   USE dynspg_oce     ! choice/control of key cpp for surface pressure gradient
-   USE diaptr         ! poleward transport diagnostics
-   !
-   USE lib_mpp        ! MPP library
-   USE lbclnk         ! ocean lateral boundary condition (or mpp link) 
-   USE in_out_manager ! I/O manager
-   USE wrk_nemo       ! Memory Allocation
-   USE timing         ! Timing
-   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)  
-
-   IMPLICIT NONE
-   PRIVATE
-
-   PUBLIC   tra_adv_tvd        ! routine called by traadv.F90
-   PUBLIC   tra_adv_tvd_zts    ! routine called by traadv.F90
-
-   LOGICAL ::   l_trd   ! flag to compute trends
-
-   !! * Substitutions
-#  include "domzgr_substitute.h90"
-#  include "vectopt_loop_substitute.h90"
-   !!----------------------------------------------------------------------
-   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
-   !! $Id: traadv_tvd.F90 6692 2016-06-13 14:39:24Z flavoni $
-   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
-   !!----------------------------------------------------------------------
-CONTAINS
-
-   SUBROUTINE tra_adv_tvd ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
-      &                                       ptb, ptn, pta, kjpt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_adv_tvd  ***
-      !! 
-      !! **  Purpose :   Compute the now trend due to total advection of 
-      !!       tracers and add it to the general trend of tracer equations
-      !!
-      !! **  Method  :   TVD scheme, i.e. 2nd order centered scheme with
-      !!       corrected flux (monotonic correction)
-      !!       note: - this advection scheme needs a leap-frog time scheme
-      !!
-      !! ** Action : - update (pta) with the now advective tracer trends
-      !!             - save the trends 
-      !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
-      !
-      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
-      !
-      INTEGER  ::   ji, jj, jk, jn           ! dummy loop indices
-      INTEGER  ::   ik  
-      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
-      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
-      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz )
-      !
-      IF( kt == kit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_adv_tvd : TVD advection scheme on ', cdtype
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-         !
-         l_trd = .FALSE.
-         IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
-      ENDIF
-      !
-      IF( l_trd )  THEN
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-         ztrdx(:,:,:) = 0.e0   ;    ztrdy(:,:,:) = 0.e0   ;   ztrdz(:,:,:) = 0.e0
-      ENDIF
-      !
-      zwi(:,:,:) = 0.e0 ; 
-      !
-      !                                                          ! ===========
-      DO jn = 1, kjpt                                            ! tracer loop
-         !                                                       ! ===========
-         ! 1. Bottom and k=1 value : flux set to zero
-         ! ----------------------------------
-         zwx(:,:,jpk) = 0.e0    ;    zwz(:,:,jpk) = 0.e0
-         zwy(:,:,jpk) = 0.e0    ;    zwi(:,:,jpk) = 0.e0
-          
-         zwz(:,:,1  ) = 0._wp
-         ! 2. upstream advection with initial mass fluxes & intermediate update
-         ! --------------------------------------------------------------------
-         ! upstream tracer flux in the i and j direction
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  ! upstream scheme
-                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
-                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
-                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
-                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
-                  zwx(ji,jj,jk) = 0.5 * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
-                  zwy(ji,jj,jk) = 0.5 * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
-               END DO
-            END DO
-         END DO
-
-         ! upstream tracer flux in the k direction
-         ! Interior value
-         DO jk = 2, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
-                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
-                  zwz(ji,jj,jk) = 0.5 * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) ) * wmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         ! Surface value
-         IF( lk_vvl ) THEN   
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable
-                  END DO
-               END DO
-            ELSE
-               zwz(:,:,1) = 0.e0          ! volume variable
-            END IF
-         ELSE                
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface 
-                  END DO
-               END DO   
-            ELSE
-               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)   ! linear free surface
-            END IF
-         ENDIF
-
-         ! total advective trend
-         DO jk = 1, jpkm1
-            z2dtt = p2dt(jk)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ! total intermediate advective trends
-                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
-                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
-                  ! update and guess with monotonic sheme
-                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
-                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
-         CALL lbc_lnk( zwi, 'T', 1. )  
-
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  THEN 
-            ! store intermediate advective trends
-            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
-         END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
-         ENDIF
-
-         ! 3. antidiffusive flux : high order minus low order
-         ! --------------------------------------------------
-         ! antidiffusive flux on i and j
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  zwx(ji,jj,jk) = 0.5 * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) ) - zwx(ji,jj,jk)
-                  zwy(ji,jj,jk) = 0.5 * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) ) - zwy(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-      
-         ! antidiffusive flux on k
-         ! Interior value
-         DO jk = 2, jpkm1                    
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zwz(ji,jj,jk) = 0.5 * pwn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj,jk-1,jn) ) - zwz(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         ! surface value
-         IF ( ln_isfcav ) THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zwz(ji,jj,mikt(ji,jj)) = 0.e0
-               END DO
-            END DO
-         ELSE
-            zwz(:,:,1) = 0.e0
-         END IF
-         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
-         CALL lbc_lnk( zwz, 'W',  1. )
-
-         ! 4. monotonicity algorithm
-         ! -------------------------
-         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
-
-
-         ! 5. final trend with corrected fluxes
-         ! ------------------------------------
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.  
-                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  ! total advective trends
-                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
-                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
-                  ! add them to the general tracer trends
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  THEN 
-            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
-            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
-            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
-            
-            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
-            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
-            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
-         END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
-         ENDIF
-         !
-      END DO
-      !
-                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz )
-      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd')
-      !
-   END SUBROUTINE tra_adv_tvd
-
-   SUBROUTINE tra_adv_tvd_zts ( kt, kit000, cdtype, p2dt, pun, pvn, pwn,      &
-      &                                       ptb, ptn, pta, kjpt )
-      !!----------------------------------------------------------------------
-      !!                  ***  ROUTINE tra_adv_tvd_zts  ***
-      !! 
-      !! **  Purpose :   Compute the now trend due to total advection of 
-      !!       tracers and add it to the general trend of tracer equations
-      !!
-      !! **  Method  :   TVD ZTS scheme, i.e. 2nd order centered scheme with
-      !!       corrected flux (monotonic correction). This version use sub-
-      !!       timestepping for the vertical advection which increases stability
-      !!       when vertical metrics are small.
-      !!       note: - this advection scheme needs a leap-frog time scheme
-      !!
-      !! ** Action : - update (pta) with the now advective tracer trends
-      !!             - save the trends 
-      !!----------------------------------------------------------------------
-      USE oce     , ONLY:   zwx => ua        , zwy => va          ! (ua,va) used as workspace
-      !
-      INTEGER                              , INTENT(in   ) ::   kt              ! ocean time-step index
-      INTEGER                              , INTENT(in   ) ::   kit000          ! first time step index
-      CHARACTER(len=3)                     , INTENT(in   ) ::   cdtype          ! =TRA or TRC (tracer indicator)
-      INTEGER                              , INTENT(in   ) ::   kjpt            ! number of tracers
-      REAL(wp), DIMENSION(        jpk     ), INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
-      REAL(wp), DIMENSION(jpi,jpj,jpk     ), INTENT(in   ) ::   pun, pvn, pwn   ! 3 ocean velocity components
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(in   ) ::   ptb, ptn        ! before and now tracer fields
-      REAL(wp), DIMENSION(jpi,jpj,jpk,kjpt), INTENT(inout) ::   pta             ! tracer trend 
-      !
-      REAL(wp), DIMENSION( jpk )                           ::   zts             ! length of sub-timestep for vertical advection
-      REAL(wp), DIMENSION( jpk )                           ::   zr_p2dt         ! reciprocal of tracer timestep
-      INTEGER  ::   ji, jj, jk, jl, jn       ! dummy loop indices  
-      INTEGER  ::   jnzts = 5       ! number of sub-timesteps for vertical advection
-      INTEGER  ::   jtb, jtn, jta   ! sub timestep pointers for leap-frog/euler forward steps
-      INTEGER  ::   jtaken          ! toggle for collecting appropriate fluxes from sub timesteps
-      REAL(wp) ::   z_rzts          ! Fractional length of Euler forward sub-timestep for vertical advection
-      REAL(wp) ::   z2dtt, zbtr, ztra        ! local scalar
-      REAL(wp) ::   zfp_ui, zfp_vj, zfp_wk   !   -      -
-      REAL(wp) ::   zfm_ui, zfm_vj, zfm_wk   !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:  ) :: zwx_sav , zwy_sav
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zwi, zwz, zhdiv, zwz_sav, zwzts
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: ztrdx, ztrdy, ztrdz
-      REAL(wp), POINTER, DIMENSION(:,:,:,:) :: ztrs
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('tra_adv_tvd_zts')
-      !
-      CALL wrk_alloc( jpi, jpj, zwx_sav, zwy_sav )
-      CALL wrk_alloc( jpi, jpj, jpk, zwi, zwz , zhdiv, zwz_sav, zwzts )
-      CALL wrk_alloc( jpi, jpj, jpk, kjpt+1, ztrs )
-      !
-      IF( kt == kit000 )  THEN
-         IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*) 'tra_adv_tvd_zts : TVD ZTS advection scheme on ', cdtype
-         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
-      ENDIF
-      !
-      l_trd = .FALSE.
-      IF( ( cdtype == 'TRA' .AND. l_trdtra ) .OR. ( cdtype == 'TRC' .AND. l_trdtrc ) ) l_trd = .TRUE.
-      !
-      IF( l_trd )  THEN
-         CALL wrk_alloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-         ztrdx(:,:,:) = 0._wp  ;    ztrdy(:,:,:) = 0._wp  ;   ztrdz(:,:,:) = 0._wp
-      ENDIF
-      !
-      zwi(:,:,:) = 0._wp
-      z_rzts = 1._wp / REAL( jnzts, wp )
-      zr_p2dt(:) = 1._wp / p2dt(:)
-      !
-      !                                                          ! ===========
-      DO jn = 1, kjpt                                            ! tracer loop
-         !                                                       ! ===========
-         ! 1. Bottom value : flux set to zero
-         ! ----------------------------------
-         zwx(:,:,jpk) = 0._wp   ;    zwz(:,:,jpk) = 0._wp
-         zwy(:,:,jpk) = 0._wp   ;    zwi(:,:,jpk) = 0._wp
-
-         ! 2. upstream advection with initial mass fluxes & intermediate update
-         ! --------------------------------------------------------------------
-         ! upstream tracer flux in the i and j direction
-         DO jk = 1, jpkm1
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  ! upstream scheme
-                  zfp_ui = pun(ji,jj,jk) + ABS( pun(ji,jj,jk) )
-                  zfm_ui = pun(ji,jj,jk) - ABS( pun(ji,jj,jk) )
-                  zfp_vj = pvn(ji,jj,jk) + ABS( pvn(ji,jj,jk) )
-                  zfm_vj = pvn(ji,jj,jk) - ABS( pvn(ji,jj,jk) )
-                  zwx(ji,jj,jk) = 0.5_wp * ( zfp_ui * ptb(ji,jj,jk,jn) + zfm_ui * ptb(ji+1,jj  ,jk,jn) )
-                  zwy(ji,jj,jk) = 0.5_wp * ( zfp_vj * ptb(ji,jj,jk,jn) + zfm_vj * ptb(ji  ,jj+1,jk,jn) )
-               END DO
-            END DO
-         END DO
-
-         ! upstream tracer flux in the k direction
-         ! Interior value
-         DO jk = 2, jpkm1
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  zfp_wk = pwn(ji,jj,jk) + ABS( pwn(ji,jj,jk) )
-                  zfm_wk = pwn(ji,jj,jk) - ABS( pwn(ji,jj,jk) )
-                  zwz(ji,jj,jk) = 0.5_wp * ( zfp_wk * ptb(ji,jj,jk,jn) + zfm_wk * ptb(ji,jj,jk-1,jn) )
-               END DO
-            END DO
-         END DO
-         ! Surface value
-         IF( lk_vvl ) THEN
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = 0.e0          ! volume variable +    isf
-                  END DO
-               END DO
-            ELSE
-               zwz(:,:,1) = 0.e0                              ! volume variable + no isf
-            END IF
-         ELSE
-            IF ( ln_isfcav ) THEN
-               DO jj = 1, jpj
-                  DO ji = 1, jpi
-                     zwz(ji,jj, mikt(ji,jj) ) = pwn(ji,jj,mikt(ji,jj)) * ptb(ji,jj,mikt(ji,jj),jn)   ! linear free surface +    isf
-                  END DO
-               END DO
-            ELSE
-               zwz(:,:,1) = pwn(:,:,1) * ptb(:,:,1,jn)                                               ! linear free surface + no isf
-            END IF
-         ENDIF
-
-         ! total advective trend
-         DO jk = 1, jpkm1
-            z2dtt = p2dt(jk)
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.
-                  ! total intermediate advective trends
-                  ztra = - (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
-                     &      + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &      + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) ) / e1e2t(ji,jj)
-                  ! update and guess with monotonic sheme
-                  pta(ji,jj,jk,jn) =                       pta(ji,jj,jk,jn) +         ztra   / fse3t_n(ji,jj,jk) * tmask(ji,jj,jk)
-                  zwi(ji,jj,jk)    = ( fse3t_b(ji,jj,jk) * ptb(ji,jj,jk,jn) + z2dtt * ztra ) / fse3t_a(ji,jj,jk) * tmask(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         !                             ! Lateral boundary conditions on zwi  (unchanged sign)
-         CALL lbc_lnk( zwi, 'T', 1. )  
-
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  THEN 
-            ! store intermediate advective trends
-            ztrdx(:,:,:) = zwx(:,:,:)   ;    ztrdy(:,:,:) = zwy(:,:,:)  ;   ztrdz(:,:,:) = zwz(:,:,:)
-         END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) )
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) )
-         ENDIF
-
-         ! 3. antidiffusive flux : high order minus low order
-         ! --------------------------------------------------
-         ! antidiffusive flux on i and j
-         !
-         DO jk = 1, jpkm1
-            !
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  zwx_sav(ji,jj) = zwx(ji,jj,jk)
-                  zwy_sav(ji,jj) = zwy(ji,jj,jk)
-
-                  zwx(ji,jj,jk) = 0.5_wp * pun(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji+1,jj,jk,jn) )
-                  zwy(ji,jj,jk) = 0.5_wp * pvn(ji,jj,jk) * ( ptn(ji,jj,jk,jn) + ptn(ji,jj+1,jk,jn) )
-               END DO
-            END DO
-
-            DO jj = 2, jpjm1         ! partial horizontal divergence
-               DO ji = fs_2, fs_jpim1
-                  zhdiv(ji,jj,jk) = (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk)   &
-                     &               + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk)  )
-               END DO
-            END DO
-
-            DO jj = 1, jpjm1
-               DO ji = 1, fs_jpim1   ! vector opt.
-                  zwx(ji,jj,jk) = zwx(ji,jj,jk)  - zwx_sav(ji,jj)
-                  zwy(ji,jj,jk) = zwy(ji,jj,jk)  - zwy_sav(ji,jj)
-               END DO
-            END DO
-         END DO
-      
-         ! antidiffusive flux on k
-         zwz(:,:,1) = 0._wp        ! Surface value
-         zwz_sav(:,:,:) = zwz(:,:,:)
-         !
-         ztrs(:,:,:,1) = ptb(:,:,:,jn)
-         zwzts(:,:,:) = 0._wp
-
-         DO jl = 1, jnzts                   ! Start of sub timestepping loop
-
-            IF( jl == 1 ) THEN              ! Euler forward to kick things off
-              jtb = 1   ;   jtn = 1   ;   jta = 2
-              zts(:) = p2dt(:) * z_rzts
-              jtaken = MOD( jnzts + 1 , 2)  ! Toggle to collect every second flux
-                                            ! starting at jl =1 if jnzts is odd; 
-                                            ! starting at jl =2 otherwise
-            ELSEIF( jl == 2 ) THEN          ! First leapfrog step
-              jtb = 1   ;   jtn = 2   ;   jta = 3
-              zts(:) = 2._wp * p2dt(:) * z_rzts
-            ELSE                            ! Shuffle pointers for subsequent leapfrog steps
-              jtb = MOD(jtb,3) + 1
-              jtn = MOD(jtn,3) + 1
-              jta = MOD(jta,3) + 1
-            ENDIF
-            DO jk = 2, jpkm1          ! Interior value
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zwz(ji,jj,jk) = 0.5_wp * pwn(ji,jj,jk) * ( ztrs(ji,jj,jk,jtn) + ztrs(ji,jj,jk-1,jtn) )
-                     IF( jtaken == 0 ) zwzts(ji,jj,jk) = zwzts(ji,jj,jk) + zwz(ji,jj,jk)*zts(jk)           ! Accumulate time-weighted vertcal flux
-                  END DO
-               END DO
-            END DO
-
-            jtaken = MOD( jtaken + 1 , 2 )
-
-            DO jk = 2, jpkm1          ! Interior value
-               DO jj = 2, jpjm1
-                  DO ji = fs_2, fs_jpim1
-                     zbtr = 1._wp / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                     ! total advective trends
-                     ztra = - zbtr * (  zhdiv(ji,jj,jk) + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
-                     ztrs(ji,jj,jk,jta) = ztrs(ji,jj,jk,jtb) + zts(jk) * ztra
-                  END DO
-               END DO
-            END DO
-
-         END DO
-
-         DO jk = 2, jpkm1          ! Anti-diffusive vertical flux using average flux from the sub-timestepping
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1
-                  zwz(ji,jj,jk) = zwzts(ji,jj,jk) * zr_p2dt(jk) - zwz_sav(ji,jj,jk)
-               END DO
-            END DO
-         END DO
-         CALL lbc_lnk( zwx, 'U', -1. )   ;   CALL lbc_lnk( zwy, 'V', -1. )         ! Lateral bondary conditions
-         CALL lbc_lnk( zwz, 'W',  1. )
-
-         ! 4. monotonicity algorithm
-         ! -------------------------
-         CALL nonosc( ptb(:,:,:,jn), zwx, zwy, zwz, zwi, p2dt )
-
-
-         ! 5. final trend with corrected fluxes
-         ! ------------------------------------
-         DO jk = 1, jpkm1
-            DO jj = 2, jpjm1
-               DO ji = fs_2, fs_jpim1   ! vector opt.  
-                  zbtr = 1. / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
-                  ! total advective trends
-                  ztra = - zbtr * (  zwx(ji,jj,jk) - zwx(ji-1,jj  ,jk  )   &
-                     &             + zwy(ji,jj,jk) - zwy(ji  ,jj-1,jk  )   &
-                     &             + zwz(ji,jj,jk) - zwz(ji  ,jj  ,jk+1) )
-                  ! add them to the general tracer trends
-                  pta(ji,jj,jk,jn) = pta(ji,jj,jk,jn) + ztra
-               END DO
-            END DO
-         END DO
-
-         !                                 ! trend diagnostics (contribution of upstream fluxes)
-         IF( l_trd )  THEN 
-            ztrdx(:,:,:) = ztrdx(:,:,:) + zwx(:,:,:)  ! <<< Add to previously computed
-            ztrdy(:,:,:) = ztrdy(:,:,:) + zwy(:,:,:)  ! <<< Add to previously computed
-            ztrdz(:,:,:) = ztrdz(:,:,:) + zwz(:,:,:)  ! <<< Add to previously computed
-            
-            CALL trd_tra( kt, cdtype, jn, jptra_xad, ztrdx, pun, ptn(:,:,:,jn) )   
-            CALL trd_tra( kt, cdtype, jn, jptra_yad, ztrdy, pvn, ptn(:,:,:,jn) )  
-            CALL trd_tra( kt, cdtype, jn, jptra_zad, ztrdz, pwn, ptn(:,:,:,jn) ) 
-         END IF
-         !                                 ! "Poleward" heat and salt transports (contribution of upstream fluxes)
-         IF( cdtype == 'TRA' .AND. ln_diaptr ) THEN  
-           IF( jn == jp_tem )  htr_adv(:) = ptr_sj( zwy(:,:,:) ) + htr_adv(:)
-           IF( jn == jp_sal )  str_adv(:) = ptr_sj( zwy(:,:,:) ) + str_adv(:)
-         ENDIF
-         !
-      END DO
-      !
-                   CALL wrk_dealloc( jpi, jpj, jpk, zwi, zwz, zhdiv, zwz_sav, zwzts )
-                   CALL wrk_dealloc( jpi, jpj, jpk, kjpt+1, ztrs )
-                   CALL wrk_dealloc( jpi, jpj, zwx_sav, zwy_sav )
-      IF( l_trd )  CALL wrk_dealloc( jpi, jpj, jpk, ztrdx, ztrdy, ztrdz )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('tra_adv_tvd_zts')
-      !
-   END SUBROUTINE tra_adv_tvd_zts
-
-
-   SUBROUTINE nonosc( pbef, paa, pbb, pcc, paft, p2dt )
-      !!---------------------------------------------------------------------
-      !!                    ***  ROUTINE nonosc  ***
-      !!     
-      !! **  Purpose :   compute monotonic tracer fluxes from the upstream 
-      !!       scheme and the before field by a nonoscillatory algorithm 
-      !!
-      !! **  Method  :   ... ???
-      !!       warning : pbef and paft must be masked, but the boundaries
-      !!       conditions on the fluxes are not necessary zalezak (1979)
-      !!       drange (1995) multi-dimensional forward-in-time and upstream-
-      !!       in-space based differencing for fluid
-      !!----------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpk)         , INTENT(in   ) ::   p2dt            ! vertical profile of tracer time-step
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(in   ) ::   pbef, paft      ! before & after field
-      REAL(wp), DIMENSION (jpi,jpj,jpk), INTENT(inout) ::   paa, pbb, pcc   ! monotonic fluxes in the 3 directions
-      !
-      INTEGER  ::   ji, jj, jk   ! dummy loop indices
-      INTEGER  ::   ikm1         ! local integer
-      REAL(wp) ::   zpos, zneg, zbt, za, zb, zc, zbig, zrtrn, z2dtt   ! local scalars
-      REAL(wp) ::   zau, zbu, zcu, zav, zbv, zcv, zup, zdo            !   -      -
-      REAL(wp), POINTER, DIMENSION(:,:,:) :: zbetup, zbetdo, zbup, zbdo
-      !!----------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 )  CALL timing_start('nonosc')
-      !
-      CALL wrk_alloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
-      !
-      zbig  = 1.e+40_wp
-      zrtrn = 1.e-15_wp
-      zbetup(:,:,:) = 0._wp   ;   zbetdo(:,:,:) = 0._wp
-
-      ! Search local extrema
-      ! --------------------
-      ! max/min of pbef & paft with large negative/positive value (-/+zbig) inside land
-      zbup = MAX( pbef * tmask - zbig * ( 1._wp - tmask ),   &
-         &        paft * tmask - zbig * ( 1._wp - tmask )  )
-      zbdo = MIN( pbef * tmask + zbig * ( 1._wp - tmask ),   &
-         &        paft * tmask + zbig * ( 1._wp - tmask )  )
-
-      DO jk = 1, jpkm1
-         ikm1 = MAX(jk-1,1)
-         z2dtt = p2dt(jk)
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-
-               ! search maximum in neighbourhood
-               zup = MAX(  zbup(ji  ,jj  ,jk  ),   &
-                  &        zbup(ji-1,jj  ,jk  ), zbup(ji+1,jj  ,jk  ),   &
-                  &        zbup(ji  ,jj-1,jk  ), zbup(ji  ,jj+1,jk  ),   &
-                  &        zbup(ji  ,jj  ,ikm1), zbup(ji  ,jj  ,jk+1)  )
-
-               ! search minimum in neighbourhood
-               zdo = MIN(  zbdo(ji  ,jj  ,jk  ),   &
-                  &        zbdo(ji-1,jj  ,jk  ), zbdo(ji+1,jj  ,jk  ),   &
-                  &        zbdo(ji  ,jj-1,jk  ), zbdo(ji  ,jj+1,jk  ),   &
-                  &        zbdo(ji  ,jj  ,ikm1), zbdo(ji  ,jj  ,jk+1)  )
-
-               ! positive part of the flux
-               zpos = MAX( 0., paa(ji-1,jj  ,jk  ) ) - MIN( 0., paa(ji  ,jj  ,jk  ) )   &
-                  & + MAX( 0., pbb(ji  ,jj-1,jk  ) ) - MIN( 0., pbb(ji  ,jj  ,jk  ) )   &
-                  & + MAX( 0., pcc(ji  ,jj  ,jk+1) ) - MIN( 0., pcc(ji  ,jj  ,jk  ) )
-
-               ! negative part of the flux
-               zneg = MAX( 0., paa(ji  ,jj  ,jk  ) ) - MIN( 0., paa(ji-1,jj  ,jk  ) )   &
-                  & + MAX( 0., pbb(ji  ,jj  ,jk  ) ) - MIN( 0., pbb(ji  ,jj-1,jk  ) )   &
-                  & + MAX( 0., pcc(ji  ,jj  ,jk  ) ) - MIN( 0., pcc(ji  ,jj  ,jk+1) )
-
-               ! up & down beta terms
-               zbt = e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) / z2dtt
-               zbetup(ji,jj,jk) = ( zup            - paft(ji,jj,jk) ) / ( zpos + zrtrn ) * zbt
-               zbetdo(ji,jj,jk) = ( paft(ji,jj,jk) - zdo            ) / ( zneg + zrtrn ) * zbt
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( zbetup, 'T', 1. )   ;   CALL lbc_lnk( zbetdo, 'T', 1. )   ! lateral boundary cond. (unchanged sign)
-
-      ! 3. monotonic flux in the i & j direction (paa & pbb)
-      ! ----------------------------------------
-      DO jk = 1, jpkm1
-         DO jj = 2, jpjm1
-            DO ji = fs_2, fs_jpim1   ! vector opt.
-               zau = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji+1,jj,jk) )
-               zbu = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji+1,jj,jk) )
-               zcu =       ( 0.5  + SIGN( 0.5 , paa(ji,jj,jk) ) )
-               paa(ji,jj,jk) = paa(ji,jj,jk) * ( zcu * zau + ( 1._wp - zcu) * zbu )
-
-               zav = MIN( 1._wp, zbetdo(ji,jj,jk), zbetup(ji,jj+1,jk) )
-               zbv = MIN( 1._wp, zbetup(ji,jj,jk), zbetdo(ji,jj+1,jk) )
-               zcv =       ( 0.5  + SIGN( 0.5 , pbb(ji,jj,jk) ) )
-               pbb(ji,jj,jk) = pbb(ji,jj,jk) * ( zcv * zav + ( 1._wp - zcv) * zbv )
-
-      ! monotonic flux in the k direction, i.e. pcc
-      ! -------------------------------------------
-               za = MIN( 1., zbetdo(ji,jj,jk+1), zbetup(ji,jj,jk) )
-               zb = MIN( 1., zbetup(ji,jj,jk+1), zbetdo(ji,jj,jk) )
-               zc =       ( 0.5  + SIGN( 0.5 , pcc(ji,jj,jk+1) ) )
-               pcc(ji,jj,jk+1) = pcc(ji,jj,jk+1) * ( zc * za + ( 1._wp - zc) * zb )
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( paa, 'U', -1. )   ;   CALL lbc_lnk( pbb, 'V', -1. )   ! lateral boundary condition (changed sign)
-      !
-      CALL wrk_dealloc( jpi, jpj, jpk, zbetup, zbetdo, zbup, zbdo )
-      !
-      IF( nn_timing == 1 )  CALL timing_stop('nonosc')
-      !
-   END SUBROUTINE nonosc
-
-   !!======================================================================
-END MODULE traadv_tvd
